The Benefits of Duality in Verifying Concurrent Programs under TSO
Parosh Aziz Abdulla1
Ahmed Bouajjani2
Mohamed Faouzi Atig1
Tuan Phong Ngo1
1Uppsala University 2IRIF, Université Paris Diderot & IUF
CONCUR 2016
1
The Benefits of Duality in Verifying Concurrent Programs under TSO - - PowerPoint PPT Presentation
The Benefits of Duality in Verifying Concurrent Programs under TSO Parosh Aziz Abdulla 1 Ahmed Bouajjani 2 Mohamed Faouzi Atig 1 Tuan Phong Ngo 1 1 Uppsala University 2 IRIF, Universit Paris Diderot & IUF CONCUR 2016 1 Motivation
Parosh Aziz Abdulla1
Ahmed Bouajjani2
Mohamed Faouzi Atig1
Tuan Phong Ngo1
1Uppsala University 2IRIF, Université Paris Diderot & IUF
CONCUR 2016
1
Sequential Consistency
shared memory
Characteristics
😁 Simple and intuitive model 😟 Disallows many hardware/compiler optimizations
Processes Execution
memory
P0 P1
write write read read P0 P1 P0 P0
2
Hardware Optimizations
😁 Better performance and energy 😟 Non-intuitive behaviors: bugs Weak memory model: captures the semantics of out-of-
Goal
safety properties
3
4
Widely Used
Intel x86
5
Optimize Memory Access
buffers x = 0 y = 0
P0 P1
classical semantics
Widely Used
Intel x86
process shared variables
6
Optimise Memory Access
buffers x = 0 y = 0
P0 P1
classical semantics
Widely Used
Intel x86
store buffer First In First Out (FIFO)
7
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
8
P0: write: x = 2
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
9
P0: write: x = 2 writes to the buffer x=1
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
10
P0: write: x = 2 writes to the buffer x=1 x=2
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
11
P0: write: x = 2 x=1 x=2
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
12
P0: write: x = 2 x=1 x=2 reads from the buffer
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
13
P0: write: x = 2 x=1 x=2
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
14
P0: write: x = 2 x=1 x=2 reads from the memory
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
15
P0: write: x = 2 x=1 x=2 updates to the memory
x = 0 y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
16
P0: write: x = 2 x=1 x=2 update the memory
y = 0
P0 P1
P0: read: x = 2 P0: write: x = 1 P0: read: y = 0
17
P0: write: x = 2 x=2 x = 1 updates to the memory
18
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section Sequential Consistency = Interleaving At most one process at its CS at any time P0 P1
19
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
20
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
21
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
22
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
23
x=1 writes to buffer
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
24
x=1
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
25
x=1 read: y = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
26
x=1 reads from memory read: y = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
27
x=1 enters CS read: y = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
28
x=1 read: y = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
29
x=1
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 read: x = 0 critical section TSO P0 P1
30
x=1 writes to buffer y=1
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
31
x=1 y=1 read: x = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
32
x=1 y=1 read: x = 0 reads from memory
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
33
x=1 y=1 read: x = 0 enters CS
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
34
x=1 y=1 read: x = 0 2 processes in CS at the same time
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
35
x=1 y=1 read: x = 0
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
36
x=1 y=1 read: x = 0
“read
write” “read
write”
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
37
x=1 y=1 read: x = 0 mfence mfence fence instruction flushes the buffer prevents re-ordeirng
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
38
x=1 y=1 read: x = 0 mfence mfence
x = 0 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
39
x=1 y=1 read: x = 0 mfence mfence
x = 1 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
40
y=1 read: x = 0 mfence mfence
x = 1 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
41
y=1 read: x = 0 mfence mfence execute fence
x = 1 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
42
y=1 read: x = 0 mfence mfence
x = 1 y = 0
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
43
y=1 read: x = 0 mfence mfence
x = 1 y = 1
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
44
read: x = 0 mfence mfence
x = 1 y = 1
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
45
read: x = 0 mfence mfence execute fence
x = 1 y = 1
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
46
read: x = 0 mfence mfence
x = 1 y = 1
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
47
read: x = 0 mfence mfence
x = 1 y = 1
P0 P1
Initially: x = y = 0 write: x = 1 read: y = 0 critical section write: y = 1 critical section TSO P0 P1
48
read: x = 0 mfence mfence At most one process executes its CS at any time
49
reachability analysis reachable? execution analysis preventable? program correct program incorrect specification no yes yes no insert fences
50
program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
51
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
52
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
53
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
54
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
55
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
56
no reordering = bug not due to memory model specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
57
specification program find reordering and prevent it
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
58
specification program try again
needed for correctness
P0
x = 0 y = 0
while (1) write: x=1 P0: write: x = 1 P0: write: x = 1 P0: write: x = 1 … …
59
P0
x = 0 y = 0
while (1) write: x=1 P0: write: x = 1 P0: write: x = 1 P0: write: x = 1 … … x=1
60
P0
x = 0 y = 0
while (1) write: x=1 P0: write: x = 1 P0: write: x = 1 P0: write: x = 1 … … x=1 x=1
61
P0
x = 0 y = 0
while (1) write: x=1 P0: write: x = 1 P0: write: x = 1 P0: write: x = 1 … … x=1 x=1
x=1 infinite state space unbounded buffer
62
Existing Methods
😟 miss bugs: under-fencing
😟 spurious bugs: over-fencing
😁 find real bugs iff they exist: optimal fencing
63
WQO for TSO
Well-Quasi Ordering (WQO) Framework
x=1
x=1 y=1 y=2 y=2
64
read: y = 2 possible read: y = 2 not possible
WQO for TSO
Well-Quasi Ordering (WQO) Framework
65
P0
x = 0 y = 0 x=1 y=1
P0
x = 0 y = 0 x=1
Monotonicity
WQO for TSO
Well-Quasi Ordering (WQO) Framework
66
P0
x = 0 y = 0 x=1 y=1
P0
x = 0 y = 0 x=1
WQO for TSO
Well-Quasi Ordering (WQO) Framework
67
P0
x = 0 y = 0 x=1 y=1
P0
x = 1 y = 0
WQO for TSO
Well-Quasi Ordering (WQO) Framework
68
P0
x = 0 y = 0 x=1 y=1
P0
x = 1 y = 0
Well-Quasi Ordering (WQO) Framework
WQO for TSO
69
Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P1
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P0
x=1 y=1
written variable writing process
70
memory snapshot view pointer P1: memory content P1: pending update
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
written variable writing process
71
memory snapshot view pointer P0: memory content P0: no pending update P0
Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
72
P0
Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
73
P0 x,P0
x=2 y=1 Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
74
P0 x,P0
x=2 y=1
y,P1
x=2 y=3 Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
75
P0 x,P0
x=2 y=1
y,P1
x=2 y=3
update view of P0
Semantics 2: Single Buffer Model [TACAS’12+13]
P0 P1
P1 y,P0
x=0 y=1
P0: write: x = 2 P1: write: y = 3 … x,P1
x=1 y=1
76
P0 x,P0
x=2 y=1
y,P1
x=1 y=3
Semantics 2: Single Buffer Model [TACAS’12+13]
memory snapshot viewing pointer ID of writing process costly
cannot be directly applied to parameterized verification
77
Semantics 2: Single Buffer Model [TACAS’12+13]
example: mutual exclusion protocols unbounded number of processes correctness: lock taken by at most
78
Exact Verification Technique
Semantics 3: Dual-TSO
79
x = 1 y = 0
P0 P1
x,1,other x,1,self
Store Buffers ☛ Load Buffers
update the memory
read operations load buffer self message
message
80
x = 0 y = 0
P0 P1
P0: read: y = 0 P0: write: x = 1
81
y = 0
P0 P1
P0: read: y = 0 P0: write: x = 1 writes to the memory x,1,self x = 1 adds self message
82
y = 0
P0 P1
P0: read: y = 0 P0: write: x = 1 x,1,self x = 1 x,1,other propagates from the memory
83
y = 0
P0 P1
P0: read: y = 0 P0: write: x = 1 propagates from the memory x,1,self x = 1 x,1,other y,0,other
84
y = 0
P0 P1
P0: read: y = 0 P0: write: x = 1 x = 1 x,1,other y,0,other
85
x,1,self deletes the
y = 0
P0 P1
x = 1 x,1,other y,0,other reads the
P0: read: y = 0 P0: write: x = 1
86
87
Theorem
The Dual-TSO semantics is equivalent to the TSO semantics with respect to the reachability problem.
88
x,2,self y,1,self y,0,self
x,1,other x,0,other
newest self message on x newest self message on y
89
x,2,self y,1,self y,0,self x,1,other x,0,other x,2,self y,1,self y,0,self x,0,other
90
x,2,self y,1,self y,0,self x,1,other x,0,other x,2,self y,1,self y,0,self x,0,other
91
WQO for Dual-TSO
x = 1 y = 0
P0 P1 x,1,other x,1,self
P0 P1
92
WQO for Dual-TSO
x = 1 y = 0
P0 P1 x,1,other x,1,self
P0 P1
93
x = 1 y = 0
P0 P1 x,1,other x,1,self
P0 P1
94
WQO for Dual-TSO
NO memory snapshot Need memory snapshot
No viewing pointer, ID of
process Need viewing pointers, IDs of processes Several channels: one channel per process Only one channel Buffers have read
Buffers have write
efficient can be applied to parameterised verification
96
Dual-TSO vs Memorax
Single buffer approach (exact method [TACAS12+13]) https://www.it.uu.se/katalog/tuang296/dual-tso
97
Dual-TSO vs Memorax
standard benchmarks: litmus tests and mutual algorithms
98
Dual-TSO vs Memorax
running time in seconds
99
Dual-TSO vs Memorax
generated configurations Dual-TSO is faster and uses less memory in most of examples
100
unbounded number of processes
101
increasing the number of processes
102
Dual-TSO is more scalable
103
200 400 600 2 3 4 5 6 7 8 9 10
LB
Dual-TSO Memorax
Dual-TSO is more efficient and scalable
104
Dual-TSO Model
105
Possible Extension
106
107
108
109
reachability analysis reachable? execution analysis preventable? program correct program incorrect specification no yes yes no insert fences
110
program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
111
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
112
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
113
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
114
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
115
specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
116
no reordering = bug not due to memory model specification program
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
117
specification program find reordering and prevent it
reachability analysis reachable? execution analysis preventable? program correct program incorrect no yes yes no insert fences
118
specification program try again
needed for correctness