From: acevest Date: Mon, 1 Nov 2021 08:10:46 +0000 (+0800) Subject: 优化进程调度 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/man.dnssec-dsfromkey.html?a=commitdiff_plain;h=d98d690bd33d28abae3ec2d27d09a92f3b26e520;p=kernel.git 优化进程调度 --- diff --git a/kernel/init.c b/kernel/init.c index 3f9a0c1..794abbf 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -62,7 +62,7 @@ void kernel_task(void *entry) void root_task_entry() { - //kernel_task(init_task_entry); + kernel_task(init_task_entry); //kernel_task(user_task_entry); //kernel_task(init_task_entry); diff --git a/kernel/sched.c b/kernel/sched.c index af94d2e..a72b401 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -167,7 +167,35 @@ unsigned long schedule() irq_save(iflags); printl(MPL_ROOT, "root:%d [%08x] cnt %u", root_task.pid, &root_task, root_task.cnt); - unsigned int min_ratio = ~0U; + float min_ratio = 1.0; + + bool need_reset_weight = true; + list_for_each_safe(pos, t, &all_tasks) + { + p = list_entry(pos, task_union, list); + if (p->state != TASK_RUNNING) + { + continue; + } + if (p->weight < p->priority) + { + need_reset_weight = false; + break; + } + } + + if (need_reset_weight) + { + list_for_each_safe(pos, t, &all_tasks) + { + p = list_entry(pos, task_union, list); + if (p->state != TASK_RUNNING) + { + continue; + } + p->weight = 0; + } + } list_for_each_safe(pos, t, &all_tasks) { @@ -180,24 +208,19 @@ unsigned long schedule() continue; } - printd("%08x %s weight %d\n", p, p->name, p->weight); + //printd("%08x %s weight %d\n", p, p->name, p->weight); - unsigned int ratio = p->weight / p->priority; + float ratio = (float)(p->weight * 1.0) / (p->priority * 1.0); if (ratio < min_ratio) { sel = p; min_ratio = ratio; } - - p->weight++; - if (p->weight > p->priority) - { - p->weight = 0; - } } irq_restore(iflags); - sel = &root_task; + sel->weight++; + printd("%08x %s weight %d\n", sel, sel->name, sel->weight); task_union *prev = current; task_union *next = sel;