From: Frederic Weisbecker Date: Sun, 25 Jan 2009 20:50:13 +0000 (-0800) Subject: x86: micro-optimize __raw_read_trylock() X-Git-Tag: v2.6.31-rc1~383^2~508^2~166^2 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=2d4d57db692ea790e185656516e6ebe8791f1788;p=~shefty%2Frdma-dev.git x86: micro-optimize __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). Signed-off-by: Frederic Weisbecker Signed-off-by: Ingo Molnar --- diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h index d17c91981da..4d3dcc51cac 100644 --- a/arch/x86/include/asm/spinlock.h +++ b/arch/x86/include/asm/spinlock.h @@ -329,8 +329,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;