[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

kern/72659: [patch] little bug in sched_ule interractivty scorer



>Number:         72659
>Category:       kern
>Synopsis:       [patch] little bug in sched_ule interractivty scorer
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 13 23:10:28 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Antoine Brodin
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
none
>Environment:
System: FreeBSD massena-4-82-67-196-50.fbx.proxad.net 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Wed Oct 13 00:03:44 CEST 2004 antoine_(_at_)_massena-4-82-67-196-50_(_dot_)_fbx_(_dot_)_proxad_(_dot_)_net:/usr/obj/usr/src/sys/BARTON i386
>Description:
There's a little bug in the interactivty scorer in sched_ule :
when the sleeptime is equal to the runtime, it returns 0 instead of
either SCHED_INTERACT_HALF or 0.
The routine also uses max() with signed ints, they should be replaced
by imax().
>How-To-Repeat:
You can print sleeptime, runtime and interactivity in a file and then
use gnuplot to show it in 3D.
The problem when sleeptime is equal to runtime is obvious.
Note : I can't reproduce the sleeptime is equal to runtime case easily,
durring boot I have a thread that has sleeptime=runtime=30720
but the applications I use don't seem to be "half interractive".
I can reproduce it by running during 2 or 3 minutes this ugly program
on my box (and adding a printf in the scorer code) :

#include <stdio.h>
#include <unistd.h>
int
main(void)
{
        int i, j;
        while (1) {
                for (i = 0; i < 100000000 - j; i++)
                        ;
                usleep(250000 + j);
                j += 100;
                printf("%d\n", j);
        }
}

>Fix:
Apply the attached patch

--- sched_ule.patch begins here ---
Index: sched_ule.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/sched_ule.c,v
retrieving revision 1.134
diff -u -r1.134 sched_ule.c
--- sched_ule.c	5 Oct 2004 22:14:02 -0000	1.134
+++ sched_ule.c	13 Oct 2004 20:09:53 -0000
@@ -1143,19 +1143,17 @@
 	int div;
 
 	if (kg->kg_runtime > kg->kg_slptime) {
-		div = max(1, kg->kg_runtime / SCHED_INTERACT_HALF);
+		div = imax(1, kg->kg_runtime / SCHED_INTERACT_HALF);
 		return (SCHED_INTERACT_HALF +
 		    (SCHED_INTERACT_HALF - (kg->kg_slptime / div)));
-	} if (kg->kg_slptime > kg->kg_runtime) {
-		div = max(1, kg->kg_slptime / SCHED_INTERACT_HALF);
+	}
+	if (kg->kg_slptime > kg->kg_runtime) {
+		div = imax(1, kg->kg_slptime / SCHED_INTERACT_HALF);
 		return (kg->kg_runtime / div);
 	}
-
-	/*
-	 * This can happen if slptime and runtime are 0.
-	 */
+	if (kg->kg_runtime > 0)
+		return (SCHED_INTERACT_HALF);
 	return (0);
-
 }
 
 /*
--- sched_ule.patch ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted: