Skip to content

Final Practice Problems | CSCI 343

Given a RAM configuration 1K×161\text{K} \times 16, we want to:

  • Increase the RAM capacity 10 times
  • Access word 3079 (draw the circuit and indicate the settings to accommodate this task)
Solution

Put 10 chips together (C0C_0C9C_9), 1024 words each

3079=3×1024+7    access chip 3, with offset 73079 = 3 \times 1024 + 7 \implies \text{access chip 3, with offset 7} 3079=211+210+7=11000000011123079 = 2^{11} + 2^{10} + 7 = \texttt{110000000111}_2

Chip config 1K×16=210×161\text{K} \times 16 = 2^{10} \times 16 indicates:

Bit width for the offset: 10 bits\text{Bit width for the offset: } 10 \text{ bits} Word size: 16 bits     16-bit address\text{Word size: } 16 \text{ bits } \implies 16\text{-bit address} 1610=6    6 bits for chip #16 - 10 = 6 \implies 6 \text{ bits for chip \#}

Address Structure:

00 0 0 0 1 1/6 bits00 0 0 0 0 0 0 1 1 1/10 bits\underset{{6 \text{ bits}}}{\boxed{\phantom{0}0\ 0\ 0\ 0\ 1\ 1\phantom{/}}} \underset{{10 \text{ bits}}}{\boxed{\phantom{0}0\ 0\ 0\ 0\ 0\ 0\ 0\ 1\ 1\ 1\phantom{/}}}

Circuit and its settings:

Implement a decoder to act as chip select. To accomodate 10 chips, we need a decoder with input size: log210=4\lceil log_2{10} \rceil = 4 bits

So, our 4×244 \times 2^4 decoder takes chip # 33 (= 001120011_2) as input and enables output line 3, activating C3C_3‘s CS line. Outputs 10—15 are unused.

The Decoder Circuit

Given a RAM configuration 2K×82\text{K} \times 8 and a 16-bit address size, we want to:

  • Increase the RAM capacity 8 times
  • Access word 5140 (draw the circuit and indicate the settings to accommodate this task)
Solution

Put 8 chips together (C0C_0C7C_7), 2048 words each

5140=2×2048+1044    access chip 2, with offset 10445140 = 2 \times 2048 + 1044 \implies \text{access chip 2, with offset 1044} 5140=212+210+24+22=101000001010025140 = 2^{12} + 2^{10} + 2^4 + 2^2 = \texttt{1010000010100}_2

Chip config 2K×8=211×82\text{K} \times 8 = 2^{11} \times 8 indicates:

Bit width for the offset: 11 bits\text{Bit width for the offset: } 11 \text{ bits} Address size: 16 bits (indicated in the problem statement)\text{Address size: } 16 \text{ bits (indicated in the problem statement)} 1611=5    5 bits for chip #16 - 11 = 5 \implies 5 \text{ bits for chip \#}

Address Structure:

00 0 0 1 0/5 bits01 0 0 0 0 0 1 0 1 0 0/11 bits\underset{{5 \text{ bits}}}{\boxed{\phantom{0}0\ 0\ 0\ 1\ 0\phantom{/}}} \underset{{11 \text{ bits}}}{\boxed{\phantom{0}1\ 0\ 0\ 0\ 0\ 0\ 1\ 0\ 1\ 0\ 0\phantom{/}}}

Circuit and its settings:

Implement a decoder to act as chip select. To accomodate 8 chips, we need a decoder with input size: log28=3\lceil log_2{8} \rceil = 3 bits

So, our 3×233 \times 2^3 decoder takes chip # 22 (= 0102010_2) as input and enables output line 2, activating C2C_2‘s CS line.

The Decoder Circuit for 8 chips

Find the total # of bytes for a direct mapping cache to store 64 KB in 1-word blocks, assuming a word size of 32 bits and MIPS addressing.

Solution

1-word blocks     \implies no word select bits.

Word size 32 bits     \implies 32-bit address.

MIPS Addressing     \implies Byte Addressing     \implies Allocate bits for byte #

Address structure:

000Tag00/0line #/0byte #/32 bits\overbrace{ \boxed{\phantom{000}\text{Tag}\phantom{00/}} \boxed{\phantom{0}\text{line \#}\phantom{/}} \boxed{\phantom{0}\text{byte \#}\phantom{/}} }^{\small 32 \text{ bits}}
Word size=32 bits=4 B=22 B    2 bits for byte #Data=64 KB=26×1 KB=26×210 B=216 B# of lines=Data SizeBlock Size=216 B22 B=214 lines    14 bits for line #\begin{aligned} \text{Word size} &= 32 \text{ bits} \\ &= 4\text{ B} \\ &= 2^2 \text{ B} \implies 2 \text{ bits for byte \#} \\[2em] \text{Data} &= 64 \text{ KB} \\ &= 2^6 \times 1 \text{ KB} \\ &= 2^6 \times 2^{10} \text{ B}\\ &= 2^{16} \text{ B} \\[2em] \text{\# of lines} &= \frac{\text{Data Size}}{\text{Block Size}} \\[1em] &= \frac{2^{16} \text{ B}}{2^2 \text{ B}} \\[1em] &= 2^{14} \text{ lines} \implies 14 \text{ bits for line \#} \end{aligned} Tag=32(14+2)=16 bits\text{Tag} = 32 - (14 + 2) = 16 \text{ bits}

Address Structure:

000Tag00016 b0line #014 b0byte #02 b\underset{16\ b}{\boxed{\phantom{000}\text{Tag}\phantom{000}}} \underset{14\ b}{\boxed{\phantom{0}\text{line \#}\phantom{0}}} \underset{2\ b}{\boxed{\phantom{0}\text{byte \#}\phantom{0}}}
diagram of a cache table with columns V/I (1b), Tag (16b), Data (32b block size), showing 2^14 lines and a 64 KB data region highlighted in blue

Each line is 1+16+32=491 + 16 + 32 = 49 bits.

Total cache size:

214 lines × 49 bits/line =49214 b=49211 B=492 KB=98 KB\begin{aligned} 2^{14} \text{ lines} \ \times \ 49 \text{ bits/line} \ &= 49 \cdot 2^{14} \text{ b} \\ & = 49 \cdot 2^{11} \text{ B} \\ & = 49 \cdot 2 \text{ KB} \\ & = 98 \text{ KB} \end{aligned}

Find the total # of bytes for a direct mapping cache to store 128 KB in 2-word blocks, assuming a word size of 64 bits and byte addressing.

Solution

2-word blocks     \implies 1 word select bit.

Word size 64 bits     \implies 64-bit address.

Byte Addressing     \implies Allocate bits for byte #

Address structure:

000Tag00/0line #/0word #/0byte #/64 bits\overbrace{ \boxed{\phantom{000}\text{Tag}\phantom{00/}} \boxed{\phantom{0}\text{line \#}\phantom{/}} \boxed{\phantom{0}\text{word \#}\phantom{/}} \boxed{\phantom{0}\text{byte \#}\phantom{/}} }^{\small 64 \text{ bits}}
Word size=64 bits=8 B=23 B    3 bits for byte #Block size=2 words=21 words    1 bit for word #Data=128 KB=27×1 KB=27×210 B=217 BBlock size=2 words=2×64 b=2×8 B=16 B=24 B# of lines=Data SizeBlock Size=217 B24 B=213 lines    13 bits for line #\begin{aligned} \text{Word size} &= 64 \text{ bits} \\ &= 8\text{ B} \\ &= 2^3 \text{ B} \implies 3 \text{ bits for byte \#} \\[2em] \text{Block size} &= 2 \text{ words} \\ &= 2^1 \text{ words} \implies 1 \text{ bit for word \#} \\[2em] \text{Data} &= 128 \text{ KB} \\ &= 2^7 \times 1 \text{ KB} \\ &= 2^7 \times 2^{10} \text{ B}\\ &= 2^{17} \text{ B} \\[2em] \text{Block size} &= 2 \text{ words} \\ &= 2 \times 64 \text{ b} \\ &= 2 \times 8 \text{ B} \\ &= 16 \text{ B} \\ &= 2^4 \text{ B} \\[2em] \text{\# of lines} &= \frac{\text{Data Size}}{\text{Block Size}} \\[1em] &= \frac{2^{17} \text{ B}}{2^4 \text{ B}} \\[1em] &= 2^{13} \text{ lines} \implies 13 \text{ bits for line \#} \end{aligned} Tag=64(13+1+3)=47 bits\text{Tag} = 64 - (13 + 1 + 3) = 47 \text{ bits}

Address Structure:

000Tag00047 b0line #013 b0word #01 b0byte #03 b\underset{47\ b}{\boxed{\phantom{000}\text{Tag}\phantom{000}}} \underset{13\ b}{\boxed{\phantom{0}\text{line \#}\phantom{0}}} \underset{1\ b}{\boxed{\phantom{0}\text{word \#}\phantom{0}}} \underset{3\ b}{\boxed{\phantom{0}\text{byte \#}\phantom{0}}}
Diagram of cache structure with V/I (1b), Tag (47b), Data (128b block size) and 2^13 lines

Each line is 1+47+128=1761 + 47 + 128 = 176 bits.

Total cache size:

213 lines × 176 bits/line =176213 b=176210 B=1761 KB=176 KB\begin{aligned} 2^{13} \text{ lines} \ \times \ 176 \text{ bits/line} \ &= 176 \cdot 2^{13} \text{ b} \\ & = 176 \cdot 2^{10} \text{ B} \\ & = 176 \cdot 1 \text{ KB} \\ & = 176 \text{ KB} \end{aligned}

Given the following block access sequence:

1,2,4,6,1,2,4,2,4,3,51, 2, 4, 6, 1, 2, 4, 2, 4, 3, 5

Find the number of misses with (assume LRU is used as the replacement policy):

  • fully associative mapping, consisting of 4 one-word blocks, given the following sequence of block addresses
  • Direct Mapping, consisting of 4 one-word blocks
  • 2-way set associative mapping, consisting of 4 one-word blocks
Solution: Fully Associative Mapping

Fully associative example: cache state after processing sequence, showing evicted blocks with strikethrough

××××××12461242435    6 misses\begin{array}{ccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} \\ 1 & 2 & 4 & 6 & 1 & 2 & 4 & 2 & 4 & 3 & 5 \end{array} \;\longrightarrow\; \textbf{6 misses}
Solution: Direct Mapping

