public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] x86: optimize a bit __raw_read_trylock
@ 2009-01-25 20:50 Frederic Weisbecker
  2009-01-26 13:07 ` Ingo Molnar
  0 siblings, 1 reply; 2+ messages in thread
From: Frederic Weisbecker @ 2009-01-25 20:50 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel, Frederic Weisbecker

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>
---
 arch/x86/include/asm/spinlock.h |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
index 2bd6b11..139b424 100644
--- a/arch/x86/include/asm/spinlock.h
+++ b/arch/x86/include/asm/spinlock.h
@@ -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;
-- 
1.6.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-26 13:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-25 20:50 [PATCH 1/2] x86: optimize a bit __raw_read_trylock Frederic Weisbecker
2009-01-26 13:07 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox