Re: [PATCH tip/core/locking 4/4] Documentation/memory-barriers.txt:Document ACCESS_ONCE()

From: Ingo Molnar
Date: Tue Dec 10 2013 - 14:46:37 EST



* Paul E. McKenney <paulmck@xxxxxxxxxxxxxxxxxx> 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.)

[ 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. ]


> [...] 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!

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/