Path: blob/master/tools/memory-model/Documentation/glossary.txt
26282 views
This document contains brief definitions of LKMM-related terms. Like most1glossaries, it is not intended to be read front to back (except perhaps2as a way of confirming a diagnosis of OCD), but rather to be searched3for specific terms.456Address Dependency: When the address of a later memory access is computed7based on the value returned by an earlier load, an "address8dependency" extends from that load extending to the later access.9Address dependencies are quite common in RCU read-side critical10sections:11121 rcu_read_lock();132 p = rcu_dereference(gp);143 do_something(p->a);154 rcu_read_unlock();1617In this case, because the address of "p->a" on line 3 is computed18from the value returned by the rcu_dereference() on line 2, the19address dependency extends from that rcu_dereference() to that20"p->a". In rare cases, optimizing compilers can destroy address21dependencies. Please see Documentation/RCU/rcu_dereference.rst22for more information.2324See also "Control Dependency" and "Data Dependency".2526Acquire: With respect to a lock, acquiring that lock, for example,27using spin_lock(). With respect to a non-lock shared variable,28a special operation that includes a load and which orders that29load before later memory references running on that same CPU.30An example special acquire operation is smp_load_acquire(),31but atomic_read_acquire() and atomic_xchg_acquire() also include32acquire loads.3334When an acquire load returns the value stored by a release store35to that same variable, (in other words, the acquire load "reads36from" the release store), then all operations preceding that37store "happen before" any operations following that load acquire.3839See also "Happens-Before", "Reads-From", "Relaxed", and "Release".4041Coherence (co): When one CPU's store to a given variable overwrites42either the value from another CPU's store or some later value,43there is said to be a coherence link from the second CPU to44the first.4546It is also possible to have a coherence link within a CPU, which47is a "coherence internal" (coi) link. The term "coherence48external" (coe) link is used when it is necessary to exclude49the coi case.5051See also "From-reads" and "Reads-from".5253Control Dependency: When a later store's execution depends on a test54of a value computed from a value returned by an earlier load,55a "control dependency" extends from that load to that store.56For example:57581 if (READ_ONCE(x))592 WRITE_ONCE(y, 1);6061Here, the control dependency extends from the READ_ONCE() on62line 1 to the WRITE_ONCE() on line 2. Control dependencies are63fragile, and can be easily destroyed by optimizing compilers.64Please see control-dependencies.txt for more information.6566See also "Address Dependency" and "Data Dependency".6768Cycle: Memory-barrier pairing is restricted to a pair of CPUs, as the69name suggests. And in a great many cases, a pair of CPUs is all70that is required. In other cases, the notion of pairing must be71extended to additional CPUs, and the result is called a "cycle".72In a cycle, each CPU's ordering interacts with that of the next:7374CPU 0 CPU 1 CPU 275WRITE_ONCE(x, 1); WRITE_ONCE(y, 1); WRITE_ONCE(z, 1);76smp_mb(); smp_mb(); smp_mb();77r0 = READ_ONCE(y); r1 = READ_ONCE(z); r2 = READ_ONCE(x);7879CPU 0's smp_mb() interacts with that of CPU 1, which interacts80with that of CPU 2, which in turn interacts with that of CPU 081to complete the cycle. Because of the smp_mb() calls between82each pair of memory accesses, the outcome where r0, r1, and r283are all equal to zero is forbidden by LKMM.8485See also "Pairing".8687Data Dependency: When the data written by a later store is computed based88on the value returned by an earlier load, a "data dependency"89extends from that load to that later store. For example:90911 r1 = READ_ONCE(x);922 WRITE_ONCE(y, r1 + 1);9394In this case, the data dependency extends from the READ_ONCE()95on line 1 to the WRITE_ONCE() on line 2. Data dependencies are96fragile and can be easily destroyed by optimizing compilers.97Because optimizing compilers put a great deal of effort into98working out what values integer variables might have, this is99especially true in cases where the dependency is carried through100an integer.101102See also "Address Dependency" and "Control Dependency".103104From-Reads (fr): When one CPU's store to a given variable happened105too late to affect the value returned by another CPU's106load from that same variable, there is said to be a from-reads107link from the load to the store.108109It is also possible to have a from-reads link within a CPU, which110is a "from-reads internal" (fri) link. The term "from-reads111external" (fre) link is used when it is necessary to exclude112the fri case.113114See also "Coherence" and "Reads-from".115116Fully Ordered: An operation such as smp_mb() that orders all of117its CPU's prior accesses with all of that CPU's subsequent118accesses, or a marked access such as atomic_add_return()119that orders all of its CPU's prior accesses, itself, and120all of its CPU's subsequent accesses.121122Happens-Before (hb): A relation between two accesses in which LKMM123guarantees the first access precedes the second. For more124detail, please see the "THE HAPPENS-BEFORE RELATION: hb"125section of explanation.txt.126127Marked Access: An access to a variable that uses an special function or128macro such as "r1 = READ_ONCE(x)" or "smp_store_release(&a, 1)".129130See also "Unmarked Access".131132Pairing: "Memory-barrier pairing" reflects the fact that synchronizing133data between two CPUs requires that both CPUs their accesses.134Memory barriers thus tend to come in pairs, one executed by135one of the CPUs and the other by the other CPU. Of course,136pairing also occurs with other types of operations, so that a137smp_store_release() pairs with an smp_load_acquire() that reads138the value stored.139140See also "Cycle".141142Reads-From (rf): When one CPU's load returns the value stored by some other143CPU, there is said to be a reads-from link from the second144CPU's store to the first CPU's load. Reads-from links have the145nice property that time must advance from the store to the load,146which means that algorithms using reads-from links can use lighter147weight ordering and synchronization compared to algorithms using148coherence and from-reads links.149150It is also possible to have a reads-from link within a CPU, which151is a "reads-from internal" (rfi) link. The term "reads-from152external" (rfe) link is used when it is necessary to exclude153the rfi case.154155See also Coherence" and "From-reads".156157Relaxed: A marked access that does not imply ordering, for example, a158READ_ONCE(), WRITE_ONCE(), a non-value-returning read-modify-write159operation, or a value-returning read-modify-write operation whose160name ends in "_relaxed".161162See also "Acquire" and "Release".163164Release: With respect to a lock, releasing that lock, for example,165using spin_unlock(). With respect to a non-lock shared variable,166a special operation that includes a store and which orders that167store after earlier memory references that ran on that same CPU.168An example special release store is smp_store_release(), but169atomic_set_release() and atomic_cmpxchg_release() also include170release stores.171172See also "Acquire" and "Relaxed".173174Unmarked Access: An access to a variable that uses normal C-language175syntax, for example, "a = b[2]";176177See also "Marked Access".178179180