Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARC: atomics: Implement arch_atomic64_cmpxchg using _relaxed

The core atomic code has a number of macros where it elaborates
architecture primitives into more functions. ARC uses
arch_atomic64_cmpxchg() as it's architecture primitive which disable alot
of the additional functions.

Instead provide arch_cmpxchg64_relaxed() as the primitive and rely on the
core macros to create arch_cmpxchg64().

The macros will also provide other functions, for instance,
try_cmpxchg64_release(), giving a more complete implementation.

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/Z0747n5bSep4_1VX@J2N7QTR9R3
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Vineet Gupta <vgupta@kernel.org>

authored by

Jason Gunthorpe and committed by
Vineet Gupta
ea7caffe 19272b37

+5 -10
+5 -10
arch/arc/include/asm/atomic64-arcv2.h
··· 137 137 #undef ATOMIC64_OP_RETURN 138 138 #undef ATOMIC64_OP 139 139 140 - static inline s64 141 - arch_atomic64_cmpxchg(atomic64_t *ptr, s64 expected, s64 new) 140 + static inline u64 __arch_cmpxchg64_relaxed(volatile void *ptr, u64 old, u64 new) 142 141 { 143 - s64 prev; 144 - 145 - smp_mb(); 142 + u64 prev; 146 143 147 144 __asm__ __volatile__( 148 145 "1: llockd %0, [%1] \n" ··· 149 152 " bnz 1b \n" 150 153 "2: \n" 151 154 : "=&r"(prev) 152 - : "r"(ptr), "ir"(expected), "r"(new) 153 - : "cc"); /* memory clobber comes from smp_mb() */ 154 - 155 - smp_mb(); 155 + : "r"(ptr), "ir"(old), "r"(new) 156 + : "memory", "cc"); 156 157 157 158 return prev; 158 159 } 159 - #define arch_atomic64_cmpxchg arch_atomic64_cmpxchg 160 + #define arch_cmpxchg64_relaxed __arch_cmpxchg64_relaxed 160 161 161 162 static inline s64 arch_atomic64_xchg(atomic64_t *ptr, s64 new) 162 163 {