kexec: Use atomic_try_cmpxchg_acquire() in kexec_trylock()
Subsystems (3)
PATCH 1/1 kexec: Use atomic_try_cmpxchg_acquire() in kexec_trylock()
Use atomic_try_cmpxchg_acquire(*ptr, &old, new) instead of atomic_cmpxchg_acquire(*ptr, old, new) == old in kexec_trylock(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg.
--- kernel/kexec_internal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/kexec_internal.h +2 -1
@@ -23,7 +23,8 @@ int kimage_is_destination_range(struct kimage *image,extern atomic_t __kexec_lock;static inline bool kexec_trylock (void ) { -return atomic_cmpxchg_acquire (&__kexec_lock,0 ,1 ) ==0 ; +int old =0 ; +return atomic_try_cmpxchg_acquire (&__kexec_lock, &old,1 ); }static inline void kexec_unlock (void ) {
Signature · 1 line
2.42.0
Quoted 4 lines · Uros Bizjak
Use
atomic_try_cmpxchg_acquire(*ptr, &old, new)instead ofatomic_cmpxchg_acquire(*ptr, old, new)== old inkexec_trylock(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg.
Seems it can simplify code even though on non-x86 arch, should we replace atomic_try_cmpxchg_acquire() with atomic_try_cmpxchg_acquire() in all similar places?
For this one,
Quoted 30 lines
Signed-off-by Uros Bizjak <[email protected]>Cc Eric Biederman <[email protected]>--- kernel/kexec_internal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/kexec_internal.h +2
-1@@ -23,7 +23,8 @@ int kimage_is_destination_range(struct kimage *image,extern atomic_t __kexec_lock;static inline bool kexec_trylock (void ) { -return atomic_cmpxchg_acquire (&__kexec_lock,0 ,1 ) ==0 ; +int old =0 ; +return atomic_try_cmpxchg_acquire (&__kexec_lock, &old,1 ); }static inline void kexec_unlock (void ) {Signature · 7 lines
2.42.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 10 lines · Baoquan He
Quoted 4 lines · Uros Bizjak
Use
atomic_try_cmpxchg_acquire(*ptr, &old, new)instead ofatomic_cmpxchg_acquire(*ptr, old, new)== old inkexec_trylock(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg.Seems it can simplify code even though on non-x86 arch, should we replace
atomic_try_cmpxchg_acquire()withatomic_try_cmpxchg_acquire()in all similar places?
Yes, the change is beneficial also for non-x86 architectures, please see analysis at thread [1]. I've been looking through the kernel sources for these places for quite some time, and I believe I have changed most of the places. The change is relatively straightforward, and immediately results in a better code.
[1] https://lore.kernel.org/lkml/[email protected]/
Quoted 4 lines
For this one,
Acked-by Baoquan He <[email protected]>
Thanks,
Uros.
Quoted 12 lines · Uros Bizjak
Quoted 10 lines · Baoquan He
Quoted 4 lines · Uros Bizjak
Use
atomic_try_cmpxchg_acquire(*ptr, &old, new)instead ofatomic_cmpxchg_acquire(*ptr, old, new)== old inkexec_trylock(). x86 CMPXCHG instruction returns success in ZF flag, so this change saves a compare after cmpxchg.Seems it can simplify code even though on non-x86 arch, should we replace
atomic_try_cmpxchg_acquire()withatomic_try_cmpxchg_acquire()in all similar places?
Quoted 7 lines
Yes, the change is beneficial also for non-x86 architectures, please see analysis at thread [1]. I've been looking through the kernel sources for these places for quite some time, and I believe I have changed most of the places. The change is relatively straightforward, and immediately results in a better code.
Good to know, thanks for telling.