a tutorial
play

A Tutorial By Sarita Adve & Kourosh Gharachorloo Slides by Jim - PowerPoint PPT Presentation

Shared Memory Consistency Models: A Tutorial By Sarita Adve & Kourosh Gharachorloo Slides by Jim Larson Outline Concurrent programming on a uniprocessor The effect of optimizations on a uniprocessor The effect of the same


  1. Shared Memory Consistency Models: A Tutorial By Sarita Adve & Kourosh Gharachorloo Slides by Jim Larson

  2. Outline  Concurrent programming on a uniprocessor  The effect of optimizations on a uniprocessor  The effect of the same optimizations on a multiprocessor  Methods for restoring sequential consistency  Conclusion

  3. Outline  Concurrent programming on a uniprocessor  The effect of optimizations on a uniprocessor  The effect of the same optimizations on a multiprocessor  Methods for restoring sequential consistency  Conclusion

  4. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0

  5. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 0

  6. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 0

  7. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 0

  8. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 1

  9. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 1

  10. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 1 Critical Section is Protected Works the same if Process 2 runs first! Process 2 enters its Critical Section

  11. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 0 Arbitrary interleaving of Processes

  12. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 1 Arbitrary interleaving of Processes

  13. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 1 Both processes can block but the critical section remains protected. Deadlock can be fixed by extending the algorithm with turn-taking

  14. Outline  Concurrent Programming on a Uniprocessor  The effect of optimizations on a Uniprocessor  The effect of the same optimizations on a Multiprocessor without Sequential Consistency  Methods for restoring Sequential Consistency  Conclusion

  15. Optimization: Write Buffer with Bypass SpeedUp: Write takes 100 cycles, buffering takes 1 cycle. So Buffer and keep going. Problem: Read from a Location with a buffered Write pending?? (Single Processor Case)

  16. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Write Buffering

  17. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 1 Flag2 = 0 Flag1 = 1 Write Buffering

  18. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 1 Flag2 = 0 Flag1 = 1 Write Buffering

  19. Optimization: Write Buffer with Bypass SpeedUp: Write takes 100 cycles, buffering takes 1 cycle. Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  20. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section STALL! Flag1 = 0 Flag2 = 1 Flag2 = 0 Flag1 = 1 Write Buffering Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  21. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 1 Flag2 = 0 Flag2 = 1 Write Buffering Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  22. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Does this work for Multiprocessors??

  23. Outline  Concurrent programming on a uniprocessor  The effect of optimizations on a uniprocessor  The effect of the same optimizations on a multiprocessor  Methods for restoring sequential consistency  Conclusion

  24. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Does this work for Multiprocessors?

  25. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  26. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  27. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  28. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  29. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  30. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  31. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Multiprocessor Case Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  32. What happens on a Processor stays on that Processor

  33. Dekker's Algorithm: Global Flags Init to 0 Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Flag1 = 0 Flag2 = 0 Flag1 = 1 Flag2 = 1 Processor 2 knows nothing about the write to Flag1, so has no reason to stall! Rule: If a WRITE is issued, buffer it and keep executing Unless: there is a READ from the same location (subsequent WRITEs don't matter), then wait for the WRITE to complete.

  34. A more general way to look at the Problem: Reordering of Reads and Writes (Loads and Stores).

  35. Consider the Instructions in these processes. Process 1:: Process 2:: Flag1 = 1 Flag2 = 1 If (Flag2 == 0) If (Flag1 == 0) critical section critical section Simplify as: WX WY RX RY

Recommend


More recommend