summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-02 22:19:17 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-07-02 22:19:17 +0000
commit97d8260479f882ea93b1225536948b7ce658b9dd (patch)
treebbe5c225f38a0ded016ff450e3d0e35563a62b08 /sys/arch
parent85cbaa0a5e474b536bea5043776f839dd50a77b9 (diff)
Per recommandation in the the sparc docs, use unlocked reads when
spinning on a contended lock. ok kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/sparc/include/lock.h31
-rw-r--r--sys/arch/sparc64/include/lock.h37
2 files changed, 37 insertions, 31 deletions
diff --git a/sys/arch/sparc/include/lock.h b/sys/arch/sparc/include/lock.h
index 2d32b88e8e7..136d9914278 100644
--- a/sys/arch/sparc/include/lock.h
+++ b/sys/arch/sparc/include/lock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.h,v 1.4 2011/03/23 16:54:37 pirofti Exp $ */
+/* $OpenBSD: lock.h,v 1.5 2011/07/02 22:19:16 guenther Exp $ */
/* public domain */
@@ -18,27 +18,30 @@ __cpu_simple_lock_init(__cpu_simple_lock_t *l)
*l = __SIMPLELOCK_UNLOCKED;
}
+static __inline__ u_int8_t
+__cpu_ldstub(__cpu_simple_lock_t *l)
+{
+ u_int8_t old;
+
+ __asm__ __volatile__
+ ("ldstub [%1], %0" : "=&r" (old) : "r" (l) : "memory");
+ return old;
+}
+
static __inline__ void
__cpu_simple_lock(__cpu_simple_lock_t *l)
{
- __cpu_simple_lock_t old;
-
- do {
- old = __SIMPLELOCK_LOCKED;
- __asm__ __volatile__
- ("ldstub [%0], %1" : "=r" (l), "=r" (old) : "0" (l));
- } while (old != __SIMPLELOCK_UNLOCKED);
+ while (__cpu_ldstub(l) != __SIMPLELOCK_UNLOCKED)
+ while (*l != __SIMPLELOCK_UNLOCKED)
+ ;
}
static __inline__ int
__cpu_simple_lock_try(__cpu_simple_lock_t *l)
{
- __cpu_simple_lock_t old = __SIMPLELOCK_LOCKED;
-
- __asm__ __volatile__
- ("ldstub [%0], %1" : "=r" (l), "=r" (old) : "0" (l));
-
- return (old == __SIMPLELOCK_UNLOCKED);
+ if (__cpu_ldstub(l) != __SIMPLELOCK_UNLOCKED)
+ return (0);
+ return (1);
}
static __inline__ void
diff --git a/sys/arch/sparc64/include/lock.h b/sys/arch/sparc64/include/lock.h
index b42f88e820f..80ceee1008f 100644
--- a/sys/arch/sparc64/include/lock.h
+++ b/sys/arch/sparc64/include/lock.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.h,v 1.6 2011/03/23 16:54:37 pirofti Exp $ */
+/* $OpenBSD: lock.h,v 1.7 2011/07/02 22:19:16 guenther Exp $ */
/* public domain */
@@ -19,35 +19,38 @@ __cpu_simple_lock_init(__cpu_simple_lock_t *l)
*l = __SIMPLELOCK_UNLOCKED;
}
+static __inline__ u_int8_t
+__cpu_ldstub(__cpu_simple_lock_t *l)
+{
+ u_int8_t old;
+
+ __asm__ __volatile__
+ ("ldstub [%1], %0" : "=&r" (old) : "r" (l) : "memory");
+ return old;
+}
+
static __inline__ void
__cpu_simple_lock(__cpu_simple_lock_t *l)
{
- __cpu_simple_lock_t old;
-
- do {
- old = __SIMPLELOCK_LOCKED;
- __asm__ __volatile__
- ("ldstub [%0], %1" : "=r" (l), "=r" (old) : "0" (l));
- membar(LoadLoad | LoadStore);
- } while (old != __SIMPLELOCK_UNLOCKED);
+ while (__cpu_ldstub(l) != __SIMPLELOCK_UNLOCKED)
+ while (*l != __SIMPLELOCK_UNLOCKED)
+ ;
+ membar(LoadLoad | LoadStore); /* only needed for PSO and RMO */
}
static __inline__ int
__cpu_simple_lock_try(__cpu_simple_lock_t *l)
{
- __cpu_simple_lock_t old = __SIMPLELOCK_LOCKED;
-
- __asm__ __volatile__
- ("ldstub [%0], %1" : "=r" (l), "=r" (old) : "0" (l));
- membar(LoadLoad | LoadStore);
-
- return (old == __SIMPLELOCK_UNLOCKED);
+ if (__cpu_ldstub(l) != __SIMPLELOCK_UNLOCKED)
+ return (0);
+ membar(LoadLoad | LoadStore); /* only needed for PSO and RMO */
+ return (1);
}
static __inline__ void
__cpu_simple_unlock(__cpu_simple_lock_t *l)
{
- membar(StoreStore | LoadStore);
+ membar(StoreStore | LoadStore); /* only needed for PSO and RMO */
*l = __SIMPLELOCK_UNLOCKED;
}