a chr based solver for weak memory behaviors
play

A CHR-Based Solver for Weak Memory Behaviors CSTVA 2016 Allan - PowerPoint PPT Presentation

A CHR-Based Solver for Weak Memory Behaviors CSTVA 2016 Allan Blanchard 1 , 2 Nikolai Kosmatov 1 eric Loulergue 2 Fr ed 1 CEA LIST - Software Reliability Laboratory 2 Univ Orl eans, INSA Centre Val de Loire, LIFO Sequential Consistency


  1. A CHR-Based Solver for Weak Memory Behaviors CSTVA 2016 — Allan Blanchard 1 , 2 Nikolai Kosmatov 1 eric Loulergue 2 Fr´ ed´ 1 CEA LIST - Software Reliability Laboratory 2 Univ Orl´ eans, INSA Centre Val de Loire, LIFO

  2. Sequential Consistency VS Weak Memory Models Memory model Reasoning about concurrency Memory models define : how threads interact with memory in particular on shared data They can be defined by : processor architectures languages July 17 th , 2016 — A.Blanchard — p. 2/19

  3. Sequential Consistency VS Weak Memory Models Sequential Consistency Lamport 1979 The semantics of the parallel composition of two programs is given by the interleavings of the executions of both programs. A simple program x :=Ω; y :=Ω Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; Possible results : r 0 = 1 ∧ r 1 = 1 Impossible result : r 0 = Ω ∧ r 1 = 1 r 0 = Ω ∧ r 1 = Ω r 0 = 1 ∧ r 1 = Ω July 17 th , 2016 — A.Blanchard — p. 3/19

  4. Sequential Consistency VS Weak Memory Models Weak behaviors Modern architectures For example, x86-TSO or ARM do not respect SC : hard to ensure such synchronization in hardware, and far too costly. Examples of weak behaviors out-of-order execution, store buffering, speculative execution, ... July 17 th , 2016 — A.Blanchard — p. 4/19

  5. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; r 0 = r 1 = Proc 0 : Store Buffer Proc 1 : Store Buffer ... ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  6. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; − → r 0 := y ; r 1 := x ; r 0 = r 1 = Proc 0 : Store Buffer Proc 1 : Store Buffer ... x = 1 ... ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  7. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; − → r 0 := y ; r 1 := x ; r 0 = r 1 = Proc 0 : Store Buffer Proc 1 : Store Buffer ... x = 1 ... ... y = 1 ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  8. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; − → r 0 := y ; r 1 := x ; r 0 = Ω r 1 = Proc 0 : Store Buffer Proc 1 : Store Buffer ... x = 1 ... ... y = 1 ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  9. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; − → r 1 := x ; r 0 = Ω r 1 = Ω Proc 0 : Store Buffer Proc 1 : Store Buffer ... x = 1 ... ... y = 1 ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  10. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; r 0 = Ω r 1 = Ω Proc 0 : Store Buffer Proc 1 : Store Buffer ... x = 1 ... ... y = 1 ... Global Memory ... x = Ω y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  11. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; r 0 = Ω r 1 = Ω Proc 0 : Store Buffer Proc 1 : Store Buffer ... ... y = 1 ... ⇓ Global Memory ... x = 1 y = Ω ... July 17 th , 2016 — A.Blanchard — p. 5/19

  12. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; r 0 = Ω r 1 = Ω Proc 0 : Store Buffer Proc 1 : Store Buffer ... ... ⇓ Global Memory ... x = 1 y = 1 ... July 17 th , 2016 — A.Blanchard — p. 5/19

  13. Sequential Consistency VS Weak Memory Models Example with store buffering Thread 0 Thread 1 x := 1 ; y := 1 ; r 0 := y ; r 1 := x ; r 0 = Ω r 1 = Ω Proc 0 : Store Buffer Proc 1 : Store Buffer ... ... Global Memory ... x = 1 y = 1 ... This behavior is allowed on ARM and TSO processors July 17 th , 2016 — A.Blanchard — p. 5/19

  14. Sequential Consistency VS Weak Memory Models We need to understand weak behaviors Reasoning about programs We have more and more multi-core software but it is hard to reason about them most analysis techniques are not aware of weak behaviors July 17 th , 2016 — A.Blanchard — p. 6/19

  15. Sequential Consistency VS Weak Memory Models Existing dedicated tools CPPMem (Batty et al. 2010) Program executions under C++11 model Herding cats (Alglave et al. 2014) Generic framework for weak behaviors written in OCaml provides a language to specify memory models JMMSolve (Schrijvers 2004) based on CCMM (Saraswat 2004) Program executions under Java Memory Model based on Concurrent Constraint-based Memory Machines written using Constraint Handling Rules (CHR) July 17 th , 2016 — A.Blanchard — p. 7/19

  16. A solver for weak memory behaviors Prolog and CHR Prolog Declarative language for logic programming Constraint Handling Rules Declarative language for constraint programming maintains a store of constraints ( ∼ terms) handled by rules that will add or remove constraints July 17 th , 2016 — A.Blanchard — p. 8/19

  17. A solver for weak memory behaviors Goals of our solver To identify allowed executions for a given parallel program according to a given memory model Additional goals possibility to add new memory models support of specific instructions July 17 th , 2016 — A.Blanchard — p. 9/19

  18. A solver for weak memory behaviors Basic relations ( st , x , Ω) ( st , y , Ω) Program-Order : PO Coherency-Order : CO ( st , x , 1 ) ( st , y , 1 ) Reads-From : RF ( ld , y , R 0 = 1 ) ( ld , x , R 1 = 1 ) July 17 th , 2016 — A.Blanchard — p. 10/19

  19. A solver for weak memory behaviors Basic relations ( st , x , Ω) ( st , y , Ω) Program-Order : PO Coherency-Order : CO ( st , x , 1 ) ( st , y , 1 ) Reads-From : RF po po ( ld , y , R 0 = 1 ) ( ld , x , R 1 = 1 ) July 17 th , 2016 — A.Blanchard — p. 10/19

  20. A solver for weak memory behaviors Basic relations ( st , x , Ω) ( st , y , Ω) co co Program-Order : PO Coherency-Order : CO ( st , x , 1 ) ( st , y , 1 ) Reads-From : RF po po ( ld , y , R 0 = 1 ) ( ld , x , R 1 = 1 ) July 17 th , 2016 — A.Blanchard — p. 10/19

  21. A solver for weak memory behaviors Basic relations ( st , x , Ω) ( st , y , Ω) co co Program-Order : PO Coherency-Order : CO ( st , x , 1 ) ( st , y , 1 ) Reads-From : RF rf rf po po ( ld , y , R 0 = 1 ) ( ld , x , R 1 = 1 ) July 17 th , 2016 — A.Blanchard — p. 10/19

  22. A solver for weak memory behaviors Chosen approach Generate all candidate executions An execution is represented by ordering relations : CO: for each location l , a total ordering of every store to l RF: for each load, a store having written the value being read we combine all permutations of CO and RF using backtracking Filter out forbidden executions apply model rules to deduce more ordering relations incoherent execution: an action must happen before itself (which means that some relations exhibits a cycle) July 17 th , 2016 — A.Blanchard — p. 11/19

  23. A solver for weak memory behaviors Express and derive relations with CHR Relation between 2 instructions CHR constraint ( st , x , Ω) CO − − → ( st , x , 1 ) co (( st , x , undefined ) , ( st , x , 1 )) ( st , x , 2 ) RF − − → ( ld , x , R ) rf (( st , x , 2 ) , ( ld , x , 2 )) ST CHR rules to derive new relations : rf co LD rf ( ST , LD ) , co ( ST , ST2 ) ⇒ fr fr ( LD , ST2 ) . ST 2 fr ( LD , ST2 ) , co ( ST2 , ST3 ) ⇒ co fr fr ( LD , ST3 ) . ST 3 July 17 th , 2016 — A.Blanchard — p. 12/19

  24. A solver for weak memory behaviors Express and derive relations with CHR Relation between 2 instructions CHR constraint ( st , x , Ω) CO − − → ( st , x , 1 ) co (( st , x , undefined ) , ( st , x , 1 )) ( st , x , 2 ) RF − − → ( ld , x , R ) rf (( st , x , 2 ) , ( ld , x , 2 )) ST CHR rules to derive new relations : rf co LD rf ( ST , LD ) , co ( ST , ST2 ) ⇒ fr fr ( LD , ST2 ) . ST 2 fr ( LD , ST2 ) , co ( ST2 , ST3 ) ⇒ co fr fr ( LD , ST3 ) . ST 3 July 17 th , 2016 — A.Blanchard — p. 12/19

  25. A solver for weak memory behaviors Express and derive relations with CHR Relation between 2 instructions CHR constraint ( st , x , Ω) CO − − → ( st , x , 1 ) co (( st , x , undefined ) , ( st , x , 1 )) ( st , x , 2 ) RF − − → ( ld , x , R ) rf (( st , x , 2 ) , ( ld , x , 2 )) ST CHR rules to derive new relations : rf co LD rf ( ST , LD ) , co ( ST , ST2 ) ⇒ fr fr ( LD , ST2 ) . ST 2 fr ( LD , ST2 ) , co ( ST2 , ST3 ) ⇒ co fr fr ( LD , ST3 ) . ST 3 July 17 th , 2016 — A.Blanchard — p. 12/19

  26. A solver for weak memory behaviors Detection of incoherent execution Reminder : incoherent execution = cycle in the perserved relations :- chr_constraint r/2, tc/2, cycle /1. 1 tc(B,E) \ tc(B,E) <=> R R true. R 5 3 tc(B,E), r(E,B) <=> cycle(B). 6 R R R R 4 2 tc(B,E), r(E,N) ==> inf(B,N) | tc(B,N). R 7 r(I,J) ==> inf(I,J) | tc(I,J). July 17 th , 2016 — A.Blanchard — p. 13/19

Recommend


More recommend