Taming Concurrency: A Program Verification Perspective Shaz Qadeer Microsoft Research.

Slides:



Advertisements
Similar presentations
CHESS : Systematic Testing of Concurrent Programs
Advertisements

Advanced programming tools at Microsoft
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
QED: A Simplifier for Concurrent Programs Shaz Qadeer Microsoft Research Joint work with Tayfun ElmasAli SezginSerdar Tasiran.
The complexity of predicting atomicity violations Azadeh Farzan Univ of Toronto P. Madhusudan Univ of Illinois at Urbana Champaign.
A Program Transformation For Faster Goal-Directed Search Akash Lal, Shaz Qadeer Microsoft Research.
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Α ϒ ʎ …… Reachability Modulo Theories Akash Lal Shaz Qadeer, Shuvendu Lahiri Microsoft Research.
Reduction, abstraction, and atomicity: How much can we prove about concurrent programs using them? Serdar Tasiran Koç University Istanbul, Turkey Tayfun.
A Randomized Dynamic Program Analysis for Detecting Real Deadlocks Koushik Sen CS 265.
1 Symbolic Execution for Model Checking and Testing Corina Păsăreanu (Kestrel) Joint work with Sarfraz Khurshid (MIT) and Willem Visser (RIACS)
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
Algorithmic Verification of Concurrent Programs Shaz Qadeer Microsoft Research.
Reducing Context-bounded Concurrent Reachability to Sequential Reachability Gennaro Parlato University of Illinois at Urbana-Champaign Salvatore La Torre.
CHESS: Systematic Concurrency Testing Tom Ball, Sebastian Burckhardt, Madan Musuvathi, Shaz Qadeer Microsoft Research
Iterative Context Bounding for Systematic Testing of Multithreaded Programs Madan Musuvathi Shaz Qadeer Microsoft Research.
CHESS: A Systematic Testing Tool for Concurrent Software CSCI6900 George.
Tom Ball, Sebastian Burckhardt, Madan Musuvathi, Shaz Qadeer Microsoft Research.
 Thomas Ball Principal Researcher Microsoft Corporation  Sebastian Burckhardt Researcher Microsoft Corporation  Madan Musuvathi Researcher Microsoft.
