arm64: lockref: add support for lockless lockrefs using cmpxchg
authorWill Deacon <will.deacon@arm.com>
Wed, 9 Oct 2013 14:54:27 +0000 (15:54 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 24 Oct 2013 14:46:34 +0000 (15:46 +0100)
Our spinlocks are only 32-bit (2x16-bit tickets) and our cmpxchg can
deal with 8-bytes (as one would hope!).

This patch wires up the cmpxchg-based lockless lockref implementation
for arm64.

Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
arch/arm64/Kconfig
arch/arm64/include/asm/spinlock.h

index c04454876bcbe6520a52ada910a7d193ff884e85..9e8233b3f1884e67f94c70372f64c3352a412d15 100644 (file)
@@ -1,6 +1,7 @@
 config ARM64
        def_bool y
        select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
+       select ARCH_USE_CMPXCHG_LOCKREF
        select ARCH_WANT_OPTIONAL_GPIOLIB
        select ARCH_WANT_COMPAT_IPC_PARSE_VERSION
        select ARCH_WANT_FRAME_POINTERS
index 525dd535443e8ec99dcb14bdf5972401fa32514e..3d5cf064d7a1702992cb89d0fe0914475ae4b1ee 100644 (file)
@@ -92,10 +92,14 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
        : "memory");
 }
 
+static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
+{
+       return lock.owner == lock.next;
+}
+
 static inline int arch_spin_is_locked(arch_spinlock_t *lock)
 {
-       arch_spinlock_t lockval = ACCESS_ONCE(*lock);
-       return lockval.owner != lockval.next;
+       return !arch_spin_value_unlocked(ACCESS_ONCE(*lock));
 }
 
 static inline int arch_spin_is_contended(arch_spinlock_t *lock)