Skip to content

Commit 87347f1

Browse files
ubizjakKAGA-KOKO
authored andcommitted
futex: Use atomic64_try_cmpxchg_relaxed() in get_inode_sequence_number()
Optimize get_inode_sequence_number() to use simpler and faster: !atomic64_try_cmpxchg_relaxed(*ptr, &old, new) instead of: atomic64_cmpxchg relaxed(*ptr, old, new) != old The x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg. The generated code improves from: 3da: 31 c0 xor %eax,%eax 3dc: f0 48 0f b1 8a 38 01 lock cmpxchg %rcx,0x138(%rdx) 3e3: 00 00 3e5: 48 85 c0 test %rax,%rax 3e8: 48 0f 44 c1 cmove %rcx,%rax to: 3da: 31 c0 xor %eax,%eax 3dc: f0 48 0f b1 8a 38 01 lock cmpxchg %rcx,0x138(%rdx) 3e3: 00 00 3e5: 48 0f 44 c1 cmove %rcx,%rax Signed-off-by: Uros Bizjak <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: André Almeida <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 19298f4 commit 87347f1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/futex/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ static u64 get_inode_sequence_number(struct inode *inode)
185185
if (WARN_ON_ONCE(!new))
186186
continue;
187187

188-
old = atomic64_cmpxchg_relaxed(&inode->i_sequence, 0, new);
189-
if (old)
188+
old = 0;
189+
if (!atomic64_try_cmpxchg_relaxed(&inode->i_sequence, &old, new))
190190
return old;
191191
return new;
192192
}

0 commit comments

Comments
 (0)