Poirot – A Concurrency Sleuth Shaz Qadeer Research in Software Engineering Microsoft Research.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture 05.
Types for Atomicity in Multithreaded Software Shaz Qadeer Microsoft Research (Joint work with Cormac Flanagan)
Atomicity in Multi-Threaded Programs Prachi Tiwari University of California, Santa Cruz CMPS 203 Programming Languages, Fall 2004.
/ PSWLAB Atomizer: A Dynamic Atomicity Checker For Multithreaded Programs By Cormac Flanagan, Stephen N. Freund 24 th April, 2008 Hong,Shin.
CS 263 Course Project1 Survey: Type Systems for Race Detection and Atomicity Feng Zhou, 12/3/2003.
Summarizing Procedures in Concurrent Programs Shaz Qadeer Sriram K. Rajamani Jakob Rehof Microsoft Research.
CHESS: Find and Reproduce Heisenbugs in Concurrent Programs Tom Ball, Sebastian Burckhardt, Peli de Halleux, Madan Musuvathi, Shaz Qadeer Microsoft Research.
Atomicity: A powerful concept for analyzing concurrent software Shaz Qadeer Microsoft Research.
C. FlanaganSAS’04: Type Inference Against Races1 Type Inference Against Races Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College.
CHESS Finding and Reproducing Heisenbugs Tom Ball, Sebastian Burckhardt Madan Musuvathi, Shaz Qadeer Microsoft Research Interns: Gerard Basler (ETH Zurich),
Modular Verification of Multithreaded Software Shaz Qadeer Compaq Systems Research Center Shaz Qadeer Compaq Systems Research Center Joint work with Cormac.
Types for Atomicity in Multithreaded Software Cormac Flanagan Systems Research Center HP Labs.
Verifying Commit-Atomicity Using Model Checking Cormac Flanagan University of California, Santa Cruz.
Part II: Atomicity for Software Model Checking. Class Account { int balance; static int MIN = 0, MAX = 100; bool synchronized deposit(int n) { int t =
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
C. FlanaganType Systems for Multithreaded Software1 Cormac Flanagan UC Santa Cruz Stephen N. Freund Williams College Shaz Qadeer Microsoft Research.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 VeriSoft A Tool for the Automatic Analysis of Concurrent Reactive Software Represents By Miller Ofer.
Runtime Refinement Checking of Concurrent Data Structures (the VYRD project) Serdar Tasiran Koç University, Istanbul, Turkey Shaz Qadeer Microsoft Research,
Scope-bounded Multistack Pushdown Systems: - fixed-point - sequentialization - tree-width 1 Salvatore La Torre Gennaro Parlato (U. Salerno, Italy) (U.
Race Checking by Context Inference Tom Henzinger Ranjit Jhala Rupak Majumdar UC Berkeley.
Reduction: A powerful technique for analyzing concurrent software Shaz Qadeer Microsoft Research Collaborators: Cormac Flanagan, UC Santa Cruz Stephen.
Context-bounded model checking of concurrent software Shaz Qadeer Microsoft Research Joint work with: Jakob Rehof, Microsoft Research Dinghao Wu, Princeton.
CIS 842: Specification and Verification of Reactive Systems Lecture 1: Course Overview Copyright 2001, Matt Dwyer, John Hatcliff, and Radu Iosif. The.
Reasoning about programs March CSE 403, Winter 2011, Brun.
1 Model Checking of Robotic Control Systems Presenting: Sebastian Scherer Authors: Sebastian Scherer, Flavio Lerda, and Edmund M. Clarke.
CS527 Topics in Software Engineering (Software Testing and Analysis) Darko Marinov August 30, 2011.
Compositionality Entails Sequentializability Pranav Garg, P. Madhusudan University of Illinois at Urbana-Champaign.
CAPP: Change-Aware Preemption Prioritization Vilas Jagannath, Qingzhou Luo, Darko Marinov Sep 6 th 2011.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Winter 2007SEG2101 Chapter 121 Chapter 12 Verification and Validation.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
CHESS Finding and Reproducing Heisenbugs in Concurrent Programs
Agenda  Quick Review  Finish Introduction  Java Threads.
Testing Concurrent Programs Sri Teja Basava Arpit Sud CSCI 5535: Fundamentals of Programming Languages University of Colorado at Boulder Spring 2010.
What is a software? Computer Software, or just Software, is the collection of computer programs and related data that provide the instructions telling.
A Calculus of Atomic Actions Serdar Tasiran Koc University, Istanbul, Turkey Tayfun ElmasShaz Qadeer Koc University Microsoft Research.
1 Active Random Testing of Parallel Programs Koushik Sen University of California, Berkeley.
Healing Data Races On-The-Fly
Verification for Concurrent Programs
Sequentializing Parameterized Programs
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Threads and Memory Models Hal Perkins Autumn 2011
Atomicity in Multithreaded Software
Over-Approximating Boolean Programs with Unbounded Thread Creation
Threads and Memory Models Hal Perkins Autumn 2009
Foundations and Definitions
Presentation transcript:

Taming Concurrency: A Program Verification Perspective Shaz Qadeer Microsoft Research

Reliable concurrent software? Correctness problem –does program behave correctly for all inputs and all interleavings? Bugs due to concurrency are insidious –non-deterministic, timing dependent –data corruption, crashes –difficult to detect, reproduce, eliminate

P satisfies S Undecidable problem! Why is verification of concurrent programs more difficult than verification of sequential programs?

P satisfies S Assertions: Provide contracts to decompose problem into a collection of decidable problems pre-condition and post-condition for each procedure loop invariant for each loop Abstractions: Provide an abstraction of the program for which verification is decidable Finite-state systems finite automata Infinite-state systems pushdown automata, counter automata, timed automata, Petri nets

Interference int t; t := x; t := t + 1; x := t; Correct pre x = 0; post x = 1;

Interference int t; t := x; t := t + 1; x := t; Incorrect! pre x = 0; post x = 2; int t; t := x; t := t + 1; x := t; AB

Controlling interference int t; acquire(l); t := x; t := t + 1; x := t; release(l); Correct! pre x = 0; post x = 2; int t; acquire(l); t := x; t := t + 1; x := t; release(l); AB

Interference makes program verification difficult Annotation explosion with the assertion approach State explosion with the abstraction approach

Annotation explosion For sequential programs –assertion for each loop –assertion refers only to variables in scope For concurrent programs –assertion for each control location –assertion may need to refer to private state of other threads

State explosion SequentialConcurrent Finite-state systems Pushdown systems P.G (P.G) 3 P = # of program locations G = # of global states PSPACE complete Undecidable n = # of threads

Taming interference Atomicity for combating annotation explosion Interference-bounding for combating state explosion

Critical_Section l; /*# guarded_by l */ int balance; Bank account /*# atomic */ void deposit (int x) { acquire(l); int r = balance; balance = r + x; release(l); } /*# atomic */ int read( ) { int r; acquire(l); r = balance; release(l); return r; } /*# atomic */ void withdraw(int x) { int r = read(); acquire(l); balance = r – x; release(l); }

Atomicity violation in StringBuffer (Flanagan-Q, PLDI 03) public final class StringBuffer { private int count; private char[ ] value;. public synchronized StringBuffer append (StringBuffer sb) { if (sb == null) sb = NULL; int len = sb.length( ); int newcount = count + len; if (newcount > value.length) expandCapacity(newcount); sb.getChars(0, len, value, count); //use of stale len !! count = newcount; return this; } public synchronized int length( ) { return count; } public synchronized void getChars(...) {... } }

Inadequate atomicity is a good predictor of undesirable interference! compared to data races Numerous tools for detecting atomicity violations static (Type systems, ESPC, QED) dynamic (Atomizer, AVIO, AtomAid, Velodrome, …) Significant effort cutting across communities architecture and operating systems programming languages and compilers testing and formal methods

Definition of atomicity deposit is atomic if for every non-serialized execution, there is a serialized execution with the same behavior         acq(l)r=balbal=r+nrel(l)xyz  Serialized execution of deposit         acq(l)r=balbal=r+nrel(l)xyz         acq(l)r=balbal=r+nrel(l)xyz  Non-serialized executions of deposit

S0S0 S1S1 S2S2 S3S3 S4S4 S7S7 S6S6 S5S5 acq(l)r=balbal=r+nrel(l)xyz S0S0 T1T1 T2T2 T3T3 S4S4 S7S7 T6T6 S5S5 r=balbal=r+nrel(l)xyz acq(l) S0S0 T1T1 S2S2 T3T3 S4S4 S7S7 S6S6 S5S5 yr=balbal=r+nrel(l)xacq(l)z S0S0 T1T1 T2T2 T3T3 S4S4 S7S7 S6S6 S5S5 r=balbal=r+nrel(l)xyz S0S0 S1S1 S2S2 T3T3 S4S4 S7S7 S6S6 S5S5 acq(l)r=balbal=r+nrel(l)yz x Reduction (Lipton, CACM 75)

 B: both right + left commutes –variable access holding lock  A: atomic action, non-commuting –access unprotected variable Four atomicities  L: left commutes –lock release  R: right commutes –lock acquire

S0S0. S5S5 R* A L*xY... S0S0. S5S5 R* A L* x Y... Sequential composition  Theorem: Sequence (R+B)*;(A+  ); (L+B)* is atomic CCCCCC CCCAAA CCCLLL CARARR CARLBB CARLB; ; A R;A;L ; R;A;L C A ; A R; B ; A; L A R

Critical_Section l; /*# guarded_by l */ int balance; Bank account /*# atomic */ void deposit (int x) { acquire(l); int r = balance; balance = r + x; release(l); } /*# atomic */ int read( ) { int r; acquire(l); r = balance; release(l); return r; } /*# atomic */ void withdraw(int x) { int r = read(); acquire(l); balance = r – x; release(l); } RBBLRBBL A RBLBRBLB A ARBLARBL C Incorrect!

Critical_Section l; /*# guarded_by l */ int balance; Bank account /*# atomic */ void deposit (int x) { acquire(l); int r = balance; balance = r + x; release(l); } /*# atomic */ int read( ) { int r; acquire(l); r = balance; release(l); return r; } /*# atomic */ void withdraw(int x) { acquire(l); int r = balance; balance = r – x; release(l); } RBBLRBBL A RBLBRBLB A RBBLRBBL A Correct!

Taming interference Atomicity for combating annotation explosion Interference-bounding for combating state explosion

Interference bounding An approach to the state-explosion problem Explore all executions with a bounded amount of interference –increase the interference bound iteratively Good idea if low interference bound –can be exploited by algorithms –is enough to expose bugs

Context-bounded verification [Wu-Q, PLDI 04] [Rehof-Q, TACAS 05]           Context Context switch Interference proportional to number of context switches Explore all executions with few context switches Unbounded computation within each context –Different from bounded model checking

Context-bounding today CHESS [Musuvathi-Q, PLDI 07] JMoped [Suwimonteerabuth et al., SPIN 08] SPIN for multithreaded C programs [Zaks- Joshi, SPIN 08] CBA [Lal-Reps, CAV 08] Static Driver Verifier

Testing concurrent programs is HARD Bugs hidden in rare thread interleavings Today, concurrency testing = stress testing –Poor coverage of interleavings –Unpredictable coverage results in “Heisenbugs” The mark of reliability of the system still remains its ability to withstand stress

CHESS in a nutshell Replace the OS scheduler with a demonic scheduler Systematically explore all scheduling choices Concurrent Program Win32 API Kernel Scheduler Kernel Scheduler Demonic Scheduler Demonic Scheduler

CHESS architecture Kernel: Threads, Scheduler, Synchronization Objects Kernel: Threads, Scheduler, Synchronization Objects While(not done) { TestScenario() } While(not done) { TestScenario() } TestScenario() { … } Program CHESS CHESS runs the scenario in a loop Each run takes different interleaving Each run is repeatable Win32 API Intercept synchronization and threading calls To control and introduce nondeterminism Detect Assertion violations Deadlocks Dataraces Livelocks

CHESS methodology generalizes CHESS works for –Unmanaged programs (written in C, C++) –Managed programs (written in C#,…) –Singularity applications With appropriate wrappers, can work for Java, Linux applications.NET Program.NET Program.NET CLR CHESS Win32 Program Win32 Program Win32 / OS CHESS Singularity Program Singularity Program Singularity CHESS

CHESS: Systematic testing for concurrency Kernel: Threads, Scheduler, Synchronization Objects While(not done){ TestScenario() } TestScenario(){ … } Program CHESS Win32 API CHESS runs the scenario in a loop Each run is a different interleaving Each run is repeatable

x = 1; … x = k; State-space explosion x = 1; … x = k; … n threads k steps each Number of executions = O( n nk ) Exponential in both n and k –Typically: n 100 Limits scalability to large programs Goal: Scale CHESS to large programs (large k) Thread 1Thread n

x = 1; if (p != 0) { x = p->f; } Preemption-bounding Prioritize executions with small number of preemptions Two kinds of context switches: Preemptions – forced by the scheduler e.g. Time-slice expiration Non-preemptions – a thread voluntarily yields e.g. Blocking on an unavailable lock, thread end x = p->f; } x = 1; if (p != 0) { p = 0; preemption non-preemption Thread 1Thread 2

Preemption-bounding in CHESS The scheduler has a budget of c preemptions –Nondeterministically choose the preemption points Resort to non-preemptive scheduling after c preemptions Once all executions explored with c preemptions –Try with c+1 preemptions

x = 1; … x = 1; … x = k; Property 1: Polynomial bound Terminating program with fixed inputs and deterministic threads –n threads, k steps each, c preemptions Number of executions <= nk C c. (n+c)! = O( (n 2 k) c. n! ) Exponential in n and c, but not in k x = 1; … x = k; x = 1; … x = k; … x = k; Choose c preemption points Permute n+c atomic blocks Thread 1Thread 2

Property 2: Simple error traces Finds smallest number of preemptions to the error Number of preemptions better metric of error complexity than execution length

Property 3: Coverage metric If search terminates with preemption- bound of c, then any remaining error must require at least c+1 preemptions Intuitive estimate for –The complexity of the bugs remaining in the program –The chance of their occurrence in practice

Property 4: Many bugs with 2 preemptions ProgramLines of code Bugs Work Stealing Q4K4 CDS6K1 CCR9K3 ConcRT16K4 Dryad18K7 APE19K4 STM20K2 TPL24K9 PLINQ24K1 Singularity175K2 37 (total) Acknowledgement: testers from PCP team

Coverage vs. Preemption-bound

CHESS status Being used by testers in many Microsoft product groups Demo and session at Professional Developer Conference 2008 CHESS for Win32 – CHESS for.NET –Coming soon

So far … Interference makes program verification difficult Taming interference –atomicity –interference-bounding

Whither next? Concurrent programs as a composition of modules implementing atomic actions Inteference-bounding for general concurrent systems Symbolic context-bounded verification

Structuring concurrent programs In addition to atomicity, we need –behavioral abstraction analogous to pre/post- conditions for sequential code fragments –intuitive and simple contract language A calculus of atomic actions (Elmas- Tasiran-Q, POPL 08) –QED verifier

Interference-bounding for general concurrent systems Task = unit-of-work Shared-memory systems –Task (usually) corresponds to a thread Message-passing systems –Task corresponds to a sequence of messages Need linguistic support for the task abstraction in software models and implementations

Context-bounded reachability is NP-complete UnboundedContext-bounded Finite-state systems Pushdown systems PSPACE complete NP-complete UndecidableNP-complete P = # of program locations G = # of global states n = # of threads c = # of context switches

Symbolic context-bounded verification The transition relations of tasks are usually encoded symbolically –reachability analysis is PSPACE-complete even for a single task Scalable tools for single symbolic task –Bebop, Moped, Getafix Can we extend these techniques to deal with multiple tasks? –Lal and Reps (TACAS 2008, CAV 2008) –Suwimonteerabuth et al. (SPIN 2008)

Questions?