From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Jason Low <jason.low2@hp.com>,
Ding Tianhong <dingtianhong@huawei.com>,
Ingo Molnar <mingo@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Davidlohr Bueso <dave@stgolabs.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
"Paul E. McKenney" <paulmck@us.ibm.com>,
Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <Will.Deacon@arm.com>,
Tim Chen <tim.c.chen@linux.intel.com>,
Waiman Long <Waiman.Long@hp.com>
Subject: Re: [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL.
Date: Fri, 22 Jan 2016 08:59:56 -0500 [thread overview]
Message-ID: <56A235DC.2060900@hpe.com> (raw)
In-Reply-To: <20160122110653.GF6375@twins.programming.kicks-ass.net>
On 01/22/2016 06:06 AM, Peter Zijlstra wrote:
> 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?
I think that should work. My only minor concern is that putting the
waiter spinner at the end of the OSQ will take it longer to get the
lock, but that shouldn't be a big issue.
> ---
> 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;
Cheers,
Longman
next prev parent reply other threads:[~2016-01-22 14:00 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-21 9:29 [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL Ding Tianhong
2016-01-21 21:23 ` Tim Chen
2016-01-22 2:41 ` Paul E. McKenney
2016-01-22 2:48 ` Davidlohr Bueso
2016-01-22 3:13 ` Paul E. McKenney
2016-01-21 23:02 ` Waiman Long
2016-01-22 6:09 ` Davidlohr Bueso
2016-01-22 13:38 ` Waiman Long
2016-01-22 16:46 ` Davidlohr Bueso
2016-01-25 2:23 ` [PATCH] locking/mutex: Allow next waiter lockless wakeup Davidlohr Bueso
2016-01-25 23:02 ` Waiman Long
2016-02-29 11:21 ` [tip:locking/core] " tip-bot for Davidlohr Bueso
2016-01-22 8:54 ` [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL Peter Zijlstra
2016-01-22 10:20 ` Jason Low
2016-01-22 10:53 ` Peter Zijlstra
2016-01-22 10:56 ` Peter Zijlstra
2016-01-22 11:06 ` Peter Zijlstra
2016-01-22 13:59 ` Waiman Long [this message]
2016-01-24 8:03 ` Ding Tianhong
2016-01-29 9:53 ` Peter Zijlstra
2016-01-30 1:18 ` Ding Tianhong
2016-02-01 3:29 ` huang ying
2016-02-01 3:35 ` Huang, Ying
2016-02-01 10:08 ` [PATCH] locking/mutex: Avoid spinner vs waiter starvation Peter Zijlstra
2016-02-02 21:19 ` Davidlohr Bueso
2016-02-03 7:10 ` Ding Tianhong
2016-02-03 19:24 ` Davidlohr Bueso
2016-02-04 1:20 ` Ding Tianhong
2016-02-12 18:33 ` Waiman Long
2016-02-03 22:07 ` Waiman Long
2016-02-04 1:35 ` Jason Low
2016-02-04 8:55 ` huang ying
2016-02-04 22:49 ` Jason Low
2016-01-22 13:41 ` [PATCH RFC] locking/mutexes: don't spin on owner when wait list is not NULL Waiman Long
-- strict thread matches above, loose matches on Subject: below --
2016-01-21 6:53 [PATCH RFC ] " Ding Tianhong
2016-01-21 7:29 ` Ingo Molnar
2016-01-21 9:04 ` Ding Tianhong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56A235DC.2060900@hpe.com \
--to=waiman.long@hpe.com \
--cc=Waiman.Long@hp.com \
--cc=Will.Deacon@arm.com \
--cc=dave@stgolabs.net \
--cc=dingtianhong@huawei.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=paulmck@us.ibm.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tim.c.chen@linux.intel.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).