38
Inferring Synchronization under Limited Observability Martin Vechev Eran Yahav Greta Yorsh IBM T.J. Watson Research Center

Inferring Synchronization under Limited Observability

  • Upload
    neena

  • View
    23

  • Download
    0

Embed Size (px)

DESCRIPTION

Inferring Synchronization under Limited Observability. Martin Vechev Eran Yahav Greta Yorsh IBM T.J. Watson Research Center. High Level Setting. Process 1. Process 2. Process 3. 2. High Level Setting. Process 1. Process 2. Process 3. 3. High Level Setting. Process 1. - PowerPoint PPT Presentation

Citation preview

Page 1: Inferring Synchronization  under Limited Observability

Inferring Synchronization under Limited Observability

Martin Vechev Eran Yahav Greta Yorsh

IBM T.J. Watson Research Center

Page 2: Inferring Synchronization  under Limited Observability

High Level Setting

2

Process 1 Process 2 Process 3

Page 3: Inferring Synchronization  under Limited Observability

High Level Setting

3

Process 1 Process 2 Process 3

Page 4: Inferring Synchronization  under Limited Observability

High Level Setting

4

Process 1 Process 2 Process 3

Page 5: Inferring Synchronization  under Limited Observability

High Level Setting

5

Process 1 Process 2 Process 3

Page 6: Inferring Synchronization  under Limited Observability

Challenge

6

Process 1 Process 2 Process 3

How to synchronize processes in order to achieve correctness and good performance ?

Page 7: Inferring Synchronization  under Limited Observability

This Work

7

Assist the programmer by automatically inferring

correct and efficient synchronization

Page 8: Inferring Synchronization  under Limited Observability

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

Synchronization Primitives

8

Page 9: Inferring Synchronization  under Limited Observability

Conditional Critical Regions

• Syntax of CCR

• Synchronization code – guard can observe the program state – guard does not modify program state

guard stmt

9

Page 10: Inferring Synchronization  under Limited Observability

High Level Setting

10

Process 1 Process 2 Process 3

Page 11: Inferring Synchronization  under Limited Observability

CCR Setting

11

Process 1 Process 2 Process 3

s1;s2; s5; s7;

s6; s3;s4;

Specification: • Permissiveness

• Cost as a language of CCR guards

Page 12: Inferring Synchronization  under Limited Observability

• Given a language LG, specification S and program A, program B is maximally permissive, if:

– B satisfies S

– B is obtained from A by adding guards from LG

– Cannot obtain a program C that is correct and more permissive than B from A via LG:

12

Maximal Permissiveness

if B C then C does not satisfy S

Page 13: Inferring Synchronization  under Limited Observability

• Two Algorithms to infer CCR guards– Greedy– Exhaustive

• Guarantee maximal permissiveness– Greedy: under some conditions– Exhaustive: always

• Implementation in SPIN– prototype, examples

Contributions

Page 14: Inferring Synchronization  under Limited Observability

This Work

Safety, No Stuck StatesSpecification:

Language of Guards

Cost:

Automatic Inference of Guards

Process 1 Process 2 Process 3

s1;s2; s5; s7;

s6; s3;s4;

Process 1 Process 2 Process 3

g1 s1;s2; s5; g2s7; s6; s3;s4;

Correct and Maximally Permissive

Page 15: Inferring Synchronization  under Limited Observability

Inference Algorithm

• Construct transition system of input program and specification

• Remove a (minimal) set of transitions such that the result satisfies the specification

• Implement resulting transition system as program by strengthening guards of CCRs in the program

15

Page 16: Inferring Synchronization  under Limited Observability

GREEDY(P : Program) : Program {R = ∅while (true) { ts = < States , Transitions \ R, Init > 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) }}

Inference Algorithm

16

Page 17: Inferring Synchronization  under Limited Observability

Example Language: Observability

• Obs: Variables that can be read by CCR guards

• LE(Obs): language of boolean combinations of equalities between variables in Obs and constants

• Example: Obs: {x, y, z} Guard Expression in LE(Obs): (x!=1 || y!=0 || z!=0)

17

Page 18: Inferring Synchronization  under Limited Observability

Example: Full Observability

• ! (y = 2 && z = 1)

• No Stuck States

Specification:

LE( { x, y, z } )

Cost:

Automatic Inference of Guards

z=y+1;

Process 1

x=z+1; y=x+1;

Process 2 Process 3

Page 19: Inferring Synchronization  under Limited Observability

What is in a state

s,s,s0,0,0

X Y Z

PC1PC2

PC3

Page 20: Inferring Synchronization  under Limited Observability

Build Transition Systems,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

20

Page 21: Inferring Synchronization  under Limited Observability

Select Transitions to Removes,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

21

Page 22: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

22

e,s,e1,0,1

e,e,e1,2,1

y=x+1

z=y+1

Build Transition System

x!=1 || y!=0 || z!=0

