Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1314892
| From | Peter Zijlstra <peterz@infradead.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. |
| Date | 2016-01-22 12:10 +0100 |
| Message-ID | <qTHLj-3dT-1@gated-at.bofh.it> (permalink) |
| References | (1 earlier) <qTwwA-3Hx-59@gated-at.bofh.it> <qTFJv-1Dd-5@gated-at.bofh.it> <qTH8B-2I1-3@gated-at.bofh.it> <qTHBE-2UG-11@gated-at.bofh.it> <qTHBE-2UG-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, Jan 22, 2016 at 11:56:52AM +0100, Peter Zijlstra wrote:
> On Fri, Jan 22, 2016 at 11:53:12AM +0100, Peter Zijlstra wrote:
>
> > There might be other details, but this is the one that stood out.
>
> I think this also does the wrong thing for use_ww_ctx.
Something like so?
---
kernel/locking/mutex.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
index 0551c219c40e..070a0ac34aa7 100644
--- a/kernel/locking/mutex.c
+++ b/kernel/locking/mutex.c
@@ -512,6 +512,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
struct task_struct *task = current;
struct mutex_waiter waiter;
unsigned long flags;
+ bool acquired;
int ret;
preempt_disable();
@@ -543,6 +544,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
lock_contended(&lock->dep_map, ip);
for (;;) {
+ acquired = false;
/*
* Lets try to take the lock again - this is needed even if
* we get here for the first time (shortly after failing to
@@ -577,7 +579,16 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
/* didn't get the lock, go to sleep: */
spin_unlock_mutex(&lock->wait_lock, flags);
schedule_preempt_disabled();
+
+ if (mutex_is_locked(lock))
+ acquired = mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx);
+
spin_lock_mutex(&lock->wait_lock, flags);
+
+ if (acquired) {
+ atomic_set(&lock->count, -1);
+ break;
+ }
}
__set_task_state(task, TASK_RUNNING);
@@ -587,6 +598,9 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
atomic_set(&lock->count, 0);
debug_mutex_free_waiter(&waiter);
+ if (acquired)
+ goto unlock;
+
skip_wait:
/* got the lock - cleanup and rejoice! */
lock_acquired(&lock->dep_map, ip);
@@ -597,6 +611,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
ww_mutex_set_context_slowpath(ww, ww_ctx);
}
+unlock:
spin_unlock_mutex(&lock->wait_lock, flags);
preempt_enable();
return 0;
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Ding Tianhong <dingtianhong@huawei.com> - 2016-01-21 10:40 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Tim Chen <tim.c.chen@linux.intel.com> - 2016-01-21 22:30 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Davidlohr Bueso <dave@stgolabs.net> - 2016-01-22 03:50 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-01-22 04:20 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2016-01-22 03:50 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Waiman Long <waiman.long@hpe.com> - 2016-01-22 00:10 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Davidlohr Bueso <dave@stgolabs.net> - 2016-01-22 07:20 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Waiman Long <waiman.long@hpe.com> - 2016-01-22 14:40 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Davidlohr Bueso <dave@stgolabs.net> - 2016-01-22 17:50 +0100
[PATCH] locking/mutex: Allow next waiter lockless wakeup Davidlohr Bueso <dave@stgolabs.net> - 2016-01-25 03:30 +0100
Re: [PATCH] locking/mutex: Allow next waiter lockless wakeup Waiman Long <waiman.long@hpe.com> - 2016-01-26 00:10 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Peter Zijlstra <peterz@infradead.org> - 2016-01-22 10:00 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Jason Low <jason.low2@hp.com> - 2016-01-22 11:30 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Peter Zijlstra <peterz@infradead.org> - 2016-01-22 12:00 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Peter Zijlstra <peterz@infradead.org> - 2016-01-22 12:00 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Peter Zijlstra <peterz@infradead.org> - 2016-01-22 12:10 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Waiman Long <waiman.long@hpe.com> - 2016-01-22 15:10 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Ding Tianhong <dingtianhong@huawei.com> - 2016-01-24 09:10 +0100
Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL. Waiman Long <waiman.long@hpe.com> - 2016-01-22 14:50 +0100
csiph-web