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.

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.

Link: https://lkml.kernel.org/r/20240719103937.53742-1-ubizjak@gmail.com
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Uros Bizjak and committed by
Andrew Morton
acf02be3 e24f4de8

+2 -1
+2 -1
kernel/kexec_internal.h
··· 23 23 extern atomic_t __kexec_lock; 24 24 static inline bool kexec_trylock(void) 25 25 { 26 - return atomic_cmpxchg_acquire(&__kexec_lock, 0, 1) == 0; 26 + int old = 0; 27 + return atomic_try_cmpxchg_acquire(&__kexec_lock, &old, 1); 27 28 } 28 29 static inline void kexec_unlock(void) 29 30 {