200 likes | 318 Views
Cache performance. CS 147 Prof. Lee Hai Lin Wu. Cache performance. Introduction Primary components Cache hits Hit ratio Cache misses Average memory access time. Why we use cache memory in a computer?. The primary reason:
E N D
Cache performance CS 147 Prof. Lee Hai Lin Wu
Cache performance • Introduction • Primary components • Cache hits • Hit ratio • Cache misses • Average memory access time
Why we use cache memory in a computer? The primary reason: to improve system performance by reducing the time needed to access memory.
Cache hits • Definition • Every time the CPU accesses memory, it checks the cache. If the requested data is in the cache, the CPU accesses the data in the cache, rather than physical memory; this is a cache hit.
A simple example Every time CPU access memory it checks cache first. CPU checkaccessesdata (not in cache) Physical memory cache
Cache misses • Definition: • If the data is not in the cache, the CPU accesses the data from main memory(and usually writes the data into the cache as well). This is a cache miss.
Hit ratio • Definition: • The hit ratio is the percentage of memory accesses that are served from the cache. Hit Ratio = #of hits / total Strings
Average Memory access time • Symbol: TM
Formula for TM • TM = hTc + (1 – h) Tp *Tc – cache access time *Tp – physical memory access time *h -- hit ratio (Note: Tc and Tp are always given)
Relationship between Hit ratios and Average memory access times • Table: So, increase the hit ratio reduce the average memory access time.
Calculating the H and TM • We will learn how to calculate the H and TM with two different type of cache * associative cache (FIFO) * two-way set-associative cache(LRU) • Besides, there is a direct mapped cache
Example cont. Given: Tc = 10ns Tp = 60ns From the previous table we get: hits = 7 inputs = 18 ** h(hit ratio)= hits/ inputs = 7/18 = 0.389 ** TM = h Tc + (1 – h) Tp =0.89*10 + (1 - 0.389) 60 = 40.56 ns
Two-way associative set- associative cache(LRU) • Hit ratio h = 0.389 • TM = 40.56 ns
A simple example for LRU • Since the example from book is kind of hard to understand, we can see the following simple example.
Simple example of LRU • 3 frame • 10 inputs: 1, 2, 3, 0, 2, 3, 1, 3, 0, 4
Construct a table • Table
Direct mapped cache • The hit ratio h = 0.167 • The TM = 50.67 ns
BUT… You have to remember • How to set up the table for FIFO and LRU • How to calculate • Hit Ratio • Average memory access time Gook luck on finals!!