From 09e9dd4fb7ecfdc1fd93c105b0fc626f77dc1127 Mon Sep 17 00:00:00 2001 From: acevest Date: Tue, 16 May 2023 15:51:02 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E5=9C=A8Mac=20M1=E6=9C=BA?= =?utf8?q?=E5=99=A8=E4=B8=8A=E7=94=A8qemu=E6=97=A0=E6=B3=95=E5=AE=8C?= =?utf8?q?=E6=88=90=E8=B0=83=E5=BA=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/sched.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index 1309aa4..54c267e 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -167,8 +167,24 @@ unsigned long schedule() { irq_save(iflags); // printl(MPL_ROOT, "root:%d [%08x] cnt %u", root_task.pid, &root_task, root_task.cnt); - float min_ratio = 1.0; +#if 1 + list_for_each_safe(pos, t, &all_tasks) { + p = list_entry(pos, task_union, list); + if (p->state != TASK_READY) { + continue; + } + if (p->weight >= p->priority) { + p->weight = 0; + continue; + } + + if (p->weight < sel->weight) { + sel = p; + } + } +#else + 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); @@ -198,15 +214,19 @@ unsigned long schedule() { continue; } + // 貌似在Mac的M1上的qemu执行这一句会有问题 + // 所以暂时把这整个逻辑注释掉,写了个简单的替代算法 float ratio = (float)(p->weight * 1.0) / (p->priority * 1.0); if (ratio < min_ratio) { sel = p; min_ratio = ratio; } } +#endif + irq_restore(iflags); sel->sched_cnt++; - sel->weight++; + sel->weight += 13; // printk("%08x %s weight %d state: %s\n", sel, sel->name, sel->weight, task_state(sel->state)); task_union *prev = current; task_union *next = sel; @@ -215,9 +235,9 @@ unsigned long schedule() { // printk("switch to: %s:%d\n", next->name, next->pid); list_for_each_safe(pos, t, &all_tasks) { p = list_entry(pos, task_union, list); - printl(MPL_TASK_0 + p->pid * 2, " "); // 清掉上一次显示的 '>' - printl(MPL_TASK_0 + p->pid * 2, "%s%4s:%d [%08x] state %s weight %03d sched %u", next == p ? ">" : " ", - p->name, p->pid, p, task_state(p->state), p->weight, p->sched_cnt); + printl(MPL_TASK_0 + p->pid, " "); // 清掉上一次显示的 '>' + printl(MPL_TASK_0 + p->pid, "%s%4s:%d [%08x] state %s weight %03d sched %u", next == p ? ">" : " ", p->name, + p->pid, p, task_state(p->state), p->weight, p->sched_cnt); } context_switch(prev, next); } -- 2.44.0