add first version of our load balancer
This commit is contained in:
parent
6b2e1f16bc
commit
670b3f850c
1 changed files with 34 additions and 7 deletions
|
@ -1115,9 +1115,33 @@ void update_load(void)
|
|||
|
||||
#if MAX_CORES > 1
|
||||
extern atomic_int32_t cpu_online;
|
||||
#endif
|
||||
|
||||
void dump_load(void)
|
||||
{
|
||||
uint32_t i;
|
||||
#if MAX_CORES > 1
|
||||
uint32_t ncores = atomic_int32_read(&cpu_online);
|
||||
#else
|
||||
uint32_t ncores = 1;
|
||||
#endif
|
||||
|
||||
for(i=0; i<ncores; i++)
|
||||
{
|
||||
kprintf("Load average of core %u: %u.%u, %u.%u, %u.%u\n",
|
||||
i, runqueues[i].load[0] >> FSHIFT,
|
||||
((runqueues[i].load[0] & ((1 << FSHIFT) - 1)) * 100) / (1 << FSHIFT),
|
||||
runqueues[i].load[1] >> FSHIFT,
|
||||
((runqueues[i].load[1] & ((1 << FSHIFT) - 1)) * 100) / (1 << FSHIFT),
|
||||
runqueues[i].load[2] >> FSHIFT,
|
||||
((runqueues[i].load[2] & ((1 << FSHIFT) - 1)) * 100) / (1 << FSHIFT));
|
||||
}
|
||||
}
|
||||
|
||||
#if MAX_CORES > 1
|
||||
void load_balancing(void)
|
||||
{
|
||||
#if 1
|
||||
uint32_t i, core_id = CORE_ID;
|
||||
uint32_t prio;
|
||||
task_t* task;
|
||||
|
@ -1133,18 +1157,19 @@ void load_balancing(void)
|
|||
kprintf("Try to steal a task from core %u (load %u) to %u (load %u)\n", i, runqueues[i].load[0], core_id, runqueues[core_id].load[0]);
|
||||
kprintf("Task on core %u: %u, core %u, %u\n", i, runqueues[i].nr_tasks, core_id, runqueues[i].nr_tasks);
|
||||
|
||||
prio = msb(runqueues[i].prio_bitmap);
|
||||
prio = lsb(runqueues[i].prio_bitmap);
|
||||
if (prio < sizeof(size_t)*8) {
|
||||
// steal a ready task
|
||||
task = runqueues[i].queue[prio-1].last;
|
||||
kprintf("Try to steal a ready task %d\n", task->id);
|
||||
kprintf("Try to steal a ready task %d with prio %u\n", task->id, prio);
|
||||
|
||||
// remove last element from queue i
|
||||
if (task->prev)
|
||||
task->prev->next = NULL;
|
||||
runqueues[i].queue[prio-1].last = task->prev;
|
||||
if (!runqueues[i].queue[prio-1].last)
|
||||
runqueues[i].queue[prio-1].first = NULL;
|
||||
if (runqueues[i].queue[prio-1].first == task) {
|
||||
runqueues[i].queue[prio-1].first = runqueues[i].queue[prio-1].last = NULL;
|
||||
runqueues[i].prio_bitmap &= ~(1 << prio);
|
||||
} else runqueues[i].queue[prio-1].last = task->prev;
|
||||
|
||||
// add task at the end of queue core_id
|
||||
if (!runqueues[core_id].queue[prio-1].last) {
|
||||
|
@ -1156,12 +1181,13 @@ void load_balancing(void)
|
|||
runqueues[core_id].queue[prio-1].last = task;
|
||||
task->next = NULL;
|
||||
}
|
||||
runqueues[core_id].prio_bitmap |= (1 << prio);
|
||||
|
||||
// update task counters
|
||||
runqueues[core_id].nr_tasks++;
|
||||
runqueues[i].nr_tasks--;
|
||||
runqueues[core_id].balance_counter = TIMER_FREQ/2;
|
||||
} /*else {
|
||||
} else {
|
||||
task_t* tmp;
|
||||
|
||||
// steal a blocked task
|
||||
|
@ -1207,12 +1233,13 @@ void load_balancing(void)
|
|||
runqueues[core_id].nr_tasks++;
|
||||
runqueues[i].nr_tasks--;
|
||||
runqueues[core_id].balance_counter = TIMER_FREQ/2;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
no_task_found:
|
||||
spinlock_irqsave_unlock(&runqueues[i].lock);
|
||||
}
|
||||
spinlock_irqsave_unlock(&runqueues[core_id].lock);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue