1 / 32

Condition Variables and Transactional Memory: Problem or Opportunity?

Polina Dudnik and Michael Swift University of Wisconsin, Madison. Condition Variables and Transactional Memory: Problem or Opportunity?. Executive Summary. Problem: thread synchronization in TM Goal: robust synchronization primitive State of the art: Retry/orelse

tate
Download Presentation

Condition Variables and Transactional Memory: Problem or Opportunity?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Polina Dudnik and Michael Swift University of Wisconsin, Madison Condition Variables and Transactional Memory: Problem or Opportunity?

  2. Executive Summary • Problem: thread synchronization in TM • Goal: robust synchronization primitive • State of the art: Retry/orelse • Main point: Condition Variables [CVs] still relevant • Our contributions: • TM-compatible condition variables • Implementation independent • Performance comparable to original CVs

  3. Outline • Lessons from the past • New ideas for TM • Transaction/Condition Variable Interactions • Design of TM-safe Condition Variables • Evaluation

  4. What is the problem? • How should threads coordinate? • How should threads wait for an event or state change? • How does this problem change with transactions?

  5. On the Road to CVs • Semaphores [Dijkstra ‘65] • Condition Critical Regions (CCRs) [Hoare ‘72]

  6. Hoare on CCR • I feel this proposal [condition critical regions] is not suitable for operating system implementation. My proposed method encourages the programmer to ignore the question of which of several outstanding requests for a resource should be granted. • Sir Anthony Hoare [Belfast ‘71]

  7. Limitations of CCR • Atomicity • Excessive Context Switching • Restrictive Scheduling

  8. Solution: Condition Variables • Condition variable = queue of waiters • Associated lock maintains mutual exclusion • Signaling a CV = hint that state has changed [Mesa semantics: Lampson ‘79] • Multiple CVs provide prioritized wakeup

  9. Problem Solved • CCR • Atomicity Concerns • Performance Issues • Restrictive Scheduling • Condition Variables • Monitors • Precise Wakeup • Explicit Signaling/Multiple CVs

  10. CVs Limitations • Nested monitor problem • How about nested function calls? • Or waiting on two event queues? • Retry/orelse solves these problems!

  11. TM Synchronization Today • Retry/orelse [Harris et al. 2005]

  12. Why not retry? • Nesting • Composability • Restrictive scheduling • Potentially poor scalability • Other proposals have the same problems: • atomic CCRs [Harris 2003], atomic Wait [Smaragdakis 2007], X10 conditional atomic blocks [Charles 2005] • It is too early to give up on condition variables!

  13. Outline • Lessons from the past • New ideas • Transaction/Condition Variable Interactions • Design of TM-safe Condition Variables • Evaluation

  14. TM Condition Variables • Original condition variables • int get() { • lock(l); • getters++; • while (!available) { • wait(cv, l); • } • getters--; • available = false; • unlock(l); • return contents; • }

  15. TM Condition Variables • Convert locks to transactions • int get() { • begin_tx; • getters++; • while (!available) { • wait(cv); • } • getters--; • available = false; • end_tx; • return contents; • }

  16. TM Condition Variables • Wait outside the transaction • int get() { • begin_tx; • getters++; • while (!available) { • end_tx; • wait(cv); • begin_tx; • } • getters--; • available = false; • end_tx; • return contents; • }

  17. Lost Wakeup • Waiting Thread • begin_tx; • read_state; • prepare_wait(); • end_tx; • wait(); • Signaling Thread • begin_tx; • update_state; • signal(); • end_tx; TIME

  18. TM Condition Variables • Split wait • prepare wait within transaction • commit • complete wait • restart transaction • int get() { • begin_tx; • getters++; • while (!available) { • prepare_wait(cv); • end_tx; • complete_wait(cv); • begin_tx; • } • getters--; • available = false; • end_tx; • return contents; • }

  19. TM Condition Variables • What happens with concurrent signalers? • int get() { • begin_tx; • getters++; • while (!available) { • prepare_wait(cv); • end_tx; • complete_wait(cv); • begin_tx; • } • getters--; • available = false; • end_tx; • return contents; • }

  20. Update-Signal Order • Waiting Thread • begin_tx; • while (!state) { • prepare_wait(); • end_tx; • wait(); • begin_tx; • } • end_tx; • Signaling Thread • begin_tx; • update_state; • signal(); • end_tx; TIME

  21. TM-CV Implementations

  22. Outline • Lessons from the past • New ideas for TM • Transaction/Condition Variable Interactions • Design of TM-safe Condition Variables • Evaluation

  23. Workloads • libMicro • Stress-test of conditional synchronization • FluidAnimate PARSEC • Many critical sections, few condition variables ops • StreamCluster PARSEC • Few critical sections, few condition variable ops • Platform: Solaris + GEMS/LogTM-SE, 16 threads

  24. Evaluation • Questions to answer: • Does it work? • How two versions compare in performance? • How does performance compare to locks?

  25. Results

  26. Evaluation • Answers to questions: • Does it work? • YES • How two versions compare in performance? • Differ under stress • How does performance compare to locks? • Comparable performace

  27. Conclusions • Condition Variables are still relevant with TM • Two implementations of TM-CV • Different requirements on TM system • Performance difference subject to potential overlap • Read the paper for: • Implementation independence

  28. QUESTIONS?

  29. Backup Slides

  30. Different Colors

  31. Example CV usage • void BeginWrite() { • pthread_mutex_lock(mutex); • while (NWriters == 1 || NReaders > 0){ • ++WaitingWriters; • pthread_cond_wait(CanWrite,mutex); • --WaitingWriters; • } • NWriters = 1; • pthread_mutex_unlock(mutex}; • }

  32. Lost Wakeup • Waiting Thread • BEGIN_TX • while (!state) { • prepare_wait() • COMMIT_TX • wait() • BEGIN_TX • } • COMMIT_TX • Signaling Thread • BEGIN_TX • update_state • BEGIN_ESCAPE • signal() • END_ESCAPE • COMMIT_TX

More Related