* [PATCH v2 0/3] Wire up lockless lockrefs for ARM
@ 2013-10-03 18:17 Will Deacon
2013-10-03 18:17 ` [PATCH v2 1/3] ARM: cmpxchg: implement barrier-less cmpxchg64_local Will Deacon
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Will Deacon @ 2013-10-03 18:17 UTC (permalink / raw)
To: linux-arm-kernel
Hello,
This is version two of the patch I originally posted here:
http://lists.infradead.org/pipermail/linux-arm-kernel/2013-September/200109.html
The main changes since then are:
* Separate cmpxchg64 from atomic64_cmpxchg, so we can implement a
barrier-less version.
* Use this new barrier-less function to implement cmpxchg64_relaxed
* Finally, use cmpxchg64_relaxed to optimise cmpxchg64_local and
implement lockless lockrefs.
This results in ~100% improvement when running Linus's t.c test
(essentially stating a file in a loop for 10 seconds).
Feedback welcome,
Will
Will Deacon (3):
ARM: cmpxchg: implement barrier-less cmpxchg64_local
ARM: cmpxchg: implement cmpxchg64_relaxed
ARM: lockref: add support for lockless lockrefs using cmpxchg64
arch/arm/Kconfig | 1 +
arch/arm/include/asm/cmpxchg.h | 58 ++++++++++++++++++++++++++++++++---------
arch/arm/include/asm/spinlock.h | 8 ++++--
3 files changed, 53 insertions(+), 14 deletions(-)
--
1.8.2.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] ARM: cmpxchg: implement barrier-less cmpxchg64_local
2013-10-03 18:17 [PATCH v2 0/3] Wire up lockless lockrefs for ARM Will Deacon
@ 2013-10-03 18:17 ` Will Deacon
2013-10-03 18:17 ` [PATCH v2 2/3] ARM: cmpxchg: implement cmpxchg64_relaxed Will Deacon
2013-10-03 18:17 ` [PATCH v2 3/3] ARM: lockref: add support for lockless lockrefs using cmpxchg64 Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2013-10-03 18:17 UTC (permalink / raw)
To: linux-arm-kernel
Our cmpxchg64 macros are wrappers around atomic64_cmpxchg. Whilst this is
great for code re-use, there is a case for barrier-less cmpxchg where it
is known to be safe (for example cmpxchg64_local and cmpxchg-based
lockrefs).
This patch introduces a 64-bit cmpxchg implementation specifically
for the cmpxchg64_* macros, so that it can be later used by the lockref
code.
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/include/asm/cmpxchg.h | 52 ++++++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 10 deletions(-)
diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
index 4f009c1..fbd978f 100644
--- a/arch/arm/include/asm/cmpxchg.h
+++ b/arch/arm/include/asm/cmpxchg.h
@@ -223,6 +223,42 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
return ret;
}
+static inline unsigned long long __cmpxchg64(unsigned long long *ptr,
+ unsigned long long old,
+ unsigned long long new)
+{
+ unsigned long long oldval;
+ unsigned long res;
+
+ __asm__ __volatile__(
+"1: ldrexd %1, %H1, [%3]\n"
+" teq %1, %4\n"
+" teqeq %H1, %H4\n"
+" bne 2f\n"
+" strexd %0, %5, %H5, [%3]\n"
+" teq %0, #0\n"
+" bne 1b\n"
+"2:"
+ : "=&r" (res), "=&r" (oldval), "+Qo" (*ptr)
+ : "r" (ptr), "r" (old), "r" (new)
+ : "cc");
+
+ return oldval;
+}
+
+static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
+ unsigned long long old,
+ unsigned long long new)
+{
+ unsigned long long ret;
+
+ smp_mb();
+ ret = __cmpxchg64(ptr, old, new);
+ smp_mb();
+
+ return ret;
+}
+
#define cmpxchg_local(ptr,o,n) \
((__typeof__(*(ptr)))__cmpxchg_local((ptr), \
(unsigned long)(o), \
@@ -230,18 +266,14 @@ static inline unsigned long __cmpxchg_local(volatile void *ptr,
sizeof(*(ptr))))
#define cmpxchg64(ptr, o, n) \
- ((__typeof__(*(ptr)))atomic64_cmpxchg(container_of((ptr), \
- atomic64_t, \
- counter), \
- (unsigned long long)(o), \
- (unsigned long long)(n)))
+ ((__typeof__(*(ptr)))__cmpxchg64_mb((ptr), \
+ (unsigned long long)(o), \
+ (unsigned long long)(n)))
#define cmpxchg64_local(ptr, o, n) \
- ((__typeof__(*(ptr)))local64_cmpxchg(container_of((ptr), \
- local64_t, \
- a), \
- (unsigned long long)(o), \
- (unsigned long long)(n)))
+ ((__typeof__(*(ptr)))__cmpxchg64((ptr), \
+ (unsigned long long)(o), \
+ (unsigned long long)(n)))
#endif /* __LINUX_ARM_ARCH__ >= 6 */
--
1.8.2.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] ARM: cmpxchg: implement cmpxchg64_relaxed
2013-10-03 18:17 [PATCH v2 0/3] Wire up lockless lockrefs for ARM Will Deacon
2013-10-03 18:17 ` [PATCH v2 1/3] ARM: cmpxchg: implement barrier-less cmpxchg64_local Will Deacon
@ 2013-10-03 18:17 ` Will Deacon
2013-10-03 18:17 ` [PATCH v2 3/3] ARM: lockref: add support for lockless lockrefs using cmpxchg64 Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2013-10-03 18:17 UTC (permalink / raw)
To: linux-arm-kernel
This patch introduces cmpxchg64_relaxed for arm, which performs a 64-bit
cmpxchg operation without barrier semantics. cmpxchg64_local is updated
to use the new operation.
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/include/asm/cmpxchg.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
index fbd978f..df2fbba 100644
--- a/arch/arm/include/asm/cmpxchg.h
+++ b/arch/arm/include/asm/cmpxchg.h
@@ -270,11 +270,13 @@ static inline unsigned long long __cmpxchg64_mb(unsigned long long *ptr,
(unsigned long long)(o), \
(unsigned long long)(n)))
-#define cmpxchg64_local(ptr, o, n) \
+#define cmpxchg64_relaxed(ptr, o, n) \
((__typeof__(*(ptr)))__cmpxchg64((ptr), \
(unsigned long long)(o), \
(unsigned long long)(n)))
+#define cmpxchg64_local(ptr, o, n) cmpxchg64_relaxed((ptr), (o), (n))
+
#endif /* __LINUX_ARM_ARCH__ >= 6 */
#endif /* __ASM_ARM_CMPXCHG_H */
--
1.8.2.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] ARM: lockref: add support for lockless lockrefs using cmpxchg64
2013-10-03 18:17 [PATCH v2 0/3] Wire up lockless lockrefs for ARM Will Deacon
2013-10-03 18:17 ` [PATCH v2 1/3] ARM: cmpxchg: implement barrier-less cmpxchg64_local Will Deacon
2013-10-03 18:17 ` [PATCH v2 2/3] ARM: cmpxchg: implement cmpxchg64_relaxed Will Deacon
@ 2013-10-03 18:17 ` Will Deacon
2 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2013-10-03 18:17 UTC (permalink / raw)
To: linux-arm-kernel
Our spinlocks are only 32-bit (2x16-bit tickets) and, on processors
with 64-bit atomic instructions, cmpxchg64 makes use of the double-word
exclusive accessors.
This patch wires up the cmpxchg-based lockless lockref implementation
for ARM.
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
arch/arm/Kconfig | 1 +
arch/arm/include/asm/spinlock.h | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index c1c551e..22700fd 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -5,6 +5,7 @@ config ARM
select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_HAVE_CUSTOM_GPIO_H
+ select ARCH_USE_CMPXCHG_LOCKREF
select ARCH_WANT_IPC_PARSE_VERSION
select BUILDTIME_EXTABLE_SORT if MMU
select CLONE_BACKWARDS
diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index 4f2c280..ed6c229 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -127,10 +127,14 @@ static inline void arch_spin_unlock(arch_spinlock_t *lock)
dsb_sev();
}
+static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
+{
+ return lock.tickets.owner == lock.tickets.next;
+}
+
static inline int arch_spin_is_locked(arch_spinlock_t *lock)
{
- struct __raw_tickets tickets = ACCESS_ONCE(lock->tickets);
- return tickets.owner != tickets.next;
+ return !arch_spin_value_unlocked(ACCESS_ONCE(*lock));
}
static inline int arch_spin_is_contended(arch_spinlock_t *lock)
--
1.8.2.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-03 18:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-03 18:17 [PATCH v2 0/3] Wire up lockless lockrefs for ARM Will Deacon
2013-10-03 18:17 ` [PATCH v2 1/3] ARM: cmpxchg: implement barrier-less cmpxchg64_local Will Deacon
2013-10-03 18:17 ` [PATCH v2 2/3] ARM: cmpxchg: implement cmpxchg64_relaxed Will Deacon
2013-10-03 18:17 ` [PATCH v2 3/3] ARM: lockref: add support for lockless lockrefs using cmpxchg64 Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).