x!=1 || y!=0 || z!=0

x!=1 || y!=0 || z!=0

x!=1 || y!=0 || z!=0

Correct and Maximally Permissive

Page 23: Inferring Synchronization  under Limited Observability

Example: Full Observability

• ! (y = 2 && z = 1)

• No Stuck States

Specification:

LE( { x, y, z } )

Cost:

Automatic Inference of Guards

z=y+1;

Process 1

x=z+1; y=x+1;

Process 2 Process 3

(x!=1 || y!=0 || z!=0)z=y+1;Process 1

x=z+1; y=x+1;

Process 2 Process 3

Page 24: Inferring Synchronization  under Limited Observability

Example: Limited Observability

• ! (y = 2 && z = 1)

• No Stuck States

Specification:

LE( { x, , z } )

Cost:

Automatic Inference of Guards

z=y+1;

Process 1

x=z+1; y=x+1;

Process 2 Process 3

Page 25: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

25

Build Transition System

Page 26: Inferring Synchronization  under Limited Observability

Build Transition Systems,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

26

Page 27: Inferring Synchronization  under Limited Observability

Select transition to removes,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

27

Page 28: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

28

Select All Equivalent Transitions

• Implementability

Page 29: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

x=z+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

29• Side-effects

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

y=x+1z=y+1 z=y+1x!=1 || z!=0

x!=1 || z!=0 z=y+1

x!=1 || z!=0

x!=1 || z!=0

Build Transition System

Page 30: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

x=z+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

30

e,e,s1,2,0

e,s,e1,0,1

e,e,s1,1,0

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

y=x+1z=y+1 z=y+1x!=1 || z!=0

x!=1 || z!=0 z=y+1

x!=1 || z!=0

x!=1 || z!=0

Select transitions to remove

Page 31: Inferring Synchronization  under Limited Observability

s,s,s0,0,0

e,s,s1,0,0

s,e,s0,1,0

s,s,e0,0,1

e,e,31,2,0

e,2,e1,0,1

e,e,31,1,0

s,e,e0,1,2

e,s,e2,0,1

s,e,e0,1,1

e,e,e1,2,3

e,e,e1,2,1

e,e,e1,1,2

e,e,e3,1,2

e,e,e,2,3,1

e,e,e2,1,1

x=z+1 y=x+1 z=y+1

y=x+1

y=x+1z=y+1

z=y+1

x=z+1

z=y+1

z=y+1

x=z+1

x=z+1

x=z+1

y=x+1

y=x+1

x!=1 || z!=0

x!=1 || z!=0

x!=1 || z!=0

x!=1 || z!=0

x!=0 || z!=0

x!=0 || z!=0

x!=0 || z!=0

x!=0 || z!=0

x!=1 || z!=0

x!=0|| z!=0

31

Build Transition System

Correct and Maximally Permissive

Page 32: Inferring Synchronization  under Limited Observability

Example: Limited Observability

Automatic Inference of Guards

(x!=1 || z!=0)z=y+1;Process 1

(x!=0 || z!=0)x=z+1; y=x+1;

Process 2 Process 3

z=y+1;

Process 1

x=z+1; y=x+1;

Process 2 Process 3

• ! (y = 2 && z = 1)

• No Stuck States

Specification:

LE( { x, , z } )

Cost:

Page 33: Inferring Synchronization  under Limited Observability

Inference Algorithms

• Greedy algorithm– Resulting program satisfies the specification– No side-effects guarantees maximal permissiveness– Experience: maximally permissive with side-effects– Polynomial

• Exhaustive algorithm– Resulting program satisfies the specification– Maximally permissive – Exponential

33

Page 34: Inferring Synchronization  under Limited Observability

Implementation• Prototype

– Greedy algorithm– Using SPIN

• Examples – Dining philosophers – Asynchronous counters– Race correction

34

Page 35: Inferring Synchronization  under Limited Observability

Infinite Transition System• Preliminary Work

– Finite state abstraction – Same algorithm– Conservatively eliminate potentially stuck states– Cannot guarantee maximally permissive

• Future Work– Refine when state becomes potentially stuck– Specialized abstractions for stuckness– Related to abstractions for termination

35

Page 36: Inferring Synchronization  under Limited Observability

Summary• Algorithms for CCR guard inferences

– Greedy (polynomial) and Exhaustive (exponential)

– Produce maximally permissive programs

– Parametric on User-specified Cost

– Deals with side effects and implementability

36

Page 37: Inferring Synchronization  under Limited Observability

Related Work• Recovery and predication mechanisms

– STM, Isolator, Tolerace

• Synthesis from temporal specification

• Game theory– Memoryless winning strategy for Buchi games

37

Page 38: Inferring Synchronization  under Limited Observability

Ongoing and Future Work

• Conditions for maximal permissiveness of greedy

• Infer other synchronization mechanisms– meta-data, atomic sections, non-blocking

• Abstraction for stuck states

38