Each block maps to line: (block#)mod4\quad (\text{block\#}) \bmod 4.

Direct mapping example: cache state after processing sequence, showing evicted blocks with strikethrough

×××××××12461242435    7 misses\begin{array}{ccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} \\ 1 & 2 & 4 & 6 & 1 & 2 & 4 & 2 & 4 & 3 & 5 \end{array} \;\longrightarrow\; \textbf{7 misses}
Solution: 2-way set associative mapping

2-way set associative mapping     \implies 2 lines per set

Given: 4 lines and 2-way     \implies 4/24/2     \implies 2 sets:  S0\ S_0 and S1S_1

block #\# maps to set:  (block#)mod2\ (\text{block\#}) \bmod 2;  LRU within each set.

2-way set associative example: cache state with S0 and S1 set groupings and eviction history

××××××××12461242435    8 misses\begin{array}{ccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} \\ 1 & 2 & 4 & 6 & 1 & 2 & 4 & 2 & 4 & 3 & 5 \end{array} \;\longrightarrow\; \textbf{8 misses}

Given the following block access sequence:

2,3,5,7,1,4,6,9,2,3,5,3,5,4,6,8,0,2,9,72, 3, 5, 7, 1, 4, 6, 9, 2, 3, 5, 3, 5, 4, 6, 8, 0, 2, 9, 7

Find the number of misses with (assume LRU is used as the replacement policy):

  • fully associative mapping, consisting of 8 one-word blocks, given the following sequence of block addresses
  • Direct Mapping, consisting of 8 one-word blocks
  • 2-way set associative mapping, consisting of 8 one-word blocks
Solution: Fully Associative Mapping

Fully associative example: cache state after processing sequence, showing evicted blocks with strikethrough

×××××××××××23571469235354680297    11 misses\begin{array}{cccccccccccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} \\ 2 & 3 & 5 & 7 & 1 & 4 & 6 & 9 & 2 & 3 & 5 & 3 & 5 & 4 & 6 & 8 & 0 & 2 & 9 & 7 \end{array} \;\longrightarrow\; \textbf{11 misses}
Solution: Direct Mapping

Each block maps to line: (block#)mod8\quad (\text{block\#}) \bmod 8.

Direct mapping example: cache state after processing sequence, showing evicted blocks with strikethrough

××××××××××23571469235354680297    10 misses\begin{array}{cccccccccccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} \\ 2 & 3 & 5 & 7 & 1 & 4 & 6 & 9 & 2 & 3 & 5 & 3 & 5 & 4 & 6 & 8 & 0 & 2 & 9 & 7 \end{array} \;\longrightarrow\; \textbf{10 misses}
Solution: 2-way set associative mapping

2-way set associative mapping     \implies 2 lines per set

Given: 8 lines and 2-way     \implies 8/28/2     \implies 4 sets:  S0,S1,S2,S3\ S_0, S_1, S_2, S_3

block #\# maps to set:  (block#)mod4\ (\text{block\#}) \bmod 4;  LRU within each set.

2-way set associative example: cache state with S0-S3 set groupings and eviction history

×××××××××××23571469235354680297    11 misses\begin{array}{cccccccccccccccccccc} \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{red}{\times} & \color{red}{\times} & \color{blue}{\checkmark} & \color{blue}{\checkmark} & \color{blue}{\checkmark} \\ 2 & 3 & 5 & 7 & 1 & 4 & 6 & 9 & 2 & 3 & 5 & 3 & 5 & 4 & 6 & 8 & 0 & 2 & 9 & 7 \end{array} \;\longrightarrow\; \textbf{11 misses}

Assume that main memory accesses take 70 ns and that memory accesses are 36% of all instructions. The following table shows data for the L1 cache attached to processor P1.

ProcessorL1 Miss RateL1 Hit Time
P18.0%0.66 ns
  • Assume that the L1 hit time determines the cycle time for the processor. What is the clock rate?

    Solution Clock rate=10.66 ns1.52 GHz\text{Clock rate} = \frac{1}{0.66\text{ ns}} \approx 1.52\text{ GHz}
  • What is the Average Memory Access Time for the processor (in ns)?

    Solution AMAT=0.66 ns+0.08×70 ns=6.26 ns\text{AMAT} = 0.66\text{ ns} + 0.08 \times 70\text{ ns} = 6.26\text{ ns}
  • Use the AMAT from above to find the average number of cycles for a memory access.

    Solution 6.26 ns0.66 ns9.48 cycles\frac{6.26\text{ ns}}{0.66\text{ ns}} \approx 9.48\text{ cycles}
  • Assuming a base CPI of 1.0 without any memory stalls (for the rest of the instruction types in the program), what is the total average CPI?

    Solution Average CPI=0.64×1+0.36×9.48=4.05\text{Average CPI} = 0.64 \times 1 + 0.36 \times 9.48 = 4.05
  • We will consider the addition of an L2 cache; on a miss, P1 will now first check L2 cache, and only if that is a miss, will then need a main memory access. The L2 miss rate is 50%, and L2 hit time is 5.62ns. What is the AMAT and average CPI with the addition of this L2 cache?

    Solution AMAT=L1 Hit Time+L1 Miss Rate×(L2 Hit Time+L2 Miss Rate×Main Memory Access Time)=0.66 ns+0.08×(5.62 ns+0.50×70 ns)=0.66 ns+0.08×40.62 ns=3.91 ns\begin{aligned} \text{AMAT} &= \text{L1 Hit Time} + \text{L1 Miss Rate} \times (\text{L2 Hit Time} + \text{L2 Miss Rate} \times \text{Main Memory Access Time}) \\ &= 0.66\text{ ns} + 0.08 \times (5.62\text{ ns} + 0.50 \times 70\text{ ns}) \\ &= 0.66\text{ ns} + 0.08 \times 40.62\text{ ns} \\ &= 3.91\text{ ns} \end{aligned} 3.91 ns0.66 ns5.92 cycles\frac{3.91\text{ ns}}{0.66\text{ ns}} \approx 5.92\text{ cycles} Average CPI=0.64×1+0.36×5.92=2.77\text{Average CPI} = 0.64 \times 1 + 0.36 \times 5.92 = 2.77

    CPI improved from 4.05 to 2.77 with the L2 cache added.