Commit ac6e60ee authored by Chris Mason's avatar Chris Mason Committed by Ingo Molnar

mutex: adaptive spinnning, performance tweaks

Spin more agressively. This is less fair but also markedly faster.

The numbers:

 * dbench 50 (higher is better):
  spin        1282MB/s
  v10         548MB/s
  v10 no wait 1868MB/s

 * 4k creates (numbers in files/second higher is better):
  spin        avg 200.60 median 193.20 std 19.71 high 305.93 low 186.82
  v10         avg 180.94 median 175.28 std 13.91 high 229.31 low 168.73
  v10 no wait avg 232.18 median 222.38 std 22.91 high 314.66 low 209.12

 * File stats (numbers in seconds, lower is better):
  spin        2.27s
  v10         5.1s
  v10 no wait 1.6s

( The source changes are smaller than they look, I just moved the
  need_resched checks in __mutex_lock_common after the cmpxchg. )
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 0d66bf6d
...@@ -170,12 +170,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -170,12 +170,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
for (;;) { for (;;) {
struct thread_info *owner; struct thread_info *owner;
/*
* If there are pending waiters, join them.
*/
if (!list_empty(&lock->wait_list))
break;
/* /*
* If there's an owner, wait for it to either * If there's an owner, wait for it to either
* release the lock or go to sleep. * release the lock or go to sleep.
...@@ -184,6 +178,13 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -184,6 +178,13 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
if (owner && !mutex_spin_on_owner(lock, owner)) if (owner && !mutex_spin_on_owner(lock, owner))
break; break;
if (atomic_cmpxchg(&lock->count, 1, 0) == 1) {
lock_acquired(&lock->dep_map, ip);
mutex_set_owner(lock);
preempt_enable();
return 0;
}
/* /*
* When there's no owner, we might have preempted between the * When there's no owner, we might have preempted between the
* owner acquiring the lock and setting the owner field. If * owner acquiring the lock and setting the owner field. If
...@@ -193,13 +194,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass, ...@@ -193,13 +194,6 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
if (!owner && (need_resched() || rt_task(task))) if (!owner && (need_resched() || rt_task(task)))
break; break;
if (atomic_cmpxchg(&lock->count, 1, 0) == 1) {
lock_acquired(&lock->dep_map, ip);
mutex_set_owner(lock);
preempt_enable();
return 0;
}
/* /*
* The cpu_relax() call is a compiler barrier which forces * The cpu_relax() call is a compiler barrier which forces
* everything in this loop to be re-loaded. We don't need * everything in this loop to be re-loaded. We don't need
......
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