cosmo a concurrent separation logic for multicore ocaml
play

Cosmo: a concurrent separation logic for Multicore OCaml Glen Mvel , - PowerPoint PPT Presentation

Cosmo: a concurrent separation logic for Multicore OCaml Glen Mvel , Jacques-Henri Jourdan, Franois Pottier August, 2020 ICFP, New York LRI & Inria, Paris, France This talk Our aim: Verifying fine-grained concurrent


  1. Cosmo: a concurrent separation logic for Multicore OCaml Glen Mével , Jacques-Henri Jourdan, François Pottier August, 2020 ICFP, “New York” LRI & Inria, Paris, France

  2. This talk Our aim: • Verifying • fine-grained concurrent programs • in the setting of Multicore OCaml’s memory model. Our contribution: A concurrent separation logic with views. 1 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  3. Multicore OCaml Multicore OCaml : OCaml language with multicore programming. Weak memory model for Multicore OCaml: • Formalized in PLDI 2018. • Two flavours of locations: “atomic”, “non-atomic”. (Also at ICFP 2020: Retrofitting Parallelism onto OCaml ) 2 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  4. In traditional fine-grained concurrent separation logics... We can assert ownership of a location and specify its value: { x �→ 42 } x := 44 { x �→ 44 } Ownership can be shared between all threads via an invariant: ∃ n ∈ N , x �→ n ∗ n is even ⊢ { True } x := 44 { True } 3 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  5. The challenge: subjectivity With weak memory, each thread has its own view of memory. Some assertions are subjective : • Their validity relies on the thread’s view. Invariants are objective : • They cannot share subjective assertions. How to keep a simple and powerful enough logic? 4 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  6. Key idea: modeling subjectivity with views A thread knows a subset U of all writes to the memory. • Affects how the thread interacts with memory. • U is the thread’s view . New assertions: • ↑ U : we have seen U , i.e. we know all writes in U . • P @ U : having seen U is objectively enough for P to hold. 5 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  7. Key idea: decomposing subjective assertions Decompose subjective assertions: P ⇐ ⇒ ∃U . P @ U ∗ ↑ U � �� � ���� objective subjective Share parts via distinct mechanisms: • P @ U : via objective invariants , as usual. • ↑ U : via synchronization offered by the memory model. 6 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  8. Our program logic

  9. Rules of atomic locations, simplified x �→ at v : the atomic location x stores the value v . • Sequentially consistent . • Objective . • Standard rules: { x �→ at v } { x �→ at v } x := at v ′ ! at x { λ v ′ . v ′ = v ∗ x �→ at v } { λ () . x �→ at v ′ } 7 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  10. Rules of non-atomic locations x �→ v : we know the latest value v of the non-atomic location x . • Relaxed . • Subjective — cannot appear in an invariant. • Standard rules too! { x �→ v } { x �→ v } x := v ′ ! x { λ v ′ . v ′ = v ∗ x �→ v } { λ () . x �→ v ′ } 8 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  11. Example: transferring an assertion through a spin lock // release lock: lock := at false // acquire lock: while CAS lock false true = false do () done 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  12. Example: transferring an assertion through a spin lock { P } // release lock: lock := at false // acquire lock: while CAS lock false true = false do () done { P } 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  13. Example: transferring an assertion through a spin lock { P } // release lock: lock := at false // acquire lock: CAS lock false true // CAS succeeds { P } 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  14. Example: transferring an assertion through a spin lock { P } {∃U . P @ U ∗ ↑ U} // release lock: lock := at false // acquire lock: CAS lock false true // CAS succeeds {∃U . P @ U ∗ ↑ U} { P } 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  15. Example: transferring an assertion through a spin lock { P } {∃U . P @ U ∗ ↑ U} // release lock: lock := at false // acquire lock: CAS lock false true // CAS succeeds {∃U . P @ U ∗ ↑ U} { P } • P @ U : transferred via objective invariants , as usual. 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  16. Example: transferring an assertion through a spin lock { P } {∃U . P @ U ∗ ↑ U} // release lock: lock := at false // acquire lock: CAS lock false true // CAS succeeds {∃U . P @ U ∗ ↑ U} { P } • ↑ U : transferred via synchronization. 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  17. Example: transferring an assertion through a spin lock { P } {∃U . P @ U ∗ ↑ U} // release lock: lock := at false // acquire lock: happens before CAS lock false true // CAS succeeds {∃U . P @ U ∗ ↑ U} { P } • ↑ U : transferred via “atomic” accesses . 9 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  18. Rules of atomic locations, simplified x �→ at v : the atomic location x stores the value v . • Sequentially consistent behavior for v . • Objective. • Rules: { x �→ at v } { x �→ at v } x := at v ′ ! at x { λ v ′ . v ′ = v ∗ x �→ at v } { λ () . x �→ at v ′ } 10 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  19. Rules of atomic locations x �→ at ( v , U ) : the atomic location x stores the value v and a view (at least) U . • Sequentially consistent behavior for v . • Release/acquire behavior for U . • Objective (still). • Rules: { x �→ at ( v , U ) ∗ ↑ U ′ } { x �→ at ( v , U ) } x := at v ′ ! at x { λ v ′ . v ′ = v ∗ x �→ at ( v , U ) ∗ ↑ U } { λ () . x �→ at ( v ′ , U ′ ) } 10 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  20. Rules of atomic locations x �→ at ( v , U ) : the atomic location x stores the value v and a view (at least) U . • Sequentially consistent behavior for v . • Release/acquire behavior for U . • Objective (still). • Rules: { x �→ at ( v , U ) ∗ ↑ U ′ } { x �→ at ( v , U ) } x := at v ′ ! at x release { λ v ′ . v ′ = v ∗ x �→ at ( v , U ) ∗ ↑ U } { λ () . x �→ at ( v ′ , U ′ ) } 10 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  21. Rules of atomic locations x �→ at ( v , U ) : the atomic location x stores the value v and a view (at least) U . • Sequentially consistent behavior for v . • Release/acquire behavior for U . • Objective (still). • Rules: { x �→ at ( v , U ) ∗ ↑ U ′ } { x �→ at ( v , U ) } acquire x := at v ′ ! at x { λ v ′ . v ′ = v ∗ x �→ at ( v , U ) ∗ ↑ U } { λ () . x �→ at ( v ′ , U ′ ) } 10 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  22. Application: the spin lock

  23. The spin lock A spin lock implements a lock using an atomic boolean variable: let release lk = let rec acquire lk = lk :={at} false if CAS lk false true then () else acquire lk Interface: isLock lk P ⊢   { P } release lk { True } { True } acquire lk { P }  11 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  24. The spin lock A spin lock implements a lock using an atomic boolean variable: let release lk = let rec acquire lk = lk :={at} false if CAS lk false true then () else acquire lk Invariant in traditional CSL: lk �→ at true ∨ ( lk �→ at false ∗ P ) ⊢   { P } release lk { True } { True } acquire lk { P }  11 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  25. The spin lock A spin lock implements a lock using an atomic boolean variable: let release lk = let rec acquire lk = lk :={at} false if CAS lk false true then () else acquire lk Invariant in our logic (where P is subjective!): lk �→ at true ∨ ( ∃U . lk �→ at ( false , U ) ∗ P @ U ) ⊢   { P } release lk { True } { True } acquire lk { P }  11 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  26. Methodology More case studies: • Ticket lock • Dekker mutual exclusion algorithm • Peterson mutual exclusion algorithm Method for proving correctness under weak memory: 1. Start with the invariant under sequential consistency; 2. Identify how information flows between threads; • i.e. where are the synchronization points; 3. Refine the invariant with corresponding views. 12 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  27. Conclusion

  28. Conclusion Key idea: The logic of views enables concise and natural reasoning about how threads synchronize. In the paper: • Model of the logic. • A lower-level logic. • More case studies. Fully mechanized in Coq with the Iris framework. Future work: • Verify more shared data structures. • Allow data races on non-atomics? 13 Mével, Jourdan, Pottier: Cosmo: a concurrent separation logic for Multicore OCaml

  29. Questions?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend