From: Davidlohr Bueso <dave@stgolabs.net>
To: Peter Zijlstra <peterz@infradead.org>
Cc: mingo@kernel.org, tglx@linutronix.de, Waiman.Long@hpe.com,
jason.low2@hp.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/4] locking/rwsem: Drop superfluous waiter refcount
Date: Mon, 9 May 2016 11:51:18 -0700 [thread overview]
Message-ID: <20160509185118.GC29630@linux-uzut.site> (raw)
In-Reply-To: <20160509161129.GC3408@twins.programming.kicks-ass.net>
On Mon, 09 May 2016, Peter Zijlstra wrote:
>> >So I think you're wrong here; imagine this:
>> >
>> >
>> > rwsem_down_read_failed() rwsem_wake()
>> > get_task_struct();
>> > raw_spin_lock_irq(&wait_lock);
>> > list_add_tail(&waiter.list, &wait_list);
>> > raw_spin_unlock_irq(&wait_lock);
>> > raw_spin_lock_irqsave(&wait_lock)
>> > __rwsem_do_wake()
>> > while (true) {
>> > set_task_state(tsk, TASK_UNINTERRUPTIBLE);
>> > waiter->task = NULL
>> > if (!waiter.task) // true
>> > break;
>> >
>> > __set_task_state(tsk, TASK_RUNNING);
>> >
>> > do_exit();
>> > wake_up_process(tsk); /* BOOM */
>>
>> I may be missing something, but rwsem_down_read_failed() will not return until
>> after the wakeup is done by the rwsem_wake() thread.
>
>The above never gets to schedule(), and even if it did, a spurious
>wakeup could've happened, no?
Ah indeed, you are most certainly correct. For some reason I was always
considering schedule() in the picture. Hmm I'll have to think about this
some more, but given the small chance of a waiter actually seeing the nil
task at the first iteration I'm wondering if we could just invert the code
and call schedule() before the task check. Saving the refcounts will serve
_all_ reader waiters otoh, but this would obviously need numbers...
Thanks,
Davidlohr
next prev parent reply other threads:[~2016-05-09 18:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-09 4:56 [PATCH -tip 0/4] locking/rwsem (xadd): Reader waiter optimizations Davidlohr Bueso
2016-05-09 4:56 ` [PATCH 1/4] locking/rwsem: Avoid stale ->count for rwsem_down_write_failed() Davidlohr Bueso
2016-05-09 5:36 ` Peter Hurley
2016-05-09 7:12 ` Peter Zijlstra
2016-05-09 14:29 ` Davidlohr Bueso
2016-05-09 4:56 ` [PATCH 2/4] locking/rwsem: Drop superfluous waiter refcount Davidlohr Bueso
2016-05-09 7:39 ` Peter Zijlstra
2016-05-09 15:56 ` Davidlohr Bueso
2016-05-09 16:11 ` Peter Zijlstra
2016-05-09 18:51 ` Davidlohr Bueso [this message]
2016-05-09 18:59 ` Peter Zijlstra
2016-05-09 4:56 ` [PATCH 3/4] locking/rwsem: Enable lockless waiter wakeup(s) Davidlohr Bueso
2016-05-09 7:48 ` Peter Zijlstra
2016-05-09 4:56 ` [PATCH 4/4] locking/rwsem: Rework zeroing reader waiter->task Davidlohr Bueso
2016-05-09 7:50 ` Peter Zijlstra
2016-05-10 1:31 ` [PATCH -tip 0/4] locking/rwsem (xadd): Reader waiter optimizations 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=20160509185118.GC29630@linux-uzut.site \
--to=dave@stgolabs.net \
--cc=Waiman.Long@hpe.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.