VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs –...

35
VMCAI / POPL 2009 Spy Report

Transcript of VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs –...

Page 1: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

VMCAI / POPL 2009Spy Report

Page 2: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Topics of Interest (I)

• Semantics of concurrent programs– Programming languages & abstractions– Transactional memory (TM)– Alternative models• Message passing• Functional programming

Page 3: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Topics of Interest (II)

• Verifying concurrent programs– Proving concurrency-related properties• “Shared memory safety”• No race conditions• Various notions of progress (no deadlock, …)• Linearizability

– Abstractions for shared-memory programs• Separation logic• Shape-modular analysis

Page 4: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Topics of Interest (III)

• Other craziness– Type theory– Abstract interpretation– Functional programming– …

Page 5: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Semantics of Concurrent Programs

• [Invited Talk: Language Constructs for Transactional Memory, by Tim Harris (MSR)]

• Convention: “Coarse-grained synchronization is inefficient, fine-grained synchronization is hard”

• The ideal solution:atomic {

// touch shared memory, etc.}

Page 6: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Atomic Blocks

• Design questions:– What can you do inside an atomic block?• Touch all variables / only pre-declared “shared”

variables?• Commands with side effects?

E.g., atomic { if(..) launch_missile(); }

– Strong atomicity / weak atomicity?atomic { if(x == 0) x = 1; } ‖ x = 2;

– What happens in case of a rollback?

Page 7: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Atomic Blocks

• Solution (advocated by Harris):– Decouple TM from language constructs– At the high level: “strong semantics”

TMLow-level semantics &implementation(optimistic concurrency,lock-based, …)

high-level semantics

atomic blocks,retry, abort, …

programming discipline

Page 8: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Tradeoff

TM

programming discipline

staticseparation

dynamicseparation

violationfreedom

allprograms

“betterconcurrency”

“worseconcurrency”

Page 9: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Progress Semantics for TM

• [The Semantics of Progress in Lock-Based Transactional Memory. Rachid Guerraoui, Michal Kapalka (EPFL)]

• What kind of progress guarantees should a TM provide?

Page 10: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

TM Model

• Over a set {x1,…,xt} of “transactional variables”

• A transaction:a sequence of operationsread(xi), write(xi,v), abort, commit

which return either a value, “ok”, or “abort”

History

Ti Tj

abort/commit

abort/commit

overlap conflict on xi:overlap + read/write orwrite/write to xi

Page 11: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Strong Progressiveness

• If Ti aborts then either– Ti called abort, or

– Some other transaction conflicts with Ti.

plus,• If a set of transactions conflict only on one

variable, at least one must succeed.

Page 12: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Proving Strong Progressiveness

• Must reason about all histories– Unbounded length– Unbounded number of transactional variables

• Restrict attention to “lock-based TMs”(TL2, TinySTM, RSTM, McRT-STM,…)

• Use “virtual locks” to reason about conflicts– Writing to x = “grabbing a lock on x”– Abort must be justified in terms of locks– Don’t care about safety, only liveness!

If writing to x, must hold lock on xIf hold lock on x, must write to x

Page 13: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Connection to Try-locks

• Try-lock object:– try-lock → “yes” / “no” (non-blocking)– unlock → “yes”

• Safety: mutual exclusion• Strong try-lock:

If several processes compete for the lock, one succeeds.

Page 14: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Verifying Strong Progressiveness

• A strong try-lock extension of a history E:– For every variable x introduce a try-lock Lx

– Add try-lock, unlock operations on Lx such that1. Lx behaves like a try-lock,2. If pi executes try-lock(Lx) or holds Lx at time t in E’,

then at time t in E, pi executes a transaction that writes to x; and

3. If Tk is aborted, then either– There is some Lx such that every try-lock(Lx) in Tk fails, or– Tk invokes read(x) such some other process holds Lx while

Tk executes and before Tk acquires Lx (if ever)try-lock(Lx)write(x, v)

Page 15: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Verifying Strong Progressiveness

• Reduction Theorem:For any TM implementation M, if every history of M has a strong try-lock extension, then M is strongly progressive.

Page 16: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Characterizing Strong Progressiveness

• How easy is strong progressiveness to implement?

• Theorem: a strongly progressive TM has consensus number 2.

• Implications:– Cannot be implemented using read/write registers– Can be implemented using test&set / queue

(does not require, e.g., CAS)

Page 17: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Strongly-Progressive TM has CN 2

• Phase 1:strongly-progressive TM ≡ strong try-locks

• Phase 2:consensus number of strong try-locks ≥ 2– 2-process consensus can be solved using try-locks

• Phase 3:consensus number of strong try-locks ≤ 2– try-locks can be implemented from test&set

Page 18: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Solving consensus using try-locks

(L : a strong try-lock ; V0,V1 : registers)

process pi executes:

write(Vi, v)

locked ← try-lock(L)if(locked)

decide velse

decide read(V1-i)

Never unlocked…Because L is a strong try-lock,one process grabs it evenif both try at the same time.

Page 19: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Weak Progressiveness

• What can be done using read/write registers?• Strong progressiveness:– If Ti aborts, then Ti conflicts with some other

transaction; and– If a set of transactions conflict on only one

variable, at least one must succeed.

• Weakly-progressive TM can be implemented from registers.

Weak

Page 20: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Proving Liveness in Concurrent Programs

• [Proving that Non-Blocking Algorithms Don’t Block, by Gotsman, Cook, Parkinson and Vafeiadis.]

• Typical approach for verifying concurrent programs:

process/threadreceive messages,

read valuessend messages,write values

Assume/Guarantee

assumption guarantee

Page 21: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Circular A/G

• Set P of symmetric processes:

• “assuming P / { pi } satisfy A, pi guarantees A”⇒ A holds (under no assumptions).• Sound for safety properties• But not for liveness properties.

p0 p1assume

guarantee

assume

guarantee

Page 22: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Layered Proofs

p0 p1 safety property p1

p0 p1liveness property p2

p0 p1

⋮ ⋮termination

Page 23: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Intermediate Properties

• Often sufficient:(safety) Λ “operations x,y,z are not called

infinitely often” ⇒ automated search procedure

• Can prove:– Wait-freedom– Lock-freedom– Obstruction-freedom

Page 24: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Proving Linearizability

• [Shape-Value Abstraction for Verifying Linearizability, by Victor Vafeiadis.]

• Linearizability:

– Every operation has a linearization point between invocation and response

– The resulting sequential history is legal.

Page 25: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Proving Linearizability

• Find linearization points in the code– Not necessarily a single point per operation– Not necessarily in the code for the operation…

• If more than one, choice must be deterministic

• Prove that they are linearization points

if x == null

if x != null

(disclaimer:may requireprophecyvariables)

Page 26: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Proving Linearizability

• Prove that they are linearization points:

(1) embed abstract spec(2) prove every LP is reached

at most once(3) prove every LP is reached

in every terminating exec.

Given by user orinferred automatically

if x == null

if x != null

pop:

return success;

return failure;

Concurrent implementation Abstract (sequential) spec

(4) prove that the result is whatthe spec requires

Page 27: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Inferring LPs

• Heuristics:– Restrict to points in the code of the operation– Restrict to accesses of shared memory– Restrict to writes to shared memory

• Unsuitable for…– Effect-free methods (e.g., find)– Algorithms with helping

Page 28: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Deadlock Avoidance

• [The Theory of Deadlock Avoidance via Discrete Control, by Lafortune, Kelly, Kudlur and Mahlke]

• Deadlock-freedom can be hard to prove• … so why not prevent deadlock?

program controllogic

i can has lock?

yes/wait

instrumented executable

Page 29: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Software Verification

• Hardware is verified by model-checking• In software we have to deal with…– Infinite state space (e.g., integer variables)– The heap, pointers, aliasing– Recursion– Unbounded concurrency, shared memory

Page 30: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Software Verification

• Ruling approaches:– Use static analysis to restrict possible values of

variables– Reduce to some “easy” representation and do model-

checking• Abstract into a finite model• Use PDA to model recursion and function calls

– Hoare-style proofs{precondition} … {postcondition}• Translate to first-order logic formula and send to theorem

prover / SMT solver

E.g.,{x > 0} y := x { y > 0 }⇩

(x = 0) Λ (y = x) Λ (y <= 0)SAT?

Page 31: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Spec#

Spec#

Page 32: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Software Verification

• Today’s state of the art can in many cases:– Verify Hoare triplets {p} S {q}– Verify termination• By automatic inference of ranking functions

– Infer invariants (abstract interpretation+widening)– Infer weakest pre/postconditions

Page 33: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

SPEED

• [SPEED: Precise and Efficient Static Estimation of Program Computational Complexity, by Gulwani, Mehra, and Chilimbi]

• Example:function f(n){ x := 0; y := 0;

while(x++ <= n) { while(y++ <= m) {

// foo}}}

c1 := 0 ; c2 := 0;

c1 ++ ; c2 := 0;

c2 ++ ;

Invariant: c1 ≤ nInvariant: c2 ≤ mBound ≤ n∙m

Page 34: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Synthesizing Switching Logic

• [Synthesizing Switching Logic Using Constraint Solving, by Tali, Gulwani and Tiwari]

• Example: AC control unit

ON OFF

Goal: maintain temp [t∈ low, thigh]

condition1

condition2

temperature temperature

Page 35: VMCAI / POPL 2009 Spy Report. Topics of Interest (I) Semantics of concurrent programs – Programming languages & abstractions – Transactional memory (TM)

Synthesizing Switching Logic

Invariant

ControlledInductiveInvariant

?

? ?

Template:a11x2+ a12x2 + … ≤ b1

…Add constraints forcontrollability (∀∃)⇩Use SMT solver tofind a11, a12,…