From nobody@FreeBSD.org  Wed Jan 30 03:43:36 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 4CB8416A41A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Jan 2008 03:43:36 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 34E8C13C43E
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Jan 2008 03:43:36 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0U3fnDU015256
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 30 Jan 2008 03:41:49 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m0U3fnDP015255;
	Wed, 30 Jan 2008 03:41:49 GMT
	(envelope-from nobody)
Message-Id: <200801300341.m0U3fnDP015255@www.freebsd.org>
Date: Wed, 30 Jan 2008 03:41:49 GMT
From: KOIE Hidetaka <koie@suri.co.jp>
To: freebsd-gnats-submit@FreeBSD.org
Subject: steal_thresh may be set a wrong value in sched_ule.c
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120138
>Category:       kern
>Synopsis:       [sched_ule] [patch] steal_thresh may be set a wrong value in sched_ule.c when mp_ncpus not power of 2
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jeff
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jan 30 03:50:00 UTC 2008
>Closed-Date:    Fri Mar 15 23:42:03 UTC 2013
>Last-Modified:  Fri Mar 15 23:42:03 UTC 2013
>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:
Responsible-Changed-From-To: freebsd-bugs->jeff 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Jan 30 10:03:11 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120138 

From: "Timothy Brown" <stimbrown@fastmail.com.au>
To: bug-followup@FreeBSD.org, koie@suri.co.jp
Cc:  
Subject: Re: kern/120138: [sched_ule] [patch] steal_thresh may be set a wrong
 value in sched_ule.c
Date: Wed, 11 Mar 2009 08:29:13 +1000

 This problem causes my AMD X3 triple core system to hang when booting.
 If I manually apply this patch and recompile the kernel, my system
 boots fine.
 
 For other people having this problem, see:
 http://www.nabble.com/AMD-Phenom(tm)-8450-Triple-Core-Processor-does-not-boot-7.1-PRERELESE-tt20936145.html
 or:
 http://www.nabble.com/SCHED_ULE-%2B-SMP-Phenom-freeze-tt22414759.html
 
 Can this ticket be raised in priority and preferably fixed asap?
 
 Thanks,
 Tim Brown

From: Jeff Roberson <jroberson@jroberson.net>
To: bug-followup@FreeBSD.org
Cc: Timothy Brown <stimbrown@fastmail.com.au>, koie@suri.co.jp
Subject: Re: kern/120138: [sched_ule] [patch] steal_thresh may be set a wrong
 value in sched_ule.c
Date: Sat, 14 Mar 2009 01:45:38 -1000 (HST)

 Thanks for the patch and report.  I have committed this to HEAD and will 
 merge back to 7 shortly.
 
 Thanks,
 Jeff
State-Changed-From-To: open->patched 
State-Changed-By: jeff 
State-Changed-When: Sun Mar 15 06:23:31 UTC 2009 
State-Changed-Why:  
Committed to 8.0, will MFC shortly. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120138 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Fri Mar 15 23:42:02 UTC 2013 
State-Changed-Why:  
MFCed/fixed by now or it will never be MFCed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120138 
>Unformatted:
