Midterm2 s2012 Sol
Midterm2 s2012 Sol
Midterm2 s2012 Sol
spring
Exam II
Name: _____________Solution_______________(print)
1.(25%) Caches are important to providing a high performance memory hierarchy to
processors. Below is a list of 32-bit memory address references, given as word addresses.
6, 214, 175, 214, 6, 84, 65, 174, 105, 85, 215.
(a) Given a direct-mapped cache with two-word blocks and a total size of eight blocks’
Identify the tag, and the index of each reference and also list if each reference is a hit or a
miss and the final cache data assuming the cache is initially empty.
The following table is for your convenient adding more entries as needed
Ans: total cache size = 8 blocks and using 2-word blocks,
1 bit for word offset, 3 bits for block selection, i.e., 3 bits for index, the rest is Tag bits
A fully-associative cache with the same cache size, i.e., N one-word blocks using LRU
A program repeatedly accesses location from word 0 to word N,
First N memory accesses will have misses (cold start)
Memory access sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, …. N-1
Block 0 has word 0
Block 1 has word 1
….
Block N-1 has word N-1
Now Block 0 is the LRU block, and Block 0 will be replaced by the next location causing
miss.
Memory access sequence: N, 0, 1, 2 ,3, 4
Accessing word N will cause replacing word 0 by word N
Accessing word 0 will cause replacing word 1 by word 0
…….
- Hit Rate = 0.
4. (a) (20%) Consider the following program
integer A[1000]
for ( i=0; i < 1000; i +=1)
{ A[i] = A[i] + i}
Run the above program on a processor with a 1K byte direct-mapped write-back cache
with 4-word cache blocks. What is the approximate data cache miss rate?
assuming integers are 1 word long and a word has 4 bytes.
Each block has 4 words and each word has 4 bytes. 1K bytes 1024/16 = 64 blocks
Block 0 has word 0 – word 3, i.e., A[0] – A[3]
Block 1 has word 4 – word 7, i.e., A[4] – A[7]
……
Block 63 has word 996 – word 999, i.e., A[996] – A[999]
Each miss brings the whole block to the cache, the next 3 memory accesses will be hit.
Altogether there are 250 misses (caused by accessing A[0], A[4], A[8], … , A[996])
The program reads 1000 times and writes 1000 times. Miss rate = 250/2000 = 12.5%
4. (b) (5%) For the same problem in 4. (a), if change the cache write policy to write
through cache, will the cache miss rate increase or decrease? Explain
Cache miss rate: no change. Write through policy will not change the cache miss rate
because write through policy does not alter cache data in any way to change the cache
miss rate.
5. (10%) Given the following information: 32-bit virtual memory address, 8-KB pages,
64-MB physical memory, 128 entry direct-mapped TLB with one physical page number
per entry, each TLB has a valid bit and a dirty bit. Determine the TLB entry size in bits if
you only use the minimum necessary physical address size.
(Show all your work)
64MB physical memory --- needs 26 bits for physical memory address.
Each page has 8KB --- 13 bits, i.e., page offset for 8KB page is 13 bits.
26 – 13 = 13 bits --- physical page number is 13 bits wide.
Virtual memory address has 32 bits, 32 – 13 = 19 bits (All 19 bits will be used as virtual
page number if TLB is fully associative)
Now TLB is 128 entry direct-mapped TLB. It needs 7 bits for TLB indexing.
19 – 7 = 12 Tag bits, or say TLB Tag.
Each TLB entry will have 12 bits TLB tag + 13 bits physical page number = 25 bit.