113 年 國立中山大學資訊工程學系碩士班甲組《計算機結構》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題8 分

(8% total) When parallelizing an application, the ideal speedup is speeding up by the number of processors. This is limited by two things: percentage of the application that can be parallelized and the cost of communication. If 80% of the application is parallelizable, answer the following questions.
1.1 (4%) What is the speedup with 8 processors, ignoring the cost of communication?
1.2 (4%) What is the speedup with 8 processors if, for every time the number of processors is doubled, the communication overhead is increased by 0.5% of the original execution time?

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題的核心考點為平行計算架構中的阿姆達爾定律(Amdahl's Law)​以及通訊開銷(Communication Overhead)對平行加速效能的影響。

  1. 阿姆達爾定律(Amdahl's Law):
    定義加速比(Speedup)為單一處理器之執行時間(T1T_1)與 pp 個處理器平行執行時間(TpT_p)的比值:
    Speedup=ToriginalTparallel=T1Tp\text{Speedup} = \frac{T_{\text{original}}}{T_{\text{parallel}}} = \frac{T_1}{T_p}
    若程式中可平行化比例為 ff,不可平行化(循序執行)比例為 1−f1 - f,在忽略通訊與同步開銷的情況下:
    Tp=T1×((1−f)+fp)T_p = T_1 \times \left( (1 - f) + \frac{f}{p} \right)
    Speedup=1(1−f)+fp\text{Speedup} = \frac{1}{(1 - f) + \dfrac{f}{p}}

  2. 納入通訊開銷之平行執行時間:
    當考量通訊額外開銷(TcommT_{\text{comm}})時,總平行執行時間變為:
    Tp=T1×((1−f)+fp)+TcommT_p = T_1 \times \left( (1 - f) + \frac{f}{p} \right) + T_{\text{comm}}
    加速比則修正為:
    Speedup=T1Tp=1(1−f)+fp+TcommT1\text{Speedup} = \frac{T_1}{T_p} = \frac{1}{(1 - f) + \dfrac{f}{p} + \dfrac{T_{\text{comm}}}{T_1}}


解題方法

令單一處理器的原始執行時間為基準 T1=1T_1 = 1。
已知可平行化比例 f=80%=0.8f = 80\% = 0.8,循序比例 1−f=20%=0.21 - f = 20\% = 0.2,處理器個數 p=8p = 8。

1.1 計算忽略通訊成本時的加速比(p=8p = 8)

  1. 計算平行執行時間 T8T_8:
    T8=T1×((1−f)+f8)=T1×(0.2+0.88)=T1×(0.2+0.1)=0.3×T1T_8 = T_1 \times \left( (1 - f) + \frac{f}{8} \right) = T_1 \times \left( 0.2 + \frac{0.8}{8} \right) = T_1 \times (0.2 + 0.1) = 0.3 \times T_1

  2. 計算加速比:
    Speedup=T1T8=10.3=103≈3.33\text{Speedup} = \frac{T_1}{T_8} = \frac{1}{0.3} = \frac{10}{3} \approx 3.33


1.2 計算加入通訊開銷時的加速比(p=8p = 8)

  1. 計算處理器數量倍增次數:
    處理器數量從 11 增長至 88,每次加倍為一個增量週期:
    1→第 1 次2→第 2 次4→第 3 次81 \xrightarrow{\text{第 1 次}} 2 \xrightarrow{\text{第 2 次}} 4 \xrightarrow{\text{第 3 次}} 8
    倍增次數為 log⁡2(8)=3\log_2(8) = 3 次。

  2. 計算總通訊開銷 TcommT_{\text{comm}}:
    題目定義「每倍增一次處理器數量,通訊開銷增加原始執行時間的 0.5%0.5\%」:

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題8 分

(8% total) Assume a hypothetical GPU with the following characteristics:
■ Clock rate 2.0 GHz
■ Contains 16 SIMD processors, each containing 16 single-precision floating-point units
■ Has 600 GB/sec off-chip memory bandwidth
2.1 (4%) Without considering memory bandwidth, what is the peak single-precision floating-point throughput for this GPU in GFLOPS/sec, assuming that all memory latencies can be hidden?
2.2 (4%) Is this throughput sustainable given the memory bandwidth limitation? Please explain your reasons clearly.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查兩個概念:

  1. GPU 的峰值浮點吞吐量
    計算所有可同時工作的浮點單元數,再乘上時脈頻率。

  2. 記憶體頻寬限制與算術強度(Arithmetic Intensity)
    算術強度定義為:

    AI=浮點運算次數從 off-chip memory 搬移的位元組數AI=\frac{\text{浮點運算次數}}{\text{從 off-chip memory 搬移的位元組數}}

    GPU 的實際效能受下式限制:

    Pactual≤min⁡(Pcompute, Bmemory×AI)P_{\text{actual}}\leq \min\left(P_{\text{compute}},\ B_{\text{memory}}\times AI\right)

    即使記憶體延遲能完全隱藏,有限的記憶體頻寬仍可能限制吞吐量。

解題方法

2.1 峰值單精度浮點吞吐量

GPU 中的單精度浮點單元總數為:

16 個 SIMD processors×16 個浮點單元=256 個浮點單元16\ \text{個 SIMD processors}\times 16\ \text{個浮點單元}=256\ \text{個浮點單元}

時脈頻率為:

2.0 GHz=2.0×109 cycles/sec2.0\ \text{GHz}=2.0\times 10^9\ \text{cycles/sec}

在每個浮點單元每個 clock 完成 1 次浮點運算的假設下:

Pcompute=256×2.0×109=512×109 FLOP/secP_{\text{compute}} =256\times 2.0\times 10^9 =512\times 10^9\ \text{FLOP/sec}

因此:

Pcompute=512 GFLOPSP_{\text{compute}}=512\ \text{GFLOPS}

2.2 記憶體頻寬是否足以維持此吞吐量

要維持 512 GFLOPS512\ \text{GFLOPS},所需的最低算術強度為:

AIbreak-even=512 GFLOPS600 GB/sec=512600≈0.853 FLOP/byteAI_{\text{break-even}} =\frac{512\ \text{GFLOPS}}{600\ \text{GB/sec}} =\frac{512}{600} \approx 0.853\ \text{FLOP/byte}

因此:

  • 若 AI≥0.853 FLOP/byteAI\geq 0.853\ \text{FLOP/byte},記憶體頻寬足以支撐計算單元達到 512 GFLOPS512\ \text{GFLOPS}。
  • 若 AI<0.853 FLOP/byteAI<0.853\ \text{FLOP/byte},效能會受記憶體頻寬限制,無法達到峰值。

題目未提供實際程式的資料搬移量,因此嚴格而言缺少算術強度,無法對所有程式給出唯一的「是」或「否」。依考題常見的無資料重用、每次浮點運算都需要搬移一個新的單精度值之假設:

單精度數值占 44 bytes,因此:

AI=1 FLOP4 bytes=0.25 FLOP/byteAI=\frac{1\ \text{FLOP}}{4\ \text{bytes}}=0.25\ \text{FLOP/byte}

此時記憶體頻寬所能支撐的最高計算吞吐量為:

Pmemory=600 GB/sec×0.25 FLOP/byte=150 GFLOPSP_{\text{memory}} =600\ \text{GB/sec}\times 0.25\ \text{FLOP/byte} =150\ \text{GFLOPS}

150 GFLOPS150\ \text{GFLOPS} 小於計算單元的峰值 512 GFLOPS512\ \text{GFLOPS},所以在此假設下無法維持峰值吞吐量。

等價地說,若要維持 512 GFLOPS512\ \text{GFLOPS},即使每個 FLOP 只需搬移一個 44-byte 單精度值,也需要:

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題18 分

(18% total) Assume that individual stages of the datapath have the following latencies, and instructions executed by the processor are broken down as the following percentages:
IF
ID
EX
MEM
WB
250 ps
150 ps
350 ps
300 ps
200 ps
alu
45%
beq
lw
SW
10%
25%
20%
3.1 (4%) What is the clock cycle time in a non-pipelined and pipelined processor, respectively?
3.2 (4%) What is the individual total latency of the following two instructions: lw, beq in a non-pipelined and pipelined processor?
3.3 (6%) Assuming there are no stalls or hazards, what is the total execution time of the following four instructions: lw, sw, add, beq in a non-pipelined and pipelined processor, respectively?
3.4 (4%) Assuming there are no stalls or hazards, what is the utilization of the data memory and the write-register port of the "Register" unit?

登入後即可作答並保存紀錄。

這一題的完整詳解

3.1 時脈週期時間 (Clock Cycle Time)

  1. 非流水線處理器 (Non-pipelined / Single-cycle):
    時脈週期時間由執行時間最長的指令(即經過全部 5 個階段的 lw 指令)決定:
    Cycle Time=IF+ID+EX+MEM+WB=250+150+350+300+200=1250 ps\text{Cycle Time} = \text{IF} + \text{ID} + \text{EX} + \text{MEM} + \text{WB} = 250 + 150 + 350 + 300 + 200 = 1250\text{ ps}

  2. 流水線處理器 (Pipelined):
    時脈週期時間由延遲最長的單一階段(EX 階段)決定:
    Cycle Time=max⁡(IF,ID,EX,MEM,WB)=350 ps\text{Cycle Time} = \max(\text{IF}, \text{ID}, \text{EX}, \text{MEM}, \text{WB}) = 350\text{ ps}

【答案】非流水線處理器為 1250 ps1250\text{ ps};流水線處理器為 350 ps350\text{ ps}。


3.2 個別指令總延遲 (Individual Total Latency)

  1. 非流水線處理器:
    單一時脈週期架構下,時脈週期固定為 1250 ps1250\text{ ps},故每筆指令執行時間皆佔據一個完整時脈週期 1250 ps1250\text{ ps}(若按硬體實際經過的階段延遲,lw 為 1250 ps1250\text{ ps},beq 為 IF+ID+EX=250+150+350=750 ps\text{IF} + \text{ID} + \text{EX} = 250 + 150 + 350 = 750\text{ ps})。

  2. 流水線處理器:
    所有指令在流水線中皆須通過 5 個 pipeline 階段,總延遲為:
    Latency=5×350 ps=1750 ps\text{Latency} = 5 \times 350\text{ ps} = 1750\text{ ps}
    因此 lw 與 beq 的總延遲皆為 1750 ps1750\text{ ps}。

【答案】

  • 非流水線處理器:lw 為 1250 ps1250\text{ ps};beq 為 1250 ps1250\text{ ps}(硬體路徑延遲為 750 ps750\text{ ps})。
  • 流水線處理器:lw 為 1750 ps1750\text{ ps};beq 為 1750 ps1750\text{ ps}。

3.3 四筆指令總執行時間 (Total Execution Time)

  1. 非流水線處理器:
    執行 4 筆指令需要 4 個時脈週期:
    Total Time=4×1250 ps=5000 ps\text{Total Time} = 4 \times 1250\text{ ps} = 5000\text{ ps}
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題15 分

(15% total) The importance of having a good branch predictor depends on how often conditional branches are executed. Together with branch predictor accuracy, this will determine how much time is spent stalling due to mispredicted branches. Assume that the breakdown of dynamic instructions into various instruction categories is as follows:
R-Type
40%
BEQ
20%
JMP
5%
LW
25%
SW
10%
Also, assume the following branch predictor accuracies:
Always-Taken
40%
Always-Not-Taken
60%
2-Bit
80%
4.1 (5%) Assume no stall cycle is required when branch prediction is correct. Stall cycles due to mispredicted branches increase the CPI. What is the extra CPI due to mispredicted branches with the always-taken predictor? Assume that branch outcomes are determined in the EX stage of a basic 5-stage pipelined processor, that there are no data hazards, and that no delay slots are used.
4.2 (5%) Repeat 4.1 for the 2-bit predictor.
4.3 (5%) With the always-taken predictor, what speedup would be achieved if we could convert half of the branch instructions in a way that replaces a branch instruction with an ALU instruction? Assume that correctly and incorrectly predicted instructions have the same chance of being replaced.

登入後即可作答並保存紀錄。

這一題的完整詳解

觀念與前提設定

  • 條件分歧指令(BEQ)比例:20%20\%
  • 分支預測錯誤懲罰(Penalty):在傳統 5 階段 Pipeline(IF, ID, EX, MEM, WB)中,若分支結果於 EX 階段(第 3 階段)確定,預測錯誤時需 Flush 已進入 IF 與 ID 階段的 2 個指令,懲罰時間為 22 個 Clock Cycles。
  • 基礎 CPI:無任何 Hazard 下之理想 CPI 為 1.01.0。

4.1

使用 Always-Taken 預測器,正確率為 40%40\%,預測錯誤率(Misprediction Rate)為 1−40%=60%1 - 40\% = 60\%。

預測錯誤導致的額外 CPI(Extra CPI)計算如下:
Extra CPI=BEQ Frequency×Misprediction Rate×Penalty Cycles\text{Extra CPI} = \text{BEQ Frequency} \times \text{Misprediction Rate} \times \text{Penalty Cycles}
Extra CPI=0.20×(1−0.40)×2=0.20×0.60×2=0.24\text{Extra CPI} = 0.20 \times (1 - 0.40) \times 2 = 0.20 \times 0.60 \times 2 = 0.24

【答案】0.240.24


4.2

使用 2-Bit 預測器,正確率為 80%80\%,預測錯誤率為 1−80%=20%1 - 80\% = 20\%。

額外 CPI 計算如下:
Extra CPI=0.20×(1−0.80)×2=0.20×0.20×2=0.08\text{Extra CPI} = 0.20 \times (1 - 0.80) \times 2 = 0.20 \times 0.20 \times 2 = 0.08

【答案】0.080.08


4.3

將半數條件分歧指令替換為普通 ALU 指令:

  • 原系統總 CPI:CPIorig=Base CPI+Extra CPIorig=1.0+0.24=1.24\text{CPI}_{\text{orig}} = \text{Base CPI} + \text{Extra CPI}_{\text{orig}} = 1.0 + 0.24 = 1.24
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題15 分

  1. (15% total) 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.
    3, 180, 43, 2, 191, 88, 190, 14, 181, 44, 186, 253
    5.1 (9%) For each of these references, identify the binary address, the tag, and the index given a direct-mapped cache with two-word blocks and a total size of 8 blocks. Also list if each reference is a hit or a miss, assuming the cache is initially empty.
Word AddressBinary AddressTagIndexHit/Miss
30000 001103Miss
180
43
2
191
...
181
44
186
253

5.2 (6%) How many total bits are required for a direct-mapped cache with 32 KiB of data, 8-word blocks, and 32-bit address?

登入後即可作答並保存紀錄。

這一題的完整詳解

5.1 快取記憶體存取追蹤分析

1. 快取結構與位址分割

依題意,快取組織為 Direct-Mapped Cache:

  • 區塊大小 (Block Size):2 words2\text{ words},因此每個區塊需要 log⁡2(2)=1 bit\log_2(2) = 1\text{ bit} 作為 Block Offset(區塊內字組偏移量)。
  • 區塊總數 (Number of Blocks):8 blocks8\text{ blocks},因此快取索引需要 log⁡2(8)=3 bits\log_2(8) = 3\text{ bits} 作為 Index(範圍 0∼70 \sim 7)。
  • 位址表示與欄位切割:
    題目給定為 Word Address,參照題目表格範例使用 8-bit 二進位表示(因為給定數列最大值 253<28253 < 2^8):
    • Block Offset (最低 1 位元):bit [0]=Word Address(mod2)\text{bit } [0] = \text{Word Address} \pmod 2
    • Index (中間 3 位元):bit [3:1]=(Word Address≫1)(mod8)\text{bit } [3:1] = (\text{Word Address} \gg 1) \pmod 8
    • Tag (高位元):bit [7:4]=Word Address≫4\text{bit } [7:4] = \text{Word Address} \gg 4(若以 32-bit word address 表示則為高 28 位元)。

註(題目表格範例之印刷勘誤):
題目表格第一列範例給出 Word Address 3 之 Binary Address=0000 0011\text{Binary Address} = 0000\ 0011、Tag=0\text{Tag} = 0、Index=3\text{Index} = 3。此處 Index 印為 3 顯係印刷筆誤(誤套用 1-word block 下 3(mod8)=33 \pmod 8 = 3 之結果)。在題幹指定的 2-word block 下,Word 3 與 Word 2 同屬 Block Address 3//2=13 // 2 = 1,映射至 Index=1(mod8)=1\text{Index} = 1 \pmod 8 = 1。以下依題意標準規格(2-word block, 8 blocks)進行完整推導,文末亦附上若出題者依範例筆誤計算之對照。

2. 各筆位址存取追蹤過程(初始快取為空)

  1. Word Address = 3 (0000 001120000\ 0011_2):
    • Offset: 11,Index: 0012001_2 (11),Tag: 000020000_2 (00)
    • 狀態:Miss(將 Block 1 載入 Tag 0,包含 Word 2 與 3)
  2. Word Address = 180 (1011 010021011\ 0100_2):
    • Offset: 00,Index: 0102010_2 (22),Tag: 101121011_2 (1111)
    • 狀態:Miss(將 Block 2 載入 Tag 11,包含 Word 180 與 181)
  3. Word Address = 43 (0010 101120010\ 1011_2):
    • Offset: 11,Index: 1012101_2 (55),Tag: 001020010_2 (22)
    • 狀態:Miss(將 Block 5 載入 Tag 2,包含 Word 42 與 43)
  4. Word Address = 2 (0000 001020000\ 0010_2):
    • Offset: 00,Index: 0012001_2 (11),Tag: 000020000_2 (00)
    • 狀態:Hit(Block 1 內已有 Tag 0)
  5. Word Address = 191 (1011 111121011\ 1111_2):
    • Offset: 11,Index: 1112111_2 (77),Tag: 101121011_2 (1111)
    • 狀態:Miss(將 Block 7 載入 Tag 11,包含 Word 190 與 191)
  6. Word Address = 88 (0101 100020101\ 1000_2):
    • Offset: 00,Index: 1002100_2 (44),Tag: 010120101_2 (55)
    • 狀態:Miss(將 Block 4 載入 Tag 5,包含 Word 88 與 89)
  7. Word Address = 190 (1011 111021011\ 1110_2):
    • Offset: 00,Index: 1112111_2 (77),Tag: 101121011_2 (1111)
    • 狀態:Hit(Block 7 內已有 Tag 11)
  8. Word Address = 14 (0000 111020000\ 1110_2):
    • Offset: 00,Index: 1112111_2 (77),Tag: 000020000_2 (00)
    • 狀態:Miss(替換 Block 7,改存 Tag 0,包含 Word 14 與 15)
  9. Word Address = 181 (1011 010121011\ 0101_2):
    • Offset: 11,Index: 0102010_2 (22),Tag: 101121011_2 (1111)
    • 狀態:Hit(Block 2 內已有 Tag 11)
  10. Word Address = 44 (0010 110020010\ 1100_2):
    • Offset: 00,Index: 1102110_2 (66),Tag: 001020010_2 (22)
    • 狀態:Miss(將 Block 6 載入 Tag 2,包含 Word 44 與 45)
  11. Word Address = 186 (1011 101021011\ 1010_2):
    • Offset: 00,Index: 1012101_2 (55),Tag: 101121011_2 (1111)
    • 狀態:Miss(替換 Block 5,改存 Tag 11,包含 Word 186 與 187)
  12. Word Address = 253 (1111 110121111\ 1101_2):
    • Offset: 11,Index: 1102110_2 (66),Tag: 111121111_2 (1515)
    • 狀態:Miss(替換 Block 6,改存 Tag 15,包含 Word 252 與 253)

3. 彙總結果表

Word AddressBinary AddressTag (Decimal / Binary)Index (Decimal / Binary)Hit / Miss
30000 00110 (0000)1 (001)Miss
1801011 010011 (1011)2 (010)Miss
430010 10112 (0010)5 (101)Miss
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 6 題16 分

(16% total) Assume that the CPI with a perfect cache is 2.0, the clock cycle time is 1.0 ns, there are 1.5 memory references per instruction, the size of both caches is 64 KB, and both have a block size of 64 bytes. One cache is direct mapped and the other is two-way set associative. Since the speed of the CPU is tied directly to the speed of a cache hit, assume the CPU clock cycle time must be stretched 1.3 times to accommodate the selection multiplexor of the set-associative cache. To the first approximation, the cache miss penalty is 80 ns for either cache organization. Assume the hit time is 1 clock cycle, the miss rate of a direct-mapped 64 KB cache is 1.5%, and the miss rate for a two-way set-associative cache of the same size is 1.1%.
6.1 (8%) Calculate the average memory access time for these two different cache organizations.
6.2 (8%) Calculate the CPU performance in terms of CPU time.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題比較兩種快取組織的兩項指標:

  1. 平均記憶體存取時間:
    AMAT=Hit Time+Miss Rate×Miss Penalty\text{AMAT}=\text{Hit Time}+\text{Miss Rate}\times\text{Miss Penalty}

  2. CPU 執行時間:
    TCPU=Instruction Count×CPI×Clock Cycle TimeT_{\text{CPU}}=\text{Instruction Count}\times\text{CPI}\times\text{Clock Cycle Time}

完美快取下的 CPI=2.0\text{CPI}=2.0 已包含正常快取命中的執行成本,因此只需額外加入快取未命中的停滯時間。

快取總區塊數為:

64 KB64 B=1024 blocks\frac{64\text{ KB}}{64\text{ B}}=1024\text{ blocks}

直接映射快取有 10241024 條快取線;二路組合相聯快取有 512512 個集合,每集合含 22 條快取線。題目已直接給出兩者的 miss rate,因此不必再由位址存取序列推導 miss rate。


6.1 平均記憶體存取時間

直接映射快取

原始時脈週期為:

Tc=1.0 nsT_c=1.0\text{ ns}

命中時間為一個時脈週期:

Thit=1.0 nsT_{\text{hit}}=1.0\text{ ns}

因此:

AMATdirect=Thit+Miss Rate×Miss Penalty=1.0+(0.015)(80)=2.20 ns\begin{aligned} \text{AMAT}_{\text{direct}} &=T_{\text{hit}}+\text{Miss Rate}\times\text{Miss Penalty}\\ &=1.0+(0.015)(80)\\ &=2.20\text{ ns} \end{aligned}

二路組合相聯快取

由於選擇多工器使 CPU 時脈週期延長為原本的 1.31.3 倍:

Tc=1.3×1.0=1.3 nsT_c=1.3\times1.0=1.3\text{ ns}

命中時間為:

Thit=1.3 nsT_{\text{hit}}=1.3\text{ ns}

因此:

AMAT2-way=1.3+(0.011)(80)=1.3+0.88=2.18 ns\begin{aligned} \text{AMAT}_{\text{2-way}} &=1.3+(0.011)(80)\\ &=1.3+0.88\\ &=2.18\text{ ns} \end{aligned}

二路組合相聯快取的 AMAT 為 2.18 ns2.18\text{ ns},略低於直接映射快取的 2.20 ns2.20\text{ ns}。


6.2 CPU 執行時間

設程式共有 II 條指令。每條指令平均有 1.51.5 次記憶體參考,因此每條指令的 miss 次數為:

Misses per Instruction=1.5×Miss Rate\text{Misses per Instruction}=1.5\times\text{Miss Rate}

每條指令的額外 miss 停滯時間為:

額外時間=(1.5)(Miss Rate)(80 ns)\text{額外時間}=(1.5)(\text{Miss Rate})(80\text{ ns})

直接映射快取

每條指令的 miss 次數:

1.5×0.015=0.02251.5\times0.015=0.0225

每條指令的 miss 停滯時間:

0.0225×80=1.8 ns0.0225\times80=1.8\text{ ns}

完美快取下,每條指令的基本執行時間為:

2.0×1.0=2.0 ns2.0\times1.0=2.0\text{ ns}

所以每條指令的平均 CPU 時間為:

Tper instruction=2.0+1.8=3.8 nsT_{\text{per instruction}}=2.0+1.8=3.8\text{ ns}

等效 CPI 為:

CPIdirect=3.8 ns1.0 ns=3.8\text{CPI}_{\text{direct}}=\frac{3.8\text{ ns}}{1.0\text{ ns}}=3.8

因此:

TCPU,direct=3.8I ns\boxed{T_{\text{CPU,direct}}=3.8I\text{ ns}}

二路組合相聯快取

每條指令的 miss 次數:

1.5×0.011=0.01651.5\times0.011=0.0165

每條指令的 miss 停滯時間:

0.0165×80=1.32 ns0.0165\times80=1.32\text{ ns}

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 7 題20 分

(20% total) Consider the virtual memory system.

7.1 (8%) The following list provides parameters of a virtual memory system.

Virtual Address (bits)Physical DRAM InstalledPage SizePTE Size (byte)
4216 GiB4 KiB4

For a single-level page table, how many page table entries (PTEs) are needed? How much physical memory is needed for storing the page table?

7.2 (12%) The following data constitutes a stream of virtual address as seen on a system. Assume 4 KiB pages, a 4-entry fully associative TLB, and true LRU replacement. If pages must be brought in from disk, increment the next largest page number.

TLB

ValidTagPhysical Page Number
11112
174
136
049

Page table

ValidPhysical Page or in Disk
15
0Disk
0Disk
16
19
111
0Disk
14
0Disk
0Disk
13
112

Given the following address stream: 4669, 13916, ..., and the initial TLB and page table states provided above, show the final state of the system. Also list for each reference if it is a hit in the TLB, a hit in the page table, or a page fault.

AddressVirtual PageTLB H/MValidTLB<br>TagPhysical Page Number
4669
13916

登入後即可作答並保存紀錄。

這一題的完整詳解

7.1 單層頁表大小計算

1. 虛擬頁號(VPN)與頁內位移(Offset)位元數

  • 頁面大小(Page Size):
    4 KiB=4×1024 bytes=212 bytes4\text{ KiB} = 4 \times 1024\text{ bytes} = 2^{12}\text{ bytes}
    因此頁內位移(Offset)需要 12 bits。
  • 虛擬位址(Virtual Address):共 42 bits。
  • 虛擬頁號(VPN)位元數:
    VPN bits=42−12=30 bits\text{VPN bits} = 42 - 12 = 30\text{ bits}

2. 單層頁表所需 PTE 數量

在單層頁表(Single-Level Page Table)架構下,虛擬位址空間中的每一個虛擬頁皆對應一個頁表項(Page Table Entry, PTE):
PTE 數量=230 個=1,073,741,824 個(即 1 G 個 PTE)\text{PTE 數量} = 2^{30}\text{ 個} = 1,073,741,824\text{ 個(即 } 1\text{ G 個 PTE)}

3. 儲存頁表所需實體記憶體容量

每個 PTE 大小為 4 bytes:
頁表容量=230×4 bytes=232 bytes=4 GiB\text{頁表容量} = 2^{30} \times 4\text{ bytes} = 2^{32}\text{ bytes} = 4\text{ GiB}

因此,儲存該單層頁表共需 4 GiB 的實體記憶體空間。


7.2 記憶體存取模擬與系統狀態更新

系統參數與初始狀態

  • 頁面大小:4 KiB=4096 bytes4\text{ KiB} = 4096\text{ bytes}。
    VPN=⌊Virtual Address/4096⌋,Offset=Virtual Address mod 4096\text{VPN} = \lfloor \text{Virtual Address} / 4096 \rfloor,\quad \text{Offset} = \text{Virtual Address} \bmod 4096
  • TLB 架構:4-entry 全相聯(Fully Associative),採真實 LRU(True LRU)替換策略。
  • 頁面替換規則:若從磁碟換入頁面,配置下一個最大的實體頁號(Increment the next largest page number)。
  • 初始狀態中,頁表中最大的實體頁號為 12(VPN 11 對應到實體頁 12),因此首次從磁碟換入時分配的實體頁號為 12+1=1312 + 1 = 13。

位址存取逐步分析

Reference 1: Virtual Address = 4669

  1. 計算 VPN 與 Offset:
    4669=1×4096+573  ⟹  VPN=1, Offset=5734669 = 1 \times 4096 + 573 \implies \text{VPN} = 1,\ \text{Offset} = 573
  2. 查詢 TLB:
    初始 TLB 內有效的 Tag 為 {11,7,3}\{11, 7, 3\},不包含 Tag 1。
      ⟹  TLB Miss\implies \mathbf{TLB\ Miss}
  3. 查詢 Page Table:
    查詢 VPN 1 的頁表項,其狀態為 Valid = 0, in Disk。
      ⟹  Page Fault(頁表未命中,發生缺頁)\implies \mathbf{Page\ Fault}\text{(頁表未命中,發生缺頁)}
  4. 處理 Page Fault:
    從磁碟將頁面載入實體記憶體,配置下一個最大實體頁號:
    新分配 Physical Page Number=12+1=13\text{新分配 Physical Page Number} = 12 + 1 = 13
    • 更新 Page Table:VPN 1 設為 Valid = 1, Physical Page = 13。
  5. 更新 TLB:
    TLB 原有一筆無效項目(Entry 3,Valid = 0),直接將新映射填入該空項:
    Entry 3←(Valid=1,Tag=1,Physical Page Number=13)\text{Entry 3} \leftarrow (\text{Valid} = 1, \text{Tag} = 1, \text{Physical Page Number} = 13)
    依 LRU 策略,VPN 1 成為最近存取項(MRU)。

Reference 2: Virtual Address = 13916

  1. 計算 VPN 與 Offset:
    13916=3×4096+1628  ⟹  VPN=3, Offset=162813916 = 3 \times 4096 + 1628 \implies \text{VPN} = 3,\ \text{Offset} = 1628
  2. 查詢 TLB:
    比對 TLB 各項,Entry 2 具備 Valid = 1 且 Tag = 3,比對成功。
      ⟹  TLB Hit\implies \mathbf{TLB\ Hit}
  3. 轉換位址:
    直接自 TLB 取得對應之實體頁號 PPN=6\text{PPN} = 6。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題