Model Checking Concurrent Software Shaz Qadeer Microsoft Research.

Slides:



Advertisements
Similar presentations
Model Checking Lecture 4. Outline 1 Specifications: logic vs. automata, linear vs. branching, safety vs. liveness 2 Graph algorithms for model checking.
Advertisements

Model Checking Lecture 1.
Automatic Verification Book: Chapter 6. How can we check the model? The model is a graph. The specification should refer the the graph representation.
A Technique for Parallel Reachability Analysis of Java Programs Raghuraman R. Sridhar Iyer G. Sajith.
Part IV: Memory Management
Operating Systems Part III: Process Management (Process Synchronization)
Representing Boolean Functions for Symbolic Model Checking Supratik Chakraborty IIT Bombay.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
1 Chao Wang, Yu Yang*, Aarti Gupta, and Ganesh Gopalakrishnan* NEC Laboratories America, Princeton, NJ * University of Utah, Salt Lake City, UT Dynamic.
Part 3: Safety and liveness
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.
Planning based on Model Checking Dept. of Information Systems and Applied CS Bamberg University Seminar Paper Svetlana Balinova.
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.
Goldilocks: Efficiently Computing the Happens-Before Relation Using Locksets Tayfun Elmas 1, Shaz Qadeer 2, Serdar Tasiran 1 1 Koç University, İstanbul,
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.
D u k e S y s t e m s Time, clocks, and consistency and the JMM Jeff Chase Duke University.
UPPAAL Introduction Chien-Liang Chen.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Introduction to Embedded Systems Chapter 14 Reachability Analysis (14.1, – ) Hao Zheng U of South Florida.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
SYMBOLIC MODEL CHECKING: STATES AND BEYOND J.R. Burch E.M. Clarke K.L. McMillan D. L. Dill L. J. Hwang Presented by Rehana Begam.
1 Basic abstract interpretation theory. 2 The general idea §a semantics l any definition style, from a denotational definition to a detailed interpreter.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
UnInformed Search What to do when you don’t know anything.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
1 Carnegie Mellon UniversitySPINFlavio Lerda SPIN An explicit state model checker.
Applying Model Checking To Large Programs Madan Musuvathi Microsoft Research.
1 Eran Yahav and Mooly Sagiv School of Computer Science Tel-Aviv University Verifying Safety Properties.
Run time vs. Compile time
1 Concurrency: Deadlock and Starvation Chapter 6.
Race Conditions CS550 Operating Systems. Review So far, we have discussed Processes and Threads and talked about multithreading and MPI processes by example.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
1 Formal Engineering of Reliable Software LASER 2004 school Tutorial, Lecture1 Natasha Sharygina Carnegie Mellon University.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
Model construction and verification for dynamic programming languages Radu Iosif
Lecture 3: Uninformed Search
Convergence of Model Checking & Program Analysis Philippe Giabbanelli CMPT 894 – Spring 2008.
Symbolic Execution with Abstract Subsumption Checking Saswat Anand College of Computing, Georgia Institute of Technology Corina Păsăreanu QSS, NASA Ames.
Predicate Abstraction. Abstract state space exploration Method: (1) start in the abstract initial state (2) use to compute reachable states (invariants)
CS265: Dynamic Partial Order Reduction Koushik Sen UC Berkeley.
/ PSWLAB S PIN Search Optimization from “THE SPIN MODEL CHECKER” by G. Holzmann Presented by Hong,Shin 23 th Nov SPIN Search.
Model Checking Lecture 1. Model checking, narrowly interpreted: Decision procedures for checking if a given Kripke structure is a model for a given formula.
/ PSWLAB Thread Modular Model Checking by Cormac Flanagan and Shaz Qadeer (published in Spin’03) Hong,Shin Thread Modular Model.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
CS 153 Design of Operating Systems Winter 2016 Lecture 7: Synchronization.
Today’s Agenda  Quiz 5 (end of the class)  Quick Review  Finish Search Algorithms Formal Methods in Software Engineering1.
Model Checking Lecture 1: Specification Tom Henzinger.
Agenda  Quick Review  Finish Introduction  Java Threads.
Symbolic Model Checking of Software Nishant Sinha with Edmund Clarke, Flavio Lerda, Michael Theobald Carnegie Mellon University.
Complexity Relief Techniques for Model Checking METU, Aug SOFTWARE VERIFICATION WORKSHOP Hüsnü Yenigün Sabanci University Informatics Institute,
Instructor: Rajeev Alur
Semaphores and Condition Variables
Section 10: Last section! Final review.
Space-Reduction Strategies for Model Checking Dynamic Software
Over-Approximating Boolean Programs with Unbounded Thread Creation
Threading And Parallel Programming Constructs
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
An explicit state model checker
Linear Time Properties
CSE 153 Design of Operating Systems Winter 19
Chapter 6: Synchronization Tools
CSE 153 Design of Operating Systems Winter 2019
Presentation transcript:

Model Checking Concurrent Software Shaz Qadeer Microsoft Research

Model checking, narrowly interpreted: Decision procedures for checking if a given Kripke structure is a model for a given formula of a temporal logic.

Why is this of interest to us? Because the dynamics of a discrete system can be captured by a Kripke structure. Because some dynamic properties of a discrete system can be stated in temporal logics.  Model checking = System verification

Model checking, generously interpreted: Algorithms, rather than proof calculi, for system verification which operate on a system model (semantics), rather than a system description (syntax).

A specific model-checking problem is defined by I |= S “implementation” (system model) “specification” (system property) “satisfies”, “implements”, “refines” (satisfaction relation)

Paradigmatic example: mutual-exclusion protocol loop out: x1 := 1; last := 1 req: await x2 = 0 or last = 2 in: x1 := 0 end loop. loop out: x2 := 1; last := 2 req: await x1 = 0 or last = 1 in: x2 := 0 end loop. || P1 P2

Model-checking problem I |= S system modelsystem property satisfaction relation

Model-checking problem I |= S system modelsystem property satisfaction relation

While the choice of system model is important for ease of modeling in a given situation, the only thing that is important for model checking is that the system model can be translated into some form of state-transition graph.

a a,bb q1q1 q3q3 q2q2

State-transition graph Q set of states{q 1,q 2,q 3 } A set of atomic observations{a,b}   Q  Q transition relation q 1  q 2 [ ]: Q  2 A observation function [q 1 ] = {a} set of observations

Mutual-exclusion protocol loop out: x1 := 1; last := 1 req: await x2 = 0 or last = 2 in: x1 := 0 end loop. loop out: x2 := 1; last := 2 req: await x1 = 0 or last = 1 in: x2 := 0 end loop. || P1 P2

oo001 rr112 ro101 or012 ir112 io101 pc1: {o,r,i} pc2: {o,r,i} x1: {0,1} x2: {0,1} last: {1,2} 3  3  2  2  2 = 72 states

The translation from a system description to a state-transition graph usually involves an exponential blow-up !!! e.g., n boolean variables  2 n states This is called the “state-explosion problem.”

Finite state-transition graphs don’t handle: - recursion (need pushdown models) We will talk about some of these issues later. State-transition graphs are not necessarily finite-state

Model-checking problem I |= S system modelsystem property satisfaction relation

Example: Mutual exclusion It cannot happen that both processes are in their critical sections simultaneously. Initial states: pc1 = o  pc2 = o  x1 = 0  x2 = 0 Error states: pc1 = r  pc2 = r Reachability analysis: Does there exist a path from an initial state to an error state?

Complexity of state transition graph is due to: 1.Control: finite (single program counter) vs. infinite (stack of program counters) 2.Data: finite domain (boolean) vs. infinite domain (integers) vs. dynamically created (heap objects) 3.Threads of control: single vs. multiple vs. dynamically created For example, the mutual exclusion protocol has multiple threads of finite control and finite data.

Control Data AcyclicLoopingInfinite Finite Infinite YesYesYes YesNoNo Decidability of reachability analysis Single thread of control: Finite

Control Data AcyclicLoopingInfinite Finite Infinite YesYesNo YesNoNo Decidability of reachability analysis Multiple threads of control: Finite

Analysis of concurrent programs is difficult Finite-data finite control program –n lines –m states for global data variables 1 thread –n * m states K threads –(n) K * m states

Outline Reachability analysis for finite data –finite control –infinite control Richer property specifications –safety vs. liveness

Part 1: Reachability analysis for finite-state systems

Why should we bother about finite-data programs? Two reasons: 1.These techniques are applicable to infinite-data programs without the guarantee of termination 2.These techniques are applicable to finite abstractions of infinite-data programs

Reachability analysis for finite data and finite control 1.Stateless model checking or systematic testing - enumerate executions 2.Explicit-state model checking with state caching - enumerate states Note: These techniques applicable even to infinite data and infinite control programs, but without the guarantee of termination.

Stateless model checking a.k.a Systematic testing

void doDfs() { stack.push(initialState); while (stack.Count > 0) { State s := (State) stack.Peek(); // execute the next enabled thread int tid := s.NextEnabledThread(); if (tid = -1) { stack.Pop(); continue; } State newS := s.Execute(tid); stack.push(newS); }

This algorithm is not fully stateless since it requires a stack of states. init t1t1 t2t2 tntn s Maintain instead a stack of thread identifiers. To recreate the state at the top of the stack, replay the stack from the initial state

The algorithm will not terminate in general. However, it will terminate if - the program is acyclic - if we impose a bound on the execution depth Even if it terminates, it is very expensive - after each step, every single thread is scheduled - leads to too many executions

T1 int x = 0; x++; g++; x++; g++; int g = 0; T2 int y = 0; y++; g++; y++; g++; Naïve stateless model checking: No. of explored executions = (4+4)!/(4!) 2 = 70 No. of threads = n No. of steps executed by each thread = k No. of executions = (nk)! / (k!)^n Atomic Increment

An access to x by T1 is invisible to T2. T1: x++ T2 Unnecessary to explore this transition An access to y by T2 is invisible to T1. T1 T2: y++ Unnecessary to explore this transition Partial-order reduction techniques

T1 int x = 0; x++; g++; x++; g++; int g = 0; T2 int y = 0; y++; g++; y++; g++; Without partial-order reduction: No. of explored executions = (4+4)!/(4!) 2 = 70 With partial-order reduction: No. of explored executions = (2+2)!/(2!) 2 = 6

T1 T2 x++g++y++g++x++g++y++g++ x++y++g++ x++g++y++g++ y++x++g++ x++g++y++g++ y++x++g++ x++y++g++ and so on … Execution e1 is equivalent to e2 if e2 can be obtained from e1 by commuting adjacent independent operations.

T2 x++g++y++g++x++g++y++g++ T1

An execution is partially rather than totally ordered! - all linearizations of a partially-ordered execution are equivalent T2 x++g++ y++g++ x++g++ y++g++ T1 Goal: an algorithm to systematically enumerate one and only one representative execution from each equivalence class

T1 int x = 0; x++; acq(l); g++; rel(l); x++; acq(l); g++; rel(l); Lock l; int g = 0; T2 int y = 0; y++; acq(l); g++; rel(l); y++; acq(l); g++; rel(l); Non-atomic Increment

Challenge Goal: an algorithm to systematically enumerate one and only one representative execution from each equivalence class Obstacles: 1.Dependence between actions difficult to compute statically 2.Difficult to avoid repeating equivalent executions

Happens-before relation Partial-order on atomic actions in a concurrent execution Inter-thread edges based on program order Intra-thread edges based on synchronization actions –acquire and release on locks –fork and join on threads –P and V on semaphores –wait and signal on events

Happens-before relation acquire(mx); acquire(my); x++; y++; release(my); release(mx); acquire(mx); x++; release(mx); acquire(my); y++; release(my);

Data race Partition of program variables into synchronization variables and data variables There is a data-race on x if there are two accesses to x such that –They are unrelated by the happens- before relation –At least one of those accesses is a write

No race acquire(mx); acquire(my); x++; y++; release(my); release(mx); acquire(mx); x++; release(mx); acquire(my); y++; release(my);

Race on x acquire(mx); acquire(my); x++; y++; release(my); release(mx); x++; acquire(my); y++; release(my); A data race usually indicates an error!

Improved partial-order reduction Schedule other threads only at accesses to synchronization variables Justified if each execution is free of data races –check by computing the happens-before relation –report each data race

Clock-vector algorithm Initially: Lock l: CV(l) = [0,…,0] Thread t: CV(t) = [0,…,0] Data variable x: Clock(x) = -1, Owner(x) = 0 Thread t performs: release(l): CV(t)[t] := CV(t)[t] + 1; CV(l) := CV(t) acquire(l): CV(t) := max(CV(t), CV(l)) access(x): if ( Owner(x) = t  Clock(x) < CV(t)[Owner(x)] ) Owner(x) := t; Clock(x) := CV(t)[t] else Report race on x

Further improvements T1 acq(lx); x++; rel(lx); T2 acq(ly); y++; rel(ly); Lock lx, ly;int x = 0, y = 0; Previous algorithm results in exploring two linearizations Yet, there is only one partially-ordered execution Perform partial-order reduction on synchronization actions Flanagan-Godefroid 06 Lei-Carver 06

Explicit-state model checking Explicitly generate the individual states Systematically explore the state space –State space: Graph that captures all behaviors Model checking = Graph search Generate the state space graph "on- the-fly" –State space is typically much larger than the reachable set of states

void doDfs() { while (stateStack.Count > 0) { State s := (State) stateStack.Peek(); // execute the next enabled thread int tid := s.NextEnabledThread(); if (tid = -1) { stateStack.Pop(); continue; } State newS := s.Execute(tid); if (stateHash.contains(newS)) continue; stateHash.add(newS); stateStack.push(newS); }

State-space explosion Reachable set of states for realistic software is huge Need to investigate state-space reduction techniques Stack compression Identify behaviorally equivalent states –Process symmetry reduction –Heap symmetry reduction

Stack compression State vector can be very large –cloning the state vector to push an entry on the stack is expensive Each transition modifies only a small part of the state Solution –update state in place –push the state-delta on the stack

Hash compaction Compact states in the hash table [Stern, 1995] –Compute a signature for each state –Only store the signature in the hashtable Signature is computed incrementally Might miss errors due to collisions Orders of magnitude memory savings –Compact 100 kilobyte state to 4-8 bytes Possible to search ~10 million states 50

Explore one out of a (large) set of equivalent states Canonicalize states before hashing State symmetries Current State Canonical State Hash table Hash Signature Successor States 51

Heap canonicalization Heap objects can be allocated in different order –Depends on the order events happen Relocate heap objects to a unique representation state1 state2Canonical Representation Find a canonical representation for each heap graph by abstracting the concrete values of pointers 52

Heap-canonicalization algorithm Basic algorithm [Iosif 01] –Perform deterministic graph traversal of the heap (bfs / dfs) –Relocate objects in the order visited I ncremental canonicalization [Musuvathi- Dill 04] Should not traverse the entire heap in every transition 53

Iosif ’ s canonicalization algorithm Do a deterministic graph traversal of the heap (bfs / dfs) Relocate objects to a canonical location –Determined by the dfs (or bfs) number of the object Hash the resulting heap c r s ayxcayx r s Heap Canonical Heap

c Example: two linked lists r s ayxc r s ayxcayx r s bayx r s 0246 bc 8 Transition: Insert b HeapCanonical Heap y Partial hash values

A Much Larger Example : Linux Kernel Core OS Network File- system Core OSNetworkFilesystem An object insertion hereAffects the canonical location of objects here HeapCanonical Heap p p

Incremental heap canonicalization Access chain –A path from the root to an object in the heap BFS access chain –Shortest of all access paths from a global variable –Break ties lexicographically Canonical location of an object is a function of its bfs access chain r c ab hg gf Access chain of c f BFS access chain of c

Revisiting example c r s ayxc r s ayxcayx r s cayx r s 0246 bb 8 HeapCanonical Heap Relocation Function Table r,s are root vars n is the next field