Lecture 11: Consistency Models: Topics: Sequential Consistency, HW and HW/SW Optimizations
Lecture 11: Consistency Models: Topics: Sequential Consistency, HW and HW/SW Optimizations
1
Coherence Vs. Consistency
2
Example Programs
Initially, A = B = 0 P1 P2
Data = 2000 while (Head == 0)
P1 P2 Head = 1 {}
A=1 B=1 … = Data
if (B == 0) if (A == 0)
critical section critical section
Initially, A = B = 0
P1 P2 P3
A=1
if (A == 1)
B=1
if (B == 1)
register = A
3
Sequential Consistency
P1 P2
Instr-a Instr-A
Instr-b Instr-B
Instr-c Instr-C
Instr-d Instr-D
… …
We assume:
• Within a program, program order is preserved
• Each instruction executes atomically
• Instructions from different threads can be interleaved arbitrarily
Valid executions:
abAcBCDdeE… or ABCDEFabGc… or abcAdBe… or
aAbBcCdDeE… or …..
4
Sequential Consistency
5
Consistency Example - I
P1 P2
Data = 2000 while (Head == 0) { }
Head = 1 … = Data
7
Consistency Example - 3
Initially, A = B = 0
P1 P2 P3
A=1
if (A == 1)
B=1
if (B == 1)
register = A
8
Sequential Consistency
9
HW Performance Optimizations
10
Relaxed Consistency Models (HW/SW)
Fence Fence
Acquire_lock Acquire_lock
Fence Fence
{ {
Racy code Racy code
} }
Fence Fence
Release_lock Release_lock
Fence Fence 12
Potential Relaxations
13
Relaxations
TSO X X
PC X X X
SC X
IBM 370: a read can complete before an earlier write to a different address, but a
read cannot return the value of a write unless all processors have seen the write
SPARC V8 Total Store Ordering (TSO): a read can complete before an earlier
write to a different address, but a read cannot return the value of a write by another
processor unless all processors have seen the write (it returns the value of own
write before others see it)
Processor Consistency (PC): a read can complete before an earlier write (by any
processor to any memory location) has been made visible to all 14
Performance Comparison
16
Summary
17
Title
• Bullet
18