x86: micro-optimize __raw_read_trylock()
authorFrederic Weisbecker <fweisbec@gmail.com>
Sun, 25 Jan 2009 20:50:13 +0000 (12:50 -0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 26 Jan 2009 13:06:36 +0000 (14:06 +0100)
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 <fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
arch/x86/include/asm/spinlock.h

index d17c919..4d3dcc5 100644 (file)
@@ -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;