Re: [PATCH memory-model 5/8] tools/memory-model: Add a glossary of LKMM terms

From: Alan Stern
Date: Fri Nov 06 2020 - 21:33:11 EST


On Fri, Nov 06, 2020 at 01:04:13PM -0800, Paul E. McKenney wrote:
> On Fri, Nov 06, 2020 at 03:40:08PM -0500, Alan Stern wrote:
> > Is it really true that data dependencies are so easily destroyed? I
> > would expect that a true "semantic" dependency (i.e., one where the
> > value written really does vary according to the value read) would be
> > rather hard to second guess.
>
> The usual optimizations apply, for but one example:
>
> r1 = READ_ONCE(x);
> WRITE_ONCE(y, (r1 + 1) % MAX_ELEMENTS);
>
> If MAX_ELEMENTS is 1, so long, data dependency!

Sure, but if MAX_ELEMENTS is 1 then the value written will always be 0
no matter what value r1 has, so it isn't a semantic dependency.
Presumably a semantic data dependency would be much more robust.

I wonder if it's worth pointing out this distinction to the reader.

> With pointers, the compiler has fewer optimization opportunities,
> but there are still cases where it can break the dependency.
> Or transform it to a control dependency.

Transforming a data dependency into a control dependency wouldn't make
any important difference; the hardware would still provide the desired
ordering.

Alan