Question: This problem is to predict the cache behavior of C code. You are given the following code to analyze: int x [ 2 ] [
This problem is to predict the cache behavior of C code. You are given the following code to analyze:
int x;
int sum ;
forint i; i; i
sum xi xi;
Assume this code is executed under the following conditions:
sizeofint
Array x begins at memory address and is stored in rowmajor order.
The cache is initially empty in each case below.
The only memory accesses are to the entries of the array x Variables i and sum are stored in registers.
Given these assumptions, estimate the miss rates for the following cases:
Size of the array x x x K bytes
Case : Assume the cache is bytes, directmapped, with byte cache blocks. What is the miss rate?
Cache size bytes, B S sets
One cache line can hold elements of the array x
i:
x misses cold miss and x x x x are loaded in set
x misses conflict miss and x x x x are loaded in set
i:
x misses conflict miss and x x x x are loaded in set
x misses conflict miss and x x x x are loaded in set
i:
x misses conflict miss and x x x x are loaded in set
x misses conflict miss and x x x x are loaded in set
i:
x misses conflict miss and x x x x are loaded in set
x misses conflict miss and x x x x are loaded in set
The pattern is always missing:
Miss rate
Case : What is the miss rate if we double the cache size to bytes?
Cache size bytes, B S sets
One cache line can hold elements of the array x
i:
x misses cold miss and x x x x are loaded in set
x misses cold miss and x x x x are loaded in set
i:
x hits
x hits
i:
x hits
x hits
i:
x hits
x hits
The pattern is always misses followed by hits of reads miss
Miss rate
Case : Now assume the cache is bytes, twoway associative using an LRU replacement policy, with byte cache blocks. What is the cache miss rate?
Cache size bytes, B E S sets
One cache line can hold elements of the array x
i:
x misses cold miss and x x x x are loaded in set line
x misses cold miss and x x x x are loaded in set line
i:
x hits
x hits
i:
x hits
x hits
i:
x hits
x hits
The pattern is always misses followed by hits of reads miss
Miss rate
Case : For case will a larger cache size help to reduce the miss rate? Why or why not?
A larger cache size will not help to reduce the miss rate because the only misses are cold misses unavoidable
Case : For case will a larger block size help to reduce the miss rate? Why or why not?
Yes. Because more elements will be loaded in the cache line.
Example: B bytes
x will miss and
elements are loaded in the cache x to x Setline
x will miss and
elements are loaded in the cache x to x Setline
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will hit
x will miss and
elements are loaded in the cache x to x Setline
x will miss and
elements are loaded in the cache x to x Setline
x will hit
x will hit
x will hit
x will hit
x
