From ef3ab5b8364d908424fd3b0123fb346b0a95a999 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 20 Sep 2011 14:37:28 +0200 Subject: [PATCH] first steps to realize load balancing --- kernel/tasks.c | 36 +++++++++++++++++------------------- kernel/tests.c | 8 +++++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/kernel/tasks.c b/kernel/tasks.c index 813ca08c..bb59b3b0 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 ... 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 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 diff --git a/kernel/tests.c b/kernel/tests.c index e8390fa6..345ebfc7 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -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);