PERFORCE change 137814 for review

Marcel Moolenaar marcel at FreeBSD.org
Sun Mar 16 00:00:40 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=137814

Change 137814 by marcel at marcel_xcllnt on 2008/03/15 23:59:52

	Handle decrementer.
	Handle openpic.
	call sched_throw().

Affected files ...

.. //depot/projects/powerpc/sys/powerpc/aim/clock.c#2 edit
.. //depot/projects/powerpc/sys/powerpc/aim/mp_cpudep.c#5 edit
.. //depot/projects/powerpc/sys/powerpc/include/pcpu.h#12 edit
.. //depot/projects/powerpc/sys/powerpc/powerpc/mp_machdep.c#20 edit
.. //depot/projects/powerpc/sys/powerpc/powerpc/openpic.c#9 edit

Differences ...

==== //depot/projects/powerpc/sys/powerpc/aim/clock.c#2 (text+ko) ====

@@ -61,11 +61,12 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
-#include <sys/sysctl.h>
 #include <sys/bus.h>
 #include <sys/clock.h>
+#include <sys/interrupt.h>
+#include <sys/pcpu.h>
+#include <sys/sysctl.h>
 #include <sys/timetc.h>
-#include <sys/interrupt.h>
 
 #include <dev/ofw/openfirm.h>
 
@@ -77,11 +78,9 @@
 /*
  * Initially we assume a processor with a bus frequency of 12.5 MHz.
  */
-u_int			tickspending;
 u_long			ns_per_tick = 80;
 static u_long		ticks_per_sec = 12500000;
 static long		ticks_per_intr;
-static volatile u_long	lasttb;
 
 #define	DIFF19041970	2082844800
 
@@ -164,7 +163,6 @@
 void
 decr_intr(struct trapframe *frame)
 {
-	u_long		tb;
 	long		tick;
 	int		nticks;
 
@@ -178,36 +176,17 @@
 	 * Based on the actual time delay since the last decrementer reload,
 	 * we arrange for earlier interrupt next time.
 	 */
-	__asm ("mftb %0; mfdec %1" : "=r"(tb), "=r"(tick));
+	__asm ("mfdec %0" : "=r"(tick));
 	for (nticks = 0; tick < 0; nticks++)
 		tick += ticks_per_intr;
 	mtdec(tick);
-	/*
-	 * lasttb is used during microtime. Set it to the virtual
-	 * start of this tick interval.
-	 */
-	lasttb = tb + tick - ticks_per_intr;
 
-	nticks += tickspending;
-	tickspending = 0;
-
-	/*
-	 * Reenable interrupts
-	 */
-#if 0
-	msr = mfmsr();
-	mtmsr(msr | PSL_EE | PSL_RI);
-#endif
-	/*
-	 * Do standard timer interrupt stuff.
-	 * Do softclock stuff only on the last iteration.
-	 */
-#if 0
-	while (--nticks > 0) {
-		hardclock(TRAPF_USERMODE(frame), TRAPF_PC(frame));
+	while (nticks-- > 0) {
+		if (PCPU_GET(cpuid) == 0)
+			hardclock(TRAPF_USERMODE(frame), TRAPF_PC(frame));
+		else
+			hardclock_cpu(TRAPF_USERMODE(frame));
 	}
-#endif
-	hardclock(TRAPF_USERMODE(frame), TRAPF_PC(frame));
 }
 
 void
@@ -235,7 +214,6 @@
 
 			ns_per_tick = 1000000000 / ticks_per_sec;
 			ticks_per_intr = ticks_per_sec / hz;
-			__asm __volatile ("mftb %0" : "=r"(lasttb));
 			mtdec(ticks_per_intr);
 
 			mtmsr(msr);

==== //depot/projects/powerpc/sys/powerpc/aim/mp_cpudep.c#5 (text+ko) ====

@@ -135,18 +135,6 @@
 	return (powerpc_smp_fill_cpuref(cpuref, bsp));
 }
 
-#if 0
-static void
-dump_rstvec(void)
-{
-	uint32_t buf[6];
-
-	bcopy((void *)EXC_RST, buf, sizeof(buf));
-	printf("XXX: %08x %08x %08x %08x %08x %08x\n", buf[0], buf[1], buf[2],
-	    buf[3], buf[4], buf[5]);
-}
-#endif
-
 uint32_t
 cpudep_ap_bootstrap(volatile uint32_t *trcp)
 {

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

@@ -41,6 +41,7 @@
 	struct pmap	*pc_curpmap;		/* current pmap */	\
 	struct thread	*pc_fputhread;		/* current fpu user */  \
 	uintptr_t	pc_hwref;					\
+	uint32_t	pc_pir;						\
 	int		pc_bsp:1;					\
 	int		pc_awake:1;					\
 	uint32_t	pc_ipimask;					\

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

@@ -33,6 +33,8 @@
 #include <sys/bus.h>
 #include <sys/malloc.h>
 #include <sys/pcpu.h>
+#include <sys/proc.h>
+#include <sys/sched.h>
 #include <sys/smp.h>
 
 #include <machine/bus.h>
@@ -45,7 +47,8 @@
 MALLOC_DEFINE(M_SMP, "smp", "SMP specific datastructures");
 
 volatile static int ap_awake;
-volatile static int ap_spin;
+volatile static u_int ap_state;
+volatile static uint32_t ap_decr;
 
 int mp_ipi_test = 0;
 
@@ -56,14 +59,19 @@
 	trcp[0] = 0x3000;
 	trcp[1] = (uint32_t)&machdep_ap_bootstrap;
 
+	__asm __volatile("mtspr 1023,%0" :: "r"(PCPU_GET(cpuid)));
+	__asm __volatile("mfspr %0,1023" : "=r"(pcpup->pc_pir));
 	pcpup->pc_awake = 1;
 
-	while (ap_spin)
-		DELAY(0);
+	while (ap_state == 0)
+		;
+
+	__asm __volatile("mtdec %0" :: "r"(ap_decr));
 
 	ap_awake++;
 
-	while (1);
+	mtmsr(mfmsr() | PSL_EE | PSL_RI);
+	sched_throw(NULL);
 }
 
 struct cpu_group *
