lkml.org 
[lkml]   [2013]   [Dec]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH tip/core/locking 4/4] Documentation/memory-barriers.txt: Document ACCESS_ONCE()
On Tue, Dec 10, 2013 at 04:10:50PM +0100, Ingo Molnar wrote:
>
> * Paul E. McKenney <paulmck@linux.vnet.ibm.com> wrote:
>
> > On Thu, Dec 05, 2013 at 10:05:47AM -0800, Paul E. McKenney wrote:
> > > On Thu, Dec 05, 2013 at 10:50:42AM +0100, Ingo Molnar wrote:
> > > >
> > > > * Paul E. McKenney <paulmck@linux.vnet.ibm.com> wrote:
> > > >
> > > > > + (*) The compiler is within its rights to reload a variable, for example,
> > > > > + in cases where high register pressure prevents the compiler from
> > > > > + keeping all data of interest in registers. The compiler might
> > > > > + therefore optimize the variable tmp out of our previous example:
> > > > > +
> > > > > + while (tmp = a)
> > > > > + do_something_with(tmp);
> > > > > +
> > > > > + This could result in the following code, which is perfectly safe in
> > > > > + single-threaded code, but can be fatal in concurrent code:
> > > > > +
> > > > > + while (a)
> > > > > + do_something_with(a);
> > > > > +
> > > > > + For example, the optimized version of this code could result in
> > > > > + passing a zero to do_something_with() in the case where the variable
> > > > > + a was modified by some other CPU between the "while" statement and
> > > > > + the call to do_something_with().
> > > >
> > > > Nit: I guess references to variable names such as 'a' should be quoted
> > > > (same for 'tmp', 'b', etc):
> > > >
> > > > For example, the optimized version of this code could result in
> > > > passing a zero to do_something_with() in the case where the variable
> > > > 'a' was modified by some other CPU between the "while" statement and
> > > > the call to do_something_with().
> > > >
> > > > which makes reading it less ambiguous and more fluid IMO. This
> > > > observation applies to the whole document as 'a' is used in many
> > > > places.
> > >
> > > Good point, fixed.
> >
> > Which reminds me -- the thing that makes me most nervous about
> > prohibiting speculative stores is the bit about having to anticipate
> > all compiler optimizations that might get rid of the needed
> > conditionals.
> >
> > Thoughts?
>
> As long as current compiler versions behave I don't the potential of
> future problems is a problem that can (or should) be solved via
> documentation - there will always be a colorful tension between
> specification and reality, both at the hardware, the code and the
> compiler level ;-)

There certainly has been in the past. ;-)

> It doesn't hurt to outline our expectations in any case, agreed?

Fair enough, I will leave it as is.

Thanx, Paul



\
 
 \ /
  Last update: 2013-12-12 13:41    [W:0.058 / U:0.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site