-
-
Cache Memory consists of entries called blocks (or lines)
-
bytes (in MIPS, )
-
(in MIPS, )
-
- (for choose the set)
- (aka: word-offset; for choose the word inside the block)
- (used for the byte part of the address)
-
-
Cache
-
Cache size:
-
-
- (this is also the number of valid-bits in the cache)
-
-
-
-
is the number of ways (for blocks) per set
- (where cache size is in bytes)
- is a direct-mapped cache
- is a 2-way set-associative cache
-
When is the cache is fully associative, and the number of sets is
-
For given cache size, when increases, (index-bits) decreases and the tag-bits increases
-
The ratio between the main memory size and the cache size (data) is
Mapping Process
in general:
- by taking modulo of a number with we get its LSB bits
- by dividing a number with we get the number without its LSB bits (i.e. shifting right by bits)
NOTE
When is a word address then we use in , but when is a byte address then we use
Given we have a word address in main memory
-
The range of addresses in a block in main memory that contains is:
-
is the memory block number of
-
is the index (set number) to which will be mapped in the cache
-
is the tag of
-
Alternatively, we can calculate the index as
EXAMPLE
- (thus, bytes per block)
- (thus, sets=blocks, because )
- is an address in main memory
- (shift by m+2) by dividing by , we get which is the block number in memory (index+tag)
- (ignore the remainder, if there were any)
- by takeing modulo to with , we get the index (set number, bit) which is
- by dividing by , we get the tag which is
- (ignore the remainder, if there were any)
- another approache:
Performance
Computer Architecture: A Quantitative
10. Average memory-access time = Hit time + Miss rate Miss penalty
11. Misses per instruction = Miss rate Memory access per instruction
12. Cache index size: 2index = Cache size /(Block size Set associativity)
Cache CPI Misses per instruction Miss penalty
-
-
-
-
The hit time is the time required to access a level of the memory hierarchy, including the time needed to determine whether the access is a hit or a miss.
-
The miss penalty is the time required to fetch a block into a level of the memory hierarchy from the lower level, including (1) the time to access the block, (2) transmit it from one level to the other, (3) insert it in the level that experienced the miss, and then (4) pass the block to the requestor.
-
-
-
(Average memory-access time)
-
Ex.
-
Ex.
- Given:
- Answer:
- Assume we add L2 cache:
- (global miss rate to main mem)
- extra penalty 400 cycles
- speedup:
- Given:
-
Given:
- (instructions that access data memory)
- base CPI = 2
-
miss cycles per instruction
- data:
- ins.:
-
total number of memory-stalls cycles per ins.:
-
new CPI (with memory stalls):
-
speedup:
-
given:
- (instructions that access data memory)
-
find the CPU time of a program with instructions
- miss cycles per instruction:
- data:
- ins.:
- total:
- new CPI:
- miss cycles per instruction:
-
in general:
N-level
- is the number of levels in the hierarchy, where level is the fastest and level is the slowest.
- is the hit rate at level given that all previous levels were misses
- (the last level is always hit)
- is the miss rate at level
- is the access time at level
example: