From: Waiman Long <waiman.long@hp.com>
To: Davidlohr Bueso <davidlohr@hp.com>
Cc: peterz@infradead.org, mingo@kernel.org, jason.low2@hp.com,
scott.norton@hp.com, aswin@hp.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH -tip] locking/mutexes: Avoid bogus wakeups after lock stealing
Date: Fri, 15 Aug 2014 13:41:33 -0400 [thread overview]
Message-ID: <53EE464D.7060803@hp.com> (raw)
In-Reply-To: <1408037423.12776.6.camel@buesod1.americas.hpqcorp.net>
On 08/14/2014 01:30 PM, Davidlohr Bueso wrote:
> On Thu, 2014-08-14 at 13:17 -0400, Waiman Long wrote:
>>
>> I still think it is better to do that after spin_lock_mutex().
> As mentioned, this causes all sorts of hung tasks when the another task
> enters the slowpath when locking. There's a big fat comment above.
>
>> In
>> addition, the atomic_set() is racy. It is better to something like
> Why is it racy? Atomically setting the lock to -1 given that the lock
> was stolen should be safe. The alternative we discussed with Jason was
> to set the counter to -1 in the spinning path. But given that we need to
> serialize the counter check with the list_empty() check that would
> require the wait_lock. This is very messy and unnecessarily complicates
> things.
>
Let's consider the following scenario:
Task 1 Task 2
------ ------
steal the lock
if (mutex_has_owner) { :
: <---- a long interrupt mutex_unlock() [cnt = 1]
atomic_set(cnt, -1);
return;
}
Now the lock is no longer available and all the tasks that are trying
to get it will hang. IOW, you cannot set the count to -1 unless you
are sure it is 0 to begin with.
>> if (atomic_cmpxchg(&lock->count, 0, -1)<= 0)
>> return;
> Not really because some archs leave the lock at 1 after the unlock
> fastpath.
Yes, I know that. I am saying x86 won't get any benefit from this patch.
-Longman
prev parent reply other threads:[~2014-08-15 17:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-14 5:57 [PATCH -tip] locking/mutexes: Avoid bogus wakeups after lock stealing Davidlohr Bueso
2014-08-14 17:17 ` Waiman Long
2014-08-14 17:30 ` Davidlohr Bueso
2014-08-15 17:41 ` Waiman Long [this message]
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=53EE464D.7060803@hp.com \
--to=waiman.long@hp.com \
--cc=aswin@hp.com \
--cc=davidlohr@hp.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=scott.norton@hp.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