Commit 8b0a7bd8 authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

[PATCH] Don't busy-lock-loop in preemptable spinlocks

Paul Mackerras points out that doing the _raw_spin_trylock each time
through the loop will generate tons of unnecessary bus traffic.
Instead, after we fail to get the lock we should poll it with simple
loads until we see that it is clear and then retry the atomic op. 
Assuming a reasonable cache design, the loads won't generate any bus
traffic until another cpu writes to the cacheline containing the lock.

Agreed.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 7619fe4e
......@@ -173,7 +173,7 @@ EXPORT_SYMBOL(_write_lock);
* (We do this in a function because inlining it would be excessive.)
*/
#define BUILD_LOCK_OPS(op, locktype) \
#define BUILD_LOCK_OPS(op, locktype, is_locked_fn) \
void __lockfunc _##op##_lock(locktype *lock) \
{ \
preempt_disable(); \
......@@ -183,6 +183,7 @@ void __lockfunc _##op##_lock(locktype *lock) \
preempt_enable(); \
if (!(lock)->break_lock) \
(lock)->break_lock = 1; \
while (is_locked_fn(lock) && (lock)->break_lock) \
cpu_relax(); \
preempt_disable(); \
} \
......@@ -204,6 +205,7 @@ unsigned long __lockfunc _##op##_lock_irqsave(locktype *lock) \
preempt_enable(); \
if (!(lock)->break_lock) \
(lock)->break_lock = 1; \
while (is_locked_fn(lock) && (lock)->break_lock) \
cpu_relax(); \
preempt_disable(); \
} \
......@@ -244,9 +246,9 @@ EXPORT_SYMBOL(_##op##_lock_bh)
* _[spin|read|write]_lock_irqsave()
* _[spin|read|write]_lock_bh()
*/
BUILD_LOCK_OPS(spin, spinlock_t);
BUILD_LOCK_OPS(read, rwlock_t);
BUILD_LOCK_OPS(write, rwlock_t);
BUILD_LOCK_OPS(spin, spinlock_t, spin_is_locked);
BUILD_LOCK_OPS(read, rwlock_t, rwlock_is_locked);
BUILD_LOCK_OPS(write, rwlock_t, spin_is_locked);
#endif /* CONFIG_PREEMPT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment