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

Configure Feed

Select the types of activity you want to include in your feed.

lockref: allow relaxed cmpxchg64 variant for lockless updates

The 64-bit cmpxchg operation on the lockref is ordered by virtue of
hazarding between the cmpxchg operation and the reference count
manipulation. On weakly ordered memory architectures (such as ARM), it
can be of great benefit to omit the barrier instructions where they are
not needed.

This patch moves the lockless lockref code over to a cmpxchg64_relaxed
operation, which doesn't provide barrier semantics. If the operation
isn't defined, we simply #define it as the usual 64-bit cmpxchg macro.

Cc: Waiman Long <Waiman.Long@hp.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Will Deacon and committed by
Linus Torvalds
d2212b4d 4b972806

+11 -2
+11 -2
lib/lockref.c
··· 4 4 #ifdef CONFIG_CMPXCHG_LOCKREF 5 5 6 6 /* 7 + * Allow weakly-ordered memory architectures to provide barrier-less 8 + * cmpxchg semantics for lockref updates. 9 + */ 10 + #ifndef cmpxchg64_relaxed 11 + # define cmpxchg64_relaxed cmpxchg64 12 + #endif 13 + 14 + /* 7 15 * Note that the "cmpxchg()" reloads the "old" value for the 8 16 * failure case. 9 17 */ ··· 22 14 while (likely(arch_spin_value_unlocked(old.lock.rlock.raw_lock))) { \ 23 15 struct lockref new = old, prev = old; \ 24 16 CODE \ 25 - old.lock_count = cmpxchg64(&lockref->lock_count, \ 26 - old.lock_count, new.lock_count); \ 17 + old.lock_count = cmpxchg64_relaxed(&lockref->lock_count, \ 18 + old.lock_count, \ 19 + new.lock_count); \ 27 20 if (likely(old.lock_count == prev.lock_count)) { \ 28 21 SUCCESS; \ 29 22 } \