aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rcuref.c
diff options
context:
space:
mode:
authorUros Bizjak <ubizjak@gmail.com>2023-05-09 17:02:55 +0200
committerIngo Molnar <mingo@kernel.org>2023-10-10 10:14:27 +0200
commit4fbf8b136ded943f8661cf48270482ad1f5ce7bd (patch)
tree6791e499a8533413fffe2b4d0b59f04e2aa1f8f1 /lib/rcuref.c
parentad0a2e4c2f20510d7e3f2bc110cf74f8578547f0 (diff)
downloadlinux-4fbf8b136ded943f8661cf48270482ad1f5ce7bd.tar.gz
locking/atomics: Use atomic_try_cmpxchg_release() to micro-optimize rcuref_put_slowpath()
Use atomic_try_cmpxchg() instead of atomic_cmpxchg(*ptr, old, new) == old in rcuref_put_slowpath(). On x86 the CMPXCHG instruction returns success in the ZF flag, so this change saves a compare after CMPXCHG. Additionaly, the compiler reorders some code blocks to follow likely/unlikely annotations in the atomic_try_cmpxchg() macro, improving the code from: 9a: f0 0f b1 0b lock cmpxchg %ecx,(%rbx) 9e: 83 f8 ff cmp $0xffffffff,%eax a1: 74 04 je a7 <rcuref_put_slowpath+0x27> a3: 31 c0 xor %eax,%eax to: 9a: f0 0f b1 0b lock cmpxchg %ecx,(%rbx) 9e: 75 4c jne ec <rcuref_put_slowpath+0x6c> a0: b0 01 mov $0x1,%al No functional change intended. Signed-off-by: Uros Bizjak <ubizjak@gmail.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Paul E. McKenney <paulmck@kernel.org> Link: https://lore.kernel.org/r/20230509150255.3691-1-ubizjak@gmail.com
Diffstat (limited to 'lib/rcuref.c')
-rw-r--r--lib/rcuref.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/rcuref.c b/lib/rcuref.c
index 5ec00a4a64d11c..97f300eca927ce 100644
--- a/lib/rcuref.c
+++ b/lib/rcuref.c
@@ -248,7 +248,7 @@ bool rcuref_put_slowpath(rcuref_t *ref)
* require a retry. If this fails the caller is not
* allowed to deconstruct the object.
*/
- if (atomic_cmpxchg_release(&ref->refcnt, RCUREF_NOREF, RCUREF_DEAD) != RCUREF_NOREF)
+ if (!atomic_try_cmpxchg_release(&ref->refcnt, &cnt, RCUREF_DEAD))
return false;
/*