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

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

第 1 題18 分

  1. (18%) A memory system is composed of eight banks, and each bank contains 2162^{16} rows. Every DRAM
    row refresh is initiated by a command from the memory controller, and it refreshes a single row in a single
    DRAM bank. Each refresh command keeps the command bus busy for 5ns. We define command bus
    utilization as the fraction of total execution time during which the command bus is occupied.

1.1 (6%) Given that the refresh interval is 64ms, calculate the command bus utilization of refresh
commands. Show your work step-by-step.
1.2 (12%) If 70% of all rows can withstand a refresh interval of 256ms, how does the command bus
utilization of refresh command change? Calculate the reduction (1−newold)(1 - \frac{new}{old}) in bus utilization. Show your
work step-by-step.

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

這一題的完整詳解

1.1

關鍵步驟:

  1. 計算記憶體系統總 Row 數:
    Ntotal=8 banks×216 rows/bank=8×65,536=524,288 rowsN_{\text{total}} = 8 \text{ banks} \times 2^{16} \text{ rows/bank} = 8 \times 65,536 = 524,288 \text{ rows}

  2. 計算在單一刷新週期(64 ms64\text{ ms})內 Command Bus 佔用的總時間:
    Tbusy=Ntotal×5 ns=524,288×5×10−9 s=2.62144 msT_{\text{busy}} = N_{\text{total}} \times 5\text{ ns} = 524,288 \times 5 \times 10^{-9}\text{ s} = 2.62144\text{ ms}

  3. 計算 Command Bus 利用率:
    Utilizationold=TbusyTref=2.62144 ms64 ms=0.04096=4.096%\text{Utilization}_{\text{old}} = \frac{T_{\text{busy}}}{T_{\text{ref}}} = \frac{2.62144\text{ ms}}{64\text{ ms}} = 0.04096 = 4.096\%

【答案】 Command Bus 利用率為 4.096%4.096\%(或 0.040960.04096)。


1.2

關鍵步驟:

  1. 計算單一 Row 的平均刷新次數比例:
    以 256 ms256\text{ ms} 為共同週期計算:

    • 30%30\% 的 Row 仍需每 64 ms64\text{ ms} 刷新一次,週期內需刷新 25664=4\frac{256}{64} = 4 次。
    • 70%70\% 的 Row 可延長至每 256 ms256\text{ ms} 刷新一次,週期內僅需刷新 11 次。

    平均每列在 256 ms256\text{ ms} 內的刷新次數加權值為:
    0.3×4+0.7×1=1.9 次0.3 \times 4 + 0.7 \times 1 = 1.9 \text{ 次}

🔒

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

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

免費註冊

第 2 題14 分

  1. (14%) Assume we have a virtual memory detailed as follows:
    • 256 MiB Physical Address Space
    • 4 GiB Virtual Address Space
    • 1 KiB page size
    • A TLB with 4 sets that is 8-way associative with LRU replacement

2.1 (10%) How many bits will be used for page offset, Virtual Page Number (VPN), Physical Page Number (PPN), TLB index, and TLB tag?
2.2 (4%) How many entries are in this page table?

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

這一題的完整詳解

核心觀念

虛擬記憶體位址可分為:

Virtual Address=VPN+Page Offset\text{Virtual Address}=\text{VPN}+\text{Page Offset}

實體記憶體位址可分為:

Physical Address=PPN+Page Offset\text{Physical Address}=\text{PPN}+\text{Page Offset}

其中:

  • Page Offset:頁面內的位移,取決於頁面大小。
  • VPN(Virtual Page Number):虛擬頁編號。
  • PPN(Physical Page Number):實體頁框編號。
  • TLB index:決定查詢哪一個 TLB set。
  • TLB tag:在該 set 中比對的標籤,通常由 VPN 扣除 index bits 得到。

TLB 為 4 sets、8-way associative,因此總共有:

4×8=324\times 8=32

個 TLB entries。LRU 只影響替換順序,不影響位元數計算。

解題方法

先將所有容量寫成 22 的次方,再依序計算頁面位移、VPN、PPN,以及 TLB 的 index 與 tag。

1. Page Offset bits

頁面大小為 1 KiB1\ \mathrm{KiB}:

1 KiB=210 bytes1\ \mathrm{KiB}=2^{10}\ \mathrm{bytes}

因此頁面內位移需要:

10 bits\boxed{10\ \mathrm{bits}}

2. Virtual Page Number(VPN)bits

虛擬位址空間為 4 GiB4\ \mathrm{GiB}:

4 GiB=22×230=232 bytes4\ \mathrm{GiB}=2^2\times 2^{30}=2^{32}\ \mathrm{bytes}

虛擬位址總長度為 3232 bits。扣除 1010 bits 的 page offset:

VPN bits=32−10=22\text{VPN bits}=32-10=22

因此:

VPN=22 bits\boxed{\text{VPN}=22\ \mathrm{bits}}

虛擬頁面的總數也就是:

232210=222\frac{2^{32}}{2^{10}}=2^{22}

3. Physical Page Number(PPN)bits

實體位址空間為 256 MiB256\ \mathrm{MiB}:

256 MiB=28×220=228 bytes256\ \mathrm{MiB}=2^8\times 2^{20}=2^{28}\ \mathrm{bytes}

實體位址長度為 2828 bits。扣除 1010 bits 的 page offset:

PPN bits=28−10=18\text{PPN bits}=28-10=18

因此:

PPN=18 bits\boxed{\text{PPN}=18\ \mathrm{bits}}

4. TLB index bits

TLB 有 4 個 sets,因此 index 需要能表示 4 種 set:

TLB index bits=log⁡24=2\text{TLB index bits}=\log_2 4=2

因此:

TLB index=2 bits\boxed{\text{TLB index}=2\ \mathrm{bits}}

5. TLB tag bits

TLB 通常以 VPN 查詢。VPN 中有 22 bits 用作 set index,其餘位元作為 tag:

TLB tag bits=22−2=20\text{TLB tag bits}=22-2=20

因此:

TLB tag=20 bits\boxed{\text{TLB tag}=20\ \mathrm{bits}}

TLB 位址欄位可表示為:

VPN tag⏟20 bitsTLB index⏟2 bits\underbrace{\text{VPN tag}}_{20\ \mathrm{bits}} \quad \underbrace{\text{TLB index}}_{2\ \mathrm{bits}}

page offset 不參與 TLB set 的選擇與 tag 比對。

2.1 位元數整理

欄位計算方式位元數
Page Offsetlog⁡2(1 KiB)=log⁡2210\log_2(1\ \mathrm{KiB})=\log_2 2^{10}10\boxed{10}
VPN32−1032-1022\boxed{22}
PPN28−1028-1018\boxed{18}
TLB indexlog⁡24\log_2 42\boxed{2}
TLB tag22−222-220\boxed{20}
🔒

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

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

免費註冊

第 3 題18 分

  1. (18%) Assume a machine with a 7-stage pipeline. Assume that branches are resolved in the sixth stage. Assume that 20% of instructions are branches.
    3.1 (4%) How many instructions of wasted work are there per branch misprediction on this machine?
    3.2 (4%) Assume N instructions are on the correct path of a program and assume a branch predictor accuracy of A. Write the equation for the number of instructions that are fetched on this machine in terms of N and A. (Show your work step-by-step)
    3.3 (4%) Let's say we modify the machine so that it uses dual path execution (where an equal number of instructions are fetched from each of the two branch paths). Assume branches are resolved before new branches are fetched. Write how many instructions would be fetched in this case, as a function of N. (Show your work step by step)
    3.4 (6%) Now let's say that the machine combines branch prediction and dual path execution in the following way: A branch confidence estimator is used to gauge how confident the machine is of the prediction made for a branch. When confidence in a prediction is high, the branch predictor's prediction is used to fetch the next instruction; when confidence in a prediction is low, dual path execution is used instead. Assume that the confidence estimator estimates a fraction C of the branch predictions have high confidence, and that the probability that the confidence estimator is wrong in its high confidence estimation is M. Write how many instructions would be fetched in this case, as a function of N, A, C, and M. (Show your work step by step)

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

這一題的完整詳解

3.1

