doc: Update control-dependencies section of memory-barriers.txt
authorpierre Kuo <vichy.kuo@gmail.com>
Fri, 7 Apr 2017 06:37:36 +0000 (14:37 +0800)
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>
Wed, 12 Apr 2017 15:23:43 +0000 (08:23 -0700)
In the following example, if MAX is defined to be 1, then the compiler
knows (Q % MAX) is equal to zero.  The compiler can therefore throw
away the "then" branch (and the "if"), retaining only the "else" branch.

q = READ_ONCE(a);
if (q % MAX) {
WRITE_ONCE(b, 1);
do_something();
} else {
WRITE_ONCE(b, 2);
do_something_else();
}

It is therefore necessary to modify the example like this:

        q = READ_ONCE(a);
-       WRITE_ONCE(b, 1);
+       WRITE_ONCE(b, 2);
        do_something_else();

Signed-off-by: pierre Kuo <vichy.kuo@gmail.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Documentation/memory-barriers.txt

index d2b0a8d..08329cb 100644 (file)
@@ -768,7 +768,7 @@ equal to zero, in which case the compiler is within its rights to
 transform the above code into the following:
 
        q = READ_ONCE(a);
-       WRITE_ONCE(b, 1);
+       WRITE_ONCE(b, 2);
        do_something_else();
 
 Given this transformation, the CPU is not required to respect the ordering