|
Memory consistency
- Need a more formal description of memory ordering
- How to establish the order between reads and writes from different processors to different variables?
- The most clear way is to use synchronization
P0: A=1; flag=1
P1: while (!flag); print A;
- Another example (assume A=0, B=0 initially)
P0: A=1; print B;
P1: B=1; print A;
- Memory consistency model is a contract between programmer and hardware regarding memory ordering
Consistency model
- A multiprocessor normally advertises the supported memory consistency model
- This essentially tells the programmer what the possible correct outcome of a program could be when run on that machine
- Cache coherence deals with memory operations to the same location, but not different locations
- Without a formally defined order across all memory operations it often becomes impossible to argue about what is correct and what is wrong in shared memory
- Various memory consistency models
- Sequential consistency (SC) is the most intuitive one and we will focus on it now (more consistency models later)
Sequential consistency
- Total order achieved by interleaving accesses from different processors
- The accesses from the same processor are presented to the memory system in program order
- Essentially, behaves like a randomly moving switch connecting the processors to memory
- Picks the next access from a randomly chosen processor
- Lamport’s definition of SC
- A multiprocessor is sequentially consistent if the result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in this sequence in the order specified by its program
What is program order?
- Any legal re-ordering is allowed
- The program order is the order of instructions from a sequential piece of code where programmer’s intuition is preserved
- The order must produce the result a programmer expects
- Can out-of-order execution violate program order?
- No. All microprocessors commit instructions in-order and that is where the state becomes visible
- For modern microprocessors the program order is really the commit order
- Can out-of-order (OOO) execution violate SC?
- Yes. Need extra logic to support SC on top of OOO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|