Port-sparc64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: SMP support for sparc64



>>> jnemeth%victoria.tc.ca@localhost (John Nemeth) wrote

>      Would it be possible to get a patch relative to your previous
> patch?

Attached is a relative diffs.

Thanks,

Takeshi Nakayama
diff -ur 20080312/include/cpu.h 20080313/include/cpu.h
--- 20080312/include/cpu.h      2008-03-14 11:59:00.000000000 +0900
+++ 20080313/include/cpu.h      2008-03-14 12:00:54.000000000 +0900
@@ -328,7 +328,7 @@
 int    tickintr(void *);       /* level 10 (tick) interrupt code */
 int    clockintr(void *);      /* level 10 (clock) interrupt code */
 int    statintr(void *);       /* level 14 (statclock) interrupt code */
-void   tickintr_establish(void);
+void   tickintr_establish(int, int (*)(void *));
 /* locore.s */
 struct fpstate64;
 void   savefpstate(struct fpstate64 *);
diff -ur 20080312/sparc64/clock.c 20080313/sparc64/clock.c
--- 20080312/sparc64/clock.c    2008-03-14 11:59:00.000000000 +0900
+++ 20080313/sparc64/clock.c    2008-03-14 12:00:54.000000000 +0900
@@ -111,8 +111,8 @@
 
 int schedintr(void *);
 
-#ifndef MULTIPROCESSOR
 static struct intrhand level10 = { .ih_fun = clockintr };
+#ifndef MULTIPROCESSOR
 static struct intrhand level14 = { .ih_fun = statintr };
 #endif
 static struct intrhand schedint = { .ih_fun = schedintr };
@@ -180,7 +180,7 @@
 static u_int
 counter_get_timecount(struct timecounter *tc)
 {
-       return (u_int)ldxa((vaddr_t)&timerreg_4u.t_timer[0].t_count,
+       return (u_int)ldxa((vaddr_t)&timerreg_4u.t_timer[1].t_count,
                           ASI_NUCLEUS) & TMR_LIM_MASK;
 }
 #endif
@@ -216,21 +216,25 @@
        timerreg_4u.t_clrintr = (int64_t *)(u_long)va[1];
        timerreg_4u.t_mapintr = (int64_t *)(u_long)va[2];
 
-       /*
-        * On SMP kernel, don't enable interrupts to use it as timecounter.
-        */
-#ifndef MULTIPROCESSOR
+       /* Disable interrupts for now. */
+       stxa((vaddr_t)&timerreg_4u.t_timer[0].t_limit, ASI_NUCLEUS,
+            TMR_LIM_MASK);
+       stxa((vaddr_t)&timerreg_4u.t_timer[1].t_limit, ASI_NUCLEUS,
+            TMR_LIM_MASK);
+
        /* Install the appropriate interrupt vector here */
        level10.ih_number = ma->ma_interrupts[0];
        level10.ih_clr = &timerreg_4u.t_clrintr[0];
        intr_establish(10, &level10);
+       printf(" irq vectors %lx", (u_long)level10.ih_number);
+#ifndef MULTIPROCESSOR
+       /*
+        * On SMP kernel, don't enable interrupt to use it as timecounter.
+        */
        level14.ih_number = ma->ma_interrupts[1];
        level14.ih_clr = &timerreg_4u.t_clrintr[1];
-
        intr_establish(14, &level14);
-       printf(" irq vectors %lx and %lx", 
-              (u_long)level10.ih_number, 
-              (u_long)level14.ih_number);
+       printf(" and %lx", (u_long)level14.ih_number);
 #endif
 
 #if 0
@@ -294,7 +298,7 @@
  * but the shortcut during dispatch makes it work.
  */
 void
-tickintr_establish()
+tickintr_establish(int pil, int (*fun)(void *))
 {
        int s;
        struct intrhand *ih;
@@ -302,14 +306,14 @@
        ih = malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT|M_ZERO);
        KASSERT(ih != NULL);
 
-       ih->ih_fun = tickintr;
+       ih->ih_fun = fun;
        ih->ih_arg = 0;
        ih->ih_clr = 0;
        ih->ih_number = 1;
        if (CPU_IS_PRIMARY(curcpu()))
-               intr_establish(10, ih);
+               intr_establish(pil, ih);
        else {
-               ih->ih_pil = 10;
+               ih->ih_pil = pil;
                ih->ih_pending = 0;
                ih->ih_next = NULL;
        }
@@ -335,9 +339,7 @@
 void
 cpu_initclocks()
 {
-#ifndef MULTIPROCESSOR
        int statint, minint;
-#endif
        uint64_t start_time = 0;
 #ifdef DEBUG
        extern int intrdebug;
@@ -391,7 +393,7 @@
                        (unsigned long)curcpu()->ci_cpu_clockrate[1]);
 
                /* We don't have a counter-timer -- use %tick */
-               tickintr_establish();
+               tickintr_establish(10, tickintr);
 
                /* We only have one timer so we have no statclock */
                stathz = 0;
@@ -399,24 +401,6 @@
                return;
        }
 
