From: Waiman Long <longman@redhat.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
mazhenhua <mazhenhua@xiaomi.com>, Hillf Danton <hdanton@sina.com>,
Maria Yu <quic_aiquny@quicinc.com>
Subject: Re: [PATCH v4] locking/rwsem: Make handoff bit handling more consistent
Date: Mon, 15 Nov 2021 17:29:10 -0500 [thread overview]
Message-ID: <ce034084-364b-e30f-cb7c-d6434afe3a7d@redhat.com> (raw)
In-Reply-To: <YZKEc+SgijOcB+0W@hirez.programming.kicks-ass.net>
On 11/15/21 11:01, Peter Zijlstra wrote:
> On Sun, Nov 14, 2021 at 10:38:57PM -0500, Waiman Long wrote:
>> On 11/12/21 07:10, Peter Zijlstra wrote:
>>> Argh, rwsem_mark_wake() doesn't clear HANDOFF when list_empty(), and
>>> write_slowpath() is *far* too clever about all of this.
>> rwsem_mark_wake() does clear the HANDOFF flag if it was set.
> Argh, yeah, I got confused by the whole !woken case, but that case won't
> ever hit list_empty() either. Perhaps that stuff could use a bit of a
> reflow too.
I think your modification already have included the rewrite for that part.
>
>>>> @@ -1098,7 +1110,7 @@ rwsem_down_write_slowpath(struct rw_semaphore *sem, int state)
>>>> * In this case, we attempt to acquire the lock again
>>>> * without sleeping.
>>>> */
>>>> - if (wstate == WRITER_HANDOFF) {
>>>> + if (waiter.handoff_set) {
>>> I'm thinking this wants to be something like:
>>>
>>> if (rwsem_first_waiter(sem) == &waiter && waiter.handoff_set) {
>> handoff_set flag is only set when the waiter becomes the first.
> Yes, but a random waiter can wake up and see it be set and also start
> spinning.
The handoff_set flag can only be true for a first waiter. A random
waiter in the middle of a wait queue will never has this flag set.
This flag is set in two places in rwsem_try_write_lock():
1)
if (has_handoff && !first)
return false;
new = count;
if (count & RWSEM_LOCK_MASK) {
/*
* Only the first waiter can inherit a
previously set
* handoff bit.
*/
waiter->handoff_set = has_handoff;
handoff_set can only be set to true here if first is also true. In that
case, it will also return false immediately afterward.
2)
if (new & RWSEM_FLAG_HANDOFF) {
waiter->handoff_set = true;
lockevent_inc(rwsem_wlock_handoff);
return false;
}
Again, only first waiter will have a chance of setting the handoff bit
and have handoff_set set to true.
>>>> enum owner_state owner_state;
>>>> preempt_disable();
>>> @@ -575,6 +610,11 @@ static inline bool rwsem_try_write_lock(
>>> return false;
>>> }
>>> + /*
>>> + * Have rwsem_try_write_lock() fully imply rwsem_del_waiter() on
>>> + * success.
>>> + */
>>> + list_del(&waiter->list);
>>> rwsem_set_owner(sem);
>>> return true;
>>> }
>>> @@ -1128,16 +1153,14 @@ rwsem_down_write_slowpath(struct rw_sema
>>> raw_spin_lock_irq(&sem->wait_lock);
>>> }
>>> __set_current_state(TASK_RUNNING);
>>> - list_del(&waiter.list);
>> + rwsem_del_waiter(sem, &waiters); ?
> I tried that, but then we get an extra atomic in this path. As is I made
> try_write_lock() do the full del_waiter, see the hunk above.
You are right. I missed your change in rwsem_try_write_lock().
Thanks,
Longman
next prev parent reply other threads:[~2021-11-16 0:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-12 4:07 [PATCH v4] locking/rwsem: Make handoff bit handling more consistent Waiman Long
2021-11-12 12:10 ` Peter Zijlstra
2021-11-15 3:38 ` Waiman Long
2021-11-15 16:01 ` Peter Zijlstra
2021-11-15 22:29 ` Waiman Long [this message]
2021-11-15 23:07 ` Peter Zijlstra
2021-11-16 0:09 ` Waiman Long
2021-11-15 15:45 ` Aiqun(Maria) Yu
2021-11-15 16:58 ` 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=ce034084-364b-e30f-cb7c-d6434afe3a7d@redhat.com \
--to=longman@redhat.com \
--cc=dave@stgolabs.net \
--cc=hdanton@sina.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mazhenhua@xiaomi.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=quic_aiquny@quicinc.com \
--cc=will@kernel.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