Inferring Synchronization under Limited Observability Martin Vechev, Eran Yahav, Greta Yorsh IBM T.J. Watson Research Center (work in progress)

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

Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
Review: Search problem formulation
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Greta YorshEran YahavMartin Vechev IBM Research. { ……………… …… …………………. ……………………. ………………………… } P1() Challenge: Correct and Efficient Synchronization { ……………………………
Greta YorshEran YahavMartin Vechev IBM Research. { ……………… …… …………………. ……………………. ………………………… } T1() Challenge: Correct and Efficient Synchronization { ……………………………
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
“FENDER” AUTOMATIC MEMORY FENCE INFERENCE Presented by Michael Kuperstein, Technion Joint work with Martin Vechev and Eran Yahav, IBM Research 1.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
1 Eran Yahav Technion Joint work with Martin Vechev (ETH), Greta Yorsh (ARM), Michael Kuperstein (Technion), Veselin Raychev (ETH)
Process Synchronization Continued 7.2 The Critical-Section Problem.
Timed Automata.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
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.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
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.
© The McGraw-Hill Companies, Inc., Chapter 8 The Theory of NP-Completeness.
Inferring Synchronization under Limited Observability Martin Vechev Eran Yahav Greta Yorsh IBM T.J. Watson Research Center.
CS21 Decidability and Tractability
1 Lecture 09 – Synthesis of Synchronization Eran Yahav.
Enhancing The Fault-Tolerance of Nonmasking Programs Sandeep S. Kulkarni and Ali Ebnenasir Software Engineering and Network Systems Laboratory Computer.
NP-complete and NP-hard problems
ESE601: Hybrid Systems Introduction to verification Spring 2006.
Complexity 1 Hardness of Approximation. Complexity 2 Introduction Objectives: –To show several approximation problems are NP-hard Overview: –Reminder:
IT University of Copenhagen Lecture 8: Binary Decision Diagrams 1. Classical Boolean expression representations 2. If-then-else Normal Form (INF) 3. Binary.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
1/20 Symbolic Execution and Program Testing Charngki PSWLAB Symbolic Execution and Program Testing James C.King IBM Thomas J.Watson Research Center.
1 The Theory of NP-Completeness 2012/11/6 P: the class of problems which can be solved by a deterministic polynomial algorithm. NP : the class of decision.
Model Checking Lecture 4 Tom Henzinger. Model-Checking Problem I |= S System modelSystem property.
1 The TSP : NP-Completeness Approximation and Hardness of Approximation All exact science is dominated by the idea of approximation. -- Bertrand Russell.
Correctness requirements. Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions.
Benjamin Gamble. What is Time?  Can mean many different things to a computer Dynamic Equation Variable System State 2.
Concurrency, Mutual Exclusion and Synchronization.
1 Automatic Refinement and Vacuity Detection for Symbolic Trajectory Evaluation Orna Grumberg Technion Haifa, Israel Joint work with Rachel Tzoref.
Space Complexity. Reminder: P, NP classes P NP is the class of problems for which: –Guessing phase: A polynomial time algorithm generates a plausible.
Race Checking by Context Inference Tom Henzinger Ranjit Jhala Rupak Majumdar UC Berkeley.
Martin Vechev Eran Yahav Greta Yorsh IBM T.J. Watson Research Center.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
PRACTICAL SYNTHESIS OF CONCURRENT SYSTEMS Martin Vechev Eran Yahav Greta Yorsh IBM T.J. Watson Research Center.
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Predicate Abstraction. Abstract state space exploration Method: (1) start in the abstract initial state (2) use to compute reachable states (invariants)
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
Space Complexity. Reminder: P, NP classes P is the class of problems that can be solved with algorithms that runs in polynomial time NP is the class of.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
1 The Theory of NP-Completeness 2 Review: Finding lower bound by problem transformation Problem X reduces to problem Y (X  Y ) iff X can be solved by.
The NP class. NP-completeness Lecture2. The NP-class The NP class is a class that contains all the problems that can be decided by a Non-Deterministic.
1 SAT SAT: Given a Boolean function in CNF representation, is there a way to assign truth values to the variables so that the function evaluates to true?
Construction We constructed the following graph: This graph has several nice properties: Diameter Two Graph Pebbling Tim Lewis 1, Dan Simpson 1, Sam Taggart.
Complexity of Compositional Model Checking of Computation Tree Logic on Simple Structures Krishnendu Chatterjee Pallab Dasgupta P.P. Chakrabarti IWDC 2004,
NP-Completeness (2) NP-Completeness Graphs 4/13/2018 5:22 AM x x x x x
New Characterizations in Turnstile Streams with Applications
Input Space Partition Testing CS 4501 / 6501 Software Testing
NP-Completeness (2) NP-Completeness Graphs 7/23/ :02 PM x x x x
NP-Completeness Proofs
Instructor: Rajeev Alur
SMT-Based Verification of Parameterized Systems
Program Synthesis is a Game
Abstraction-Guided Synthesis
Intro to Theory of Computation
Where Can We Draw The Line?
Module 7a: Classic Synchronization
NP-Completeness Yin Tat Lee
CS21 Decidability and Tractability
CSE 542: Operating Systems
Abstraction-Guided Synthesis of synchronization
Presentation transcript:

Inferring Synchronization under Limited Observability Martin Vechev, Eran Yahav, Greta Yorsh IBM T.J. Watson Research Center (work in progress)

Assist the programmer in systematically exploring alternative choices of synchronization – correctness – synchronization cost Concurrency is Hard.

Inferring Synchronization Input – program P – specification S Output a program P’ – P’ satisfies S – P’ obtained from P by adding synchronization Challenge: eliminate invalid interleavings while preserving as many valid ones as possible

Dimensions for Comparing Solutions Permissiveness – P1 is more permissive than P2 when  P2    P1  Synchronization Cost – P1 has lower cost than P2 when the running time of synchronization code in P1 is smaller than that of P2

Observability Connection between permissiveness and synchronization cost User input: upper bound on synchronization cost Limits the observations about program state that can be made by the synchronization code max perm for bounded cost permissiveness cost max perm incomparable solutions

Synchronization under Limited Observability Input – program P – specification S – cost function and cost bound C Output a program P’ – P’ satisfies S – P’ obtained from P by adding synchronization restricted to C Is it always possible to find P’ s.t.  P    P’  ? NO!

Maximally Permissive Program P’ is maximally permissive with respect to C – P’ satisfies S – P’ obtained from P by adding synchronization restricted to C – for every P’’ obtained from P by adding synchronization restricted to C if  P’    P’’  then P’’ does not satisfy S

Our Goal Input – program P – specification S – observability C Output a concurrent program P’ – P’ satisfies S – P’ obtained from P by adding synchronization restricted to C – P’ is maximally permissive with respect to C – synchronization code in P’ must not block indefinitely

Semaphores Monitors Conditional critical region (CCR) Fine grained (e.g., CAS) Locks.... Synchronization Mechanisms

Conditional Critical Regions Syntax of CCR Declarative Synchronization code – can observe the program state – does not modify program state How to infer guards for CCRs ? guard  stmt

Limited Observability Bounded cost of synchronization means restricted language of guards LG = { guard | cost(guard) < bound } Limits observations about program state that can be made by the guards

Example Languages of Guards EQ(V) – boolean combination of equalities between variable from V and integer constant – (x != 1 || z != 0) EvenOdd(V) – boolean combinations of predicates even and odd applied to program expressions over V – e(x) || o(y)

Example !(y = 2 && z = 1) Program Specification Full observability EQ({ x,y,z }) op1 { 1: x = z + 1 } op2 { 2: y = x + 1 } op3 { 3: z = y + 1 } main { int x = 0, y = 0, z = 0; op1 || op2 || op3 }

Example 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1

Example !(y = 2 && z = 1) op1 { 1: x = z + 1 } op2 { 2: y = x + 1 } op3 { 3: (x!=1 || y!=0 || z!=0)  z = y + 1 } main { int x = 0, y = 0, z = 0; op1 || op2 || op3 } Program Specification Full observability EQ( { x,y,z } )

Example !(y = 2 && z = 1) Program Specification Limited observability EQ( { x, z } ) op1 { 1: x = z + 1 } op2 { 2: y = x + 1 } op3 { 3: z = y + 1 } main { int x = 0, y = 0, z = 0; op1 || op2 || op3 }

Example !(y = 2 && z = 1) op1 { 1: (x != 0 || z != 0)  x = z + 1 } op2 { 2: y = x + 1 } op3 { 3: (x != 1 || z != 0)  z = y + 1 } main { int x = 0, y = 0, z = 0; op1 || op2 || op3 } Program Specification Limited observability EQ( { x, z } )

Example 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1 x!=1 || z!=0  x!=0 || z!=0  x!=1 || z!=0  x!=0|| z!=0 

Our Approach Construct transition system of P and S Remove a (minimal) set of transitions such that the result satisfies S Implement resulting transition system as program by strengthening guards of CCRs in P

Removing Transitions Which transitions to remove? – bad-transitions transitions on a path to doomed state – cut-transitions transitions from non-doomed to doomed state In what order to remove transitions?

GREEDY(P : Program) : Program { R = ∅ while (true) { ts = if valid(ts) return implement(P,R) B = cut-transitions(ts) if B = ∅ abort “cannot find valid synchronization” select a transition t ∈ B R = R ∪ equiv(t) } Algorithm

Example !(y = 2 && z = 1) Program Specification Limited observability EQ( { x, z } ) op1 { 1: x = z + 1 } op2 { 2: y = x + 1 } op3 { 3: z = y + 1 } main { int x = 0, y = 0, z = 0; op1 || op2 || op3 }

Example 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1

Side Effects Transitions associated with the same CCR are controlled by the same guard Strengthening guard associated with transition t1 has side-effect – if no guard can distinguish between source(t1) and sourc(t2) due to limited observability – transition system without t1 but with t2 is not implementable Side effect may create new doomed states!

Step 0 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1

Step 1 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1 x!=1 || z!=0 

Step 2 1,2,3 0,0,0 e,2,3 1,0,0 1,e,3 0,1,0 1,2,e 0,0,1 e,e,3 1,2,0 e,2,e 1,0,1 e,e,3 1,1,0 1,e,e 0,1,2 e,2,e 2,0,1 1,e,e 0,1,1 e,e,e 1,2,3 e,e,e 1,2,1 e,e,e 1,1,2 e,e,e 3,1,2 e,e,e, 2,3,1 e,e,e 2,1,1 x=z+1 y=x+1 z=y+1 y=x+1 z=y+1 x=z+1 z=y+1 x=z+1 y=x+1 x!=1 || z!=0  x!=0 || z!=0  x!=1 || z!=0  x!=0|| z!=0 

GREEDY(P : Program) : Program { R = ∅ while (true) { ts = if valid(ts) return implement(P,R) B = cut-transitions(ts) if B = ∅ abort “cannot find valid synchronization” select a transition t ∈ B R = R ∪ equiv(t) } Algorithm

Algorithms Greedy algorithm – removes cut-transitions – result satisfies spec (or abort) – if there are no side-effects then the result is maximally permissive – can be extended to be maximally permissive – polynomial Exhaustive algorithm – removes bad-transitions – result satisfies spec (or abort) – (all) maximally permissive – exponential

Initial Evaluation Prototype – greedy algorithm – transition system constructed using SPIN Examples – Dining philosophers – Asynchronous counters – Race correction

Infinite Transition System Finite state abstraction Same algorithm

Example pc2 == 6  even(x+y) op1 { 1: x = x + 1 2: y = y + 1 3: goto 1 } Program Specification EvenOdd(x,y) main { x = 0, y =0; op1 || op2 } op2 { 4: x = x - 1 5: y = y - 1 6: goto 4 } Limited observability

Example op1 { 1: odd(x+y)  x = x + 1 2: y = y + 1 3: goto 1 } Program op2 { 4: x = x - 1 5: odd(x+y)  y = y - 1 6: goto 4 } Result satisfies the spec but might block pc2 == 6  even(x+y) Specification EvenOdd(x,y) Limited observability

Inferring Guards under Abstraction Conservatively eliminate potentially stuck states – cannot guarantee maximally permissive Refine when state becomes potentially stuck – terminates if there is a finite bisimulation quotient Specialized abstractions for stuckness – related to abstractions for termination

Summary Greedy and exhaustive algorithms for inferring guards of CCRs – maximally permissive programs – limited observability – side effects – implementability – observational equivalence – characterizing observable states – minimize synchronization cost

Related Work Recovery and predication mechanisms – STM, Isolator, Tolerace Synthesis from temporal specification – controller synthesis Program repair as a game – memoryless maximal winning strategy

Ongoing and Future Work Greedy algorithm based on domination Conditions for maximal permissiveness Minimize synchronization cost for given observability Complexity of guard inference (NP-hard,coNP-hard,  2 ) Abstraction for stuck states Temporal safety and liveness properties Infer other synchronization mechanisms – meta-data, atomic sections, non-blocking

Problem on Graphs Input – graph G = (V,E) – initial nodes Init  V – equivalence relation   E  E E’ is admissible iff – E’ is closed under  – every node reachable from Init using only edges in E’ has at least one outgoing edge in E’ Search problem: find admissible E’ such that for every E’’ if E’  E’’ then E’’ is not admissible Decision problem: given k, is there a solution E’ to the search problem and |E’| = k Complexity: NP-hard, coNP-hard, in  2

Reduction from 3SAT i=1 m    (l i1  l i2  l i3 ) l ij  { x 1,..., x n, x 1,..., x n } xixi xixi xixi xixi a a choose exactly one of xi, xi l i1 l i3 l i2 l i1 l i3 l i2 aaa choose exactly one of li1,li2,li3

Example l 11 l 13 l 12 x2x2   (x 1  x 2  x 3 )  (x 1  x 4  x 3 ) x3x3 x1x1 l 21 l 23 l 22 x4x4 x3x3 x1x1 Construction b c c b a a

Reduction from 3SAT Build problem of decision problem from gadgets – (G=(E,V), Init, , k) NP-hard – k = 2n + 2m + m + 2 –  is sat iff (G, Init, , k) is YES coNP-hard – k = 2n + 2m + 2 –  is not sat iff (G, Init, , k) is YES