<div dir="ltr">Hi, I read an example in the Documentation/memory-barriers.txt, which says<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><pre style="color:rgb(0,0,0);white-space:pre-wrap"> (*) On any given CPU, dependent memory accesses will be issued in order, with
     respect to itself.  This means that for:

        Q = READ_ONCE(P); D = READ_ONCE(*Q);

     the CPU will issue the following memory operations:

        Q = LOAD P, D = LOAD *Q

     and always in that order.  However, on DEC Alpha, READ_ONCE() also
     emits a memory-barrier instruction, so that a DEC Alpha CPU will
     instead issue the following memory operations:

        Q = LOAD P, MEMORY_BARRIER, D = LOAD *Q, MEMORY_BARRIER</pre></blockquote><div>As far as  I understand it, linux kernel memory model (LKMM) guarantee two read operations execute in order. And if the CPU architecture offer an looser memory ordering (like Alpha), then the compiler must help to add a memory barrier after the load instruction to fufill the LKMM's standard. </div><div><br></div><div>However i did a test using klitmus like this</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">P0(int *x, int *y) <br>{<br>        WRITE_ONCE(*x, 1); <br>        smp_wmb();<br>        WRITE_ONCE(*y, 1); <br>}<br><br>P1(int *x, int *y) <br>{<br>        int r0; <br>        int r1; <br><br>        r0 = READ_ONCE(*y);<br>        r1 = READ_ONCE(*x);<br>}<br><br>exists (1:r0=1 /\ 1:r1=0)<br></blockquote><div> </div><div>I run this test in an aarch64 machine, and get the result </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Histogram (4 states)<br>1292209 :>1:r0=0; 1:r1=0;<br>1585    *>1:r0=1; 1:r1=0;<br>221437  :>1:r0=0; 1:r1=1;<br>484769  :>1:r0=1; 1:r1=1;<br>Ok<br><br>Witnesses<br>Positive: 1585, Negative: 1998415<br></blockquote><div> </div><div>It seems that these two READ_ONCE()s can be executed in any order. But if I run this test in a x86 machine, which has a more strict memory model, result 1:r0=1; 1:r1=0; disappears. So the order depends on the memory model provided by the CPU architecture? Isn't this contradicted with memory-barrier.txt?</div></div>