解題觀念
在管線化處理器中,分支指令在第 6 階段(Stage 6)完成解析前,前端每個週期持續擷取後續指令。若發生分支預測錯誤(Misprediction),在該分支之後進入管線的指令皆屬於錯誤路徑,必須全部清空(Flush),這些指令即為被浪費的工作(Wasted work)。

推導步驟

  1. 分支指令於第 1 階段擷取,至第 6 階段解析完成。
  2. 在分支指令進入第 2 至第 6 階段期間,管線依序接續擷取了 6−1=56 - 1 = 5 個後續指令。
  3. 當分支預測錯誤時,這 5 個指令皆須丟棄,故每次預測錯誤所浪費的指令數為 5 個。

【答案】5(或 5 個指令)


3.2

解題觀念
總擷取指令數(Total fetched instructions)等於程式正確路徑上的指令數,加上因分支預測錯誤而在錯誤路徑上額外擷取的指令數。

推導步驟

  1. 正確路徑上的指令總數為 NN。
  2. 題目給定分支指令佔總指令數的 20%,故正確路徑上的分支指令數為 0.2N0.2N。
  3. 分支預測正確率為 AA,則預測錯誤率為 1−A1 - A,預測錯誤的分支數為 0.2N(1−A)0.2N(1 - A)。
  4. 承 3.1,每次預測錯誤會在錯誤路徑上額外擷取 5 個指令,故因預測錯誤額外擷取的指令總數為:
    5×0.2N(1−A)=N(1−A)5 \times 0.2N(1 - A) = N(1 - A)
  5. 總擷取指令數 NfetchN_{\text{fetch}} 為:
    Nfetch=N+N(1−A)=N(2−A)N_{\text{fetch}} = N + N(1 - A) = N(2 - A)

【答案】N(2−A)N(2 - A)(或 N+N(1−A)N + N(1 - A))


3.3

解題觀念
雙路徑執行(Dual Path Execution)在遇到分支指令時,同時從跳躍(Taken)與不跳躍(Not-Taken)兩條路徑擷取等量指令。題目假設「在既有分支解析完成前,不會擷取新的分支」(Assume branches are resolved before new branches are fetched),此設定保證管線在執行雙路徑期間不會遭遇次級分支,避免了路徑呈指數級爆炸(Path explosion),使每個分支皆維持嚴格的雙路徑擷取。

推導步驟

  1. 正確路徑上的指令總數為 NN,其中包含 0.2N0.2N 個分支指令。
  2. 對於每一個分支指令,在第 6 階段解析完成前(需歷經 5 個週期),雙路徑執行會同時從正確路徑與錯誤路徑各擷取 5 個指令。
  3. 因此,無論該分支最終走向為何,每個分支指令皆固定在錯誤路徑上額外擷取 5 個指令。
  4. 全程式因雙路徑執行額外擷取的錯誤路徑指令總數為:
    0.2N×5=N0.2N \times 5 = N
  5. 總擷取指令數 NfetchN_{\text{fetch}} 為正確路徑指令數加上錯誤路徑額外擷取數:
    Nfetch=N+N=2NN_{\text{fetch}} = N + N = 2N

【答案】2N2N


3.4

解題觀念
處理器結合分支信心估計器(Confidence Estimator)與雙路徑執行:

  • 高信心分支:信任分支預測器,走單路徑執行;
🔒

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

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

免費註冊

第 4 題14 分

  1. (14%) Suppose that (after optimization) a typical n-instruction program requires an additional 0.4n NOP instructions to correctly handle data hazards.
    4.1 (4%) Suppose that the cycle time of this pipeline without forwarding is 250 ps. Suppose also that adding forwarding hardware will reduce the number of NOPs from 0.4
    n to 0.05n, but increase the cycle time to 300 ps. What is the speedup of this new pipeline compared to the one without forwarding?
    4.2 (4%) Can a program with only 0.075
    n NOPs possibly run faster on the pipeline with forwarding? Explain why or why not.
    4.3. (6%) At minimum, how many NOPs (as a percentage of code instructions) must a program have before it can possibly run faster on the pipeline with forwarding?

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

這一題的完整詳解

核心觀念

