Date: Wed, 30 Jan 2008 03:41:49 GMT From: KOIE Hidetaka <koie@suri.co.jp> To: freebsd-gnats-submit@FreeBSD.org Subject: kern/120138: steal_thresh may be set a wrong value in sched_ule.c Message-ID: <200801300341.m0U3fnDP015255@www.freebsd.org> Resent-Message-ID: <200801300350.m0U3o0Qt016941@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801300341.m0U3fnDP015255>