From: Waiman Long <waiman.long@hpe.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Pan Xinhui <xinhui@linux.vnet.ibm.com>,
Ingo Molnar <mingo@redhat.com>, <linux-kernel@vger.kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
Scott J Norton <scott.norton@hpe.com>,
Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH v2 2/5] locking/pvqspinlock: Fix missed PV wakeup problem
Date: Fri, 15 Jul 2016 16:06:37 -0400 [thread overview]
Message-ID: <5789424D.7020908@hpe.com> (raw)
In-Reply-To: <20160715100703.GQ30154@twins.programming.kicks-ass.net>
On 07/15/2016 06:07 AM, Peter Zijlstra wrote:
> On Fri, Jul 15, 2016 at 05:39:46PM +0800, Pan Xinhui wrote:
>>> I'm thinking you're trying to say this:
>>>
>>>
>>> CPU0 CPU1 CPU2
>>>
>>> __pv_queued_spin_unlock_slowpath()
>>> ...
>>> smp_store_release(&l->locked, 0);
>>> __pv_queued_spin_lock_slowpath()
>>> ...
>>> pv_queued_spin_steal_lock()
>>> cmpxchg(&l->locked, 0, _Q_LOCKED_VAL) == 0
>>>
>>>
>>> pv_wait_head_or_lock()
>>>
>>> pv_kick(node->cpu); ----------------------> pv_wait(&l->locked, _Q_SLOW_VAL);
>>>
>>> __pv_queued_spin_unlock()
>>> cmpxchg(&l->locked, _Q_LOCKED_VAL, 0) == _Q_LOCKED_VAL
>>>
>>> for () {
>>> trylock_clear_pending();
>>> cpu_relax();
>>> }
>>>
>>> pv_wait(&l->locked, _Q_SLOW_VAL);
>>>
>>>
>>> Which is indeed 'bad', but not fatal, note that the later pv_wait() will
>>> not in fact go wait, since l->locked will _not_ be _Q_SLOW_VAL.
>> the problem is that "this later pv_wait will do nothing as l->locked
>> is not _Q_SLOW_VAL", So it is not paravirt friendly then. we will go
>> into the trylock loop again and again until the lock is unlocked.
> Agreed, which is 'bad'. But the patch spoke about a missing wakeup,
> which is worse, as that would completely inhibit progress.
Sorry, it is my mistake. There is no missing pv_wait().
>> So if we are kicked by the unlock_slowpath, and the lock is stealed by
>> someone else, we need hash its node again and set l->locked to
>> _Q_SLOW_VAL, then enter pv_wait.
> Right, let me go think about this a bit.
Yes, the purpose of this patch is to do exactly that. Let's the queue
head vCPU sleeps until the lock holder release the lock and wake the
queue head vCPU up.
>
>> but I am worried about lock stealing. could the node in the queue
>> starve for a long time? I notice the latency of pv_wait on an
>> over-commited guest can be bigger than 300us. I have not seen such
>> starving case, but I think it is possible to happen.
> I share that worry, which is why we limit the steal attempt to one.
> But yes, theoretically its possible to starve things AFAICT.
>
> We've not come up with sensible way to completely avoid starvation.
If you guys are worrying about lock constantly getting stolen between
pv_kick() of queue head vCPU and it is ready to take the lock, we can
keep the pending bit set across pv_wait() if it is the 2nd or later time
that pv_wait() is called. That will ensure that no lock stealing can
happen and cap the maximum wait time to about 2x (spin + pv_wait). I
will add that patch to my patch series.
Cheers,
Longman
next prev parent reply other threads:[~2016-07-15 20:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-31 16:53 [PATCH v2 0/5] locking/pvqspinlock: Fix missed PV wakeup & support PPC Waiman Long
2016-05-31 16:53 ` [PATCH v2 1/5] locking/pvstat: Separate wait_again and spurious wakeup stats Waiman Long
2016-08-10 18:07 ` [tip:locking/core] " tip-bot for Waiman Long
2016-05-31 16:53 ` [PATCH v2 2/5] locking/pvqspinlock: Fix missed PV wakeup problem Waiman Long
2016-07-15 8:47 ` Peter Zijlstra
2016-07-15 9:39 ` Pan Xinhui
2016-07-15 10:07 ` Peter Zijlstra
2016-07-15 16:35 ` Peter Zijlstra
2016-07-16 1:16 ` Boqun Feng
2016-07-17 23:07 ` Waiman Long
2016-07-17 23:10 ` Waiman Long
2016-07-17 23:22 ` Wanpeng Li
2016-07-17 22:52 ` Waiman Long
2016-07-21 6:40 ` xinhui
2016-07-15 20:06 ` Waiman Long [this message]
2016-07-15 19:47 ` Waiman Long
2016-05-31 16:53 ` [PATCH v2 3/5] locking/pvqspinlock: Make pv_unhash() atomic Waiman Long
2016-05-31 16:53 ` [PATCH v2 4/5] locking/pvstat: Add stat counter to track _Q_SLOW_VAL race Waiman Long
2016-05-31 16:53 ` [PATCH v2 5/5] locking/pvqspinlock: Add lock holder CPU argument to pv_wait() Waiman Long
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=5789424D.7020908@hpe.com \
--to=waiman.long@hpe.com \
--cc=boqun.feng@gmail.com \
--cc=doug.hatch@hpe.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=scott.norton@hpe.com \
--cc=xinhui@linux.vnet.ibm.com \
/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).