The notation
To compare SC with the weaker models of the next two chapters, we need it in a form we can manipulate. The book adopts the axiomatic formalism of Weaver and Germond (the SPARC manual — chapter 11 discusses axiomatic specification as a method):
- and — a load and a store to address ;
- — program order program order The per-core total order (<p) of a core's memory operations as specified by its program. defined in Chapter 3 — open in glossary : a per-core total order capturing the sequence in which that core logically executes memory operations;
- — memory order memory order The total order (<m) on all cores' memory operations that an execution appears to perform. defined in Chapter 3 — open in glossary : a total order on the memory operations of all cores.
SC in two rules
An SC execution requires:
(1) Program order is preserved — all cores insert their loads and stores into respecting their program order, regardless of whether the addresses are the same or different ( or ). Four cases:
(2) The value rule — every load gets its value from the last store before it in memory order to the same address:
where denotes “latest in memory order.”
Atomic read-modify-write read-modify-write (rmw) An atomic instruction (e.g., test-and-set, fetch-and-increment, compare-and-swap) whose load and store appear consecutively in memory order. defined in Chapter 3 — open in glossary instructions (details in §3.9) add one more constraint: each RMW’s load and store must appear consecutively in — no other memory operation, to any address, may interpose between the test and the set.
The ordering table
The book compresses rule (1) into a table — the template every later model will relax. An “X” means the program ordering (Operation 1 before Operation 2) is enforced:
| Op 1 ↓ \ Op 2 → | Load | Store | RMW |
|---|---|---|---|
| Load | XLoad → Load: a load before a load in program order must appear in that order in memory order. | XLoad → Store: a load before a store in program order must appear in that order in memory order. | XLoad → RMW: a load before a rmw in program order must appear in that order in memory order. |
| Store | XStore → Load: a store before a load in program order must appear in that order in memory order. | XStore → Store: a store before a store in program order must appear in that order in memory order. | XStore → RMW: a store before a rmw in program order must appear in that order in memory order. |
| RMW | XRMW → Load: a rmw before a load in program order must appear in that order in memory order. | XRMW → Store: a rmw before a store in program order must appear in that order in memory order. | XRMW → RMW: a rmw before a rmw in program order must appear in that order in memory order. |
X = ordering enforced · hover any cell
Table 3.4 (recreated): SC ordering rules — every entry is enforced.
Keep this table in mind as a baseline. In Chapter 4, TSO will erase exactly one X (Store→Load — the write-buffer relaxation you saw break Dekker in §3.1); Chapter 5’s relaxed models will erase nearly all of them and hand you a FENCE instruction to paint Xs back where you need them.
Safety and liveness
“An SC implementation permits only SC executions” — strictly speaking, that is the safety property (do no harm). Implementations also need liveness (do some good): a store must eventually become visible to a load repeatedly attempting to read that location — eventual write-propagation eventual write-propagation Liveness property: a store eventually becomes visible to a load repeatedly attempting to read that location. defined in Chapter 3 — open in glossary , typically ensured by the coherence protocol. (Without it, a machine that never propagated anything would be vacuously “SC.”) Starvation avoidance and fairness also matter but lie beyond this discussion.
Check yourself
1.SC's ordering rule (1) says op1 <p op2 implies op1 <m op2 for all four load/store cases. Does this apply when the two operations access the SAME address?
2.What does the value rule — val(L(a)) = val(MAX<m {S(a) | S(a) <m L(a)}) — say in plain English?
3.How does an atomic RMW (e.g., test-and-set) further constrain an SC execution?
4.The book notes SC implementations need a safety property and a liveness property. Which is which?