Cache Control
Philipp Koehn 16 October 2019
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
Cache Control Philipp Koehn 16 October 2019 Philipp Koehn - - PowerPoint PPT Presentation
Cache Control Philipp Koehn 16 October 2019 Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019 Memory Tradeoff 1 Fastest memory is on same chip as CPU ... but it is not very big (say, 32 KB in L1 cache)
Philipp Koehn 16 October 2019
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
1
... but it is not very big (say, 32 KB in L1 cache)
... but can be very large (say, 256GB in compute server)
illusion that large memory is fast
use small memory as cache for large memory
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
2
Smaller memory mirrors some of the large memory content
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
3
keep mapping from cache to main memory simple ⇒ Use part of the address as index to cache
– memory position in block (offset) – index – tag to identify position in main memory
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
4
0010 0011 1101 1100 0001 0011 1010 1111
256 bytes (8 bits)
1MB (20 bits) 0010 0011 1101 1100 0001 0011 1010 1111 Tag Index Offset
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
5
0010 0011 1101 1100 0001 0011 1010 1111 Tag Index Offset
Index Tag Valid Data 4096 slots (12 bits) (1 bit) 256 bytes 000 001 xx xx xx xx xx xx xx xx 002 ... ... ... ... fff
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
6
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
7
Cache Main Memory CPU
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
8
Tag Index Offset 256 byte Memory Tag Valid Decoder 256 byte Memory Tag Valid Main Memory CPU 256 byte Memory Tag Valid 256 byte Memory Tag Valid 256 byte Memory Tag Valid 256 byte Memory Tag Valid
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
9
Tag Index Offset 256 byte Memory Tag Valid Decoder 256 byte Memory Tag Valid =
AND
Main Memory CPU
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
10
Tag Index Offset 256 byte Memory Tag Valid Decoder 256 byte Memory Tag Valid =
AND
Select Main Memory CPU
(identified by offset)
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
11
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
12
Cache Main Memory CPU
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
13
– CPU clock cycle: 3 GHz → 0.33ns per instruction – DRAM speeds: 50ns ⇒ Significant delay (150 instruction cycles stalled)
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
14
Tag Index Offset Tag Valid Decoder 256 byte Memory Tag Valid =
AND
Select Main Memory CPU 256 byte Memory
– block size 256 bytes – request to read memory address $00d3ff53
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
15
this requires 53 read cycles before relevant byte is loaded
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
16
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
17
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
18
Cache Main Memory CPU
immediately store changed value in memory
slows down every write
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
19
Cache Main Memory CPU
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
20
– store value in write buffer – transfer values from write buffer to main memory in background – free write buffer
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
21
CPU writes to address X, but X is not cached
– allocate cache slot – write in value for X – load remaining values from main memory – set dirty bit
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
22
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
23
– IF: instruction fetch loads current instruction – MEM: memory stage reads and writes data ⇒ 2 memory caches in processor – instruction memory – data memory
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
24
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019
25
same memory block in both caches ... but very unlikely: code and data usually separated
→ contention for memory lookup, blocking
no writes
Philipp Koehn Computer Systems Fundamentals: Cache Control 16 October 2019