From: Chris Friesen <chris.friesen@windriver.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: rt-users <linux-rt-users@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: semantics of reader/writer semaphores in rt patch
Date: Mon, 27 Oct 2014 09:02:15 -0600 [thread overview]
Message-ID: <544E5E77.1000000@windriver.com> (raw)
In-Reply-To: <alpine.DEB.2.11.1410252354030.5308@nanos>
On 10/25/2014 04:19 PM, Thomas Gleixner wrote:
> On Thu, 23 Oct 2014, Chris Friesen wrote:
>
>> I recently noticed that when CONFIG_PREEMPT_RT_FULL is enabled we the
>> semantics change. From "include/linux/rwsem_rt.h":
>>
>> * Note that the semantics are different from the usual
>> * Linux rw-sems, in PREEMPT_RT mode we do not allow
>> * multiple readers to hold the lock at once, we only allow
>> * a read-lock owner to read-lock recursively. This is
>> * better for latency, makes the implementation inherently
>> * fair and makes it simpler as well.
>>
>> How is this valid? It seems to me that there are any number of code paths
>> that could depend on having multiple threads of execution be able to hold the
>> reader lock simultaneously. Something as simple as:
>>
>> thread A:
>> take rw_semaphore X for reading
>> take lock Y, modify data, release lock Y
>> wake up thread B
>> wait on conditional protected by lock Y
>> free rw_semaphore X
>>
>> thread B:
>> take rw_semaphore X for reading
>> wait on conditional protected by lock Y
>> send message to wake up thread A
>> free rw_semaphore X
>
> I don't see why B should wake A without changing the conditional. A
> won't make progress by being woken by B as the conditional does not
> magically change just because B wakes A.
>
> So what you wanted to say is:
>
> thread B:
> take rw_semaphore X for reading
> wait on conditional protected by lock Y
> + take lock Y, modify data, release lock Y
> send message to wake up thread A
> free rw_semaphore X
>
> Otherwise your example does not make any sense at all. And that has
> some serious non RT related implications.
Yes, your reformulated version is what I meant to say. Sorry for any
confusion.
>> Does the RT kernel just disallow this sort of algorithm?
>
> Yes. For a good reason. Let's add thread C
>
> A B C
> down_read(X)
> down_write(X)
> lock(Y)
> modify data
> unlock(Y)
> wake(B)
> down_read(X)
>
> Due to the mainline rwsem fairness semantics:
>
> A holds X, C is blocked on A and B is blocked on A.
>
> Deadlock, without RT and the single reader restriction being involved.
Crap, I had forgotten about the fairness semantics stuff. That makes
perfect sense.
Thanks for the explanation.
Chris
prev parent reply other threads:[~2014-10-27 15:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-23 19:27 semantics of reader/writer semaphores in rt patch Chris Friesen
2014-10-25 22:19 ` Thomas Gleixner
2014-10-25 22:21 ` Thomas Gleixner
2014-10-26 7:42 ` Peter Zijlstra
2014-10-26 8:47 ` Peter Zijlstra
2014-10-27 15:02 ` Chris Friesen [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=544E5E77.1000000@windriver.com \
--to=chris.friesen@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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.