]> Zhao Yanbai Git Server - kernel.git/commitdiff
优化进程调度
authoracevest <zhaoyanbai@126.com>
Mon, 1 Nov 2021 08:10:46 +0000 (16:10 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 3 Nov 2021 02:45:45 +0000 (10:45 +0800)
kernel/init.c
kernel/sched.c

index 3f9a0c1b10215fb160e22d30938c0b2622d273a4..794abbf2ee06e345c57b62feec4e4e4ae69a82d4 100644 (file)
@@ -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);
 
index af94d2e380ab44fb7a0d6ad98f8f97fd4fea0ba4..a72b401d9597d007b6c5eb78827ca5098b7e0f8d 100644 (file)
@@ -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;