From: Jeffrey Hsu Date: Fri, 5 Mar 2004 19:29:17 +0000 (+0000) Subject: Remember the next lowest power of 2 of "npus" in "ncpus2". X-Git-Tag: v2.0.1~11877 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/9010005588614e2173b1f5e8ce69a0185ff872a3 Remember the next lowest power of 2 of "npus" in "ncpus2". --- diff --git a/sys/i386/i386/mp_machdep.c b/sys/i386/i386/mp_machdep.c index 3677e42ba3..7df65b110e 100644 --- a/sys/i386/i386/mp_machdep.c +++ b/sys/i386/i386/mp_machdep.c @@ -23,7 +23,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.115.2.15 2003/03/14 21:22:35 jhb Exp $ - * $DragonFly: src/sys/i386/i386/Attic/mp_machdep.c,v 1.24 2004/03/01 06:33:16 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/mp_machdep.c,v 1.25 2004/03/05 19:29:17 hsu Exp $ */ #include "opt_cpu.h" @@ -1940,7 +1940,7 @@ default_mp_table(int type) static int start_all_aps(u_int boot_addr) { - int x, i, pg; + int x, i, pg, n; u_char mpbiosreason; u_long mpbioswarmvec; struct mdglobaldata *gd; @@ -2050,6 +2050,13 @@ start_all_aps(u_int boot_addr) /* set ncpus to 1 + highest logical cpu. Not all may have come up */ ncpus = x; + /* round ncpus down to power of 2 */ + n = ncpus; + while (n >>= 1) + ++ncpus2_shift; + ncpus2 = 1 << ncpus2_shift; + ncpus2_mask = ncpus2 - 1; + /* build our map of 'other' CPUs */ mycpu->gd_other_cpus = smp_startup_mask & ~(1 << mycpu->gd_cpuid); mycpu->gd_ipiq = (void *)kmem_alloc(kernel_map, sizeof(lwkt_ipiq) * ncpus); diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index ee48b3def3..db1b370ca6 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -37,7 +37,7 @@ * * @(#)kern_synch.c 8.9 (Berkeley) 5/19/95 * $FreeBSD: src/sys/kern/kern_synch.c,v 1.87.2.6 2002/10/13 07:29:53 kbyanc Exp $ - * $DragonFly: src/sys/kern/kern_synch.c,v 1.27 2004/01/30 05:42:17 dillon Exp $ + * $DragonFly: src/sys/kern/kern_synch.c,v 1.28 2004/03/05 19:29:17 hsu Exp $ */ #include "opt_ktrace.h" @@ -68,6 +68,7 @@ int hogticks; int lbolt; int sched_quantum; /* Roundrobin scheduling quantum in ticks. */ int ncpus; +int ncpus2, ncpus2_shift, ncpus2_mask; static struct callout loadav_callout; diff --git a/sys/platform/pc32/i386/mp_machdep.c b/sys/platform/pc32/i386/mp_machdep.c index cf2c49a1b7..c71de29711 100644 --- a/sys/platform/pc32/i386/mp_machdep.c +++ b/sys/platform/pc32/i386/mp_machdep.c @@ -23,7 +23,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/i386/i386/mp_machdep.c,v 1.115.2.15 2003/03/14 21:22:35 jhb Exp $ - * $DragonFly: src/sys/platform/pc32/i386/mp_machdep.c,v 1.24 2004/03/01 06:33:16 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/mp_machdep.c,v 1.25 2004/03/05 19:29:17 hsu Exp $ */ #include "opt_cpu.h" @@ -1940,7 +1940,7 @@ default_mp_table(int type) static int start_all_aps(u_int boot_addr) { - int x, i, pg; + int x, i, pg, n; u_char mpbiosreason; u_long mpbioswarmvec; struct mdglobaldata *gd; @@ -2050,6 +2050,13 @@ start_all_aps(u_int boot_addr) /* set ncpus to 1 + highest logical cpu. Not all may have come up */ ncpus = x; + /* round ncpus down to power of 2 */ + n = ncpus; + while (n >>= 1) + ++ncpus2_shift; + ncpus2 = 1 << ncpus2_shift; + ncpus2_mask = ncpus2 - 1; + /* build our map of 'other' CPUs */ mycpu->gd_other_cpus = smp_startup_mask & ~(1 << mycpu->gd_cpuid); mycpu->gd_ipiq = (void *)kmem_alloc(kernel_map, sizeof(lwkt_ipiq) * ncpus); diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 7ed671ed01..9714ccd85f 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -37,7 +37,7 @@ * * @(#)systm.h 8.7 (Berkeley) 3/29/95 * $FreeBSD: src/sys/sys/systm.h,v 1.111.2.18 2002/12/17 18:04:02 sam Exp $ - * $DragonFly: src/sys/sys/systm.h,v 1.17 2004/01/30 05:42:18 dillon Exp $ + * $DragonFly: src/sys/sys/systm.h,v 1.18 2004/03/05 19:29:17 hsu Exp $ */ #ifndef _SYS_SYSTM_H_ @@ -84,6 +84,9 @@ extern int bootverbose; /* nonzero to print verbose messages */ extern int maxusers; /* system tune hint */ extern int ncpus; /* total number of cpus (real, hyper, virtual)*/ +extern int ncpus2; /* ncpus rounded down to power of 2 */ +extern int ncpus2_shift; /* log base 2 of ncpus2 */ +extern int ncpus2_mask; /* ncpus2 - 1 */ #ifdef INVARIANTS /* The option is always available */ #define KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0)