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) ...@@ -2465,15 +2465,12 @@ void __preempt_spin_lock(spinlock_t *lock)
_raw_spin_lock(lock); _raw_spin_lock(lock);
return; return;
} }
do {
while (!_raw_spin_trylock(lock)) { preempt_enable();
if (need_resched()) { while (spin_is_locked(lock))
preempt_enable_no_resched();
__cond_resched();
preempt_disable();
}
cpu_relax(); cpu_relax();
} preempt_disable();
} while (!_raw_spin_trylock(lock));
} }
void __preempt_write_lock(rwlock_t *lock) void __preempt_write_lock(rwlock_t *lock)
...@@ -2483,13 +2480,11 @@ void __preempt_write_lock(rwlock_t *lock) ...@@ -2483,13 +2480,11 @@ void __preempt_write_lock(rwlock_t *lock)
return; return;
} }
while (!_raw_write_trylock(lock)) { do {
if (need_resched()) { preempt_enable();
preempt_enable_no_resched(); while (rwlock_is_locked(lock))
__cond_resched();
preempt_disable();
}
cpu_relax(); cpu_relax();
} preempt_disable();
} while (!_raw_write_trylock(lock));
} }
#endif #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