diff options
author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2015-02-17 13:00:06 -0500 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2015-02-26 14:57:32 -0500 |
commit | ff382810590e7182a1482a225965d6943e61699c (patch) | |
tree | ae5066e255ea457d4c9d402d7f56666039484235 /Documentation/memory-barriers.txt | |
parent | daf1aab9acfaaded09f53fa91dfe6e4e6926ec39 (diff) |
documentation: Clarify control-dependency pairing
This commit explicitly states that control dependencies pair normally
with other barriers, and gives an example of such pairing.
Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Diffstat (limited to 'Documentation/memory-barriers.txt')
-rw-r--r-- | Documentation/memory-barriers.txt | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index ca2387ef27ab..6974f1c2b4e1 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt | |||
@@ -592,9 +592,9 @@ See also the subsection on "Cache Coherency" for a more thorough example. | |||
592 | CONTROL DEPENDENCIES | 592 | CONTROL DEPENDENCIES |
593 | -------------------- | 593 | -------------------- |
594 | 594 | ||
595 | A control dependency requires a full read memory barrier, not simply a data | 595 | A load-load control dependency requires a full read memory barrier, not |
596 | dependency barrier to make it work correctly. Consider the following bit of | 596 | simply a data dependency barrier to make it work correctly. Consider the |
597 | code: | 597 | following bit of code: |
598 | 598 | ||
599 | q = ACCESS_ONCE(a); | 599 | q = ACCESS_ONCE(a); |
600 | if (q) { | 600 | if (q) { |
@@ -615,14 +615,15 @@ case what's actually required is: | |||
615 | } | 615 | } |
616 | 616 | ||
617 | However, stores are not speculated. This means that ordering -is- provided | 617 | However, stores are not speculated. This means that ordering -is- provided |
618 | in the following example: | 618 | for load-store control dependencies, as in the following example: |
619 | 619 | ||
620 | q = ACCESS_ONCE(a); | 620 | q = ACCESS_ONCE(a); |
621 | if (q) { | 621 | if (q) { |
622 | ACCESS_ONCE(b) = p; | 622 | ACCESS_ONCE(b) = p; |
623 | } | 623 | } |
624 | 624 | ||
625 | Please note that ACCESS_ONCE() is not optional! Without the | 625 | Control dependencies pair normally with other types of barriers. |
626 | That said, please note that ACCESS_ONCE() is not optional! Without the | ||
626 | ACCESS_ONCE(), might combine the load from 'a' with other loads from | 627 | ACCESS_ONCE(), might combine the load from 'a' with other loads from |
627 | 'a', and the store to 'b' with other stores to 'b', with possible highly | 628 | 'a', and the store to 'b' with other stores to 'b', with possible highly |
628 | counterintuitive effects on ordering. | 629 | counterintuitive effects on ordering. |
@@ -813,6 +814,8 @@ In summary: | |||
813 | barrier() can help to preserve your control dependency. Please | 814 | barrier() can help to preserve your control dependency. Please |
814 | see the Compiler Barrier section for more information. | 815 | see the Compiler Barrier section for more information. |
815 | 816 | ||
817 | (*) Control dependencies pair normally with other types of barriers. | ||
818 | |||
816 | (*) Control dependencies do -not- provide transitivity. If you | 819 | (*) Control dependencies do -not- provide transitivity. If you |
817 | need transitivity, use smp_mb(). | 820 | need transitivity, use smp_mb(). |
818 | 821 | ||
@@ -823,14 +826,14 @@ SMP BARRIER PAIRING | |||
823 | When dealing with CPU-CPU interactions, certain types of memory barrier should | 826 | When dealing with CPU-CPU interactions, certain types of memory barrier should |
824 | always be paired. A lack of appropriate pairing is almost certainly an error. | 827 | always be paired. A lack of appropriate pairing is almost certainly an error. |
825 | 828 | ||
826 | General barriers pair with each other, though they also pair with | 829 | General barriers pair with each other, though they also pair with most |
827 | most other types of barriers, albeit without transitivity. An acquire | 830 | other types of barriers, albeit without transitivity. An acquire barrier |
828 | barrier pairs with a release barrier, but both may also pair with other | 831 | pairs with a release barrier, but both may also pair with other barriers, |
829 | barriers, including of course general barriers. A write barrier pairs | 832 | including of course general barriers. A write barrier pairs with a data |
830 | with a data dependency barrier, an acquire barrier, a release barrier, | 833 | dependency barrier, a control dependency, an acquire barrier, a release |
831 | a read barrier, or a general barrier. Similarly a read barrier or a | 834 | barrier, a read barrier, or a general barrier. Similarly a read barrier, |
832 | data dependency barrier pairs with a write barrier, an acquire barrier, | 835 | control dependency, or a data dependency barrier pairs with a write |
833 | a release barrier, or a general barrier: | 836 | barrier, an acquire barrier, a release barrier, or a general barrier: |
834 | 837 | ||
835 | CPU 1 CPU 2 | 838 | CPU 1 CPU 2 |
836 | =============== =============== | 839 | =============== =============== |
@@ -850,6 +853,19 @@ Or: | |||
850 | <data dependency barrier> | 853 | <data dependency barrier> |
851 | y = *x; | 854 | y = *x; |
852 | 855 | ||
856 | Or even: | ||
857 | |||
858 | CPU 1 CPU 2 | ||
859 | =============== =============================== | ||
860 | r1 = ACCESS_ONCE(y); | ||
861 | <general barrier> | ||
862 | ACCESS_ONCE(y) = 1; if (r2 = ACCESS_ONCE(x)) { | ||
863 | <implicit control dependency> | ||
864 | ACCESS_ONCE(y) = 1; | ||
865 | } | ||
866 | |||
867 | assert(r1 == 0 || r2 == 0); | ||
868 | |||
853 | Basically, the read barrier always has to be there, even though it can be of | 869 | Basically, the read barrier always has to be there, even though it can be of |
854 | the "weaker" type. | 870 | the "weaker" type. |
855 | 871 | ||