x86: optimize a bit __raw_read_trylock
Subsystems (2)
PATCH 1/2 x86: optimize a bit __raw_read_trylock
The current version of __raw_read_trylock starts with decrementing the lock and read its new value as a separate operation after that.
That makes 3 dereferences (read, write (after sub), read) whereas a single atomic_dec_return does only two pointers dereferences (read, write).
--- arch/x86/include/asm/spinlock.h | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
arch/x86/include/asm/spinlock.h +1 -2
@@ -267,8 +267,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock) {atomic_t *count = (atomic_t *)lock; -atomic_dec (count); -if (atomic_read (count) >=0 ) +if (atomic_dec_return (count) >=0 )return 1 ;atomic_inc (count);return 0 ;
Signature · 1 line
1.6.1
Quoted 16 lines · Frederic Weisbecker
The current version of
__raw_read_trylockstarts with decrementing the lock and read its new value as a separate operation after that.That makes 3 dereferences (read, write (after sub), read) whereas a single
atomic_dec_returndoes only two pointers dereferences (read, write).Signed-off-by Frederic Weisbecker <[email protected]>--- arch/x86/include/asm/spinlock.h | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)arch/x86/include/asm/spinlock.h +0
-0
arch/x86/include/asm/spinlock.h static inline int __raw_read_trylock(raw_rwlock_t *lock) · line 273
Quoted 9 lines
arch/x86/include/asm/spinlock.h +1
-2@@ -267,8 +267,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock) {atomic_t *count = (atomic_t *)lock; -atomic_dec (count); -if (atomic_read (count) >=0 ) +if (atomic_dec_return (count) >=0 )return 1 ;atomic_inc (count);return 0 ;
nice one ... applied it to tip/x86/asm, thanks Frederic!
Ingo