Skip to contentSkip to conversation

Hook up qspinlock for arm64

PATCH New Will Deacon 2 participants 5 messages Jun 26, 2018 – Jul 20, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index f11518af96a9..822a9192c551 100644
@@ -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
#2 lore raw

PATCH 2/3 arm64: locking: Replace ticket lock implementation with qspinlock

In reply to Will Deacon

It'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
index 42c090cf0292..facd19625563 100644
@@ -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
index 3a9b84d39d71..6cd5d77b6b44 100644
@@ -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
index 6b856012c51b..a157ff465e27 100644
@@ -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
#3 lore raw

PATCH 3/3 arm64: kconfig: Ensure spinlock fastpaths are inlined if !PREEMPT

In reply to Will Deacon

When 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
index facd19625563..476de9b1d239 100644
@@ -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
#4 lore raw

cover Hook up qspinlock for arm64

In reply to Will Deacon
Quoted 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: 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(-)