Hook up qspinlock for arm64
Subsystems (2)
cover Hook up qspinlock for arm64
Hi everybody,
With my recent changes to the core qspinlock code, it now performs well enough on arm64 to replace our ticket-based approach.
Testing welcome,
Will
--->8
Will Deacon (3):
arm64: barrier: Implement smp_cond_load_relaxed
arm64: locking: Replace ticket lock implementation with qspinlock
arm64: kconfig: Ensure spinlock fastpaths are inlined if !PREEMPT
arch/arm64/Kconfig | 11 +++ arch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/barrier.h | 13 ++++ arch/arm64/include/asm/spinlock.h | 117 +------------------------------- arch/arm64/include/asm/spinlock_types.h | 17 +---- 5 files changed, 27 insertions(+), 132 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/3 arm64: barrier: Implement smp_cond_load_relaxed
We can provide an implementation of smp_cond_load_relaxed using READ_ONCE and __cmpwait_relaxed.
--- arch/arm64/include/asm/barrier.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm64/include/asm/barrier.h +13 -0
@@ -128,6 +128,19 @@ do { \ __u.__val; \ }) +#define smp_cond_load_relaxed (ptr, cond_expr) \ +({ \ + typeof(ptr) __PTR = (ptr); \ + typeof(*ptr) VAL; \ + for (;;) { \ + VAL = READ_ONCE(*__PTR); \ + if (cond_expr) \ + break; \ + __cmpwait_relaxed(__PTR, VAL); \ + } \ + VAL; \ +}) +#define smp_cond_load_acquire (ptr, cond_expr) \ ({ \ typeof(ptr) __PTR = (ptr); \
Signature · 1 line
2.1.4
PATCH 2/3 arm64: locking: Replace ticket lock implementation with qspinlock
In reply to Will DeaconIt's fair to say that our ticket lock has served us well over time, but it's time to bite the bullet and start using the generic qspinlock code so we can make use of explicit MCS queuing and potentially better PV performance in future.
--- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/spinlock.h | 117 +------------------------------- arch/arm64/include/asm/spinlock_types.h | 17 +---- 4 files changed, 4 insertions(+), 132 deletions(-)
arch/arm64/Kconfig +1 -0
@@ -44,6 +44,7 @@ config ARM64 select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE if !PREEMPT select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_QUEUED_RWLOCKS + select ARCH_USE_QUEUED_SPINLOCKS select ARCH_SUPPORTS_MEMORY_FAILURE select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_INT128 if GCC_VERSION >= 50000 || CC_IS_CLANG
arch/arm64/include/asm/Kbuild +1 -0
@@ -16,6 +16,7 @@ generic-y += mm-arch-hooks.h generic-y += msi.h generic-y += preempt.h generic-y += qrwlock.h +generic-y += qspinlock.h generic-y += rwsem.h generic-y += segment.h generic-y += serial.h
arch/arm64/include/asm/spinlock.h +1 -116
124 lines not on this page · raw message
arch/arm64/include/asm/spinlock_types.h +1 -16
@@ -20,22 +20,7 @@# error "please don't include this file directly"#endif -#include <linux/types.h> - -#define TICKET_SHIFT 16 - -typedef struct { -#ifdef __AARCH64EB__ -u16 next; -u16 owner; -#else -u16 owner; -u16 next; -#endif -}__aligned(4) arch_spinlock_t ; - -#define __ARCH_SPIN_LOCK_UNLOCKED { 0 , 0 } - +#include <asm-generic/qspinlock_types.h> #include <asm-generic/qrwlock_types.h> #endif
Signature · 1 line
2.1.4
PATCH 3/3 arm64: kconfig: Ensure spinlock fastpaths are inlined if !PREEMPT
In reply to Will DeaconWhen running with CONFIG_PREEMPT=n, the spinlock fastpaths fit inside 64 bytes, which typically coincides with the L1 I-cache line size.
Inline the spinlock fastpaths, like we do already for rwlocks.
--- arch/arm64/Kconfig | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm64/Kconfig +10 -0
@@ -42,6 +42,16 @@ config ARM64 select ARCH_INLINE_WRITE_UNLOCK_BH if !PREEMPT select ARCH_INLINE_WRITE_UNLOCK_IRQ if !PREEMPT select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE if !PREEMPT + select ARCH_INLINE_SPIN_TRYLOCK if !PREEMPT + select ARCH_INLINE_SPIN_TRYLOCK_BH if !PREEMPT + select ARCH_INLINE_SPIN_LOCK if !PREEMPT + select ARCH_INLINE_SPIN_LOCK_BH if !PREEMPT + select ARCH_INLINE_SPIN_LOCK_IRQ if !PREEMPT + select ARCH_INLINE_SPIN_LOCK_IRQSAVE if !PREEMPT + select ARCH_INLINE_SPIN_UNLOCK if !PREEMPT + select ARCH_INLINE_SPIN_UNLOCK_BH if !PREEMPT + select ARCH_INLINE_SPIN_UNLOCK_IRQ if !PREEMPT + select ARCH_INLINE_SPIN_UNLOCK_IRQRESTORE if !PREEMPT select ARCH_USE_CMPXCHG_LOCKREF select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS
Signature · 1 line
2.1.4
cover Hook up qspinlock for arm64
In reply to Will DeaconQuoted 7 lines · Will Deacon
Hi everybody,
With my recent changes to the core qspinlock code, it now performs well enough on arm64 to replace our ticket-based approach.
Testing welcome,
Hi Will,
JFYI, In the scenario we tested - which had a spinlock under high contention from many CPUs - we were see a big performance improvement.
I see this patchset is in linux-next, so assume it will be in 4.19
Cheers,
John
Quoted 16 lines
Will
--->8
Will Deacon (3):
arm64: barrier: Implementsmp_cond_load_relaxed
arm64: locking: Replace ticket lock implementation with qspinlock
arm64: kconfig: Ensure spinlock fastpaths are inlined if !PREEMPTarch/arm64/Kconfig | 11 +++ arch/arm64/include/asm/Kbuild | 1 + arch/arm64/include/asm/barrier.h | 13 ++++ arch/arm64/include/asm/spinlock.h | 117 +------------------------------- arch/arm64/include/asm/spinlock_types.h | 17 +---- 5 files changed, 27 insertions(+), 132 deletions(-)