Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Apr 2007 21:52:17 GMT
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 117140 for review
Message-ID:  <200704012152.l31LqHuB022635@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=117140

Change 117140 by marcel@marcel_xcllnt on 2007/04/01 21:52:12

	Create PCPU structures for all CPUs. Reduce dependency
	on MAXCPU by allocating PCPU structures on demand.

Affected files ...

.. //depot/projects/powerpc/sys/powerpc/include/pcpu.h#6 edit
.. //depot/projects/powerpc/sys/powerpc/powerpc/machdep.c#8 edit
.. //depot/projects/powerpc/sys/powerpc/powerpc/mp_machdep.c#9 edit
.. //depot/projects/powerpc/sys/powerpc/powerpc/ofw_machdep.c#7 edit

Differences ...

==== //depot/projects/powerpc/sys/powerpc/include/pcpu.h#6 (text+ko) ====

@@ -40,6 +40,7 @@
 	int		pc_inside_intr;					\
 	struct pmap	*pc_curpmap;		/* current pmap */	\
 	struct thread   *pc_fputhread;          /* current fpu user */  \
+	int		pc_bsp:1;					\
 	int		pc_awake:1;					\
 	register_t	pc_tempsave[CPUSAVE_LEN];			\
 	register_t	pc_disisave[CPUSAVE_LEN];			\

==== //depot/projects/powerpc/sys/powerpc/powerpc/machdep.c#8 (text+ko) ====

@@ -127,8 +127,8 @@
 
 int cold = 1;
 
-struct		pcpu __pcpu[MAXCPU];
-struct		trapframe frame0;
+static struct pcpu pcpu0;
+static struct trapframe frame0;
 
 vm_offset_t	kstack0;
 vm_offset_t	kstack0_phys;
@@ -290,7 +290,7 @@
 	/*
 	 * Set up per-cpu data.
 	 */
-	pc = &__pcpu[0];
+	pc = &pcpu0;
 	pcpu_init(pc, 0, sizeof(struct pcpu));
 	pc->pc_curthread = &thread0;
 	pc->pc_curpcb = thread0.td_pcb;

==== //depot/projects/powerpc/sys/powerpc/powerpc/mp_machdep.c#9 (text+ko) ====

@@ -37,6 +37,8 @@
 
 #include <dev/ofw/openfirm.h>
 
+MALLOC_DEFINE(M_SMP, "smp", "SMP specific datastructures");
+
 volatile static int ap_awake;
 volatile static int ap_spin;
 
@@ -45,9 +47,9 @@
 void
 cpu_mp_setmaxid(void)
 {
+	char buf[8];
 	phandle_t dev, root;
 	int res;
-	char buf[8];
 
 	mp_ncpus = 0;
 
@@ -93,6 +95,57 @@
 void
 cpu_mp_start(void)
 {
+	char buf[8];
+	struct pcpu *pc;
+	ihandle_t inst;
+	phandle_t bsp, chosen, dev, root;
+	int cpuid, res;
+
+	/* Get the p-handle of the BSP. */
+	chosen = OF_finddevice("/chosen");
+	if (chosen != -1) {
+		res = OF_getprop(chosen, "cpu", &inst, sizeof(inst));
+		bsp = (res > 0) ? OF_instance_to_package(inst) : -1;
+	} else
+		bsp = -1;
+
+	root = OF_peer(0);
+	dev = OF_child(root);
+	while (dev != 0) {
+		res = OF_getprop(dev, "name", buf, sizeof(buf));
+		if (res > 0 && !strcmp(buf, "cpus"))
+			break;
+		dev = OF_peer(dev);
+	}
+	KASSERT(dev != 0, ("%s: dev == 0", __func__));
+	for (dev = OF_child(dev); dev != 0; dev = OF_peer(dev)) {
+		res = OF_getprop(dev, "device_type", buf, sizeof(buf));
+		if (res < 0 || strcmp(buf, "cpu") != 0)
+			continue;
+		res = OF_getprop(dev, "reg", &cpuid, sizeof(cpuid));
+		if (res < 0)
+			continue;
+		cpuid &= 0xff;
+		if (cpuid >= MAXCPU) {
+			printf("SMP: cpu%d: skipped -- ID out of range\n",
+			    cpuid);
+			continue;
+		}
+		if (all_cpus & (1 << cpuid)) {
+			printf("SMP: cpu%d: skipped - duplicate ID\n", cpuid);
+			continue;
+		}
+		if (dev != bsp) {
+			pc = (struct pcpu *)malloc(sizeof(*pc), M_SMP,
+			    M_WAITOK);
+			pcpu_init(pc, cpuid, sizeof(*pc));
+		} else {
+			KASSERT(cpuid == 0, ("%s: cpuid != 0", __func__));
+			pc = pcpup;
+			pc->pc_bsp = 1;
+		}
+		all_cpus |= 1 << cpuid;
+	}
 }
 
 void
@@ -106,7 +159,7 @@
 		if (pc == NULL)
 			continue;
 		printf("cpu%d", i);
-		if (i == 0)
+		if (pc->pc_bsp)
 			printf(" (BSP)");
 		printf("\n");
 	}
@@ -152,6 +205,9 @@
 static void
 ipi_send(struct pcpu *pc, int ipi)
 {
+	/*
+	 *
+	 */
 }
 
 /* Send an IPI to a set of cpus. */

==== //depot/projects/powerpc/sys/powerpc/powerpc/ofw_machdep.c#7 (text+ko) ====

@@ -63,7 +63,6 @@
 static struct mem_region OFfree[OFMEM_REGIONS + 3];
 
 extern register_t ofmsr[5];
-extern struct   pcpu __pcpu[MAXCPU];
 extern struct	pmap ofw_pmap;
 static int	(*ofwcall)(void *);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704012152.l31LqHuB022635>