1 beyond reduction.... 2 busy acquire atomic void busy_acquire() { while (true) { if (cas(m,0,1))...
TRANSCRIPT
![Page 1: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/1.jpg)
1
Beyond Reduction ...
![Page 2: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/2.jpg)
2
Busy Acquire
atomic void busy_acquire() {while (true) { if (CAS(m,0,1)) break;}
}
if (m == 0) { m = 1; return true;} else { return false;}
![Page 3: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/3.jpg)
3
Busy Acquire
atomic void busy_acquire() {while (true) { if (CAS(m,0,1)) break;}
}
CAS(m,0,1) CAS(m,0,1) CAS(m,0,1)
(fails) (fails) (succeeds)
![Page 4: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/4.jpg)
4
Non-Serial Execution:
Serial Execution:
Atomic but not reducible
CAS(m,0,1) CAS(m,0,1) CAS(m,0,1)
(fails) (fails) (succeeds)
CAS(m,0,1)
(succeeds)
![Page 5: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/5.jpg)
5
alloc boolean b[MAX]; // b[i]==true iff block i is free
Lock m[MAX];
atomic int alloc() { int i = 0; while (i < MAX) { acquire(m[i]); if (b[i]) { b[i] = false; release(m[i]); return i; } release(m[i]); i++; } return -1;
}
![Page 6: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/6.jpg)
6
alloc
acq(m[0]) test(b[0]) rel(m[0])acq(m[1]) test(b[1]) rel(m[1])b[1]=false
![Page 7: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/7.jpg)
7
alloc is not Atomic
There are non-serial executions with no equivalent serial executions
![Page 8: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/8.jpg)
8
m[0] = m[1] = 0; b[0] = b[1] = false;
t = alloc(); || free(0); free(1);
void free(int i) { acquire(m[i]); b[i] = true; release(m[i]);}
![Page 9: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/9.jpg)
9
Non-Serial Execution:
Serial Executions:
loop for b[0] t = 1
free(0) loop for b[1]free(1)
loop for b[0] free(0)loop for b[1] free(1)
loop for b[0]free(0) free(1)
t = -1
t = 0
loop for b[0]free(0) free(1) t = 0
m[0] = m[1] = 0; b[0] = b[1] = false;
t = alloc(); || free(0); free(1);
![Page 10: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/10.jpg)
10
Extending Atomicity
Atomicity doesn't always hold for methods that are "intuitively atomic"– serializable but not reducible
(busy_acquire)– not serializable (alloc)
Examples– initialization – resource allocation– wait/notify
– caches– commit/retry transactions
![Page 11: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/11.jpg)
11
Pure Code Blocks
Pure block: pure { E }– If E terminates normally, it does not update
state visible outside of E–E is reducible
Example while (true) { pure { acquire(mx); if (x == 0) { x = 1; release(mx); break; } release(mx); } }
![Page 12: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/12.jpg)
12
Purity and Abstraction
A pure block's behavior under normal termination is the same as skip
Abstract execution semantics:– pure blocks can be skipped
acq(m) test(x) rel(m)
acq(m)test(x)rel(m)
skip
![Page 13: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/13.jpg)
13
Abstraction
Abstract semantics that admits more behaviors – pure blocks can be skipped– hides "irrelevant" details (ie, failed loop iters)–
Program must still be (sequentially) correct in abstract semantics
Abstract semantics make reduction possible
![Page 14: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/14.jpg)
14
Busy Acquire
atomic void busy_acquire() {while (true) { pure { if (CAS(m,0,1)) break; }}
}
![Page 15: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/15.jpg)
15
Abstract Execution of Busy Acquire
atomic void busy_acquire() {while (true) { pure { if (CAS(m,0,1)) break; }}
}CAS(m,0,1) CAS(m,0,1) CAS(m,0,1)
skip skip CAS(m,0,1)
(Concrete)
(Abstract)
(Reduced Abstract)
![Page 16: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/16.jpg)
16
alloc atomic int alloc() {
int i = 0; while (i < MAX) { pure { acquire(m[i]); if (b[i]) { b[i] = false; release(m[i]); return i; } release(m[i]); } i++; } return -1;}
![Page 17: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/17.jpg)
17
Abstract Execution of alloc
acq(m[0]) test(b[0]) rel(m[0])acq(m[1]) test(b[1]) rel(m[1])b[1]=false
skip acq(m[1]) test(b[1]) rel(m[1])b[1]=false
(Abstract)
(Reduced Abstract)
![Page 18: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/18.jpg)
18
Abstract semantics admits more executions
Can still reason about important properties – "alloc returns either the index of a freshly
allocated block or -1"– cannot guarantee "alloc returns smallest
possible index"• but what does this really mean anyway???
Abstraction
skip acq(m[1]) test(b[1]) rel(m[1])b[1]=false
(Abstract)
free(0) free(1)
![Page 19: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/19.jpg)
19
To Atomicity and Beyond ...
![Page 20: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/20.jpg)
20
![Page 21: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/21.jpg)
21
Commit-Atomicity
Reduction– Great if can get serial execution via commuting
Reduction + Purity– Great if non-serial execution performs extra pure
loops
Commit Atomicity– More heavyweight technique to verify if some
corresponding serial execution has same behavior• can take different steps
![Page 22: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/22.jpg)
22
Checking Commit Atomicity
Run normal and serial executions of program concurrently, on separate stores
Normal execution runs as normal– threads execute atomic blocks– each atomic block has commit point
Serial execution– runs on separate shadow store– when normal execution commits an atomic
block, serial execution runs entire atomic block serially
Check two executions yield same behavior
![Page 23: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/23.jpg)
23
Commit-Atomic
commitatomic block
...
...
Normal execution
Serial execution
comparestates
![Page 24: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/24.jpg)
24
Preliminary Evaluation
Some small benchmarks– Bluetooth device driver• atomicity violation due to error
– Busy-waiting lock acquire• acquire1: 1 line of code in critical section• acquire100: 100 lines of code in critical section
Hand translated to PROMELA code– Two versions, with and without commit-
atomic– Model check with SPIN
![Page 25: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/25.jpg)
25
Performance: Bluetooth device driver
Bluetooth driver benchmark
10
100
1000
10000
100000
1000000
2 3 4 5 6
Number of Threads
Siz
e o
f s
tate
sp
ac
e
Normal
Commit-Atomic
![Page 26: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/26.jpg)
26
Performance: acquire1 and acquire100
Busy-waiting lock acquire
100
1000
10000
100000
1000000
2 3 4 5 6 7
Number of threads
Siz
e o
f sta
te s
pace
acquire1: normal
acquire1: commit-atomic
acquire100: normal
acquire100: commit-atomic
![Page 27: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/27.jpg)
27
Summary
Atomicity– concise, semantically deep partial specification– aka serializability
Reduction– lightweight technique for verifying atomicity– can verify with types, or dynamically– plus purity, for complex cases
Commit-Atomicity– more general technique
![Page 28: 1 Beyond Reduction.... 2 Busy Acquire atomic void busy_acquire() { while (true) { if (CAS(m,0,1)) break; } } if (m == 0) { m = 1; return true; } else](https://reader036.vdocuments.net/reader036/viewer/2022062407/56649d055503460f949d8fc0/html5/thumbnails/28.jpg)
28
Summary
Atomicity– concise, semantically deep partial specification
Reduction– lightweight technique for verifying atomicity
Commit-Atomicity– more general technique
Future work– combine reduction and commit-atomic– generalizing atomicity
• temporal logics for determinism?