Detecting Data Races in Multi-Threaded Programs

Slides:



Advertisements
Similar presentations
On-the-fly Healing of Race Conditions in ARINC-653 Flight Software
Advertisements

A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Pallavi Joshi  Chang-Seo Park  Koushik Sen  Mayur Naik ‡  Par Lab, EECS, UC Berkeley‡
1 Chao Wang, Yu Yang*, Aarti Gupta, and Ganesh Gopalakrishnan* NEC Laboratories America, Princeton, NJ * University of Utah, Salt Lake City, UT Dynamic.
Goldilocks: Efficiently Computing the Happens-Before Relation Using Locksets Tayfun Elmas 1, Shaz Qadeer 2, Serdar Tasiran 1 1 Koç University, İstanbul,
Race Directed Random Testing of Concurrent Programs KOUSHIK SEN - UNIVERSITY OF CALIFORNIA, BERKELEY PRESENTED BY – ARTHUR KIYANOVSKI – TECHNION, ISRAEL.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
Chapter 6: Process Synchronization
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Debugging Techniques For Concurrent Programs Divjyot Sethi with Stephen Beard, Raman Arun, Arnab Sinha, Yun Zhang, Soumyadeep Ghosh.
Eraser: A Dynamic Data Race Detector for Multithreaded Programs STEFAN SAVAGE, MICHAEL BURROWS, GREG NELSON, PATRICK SOBALVARRO and THOMAS ANDERSON.
Iterative Context Bounding for Systematic Testing of Multithreaded Programs Madan Musuvathi Shaz Qadeer Microsoft Research.
Scaling Model Checking of Dataraces Using Dynamic Information Ohad Shacham Tel Aviv University IBM Haifa Lab Mooly Sagiv Tel Aviv University Assaf Schuster.
Dynamic Data Race Detection. Sources Eraser: A Dynamic Data Race Detector for Multithreaded Programs –Stefan Savage, Michael Burrows, Greg Nelson, Patric.
Today’s Agenda  Midterm: Nov 3 or 10  Finish Message Passing  Race Analysis Advanced Topics in Software Engineering 1.
An efficient data race detector for DIOTA Michiel Ronsse, Bastiaan Stougie, Jonas Maebe, Frank Cornelis, Koen De Bosschere Department of Electronics and.
Atomicity in Multi-Threaded Programs Prachi Tiwari University of California, Santa Cruz CMPS 203 Programming Languages, Fall 2004.
CS 263 Course Project1 Survey: Type Systems for Race Detection and Atomicity Feng Zhou, 12/3/2003.
Efficient On-the-Fly Data Race Detection in Multithreaded C++ Programs Eli Pozniansky & Assaf Schuster.
Concurrency.
S. Narayanasamy, Z. Wang, J. Tigani, A. Edwards, B. Calder UCSD and Microsoft PLDI 2007.
TaintCheck and LockSet LBA Reading Group Presentation by Shimin Chen.
CS533 Concepts of Operating Systems Class 3 Data Races and the Case Against Threads.
Synchronization in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CS533 Concepts of Operating Systems Class 3 Monitors.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Multithreading in Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Cormac Flanagan UC Santa Cruz Velodrome: A Sound and Complete Dynamic Atomicity Checker for Multithreaded Programs Jaeheon Yi UC Santa Cruz Stephen Freund.
/ PSWLAB Eraser: A Dynamic Data Race Detector for Multithreaded Programs By Stefan Savage et al 5 th Mar 2008 presented by Hong,Shin Eraser:
Slide 1 LIRA: Linux Inter-process Race Analyzer Tipp Moseley Intel Corporation University of Colorado.
DETECTION OF POTENTIAL DEADLOCKS AND DATARACES ROZA GHAMARI Bogazici UniversityMarch 2009.
Testing Concurrent Programs COMP Production Programming Mathias Ricken Rice University Spring 2009.
Accelerating Precise Race Detection Using Commercially-Available Hardware Transactional Memory Support Serdar Tasiran Koc University, Istanbul, Turkey.
Eraser: A Dynamic Data Race Detector for Multithreaded Programs STEFAN SAVAGE, MICHAEL BURROWS, GREG NELSON, PATRICK SOBALVARRO, and THOMAS ANDERSON Ethan.
50.530: Software Engineering Sun Jun SUTD. Week 8: Race Detection.
Static Program Analysis of Embedded Software Ramakrishnan Venkitaraman Graduate Student, Computer Science Advisor: Dr. Gopal Gupta.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Dynamic Data Race Detection. Sources Eraser: A Dynamic Data Race Detector for Multithreaded Programs –Stefan Savage, Michael Burrows, Greg Nelson, Patric.
Bugs (part 1) CPS210 Spring Papers  Bugs as Deviant Behavior: A General Approach to Inferring Errors in System Code  Dawson Engler  Eraser: A.
Polytechnic University of Tirana Faculty of Information Technology Computer Engineering Department A MULTITHREADED SEARCH ENGINE AND TESTING OF MULTITHREADED.
Threads. Readings r Silberschatz et al : Chapter 4.
HARD: Hardware-Assisted lockset- based Race Detection P.Zhou, R.Teodorescu, Y.Zhou. HPCA’07 Shimin Chen LBA Reading Group Presentation.
Eraser: A dynamic Data Race Detector for Multithreaded Programs Stefan Savage, Michael Burrows, Greg Nelson, Patrick Sobalvarro, Thomas Anderson Presenter:
Institute for Software Technology Professor Horst Cerjak, Roderick Bloem V&T 02Dynamic Algorithms for Concurrency Verification & Testing Dynamic.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
W4118 Operating Systems Instructor: Junfeng Yang.
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Presenter: Godmar Back
Data Race Detection Assaf Schuster.
Healing Data Races On-The-Fly
Done By: Ashlee Lizarraga Ricky Usher Jacinto Roches Eli Gomez
Instructor: Junfeng Yang
Multithreading Tutorial
Yuan Yu(MSR) Tom Rodeheffer(MSR) Wei Chen(UC Berkeley) SOSP 2005
Threads and Memory Models Hal Perkins Autumn 2011
18.5 An Architecture for Locking Scheduler
Multithreading Tutorial
Threads and Memory Models Hal Perkins Autumn 2009
Multithreading Tutorial
Multithreading Tutorial
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
Chapter 6: Synchronization Tools
50.530: Software Engineering
Tools for the development of parallel applications
CSE 332: Concurrency and Locks
Eraser: A dynamic data race detector for multithreaded programs
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Detecting Data Races in Multi-Threaded Programs Er a s e r A D y n a m ic D a t a - R a c e D e t e c t o r f o r M u lti - T h r e a d e d P r o g r a m s Jo h n C . L i n f o r d Detecting Data Races in Multi-Threaded Programs Slide 1 / 22

