Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Jul 2001 11:25:46 -0700 (PDT)
From:      Matthew Jacob <mjacob@feral.com>
To:        smp@freebsd.org, audit@freebsd.org
Subject:   planned change to mbinit code and minor changes to mp startup
Message-ID:  <Pine.BSF.4.21.0107141117110.87022-100000@beppo>
In-Reply-To: <Pine.BSF.4.21.0107130000220.61694-100000@beppo>

next in thread | previous in thread | raw e-mail | index | archive | help

Problem: the MB init and alloc code assumes that in the SMP case that there is
a dense array of CPU ids for the CPUs present and reported via mp_ncpus.

This is not true and cannot be true for a number of reasons:

a) CPUids don't always start at 0 (e.g, Alpha 8200)
b) CPUs may be disabled, leaving holes in the map.
c) CPUs may (eventually) want to come and go while we're running.

I thought about making cpuid a 'virtual' construct. We may eventually want to
do this, but this only solves #a/#b- it will not move us toward #c. And it can
get somewhat dicey for the amount of code to check and change by doing this.

Below is a partial solution that takes the approach of just checking who is
'absent' when mbinit is called. It requires that all_cpus be set sensibly
whether there are more than one cpu or not (which makes sense too).

Making this change allows the ALpha 8200s to work again and also allows
disabling arbitrary CPUs leaving holes in the CPU map to work without getting
out of sync.

-matt


Index: kern/subr_mbuf.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/subr_mbuf.c,v
retrieving revision 1.2
diff -u -r1.2 subr_mbuf.c
--- kern/subr_mbuf.c	2001/06/22 16:03:23	1.2
+++ kern/subr_mbuf.c	2001/07/14 18:14:30
@@ -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,11 @@
 #endif
 
 /*
- * SMP and non-SMP kernels clearly have a different number of possible cpus.
  */
 #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 +392,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),
@@ -626,7 +633,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: 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
--- powerpc/powerpc/mp_machdep.c	2001/06/16 07:14:07	1.8
+++ powerpc/powerpc/mp_machdep.c	2001/07/14 18:15:14
@@ -51,6 +51,7 @@
 int
 cpu_mp_probe(void)
 {
+	all_cpus = 1;	/* needed for MB init code */
 	return 0;
 }
 
Index: 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
--- ia64/ia64/mp_machdep.c	2001/05/15 23:22:24	1.17
+++ ia64/ia64/mp_machdep.c	2001/07/14 18:15:14
@@ -71,6 +71,7 @@
 int
 cpu_mp_probe()
 {
+	all_cpus = 1;	/* Needed for MB init code */
 	return (0);
 }
 
Index: 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
--- i386/i386/mp_machdep.c	2001/07/12 06:32:50	1.160
+++ i386/i386/mp_machdep.c	2001/07/14 18:15:15
@@ -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: alpha/alpha/mp_machdep.c
===================================================================
RCS file: /home/ncvs/src/sys/alpha/alpha/mp_machdep.c,v
retrieving revision 1.22
diff -u -r1.22 mp_machdep.c
--- alpha/alpha/mp_machdep.c	2001/06/29 11:10:25	1.22
+++ alpha/alpha/mp_machdep.c	2001/07/14 18:15:47
@@ -301,6 +303,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,17 +331,14 @@
 }
 
 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;
 
 		if (i == boot_cpu_id)



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0107141117110.87022-100000>