810 likes | 1.09k Views
CS294-32: Dynamic Partial Order Reduction. Koushik Sen UC Berkeley. t1: if (x==100) a = 1 else a = 2. t2: if (y==9) a = 3 else a = 4. Exponential Blowup. Computation tree for a single thread . Conditional statement.
E N D
CS294-32: Dynamic Partial Order Reduction Koushik Sen UC Berkeley
t1: if (x==100) a = 1 else a = 2 t2: if (y==9) a = 3 else a = 4 Exponential Blowup Computation tree for a single thread Conditional statement Computation tree for two threads Scheduler choice: thread switch
Solution • All paths in the tree are not important for statement reachability • Many paths are equivalent to each other • Prune equivalent paths => Partial Order Reduction • Generate inputs along with Partial Order Reduction
Initially x = 0 and y = 0 x=3 y=2 x=3 y=2 t1: x = 3 t2: y = 2 Equivalent Paths x=0, y=0 x=0, y=0 One partial order Same partial order Different linear order => Different Path => Equivalent Path
R B R B Independent transitions • B and R are independent transitions if • they commute: B ∘ R = R ∘ B • neither enables nor disables the other s • Example: x = 3 and y = 2 are independent
Existing Approaches • Static Partial Order Reduction • Valmari 91, Peled 93, Godefroid 96, SPIN model checkerby Holzmann, Verisoft • Limitation • Results in a large dependent relation • Pointers -> Whether two pointers point to the same location is determined conservatively (May point-to) • Results in over-approximation of the dependency relation • Limited POR
may-alias (according to static analysis) Example: static partial-order reduction • Static analysis gives • i1, i2 are thread-local • x is protected by m • but a[i1] and a[i2] may alias • Static POR gives O(n2) explored states and transitions • but only two possible terminating states Global Vars lock m int i1,i2 int x=0 int n=100 char[] a Thread 1 lock(m) i1 := x++ unlock(m) for( ;i1<n; i1+=2) a[i1] := ‘b’ Thread 2 lock(m) i2 := x++ unlock(m) for( ;i2<n; i2+=2) a[i2] := ‘r’ never alias (in practice)
Dynamic partial-order reduction • Static POR relies on static analysis • to yield approximate information about run-time behavior • pointers => coarse information => limited POR => path explosion • Dynamic POR • while model checker executes the program, it sees exactly which threads access which locations • use to simultaneously reduce the path space while model-checking
Focus on Race-Detection and Flipping Algorithm and Concolic Testing: jCUTE • Race-Detection and Flipping Algorithm is a simplified form of DPOR • Proof of correctness in the presence of inputs and conditionals
Event • (t,l,a) • If thread t executes the statement labeled l and the access type is a • a 2 {w,r,l,u,?} • An execution path is a sequence of events
5: x=3 e5 11: y=5 e12 8: lock(m) e9 12: halt e13 1: x=1 e1 9: x=4 e10 3: y=2 e3 2: fork(8) e2 7: halt e7 4: lock(m) e4 6: unlock(m) e6 t0 10: unlock(m) e11 t1 e8 Sequential Relation • e = (t,l,a) and e’ = (t’,l’,a’) • e C e’ • e = e', or • t=t’ and e appears before e' in , or • t t’, t created the thread t’, and e appears before e'' in , where e'' is the fork event on t creating the thread t’, or • there exists an event e'' in such that e C e'' and e'' C e'.
5: x=3 e5 11: y=5 e12 8: lock(m) e9 12: halt e13 1: x=1 e1 9: x=4 e10 3: y=2 e3 2: fork(8) e2 7: halt e7 4: lock(m) e4 6: unlock(m) e6 t0 10: unlock(m) e11 t1 e8 Causal Relation (Happens-Before Relation) • e = (t,l,a) and e’ = (t’,l’,a’) • e ¹ e’ • e C e’, or • e appears before e' in and both access a shared memory location m and one of the accesses is update (write, lock acquire, release), or • there exists an event e'' in such that e ¹ e'' and e'' ¹ e'. • ¹is a partial order relation
Equivalent Paths • Definition: Two execution paths are equivalent if they are linearizations of the same partial order • Proposition: Exploration of one linear order of each partial order is sufficient for statement reachability
Not so strict definition (see paper for the strict definition) e = (t,l,a) and e’ = (t’,l’,a’) e l e’ e ¹ e’ Not (e C e’ or e’ C e) There exists no e1 such that e ¹ e1 and e1¹ e’ Where e1 is not equal to e or e’ x := 1 y := 2 y := 3 x := 4 Partial Order Race Relation • Events in race relation can be permuted by changing schedule • What happens if we have locks? (see paper)
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 DPOR (Race-detection and flipping) Example
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 DPOR (Race-detection and flipping) Example Execution 1
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 x := 1 y := 2 y := 2 y := 3 y := 3 x := 4 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 1 { } { } { } { }
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 1 { } x := 1 { t1} y := 2 { } Race y := 3 { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 1 { } x := 1 Backtrack Here { t1} y := 2 { } Race y := 3 { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 1 { } x := 1 Backtrack Here { t1} y := 2 Race y := 3 x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 2 { } x := 1 { t1} y := 3 { } x := 4 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 2 { t1} x := 1 { t1 ,t2} Race y := 3 { } Race x := 4 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 2 { t1} x := 1 Cannot Backtrack Here { t1 ,t2} Race y := 3 { } Race x := 4 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 2 Backtrack Here { t1} x := 1 { t1 ,t2} Race y := 3 { } Race x := 4 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 2 Backtrack Here { t1} x := 1 Race y := 3 Race x := 4 y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 3 { t1} y := 3 { } x := 4 { } x := 1 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 3 { t1} y := 3 { t2} x := 4 { } Race x := 1 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 3 { t1} y := 3 Backtrack Here { t2} x := 4 { } Race x := 1 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 3 { t1} y := 3 Backtrack Here { t2} x := 4 Race x := 1 y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 4 { t1} y := 3 { t2} x := 1 { } y := 2 { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Execution 4 Cannot Backtrack Here { t1,t2} y := 3 Cannot Backtrack Here { t1,t2} Race x := 1 { } y := 2 Race { } x := 4 Done!
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (POPL 05) Example Postponed Persistent Execution 1 { } { } x := 1 { t1} { t2} y := 2 { } { } Race y := 3 { } { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (POPL 05) Example Postponed Persistent Execution 2 { t1} { t2} x := 1 { t1 ,t2} { t1 ,t2} y := 3 { } { } x := 4 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (POPL 05) Example Postponed Persistent Execution 3 { t1} { t2} y := 3 { t2} { t1} x := 4 { } { } x := 1 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (POPL 05) Example Postponed Persistent Execution 4 { t1,t2} { t1,t2} y := 3 { t1,t2} { t1,t2} x := 1 { } { } y := 2 { } { } x := 4
Thread t1: 1: x := 1 2: x := 2 Thread t2: 1: y := 1 2: x := 3 DPOR Problem • DPOR (both approaches) explores all 6 execution paths => No reduction • Example in the POPL 05 paper has error • Think about it • Need Sleep Set to obtain reduction
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 DPOR (Race-detection and flipping) Example
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 DPOR (Race-detection and flipping) Example Execution 1
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 x := 1 y := 2 y := 2 y := 3 y := 3 x := 4 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 1 { } { } { } { } { } { } { } { }
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 1 { } { } x := 1 { t1} { } y := 2 { } { } Race y := 3 { } { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 1 { } { } x := 1 Backtrack Here { t1} { } y := 2 { } { } Race y := 3 { } { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 1 { } { } x := 1 Backtrack Here { t1} { } y := 2 { } Race y := 3 { } x := 4
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 2 { } { } x := 1 { t1} { t1 } y := 3 { } { t1 } x := 4 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 2 { t1} { } x := 1 { t1} { t1 } Race y := 3 { } { t1 } X Race x := 4 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 2 { t1} { } x := 1 Nothing to Backtrack Here { t1} { t1 } Race y := 3 { } { t1 } X Race x := 4 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 2 Backtrack Here { t1} { } x := 1 { t1} { t1 } Race y := 3 { } { t1 } X Race x := 4 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 2 Backtrack Here { t1} { } x := 1 { t1 } Race y := 3 { t1 } X Race x := 4 { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 3 { t1} { t1 } y := 3 { } { t1 } x := 4 { } { } x := 1 { } { } y := 2
Thread t1: 1: x := 1 2: y := 2 Thread t2: 1: y := 3 2: x := 4 x := 1 y := 2 y := 3 x := 4 Partial Order DPOR (Race-detection and flipping) Example Postponed Delayed Execution 3 { t1} { t1 } y := 3 { } { t1 } x := 4 { } { } Race X x := 1 { } { } y := 2