Skip to contentSkip to conversation

A nicer nice scheduling

PATCH In review Roberto Ragusa 2 participants 2 messages Sep 15, 2001 – Sep 17, 2001 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 A nicer nice scheduling

Hi,

please consider including this patch in the main kernel. It was proposed on 11/04/2001 by Rik van Riel ([test-PATCH] Re: [QUESTION] 2.4.x nice level)

This patch has been working great for me, I applied it to every new kernel out.

Without this patch, a nice=19 busy-looping process is given 15% of CPU cycles when there is a busy-looping nice=0 process.

Well, if one runs background CPU-consuming programs (dnetc), this patch makes a nice speed boost.

Please CC to me any replies.

include/linux/sched.h Sun Aug 12 12:19:16 2001 renamed from include/linux/sched.h Sun Aug 12 10:18:03 2001 +2 -1
diff -urN linux-2.4.8-lmshsbrnc1/include/linux/sched.h linux-2.4.8-lmshsbrnc1_/include/linux/sched.h
@@ -305,7 +305,8 @@
  * the goodness() loop in schedule().
  */
     long counter;
-    long nice;
+    short nice_calc;
+    short nice;
     unsigned long policy;
     struct mm_struct *mm;
     int has_cpu, processor;
kernel/sched.c Sun Aug 12 12:19:16 2001 renamed from kernel/sched.c Sun Aug 12 10:18:03 2001 +19 -1
diff -urN linux-2.4.8-lmshsbrnc1/kernel/sched.c linux-2.4.8-lmshsbrnc1_/kernel/sched.c
@@ -680,8 +680,26 @@
         struct task_struct *p;
         spin_unlock_irq(&runqueue_lock);
         read_lock(&tasklist_lock);
-        for_each_task(p)
+        for_each_task(p) {
+            if (p->nice <= 0) {
+            /* The normal case... */
             p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice);
+            } else {
+            /*
+             * Niced tasks get less CPU less often, leading to
+             * the following distribution of CPU time:
+             *
+             * Nice    0    5   10   15   19
+             * %CPU  100   56   25    6    1    
+             */
+            short prio = 20 - p->nice;
+            p->nice_calc += prio;
+            if (p->nice_calc >= 20) {
+                p->nice_calc -= 20;
+                p->counter = (p->counter >> 1) + NICE_TO_TICKS(p->nice);
+            }
+            }
+        }
         read_unlock(&tasklist_lock);
         spin_lock_irq(&runqueue_lock);
     }
Signature · 1 line
            Roberto Ragusa   robertoragusa at technologist.com
#1 lore raw
Quoted 7 lines · Roberto Ragusa

Hi,

please consider including this patch in the main kernel. It was proposed on 11/04/2001 by Rik van Riel ([test-PATCH] Re: [QUESTION] 2.4.x nice level)

Quoted 6 lines

This patch has been working great for me, I applied it to every new kernel out.

Without this patch, a nice=19 busy-looping process is given 15% of CPU cycles when there is a busy-looping nice=0 process. [...]

I think it's simpler to change NICE_TO_TICKS() macro in sched.c

Bye.