From d98d690bd33d28abae3ec2d27d09a92f3b26e520 Mon Sep 17 00:00:00 2001 From: acevest Date: Mon, 1 Nov 2021 16:10:46 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E8=BF=9B=E7=A8=8B=E8=B0=83?= =?utf8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/init.c | 2 +- kernel/sched.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 11 deletions(-) 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; -- 2.44.0