Cache Coherency
Cache Coherency
Cache Coherency
shared-memory architectures
1
Overview
Shared
CPU CPU CPU Memory
Cache Cache Cache
Shared Bus
3
Organization
4
Problem of Memory Coherence
5
Example
1 X: 24
32 2 X: 24 3 Shared X: 24
CPU CPU CPU Memory
Cache Cache Cache
Shared Bus
Processor 1 reads X: obtains 24 from memory and caches it
Processor 2 reads X: obtains 24 from memory and caches it
Processor 1 writes 32 to X: its locally cached copy is updated
Processor 3 reads X: what value should it get?
Memory and processor 2 think it is 24
Processor 1 thinks it is 32
6
Notice that having write-through caches is not good enough
Bus Snooping
7
Snooping Protocols
Write Invalidate
CPU wanting to write to an address, grabs a bus
cycle and sends a write invalidate message
All snooping caches invalidate their copy of
appropriate cache line
CPU writes to its cached copy (assume for now
that it also writes through to memory)
Any shared read in other CPUs will now miss
in cache and re-fetch new data.
8
Snooping Protocols
Write Update
CPU wanting to write grabs bus cycle and
broadcasts new data as it updates its own copy
All snooping caches update their copy
Note that in both schemes, problem of
simultaneous writes is taken care of by bus
arbitration - only one CPU can use the bus
at any one time.
9
Update or Invalidate?
10
Update or Invalidate?
12
MESI Protocol (1)
13
MESI Protocol (2)
15
MESI Protocol (4)
16
MESI Local Read Hit
17
MESI Local Read Miss (1)
20
MESI Local Write Hit (1)
S
Processor broadcasts an invalidate on bus
Snooping processors with S copy change S->I
Local cache value is updated
Local state change S->M
22
MESI Local Write Miss (1)
No other copies
Value read from memory to local cache (?)
Value updated
Local copy state set to M
23
MESI Local Write Miss (2)
24
MESI Local Write Miss (3)
26
Putting it all together
Read
Miss(sh) Read
Invalid Mem Read Shared Hit
Read Invalidate
RWITM Mem Read
Miss(ex) Write
Write Hit
Miss
Read Read
Modified Exclusive Hit
Hit Write
Hit
Write = bus transaction
Hit 28
MESI remotely initiated accesses
Mem Read
Invalidate
Invalid Shared
Mem Read
RWITM Mem Read RWITM
Modified Exclusive
= copy back
29
MESI notes
There are minor variations (particularly to
do with write miss)
Normal write back when cache line is
evicted is done if line state is M
Multi-level caches
If caches are inclusive, only the lowest level
cache needs to snoop on the bus
30
Directory Schemes
31
Basic Scheme (Censier & Feautrier)
P P
33