summaryrefslogtreecommitdiffstats
path: root/Documentation/memory-barriers.txt
diff options
context:
space:
mode:
authorSeongJae Park <sj38.park@gmail.com>2016-04-12 11:52:53 -0400
committerIngo Molnar <mingo@kernel.org>2016-04-13 02:52:22 -0400
commit0b6fa347dc08c6f757a35f3a180269b3ffc4cd28 (patch)
tree4927deaec9a475067ce8c1525559135cc28a6ad0 /Documentation/memory-barriers.txt
parent3dbf0913f6cac722805a94f16b1e61ffc3483eaf (diff)
locking/Documentation: Insert white spaces consistently
The document uses two newlines between sections, one newline between item and its detailed description, and two spaces between sentences. There are a few places that used these rules inconsistently - fix them. Signed-off-by: SeongJae Park <sj38.park@gmail.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Acked-by: David Howells <dhowells@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: bobby.prani@gmail.com Cc: dipankar@in.ibm.com Cc: dvhart@linux.intel.com Cc: edumazet@google.com Cc: fweisbec@gmail.com Cc: jiangshanlai@gmail.com Cc: josh@joshtriplett.org Cc: mathieu.desnoyers@efficios.com Cc: oleg@redhat.com Cc: rostedt@goodmis.org Link: http://lkml.kernel.org/r/1460476375-27803-5-git-send-email-paulmck@linux.vnet.ibm.com [ Fixed the changelog. ] Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'Documentation/memory-barriers.txt')
-rw-r--r--Documentation/memory-barriers.txt43
1 files changed, 23 insertions, 20 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt
index 1f1541862239..7133626a61d0 100644
--- a/Documentation/memory-barriers.txt
+++ b/Documentation/memory-barriers.txt
@@ -1733,15 +1733,15 @@ The Linux kernel has eight basic CPU memory barriers:
1733 1733
1734 1734
1735All memory barriers except the data dependency barriers imply a compiler 1735All memory barriers except the data dependency barriers imply a compiler
1736barrier. Data dependencies do not impose any additional compiler ordering. 1736barrier. Data dependencies do not impose any additional compiler ordering.
1737 1737
1738Aside: In the case of data dependencies, the compiler would be expected 1738Aside: In the case of data dependencies, the compiler would be expected
1739to issue the loads in the correct order (eg. `a[b]` would have to load 1739to issue the loads in the correct order (eg. `a[b]` would have to load
1740the value of b before loading a[b]), however there is no guarantee in 1740the value of b before loading a[b]), however there is no guarantee in
1741the C specification that the compiler may not speculate the value of b 1741the C specification that the compiler may not speculate the value of b
1742(eg. is equal to 1) and load a before b (eg. tmp = a[1]; if (b != 1) 1742(eg. is equal to 1) and load a before b (eg. tmp = a[1]; if (b != 1)
1743tmp = a[b]; ). There is also the problem of a compiler reloading b after 1743tmp = a[b]; ). There is also the problem of a compiler reloading b after
1744having loaded a[b], thus having a newer copy of b than a[b]. A consensus 1744having loaded a[b], thus having a newer copy of b than a[b]. A consensus
1745has not yet been reached about these problems, however the READ_ONCE() 1745has not yet been reached about these problems, however the READ_ONCE()
1746macro is a good place to start looking. 1746macro is a good place to start looking.
1747 1747
@@ -1796,6 +1796,7 @@ There are some more advanced barrier functions:
1796 1796
1797 1797
1798 (*) lockless_dereference(); 1798 (*) lockless_dereference();
1799
1799 This can be thought of as a pointer-fetch wrapper around the 1800 This can be thought of as a pointer-fetch wrapper around the
1800 smp_read_barrier_depends() data-dependency barrier. 1801 smp_read_barrier_depends() data-dependency barrier.
1801 1802
@@ -1897,7 +1898,7 @@ for each construct. These operations all imply certain barriers:
1897 Memory operations issued before the ACQUIRE may be completed after 1898 Memory operations issued before the ACQUIRE may be completed after
1898 the ACQUIRE operation has completed. An smp_mb__before_spinlock(), 1899 the ACQUIRE operation has completed. An smp_mb__before_spinlock(),
1899 combined with a following ACQUIRE, orders prior stores against 1900 combined with a following ACQUIRE, orders prior stores against
1900 subsequent loads and stores. Note that this is weaker than smp_mb()! 1901 subsequent loads and stores. Note that this is weaker than smp_mb()!
1901 The smp_mb__before_spinlock() primitive is free on many architectures. 1902 The smp_mb__before_spinlock() primitive is free on many architectures.
1902 1903
1903 (2) RELEASE operation implication: 1904 (2) RELEASE operation implication:
@@ -2092,9 +2093,9 @@ or:
2092 event_indicated = 1; 2093 event_indicated = 1;
2093 wake_up_process(event_daemon); 2094 wake_up_process(event_daemon);
2094 2095
2095A write memory barrier is implied by wake_up() and co. if and only if they wake 2096A write memory barrier is implied by wake_up() and co. if and only if they
2096something up. The barrier occurs before the task state is cleared, and so sits 2097wake something up. The barrier occurs before the task state is cleared, and so
2097between the STORE to indicate the event and the STORE to set TASK_RUNNING: 2098sits between the STORE to indicate the event and the STORE to set TASK_RUNNING:
2098 2099
2099 CPU 1 CPU 2 2100 CPU 1 CPU 2
2100 =============================== =============================== 2101 =============================== ===============================
@@ -2208,7 +2209,7 @@ three CPUs; then should the following sequence of events occur:
2208 2209
2209Then there is no guarantee as to what order CPU 3 will see the accesses to *A 2210Then there is no guarantee as to what order CPU 3 will see the accesses to *A
2210through *H occur in, other than the constraints imposed by the separate locks 2211through *H occur in, other than the constraints imposed by the separate locks
2211on the separate CPUs. It might, for example, see: 2212on the separate CPUs. It might, for example, see:
2212 2213
2213 *E, ACQUIRE M, ACQUIRE Q, *G, *C, *F, *A, *B, RELEASE Q, *D, *H, RELEASE M 2214 *E, ACQUIRE M, ACQUIRE Q, *G, *C, *F, *A, *B, RELEASE Q, *D, *H, RELEASE M
2214 2215
@@ -2488,9 +2489,9 @@ The following operations are special locking primitives:
2488 clear_bit_unlock(); 2489 clear_bit_unlock();
2489 __clear_bit_unlock(); 2490 __clear_bit_unlock();
2490 2491
2491These implement ACQUIRE-class and RELEASE-class operations. These should be used in 2492These implement ACQUIRE-class and RELEASE-class operations. These should be
2492preference to other operations when implementing locking primitives, because 2493used in preference to other operations when implementing locking primitives,
2493their implementations can be optimised on many architectures. 2494because their implementations can be optimised on many architectures.
2494 2495
2495[!] Note that special memory barrier primitives are available for these 2496[!] Note that special memory barrier primitives are available for these
2496situations because on some CPUs the atomic instructions used imply full memory 2497situations because on some CPUs the atomic instructions used imply full memory
@@ -2570,12 +2571,12 @@ explicit barriers are used.
2570 2571
2571Normally this won't be a problem because the I/O accesses done inside such 2572Normally this won't be a problem because the I/O accesses done inside such
2572sections will include synchronous load operations on strictly ordered I/O 2573sections will include synchronous load operations on strictly ordered I/O
2573registers that form implicit I/O barriers. If this isn't sufficient then an 2574registers that form implicit I/O barriers. If this isn't sufficient then an
2574mmiowb() may need to be used explicitly. 2575mmiowb() may need to be used explicitly.
2575 2576
2576 2577
2577A similar situation may occur between an interrupt routine and two routines 2578A similar situation may occur between an interrupt routine and two routines
2578running on separate CPUs that communicate with each other. If such a case is 2579running on separate CPUs that communicate with each other. If such a case is
2579likely, then interrupt-disabling locks should be used to guarantee ordering. 2580likely, then interrupt-disabling locks should be used to guarantee ordering.
2580 2581
2581 2582
@@ -2589,8 +2590,8 @@ functions:
2589 (*) inX(), outX(): 2590 (*) inX(), outX():
2590 2591
2591 These are intended to talk to I/O space rather than memory space, but 2592 These are intended to talk to I/O space rather than memory space, but
2592 that's primarily a CPU-specific concept. The i386 and x86_64 processors do 2593 that's primarily a CPU-specific concept. The i386 and x86_64 processors
2593 indeed have special I/O space access cycles and instructions, but many 2594 do indeed have special I/O space access cycles and instructions, but many
2594 CPUs don't have such a concept. 2595 CPUs don't have such a concept.
2595 2596
2596 The PCI bus, amongst others, defines an I/O space concept which - on such 2597 The PCI bus, amongst others, defines an I/O space concept which - on such
@@ -2612,7 +2613,7 @@ functions:
2612 2613
2613 Whether these are guaranteed to be fully ordered and uncombined with 2614 Whether these are guaranteed to be fully ordered and uncombined with
2614 respect to each other on the issuing CPU depends on the characteristics 2615 respect to each other on the issuing CPU depends on the characteristics
2615 defined for the memory window through which they're accessing. On later 2616 defined for the memory window through which they're accessing. On later
2616 i386 architecture machines, for example, this is controlled by way of the 2617 i386 architecture machines, for example, this is controlled by way of the
2617 MTRR registers. 2618 MTRR registers.
2618 2619
@@ -2637,10 +2638,10 @@ functions:
2637 (*) readX_relaxed(), writeX_relaxed() 2638 (*) readX_relaxed(), writeX_relaxed()
2638 2639
2639 These are similar to readX() and writeX(), but provide weaker memory 2640 These are similar to readX() and writeX(), but provide weaker memory
2640 ordering guarantees. Specifically, they do not guarantee ordering with 2641 ordering guarantees. Specifically, they do not guarantee ordering with
2641 respect to normal memory accesses (e.g. DMA buffers) nor do they guarantee 2642 respect to normal memory accesses (e.g. DMA buffers) nor do they guarantee
2642 ordering with respect to LOCK or UNLOCK operations. If the latter is 2643 ordering with respect to LOCK or UNLOCK operations. If the latter is
2643 required, an mmiowb() barrier can be used. Note that relaxed accesses to 2644 required, an mmiowb() barrier can be used. Note that relaxed accesses to
2644 the same peripheral are guaranteed to be ordered with respect to each 2645 the same peripheral are guaranteed to be ordered with respect to each
2645 other. 2646 other.
2646 2647
@@ -3042,6 +3043,7 @@ The Alpha defines the Linux kernel's memory barrier model.
3042 3043
3043See the subsection on "Cache Coherency" above. 3044See the subsection on "Cache Coherency" above.
3044 3045
3046
3045VIRTUAL MACHINE GUESTS 3047VIRTUAL MACHINE GUESTS
3046---------------------- 3048----------------------
3047 3049
@@ -3052,7 +3054,7 @@ barriers for this use-case would be possible but is often suboptimal.
3052 3054
3053To handle this case optimally, low-level virt_mb() etc macros are available. 3055To handle this case optimally, low-level virt_mb() etc macros are available.
3054These have the same effect as smp_mb() etc when SMP is enabled, but generate 3056These have the same effect as smp_mb() etc when SMP is enabled, but generate
3055identical code for SMP and non-SMP systems. For example, virtual machine guests 3057identical code for SMP and non-SMP systems. For example, virtual machine guests
3056should use virt_mb() rather than smp_mb() when synchronizing against a 3058should use virt_mb() rather than smp_mb() when synchronizing against a
3057(possibly SMP) host. 3059(possibly SMP) host.
3058 3060
@@ -3060,6 +3062,7 @@ These are equivalent to smp_mb() etc counterparts in all other respects,
3060in particular, they do not control MMIO effects: to control 3062in particular, they do not control MMIO effects: to control
3061MMIO effects, use mandatory barriers. 3063MMIO effects, use mandatory barriers.
3062 3064
3065
3063============ 3066============
3064EXAMPLE USES 3067EXAMPLE USES
3065============ 3068============