diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2014-08-04 14:49:34 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2014-09-07 19:15:52 -0400 |
commit | efdcd51a4d5bd355796b1a757ff0355bb09ed394 (patch) | |
tree | c8b39a7b01980753ff864c7a28bc9ac0ae180701 /Documentation/memory-barriers.txt | |
parent | 5646f7acc95f14873f1ec715380c1c493b4243ce (diff) |
memory-barriers: Retain barrier() in fold-to-zero example
The transformation in the fold-to-zero example incorrectly omits the
barrier() directive. This commit therefore adds it back in.
Reported-by: Pranith Kumar <pranith@gatech.edu>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'Documentation/memory-barriers.txt')
-rw-r--r-- | Documentation/memory-barriers.txt | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index d67c508eb660..600b45c6e2ad 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt | |||
@@ -679,12 +679,15 @@ equal to zero, in which case the compiler is within its rights to | |||
679 | transform the above code into the following: | 679 | transform the above code into the following: |
680 | 680 | ||
681 | q = ACCESS_ONCE(a); | 681 | q = ACCESS_ONCE(a); |
682 | barrier(); | ||
682 | ACCESS_ONCE(b) = p; | 683 | ACCESS_ONCE(b) = p; |
683 | do_something_else(); | 684 | do_something_else(); |
684 | 685 | ||
685 | This transformation loses the ordering between the load from variable 'a' | 686 | This transformation fails to require that the CPU respect the ordering |
686 | and the store to variable 'b'. If you are relying on this ordering, you | 687 | between the load from variable 'a' and the store to variable 'b'. |
687 | should do something like the following: | 688 | Yes, the barrier() is still there, but it affects only the compiler, |
689 | not the CPU. Therefore, if you are relying on this ordering, you should | ||
690 | do something like the following: | ||
688 | 691 | ||
689 | q = ACCESS_ONCE(a); | 692 | q = ACCESS_ONCE(a); |
690 | BUILD_BUG_ON(MAX <= 1); /* Order load from a with store to b. */ | 693 | BUILD_BUG_ON(MAX <= 1); /* Order load from a with store to b. */ |