Tractable Refinement Checking for Concurrent Objects
Constantin Enea
LIAFA, CNRS & University Paris Diderot - Paris 7 joint work with Ahmed Bouajjani, Michael Emmi, Jad Hamza
Tractable Refinement Checking for Concurrent Objects Constantin - - PowerPoint PPT Presentation
Tractable Refinement Checking for Concurrent Objects Constantin Enea LIAFA, CNRS & University Paris Diderot - Paris 7 joint work with Ahmed Bouajjani, Michael Emmi, Jad Hamza Concurrent objects Concurrent Object call (push, pop, )
LIAFA, CNRS & University Paris Diderot - Paris 7 joint work with Ahmed Bouajjani, Michael Emmi, Jad Hamza
Concurrent Object
Thread 1 Thread 2
call (push, pop, …) return value
| | | |
Ensure an atomic view of the method calls
Thread 1 Thread 2
push(1) push(2)
Thread 1 Thread 2
push(1) push(2)
locking, CAS, …)
pop ⇒ 2 pop ⇒ 1 pop ⇒ 2 pop ⇒ 1
Efficient implementation
class TreiberStack { cell* top; void push (int v) { cell* t; cell* x = malloc(sizeof *x); x->data = v; do { t = top; x->next = top; } while (!CAS(&top,t,x)); } int pop () { ... } }
Reference implementation
class AtomicStack { cell* top; Lock l; void push (int v) { l.lock(); top->next = malloc(sizeof *x); top = top->next; top->data = v; l.unlock(); } int pop () { ... } }
minimize contention checking interference
For every Client, Client x Impl included in Client x Spec
preemption
pushed: 1, 2, 3 popped: 1, 3, EMPTY
c a l l p u s h ( 1 ) c a l l p
( ) r e t u r n r e t u r n 3 pop => 1 push(2) push(3) pop => EMPTY
Thread2 Thread1
preemption
PROBLEM not admitted by atomic stack
HARD TO REPRODUCE
HARD TO DIAGNOSE program assertions don’t suffice DEMANDS AUTOMATION
For every Client, Client x Impl included in Client x Spec
CHALLENGES
push(1) push(0) push(0) push(1)
Execution admitted by the specification
by the specification
Spec is atomic) [Filipovic et al. 2009, Bouajjani et al. 2015]
pop ⇒ 0 pop ⇒ 0
Exponentially-many linearizations AtomicStack ?
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3 push(1) pop⇒3 pop⇒1 push(2) pop⇒EMPTY push(3)
∉
push(1) pop⇒1 pop⇒3 push(2) pop⇒EMPTY push(3)
∉
push(1) pop⇒1 push(2) pop⇒3 pop⇒EMPTY push(3)
∉ ∉
push(1) pop⇒1 push(2) pop⇒3 pop⇒EMPTY push(3)
Single trace NL-complete NP-completea Reachability Linearizability n threads PSPACE-complete EXPSPACE-completeb ∞ threads EXPSPACE-complete Undecidablec
a Testing Shared Memory. Gibbons et al. 1996 b Linearizability is EXPSPACE-complete Hamza 2015 c Verifying Concurrent Programs Against Sequential Specifications Bouajjani et al. 2013
[Bouajjani, Emmi, E, Hamza, POPL’15]
[Bouajjani, Emmi, E, Hamza, POPL’15]
pop ⇒ 1 push(2) push(3) pop ⇒ EMPTY push(1) pop ⇒ 3
happens-before partial order
push(1) pop ⇒ 1 push(2) push(3) pop ⇒ EMPTY pop ⇒ 3
THEOREM L refines S ⇔ Hist(L) ⊆ Hist(S) Hist(L) = the histories of all executions of L (arbitrary calls with arbitrary many threads)
the happen-before constraints of h.
history.
[Bouajjani, Emmi, E, Hamza, POPL’15]
GOAL parameterized approximation Ak
HYPOTHESIS violations surface in histories with low-complexity orderings
INTERVAL LENGTH smallest maximum integral interval bound execution histories are interval orders
1 2 3
4
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3 push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
LEMMA Libraries closed under weakening
weaker order
LENGTH 4
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
LENGTH 1
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
all concurrent STILL A VIOLATION
and merge the remaining ones)
1 2 3
4
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
1
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
Counter-based representations of histories
1
push(1) pop⇒1 push(2) push(3) pop⇒EMPTY pop⇒3
#(push(1), 0,0) = 1 #(pop⇒1,0,0) = 1 #(push(2),0,0) = 1 … Checking Ak(Hist (L)) ⊆ Histk(S)
client of L with counter increments/decrements
[Bouajjani, Emmi, E, Hamza, POPL’15]
small bounds suffice as sample-size increases exponentially-lower monitoring overhead
1 10 100 1000 10000 100000 Histoires Violations Covered w/ k=4 Covered w/ k=3 Covered w/ k=2 Covered w/ k=1
execution sample vs. violations covered 1x103 executions — 2.4x106 executions missed violations due to small sample
1 10 100 1000 Linearization Operation Counting
execution size vs. monitoring overhead 2 operations — 20 operations
~1000x ~2x
Approximation k=2
Library P k Unrolling Rounds Time Michael-Scott Queue (Head) 2, 2 1 2 2 24.76s Michael-Scott Queue (Tail) 3, 1 1 2 3 45.44s Treiber Stack (ABA) 3, 4 1 1 2 52.59s Treiber Stack (push) 2, 2 1 1 2 24.46s Treiber Stack (pop) 2, 2 1 1 2 15.16s Elimination Stack 4, 1 1 4 317.79s Elimination Stack 3, 1 1 1 4 222.04s Elimination Stack 3, 4 1 2 434.84s Lock-coupling Set 1, 2 2 2 11.27s LFDS Queue 2, 2 1 1 2 77.00s
Future work:
reference impls?
atomicity?
Hist(S)
(bounded interval length)