memory consistency models
play

Memory consistency models Computer Architecture J. Daniel Garca - PowerPoint PPT Presentation

Memory consistency models Memory consistency models Computer Architecture J. Daniel Garca Snchez (coordinator) David Expsito Singh Francisco Javier Garca Blas ARCOS Group Computer Science and Engineering Department University Carlos


  1. Memory consistency models Memory consistency models Computer Architecture J. Daniel García Sánchez (coordinator) David Expósito Singh Francisco Javier García Blas ARCOS Group Computer Science and Engineering Department University Carlos III of Madrid cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 1/50

  2. Memory consistency models Memory model Memory model 1 2 Sequential consistency 3 Other consistency models 4 Use case: Intel 5 Conclusion cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 2/50

  3. Memory consistency models Memory model Memory consistency P1 P2 Memory P3 P4 Memory consistency model : Set of rules defining how the memory system processes memory operations from multiple processors . Contract between programmer and system. Determines which optimizations are valid on correct programs. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 3/50

  4. Memory consistency models Memory model Memory model Interface between program and its transformers. Defines which values can be returned by a read operation. The language’s memory model has implications for hardware. Hardware Compiler Language Machine Executed C, C++, FORTRAN Code Code . . . cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 4/50

  5. Memory consistency models Memory model Single processor memory model Memory behavior model : Memory operations happen in program order . A read returns the value from the last write in P STORE program order. . . . LOAD Semantics defined by sequential program . . . order : STORE Simple but constrained reasoning. Memory . . . Solve data and control dependencies . LOAD Independent operations may be executed in parallel . Optimizations preserve semantics . cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 5/50

  6. Memory consistency models Sequential consistency Memory model 1 2 Sequential consistency 3 Other consistency models 4 Use case: Intel 5 Conclusion cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 6/50

  7. Memory consistency models Sequential consistency P P2 P3 P4 P5 LOAD . . . STORE . . . LOAD Memory A multiprocessor system is sequentially consistent if the result of any execution is the same that would be obtained if operations from all processors were executed in some sequential order, and operations from each individual processor appear in that sequence in the order established by the program. Leslie Lamport, 1979 cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 7/50

  8. Memory consistency models Sequential consistency Sequential Consistency: Constraints Program order . Memory operations from a program must be made visible to all processes in program order . Atomicity . Total execution order between processes must be consistent requiring that all operations are atomic . All the operations that a processor does after it has seen the new value of a write are not visible to other processes until they have seen the value from that write. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 8/50

  9. Memory consistency models Sequential consistency Atomicity a=1 while(a==0) {} while(b==0) {} x=a b=1 Non atomic writes : Write on b could bypass to while loop and read from a would bypass the write. X=0 . Atomic writes : Sequential consistency is preserved . cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 9/50

  10. Memory consistency models Sequential consistency Sequential consistency constraints all memory operations: Write → Read. Write → Write. Read → Read, Read → Write. Simple model to reason about parallel programs. But, simple single processor reorderings may violate sequential consistency model: Hardware reordering to improve performance. Write buffers, overlapped writes, . . . Compiler optimizations apply transformations with memory operations reordering. Scalar replacement, register allocation, instruction scheduling, . . . Transformations by programmers, or refactoring tools also modify program semantics. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 10/50

  11. Memory consistency models Sequential consistency Sequential consistency violation If caches use a write flag1=0; flag2=0; buffer : Writes are delayed in flag1=1; flag2=1; buffer. if (flag2==0) { if (flag1==0) { Reads obtain the old critical section critical section value . } } Dekker Algorithm is no longer valid . assert(p1!=0 || p2!=0); Dekker algorithm is the first known solution to the mutual exclusion problem. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 11/50

  12. Memory consistency models Sequential consistency Program order flag1=0; flag2=0; Write flag1, 1 Write flag2, 1 flag1=1; flag2=1; if (flag2==0) { if (flag1==0) { critical section critical section } } Read flag2 ← 0 Read flag1 ← ¿0? assert(p1!=0 || p2!=0); cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 12/50

  13. Memory consistency models Sequential consistency Program order flag=0; Write flag, 42 Read flag ← 0 A=42; while (flag!=1) {} flag=1 X=A; Write flag, 1 Read flag ← 1 Read A ← ¿0? cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 13/50

  14. Memory consistency models Sequential consistency Conditions for sequential consistency Sufficient conditions : Each process issues memory operations in program order. After issuing a write , the process that performed the issue waits for completions of write before issuing another operation. After issuing a read , the process that performed the issue waits for completion of read and for completion of the write of the value being read. Wait for write propagation to all processes. Very demanding conditions. There might be necessary conditions that are less demanding. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 14/50

  15. Memory consistency models Other consistency models Memory model 1 2 Sequential consistency 3 Other consistency models 4 Use case: Intel 5 Conclusion cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 15/50

  16. Memory consistency models Other consistency models Optimizations Models relaxing program execution order. W → R. W → W. R → W, W → W. Notation : X → Y Y bypasses X. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 16/50

  17. Memory consistency models Other consistency models Reorderings Processor R → R R → W W → R W → W Alpha � � � � PA-RISC � � � � POWER � � � � SPARC � x86 � AMD64 � IA64 � � � � zSeries � cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 17/50

  18. Memory consistency models Other consistency models Reads bypass writes (W → R) A read may execute before a preceding write . Typical in systems with write buffer . Check consistency with buffer. Allow read buffer. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 18/50

  19. Memory consistency models Other consistency models Other models R → W, W → R. Allow that writes may arrive into memory out of program order. R → W, W → R, R → R, W → W. Avoid only data and control dependencies within processor. Alternatives : Weak consistency. Release consistency. cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 19/50

  20. Memory consistency models Other consistency models Weak ordering Divides memory operations into data operations and synchronization operations . Synchronization operations act as a barrier . 1 All preceding data operations in program order to a synchronization must complete before synchronization is executed. 2 All subsequent data operations in program order to a synchronization operation must wait until synchronization ins completed. 3 Synchronization are performed in program order. Hardware implementation of barrier . Processor keeps a counter : Data operation issue ⇒ increment . Data operation completed ⇒ decrement . cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 20/50

  21. Memory consistency models Other consistency models Release/acquire consistency More relaxed than weak consistency. Synchronization accesses divided into: Acquire . Release . Semantics : Acquire Must complete before all subsequent memory accesses. Release Must complete all previous memory accesses. Subsequent memory accesses MAY initiate. Operations following a release and must wait, must be protected with an acquire . cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 21/50

  22. Memory consistency models Use case: Intel Memory model 1 2 Sequential consistency 3 Other consistency models 4 Use case: Intel 5 Conclusion cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 22/50

  23. Memory consistency models Use case: Intel Consistency model Use case: Intel 4 Consistency model Examples Model effects cbed – Computer Architecture – ARCOS Group – http://www.arcos.inf.uc3m.es 23/50

Recommend


More recommend