From owner-p4-projects@FreeBSD.ORG Thu Apr 17 00:48:45 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 4B02310656C9; Thu, 17 Apr 2008 00:48:45 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B82C10656C3 for ; Thu, 17 Apr 2008 00:48:45 +0000 (UTC) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id EC3D28FC1B for ; Thu, 17 Apr 2008 00:48:44 +0000 (UTC) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m3H0mitc002625 for ; Thu, 17 Apr 2008 00:48:44 GMT (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m3H0miGF002623 for perforce@freebsd.org; Thu, 17 Apr 2008 00:48:44 GMT (envelope-from marcel@freebsd.org) Date: Thu, 17 Apr 2008 00:48:44 GMT Message-Id: <200804170048.m3H0miGF002623@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Cc: Subject: PERFORCE change 140142 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Apr 2008 00:48:45 -0000 http://perforce.freebsd.org/chv.cgi?CH=140142 Change 140142 by marcel@marcel_xcllnt on 2008/04/17 00:48:08 Make SMP go all the way into the scheduler. Affected files ... .. //depot/projects/powerpc/sys/powerpc/aim/machdep.c#9 edit .. //depot/projects/powerpc/sys/powerpc/aim/mp_cpudep.c#6 edit .. //depot/projects/powerpc/sys/powerpc/aim/swtch.S#4 edit .. //depot/projects/powerpc/sys/powerpc/aim/vm_machdep.c#5 edit .. //depot/projects/powerpc/sys/powerpc/conf/XSERVE#8 edit .. //depot/projects/powerpc/sys/powerpc/powerpc/mp_machdep.c#21 edit .. //depot/projects/powerpc/sys/powerpc/powerpc/openpic.c#10 edit Differences ... ==== //depot/projects/powerpc/sys/powerpc/aim/machdep.c#9 (text+ko) ==== @@ -55,7 +55,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/powerpc/aim/machdep.c,v 1.111 2008/03/16 10:58:08 rwatson Exp $"); +__FBSDID("$FreeBSD: src/sys/powerpc/aim/machdep.c,v 1.112 2008/04/16 23:28:12 marcel Exp $"); #include "opt_compat.h" #include "opt_ddb.h" @@ -130,12 +130,10 @@ int cold = 1; -static struct pcpu pcpu0; +struct pcpu __pcpu[MAXCPU]; + static struct trapframe frame0; -vm_offset_t kstack0; -vm_offset_t kstack0_phys; - char machine[] = "powerpc"; SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, ""); @@ -146,7 +144,7 @@ static void cpu_startup(void *); SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL); -void powerpc_init(u_int, u_int, u_int, void *); +u_int powerpc_init(u_int, u_int, u_int, void *); int save_ofw_mapping(void); int restore_ofw_mapping(void); @@ -250,11 +248,11 @@ extern void *dblow, *dbsize; extern void *vectrap, *vectrapsize; -void +u_int powerpc_init(u_int startkernel, u_int endkernel, u_int basekernel, void *mdp) { struct pcpu *pc; - vm_offset_t end, off; + vm_offset_t end; void *kmdp; char *env; @@ -294,10 +292,9 @@ /* * Set up per-cpu data. */ - pc = &pcpu0; + pc = __pcpu; pcpu_init(pc, 0, sizeof(struct pcpu)); pc->pc_curthread = &thread0; - pc->pc_curpcb = thread0.td_pcb; pc->pc_cpuid = 0; __asm __volatile("mtsprg 0, %0" :: "r"(pc)); @@ -380,15 +377,12 @@ /* * Finish setting up thread0. */ - thread0.td_kstack = kstack0; thread0.td_pcb = (struct pcb *) - (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1; + ((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE - + sizeof(struct pcb)) & ~15); + pc->pc_curpcb = thread0.td_pcb; - /* - * Map and initialise the message buffer. - */ - for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) - pmap_kenter((vm_offset_t)msgbufp + off, msgbuf_phys + off); + /* Initialise the message buffer. */ msgbufinit(msgbufp, MSGBUF_SIZE); #ifdef KDB @@ -396,6 +390,8 @@ kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); #endif + + return (((uintptr_t)thread0.td_pcb - 16) & ~15); } void ==== //depot/projects/powerpc/sys/powerpc/aim/mp_cpudep.c#6 (text+ko) ==== @@ -38,9 +38,12 @@ #include #include #include +#include #include #include +#include #include +#include #include #include @@ -138,7 +141,7 @@ uint32_t cpudep_ap_bootstrap(volatile uint32_t *trcp) { - uint32_t sp; + uint32_t hid, msr, sp; trcp[0] = 0x2000; trcp[1] = (uint32_t)&cpudep_ap_bootstrap; @@ -149,17 +152,48 @@ trcp[0] = 0x2001; trcp[1] = (uint32_t)pcpup; - mtmsr(PSL_IR | PSL_DR | PSL_ME); + hid = mfspr(SPR_HID0); + hid &= ~(HID0_ICE | HID0_DCE); + hid &= ~(HID0_DOZE | HID0_NAP | HID0_SLEEP); + mtspr(SPR_HID0, hid); isync(); trcp[0] = 0x2002; - trcp[1] = 0; + trcp[1] = hid; + + mtspr(SPR_HID0, hid | HID0_ICFI | HID0_DCFI); + mtspr(SPR_HID0, hid); + isync(); + + trcp[0] = 0x2003; + trcp[1] = hid; + + hid |= HID0_ICE | HID0_DCE; + mtspr(SPR_HID0, hid); + isync(); + + trcp[0] = 0x2004; + trcp[1] = hid; + + msr = PSL_IR | PSL_DR | PSL_ME; + mtmsr(msr); + isync(); + + trcp[0] = 0x2005; + trcp[1] = msr; + + hid |= HID0_NAP | HID0_DPM; + mtspr(SPR_HID0, hid); + isync(); + + trcp[0] = 0x2006; + trcp[1] = hid; pcpup->pc_curthread = pcpup->pc_idlethread; pcpup->pc_curpcb = pcpup->pc_curthread->td_pcb; sp = pcpup->pc_curpcb->pcb_sp; - trcp[0] = 0x2003; + trcp[0] = 0x2007; trcp[1] = sp; return (sp); ==== //depot/projects/powerpc/sys/powerpc/aim/swtch.S#4 (text+ko) ==== @@ -67,6 +67,13 @@ #include /* + * void cpu_throw(struct thread *old, struct thread *new) + */ +ENTRY(cpu_throw) + mr %r15, %r4 + b cpu_switchin + +/* * void cpu_switch(struct thread *old, * struct thread *new, * struct mutex *mtx); @@ -111,6 +118,7 @@ .L1: bl pmap_deactivate /* Deactivate the current pmap */ +cpu_switchin: mr %r3,%r15 /* Get new thread ptr */ bl pmap_activate /* Activate the new address space */ ==== //depot/projects/powerpc/sys/powerpc/aim/vm_machdep.c#5 (text+ko) ==== @@ -193,15 +193,6 @@ { } -/* Temporary helper */ -void -cpu_throw(struct thread *old, struct thread *new) -{ - - cpu_switch(old, new, old->td_lock); - panic("cpu_throw() didn't"); -} - /* * Reset back to firmware. */ ==== //depot/projects/powerpc/sys/powerpc/conf/XSERVE#8 (text+ko) ==== @@ -5,6 +5,7 @@ makeoptions NO_MODULES=yes options ALT_BREAK_TO_DEBUGGER +options BREAK_TO_DEBUGGER options CD9660 options DDB options FFS ==== //depot/projects/powerpc/sys/powerpc/powerpc/mp_machdep.c#21 (text+ko) ==== @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,7 @@ #include "pic_if.h" -MALLOC_DEFINE(M_SMP, "smp", "SMP specific datastructures"); +extern struct pcpu __pcpu[MAXCPU]; volatile static int ap_awake; volatile static u_int ap_state; @@ -59,7 +58,7 @@ trcp[0] = 0x3000; trcp[1] = (uint32_t)&machdep_ap_bootstrap; - __asm __volatile("mtspr 1023,%0" :: "r"(PCPU_GET(cpuid))); + // __asm __volatile("mtspr 1023,%0" :: "r"(PCPU_GET(cpuid))); __asm __volatile("mfspr %0,1023" : "=r"(pcpup->pc_pir)); pcpup->pc_awake = 1; @@ -70,6 +69,9 @@ ap_awake++; + /* Initialize curthread. */ + PCPU_SET(curthread, PCPU_GET(idlethread)); + mtmsr(mfmsr() | PSL_EE | PSL_RI); sched_throw(NULL); } @@ -138,8 +140,7 @@ goto next; } if (cpu.cr_cpuid != bsp.cr_cpuid) { - pc = (struct pcpu *)malloc(sizeof(*pc), M_SMP, - M_WAITOK); + pc = &__pcpu[cpu.cr_cpuid]; pcpu_init(pc, cpu.cr_cpuid, sizeof(*pc)); } else { pc = pcpup; ==== //depot/projects/powerpc/sys/powerpc/powerpc/openpic.c#10 (text+ko) ==== @@ -132,10 +132,8 @@ "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); - } + for (cpu = 0; cpu < sc->sc_ncpu; cpu++) + openpic_write(sc, OPENPIC_PCPU_TPR(cpu), 15); /* Reset and disable all interrupts. */ for (irq = 0; irq < sc->sc_nirq; irq++) { @@ -164,10 +162,8 @@ for (irq = 0; irq < sc->sc_nirq; irq++) openpic_write(sc, OPENPIC_IDEST(irq), 1 << 0); - for (cpu = 0; cpu < sc->sc_ncpu; cpu++) { + 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++) { @@ -207,15 +203,25 @@ void openpic_dispatch(device_t dev, struct trapframe *tf) { + static int once = 0; struct openpic_softc *sc; u_int vector; + if (once == 0 && PCPU_GET(cpuid) != 0) { + printf("XXX: got interrupt!\n"); + once++; + } + sc = device_get_softc(dev); while (1) { vector = openpic_read(sc, OPENPIC_PCPU_IACK(PCPU_GET(cpuid))); vector &= OPENPIC_VECTOR_MASK; if (vector == 255) break; + if (once == 1 && PCPU_GET(cpuid) != 0) { + printf("XXX: got vector %u\n", vector); + once++; + } powerpc_dispatch_intr(vector, tf); } }