diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index 6813896e..3e0253cd 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -123,7 +123,7 @@ typedef struct { /// total number of tasks in the queue uint32_t nr_tasks; // current load = average number of tasks in the queue (1-minute average) - uint32_t load; + uint32_t load[3]; // help counter to determine the the cpu load int32_t load_counter; // help counter to avoid "over balancing" diff --git a/kernel/tasks.c b/kernel/tasks.c index 039d7ad1..813ca08c 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -53,11 +53,11 @@ static task_t task_table[MAX_TASKS] = { \ static spinlock_irqsave_t table_lock = SPINLOCK_IRQSAVE_INIT; #if MAX_CORES > 1 static runqueue_t runqueues[MAX_CORES] = { \ - [0] = {task_table+0, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}, \ - [1 ... MAX_CORES-1] = {NULL, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}}; + [0] = {task_table+0, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}, \ + [1 ... MAX_CORES-1] = {NULL, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}}; #else static runqueue_t runqueues[1] = { \ - [0] = {task_table+0, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}}; + [0] = {task_table+0, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}}; #endif DEFINE_PER_CORE(task_t*, current_task, task_table+0); @@ -1079,27 +1079,37 @@ int set_timer(uint64_t deadline) return ret; } -#define FSHIFT 21 /* nr of bits of precision (e.g. 11) */ -#define FIXED_1 (1< 0) runqueues[core_id].balance_counter--; + + runqueues[core_id].load_counter--; if (runqueues[core_id].load_counter < 0) { - runqueues[core_id].load_counter += 5*TIMER_FREQ; + runqueues[core_id].load_counter += TIMER_FREQ/5 + 1; spinlock_irqsave_lock(&runqueues[core_id].lock); - runqueues[core_id].load *= EXP; - runqueues[core_id].load += runqueues[core_id].nr_tasks*(FIXED_1-EXP); - runqueues[core_id].load >>= FSHIFT; + runqueues[core_id].load[0] *= EXP_1; + runqueues[core_id].load[0] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_1); + runqueues[core_id].load[0] >>= FSHIFT; + runqueues[core_id].load[1] *= EXP_5; + runqueues[core_id].load[1] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_5); + runqueues[core_id].load[1] >>= FSHIFT; + runqueues[core_id].load[2] *= EXP_15; + runqueues[core_id].load[2] += (runqueues[core_id].nr_tasks *FIXED_1) * (FIXED_1 - EXP_15); + runqueues[core_id].load[2] >>= FSHIFT; spinlock_irqsave_unlock(&runqueues[core_id].lock); - //kprintf("load of core %u: %u, %u\n", core_id, runqueues[core_id].load, runqueues[core_id].nr_tasks); + kprintf("load of core %u: %u, %u, %u, %u\n", core_id, runqueues[core_id].load[0], runqueues[core_id].load[1], runqueues[core_id].load[2], runqueues[core_id].nr_tasks); } }