-#ifdef MULTIPROCESSOR
-       /*
-        * Use %tick interrupt instead of counter-timer on SMP kernel.
-        */
-       printf("SMP kernel -- using %%tick at %luMHz as system clock.\n",
-              (unsigned long)curcpu()->ci_cpu_clockrate[1]);
-       tickintr_establish();
-       stathz = 0;
-
-       /*
-        * Use counter-timer as timecounter.
-        */
-       stxa((vaddr_t)&timerreg_4u.t_timer[0].t_limit, ASI_NUCLEUS,
-            TMR_LIM_MASK);
-       stxa((vaddr_t)&timerreg_4u.t_timer[1].t_limit, ASI_NUCLEUS, 
-            TMR_LIM_MASK);
-       tc_init(&counter_timecounter);
-#else
        if (stathz == 0)
                stathz = hz;
        if (1000000 % stathz) {
@@ -426,7 +410,11 @@
 
        profhz = stathz;                /* always */
 
+#ifdef MULTIPROCESSOR
+       statint = curcpu()->ci_cpu_clockrate[0] / stathz;
+#else
        statint = 1000000 / stathz;
+#endif
        minint = statint / 2 + 100;
        while (statvar > minint)
                statvar >>= 1;
@@ -449,8 +437,23 @@
        stxa((vaddr_t)&timerreg_4u.t_timer[0].t_limit, ASI_NUCLEUS,
             tmr_ustolim(tick)|TMR_LIM_IEN|TMR_LIM_PERIODIC|TMR_LIM_RELOAD); 
        stxa((vaddr_t)&timerreg_4u.t_mapintr[0], ASI_NUCLEUS, 
-            timerreg_4u.t_mapintr[0]|INTMAP_V|(CPU_UPAID << 
INTMAP_TID_SHIFT)); 
+            timerreg_4u.t_mapintr[0]|INTMAP_V|(CPU_UPAID<<INTMAP_TID_SHIFT));
 
+#ifdef MULTIPROCESSOR
+       /*
+        * Disable counter-timer1 interrupt and use it as timecounter.
+        */
+       stxa((vaddr_t)&timerreg_4u.t_timer[1].t_limit, ASI_NUCLEUS,
+            TMR_LIM_MASK);
+       stxa((vaddr_t)&timerreg_4u.t_mapintr[1], ASI_NUCLEUS,
+            timerreg_4u.t_mapintr[1]|INTMAP_V|(CPU_UPAID<<INTMAP_TID_SHIFT));
+       tc_init(&counter_timecounter);
+
+       /*
+        * Enable tick interrupt for statintr.
+        */
+       tickintr_establish(14, statintr);
+#else
 #ifdef DEBUG
        if (intrdebug)
                /* Neglect to enable timer */
@@ -462,9 +465,9 @@
                     tmr_ustolim(statint)|TMR_LIM_IEN|TMR_LIM_RELOAD); 
        stxa((vaddr_t)&timerreg_4u.t_mapintr[1], ASI_NUCLEUS, 
             timerreg_4u.t_mapintr[1]|INTMAP_V|(CPU_UPAID << INTMAP_TID_SHIFT));
+#endif
 
        statmin = statint - (statvar >> 1);
-#endif
 }
 
 /*
@@ -550,6 +553,9 @@
 {
        register u_long newint, r, var;
        struct cpu_info *ci = curcpu();
+#ifdef MULTIPROCESSOR
+       int s;
+#endif
 
 #ifdef NOT_DEBUG
        printf("statclock: count %x:%x, limit %x:%x\n", 
@@ -577,8 +583,15 @@
        if (schedhz)
                if ((++ci->ci_schedstate.spc_schedticks & 3) == 0)
                        send_softint(-1, PIL_SCHED, &schedint);
+#ifdef MULTIPROCESSOR
+       s = intr_disable();
+       next_tick(newint);
+       intr_restore(s);
+       curcpu()->ci_tick_evcnt.ev_count++;
+#else
        stxa((vaddr_t)&timerreg_4u.t_timer[1].t_limit, ASI_NUCLEUS, 
             tmr_ustolim(newint)|TMR_LIM_IEN|TMR_LIM_RELOAD);
+#endif
        return (1);
 }
 
diff -ur 20080312/sparc64/cpu.c 20080313/sparc64/cpu.c
--- 20080312/sparc64/cpu.c      2008-03-14 11:59:00.000000000 +0900
+++ 20080313/sparc64/cpu.c      2008-03-14 12:00:54.000000000 +0900
@@ -420,7 +420,7 @@
        cpu_reset_fpustate();
        curlwp = curcpu()->ci_data.cpu_idlelwp;
        membar_sync();
-       tickintr_establish();
+       tickintr_establish(14, statintr);
        spl0();
 }
 #endif /* MULTIPROCESSOR */
