compositional reasoning about concurrent libraries on the
play

Compositional reasoning about concurrent libraries on the axiomatic - PowerPoint PPT Presentation

Compositional reasoning about concurrent libraries on the axiomatic TSO memory model Artem Khyzha IMDEA Software Institute, Madrid, Spain Joint work with Alexey Gotsman (IMDEA Software) Weak memory x = y = 0; x = 1; y = 1; a = y; b = x;


  1. Compositional reasoning about concurrent libraries on the axiomatic TSO memory model Artem Khyzha IMDEA Software Institute, Madrid, Spain Joint work with Alexey Gotsman (IMDEA Software)

  2. Weak memory x = y = 0; x = 1; y = 1; a = y; b = x; { a = b = 0 }

  3. Weak memory x = y = 0; x = 1; y = 1; a = y; b = x; { a = b = 0 }

  4. Weak memory x = y = 0; x = 1; y = 1; a = y; b = x; { a = b = 0 }

  5. Weak memory x = y = 0; x = 1; y = 1; a = y; b = x; { a = b = 0 }

  6. Weak memory x = y = 0; x = 1; y = 1; a = y; b = x; { a = b = 0 } Possible on a weak memory model

  7. The TSO memory model (x86) ... RAM

  8. The TSO memory model (x86) *x = a; *y = b; Writes stored into the write buffer in the order of issue RAM

  9. The TSO memory model (x86) *x = a; *y = b; Writes stored into the write buffer in the order of issue x:a RAM

  10. The TSO memory model (x86) *x = a; *y = b; Writes stored into y:b the write buffer in the order of issue x:a RAM

  11. The TSO memory model (x86) *x = a; *y = b; Writes flushed in y:b FIFO order x:a

  12. The TSO memory model (x86) *x = a; *y = b; Writes flushed in FIFO order y:b RAM x:a

  13. The TSO memory model (x86) *x = a; *y = b; Writes flushed in FIFO order RAM x:a y:b

  14. Our goal ● Is compositional reasoning on weak memory possible? L (Implementation) L' (Specification) C C struct Node { Node *next; int val; } *T op; Sequence S; void push(int v) { abstracted by Node *t, *x; void push(int v) { x = new Node; atomic { S = v⋅S; } x->val = v; } do { t = T op; x->next = t; } while(!CAS(&T op,t,x)); }

  15. Our goal ● Is compositional reasoning on weak memory possible? Linearizability [Herlihy, Wing] L (Implementation) L' (Specification) C C struct Node { Node *next; int val; } *T op; Sequence S; void push(int v) { linearized by Node *t, *x; void push(int v) { x = new Node; atomic { S = v⋅S; } x->val = v; } do { t = T op; x->next = t; } while(!CAS(&T op,t,x)); }

  16. Challenge f() { Store *x = a; buffer *y = b; y:b } x:a ● Writes can be flushed after f returns ● Just parameters and return values not enough

  17. Axiomatic model An execution of C(L) is (A, po, rf, mo, ..., hb) x = y = a = b = 0 x = 1; y = 1; write y = 1 write x = 1 po po a = y; b = x; read x = 1 read y = 0 ● Actions A : reads, writes, calls, returns

  18. Axiomatic model An execution of C(L) is (A, po, rf, mo, ..., hb) x = y = a = b = 0 x = 1; y = 1; po po a = y; b = x; ● po – program order relates actions by the same thread

  19. Axiomatic model An execution of C(L) is (A, po, rf, mo, ..., hb) x = y = a = b = 0 (x = 1) is flushed before (y = 1) x = 1; y = 1; mo rf po po rf a = y; b = x; read x = 1 read y = 0 ● mo – modification order order in which writes hit the memory ● rf – “reads from” relation relates reads to correspondent writes

  20. Axiomatic model An execution of C(L) is (A, po, rf, mo, ..., hb) x = y = a = b = 0 x = 1; y = 1; mo rf po po rf a = y; b = x; ● hb – “happens before” relation indicates precedence in the whole execution

  21. Axioms

  22. Axioms ● Filter out impossible executions ● Capture the effect of store buffering Disallows “writing to the future”

  23. Abstraction Theorem Assume that L L'. Then C C L’ specifies L : L L’ ⇒ L L’

  24. Subgraph replacement C L L'

  25. Subgraph replacement C L L' History - several relations on boundary actions

  26. Subgraph replacement C L L'

  27. Computing histories ● Take a library L on TSO or SC ● Take the most general client: ● Get all possible library executions:

  28. Computing histories ● Take a library L on TSO or SC Any methods, ● Take the most general client: in any order, with any parameters Any number of threads ● Get all possible library executions:

  29. Guarantee relation ● Histories include the projection of happens- before to calls and returns: data = f = 0; data = 1; call wait call signal po while (!f) {} f = 1 rf ret wait ret signal po b = data;

  30. Guarantee relation ● Histories include the projection of happens- before to calls and returns: data = f = 0; data = 1; call wait call signal while (!f) {} f = 1 hb ret wait ret signal b = data;

  31. Guarantee relation ● Histories include the projection of happens- before to calls and returns: data = f = 0; data = 1; call wait call signal po while (!f) {} f = 1 rf ret wait ret signal po b = data; { b = 1 }

  32. Conclusions ● Through thorns to the stars – compositional reasoning is possible on TSO. ● Axiomatic semantics can be straightforwardly implemented in SAT solvers ● Can be applied to more complicated models (IBM Power, ARM)

  33. Related work ● Concurrent library correctness on the TSO memory model ● S. Burckhardt et al. (ESOP'12) ● Library abstraction for C/C++ concurrency ● M. Batty et al. (POPL'13)

  34. Linearizability ● History: (Interface, Guarantee, Deny) ● ● Specification can guarantee and deny less to the client ● So client has more behaviours when using specification instead of implementation ●

  35. Linearizability (t1, ret isEmpty (yes)) (t1, call push(42)) (t1, ret push) (t1, call isEmpty) t1: (t2, call push(11)) (t2, ret push) (t2, call pop) (t2, ret pop(42)) t2: (t1, call push(42)) (t2, call pop) (t1, call isEmpty) (t2, call push(11)) (t2, ret pop(42)) (t1, ret isEmpty(yes)) (t2, ret push) (t1, ret push) • We can permute calls and returns by different threads • But non-overlapping method invocations can’t be rearranged

  36. Linearizability • How it fails: x = y = 0; x = 1; y = 1; m(); m(); a = y; b = x; { a = b = 0 }

  37. Linearizability • How it fails: x = y = 0; x = 1; y = 1; m(); m(); a = y; b = x; { a = b = 0 } • Not possible, if m contains a fence.

Recommend


More recommend