Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/alpha Use SysValue to store curlwp rather than curc...



details:   https://anonhg.NetBSD.org/src/rev/485589dfa156
branches:  trunk
changeset: 938206:485589dfa156
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Sep 04 03:53:12 2020 +0000

description:
Use SysValue to store curlwp rather than curcpu.  curlwp is acceessed
much more frequently, and this makes curlwp preemption-safe.

diffstat:

 sys/arch/alpha/alpha/machdep.c   |  20 +++++++++++---------
 sys/arch/alpha/alpha/multiproc.s |  16 ++++++++--------
 sys/arch/alpha/include/asm.h     |  12 +++++++-----
 sys/arch/alpha/include/cpu.h     |   7 ++++---
 4 files changed, 30 insertions(+), 25 deletions(-)

diffs (149 lines):

diff -r 98f999866017 -r 485589dfa156 sys/arch/alpha/alpha/machdep.c
--- a/sys/arch/alpha/alpha/machdep.c    Fri Sep 04 03:41:49 2020 +0000
+++ b/sys/arch/alpha/alpha/machdep.c    Fri Sep 04 03:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machdep.c,v 1.363 2020/09/03 02:09:09 thorpej Exp $ */
+/* $NetBSD: machdep.c,v 1.364 2020/09/04 03:53:12 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2019 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>                 /* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.363 2020/09/03 02:09:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.364 2020/09/04 03:53:12 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -253,18 +253,20 @@
 
        cpu_id = cpu_number();
 
+       ci = &cpu_info_primary;
+       ci->ci_cpuid = cpu_id;
+
 #if defined(MULTIPROCESSOR)
        /*
-        * Set our SysValue to the address of our cpu_info structure.
-        * Secondary processors do this in their spinup trampoline.
+        * Set the SysValue to &lwp0, after making sure that lwp0
+        * is pointing at the primary CPU.  Secondary processors do
+        * this in their spinup trampoline.
         */
-       alpha_pal_wrval((u_long)&cpu_info_primary);
-       cpu_info[cpu_id] = &cpu_info_primary;
+       lwp0.l_cpu = ci;
+       cpu_info[cpu_id] = ci;
+       alpha_pal_wrval((u_long)&lwp0);
 #endif
 
-       ci = curcpu();
-       ci->ci_cpuid = cpu_id;
-
        /*
         * Get critical system information (if possible, from the
         * information provided by the boot program).
diff -r 98f999866017 -r 485589dfa156 sys/arch/alpha/alpha/multiproc.s
--- a/sys/arch/alpha/alpha/multiproc.s  Fri Sep 04 03:41:49 2020 +0000
+++ b/sys/arch/alpha/alpha/multiproc.s  Fri Sep 04 03:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: multiproc.s,v 1.14 2020/09/03 15:38:17 thorpej Exp $ */
+/* $NetBSD: multiproc.s,v 1.15 2020/09/04 03:53:12 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-__KERNEL_RCSID(5, "$NetBSD: multiproc.s,v 1.14 2020/09/03 15:38:17 thorpej Exp $")
+__KERNEL_RCSID(5, "$NetBSD: multiproc.s,v 1.15 2020/09/04 03:53:12 thorpej Exp $")
 
 /*
  * Multiprocessor glue code.
@@ -59,16 +59,16 @@
        mov     gp, a0
        call_pal PAL_OSF1_wrkgp
 
-       /* Store our CPU info in SysValue. */
-       mov     s0, a0
-       call_pal PAL_OSF1_wrval
+       /* Make sure the cpu_info and lwp reference each other. */
+       ldq     s1, CPU_INFO_IDLE_LWP(s0)
+       stq     s0, L_CPU(s1)           /* set lwp::l_cpu */
 
        /* Switch to this CPU's idle thread. */
-       ldq     a0, CPU_INFO_IDLE_LWP(s0)
-       stq     a0, CPU_INFO_CURLWP(s0) /* set curlwp */
-       ldq     a0, L_MD_PCBPADDR(a0)
+       ldq     a0, L_MD_PCBPADDR(s1)
        call_pal PAL_OSF1_swpctx
 
+       SET_CURLWP(s1)
+
        /* Invalidate TLB and I-stream. */
        ldiq    a0, -2                  /* TBIA */
        call_pal PAL_OSF1_tbi
diff -r 98f999866017 -r 485589dfa156 sys/arch/alpha/include/asm.h
--- a/sys/arch/alpha/include/asm.h      Fri Sep 04 03:41:49 2020 +0000
+++ b/sys/arch/alpha/include/asm.h      Fri Sep 04 03:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: asm.h,v 1.43 2020/09/04 02:59:44 thorpej Exp $ */
+/* $NetBSD: asm.h,v 1.44 2020/09/04 03:53:12 thorpej Exp $ */
 
 /*
  * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
@@ -662,16 +662,18 @@
 /*
  * Get various per-cpu values.  A pointer to our cpu_info structure
  * is stored in SysValue.  These macros clobber v0, t0, t8..t11.
+ * SET_CURLWP also clobbers a0.
  *
  * All return values are in v0.
  */
 #define        GET_CURLWP                                                      \
-       call_pal PAL_OSF1_rdval                                 ;       \
-       ldq     v0, CPU_INFO_CURLWP(v0)
+       call_pal PAL_OSF1_rdval
 
 #define        SET_CURLWP(r)                                                   \
-       call_pal PAL_OSF1_rdval                                 ;       \
-       stq     r, CPU_INFO_CURLWP(v0)
+       ldq     v0, L_CPU(r)                                    ;       \
+       mov     r, a0                                           ;       \
+       stq     r, CPU_INFO_CURLWP(v0)                          ;       \
+       call_pal PAL_OSF1_wrval
 
 #else  /* if not MULTIPROCESSOR... */
 
diff -r 98f999866017 -r 485589dfa156 sys/arch/alpha/include/cpu.h
--- a/sys/arch/alpha/include/cpu.h      Fri Sep 04 03:41:49 2020 +0000
+++ b/sys/arch/alpha/include/cpu.h      Fri Sep 04 03:53:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.92 2020/09/04 01:57:29 thorpej Exp $ */
+/* $NetBSD: cpu.h,v 1.93 2020/09/04 03:53:12 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -161,7 +161,8 @@
 extern volatile u_long cpus_paused;
 extern struct cpu_info *cpu_info[];
 
-#define        curcpu()                ((struct cpu_info *)alpha_pal_rdval())
+#define        curlwp                  ((struct lwp *)alpha_pal_rdval())
+#define        curcpu()                curlwp->l_cpu
 #define        CPU_IS_PRIMARY(ci)      ((ci)->ci_flags & CPUF_PRIMARY)
 
 void   cpu_boot_secondary_processors(void);
@@ -170,9 +171,9 @@
 void   cpu_pause_resume_all(int);
 #else /* ! MULTIPROCESSOR */
 #define        curcpu()        (&cpu_info_primary)
+#define        curlwp          curcpu()->ci_curlwp
 #endif /* MULTIPROCESSOR */
 
-#define        curlwp          curcpu()->ci_curlwp
 
 /*
  * definitions of cpu-dependent requirements



Home | Main Index | Thread Index | Old Index