Commit 157697eb authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] preempt spinlock efficiency fix

Patch from: jak@rudolph.ccur.com (Joe Korty)

The new, preemptable spin_lock() spins on an atomic bus-locking read/write
instead of an ordinary read, as the original spin_lock implementation did.
Perhaps that is the source of the inefficiency being seen.

Attached sample code compiles but is untested and incomplete (present
only to illustrate the idea).
parent df38988c
......@@ -2465,15 +2465,12 @@ void __preempt_spin_lock(spinlock_t *lock)
_raw_spin_lock(lock);
return;
}
while (!_raw_spin_trylock(lock)) {
if (need_resched()) {
preempt_enable_no_resched();
__cond_resched();
preempt_disable();
}
cpu_relax();
}
do {
preempt_enable();
while (spin_is_locked(lock))
cpu_relax();
preempt_disable();
} while (!_raw_spin_trylock(lock));
}
void __preempt_write_lock(rwlock_t *lock)
......@@ -2483,13 +2480,11 @@ void __preempt_write_lock(rwlock_t *lock)
return;
}
while (!_raw_write_trylock(lock)) {
if (need_resched()) {
preempt_enable_no_resched();
__cond_resched();
preempt_disable();
}
cpu_relax();
}
do {
preempt_enable();
while (rwlock_is_locked(lock))
cpu_relax();
preempt_disable();
} while (!_raw_write_trylock(lock));
}
#endif
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