l ockpick lock inference for atomic sections
play

L OCKPICK : Lock Inference for Atomic Sections Jeffrey S. Foster - PowerPoint PPT Presentation

L OCKPICK : Lock Inference for Atomic Sections Jeffrey S. Foster Michael Hicks Polyvios Pratikakis University of Maryland, College Park Lock Inference for Atomic Sections p. 1/11 Introduction Concurrent programming is notoriously


  1. L OCKPICK : Lock Inference for Atomic Sections Jeffrey S. Foster Michael Hicks Polyvios Pratikakis University of Maryland, College Park Lock Inference for Atomic Sections – p. 1/11

  2. Introduction Concurrent programming is “notoriously difficult” More parallelism is good, too much is wrong Less parallelism is easier, but it slows down the program Synchronization is done using locks Locks are difficult to program Alternative, higher level synchronization abstraction: atomic sections Lock Inference for Atomic Sections – p. 2/11

  3. Atomic Sections int x, y; thread1() { thread2() { atomic { atomic { x = 42; x = 44; y = 43; } } } } Atomic sections usually use optimistic concurrency This work: atomic sections with pessimistic concurrency Lock Inference for Atomic Sections – p. 3/11

  4. L OCKPICK at a glance Create a mutex ℓ ρ for each memory location ρ Create a total ordering on all ℓ ρ to avoid deadlock For every atomic block, if ρ is referenced, then acuire ℓ ρ at the beginning Maintain maximum parallelism (for the given points-to analysis) Lock Inference for Atomic Sections – p. 4/11

  5. L OCKPICK at a glance Create a mutex ℓ ρ for each memory location ρ Create a total ordering on all ℓ ρ to avoid deadlock For every atomic block, if ρ is referenced, then acuire ℓ ρ at the beginning Maintain maximum parallelism (for the given points-to analysis) Inefficient: large number of locations ⇒ large number of locks Lock Inference for Atomic Sections – p. 4/11

  6. L OCKPICK at a glance Find all memory locations ρ that are shared between threads Create a mutex ℓ ρ for each memory location ρ Create a total ordering on all ℓ ρ to avoid deadlock For every atomic block, if ρ is referenced, then acuire ℓ ρ at the beginning Maintain maximum parallelism (for the given points-to analysis) Lock Inference for Atomic Sections – p. 4/11

  7. L OCKPICK at a glance Find all memory locations ρ that are shared between threads Create a mutex ℓ ρ for each memory location ρ Create a total ordering on all ℓ ρ to avoid deadlock For every atomic block, if ρ is referenced, then acuire ℓ ρ at the beginning Maintain maximum parallelism (for the given points-to analysis) Inefficient: many locations are always referenced together Lock Inference for Atomic Sections – p. 4/11

  8. L OCKPICK at a glance Find all memory locations ρ that are shared between threads Create a mutex ℓ ρ for each memory location ρ Create a total ordering on all ℓ ρ to avoid deadlock For every atomic block, if ρ is referenced, then acuire ℓ ρ at the beginning Find and remove unnecessary locks Maintain maximum parallelism (for the given points-to analysis) Lock Inference for Atomic Sections – p. 4/11

  9. Example int x, y; thread1() { atomic { thread2() { atomic { x = 42; x = 44; y = 43; } } } } Lock Inference for Atomic Sections – p. 5/11

  10. Example int x, y; mutex t Lx, Ly; thread1() { atomic { thread2() { atomic { x = 42; x = 44; y = 43; } } } } Lock Inference for Atomic Sections – p. 5/11

  11. Example int x, y; mutex t Lx, Ly; thread1() { atomic { thread2() { atomic { lock(Lx); lock(Ly); x = 42; x = 44; y = 43; } } } } Lock Inference for Atomic Sections – p. 5/11

  12. Example int x, y; mutex t Lx, Ly; thread1() { atomic { thread2() { atomic { lock(Lx); lock(Ly); x = 42; x = 44; y = 43; unlock(Lx); unlock(Ly); } } } } Lock Inference for Atomic Sections – p. 5/11

  13. Example int x, y; mutex t Lx, Ly; thread1() { atomic { thread2() { atomic { lock(Lx); lock(Ly); lock(Lx); x = 42; x = 44; y = 43; unlock(Lx); unlock(Lx); unlock(Ly); } } } } Lock Inference for Atomic Sections – p. 5/11

  14. Example int x, y; mutex t Lx, Ly; thread1() { atomic { thread2() { atomic { lock(Lx); lock(Ly); lock(Lx); x = 42; x = 44; y = 43; unlock(Lx); unlock(Lx); unlock(Ly); } } } } Whenever Ly is locked, Lx is also locked Lx dominates Ly Ly is unnecessary, only adds overhead Optimization: when ρ dominates ρ ′ , protect ρ ′ with ℓ ρ . Lock Inference for Atomic Sections – p. 5/11

  15. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic { atomic { x = 42; x = 44; } y = 43; } } } Lock Inference for Atomic Sections – p. 6/11

  16. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic { atomic { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Lock Inference for Atomic Sections – p. 6/11

  17. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic α 1 { atomic { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Lock Inference for Atomic Sections – p. 6/11

  18. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic α 1 { atomic α 2 { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Lock Inference for Atomic Sections – p. 6/11

  19. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic α 1 { atomic α 2 { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Atomic section α is a set of the locations it dereferences Lock Inference for Atomic Sections – p. 6/11

  20. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic α 1 { atomic α 2 { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Atomic section α is a set of the locations it dereferences α 1 = { x , y } , α 2 = { x } Lock Inference for Atomic Sections – p. 6/11

  21. Example: The Dominates Algorithm int x, y; thread1() { thread2() { atomic α 1 { atomic α 2 { x = 42; x = 44; } y = 43; } } } Each atomic section dereferences a set of locations Atomic section α is a set of the locations it dereferences α 1 = { x , y } , α 2 = { x } x > y Lock Inference for Atomic Sections – p. 6/11

  22. Remarks Domination algorithm reduces the number of used locks Always retains maximum parallelism Sound: it never introduces races May not find minimum number of locks Minimizing the number of locks is NP-hard Proof: reduction from Edge Clique Cover Lock Inference for Atomic Sections – p. 7/11

  23. Example: Limitation of the algorithm atomic { atomic { atomic { y = 3; x = 1; z = 5; z = 4; y = 2; x = 6; } } } α 1 = { x , y } α 2 = { y , z } α 3 = { x , z } No “dominates” relation holds No parallelism possible The program can be synchronized with one lock Lock Inference for Atomic Sections – p. 8/11

  24. What is shared? Inefficiency: Atomic blocks might dereference many locations Only a few are shared between threads Optimization: Only protect shared locations Find continuation effects Intersect effects of threads to find shared locations Lock Inference for Atomic Sections – p. 9/11

  25. Continuation Effects: Example int x, y; main() { x = 1; pthread create(&thread1); y = 2; } thread1() { x = 42; y = 43; } Lock Inference for Atomic Sections – p. 10/11

  26. Continuation Effects: Example int x, y; main() { ε 1 x = 1; ε 2 pthread create(&thread1); ε 3 y = 2; ε 4 } thread1() { ε 5 x = 42; ε 6 y = 43; ε 7 } Lock Inference for Atomic Sections – p. 10/11

  27. Continuation Effects: Example int x, y; main() { ε 1 x = 1; ε 2 pthread create(&thread1); ε 3 y = 2; ε 4 } thread1() { ε 5 x = 42; ε 6 y = 43; ε 7 } Lock Inference for Atomic Sections – p. 10/11

  28. Continuation Effects: Example int x, y; main() { ε 1 x = 1; ε 2 pthread create(&thread1); ε 3 y = 2; ε 4 } thread1() { ε 5 x = 42; ε 6 y = 43; ε 7 } Lock Inference for Atomic Sections – p. 10/11

  29. Continuation Effects: Example int x, y; main() { ε 1 x = 1; ε 2 pthread create(&thread1); ε 3 y = 2; ε 4 } thread1() { ε 5 x = 42; ε 6 y = 43; ε 7 } Lock Inference for Atomic Sections – p. 10/11

  30. Continuation Effects: Example int x, y; main() { ε 1 x = 1; ε 2 pthread create(&thread1); ε 3 y = 2; ε 4 } thread1() { ε 5 x = 42; ε 6 y = 43; ε 7 } shared = ε 4 ∩ ε 6 = { y } Lock Inference for Atomic Sections – p. 10/11

  31. Conclusions Contributions: Atomic sections can be implemented with pessimistic concurrency Heuristic algorithm to reduce number of locks without losing parallelism Finding the minimum number of locks is NP-hard Precise sharing analysis to further reduce needed locks Implementation under construction: L OCKPICK Fine grain locking for shared data-structures Lock Inference for Atomic Sections – p. 11/11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend