diff options
Diffstat (limited to 'Documentation/memory-barriers.txt')
-rw-r--r-- | Documentation/memory-barriers.txt | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index f1dc4a215593..a4de88fb55f0 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt | |||
@@ -757,10 +757,14 @@ SMP BARRIER PAIRING | |||
757 | When dealing with CPU-CPU interactions, certain types of memory barrier should | 757 | When dealing with CPU-CPU interactions, certain types of memory barrier should |
758 | always be paired. A lack of appropriate pairing is almost certainly an error. | 758 | always be paired. A lack of appropriate pairing is almost certainly an error. |
759 | 759 | ||
760 | A write barrier should always be paired with a data dependency barrier or read | 760 | General barriers pair with each other, though they also pair with |
761 | barrier, though a general barrier would also be viable. Similarly a read | 761 | most other types of barriers, albeit without transitivity. An acquire |
762 | barrier or a data dependency barrier should always be paired with at least an | 762 | barrier pairs with a release barrier, but both may also pair with other |
763 | write barrier, though, again, a general barrier is viable: | 763 | barriers, including of course general barriers. A write barrier pairs |
764 | with a data dependency barrier, an acquire barrier, a release barrier, | ||
765 | a read barrier, or a general barrier. Similarly a read barrier or a | ||
766 | data dependency barrier pairs with a write barrier, an acquire barrier, | ||
767 | a release barrier, or a general barrier: | ||
764 | 768 | ||
765 | CPU 1 CPU 2 | 769 | CPU 1 CPU 2 |
766 | =============== =============== | 770 | =============== =============== |
@@ -1893,6 +1897,21 @@ between the STORE to indicate the event and the STORE to set TASK_RUNNING: | |||
1893 | <general barrier> STORE current->state | 1897 | <general barrier> STORE current->state |
1894 | LOAD event_indicated | 1898 | LOAD event_indicated |
1895 | 1899 | ||
1900 | To repeat, this write memory barrier is present if and only if something | ||
1901 | is actually awakened. To see this, consider the following sequence of | ||
1902 | events, where X and Y are both initially zero: | ||
1903 | |||
1904 | CPU 1 CPU 2 | ||
1905 | =============================== =============================== | ||
1906 | X = 1; STORE event_indicated | ||
1907 | smp_mb(); wake_up(); | ||
1908 | Y = 1; wait_event(wq, Y == 1); | ||
1909 | wake_up(); load from Y sees 1, no memory barrier | ||
1910 | load from X might see 0 | ||
1911 | |||
1912 | In contrast, if a wakeup does occur, CPU 2's load from X would be guaranteed | ||
1913 | to see 1. | ||
1914 | |||
1896 | The available waker functions include: | 1915 | The available waker functions include: |
1897 | 1916 | ||
1898 | complete(); | 1917 | complete(); |