本題考查計算機結構中的管線效能評估(Pipeline Performance Evaluation)、資料冒險(Data Hazards)​與前推技術(Forwarding / Bypassing)​對時脈週期時間(Clock Cycle Time, CCT)與執行時間(Execution Time)之權衡(Trade-off):

  1. 程式執行時間公式:

    CPU Execution Time=Total Cycles×Clock Cycle Time (CCT)\text{CPU Execution Time} = \text{Total Cycles} \times \text{Clock Cycle Time (CCT)}

    在單發射管線架構的理想穩定狀態下,每執行一條有效指令或停頓(NOP)耗費 1 個時脈週期(CPI = 1)。因此,若一個含有 nn 條指令的程式需插入 NOP\text{NOP} 個空指令以解決資料冒險,其總執行週期數為:

    Total Cycles=n+NOP\text{Total Cycles} = n + \text{NOP}

    總執行時間為:

    Execution Time=(n+NOP)×CCT\text{Execution Time} = (n + \text{NOP}) \times \text{CCT}
  2. 加速比(Speedup):

    Speedup=Execution Timewithout forwardingExecution Timewith forwarding\text{Speedup} = \frac{\text{Execution Time}_{\text{without forwarding}}}{\text{Execution Time}_{\text{with forwarding}}}
  3. 前推硬體的設計權衡(Trade-off):

    • 增加前推硬體能透過旁路(Bypass)線路與多工器直接傳遞資料,有效減少管線停頓所產生的 NOP 指令數量。
    • 然而,前推電路會增加關鍵路徑(Critical Path)的延遲,導致時脈週期時間(CCT)由 250 ps250\text{ ps} 延長至 300 ps300\text{ ps}(增加了 20%20\%)。
    • 只有當前推硬體所縮減的週期數效益足以克服週期時間增加的代價時,整體程式執行才會獲得加速。

子題詳解與推導

4.1 加速比(Speedup)計算

  1. 無前推管線(Without Forwarding):

    • 時脈週期時間:CCTno_fwd=250 ps\text{CCT}_{\text{no\_fwd}} = 250\text{ ps}
    • NOP 數量:0.4n0.4n
    • 總執行週期數:n+0.4n=1.4nn + 0.4n = 1.4n
    • 總執行時間: Tno_fwd=1.4n×250 ps=350n psT_{\text{no\_fwd}} = 1.4n \times 250\text{ ps} = 350n\text{ ps}
  2. 具前推管線(With Forwarding):

    • 時脈週期時間:CCTfwd=300 ps\text{CCT}_{\text{fwd}} = 300\text{ ps}
    • NOP 數量:0.05n0.05n
    • 總執行週期數:n+0.05n=1.05nn + 0.05n = 1.05n
    • 總執行時間: Tfwd=1.05n×300 ps=315n psT_{\text{fwd}} = 1.05n \times 300\text{ ps} = 315n\text{ ps}
  3. 加速比(Speedup):

    Speedup=Tno_fwdTfwd=350n ps315n ps=350315=109≈1.1111\text{Speedup} = \frac{T_{\text{no\_fwd}}}{T_{\text{fwd}}} = \frac{350n\text{ ps}}{315n\text{ ps}} = \frac{350}{315} = \frac{10}{9} \approx 1.1111

    即新管線相較於無前推管線具有約 1.111.11 倍的加速比(效能提升約 11.11%11.11\%)。

【答案】109\frac{10}{9}(或約 1.111.11)


4.2 僅含 0.075n0.075n 個 NOP 的程式是否可能在具前推管線上執行得更快

  1. 無前推管線之執行時間:
    若該程式在無前推管線上僅需要 0.075n0.075n 個 NOP,其總執行時間為:

    Tno_fwd=(n+0.075n)×250 ps=1.075n×250 ps=268.75n psT_{\text{no\_fwd}} = (n + 0.075n) \times 250\text{ ps} = 1.075n \times 250\text{ ps} = 268.75n\text{ ps}
  2. 具前推管線的理論最快執行時間:
    在具前推機制的管線上,時脈週期時間延長為 300 ps300\text{ ps}。即使前推硬體能完美消除該程式的所有資料相依(即 NOP 數量降為理論極限值 00),該程式的執行週期數最少仍需 nn 個週期,其最短執行時間為:

🔒

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

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

免費註冊

其他考古題