public inbox for linux-arch@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.ibm.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: David Goldblatt <davidtgoldblatt@gmail.com>,
	mathieu.desnoyers@efficios.com,
	Florian Weimer <fweimer@redhat.com>,
	triegel@redhat.com, libc-alpha@sourceware.org,
	andrea.parri@amarulasolutions.com, will.deacon@arm.com,
	peterz@infradead.org, boqun.feng@gmail.com, npiggin@gmail.com,
	dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr,
	akiyks@gmail.com, dlustig@nvidia.com, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Linux: Implement membarrier function
Date: Sun, 16 Dec 2018 10:51:30 -0800	[thread overview]
Message-ID: <20181216185130.GB4170@linux.ibm.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1812141404450.1570-100000@iolanthe.rowland.org>

On Fri, Dec 14, 2018 at 04:39:34PM -0500, Alan Stern wrote:
> On Fri, 14 Dec 2018, Paul E. McKenney wrote:
> 
> > I would say that sys_membarrier() has zero-sized read-side critical
> > sections, either comprising a single instruction (as is the case for
> > synchronize_sched(), actually), preempt-disable regions of code
> > (which are irrelevant to userspace execution), or the spaces between
> > consecutive pairs of instructions (as is the case for the newer
> > IPI-based implementation).
> > 
> > The model picks the single-instruction option, and I haven't yet found
> > a problem with this -- which is no surprise given that, as you say,
> > an actual implementation makes this same choice.
> 
> I believe that for RCU tests the LKMM gives the same results for
> length-zero critical sections interspersed between all the instructions
> and length-one critical sections surrounding all instructions (except
> synchronize_rcu).  But the proof is tricky and I haven't checked it
> carefully.

That assertion is completely consistent with my implementation experience,
give or take the usual caveats about idle and offline execution.

> > > > The other thing that took some time to get used to is the possibility
> > > > of long delays during sys_membarrier() execution, allowing significant
> > > > execution and reordering between different CPUs' IPIs.  This was key
> > > > to my understanding of the six-process example, and probably needs to
> > > > be clearly called out, including in an example or two.
> > > 
> > > In all the examples I'm aware of, no more than one of the IPIs
> > > generated by each sys_membarrier call really matters.  (Of course,
> > > there's no way to know in advance which one it will be, so you have to
> > > send an IPI to every CPU.)  The execution delays and reordering
> > > between different CPUs' IPIs don't appear to be significant.
> > 
> > Well, there are litmus tests that are allowed in which the allowed
> > execution is more easily explained in terms of delays between different
> > CPUs' IPIs, so it seems worth keeping track of.
> > 
> > There might be a litmus test that can tell the difference between
> > simultaneous and non-simultaneous IPIs, but I cannot immediately think of
> > one that matters.  Might be a failure of imagination on my part, though.
> 
> 	P0	P1	P2
> 	Wc=1	[mb01]	Rb=1
> 	memb	Wa=1	Rc=0
> 	Ra=0	Wb=1	[mb02]
> 
> The IPIs have to appear in the positions shown, which means they cannot
> be simultaneous.  The test is allowed because P2's reads can be
> reordered.

OK, so "simultaneous" IPIs could be emulated in a real implementation by
having sys_membarrier() send each IPI (but not wait for a response), then
execute a full memory barrier and set a shared variable.  Each IPI handler
would spin waiting for the shared variable to be set, then execute a full
memory barrier and atomically increment yet another shared variable and
return from interrupt.  When that other shared variable's value reached
the number of IPIs sent, the sys_membarrier() would execute its final
(already existing) full memory barrier and return.  Horribly expensive
and definitely not recommended, but eminently doable.

The difference between current sys_membarrier() and the "simultaneous"
variant described above is similar to the difference between
non-multicopy-atomic and multicopy-atomic memory ordering.  So, after
thinking it through, my guess is that pretty much any litmus test that
can discern between multicopy-atomic and  non-multicopy-atomic should
be transformable into something that can distinguish between the current
and the "simultaneous" sys_membarrier() implementation.

Seem reasonable?

