diff --git a/kernel/tasks.c b/kernel/tasks.c index 9939651a..57fccdba 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -50,9 +50,14 @@ static task_t task_table[MAX_TASKS] = { \ [0] = {0, TASK_IDLE, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}, \ [1 ... MAX_TASKS-1] = {0, TASK_INVALID, 0, 0, 0, NULL, NULL, 0, ATOMIC_INIT(0), SPINLOCK_INIT, NULL, SPINLOCK_INIT, NULL, 0, 0, 0, 0}}; 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_INIT}, \ [1 ... MAX_CORES-1] = {NULL, NULL, 0, 0, 0, 0, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_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_INIT}}; +#endif DEFINE_PER_CORE(task_t*, current_task, task_table+0); @@ -859,6 +864,9 @@ int wakeup_task(tid_t id) ret = 0; spinlock_lock(&runqueues[core_id].lock); + // increase the number of ready tasks + runqueues[core_id].nr_tasks++; + // add task to the runqueue if (!runqueues[core_id].queue[prio-1].last) { runqueues[core_id].queue[prio-1].last = runqueues[core_id].queue[prio-1].first = task; @@ -906,6 +914,8 @@ int block_current_task(void) ret = 0; spinlock_lock(&runqueues[core_id].lock); + // reduce the number of ready tasks + runqueues[core_id].nr_tasks--; // remove task from queue if (task_table[id].prev) @@ -953,6 +963,9 @@ int set_timer(uint64_t deadline) spinlock_lock(&runqueues[core_id].lock); + // reduce the number of ready tasks + runqueues[core_id].nr_tasks--; + // remove task from queue if (curr_task->prev) curr_task->prev->next = curr_task->next; @@ -1035,6 +1048,7 @@ extern atomic_int32_t cpu_online; void load_balancing(void) { +#if 0 uint32_t i, core_id = CORE_ID; uint32_t prio; task_t* task; @@ -1130,6 +1144,7 @@ no_task_found: spinlock_unlock(&runqueues[i].lock); } spinlock_unlock(&runqueues[core_id].lock); +#endif } #endif @@ -1172,6 +1187,9 @@ void scheduler(void) task->status = TASK_READY; prio = task->prio; + // increase the number of ready tasks + runqueues[core_id].nr_tasks++; + // add task to the runqueue if (!runqueues[core_id].queue[prio-1].first) { runqueues[core_id].queue[prio-1].last = runqueues[core_id].queue[prio-1].first = task; @@ -1189,10 +1207,10 @@ void scheduler(void) runqueues[core_id].old_task = NULL; // reset old task prio = last_set(runqueues[core_id].prio_bitmap); // determines highest priority #if MAX_CORES > 1 - /*if (!prio) { + if (!prio) { load_balancing(); prio = last_set(runqueues[core_id].prio_bitmap); // retry... - }*/ + } #endif if (BUILTIN_EXPECT(prio > MAX_PRIO, 0)) {