

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























Cache Structure
-^ Set-Associativity •^ Replacement policies -^ Overhead •^ Implementation -^ Handling writes •^ Cache simulations
Cache Structure
READ HIT:One of the cache tags matchesthe incoming address; the dataassociated with that tag isreturned to CPU.READ MISS:None of the cache tagsmatched, so initiate access tomain memory and stall CPUuntil complete. Update cacheentry with new tag (address)and data.
Cache Structure
Amortize Tag Costs: More Data/Tag
ADDR
DATAHIT
-^ blocks
of 2
B^ words, on 2
B^ word boundaries
-^ always read/write 2
B^ word BLOCK from/to memory
-^ exploits
spatial locality
: nearby words in block, likely to accessed
BIG Cache Lines:^ •^ cost: some fetches of unaccessed words^ •^ BIG WIN if path to memory is wide, or sequential accesses are fast
Enlarge each line in fully-associative cache TAG
D^
D^
D^
D
Tag bits/cache entry = (30 – 2) bitsData bits/cache entry = 4*32 bits
Only 18% of cache’s memory used for tags
Cache Structure
Block Size vs. Miss Rate
-^ spatial locality: larger blocks
→→→→
reduce miss rate
-^ fixed cache size: larger blocks
→→→→^
fewer lines in cache →→→→^
higher miss rate, especially in small caches
Cache Structure
Fully-Assoc. vs. Direct-mapped
Fully-associative N-line cache: •^ N tag comparators, registers usedfor tag/data storage ($$$) •^ Location A can be stored in ANYof the N cache lines; no “collisions” •^ Replacement strategy (e.g., LRU)used to pick which line to use whenloading new word(s) into cache
Direct-mapped N-line cache: •^ 1 tag comparator, SRAM used fortag/data storage ($) •^ Location A is stored in aSPECIFIC line of the cachedetermined by its address;address “collisions” possible •^ Replacement strategy not needed:each word can only be cached in onespecific cache line
COLLISIONs occur when theremultiple items that we’d like tokeep cached, we have room, butour management policies allowsus to only a subset of them.
Is there something in- between?
Cache Structure
N-Way Set-Associative Cache k HIT
=? t
There areN possibleplacesthat agiven itemcould bestored inthe cache^ MEM DATA
N direct-mapped caches, each with 2
t^ entries of N lines^ =?
=?
This lines of each index are a set
(N lines/cache index)
Cache Structure
14 12 10 8 6 4 2 0
1-way 2-way 4-way 8-way fully assoc.
Associativity vs. Miss Rate
Miss rate
(%)
Cache size (bytes)
Associativity
-^ 8-way is (almost) as effective as fully-associative •^ rule of thumb: N-byte M-way set assoc ≈ N/2-byte 2M-way set assoc.
Direct-mapped
Cache Structure
N
address
N-way set associative • compares addr with
N
tags simultaneously •^ Data can be stored inany of the N cache linesbelonging to a “set” •^ like N Direct-mappedcaches
Continuum of Associativity
Fully associative address • compares addr with all tags simultaneously • location A can bestored in any cache line
address
Direct-mapped
-^ compare addr withonly
one
tag
-^ location A can bestored in exactly onecache line
Allocates a cache entry
Allocates 1 of N lines in a set
Only one place to put it
Cache Structure
Three Replacement Strategies
-^ replaces the item that has gone UNACCESSED the LONGEST •^ favors the most recently accessed
data
-^ replaces the OLDEST item in cache •^ favors recently loaded
items over older STALE items
-^ replace some item at RANDOM •^ no favoritism – uniform distribution •^ no “pathological” reference streams causing worst-case results •^ use pseudo-random generator to get reproducible behavior
Cache Structure
Keeping Track of LRU
-^ Needs to keep ordered list of N items for anN-way associative cache, that is
(0,1,2,3)
Hit 2
Current Order
Action
Resulting Order
(2,0,1,3)
(2,0,1,3)
Hit 1
(1,2,0,3)
(1,2,0,3)
Miss, Replace 3
(^3 ,1,2,0)
(3,1,2,0)
Hit 3
(3,1,2,0)
-^
Cache Structure
Example: LRU for 4-Way Sets
-^
-^
How?
-^
One Method:
“One-Out/Hidden Line” coding (and variants) Directly encode the indices of the N-2 most recently accessed lines,plus one bit indicating if the smaller (0) or larger (1) of theremaining lines was most recently accessed
(2,0,1,3)
->
10 00 0
(3,2,1,0)
->
1 1 10 1
(3,2,0,1)
->
1 1 10 0
Requires (N-2)*log
N + 1 bits 2
-^ 8-Way sets? log
8! = 16, (8-2)*log 2
8 + 1 = 19 2
Bottom line,LRUreplacementrequiresconsiderableoverhead asassociativityincreases Overhead isO(N log
N) 2 bits/set
Cache Structure
FIFO Replacement
-^
Each set keeps a modulo-N counter that points to victimline that will be replaced on the next miss
-^
Counter is only
updated only on cache misses
Ex: for a 4-way set associative cache:
(0)
Miss, Replace 0
Next Victim
Action
( 1)
Hit 1
( 1)
Miss, Replace 1
(2)
Miss, Replace 2
(3)
Miss, Replace 3
(0)
Miss, Replace 0
Overhead isO(log
N) 2 bits/set
Cache Structure
FIFO For 4-way Sets
-^
-^
-^
-^
-^
-^
Easy to implement, scales well,BUT CAN WE AFFORD IT?
Cache Structure
Random Replacement
-^
Build a single Pseudorandom Number generator forthe WHOLE cache. On a miss, roll the dice andthrow out a cache line at random.
-^
Updates only on misses.
-^
How do you build a random numbergenerator (easier than you might think).
0x1F 01111
0x0F 00111
0x 10011
0x 11001
0x 01100
0x0C 10110
0x 01011
0x0B 00101
0x 10010
0x 01001
0x 00100
0x 00010
0x 00001
0x 10000
0x
0x 10100
0x 01010
0x0A 10101
0x 11010
0x1A 11101
0x1D 01110
0x0E 10111
0x 11011
0x1B 01101
0x0D 00110
0x 00011
0x 10001
0x 11000
0x 11100
0x1C 11110
0x1E
Counting
Sequence
Pseudorandom Linear Feedback Shift Register
Overhead isO(log
N) 2 bits/cache!