kern/120138: steal_thresh may be set a wrong value in sched_ule.c

KOIE Hidetaka koie at suri.co.jp
Wed Jan 30 03:50:01 UTC 2008


>Number:         120138
>Category:       kern
>Synopsis:       steal_thresh may be set a wrong value in sched_ule.c
>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 Jan 30 03:50:00 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     KOIE Hidetaka
>Release:        FreeBSD 8.0-CURRENT amd64
>Organization:
surigiken
>Environment:
System: FreeBSD guriandgura 8.0-CURRENT FreeBSD 8.0-CURRENT #0: Sat Jan 26 13:56
:29 JST 2008 koie at guriandgura:/usr/obj/usr/src/sys/GURIANDGURA amd64
>Description:
If mp_ncpus is not a power of 2, ffs(mp_ncpus) != floor(log2(mp_ncpu)).
But I'm not seen an irregular system,
I don't verify whether the problem occurs.

>How-To-Repeat:
#include <math.h>
#include <stdio.h>
#include <string.h>
main()
{
    int i;
    for (i = 1 ;i < 10;i++)
        printf("%d %d %d %d\n",
            i,
            ffs(i)-1,
            fls(i)-1,
            (int)floor(log(i)/log(2)));
}
>Fix:
use fls().


Patch attached with submission follows:

--- sched_ule.c.orig	2008-01-30 12:08:11.896645510 +0900
+++ sched_ule.c	2008-01-30 12:15:32.154540563 +0900
@@ -1365,11 +1365,11 @@ sched_initticks(void *dummy)
 	 */
 	balance_interval = realstathz;
 	/*
-	 * Set steal thresh to log2(mp_ncpu) but no greater than 4.  This
+	 * Set steal thresh to floor(log2(mp_ncpu)) but no greater than 4.  This
 	 * prevents excess thrashing on large machines and excess idle on
 	 * smaller machines.
 	 */
-	steal_thresh = min(ffs(mp_ncpus) - 1, 4);
+	steal_thresh = min(fls(mp_ncpus) - 1, 4);
 	affinity = SCHED_AFFINITY_DEFAULT;
 #endif
 }


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


More information about the freebsd-bugs mailing list