Title: Implementing Sequentially Consistent Programs on Processor Consistent Platforms
1Implementing Sequentially Consistent Programson
Processor Consistent Platforms
- Lisa Higham and Jalal Kawash
- University of Calgary, Canada
- American University of Sharjah, UAE
2Outline
- Memory consistency models
- Sequential consistency
- P-RAM
- Coherence
- PC-G
- Compiling from SC to PC-G
- Good news
- Bad news
- Proof
3Multi-Processors Computation
..
P
P
P
P
o1
o1
o1
o1
o2
o2
o2
o2
O
o3
o3
o3
o3
..
..
4Sequential Consistency
..
P
P
P
P
Switch
Shared Memory
5Sequential Consistency Example
P
P
P
w(x, 3)
r(y) 4 r(x) 2
w(x, 2) w(y, 1)
w(x, 3) w(y, 4)
w(y, 4)
r(y) 4
w(x, 2)
w(y, 1)
r(x) 2
0
0
0
0
0
0
3
4
2
1
x
y
6Sequential Consistency Definition
- A computation is sequentially consistent iff ? a
valid total order on O such that - (O, ) ? (O, )
7P-RAM
x
y
z
x
y
z
P
P
FIFO Channels
Copies of Memory
P
P
x
y
z
x
y
z
8P-RAM Example
x
y
x
y
0
0
0
0
2
1
0
0
0
0
2
1
y ? 2
P
w(x, 1)
x? 1
P
x? 1
y ? 2
y ? 2
x? 1
w(y, 2)
r(x) 1
r(y) 0
r(y) 2
P
r(x) 0
P
0
0
0
0
2
1
0
0
0
0
2
1
x
y
x
y
P
P
P
P
r(y) 2 r(x) 0
r(x) 1 r(y) 0
w(y, 2)
w(x, 1)
9P-RAM Definition
- A computation is P-RAM iff for each process p,
? a valid total order such that - (Op Ow, ) ? (Op Ow,
)
n
n
10Coherence
...
P
P
P
P
z
y
x
11Coherence Example
P
P
P
P
P
w(x, 2)
w(y, 3)
x ? 2
y ? 3
r(y) 0
r(x) 0
w(x, 2)
r(y) 0
2
3
0
0
w(y, 3)
r(x) 0
y
x
12Coherence Definition
- A computation is Coherent iff for each
variable x, ? a valid total order
such that - (Ox , ) ? (Ox , )
13PC-G P-RAM and Coherence
Coherence
P-RAM
PC-G
14P-CG Definition
- A computation is P-CG iff for each process p,
? a valid total order such that - (Op Ow, ) ? (Op Ow,
) - ? processes q, and ? variable x
- (Ow n Ox, ) (Ow n Ox, )
n
n
15P-CG vs. SC
- Algorithms are designed for SC machines
- Some of them work directly when run on
- P-CG (e.g. Peterson 2)
- Most of the SC algorithms do not work on P-CG
machines (e.g. testset and Bakery algorithm)
16 - Can we transform an SC algorithm to an equivalent
P-CG algorithm? - Can we find a compiler that transforms any SC
algorithm to an equivalent P-CG algorithm?
17Program Transformation and Interpretation
C
E
Program P
Execute P on SC
Transformation a
Interpretation
D
Program a(P)
Execute a(P) on PC-G
C Computations of P on SC machines D
Computations of a(P) on M machines E
Interpretations of D on SC machines
18Program Implementation
C
E
Program P
Execute P on SC
Transformation a
Interpretation
D
Program a(P)
Execute a(P) on PC-G
If ? program P, a implements P, then a is a
compiler from SC to PC-G
C SC Computations of P D P-CG Computations
of a(P) E Interpretations of D
19Transformation Function a
- m a new multi-writer variable
20Results
- Claim 1
- ? implements Lamports Bakery algorithm for 2
processes on PC-G - Claim 2
- ? is a compiler from SC to PC-G for any program
provided - Only 2 processes
- Only single-writer variables
21Transformation Example
Program
P
P
w(x, 1) r(y)
w(y, 4) w(y, 2) r(x)
Under SC if r(y) returns 4, then r(x) returns 1
Under PC-G r(y) returns 4 and r(x) may return 0
22Transformation Example
Program
?(Program)
P
P
w1(m, P)
w1(m, P)
w(x, 1)
w(y, 4)
w2(m, P)
w2(m, P)
r(y)
w3(m, P)
w(y, 2)
w4(m, P)
r(x)
23Transformation Example
P
P
View for
View for
w1(m, P)
w1(m, P)
w1(m, P)
w1(m, P)
w(x, 1)
w(y, 4)
w(x, 1)
w(y, 4)
w2(m, P)
w2(m, P)
w2(m, P)
w2(m, P)
r(y)
w3(m, P)
w3(m, P)
w(y, 2)
w(y, 2)
If r(y) returns 4
w4(m, P)
r(x) must return 1
w4(m, P)
r(x)
24Proof Sketch
Program
PC-G Views
P
P
P
P
w1
w
w2
25Proof Sketch
- System view
- Contains all reads and writes by both processes
- Maintains program order
- Is valid
26Summary
- Compiler
- Only one additional variable
- Only writes to that variable
- Provided
- Two processors
- Single writer variables
27Impossibilities
- For more than 2 processors, there is no compiler
from SC to PC-G that - Only adds write instructions (with any number of
variables) - nor
- Uses only one additional variable (with any
number of reads and writes)
28Pros and Cons
- Restricted
- 2 processes
- Only single writer variables
- Valuable
- ME Lamports Bakery algorithm
- Wait-free testset had no known solutions in weak
memory consistency
29Wait-Free Testset
- Define testsetlt(O, i)gt
- if (si you and sj ? rst) the return 1
- repeat
-
- si ? choose
- case sj is
- you, rst
- si ? me
- me
- si ? you
- choose
- si ? random (me, you)
- end case
- until (si ? sj)
- if (si me) then return 0
- else return 1
Define resetlt(O, i)gt si ? rst
m? i
m? i
m? i
m? i
m? i
m? i
m? i
m? i
30Conclusions
- a works for any two-process program with
- single-writer variables
- a works for particular programs with gt 2
processes (randomized wait-free n-process
testset) - If there is a transformation that work for other
cases, it must be more complicated - Cannot be write-adding
- Must use more than one additional variable
31Thank You?
32Proof Sketch
Program
PC-G Views
P
P
P
P
w1
w
w2