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

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Ch 7 B.
Section 3. True/False Changing the order of semaphores’ operations in a program does not matter. False.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Concurrent Programming James Adkison 02/28/2008. What is concurrency? “happens-before relation – A happens before B if A and B belong to the same process.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
1 Semaphores and Monitors: High-level Synchronization Constructs.
PARALLEL PROGRAMMING with TRANSACTIONAL MEMORY Pratibha Kona.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Department of Computer Science Presenters Dennis Gove Matthew Marzilli The ATOMO ∑ Transactional Programming Language.
XCalls: Safe I/O in Memory Transactions Haris Volos, Andres Jaan Tack, Neelam Goyal +, Michael Swift, Adam Welc § University of Wisconsin - Madison + §
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
1 Interprocess Communication Race Conditions Two processes want to access shared memory at same time.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Why The Grass May Not Be Greener On The Other Side: A Comparison of Locking vs. Transactional Memory Written by: Paul E. McKenney Jonathan Walpole Maged.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
CS4231 Parallel and Distributed Algorithms AY 2006/2007 Semester 2 Lecture 2 (19/01/2006) Instructor: Haifeng YU.
CS510 Concurrent Systems Introduction to Concurrency.
Concurrency, Mutual Exclusion and Synchronization.
Internet Software Development Controlling Threads Paul J Krause.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
© 2008 Multifacet ProjectUniversity of Wisconsin-Madison Pathological Interaction of Locks with Transactional Memory Haris Volos, Neelam Goyal, Michael.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
CS510 Concurrent Systems Jonathan Walpole. Introduction to Concurrency.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Scalable Computing model : Lock free protocol By Peeyush Agrawal 2010MCS3469 Guided By Dr. Kolin Paul.
CS 311/350/550 Semaphores. Semaphores – General Idea Allows two or more concurrent threads to coordinate through signaling/waiting Has four main operations.
Chapter 6: Process Synchronization
Process Synchronization: Semaphores
PARALLEL PROGRAM CHALLENGES
Background on the need for Synchronization
Chapter 5: Process Synchronization
Midterm review: closed book multiple choice chapters 1 to 9
Semaphore Originally called P() and V() wait (S) { while S <= 0
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
Why Threads Are A Bad Idea (for most purposes)
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
CS333 Intro to Operating Systems
Why Threads Are A Bad Idea (for most purposes)
Why Threads Are A Bad Idea (for most purposes)
Monitors and Inter-Process Communication
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

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

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

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

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?

On the Road to CVs Semaphores [Dijkstra ‘65] Condition Critical Regions (CCRs) [Hoare ‘72] ProducerConsumer region buffer when (count < n) { pool [in] = nextp; in = (in+l) % n; count++; } region buffer when (count > 0 ) { nextc = pool [out]; out = (out + l) % n; count--; }

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]

Limitations of CCR 1.Atomicity 2.Excessive Context Switching 3.Restrictive Scheduling

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

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

CVs Limitations Nested monitor problem How about nested function calls? Or waiting on two event queues?  Retry/orelse solves these problems! void foo () { lock(A); foo_bar(); unlock(A); } void foo_bar() { lock(B); wait(); unlock(B); }

TM Synchronization Today Retry/orelse [Harris et al. 2005] ProducerConsumer void put (int value) { atomic { if (available) { retry; } contents = value; available = true; } int get() { atomic { if (!available) { retry; } available = false; return contents; }

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!

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

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

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

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; }

Lost Wakeup Waiting Thread begin_tx; read_state; prepare_wait(); end_tx; wait(); Signaling Thread begin_tx; update_state; signal(); end_tx;

TM Condition Variables Split wait 1.prepare wait within transaction 2.commit 3.complete wait 4.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; }

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; }

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;

TM-CV Implementations Deferred SignalSpeculative Signal Requirement — Commit Actions to invoke signal Implications — Increased wakeup latency — Commit action overhead Requirements — Escape actions to signal — Robust conflict detection to prevent livelock Implications — Low-latency wakeup

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

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

Evaluation Questions to answer: 1)Does it work? 2)How two versions compare in performance? 3)How does performance compare to locks?

Results

Evaluation Answers to questions: 1)Does it work? YES 2)How two versions compare in performance? Differ under stress 3)How does performance compare to locks? Comparable performace

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

QUESTIONS?

Backup Slides

Different Colors

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}; }

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