summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2020-09-04 03:53:12 +0000
committerthorpej <thorpej@NetBSD.org>2020-09-04 03:53:12 +0000
commita3f978ce6f32da4391f45429e78b9eb09cfdfd8b (patch)
tree0f0a42a10d5ca3a0fd2b06ff9ffcf381ccc672ab /sys
parent349ada9b9a35f297bd03501a0e97fa1f1c77d449 (diff)
Use SysValue to store curlwp rather than curcpu. curlwp is acceessed
much more frequently, and this makes curlwp preemption-safe.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/alpha/alpha/machdep.c20
-rw-r--r--sys/arch/alpha/alpha/multiproc.s16
-rw-r--r--sys/arch/alpha/include/asm.h12
-rw-r--r--sys/arch/alpha/include/cpu.h7
4 files changed, 30 insertions, 25 deletions
diff --git a/sys/arch/alpha/alpha/machdep.c b/sys/arch/alpha/alpha/machdep.c
index d193125b9c8..89507e483cd 100644
--- a/sys/arch/alpha/alpha/machdep.c
+++ b/sys/arch/alpha/alpha/machdep.c
@@ -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_long ptb, u_long bim, u_long bip,
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 --git a/sys/arch/alpha/alpha/multiproc.s b/sys/arch/alpha/alpha/multiproc.s
index d0ec0305a67..44092375749 100644
--- a/sys/arch/alpha/alpha/multiproc.s
+++ b/sys/arch/alpha/alpha/multiproc.s
@@ -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,0,ra,0,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
diff --git a/sys/arch/alpha/include/asm.h b/sys/arch/alpha/include/asm.h
index b11efeeb821..910167763f3 100644
--- a/sys/arch/alpha/include/asm.h
+++ b/sys/arch/alpha/include/asm.h
@@ -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... */
diff --git a/sys/arch/alpha/include/cpu.h b/sys/arch/alpha/include/cpu.h
index e15faf4fcb8..7c78f644548 100644
--- a/sys/arch/alpha/include/cpu.h
+++ b/sys/arch/alpha/include/cpu.h
@@ -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