Subject: Re: kern/37244: sched_m2 assumes ncpu is a power of 2
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org>
From: Mindaugas R. <rmind@NetBSD.org>
List: netbsd-bugs
Date: 10/29/2007 16:54:53
This is a multi-part message in MIME format.

--Multipart=_Mon__29_Oct_2007_16_54_53_+0200_wE/0a8DtR.alv=xc
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

> >Number:         37244
> >Category:       kern
> >Synopsis:       sched_m2 assumes ncpu is a power of 2
> <...>
> >Description:
> 	sched_m2's sched_setup seems assuming ncpu is a power of 2.

Here is the patch to deal with non power of 2 values. We need to take the
lower value for min_catch.

Actually, min_catch value should change according to the cpuctl
actions, that is ncpuonline. But that is a separate story..

-- 
Best regards,
Mindaugas
www.NetBSD.org

--Multipart=_Mon__29_Oct_2007_16_54_53_+0200_wE/0a8DtR.alv=xc
Content-Type: text/plain;
 name="sched_setup.diff"
Content-Disposition: attachment;
 filename="sched_setup.diff"
Content-Transfer-Encoding: 7bit

Index: sched_m2.c
===================================================================
RCS file: /cvsroot/src/sys/kern/sched_m2.c,v
retrieving revision 1.6
diff -u -p -r1.6 sched_m2.c
--- sched_m2.c	19 Oct 2007 12:16:43 -0000	1.6
+++ sched_m2.c	29 Oct 2007 14:40:33 -0000
@@ -193,10 +193,15 @@ sched_rqinit(void)
 void
 sched_setup(void)
 {
-
 #ifdef MULTIPROCESSOR
+	int ncpu2 = 1;
+
 	/* Minimal count of LWPs for catching: log2(count of CPUs) */
-	min_catch = min(ffs(ncpu) - 1, 4);
+	while (ncpu2 < ncpu)
+		ncpu2 <<= 1;
+	if (ncpu2 != ncpu)
+		ncpu2 >>= 1;
+	min_catch = min(ffs(ncpu2) - 1, 4);
 
 	/* Initialize balancing callout and run it */
 	callout_init(&balance_ch, CALLOUT_MPSAFE);

--Multipart=_Mon__29_Oct_2007_16_54_53_+0200_wE/0a8DtR.alv=xc--