Or alternatively, may I please apply your Signed-off-by to your earlier
sys_membarrier() patch so that I can queue it?  I will probably also
change smp_memb() to membarrier() or some such.  Again, within the
Linux kernel, membarrier() can be emulated with smp_call_function()
invoking a handler that does smp_mb().

							Thanx, Paul

  parent reply	other threads:[~2018-12-16 18:51 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8736rldyzm.fsf@oldenburg.str.redhat.com>
     [not found] ` <1543444466.5493.220.camel@redhat.com>
     [not found]   ` <87y39c2dsg.fsf@oldenburg.str.redhat.com>
     [not found]     ` <1689938209.14804.1543502662882.JavaMail.zimbra@efficios.com>
     [not found]       ` <20181129150433.GH4170@linux.ibm.com>
     [not found]         ` <CAHD6eXcvx1bskbp-X+vuMYoMQiCLOt0PiCZ5FT1yFsda9Ud-yA@mail.gmail.com>
2018-12-06 21:54           ` [PATCH] Linux: Implement membarrier function Paul E. McKenney
2018-12-06 21:54             ` Paul E. McKenney
2018-12-10 16:22             ` Alan Stern
2018-12-10 16:22               ` Alan Stern
2018-12-10 18:25               ` Paul E. McKenney
2018-12-10 18:25                 ` Paul E. McKenney
2018-12-11 16:21                 ` Alan Stern
2018-12-11 16:21                   ` Alan Stern
2018-12-11 19:08                   ` Paul E. McKenney
2018-12-11 19:08                     ` Paul E. McKenney
2018-12-11 20:09                     ` Alan Stern
2018-12-11 20:09                       ` Alan Stern
2018-12-11 21:22                       ` Paul E. McKenney
2018-12-11 21:22                         ` Paul E. McKenney
2018-12-12 17:07                         ` Paul E. McKenney
2018-12-12 17:07                           ` Paul E. McKenney
2018-12-12 18:04                           ` Alan Stern
2018-12-12 18:04                             ` Alan Stern
2018-12-12 19:42                             ` Paul E. McKenney
2018-12-12 19:42                               ` Paul E. McKenney
2018-12-12 21:32                               ` Alan Stern
2018-12-12 21:32                                 ` Alan Stern
2018-12-12 21:52                                 ` Paul E. McKenney
2018-12-12 21:52                                   ` Paul E. McKenney
2018-12-12 22:12                                   ` Alan Stern
2018-12-12 22:12                                     ` Alan Stern
2018-12-12 22:49                                     ` Paul E. McKenney
2018-12-12 22:49                                       ` Paul E. McKenney
2018-12-13 15:49                                       ` Alan Stern
2018-12-13 15:49                                         ` Alan Stern
2018-12-14  0:20                                         ` Paul E. McKenney
2018-12-14  0:20                                           ` Paul E. McKenney
2018-12-14  2:26                                           ` Alan Stern
2018-12-14  2:26                                             ` Alan Stern
2018-12-14  5:20                                             ` Paul E. McKenney
2018-12-14  5:20                                               ` Paul E. McKenney
2018-12-14 15:31                                           ` Alan Stern
2018-12-14 15:31                                             ` Alan Stern
2018-12-14 18:43                                             ` Paul E. McKenney
2018-12-14 18:43                                               ` Paul E. McKenney
2018-12-14 21:39                                               ` Alan Stern
2018-12-14 21:39                                                 ` Alan Stern
2018-12-16 18:51                                                 ` Paul E. McKenney [this message]
2018-12-16 18:51                                                   ` Paul E. McKenney
2018-12-17 16:02                                                   ` Alan Stern
2018-12-17 16:02                                                     ` Alan Stern
2018-12-17 18:32                                                     ` Paul E. McKenney
2018-12-17 18:32                                                       ` Paul E. McKenney
2018-12-12 22:19                                   ` Paul E. McKenney
2018-12-12 22:19                                     ` Paul E. McKenney
2018-12-11  6:42             ` David Goldblatt
2018-12-11  6:42               ` David Goldblatt
2018-12-11 14:49               ` Paul E. McKenney
2018-12-11 14:49                 ` Paul E. McKenney

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=20181216185130.GB4170@linux.ibm.com \
    --to=paulmck@linux.ibm.com \
    --cc=akiyks@gmail.com \
    --cc=andrea.parri@amarulasolutions.com \
    --cc=boqun.feng@gmail.com \
    --cc=davidtgoldblatt@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dlustig@nvidia.com \
    --cc=fweimer@redhat.com \
    --cc=j.alglave@ucl.ac.uk \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luc.maranget@inria.fr \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=stern@rowland.harvard.edu \
    --cc=triegel@redhat.com \
    --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