first steps to realize load balancing
This commit is contained in:
parent
c2ec2800bc
commit
ef3ab5b836
2 changed files with 22 additions and 22 deletions
|
@ -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 ... 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}};
|
||||
[0] = {task_table+0, NULL, 0, {[0 ... 2] = 0}, TIMER_FREQ/5, TIMER_FREQ/2, 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, TIMER_FREQ/2, 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 ... 2] = 0}, TIMER_FREQ/5, 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, TIMER_FREQ/2, 0, {[0 ... MAX_PRIO-1] = {NULL, NULL}}, {NULL, NULL}, SPINLOCK_IRQSAVE_INIT}};
|
||||
#endif
|
||||
|
||||
DEFINE_PER_CORE(task_t*, current_task, task_table+0);
|
||||
|
@ -1109,7 +1109,7 @@ void update_load(void)
|
|||
runqueues[core_id].load[2] >>= FSHIFT;
|
||||
spinlock_irqsave_unlock(&runqueues[core_id].lock);
|
||||
|
||||
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);
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1118,24 +1118,23 @@ 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;
|
||||
|
||||
spinlock_lock(&runqueues[core_id].lock);
|
||||
spinlock_irqsave_lock(&runqueues[core_id].lock);
|
||||
for(i=0; (i<atomic_int32_read(&cpu_online)) && (runqueues[core_id].balance_counter <= 0); i++)
|
||||
{
|
||||
if (i == core_id)
|
||||
break;
|
||||
continue;
|
||||
|
||||
spinlock_lock(&runqueues[i].lock);
|
||||
if (runqueues[i].load > runqueues[core_id].load) {
|
||||
kprintf("Try to steal a task from core %u (load %u) to %u (load %u)\n", i, runqueues[i].load, core_id, runqueues[core_id].load);
|
||||
spinlock_irqsave_lock(&runqueues[i].lock);
|
||||
if ((runqueues[i].load[0] >> (FSHIFT-1)) > (runqueues[core_id].load[0] >> (FSHIFT-1))) {
|
||||
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 = last_set(runqueues[i].prio_bitmap);
|
||||
if (prio) {
|
||||
prio = msb(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);
|
||||
|
@ -1161,8 +1160,8 @@ void load_balancing(void)
|
|||
// update task counters
|
||||
runqueues[core_id].nr_tasks++;
|
||||
runqueues[i].nr_tasks--;
|
||||
runqueues[core_id].balance_counter = 5*TIMER_FREQ;
|
||||
} else {
|
||||
runqueues[core_id].balance_counter = TIMER_FREQ/2;
|
||||
} /*else {
|
||||
task_t* tmp;
|
||||
|
||||
// steal a blocked task
|
||||
|
@ -1207,14 +1206,13 @@ void load_balancing(void)
|
|||
// update task counters
|
||||
runqueues[core_id].nr_tasks++;
|
||||
runqueues[i].nr_tasks--;
|
||||
runqueues[core_id].balance_counter = 5*TIMER_FREQ;
|
||||
}
|
||||
runqueues[core_id].balance_counter = TIMER_FREQ/2;
|
||||
}*/
|
||||
}
|
||||
no_task_found:
|
||||
spinlock_unlock(&runqueues[i].lock);
|
||||
spinlock_irqsave_unlock(&runqueues[i].lock);
|
||||
}
|
||||
spinlock_unlock(&runqueues[core_id].lock);
|
||||
#endif
|
||||
spinlock_irqsave_unlock(&runqueues[core_id].lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -91,6 +91,8 @@ static int foo(void* arg)
|
|||
sleep(1);
|
||||
}
|
||||
|
||||
while(1);
|
||||
|
||||
return 42;
|
||||
}
|
||||
|
||||
|
@ -278,7 +280,7 @@ int test_init(void)
|
|||
{
|
||||
// char* argv[] = {"/bin/mshell", NULL};
|
||||
char* argv[] = {"/bin/tests", NULL};
|
||||
// char* server_argv[] = {"/bin/server", "6789", NULL};
|
||||
char* server_argv[] = {"/bin/server", "6789", NULL};
|
||||
// char* client_argv[] = {"/bin/client", "127.0.0.1", "6789", NULL};
|
||||
|
||||
sem_init(&producing, 1);
|
||||
|
@ -294,9 +296,9 @@ int test_init(void)
|
|||
//create_kernel_task(NULL, svm_test, NULL, NORMAL_PRIO);
|
||||
//create_user_task(NULL, "/bin/hello", argv);
|
||||
create_user_task(NULL, "/bin/tests", argv);
|
||||
//create_user_task(NULL, "/bin/jacobi", argv);
|
||||
create_user_task(NULL, "/bin/jacobi", argv);
|
||||
//create_user_task(NULL, "/bin/mshell", argv);
|
||||
//create_user_task(NULL, "/bin/jacobi", argv);
|
||||
create_user_task(NULL, "/bin/jacobi", argv);
|
||||
//create_user_task(NULL, "/bin/server", server_argv);
|
||||
//sleep(5);
|
||||
//create_user_task(NULL, "/bin/client", client_argv);
|
||||
|
|
Loading…
Add table
Reference in a new issue