diff -ur 20080312/sparc64/ipifuncs.c 20080313/sparc64/ipifuncs.c
--- 20080312/sparc64/ipifuncs.c 2008-03-14 11:59:00.000000000 +0900
+++ 20080313/sparc64/ipifuncs.c 2008-03-14 12:00:54.000000000 +0900
@@ -89,6 +89,8 @@
 
        printf("cpu%d: shutting down\n", cpu_number());
        CPUSET_ADD(cpus_halted, cpu_number());
+       if (CPU_IS_PRIMARY(curcpu()))
+               DELAY(1000000);         /* XXX - wait for interrupter's halt */
        prom_stopself();
 
        return(1);
diff -ur 20080312/sparc64/locore.s 20080313/sparc64/locore.s
--- 20080312/sparc64/locore.s   2008-03-14 11:59:00.000000000 +0900
+++ 20080313/sparc64/locore.s   2008-03-14 12:00:54.000000000 +0900
@@ -5388,7 +5388,8 @@
        flushw                                  ! Flush register windows
 
        wrpr    %g0, PIL_HIGH, %pil             ! Disable interrupts
-       set     romtba, %l5
+       sethi   %hi(romtba), %l5
+       LDPTR   [%l5 + %lo(romtba)], %l5
        wrpr    %l5, 0, %tba                    ! restore the ofw trap table
 
        /* Arrange locked kernel stack as PROM stack */
@@ -5401,8 +5402,8 @@
        mov     %l5, %sp
        flushw
 
-       set     romp, %l6
-       LDPTR   [%l6], %l6
+       sethi   %hi(romp), %l6
+       LDPTR   [%l6 + %lo(romp)], %l6
 
        mov     CTX_PRIMARY, %l3                ! set context 0
        stxa    %g0, [%l3] ASI_DMMU
@@ -9637,10 +9638,9 @@
        or      %g1, PSTATE_PEF, %g1
        wrpr    %g1, 0, %pstate
        sethi   %hi(FPLWP), %g1
-       STPTR   %g0, [%g1 + %lo(FPLWP)] ! fplwp = NULL
        IPIEVC_INC(IPI_EVCNT_FPU_FLUSH,%g2,%g3)
-       ba,a    ret_from_intr_vector
-        nop
+       ba      ret_from_intr_vector
+        STPTR  %g0, [%g1 + %lo(FPLWP)] ! fplwp = NULL
 #endif
 
 /*
diff -ur 20080312/sparc64/machdep.c 20080313/sparc64/machdep.c
--- 20080312/sparc64/machdep.c  2008-03-14 11:59:00.000000000 +0900
+++ 20080313/sparc64/machdep.c  2008-03-14 12:00:54.000000000 +0900
@@ -591,11 +591,6 @@
        }
        (void) splhigh();               /* ??? */
 
-#if defined(MULTIPROCESSOR)
-       /* Stop all secondary cpus */
-       mp_halt_cpus();
-#endif
-
        /* If rebooting and a dump is requested, do it. */
        if (howto & RB_DUMP)
                dumpsys();
@@ -604,6 +599,11 @@
        /* Run any shutdown hooks. */
        doshutdownhooks();
 
+#ifdef MULTIPROCESSOR
+       /* Stop all secondary cpus */
+       mp_halt_cpus();
+#endif
+
        /* If powerdown was requested, do it. */
        if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
                /* Let the OBP do the work. */
@@ -615,12 +615,20 @@
        }
 
        if (howto & RB_HALT) {
+#ifdef MULTIPROCESSOR
+               printf("cpu%d: halted\n\n", cpu_number());
+#else
                printf("halted\n\n");
+#endif
                OF_exit();
                panic("PROM exit failed");
        }
 
+#ifdef MULTIPROCESSOR
+       printf("cpu%d: rebooting\n\n", cpu_number());
+#else
        printf("rebooting\n\n");
+#endif
        if (user_boot_string && *user_boot_string) {
                i = strlen(user_boot_string);
                if (i > sizeof(str))


Home | Main Index | Thread Index | Old Index