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.

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 <ubizjak@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: André Almeida <andrealmeid@igalia.com>
Link: https://lore.kernel.org/all/20241010071023.21913-2-ubizjak@gmail.com

authored by

Uros Bizjak and committed by
Thomas Gleixner
87347f14 19298f48

+2 -2
+2 -2
kernel/futex/core.c
··· 185 185 if (WARN_ON_ONCE(!new)) 186 186 continue; 187 187 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)) 190 190 return old; 191 191 return new; 192 192 }