Kill SPINLOCK_SPIN_HOOK, use CPU_BUSY_CYCLE() instead.
authormpi <mpi@openbsd.org>
Mon, 29 May 2017 14:19:49 +0000 (14:19 +0000)
committermpi <mpi@openbsd.org>
Mon, 29 May 2017 14:19:49 +0000 (14:19 +0000)
ok visa@, kettenis@

26 files changed:
sys/arch/alpha/alpha/lock_machdep.c
sys/arch/alpha/alpha/machdep.c
sys/arch/alpha/alpha/mutex.c
sys/arch/alpha/include/cpu.h
sys/arch/alpha/include/lock.h
sys/arch/amd64/amd64/fpu.c
sys/arch/amd64/amd64/lapic.c
sys/arch/amd64/amd64/lock_machdep.c
sys/arch/amd64/amd64/pmap.c
sys/arch/amd64/include/lock.h
sys/arch/hppa/hppa/lock_machdep.c
sys/arch/i386/i386/lock_machdep.c
sys/arch/i386/i386/pmap.c
sys/arch/i386/include/lock.h
sys/arch/i386/isa/npx.c
sys/arch/luna88k/luna88k/machdep.c
sys/arch/m88k/m88k/m8820x_machdep.c
sys/arch/m88k/m88k/m88k_machdep.c
sys/arch/m88k/m88k/mplock.c
sys/arch/mips64/mips64/lock_machdep.c
sys/arch/powerpc/include/lock.h
sys/arch/powerpc/powerpc/lock_machdep.c
sys/arch/powerpc/powerpc/mutex.c
sys/arch/sparc64/include/cpu.h
sys/arch/sparc64/include/lock.h
sys/arch/sparc64/sparc64/lock_machdep.c

index 21100c8..f9292e8 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.5 2017/04/30 16:45:45 mpi Exp $    */
+/*     $OpenBSD: lock_machdep.c,v 1.6 2017/05/29 14:19:49 mpi Exp $    */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -22,7 +22,6 @@
 
 #include <machine/atomic.h>
 #include <machine/cpu.h>
-#include <machine/lock.h>
 
 #if defined(MP_LOCKDEBUG)
 #ifndef DDB
@@ -69,14 +68,14 @@ __mp_lock_spin(struct __mp_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_count != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
        if (!CPU_IS_PRIMARY(curcpu()))
                nticks += nticks;
 
        while (mpl->mpl_count != 0 && --nticks > 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
        if (nticks == 0) {
                db_printf("__mp_lock(%p): lock spun out", mpl);
index 9a0db10..57c7d0f 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.180 2017/04/30 16:45:45 mpi Exp $ */
+/* $OpenBSD: machdep.c,v 1.181 2017/05/29 14:19:49 mpi Exp $ */
 /* $NetBSD: machdep.c,v 1.210 2000/06/01 17:12:38 thorpej Exp $ */
 
 /*-
 #ifndef NO_IEEE
 #include <machine/ieeefp.h>
 #endif
-#ifdef MULTIPROCESSOR
-#include <machine/lock.h>
-#endif
 
 #include <dev/pci/pcivar.h>
 
@@ -1761,7 +1758,7 @@ fpusave_proc(struct proc *p, int save)
                alpha_pal_swpipl(s);
 
                while (p->p_addr->u_pcb.pcb_fpcpu != NULL)
-                       SPINLOCK_SPIN_HOOK;
+                       CPU_BUSY_CYCLE();
 #else
                KASSERT(ci->ci_fpcurproc == p);
                fpusave_cpu(ci, save);
index ada28fa..04dbf9c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mutex.c,v 1.17 2017/04/20 13:57:29 visa Exp $ */
+/*     $OpenBSD: mutex.c,v 1.18 2017/05/29 14:19:49 mpi Exp $  */
 
 /*
  * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -31,7 +31,7 @@
 #include <sys/atomic.h>
 
 #include <machine/intr.h>
-#include <machine/lock.h>
+#include <machine/cpu.h>
 
 #include <ddb/db_output.h>
 
@@ -48,7 +48,7 @@ void
 __mtx_enter(struct mutex *mtx)
 {
        while (__mtx_enter_try(mtx) == 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 }
 
 int
index fb1dc79..bded5b3 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.57 2016/03/30 15:39:46 afresh1 Exp $ */
+/* $OpenBSD: cpu.h,v 1.58 2017/05/29 14:19:49 mpi Exp $ */
 /* $NetBSD: cpu.h,v 1.45 2000/08/21 02:03:12 thorpej Exp $ */
 
 /*-
@@ -246,15 +246,36 @@ void      cpu_pause_resume(unsigned long, int);
 void   cpu_pause_resume_all(int);
 void   cpu_unidle(struct cpu_info *);
 
+/*
+ * On the Alpha, interprocessor interrupts come in at device priority
+ * level.  This can cause some problems while waiting for r/w spinlocks
+ * from a high'ish priority level: IPIs that come in will not be processed.
+ * This can lead to deadlock.
+ *
+ * This hook allows IPIs to be processed while a spinlock's interlock
+ * is released.
+ */
+#define        CPU_BUSY_CYCLE()                                                \
+do {                                                                   \
+       struct cpu_info *__ci = curcpu();                               \
+       int __s;                                                        \
+                                                                       \
+       if (__ci->ci_ipis != 0) {                                       \
+               __s = splipi();                                         \
+               alpha_ipi_process_with_frame(__ci);                     \
+               splx(__s);                                              \
+       }                                                               \
+} while (0)
+
 #else /* ! MULTIPROCESSOR */
 
 #define        curcpu()                        (&cpu_info_primary)
 #define        CPU_IS_PRIMARY(ci)              1
 #define cpu_unidle(ci)                 do { /* nothing */ } while (0)
+#define CPU_BUSY_CYCLE()               do {} while (0)
 
 #endif /* MULTIPROCESSOR */
 
-#define CPU_BUSY_CYCLE()       do {} while (0)
 
 #define        curproc         curcpu()->ci_curproc
 #define        fpcurproc       curcpu()->ci_fpcurproc
index 3ef8a5c..c2214df 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.h,v 1.9 2015/02/11 03:56:00 dlg Exp $        */
+/* $OpenBSD: lock.h,v 1.10 2017/05/29 14:19:49 mpi Exp $       */
 /* $NetBSD: lock.h,v 1.16 2001/12/17 23:34:57 thorpej Exp $ */
 
 /*-
 #ifndef _MACHINE_LOCK_H_
 #define        _MACHINE_LOCK_H_
 
-#if defined(MULTIPROCESSOR)
-/*
- * On the Alpha, interprocessor interrupts come in at device priority
- * level.  This can cause some problems while waiting for r/w spinlocks
- * from a high'ish priority level: IPIs that come in will not be processed.
- * This can lead to deadlock.
- *
- * This hook allows IPIs to be processed while a spinlock's interlock
- * is released.
- */
-#define        SPINLOCK_SPIN_HOOK                                              \
-do {                                                                   \
-       struct cpu_info *__ci = curcpu();                               \
-       int __s;                                                        \
-                                                                       \
-       if (__ci->ci_ipis != 0) {                                       \
-               __s = splipi();                                         \
-               alpha_ipi_process_with_frame(__ci);                     \
-               splx(__s);                                              \
-       }                                                               \
-} while (0)
-#endif /* MULTIPROCESSOR */
-
 #endif /* _MACHINE_LOCK_H_ */
index 4b280fb..4e8365c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: fpu.c,v 1.34 2017/04/27 06:16:39 mlarkin Exp $        */
+/*     $OpenBSD: fpu.c,v 1.35 2017/05/29 14:19:49 mpi Exp $    */
 /*     $NetBSD: fpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $     */
 
 /*-
@@ -52,7 +52,6 @@
 #include <machine/trap.h>
 #include <machine/specialreg.h>
 #include <machine/fpu.h>
-#include <machine/lock.h>
 
 #include <dev/isa/isavar.h>
 
@@ -335,7 +334,7 @@ fpusave_proc(struct proc *p, int save)
                x86_send_ipi(oci,
                    save ? X86_IPI_SYNCH_FPU : X86_IPI_FLUSH_FPU);
                while (p->p_addr->u_pcb.pcb_fpcpu != NULL)
-                       SPINLOCK_SPIN_HOOK;
+                       CPU_BUSY_CYCLE();
        }
 #else
        KASSERT(ci->ci_fpcurproc == p);
index 8ce1462..4936398 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lapic.c,v 1.46 2017/05/25 03:54:10 visa Exp $ */
+/*     $OpenBSD: lapic.c,v 1.47 2017/05/29 14:19:49 mpi Exp $  */
 /* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */
 
 /*-
@@ -41,7 +41,6 @@
 #include <machine/codepatch.h>
 #include <machine/cpu.h>
 #include <machine/cpufunc.h>
-#include <machine/lock.h>
 #include <machine/pmap.h>
 #include <machine/vmparam.h>
 #include <machine/mpbiosvar.h>
@@ -572,7 +571,7 @@ lapic_delay(int usec)
                        deltat -= otick - tick;
                otick = tick;
 
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
        }
 }
 
index 5943c3b..c3fd540 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.15 2017/05/28 08:47:19 mpi Exp $   */
+/*     $OpenBSD: lock_machdep.c,v 1.16 2017/05/29 14:19:49 mpi Exp $   */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -23,7 +23,7 @@
 #include <sys/witness.h>
 #include <sys/_lock.h>
 
-#include <machine/lock.h>
+#include <machine/cpu.h>
 #include <machine/cpufunc.h>
 
 #include <ddb/db_output.h>
@@ -50,12 +50,12 @@ __mp_lock_spin(struct __mp_lock *mpl, u_int me)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_ticket != me)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_ticket != me) {
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
                if (--nticks <= 0) {
                        db_printf("__mp_lock(%p): lock spun out", mpl);
index dbc8c1a..68580d2 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pmap.c,v 1.103 2017/01/02 07:41:18 tedu Exp $ */
+/*     $OpenBSD: pmap.c,v 1.104 2017/05/29 14:19:49 mpi Exp $  */
 /*     $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */
 
 /*
 
 #include <uvm/uvm.h>
 
-#include <machine/lock.h>
 #include <machine/cpu.h>
 #include <machine/specialreg.h>
 #ifdef MULTIPROCESSOR
@@ -2473,7 +2472,7 @@ pmap_tlb_shootpage(struct pmap *pm, vaddr_t va, int shootself)
 
                while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
                tlb_shoot_addr1 = va;
                CPU_INFO_FOREACH(cii, ci) {
@@ -2511,7 +2510,7 @@ pmap_tlb_shootrange(struct pmap *pm, vaddr_t sva, vaddr_t eva, int shootself)
 
                while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
                tlb_shoot_addr1 = sva;
                tlb_shoot_addr2 = eva;
@@ -2549,7 +2548,7 @@ pmap_tlb_shoottlb(struct pmap *pm, int shootself)
 
                while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
 
                CPU_INFO_FOREACH(cii, ci) {
@@ -2569,7 +2568,7 @@ void
 pmap_tlb_shootwait(void)
 {
        while (tlb_shoot_wait != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 }
 
 #else
index d93111b..2ea630a 100644 (file)
@@ -1,10 +1,8 @@
-/*     $OpenBSD: lock.h,v 1.12 2017/05/25 03:50:10 visa Exp $  */
+/*     $OpenBSD: lock.h,v 1.13 2017/05/29 14:19:49 mpi Exp $   */
 
 /* public domain */
 
 #ifndef _MACHINE_LOCK_H_
 #define        _MACHINE_LOCK_H_
 
-#define SPINLOCK_SPIN_HOOK __asm volatile("pause": : :"memory")
-
 #endif /* _MACHINE_LOCK_H_ */
index 444e285..972b5bb 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.10 2017/04/30 16:45:45 mpi Exp $   */
+/*     $OpenBSD: lock_machdep.c,v 1.11 2017/05/29 14:19:49 mpi Exp $   */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -22,6 +22,7 @@
 #include <machine/atomic.h>
 #include <machine/intr.h>
 #include <machine/psl.h>
+#include <machine/cpu.h>
 
 #include <ddb/db_output.h>
 
@@ -72,19 +73,17 @@ __mp_lock_init(struct __mp_lock *lock)
 extern int __mp_lock_spinout;
 #endif
 
-#define SPINLOCK_SPIN_HOOK     /**/
-
 static __inline void
 __mp_lock_spin(struct __mp_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_count != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_count != 0 && --nticks > 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
        if (nticks == 0) {
                db_printf("__mp_lock(%p): lock spun out", mpl);
index 92e9fe6..0274c6f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.24 2017/05/28 08:47:19 mpi Exp $   */
+/*     $OpenBSD: lock_machdep.c,v 1.25 2017/05/29 14:19:49 mpi Exp $   */
 /* $NetBSD: lock_machdep.c,v 1.1.2.3 2000/05/03 14:40:30 sommerfeld Exp $ */
 
 /*-
@@ -41,7 +41,7 @@
 #include <sys/witness.h>
 #include <sys/_lock.h>
 
-#include <machine/lock.h>
+#include <machine/cpu.h>
 #include <machine/cpufunc.h>
 
 #include <ddb/db_output.h>
@@ -69,12 +69,12 @@ __mp_lock_spin(struct __mp_lock *mpl, u_int me)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_ticket != me)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_ticket != me) {
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
                if (--nticks <= 0) {
                        db_printf("__mp_lock(%p): lock spun out", mpl);
index 04248ba..b2345ce 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pmap.c,v 1.195 2016/10/21 06:20:58 mlarkin Exp $      */
+/*     $OpenBSD: pmap.c,v 1.196 2017/05/29 14:19:49 mpi Exp $  */
 /*     $NetBSD: pmap.c,v 1.91 2000/06/02 17:46:37 thorpej Exp $        */
 
 /*
@@ -65,7 +65,6 @@
 
 #include <uvm/uvm.h>
 
-#include <machine/lock.h>
 #include <machine/cpu.h>
 #include <machine/specialreg.h>
 #include <machine/gdt.h>
@@ -2520,7 +2519,7 @@ pmap_tlb_shootpage(struct pmap *pm, vaddr_t va)
 
                while (atomic_cas_uint(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
                tlb_shoot_addr1 = va;
                CPU_INFO_FOREACH(cii, ci) {
@@ -2558,7 +2557,7 @@ pmap_tlb_shootrange(struct pmap *pm, vaddr_t sva, vaddr_t eva)
 
                while (atomic_cas_uint(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
                tlb_shoot_addr1 = sva;
                tlb_shoot_addr2 = eva;
@@ -2596,7 +2595,7 @@ pmap_tlb_shoottlb(void)
 
                while (atomic_cas_uint(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
 
                CPU_INFO_FOREACH(cii, ci) {
@@ -2632,7 +2631,7 @@ pmap_tlb_droppmap(struct pmap *pm)
 
                while (atomic_cas_uint(&tlb_shoot_wait, 0, wait) != 0) {
                        while (tlb_shoot_wait != 0)
-                               SPINLOCK_SPIN_HOOK;
+                               CPU_BUSY_CYCLE();
                }
 
                CPU_INFO_FOREACH(cii, ci) {
@@ -2654,7 +2653,7 @@ void
 pmap_tlb_shootwait(void)
 {
        while (tlb_shoot_wait != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 }
 
 #else
index 6fcd36b..2ea630a 100644 (file)
@@ -1,10 +1,8 @@
-/*     $OpenBSD: lock.h,v 1.12 2016/04/03 11:05:26 jsg Exp $   */
+/*     $OpenBSD: lock.h,v 1.13 2017/05/29 14:19:49 mpi Exp $   */
 
 /* public domain */
 
 #ifndef _MACHINE_LOCK_H_
 #define        _MACHINE_LOCK_H_
 
-#define SPINLOCK_SPIN_HOOK __asm volatile("pause": : :"memory")
-
 #endif /* _MACHINE_LOCK_H_ */
index 2240838..782e018 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: npx.c,v 1.61 2015/02/11 05:54:48 dlg Exp $    */
+/*     $OpenBSD: npx.c,v 1.62 2017/05/29 14:19:50 mpi Exp $    */
 /*     $NetBSD: npx.c,v 1.57 1996/05/12 23:12:24 mycroft Exp $ */
 
 #if 0
@@ -61,7 +61,6 @@
 #include <machine/trap.h>
 #include <machine/specialreg.h>
 #include <machine/i8259.h>
-#include <machine/lock.h>
 
 #include <dev/isa/isareg.h>
 #include <dev/isa/isavar.h>
@@ -875,7 +874,7 @@ npxsave_proc(struct proc *p, int save)
                i386_send_ipi(oci,
                    save ? I386_IPI_SYNCH_FPU : I386_IPI_FLUSH_FPU);
                while (p->p_addr->u_pcb.pcb_fpcpu != NULL)
-                       SPINLOCK_SPIN_HOOK;
+                       CPU_BUSY_CYCLE();
        }
 #else
        KASSERT(ci->ci_fpcurproc == p);
index 1d684f7..2c2ecd4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: machdep.c,v 1.124 2017/04/30 16:45:45 mpi Exp $       */
+/*     $OpenBSD: machdep.c,v 1.125 2017/05/29 14:19:50 mpi Exp $       */
 /*
  * Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
  * Copyright (c) 1996 Nivas Madhur
@@ -84,7 +84,6 @@
 #include <machine/cmmu.h>
 #include <machine/cpu.h>
 #include <machine/kcore.h>
-#include <machine/lock.h>
 #include <machine/reg.h>
 #include <machine/trap.h>
 #include <machine/m88100.h>
index 32bec51..7281a5d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: m8820x_machdep.c,v 1.61 2013/11/16 18:45:20 miod Exp $        */
+/*     $OpenBSD: m8820x_machdep.c,v 1.62 2017/05/29 14:19:50 mpi Exp $ */
 /*
  * Copyright (c) 2004, 2007, 2010, 2011, 2013, Miodrag Vallat.
  *
@@ -80,7 +80,6 @@
 #include <machine/asm_macro.h>
 #include <machine/cmmu.h>
 #include <machine/cpu.h>
-#include <machine/lock.h>
 #include <machine/m8820x.h>
 #include <machine/psl.h>
 
index be18179..2d1d9fd 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: m88k_machdep.c,v 1.67 2017/03/19 10:57:29 miod Exp $  */
+/*     $OpenBSD: m88k_machdep.c,v 1.68 2017/05/29 14:19:50 mpi Exp $   */
 /*
  * Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
  * Copyright (c) 1996 Nivas Madhur
@@ -60,7 +60,6 @@
 #include <machine/asm.h>
 #include <machine/asm_macro.h>
 #include <machine/atomic.h>
-#include <machine/lock.h>
 #include <machine/cmmu.h>
 #include <machine/cpu.h>
 #include <machine/reg.h>
index 91c33ed..5422b03 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mplock.c,v 1.5 2017/04/30 16:45:45 mpi Exp $  */
+/*     $OpenBSD: mplock.c,v 1.6 2017/05/29 14:19:50 mpi Exp $  */
 
 /*
  * Copyright (c) 2004 Niklas Hallqvist.  All rights reserved.
@@ -28,7 +28,7 @@
 #include <sys/systm.h>
 
 #include <machine/asm_macro.h>
-#include <machine/lock.h>
+#include <machine/cpu.h>
 
 #include <ddb/db_output.h>
 
 extern int __mp_lock_spinout;
 #endif
 
-#define        SPINLOCK_SPIN_HOOK      do { /* nothing */ } while (0)
-
 static __inline void
 __mp_lock_spin(struct __mp_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_count != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_count != 0 && nticks-- > 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
        if (nticks == 0) {
                db_printf("__mp_lock(0x%x): lock spun out", mpl);
index e27cf8d..4af2c02 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.4 2017/05/19 00:52:49 visa Exp $   */
+/*     $OpenBSD: lock_machdep.c,v 1.5 2017/05/29 14:19:50 mpi Exp $    */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -22,7 +22,6 @@
 #include <sys/atomic.h>
 
 #include <machine/cpu.h>
-#include <machine/lock.h>
 
 #include <ddb/db_output.h>
 
@@ -42,19 +41,17 @@ __mp_lock_init(struct __mp_lock *lock)
 extern int __mp_lock_spinout;
 #endif
 
-#define SPINLOCK_SPIN_HOOK     /**/
-
 static __inline void
 __mp_lock_spin(struct __mp_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_count != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_count != 0 && --nticks > 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
        if (nticks == 0) {
                db_printf("__mp_lock(%p): lock spun out", mpl);
index a533cba..e3b41ca 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock.h,v 1.7 2015/08/14 06:14:19 dlg Exp $    */
+/*     $OpenBSD: lock.h,v 1.8 2017/05/29 14:19:50 mpi Exp $    */
 /*     $NetBSD: lock.h,v 1.8 2005/12/28 19:09:29 perry Exp $   */
 
 /*-
@@ -37,6 +37,4 @@
 #ifndef _POWERPC_LOCK_H_
 #define _POWERPC_LOCK_H_
 
-#define SPINLOCK_SPIN_HOOK do { } while (0)
-
 #endif /* _POWERPC_LOCK_H_ */
index 3ee3c25..b78af74 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.5 2017/04/30 16:45:45 mpi Exp $    */
+/*     $OpenBSD: lock_machdep.c,v 1.6 2017/05/29 14:19:50 mpi Exp $    */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -21,7 +21,7 @@
 #include <sys/systm.h>
 #include <sys/atomic.h>
 
-#include <machine/lock.h>
+#include <machine/cpu.h>
 #include <machine/psl.h>
 
 #include <ddb/db_output.h>
@@ -47,12 +47,12 @@ __mp_lock_spin(struct __mp_lock *mpl)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_count != 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_count != 0 && --nticks > 0)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
        if (nticks == 0) {
                db_printf("__mp_lock(%p): lock spun out", mpl);
index 7559371..5a6a801 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mutex.c,v 1.5 2017/04/30 16:45:45 mpi Exp $   */
+/*     $OpenBSD: mutex.c,v 1.6 2017/05/29 14:19:50 mpi Exp $   */
 
 /*
  * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -31,7 +31,7 @@
 #include <sys/atomic.h>
 
 #include <machine/intr.h>
-#include <machine/lock.h>
+#include <machine/cpu.h>
 
 #include <ddb/db_output.h>
 
@@ -61,7 +61,7 @@ __mtx_enter(struct mutex *mtx)
 #endif
 
        while (__mtx_enter_try(mtx) == 0) {
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
 #if defined(MP_LOCKDEBUG)
                if (--nticks == 0) {
index d090108..931d9a4 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cpu.h,v 1.90 2017/04/20 10:03:40 kettenis Exp $       */
+/*     $OpenBSD: cpu.h,v 1.91 2017/05/29 14:19:50 mpi Exp $    */
 /*     $NetBSD: cpu.h,v 1.28 2001/06/14 22:56:58 thorpej Exp $ */
 
 /*
@@ -210,7 +210,46 @@ void       cpu_unidle(struct cpu_info *);
 #define curpcb         __curcpu->ci_cpcb
 #define fpproc         __curcpu->ci_fpproc
 
-#define CPU_BUSY_CYCLE()       do {} while (0)
+/*
+ * On processors with multiple threads we force a thread switch.
+ *
+ * On UltraSPARC T2 and its successors, the optimal way to do this
+ * seems to be to do three nop reads of %ccr.  This works on
+ * UltraSPARC T1 as well, even though three nop casx operations seem
+ * to be slightly more optimal.  Since these instructions are
+ * effectively nops, executing them on earlier non-CMT processors is
+ * harmless, so we make this the default.
+ *
+ * On SPARC T4 and later, we can use the processor-specific pause
+ * instruction.
+ *
+ * On SPARC64 VI and its successors we execute the processor-specific
+ * sleep instruction.
+ */
+#define CPU_BUSY_CYCLE()                                               \
+do {                                                                   \
+       __asm volatile(                                                 \
+               "999:   rd      %%ccr, %%g0                     \n"     \
+               "       rd      %%ccr, %%g0                     \n"     \
+               "       rd      %%ccr, %%g0                     \n"     \
+               "       .section .sun4v_pause_patch, \"ax\"     \n"     \
+               "       .word   999b                            \n"     \
+               "       .word   0xb7802080      ! pause 128     \n"     \
+               "       .word   999b + 4                        \n"     \
+               "       nop                                     \n"     \
+               "       .word   999b + 8                        \n"     \
+               "       nop                                     \n"     \
+               "       .previous                               \n"     \
+               "       .section .sun4u_mtp_patch, \"ax\"       \n"     \
+               "       .word   999b                            \n"     \
+               "       .word   0x81b01060      ! sleep         \n"     \
+               "       .word   999b + 4                        \n"     \
+               "       nop                                     \n"     \
+               "       .word   999b + 8                        \n"     \
+               "       nop                                     \n"     \
+               "       .previous                               \n"     \
+               : : : "memory");                                        \
+} while (0)
 
 /*
  * Arguments to hardclock, softclock and gatherstats encapsulate the
index 5b3e63d..ef68208 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock.h,v 1.11 2017/05/27 15:11:03 mpi Exp $   */
+/*     $OpenBSD: lock.h,v 1.12 2017/05/29 14:19:50 mpi Exp $   */
 /*
  * Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org>
  *
 #ifndef        _MACHINE_LOCK_H_
 #define        _MACHINE_LOCK_H_
 
-#ifdef _KERNEL
-
-/*
- * On processors with multiple threads we force a thread switch.
- *
- * On UltraSPARC T2 and its successors, the optimal way to do this
- * seems to be to do three nop reads of %ccr.  This works on
- * UltraSPARC T1 as well, even though three nop casx operations seem
- * to be slightly more optimal.  Since these instructions are
- * effectively nops, executing them on earlier non-CMT processors is
- * harmless, so we make this the default.
- *
- * On SPARC T4 and later, we can use the processor-specific pause
- * instruction.
- *
- * On SPARC64 VI and its successors we execute the processor-specific
- * sleep instruction.
- */
-#define SPINLOCK_SPIN_HOOK                                             \
-do {                                                                   \
-       __asm volatile(                                                 \
-               "999:   rd      %%ccr, %%g0                     \n"     \
-               "       rd      %%ccr, %%g0                     \n"     \
-               "       rd      %%ccr, %%g0                     \n"     \
-               "       .section .sun4v_pause_patch, \"ax\"     \n"     \
-               "       .word   999b                            \n"     \
-               "       .word   0xb7802080      ! pause 128     \n"     \
-               "       .word   999b + 4                        \n"     \
-               "       nop                                     \n"     \
-               "       .word   999b + 8                        \n"     \
-               "       nop                                     \n"     \
-               "       .previous                               \n"     \
-               "       .section .sun4u_mtp_patch, \"ax\"       \n"     \
-               "       .word   999b                            \n"     \
-               "       .word   0x81b01060      ! sleep         \n"     \
-               "       .word   999b + 4                        \n"     \
-               "       nop                                     \n"     \
-               "       .word   999b + 8                        \n"     \
-               "       nop                                     \n"     \
-               "       .previous                               \n"     \
-               : : : "memory");                                        \
-} while (0)
-
-
-#endif /* _KERNEL */
 #endif /* _MACHINE_LOCK_H_ */
index 4680a5f..bd55818 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lock_machdep.c,v 1.16 2017/05/27 15:11:03 mpi Exp $   */
+/*     $OpenBSD: lock_machdep.c,v 1.17 2017/05/29 14:19:50 mpi Exp $   */
 
 /*
  * Copyright (c) 2007 Artur Grabowski <art@openbsd.org>
@@ -20,7 +20,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 
-#include <machine/lock.h>
+#include <machine/cpu.h>
 #include <machine/psl.h>
 
 #include <ddb/db_output.h>
@@ -47,12 +47,12 @@ __mp_lock_spin(struct __mp_lock *mpl, u_int me)
 {
 #ifndef MP_LOCKDEBUG
        while (mpl->mpl_ticket != me)
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 #else
        int nticks = __mp_lock_spinout;
 
        while (mpl->mpl_ticket != me) {
-               SPINLOCK_SPIN_HOOK;
+               CPU_BUSY_CYCLE();
 
                if (--nticks <= 0) {
                        db_printf("__mp_lock(%p): lock spun out", mpl);