Re: Prototype patch for Linux-kernel memory model

From: Alan Stern
Date: Tue Dec 19 2017 - 11:05:54 EST


On Tue, 19 Dec 2017, afzal mohammed wrote:

> Hi,
>
> A trivial & late (sorry) comment,
>
> On Wed, Nov 15, 2017 at 08:37:49AM -0800, Paul E. McKenney wrote:
>
> > +THE HAPPENS-BEFORE RELATION: hb
> > +-------------------------------
>
> > +Less trivial examples of prop all involve fences. Unlike the simple
> > +examples above, they can require that some instructions are executed
> > +out of program order. This next one should look familiar:
> > +
> > + int buf = 0, flag = 0;
> > +
> > + P0()
> > + {
> > + WRITE_ONCE(buf, 1);
> > + smp_wmb();
> > + WRITE_ONCE(flag, 1);
> > + }
> > +
> > + P1()
> > + {
> > + int r1;
> > + int r2;
> > +
> > + r1 = READ_ONCE(flag);
> > + r2 = READ_ONCE(buf);
> > + }
> > +
> > +This is the MP pattern again, with an smp_wmb() fence between the two
> > +stores. If r1 = 1 and r2 = 0 at the end then there is a prop link
> > +from P1's second load to its first (backwards!). The reason is
> > +similar to the previous examples: The value P1 loads from buf gets
> > +overwritten by P1's store to buf,
>
> P0's store to buf
>
> afzal

Thank you; I have applied the change.

Alan Stern