futex: Use atomic64_inc_return() in get_inode_sequence_number()
PATCH 1/2 futex: Use atomic64_inc_return() in get_inode_sequence_number()
Use atomic64_inc_return(&ref) instead of atomic64_add_return(1, &ref) to use optimized implementation and ease register pressure around the primitive for targets that implement optimized variant.
--- kernel/futex/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/futex/core.c +1 -1
@@ -181,7 +181,7 @@ static u64 get_inode_sequence_number(struct inode *inode)return old;for (;;) { -u64 new =atomic64_add_return (1 , &i_seq); +u64 new =atomic64_inc_return (&i_seq);if (WARN_ON_ONCE (!new))continue ;
Signature · 1 line
2.46.2
PATCH 2/2 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
--- kernel/futex/core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/futex/core.c +3 -2
@@ -185,8 +185,9 @@ static u64 get_inode_sequence_number(struct inode *inode)if (WARN_ON_ONCE (!new))continue ; - old =atomic64_cmpxchg_relaxed (&inode->i_sequence,0 , new); -if (old) + old =0 ; +if (!atomic64_try_cmpxchg_relaxed (&inode->i_sequence, + &old, new))return old;return new; }
Signature · 1 line
2.46.2
Re: [PATCH 2/2] futex: Use atomic64_try_cmpxchg_relaxed() in get_inode_sequence_number()
Em 10/10/2024 04:10, Uros Bizjak escreveu:
Quoted 25 lines
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) != oldThe 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 003e5: 48 85 c0 test %rax,%rax 3e8: 48 0f 44 c1 cmove %rcx,%raxto:
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
Quoted 7 lines
Signed-off-by Uros Bizjak <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Darren Hart <[email protected]>Cc Davidlohr Bueso <[email protected]>Cc "André Almeida" <[email protected]>
[tip: locking/core] futex: Use atomic64_try_cmpxchg_relaxed() in get_inode_sequence_number()
In reply to Uros BizjakThe following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 87347f148061b48c3495fb61dcbad384760da9cf Gitweb: https://git.kernel.org/tip/87347f148061b48c3495fb61dcbad384760da9cf Author: Uros Bizjak <[email protected]> AuthorDate: Thu, 10 Oct 2024 09:10:05 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 17 Oct 2024 22:02:27 +02:00
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
--- kernel/futex/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/futex/core.c +2 -2
@@ -185,8 +185,8 @@ static u64 get_inode_sequence_number(struct inode *inode)if (WARN_ON_ONCE (!new))continue ; - old =atomic64_cmpxchg_relaxed (&inode->i_sequence,0 , new); -if (old) + old =0 ; +if (!atomic64_try_cmpxchg_relaxed (&inode->i_sequence, &old, new))return old;return new; }
Em 10/10/2024 04:10, Uros Bizjak escreveu:
Quoted 4 lines
Use
atomic64_inc_return(&ref)instead ofatomic64_add_return(1, &ref)to use optimized implementation and ease register pressure around the primitive for targets that implement optimized variant.
Quoted 8 lines
Signed-off-by Uros Bizjak <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Darren Hart <[email protected]>Cc Davidlohr Bueso <[email protected]>Cc "André Almeida" <[email protected]>---
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 19298f48694987fac843261c84e24834c255b451 Gitweb: https://git.kernel.org/tip/19298f48694987fac843261c84e24834c255b451 Author: Uros Bizjak <[email protected]> AuthorDate: Thu, 10 Oct 2024 09:10:04 +02:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 17 Oct 2024 22:02:27 +02:00
futex: Use atomic64_inc_return() in get_inode_sequence_number()
Use atomic64_inc_return(&ref) instead of atomic64_add_return(1, &ref) to use optimized implementation and ease register pressure around the primitive for targets that implement optimized variant.
--- kernel/futex/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/futex/core.c +1 -1
@@ -181,7 +181,7 @@ static u64 get_inode_sequence_number(struct inode *inode)return old;for (;;) { -u64 new =atomic64_add_return (1 , &i_seq); +u64 new =atomic64_inc_return (&i_seq);if (WARN_ON_ONCE (!new))continue ;