From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Daniel Lustig <dlustig@nvidia.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
Peter Zijlstra <peterz@infradead.org>,
Andrea Parri <parri.andrea@gmail.com>,
Luc Maranget <luc.maranget@inria.fr>,
Jade Alglave <j.alglave@ucl.ac.uk>,
Boqun Feng <boqun.feng@gmail.com>,
Nicholas Piggin <npiggin@gmail.com>,
Will Deacon <will.deacon@arm.com>,
David Howells <dhowells@redhat.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: Unlock-lock questions and the Linux Kernel Memory Model
Date: Wed, 29 Nov 2017 14:59:26 -0800 [thread overview]
Message-ID: <20171129225926.GK3624@linux.vnet.ibm.com> (raw)
In-Reply-To: <6b068a40-75bb-4152-b1ec-9ef3beacbdd5@nvidia.com>
On Wed, Nov 29, 2017 at 02:18:48PM -0800, Daniel Lustig wrote:
> On 11/29/2017 12:42 PM, Paul E. McKenney wrote:
> > On Wed, Nov 29, 2017 at 02:53:06PM -0500, Alan Stern wrote:
> >> On Wed, 29 Nov 2017, Peter Zijlstra wrote:
> >>
> >>> On Wed, Nov 29, 2017 at 11:04:53AM -0800, Daniel Lustig wrote:
> >>>
> >>>> While we're here, let me ask about another test which isn't directly
> >>>> about unlock/lock but which is still somewhat related to this
> >>>> discussion:
> >>>>
> >>>> "MP+wmb+xchg-acq" (or some such)
> >>>>
> >>>> {}
> >>>>
> >>>> P0(int *x, int *y)
> >>>> {
> >>>> WRITE_ONCE(*x, 1);
> >>>> smp_wmb();
> >>>> WRITE_ONCE(*y, 1);
> >>>> }
> >>>>
> >>>> P1(int *x, int *y)
> >>>> {
> >>>> r1 = atomic_xchg_relaxed(y, 2);
> >>>> r2 = smp_load_acquire(y);
> >>>> r3 = READ_ONCE(*x);
> >>>> }
> >>>>
> >>>> exists (1:r1=1 /\ 1:r2=2 /\ 1:r3=0)
> >>>>
> >>>> C/C++ would call the atomic_xchg_relaxed part of a release sequence
> >>>> and hence would forbid this outcome.
> >>>
> >>> That's just weird. Either its _relaxed, or its _release. Making _relaxed
> >>> mean _release is just daft.
> >>
> >> The C11 memory model specifically allows atomic operations to be
> >> interspersed within a release sequence. But it doesn't say why.
> >
> > The use case put forward within the committee is for atomic quantities
> > with mode bits. The most frequent has the atomic quantity having
> > lock-like properties, in which case you don't want to lose the ordering
> > effects of the lock handoff just because a mode bit got set or cleared.
> > Some claim to actually use something like this, but details have not
> > been forthcoming.
> >
> > I confess to being a bit skeptical. If the mode changes are infrequent,
> > the update could just as well be ordered.
>
> Aren't reference counting implementations which use memory_order_relaxed
> for incrementing the count another important use case? Specifically,
> the synchronization between a memory_order_release decrement and the
> eventual memory_order_acquire/consume free shouldn't be interrupted by
> other (relaxed) increments and (release-only) decrements that happen in
> between. At least that's my understanding of this use case. I wasn't
> there when the C/C++ committee decided this.
Well, C++ release sequences will likely soon not order memory_order_consume
loads: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0735r0.html
So we were hoping to avoid release sequences entirely. But if someone
in the kernel really is using them, we will have to model them, but
only those interacting with acquire loads.
> > That said, Daniel, the C++ memory model really does require that the
> > above litmus test be forbidden, my denigration of it notwithstanding.
>
> Yes I agree, that's why I'm curious what the Linux memory model has
> in mind here :)
Read P0735R0 (the above URL) and then tell me with a straight face that
you would not also have been tempted. ;-)
Thanx, Paul
next prev parent reply other threads:[~2017-11-29 22:59 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4118cdbe-c396-08b9-a3e3-a0a6491b82fa@nvidia.com>
2017-11-27 21:16 ` Unlock-lock questions and the Linux Kernel Memory Model Alan Stern
2017-11-27 23:28 ` Daniel Lustig
2017-11-28 9:44 ` Peter Zijlstra
2017-11-28 9:58 ` Peter Zijlstra
2017-11-29 19:04 ` Daniel Lustig
2017-11-29 19:33 ` Paul E. McKenney
2017-11-29 19:44 ` Alan Stern
2017-11-30 8:55 ` Boqun Feng
2017-11-30 9:15 ` Peter Zijlstra
2017-11-30 15:46 ` Alan Stern
2017-12-01 2:46 ` Boqun Feng
2017-12-01 15:32 ` Alan Stern
2017-12-01 16:17 ` Daniel Lustig
2017-12-01 16:24 ` Will Deacon
2017-12-01 17:18 ` Alan Stern
2017-11-29 19:46 ` Peter Zijlstra
2017-11-29 19:53 ` Alan Stern
2017-11-29 20:42 ` Paul E. McKenney
2017-11-29 22:18 ` Daniel Lustig
2017-11-29 22:59 ` Paul E. McKenney [this message]
2017-11-30 15:20 ` Alan Stern
2017-11-30 16:14 ` Paul E. McKenney
2017-11-30 16:25 ` Peter Zijlstra
2017-11-30 16:39 ` Paul E. McKenney
2017-11-30 16:41 ` Will Deacon
2017-11-30 16:54 ` Paul E. McKenney
2017-11-30 17:04 ` Will Deacon
2017-11-30 17:56 ` Alan Stern
2017-11-30 10:02 ` Will Deacon
2017-11-29 19:58 ` Peter Zijlstra
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=20171129225926.GK3624@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=boqun.feng@gmail.com \
--cc=dhowells@redhat.com \
--cc=dlustig@nvidia.com \
--cc=j.alglave@ucl.ac.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=npiggin@gmail.com \
--cc=palmer@dabbelt.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=stern@rowland.harvard.edu \
--cc=will.deacon@arm.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).