Index: src/sys/alpha/alpha/mp_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/alpha/alpha/mp_machdep.c,v retrieving revision 1.23 diff -u -r1.23 mp_machdep.c --- src/sys/alpha/alpha/mp_machdep.c 2001/07/14 21:37:57 1.23 +++ src/sys/alpha/alpha/mp_machdep.c 2001/07/22 21:45:04 @@ -301,6 +301,11 @@ /* XXX: Need to check for valid platforms here. */ + boot_cpu_id = PCPU_GET(cpuid); + KASSERT(boot_cpu_id == hwrpb->rpb_primary_cpu_id, + ("cpu_mp_probe() called on non-primary CPU")); + all_cpus = 1 << boot_cpu_id; + mp_ncpus = 1; /* Make sure we have at least one secondary CPU. */ @@ -324,16 +329,12 @@ } void -cpu_mp_start() +cpu_mp_start(void) { int i; mtx_init(&ap_boot_mtx, "ap boot", MTX_SPIN); - boot_cpu_id = PCPU_GET(cpuid); - KASSERT(boot_cpu_id == hwrpb->rpb_primary_cpu_id, - ("mp_start() called on non-primary CPU")); - all_cpus = 1 << boot_cpu_id; for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) { struct pcs *pcsp; Index: src/sys/i386/i386/mp_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/i386/i386/mp_machdep.c,v retrieving revision 1.160 diff -u -r1.160 mp_machdep.c --- src/sys/i386/i386/mp_machdep.c 2001/07/12 06:32:50 1.160 +++ src/sys/i386/i386/mp_machdep.c 2001/07/22 21:45:04 @@ -406,6 +406,12 @@ int cpu_mp_probe(void) { + /* + * Record BSP in CPU map + * This is done here so that MBUF init code works correctly. + */ + all_cpus = 1; + return (mp_capable); } @@ -1928,9 +1934,6 @@ outb(CMOS_REG, BIOS_RESET); mpbiosreason = inb(CMOS_DATA); #endif - - /* record BSP in CPU map */ - all_cpus = 1; /* set up temporary P==V mapping for AP boot */ /* XXX this is a hack, we should boot the AP on its own stack/PTD */ Index: src/sys/ia64/ia64/mp_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/ia64/ia64/mp_machdep.c,v retrieving revision 1.17 diff -u -r1.17 mp_machdep.c --- src/sys/ia64/ia64/mp_machdep.c 2001/05/15 23:22:24 1.17 +++ src/sys/ia64/ia64/mp_machdep.c 2001/07/22 21:45:04 @@ -71,6 +71,7 @@ int cpu_mp_probe() { + all_cpus = 1; /* Needed for MB init code */ return (0); } Index: src/sys/kern/subr_mbuf.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_mbuf.c,v retrieving revision 1.3 diff -u -r1.3 subr_mbuf.c --- src/sys/kern/subr_mbuf.c 2001/07/17 15:51:12 1.3 +++ src/sys/kern/subr_mbuf.c 2001/07/22 21:45:04 @@ -48,7 +48,12 @@ /* * Maximum number of PCPU containers. If you know what you're doing you could * explicitly define MBALLOC_NCPU to be exactly the number of CPUs on your - * system during compilation, and thus prevent kernel structure bloats. + * system during compilation, and thus prevent kernel structure bloat. + * + * SMP and non-SMP kernels clearly have a different number of possible cpus, + * but because we cannot assume a dense array of CPUs, we always allocate + * and traverse PCPU containers up to NCPU amount and merely check for + * CPU availability. */ #ifdef MBALLOC_NCPU #define NCPU MBALLOC_NCPU @@ -57,12 +62,18 @@ #endif /* - * SMP and non-SMP kernels clearly have a different number of possible cpus. + * Macros allowing us to determine whether or not a given CPU's container + * should be configured during mb_init(). + * XXX: Eventually we may want to provide hooks for CPU spinon/spinoff that + * will allow us to configure the containers on spinon/spinoff. As it + * stands, booting with CPU x disactivated and activating CPU x only + * after bootup will lead to disaster and CPU x's container will be + * uninitialized. */ #ifdef SMP -#define NCPU_PRESENT mp_ncpus +#define CPU_ABSENT(x) ((all_cpus & (1 << x)) == 0) #else -#define NCPU_PRESENT 1 +#define CPU_ABSENT(x) 0 #endif /* @@ -388,7 +399,10 @@ /* * Allocate and initialize PCPU containers. */ - for (i = 0; i < NCPU_PRESENT; i++) { + for (i = 0; i < NCPU; i++) { + if (CPU_ABSENT(i)) + continue; + mb_list_mbuf.ml_cntlst[i] = malloc(sizeof(struct mb_pcpu_list), M_MBUF, M_NOWAIT); mb_list_clust.ml_cntlst[i] = malloc(sizeof(struct mb_pcpu_list), @@ -401,6 +415,7 @@ mb_list_mbuf.ml_cntlst[i]->mb_cont.mc_lock = mb_list_clust.ml_cntlst[i]->mb_cont.mc_lock = &mbuf_pcpu[i]; + mb_statpcpu[i].mb_active = 1; mb_list_mbuf.ml_cntlst[i]->mb_cont.mc_numowner = mb_list_clust.ml_cntlst[i]->mb_cont.mc_numowner = i; mb_list_mbuf.ml_cntlst[i]->mb_cont.mc_starved = @@ -626,7 +641,9 @@ * Cycle all the PCPU containers. Increment starved counts if found * empty. */ - for (i = 0; i < NCPU_PRESENT; i++) { + for (i = 0; i < NCPU; i++) { + if (CPU_ABSENT(i)) + continue; cnt_lst = MB_GET_PCPU_LIST_NUM(mb_list, i); MB_LOCK_CONT(cnt_lst); Index: src/sys/powerpc/powerpc/mp_machdep.c =================================================================== RCS file: /home/ncvs/src/sys/powerpc/powerpc/mp_machdep.c,v retrieving revision 1.8 diff -u -r1.8 mp_machdep.c --- src/sys/powerpc/powerpc/mp_machdep.c 2001/06/16 07:14:07 1.8 +++ src/sys/powerpc/powerpc/mp_machdep.c 2001/07/22 21:45:04 @@ -51,6 +51,7 @@ int cpu_mp_probe(void) { + all_cpus = 1; /* needed for MB init code */ return 0; } Index: src/sys/sys/mbuf.h =================================================================== RCS file: /home/ncvs/src/sys/sys/mbuf.h,v retrieving revision 1.82 diff -u -r1.82 mbuf.h --- src/sys/sys/mbuf.h 2001/06/22 06:35:19 1.82 +++ src/sys/sys/mbuf.h 2001/07/22 21:45:04 @@ -216,6 +216,7 @@ u_long mb_mbpgs; u_long mb_clfree; u_long mb_clpgs; + short mb_active; }; /* Index: src/usr.bin/netstat/mbuf.c =================================================================== RCS file: /home/ncvs/src/usr.bin/netstat/mbuf.c,v retrieving revision 1.26 diff -u -r1.26 mbuf.c --- src/usr.bin/netstat/mbuf.c 2001/06/23 17:04:17 1.26 +++ src/usr.bin/netstat/mbuf.c 2001/07/22 21:45:47 @@ -102,7 +102,7 @@ u_long mblimaddr, u_long cllimaddr, u_long cpusaddr, u_long pgsaddr, u_long mbpaddr) { - int i, nmbufs, nmbclusters, ncpu, page_size, num_objs; + int i, nmbufs, nmbclusters, page_size, num_objs; u_int mbuf_limit, clust_limit; u_long totspace, totnum, totfree; size_t mlen; @@ -180,8 +180,6 @@ goto err; if (kread(cllimaddr, (char *)&clust_limit, sizeof(u_int))) goto err; - if (kread(cpusaddr, (char *)&ncpu, sizeof(int))) - goto err; if (kread(pgsaddr, (char *)&page_size, sizeof(int))) goto err; } else { @@ -228,12 +226,6 @@ goto err; } mlen = sizeof(int); - if (sysctlbyname("kern.smp.cpus", &ncpu, &mlen, NULL, 0) < 0 && - sysctlbyname("hw.ncpu", &ncpu, &mlen, NULL, 0) < 0) { - warn("sysctl: retrieving number of cpus"); - goto err; - } - mlen = sizeof(int); if (sysctlbyname("hw.pagesize", &page_size, &mlen, NULL, 0) < 0) { warn("sysctl: retrieving hw.pagesize"); @@ -259,7 +251,9 @@ totnum = mbpstat[GENLST]->mb_mbpgs * MBPERPG; totfree = mbpstat[GENLST]->mb_mbfree; totspace = mbpstat[GENLST]->mb_mbpgs * page_size; - for (i = 0; i < ncpu; i++) { + for (i = 0; i < (num_objs - 1); i++) { + if (mbpstat[i]->mb_active == 0) + continue; printf("\tCPU #%d list:\t%lu/%lu (in use/in pool)\n", i, (mbpstat[i]->mb_mbpgs * MBPERPG - mbpstat[i]->mb_mbfree), (mbpstat[i]->mb_mbpgs * MBPERPG)); @@ -281,7 +275,9 @@ totnum = mbpstat[GENLST]->mb_clpgs * CLPERPG; totfree = mbpstat[GENLST]->mb_clfree; totspace = mbpstat[GENLST]->mb_clpgs * page_size; - for (i = 0; i < ncpu; i++) { + for (i = 0; i < (num_objs - 1); i++) { + if (mbpstat[i]->mb_active == 0) + continue; printf("\tCPU #%d list:\t%lu/%lu (in use/in pool)\n", i, (mbpstat[i]->mb_clpgs * CLPERPG - mbpstat[i]->mb_clfree), (mbpstat[i]->mb_clpgs * CLPERPG)); Index: src/usr.bin/systat/mbufs.c =================================================================== RCS file: /home/ncvs/src/usr.bin/systat/mbufs.c,v retrieving revision 1.13 diff -u -r1.13 mbufs.c --- src/usr.bin/systat/mbufs.c 2001/06/23 17:03:27 1.13 +++ src/usr.bin/systat/mbufs.c 2001/07/22 21:45:59 @@ -50,7 +50,7 @@ #include "extern.h" static struct mbpstat **mbpstat; -static int num_objs, ncpu; +static int num_objs; #define GENLST (num_objs - 1) /* XXX: mbtypes stats temporarily disabled. */ @@ -150,8 +150,11 @@ * Print total number of free mbufs. */ totfree = mbpstat[GENLST]->mb_mbfree; - for (i = 0; i < ncpu; i++) + for (i = 0; i < (num_objs - 1); i++) { + if (mbpstat[i]->mb_active == 0) + continue; totfree += mbpstat[i]->mb_mbfree; + } j = 0; /* XXX */ if (totfree > 0) { mvwprintw(wnd, 1+j, 0, "%-10.10s", "free"); @@ -189,12 +192,6 @@ } nmbtypes = mbtypeslen / sizeof(*m_mbtypes); #endif - len = sizeof(int); - if (sysctlbyname("kern.smp.cpus", &ncpu, &len, NULL, 0) < 0 && - sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0) < 0) { - error("sysctl getting number of cpus"); - return 0; - } if (sysctlbyname("kern.ipc.mb_statpcpu", NULL, &len, NULL, 0) < 0) { error("sysctl getting mbpstat total size failed"); return 0;