Module Name:    src
Committed By:   thorpej
Date:           Fri Sep  4 03:53:12 UTC 2020

Modified Files:
        src/sys/arch/alpha/alpha: machdep.c multiproc.s
        src/sys/arch/alpha/include: asm.h cpu.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.363 -r1.364 src/sys/arch/alpha/alpha/machdep.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/alpha/alpha/multiproc.s
cvs rdiff -u -r1.43 -r1.44 src/sys/arch/alpha/include/asm.h
cvs rdiff -u -r1.92 -r1.93 src/sys/arch/alpha/include/cpu.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/machdep.c
diff -u src/sys/arch/alpha/alpha/machdep.c:1.363 src/sys/arch/alpha/alpha/machdep.c:1.364
--- src/sys/arch/alpha/alpha/machdep.c:1.363	Thu Sep  3 02:09:09 2020
+++ src/sys/arch/alpha/alpha/machdep.c	Fri Sep  4 03:53:12 2020
@@ -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 @@ alpha_init(u_long xxx_pfn __unused, u_lo
 
 	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).

Index: src/sys/arch/alpha/alpha/multiproc.s
diff -u src/sys/arch/alpha/alpha/multiproc.s:1.14 src/sys/arch/alpha/alpha/multiproc.s:1.15
--- src/sys/arch/alpha/alpha/multiproc.s:1.14	Thu Sep  3 15:38:17 2020
+++ src/sys/arch/alpha/alpha/multiproc.s	Fri Sep  4 03:53:12 2020
@@ -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 @@ NESTED_NOPROFILE(cpu_spinup_trampoline,0
 	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

Index: src/sys/arch/alpha/include/asm.h
diff -u src/sys/arch/alpha/include/asm.h:1.43 src/sys/arch/alpha/include/asm.h:1.44
--- src/sys/arch/alpha/include/asm.h:1.43	Fri Sep  4 02:59:44 2020
+++ src/sys/arch/alpha/include/asm.h	Fri Sep  4 03:53:12 2020
@@ -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 @@ label:	ASCIZ msg;						\
 /*
  * 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... */
 

Index: src/sys/arch/alpha/include/cpu.h
diff -u src/sys/arch/alpha/include/cpu.h:1.92 src/sys/arch/alpha/include/cpu.h:1.93
--- src/sys/arch/alpha/include/cpu.h:1.92	Fri Sep  4 01:57:29 2020
+++ src/sys/arch/alpha/include/cpu.h	Fri Sep  4 03:53:12 2020
@@ -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_running;
 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(unsigned long, int
 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

Reply via email to