Messages in this thread | | | Date | Tue, 10 Dec 2013 12:09:36 -0800 | From | "Paul E. McKenney" <> | Subject | Re: [PATCH tip/core/locking 4/4] Documentation/memory-barriers.txt: Document ACCESS_ONCE() |
| |
On Tue, Dec 10, 2013 at 08:46:28PM +0100, Ingo Molnar wrote: > > * Paul E. McKenney <paulmck@linux.vnet.ibm.com> wrote: > > > > So, what I don't see this statement cover (and I might be dense about > > > it!) is whether two ACCESS_ONCE() macros referring to different > > > variables are allowed to be reordered with each other. > > > > > > If the compiler reorders: > > > > > > ACCESS_ONCE(x); > > > ACCESS_ONCE(y); > > > > > > to: > > > > > > ACCESS_ONCE(y); > > > ACCESS_ONCE(x); > > > > > > then AFAICS it still meets the "compiler need only forget the contents > > > of the indicated memory located" requirement that you listed, right? > > > > True, but if the compiler was willing to reorder ACCESS_ONCE()'s > > volatile accesses, it would be really hard to write reliable device > > drivers. [...] > > But nowhere do we link ACCESS_ONCE() to 'volatile' semantics in the > document, do we? (and I'm not sure we should.)
Agreed, stating ACCESS_ONCE()'s semantics separately is better.
> [ In theory a future compiler could offer a smarter, more flexible > 'compiler barrier' implementation - at which point we might be > tempted to use that new facility to implement ACCESS_ONCE(). At that > point this ambiguity might arise. ]
And they are trying to obsolete volatile, but haven't quite got there yet. ;-)
> > [...] The standard says the following: > > > > Access to volatile objects are evaluated strictly according to > > the rules of the abstract machine. > > > > That said, compiler writers and standards wonks will argue endlessly > > about exactly what that does and does not mean. :-/ > > > > I added a sentence reading: > > > > Of course, the compiler must also respect the order in which > > the ACCESS_ONCE()s occur, though the CPU of course need not do so. > > > > To the end of that paragraph. Does that help? > > Yeah, that looks perfect!
Very good!
Thanx, Paul
| |