Data races are easy to cause and hard to debug. Key Points Data races are easy to cause and hard to debug. Data races can be prevented by following a locking discipline. Lockset enforces a locking discipline. Locking discipline violations are located by lockset refinement. Slide 2 / 22

Lockset is (mostly) insensitive to the scheduler. Key Points Cont. Lockset is (mostly) insensitive to the scheduler. Lockset will detect races which do not manifest in a given execution. Lockset is vulnerable to false alarms. Slide 3 / 22

Data Race Review Two threads access a shared variable At least one access is a write, Simultaneous access is not prevented. Example (variable X is global and shared) Thread 1 Thread 2 X = 2.7 X = 3.1 Z = 2 T = X Two threads access a shared variable Execution Slide 4 / 22

Data Race Demonstration Cont. t1 = new Thread() { public void run() { while(t1 != null) { ... shared[0] = shared[0] + 1; } t2 = new Thread() { public void run() { while(t2 != null) { ... shared[0] = shared[0] + 1; } int[] shared = new int[1]; Thread t1, t2; public DataRace() { // Initialize and start threads (shown below) } Slide 5 / 22

Data Race Demonstration Data races often lead to unexpected and even nondeterministic behavior The outcome may be dependent on specific execution order (threads' interleaving) Click image to start Slide 6 / 22

Eraser [Savage, Burrows, et al., 1997] On-the-fly tool. Lockset algorithm. Code annotations to flag special cases. Can be extended to handle other locking mechanisms (IRQs). Used in industry. Slows applications by a factor of 10 – 30. Slide 7 / 22

The Lockset Algorithm (Simple Form) Let locks_held(t) be the set of locks held by thread t For each shared memory location v, initialize C(v) to the set of all locks On each access to v by thread t, Set C(v) := C(v) ∩ locks_held(t) If C(v) := {}, then issue a warning Detects races not manifested in one execution. Generates false alarms. Lockset Refinement Slide 8 / 22

Lockset Refinement Example Program locks_held C(v) Warning! int v; v := 1024; lock(mu1); v := v + 1; unlock(mu1); lock(mu2); unlock(mu2); {} {mu1} {mu2} {mu1, mu2} {mu1} {} Slide 9 / 22

Simple Lockset is too Strict Variables initialized without locks held. Read-shared data read without locks held. Read-write locking mechanisms (producer / consumer). Lockset will produce false-positives for: Slide 10 / 22

Lockset State Diagram Virgin Exclusive Shared Shared-Modified Warnings are issued only in the Shared-Modified state Slide 11 / 22

Lockset State Example Program locks_held C(v) State(v) int v; lock(mu1); v := v + 1; unlock(mu1); lock(mu2); unlock(mu2); {} {mu1} {mu2} {mu1, mu2} {mu1} {} Virgin Exclusive Shared Shared-Modified T1 T2 T1 Race detected correctly Slide 12 / 22

The Lockset Algorithm (Extended) Let locks_held(t) be the set of locks held in any mode by thread t Let write_locks_held(t) be the set of locks held in write mode by thread t For each shared memory location v, initialize C(v) to the set of all locks On each read of v by thread t, Set C(v) := C(v) ∩ locks_held(t) If C(v) = {}, then issue a warning On each write of v by thread t, Set C(v) := C(v) ∩ write_locks_held(t) Slide 13 / 22

Unhandled Cases in Eraser Memory reuse Unrecognized thread API Initialization in different thread Benign races if(fptr == NULL) { lock(fptr_mu); fptr = open(filename); } unlock(fptr_mu); Slide 14 / 22

Unhandled Cases in Eraser Cont. Race on and will be missed if executes first int[] shared = new int[1]; Thread t = new Thread() { public void run() { shared = shared + 1; ... }; ... shared = 512; t.start(); shared = shared + 256; ... [Seragiotto, 2005] Slide 15 / 22

Unhandled Cases in Eraser Cont. Program State(shared) Data race is not detected! int[] shared = new int[1]; shared = 512; t.start(); shared = shared + 256; Thread t = new Thread() { public void run() { shared = shared + 1; ... }; ... Virgin Exclusive Shared Shared-Modified locks_held C(v) {} {mu1} {} Slide 16 / 22

Unhandled Cases in Eraser Cont. Data race is detected! Program State(shared) int[] shared = new int[1]; shared = 512; t.start(); Thread t = new Thread() { public void run() { shared = shared + 1; ... }; shared = shared + 256; Virgin Exclusive Shared Shared-Modified locks_held C(v) {} {mu1} {} Slide 17 / 22

Implementations: Eraser Maintains hash table of sets of locks. Represents each set of locks with an index. Every shared memory location has shadow memory containing lockset index and state. Shadow memory is located by adding offset to shared memory location address. Slide 18 / 22

Implementations: Eraser v Program Memory Shadow Memory &v + Shadow Offset Lockset Index Table mu1 mu2 Lock Vector Shared memory location v is associated with locks mu1 and mu2 [Savage, Burrows, et al., 2005] Slide 19 / 22

Ladybug Demonstration Rewrite class file j a v a - c p L a d y b u g .j a r b r. i m e . u s p .l a d y b u g . L a d y b u g C l a s s R e w ri t e r D a t a R a c e . cl a s s Run modified class j a v a - c p L a d y b u g .j a r: . D a t a R a c e Races reported as exceptions br.ime.usp.ladybug.RCException: [line 9] Race condition detected: t2 of DataRace (hash code = 1b67f74) with Thread-0 at br.ime.usp.ladybug.StaticLadybug.warn(StaticLadybug.java:1014) at br.ime.usp.ladybug.eraser.EraserGC.writeField(EraserGC.java:47) ... at DataRace.access$202(DataRace.java:9) at DataRace$1.run(DataRace.java:37) Can also use GUI Slide 20 / 22

Data races are easy to cause and hard to debug. Conclusion Data races are easy to cause and hard to debug. Data races can be prevented by following a locking discipline. Lockset enforces a locking discipline. Locking discipline violations are located by lockset refinement. Lockset is vulnerable to false alarms. Slide 21 / 22

References S. Savage, M. Burrows, G. Nelson, P. Sobalvarro, and T.E. Anderson. Eraser: A Dynamic Data Race Detector for Multithreaded Programs. In ACM Transactions on Computer Systems, 15(4): pp. 391-411, 1997. E. Pozniansky and A. Schuster. Dynamic Data-Race Detection in Lock-Based Multi-Threaded Programs. In Principles and Practice of Parallel Programming, pp. 170-190, 2003. E. Pozniansky and A. Schuster. MultiRace: Efficient Data Race Detection Tool for Multithreaded C++ Programs. 2005. http://dsl.cs.technion.ac.il/projects/multirace/MultiRace.htm. C. Seragiotto. Ladybug: Race Condition Detection in Java. 2005. http://www.par.univie.ac.at/~clovis/ladybug/ Slide 22 / 22