@@ -135,10 +143,12 @@
 			pcpu_init(pc, cpu.cr_cpuid, sizeof(*pc));
 		} else {
 			pc = pcpup;
+			pc->pc_cpuid = bsp.cr_cpuid;
 			pc->pc_bsp = 1;
 		}
+		pc->pc_cpumask = 1 << pc->pc_cpuid;
 		pc->pc_hwref = cpu.cr_hwref;
-		all_cpus |= 1 << cpu.cr_cpuid;
+		all_cpus |= pc->pc_cpumask;
 
  next:
 		error = powerpc_smp_next_cpu(&cpu);
@@ -176,28 +186,29 @@
 		return;
 	}
 
-	ap_spin = 1;
-
 	cpus = 0;
 	smp_cpus = 0;
 	SLIST_FOREACH(pc, &cpuhead, pc_allcpu) {
 		cpus++;
+		pc->pc_other_cpus = all_cpus & ~pc->pc_cpumask;
 		if (!pc->pc_bsp) {
 			printf("Waking up CPU %d (dev=%x)\n", pc->pc_cpuid,
 			    pc->pc_hwref);
 			powerpc_smp_start_cpu(pc);
-		} else
+		} else {
+			__asm __volatile("mfspr %0,1023" : "=r"(pc->pc_pir));
 			pc->pc_awake = 1;
-
+		}
 		if (pc->pc_awake)
 			smp_cpus++;
 	}
 
 	ap_awake = 1;
-	ap_spin = 0;
+	__asm __volatile("mfdec %0" : "=r"(ap_decr));
+	ap_state++;
 
 	while (ap_awake < smp_cpus)
-		DELAY(0);
+		;
 
 	if (smp_cpus != cpus || cpus != mp_ncpus) {
 		printf("SMP: %d CPUs found; %d CPUs usable; %d CPUs woken\n",
@@ -229,7 +240,7 @@
 		case IPI_AST:
 			break;
 		case IPI_PREEMPT:
-			/* TBD */
+			sched_preempt(curthread);
 			break;
 		case IPI_RENDEZVOUS:
 			smp_rendezvous_action();

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

@@ -82,7 +82,7 @@
 openpic_attach(device_t dev)
 {
 	struct openpic_softc *sc;
-	u_int     ipi, irq;
+	u_int     cpu, ipi, irq;
 	u_int32_t x;
 
 	sc = device_get_softc(dev);
@@ -132,6 +132,11 @@
 		    "Version %s, supports %d CPUs and %d irqs\n",
 		    sc->sc_version, sc->sc_ncpu, sc->sc_nirq);
 
+	for (cpu = 0; cpu < sc->sc_ncpu; cpu++) {
+		openpic_write(sc, OPENPIC_PCPU_TPR(cpu), 0);
+		openpic_write(sc, OPENPIC_PCPU_WHOAMI(cpu), cpu);
+	}
+
 	/* Reset and disable all interrupts. */
 	for (irq = 0; irq < sc->sc_nirq; irq++) {
 		x = irq;                /* irq == vector. */
@@ -150,8 +155,6 @@
 		openpic_write(sc, OPENPIC_IPI_VECTOR(ipi), x);
 	}
 
-	openpic_set_priority(sc, 15);
-
 	/* we don't need 8259 passthrough mode */
 	x = openpic_read(sc, OPENPIC_CONFIG);
 	x |= OPENPIC_CONFIG_8259_PASSTHRU_DISABLE;
@@ -161,9 +164,10 @@
 	for (irq = 0; irq < sc->sc_nirq; irq++)
 		openpic_write(sc, OPENPIC_IDEST(irq), 1 << 0);
 
-	/* XXX set spurious intr vector */
-
-	openpic_set_priority(sc, 0);
+	for (cpu = 0; cpu < sc->sc_ncpu; cpu++) {
+		openpic_write(sc, OPENPIC_PCPU_TPR(cpu), 0);
+		openpic_write(sc, OPENPIC_PCPU_WHOAMI(cpu), cpu);
+	}
 
 	/* clear all pending interrupts */
 	for (irq = 0; irq < sc->sc_nirq; irq++) {


More information about the p4-projects mailing list