109 年 國立中山大學資訊工程學系碩士班甲組《計算機結構》
第 1 題10 分
- (10% total) Assume a 32-bit, byte-addressed machine with virtual addressing. The two high-order bits are 11 is treated as unmapped. These addresses are only accessible by the operating system and bypass virtual address translation. The answers need to express as a multiple of a power of 2, or in terms of KB, MB, GB, or TB as appropriate.
1.1 (2%) What is the maximum amount of physical memory this system can address?
1.2 (2%) What is the maximum amount of virtual memory any single process on this system can address?
1.3 (2%) How many virtual pages are available to each process, assuming 4KB pages?
1.4 (2%) Assume each page table entry is 4 bytes, how much memory would a single-level page table require?
1.5 (2%) Assuming a two-level page table where half the bits of the virtual page number are used to index the first level, and the other half are used to index the second level, how many second-level page tables can a process use if its total page table size is limited to 400KB?
登入後即可作答並保存紀錄。
1.1
在 32-bit 位元組定址(byte-addressed)系統中,實體位址空間為 Bytes:
【答案】 4 GB
1.2
32-bit 虛擬位址空間總大小為 。
題目規定最高 2 bits 為 11 的位址區間(佔整體空間的 ,即 )屬於 unmapped 區域,僅供作業系統使用並繞過虛擬位址轉譯。
因此,單一程序可定址的虛擬記憶體空間為其餘 (最高 2 bits 為 00、01、10):
【答案】 3 GB(或 Bytes)
1.3
分頁大小(Page Size)為 。
單一程序可定址的虛擬記憶體容量為 ,故可用的虛擬分頁數量為:
【答案】 (或 768K 個)
1.4
單層分頁表需為程序可用的每個虛擬分頁配置一個分頁表項(PTE),已知共有 個虛擬分頁,且每個 PTE 大小為 4 Bytes:
【答案】 3 MB
第 2 題15 分
- (15% total) The instruction latency for a given CPU is shown in Table 1.
Table 1.
Instructions | Breakdown | Latency
------------ | --------- | -------
load | 5% | 3 cycles
add | 10% | 5 cycles
divide | 10% | 8 cycles
branch | 50% | 2 cycles
shift left | 15% | 5 cycles
shift right | 10% | 1 cycles
2.1 (3%) Calculate the CPI of the given CPU?
2.2 (4%) Variant 1: All add instructions are replaced with corresponding subtract instructions that take the same amount of time. Calculate the CPI of the Variant 1?
2.3 (4%) Variant 2: Remove the highest-latency instruction, and replace all those instructions with additional latency of three cycles for the lowest latency instruction in the mix. Calculate the CPI of the Variant 2 (relative to the original instruction count)?
2.4 (4%) Variant 3: Reduce the latency for divides by a factor of four, but increase the latencies of branches by 50%. Calculate the CPI of the Variant 3?
登入後即可作答並保存紀錄。
2.1
觀念與推導:
平均每指令週期數(CPI)為各類指令比例(Breakdown)與其執行週期(Latency)之加權總和:
帶入原始數據計算:
【答案】
2.2
觀念與推導:
Variant 1 將所有 add 指令替換為執行時間相同的 subtract 指令(延遲同為 5 cycles),指令比例與對應延遲皆未改變,故 CPI 與原 CPU 相同。
【答案】
2.3
觀念與推導:
- 最高延遲指令:
divide(8 cycles,占比 10%)。 - 最低延遲指令:
shift right(1 cycle)。 - 變更後的指令延遲:原
divide指令(占比 10%)被替換為最低延遲指令加上 3 cycles 的額外延遲,其新延遲為 cycles。 - 計算新 CPI(相對於原始指令數):
第 3 題10 分
- (10% total) A old program needs to be parallelized. Then, it can run faster on modern multicore processors. In order to execute the program with parallel and serial portions more efficiently, a custom heterogeneous processor needs to be designed.
➤ The processor has one large core which executes code more quickly but takes greater die area on-chip, the multiple small cores which execute code more slowly but consume less area, all sharing one processor die.
When program in its parallel portion, all of its threads execute only on small cores.
When program in its serial portion, the one active thread executes on the large core.
Performance (execution speed) of a core is proportional to the square root of its area.
Assume 16 units of die area available. A small core takes 1 unit of die area. The large core can take any number of units of die area n², where n is the positive number. Area not used by the large core will be filled with smaller cores.
The serial portion is only 10% of total work, and the parallel portion is the remaining 90%.
3.1 (5%) What would be the speed up for the fastest possible execution of the program?
3.2 (5%) What would the same program's speedup be if all 16 units of die area were used to build a homogeneous system with 16 small cores, the serial portion ran on one of the small cores, and the parallel portion ran on all 16 small cores?
登入後即可作答並保存紀錄。
3.1 詳解
設單一小核心面積為 ,效能為 。
大型核心佔用面積為 ,效能為 ,剩餘面積可容納的小核心數量為 個。
根據異質多核心架構下之執行時間公式:
欲求最快執行時間(即 之極小值),對 求微分:
解得正整數解 。即大型核心佔用 單位面積,剩餘建構 個小核心。
代回求得最小執行時間:
第 4 題15 分
- (15% total) An 8-bit byte-addressed virtual address space and the physical memory has 128 bytes. Each page contains 16 bytes. A simple, one level translation scheme is used and the page table resides in physical memory. The initial contents of the frames of the physical memory are shown in Table 2.
Table 2.
| Frame Number | Frame Contents |
|---|---|
| 0 | Empty |
| 1 | Page 13 |
| 2 | Page 5 |
| 3 | Page 2 |
| 4 | Empty |
| 5 | Page 0 |
| 6 | Empty |
| 7 | Page Table |
A three-entry translation lookaside buffer (TLB) that uses Least Recently-Used (LRU) replacement is added to this system. Initially, this TLB contains the entries for pages 0, 2, and 13. (Note: LRU is used to select pages for replacement in physical memory.)
References (to pages): 0, 13, 5, 2, 14, 14, 13, 6, 6, 13, 15, 14, 15, 13, 4, 3.
4.1 (4%) What is the hit rate of the TLB for this sequence of references?
4.2 (3%) At the end of this sequence, what three entries are contained in the TLB?
4.3 (8%) What are the contents of the 8 physical frames?
登入後即可作答並保存紀錄。
4.1 TLB Hit Rate
系統包含 3 個 entry 的 TLB,採用 LRU 替換策略。初始內容為 Page 0, 2, 13。
存取序列 (共 16 次) 追蹤過程如下:
- Page 0:Hit (TLB 更新為 ,最右側為 MRU)
- Page 13:Hit (TLB 更新為 )
- Page 5:Miss,剔除 LRU (2),放入 5 (TLB 更新為 )
- Page 2:Miss,剔除 LRU (0),放入 2 (TLB 更新為 )
- Page 14:Miss,剔除 LRU (13),放入 14 (TLB 更新為 )
- Page 14:Hit (TLB 更新為 )
- Page 13:Miss,剔除 LRU (5),放入 13 (TLB 更新為 )
- Page 6:Miss,剔除 LRU (2),放入 6 (TLB 更新為 )
- Page 6:Hit (TLB 更新為 )
- Page 13:Hit (TLB 更新為 )
- Page 15:Miss,剔除 LRU (14),放入 15 (TLB 更新為 )
- Page 14:Miss,剔除 LRU (6),放入 14 (TLB 更新為 )
- Page 15:Hit (TLB 更新為 )
- Page 13:Hit (TLB 更新為 )
- Page 4:Miss,剔除 LRU (14),放入 4 (TLB 更新為 )
- Page 3:Miss,剔除 LRU (15),放入 3 (TLB 更新為 )
總存取次數為 16 次,TLB Hit 次數為 7 次 (第 1, 2, 6, 9, 10, 13, 14 次存取)。
【答案】 (或 )
4.2 TLB 最終內容
依據 4.1 之追蹤結果,在第 16 次存取 (Page 3) 完成後,TLB 中保留的三個頁面為 Page 3, Page 4, Page 13。
【答案】Page 3, Page 4, Page 13
4.3 8 個 Physical Frames 的最終內容
實體記憶體共有 8 個頁框 (Frame 0 ~ 7)。初始時空閒頁框為 Frame 0, 4, 6。當發生 Page Fault 時,優先依序填入空閒頁框;無空閒頁框時,採用 LRU 替換實體頁面。
第 5 題15 分
- (15% total) Assume a machine with a 7-stage pipeline. Assume that branches are resolved in the sixth stage. Assume that 20% of instructions are branches. Answer the following questions.
5.1 (5%) How many instructions of wasted work are there per branch misprediction on this machine?
5.2 (5%) 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.
5.3 (5%) If the machine were modified so that it used the dual path execution (where an equal number of instructions are fetched from each of the two branch paths). Assume that branches are resolved before new branches are fetched. Write how many instructions would be fetched in this case as a function of N.
登入後即可作答並保存紀錄。
5.1
分支指令於第 1 階段擷取(Fetch),並於第 6 階段確定跳躍方向(Resolve)。在第 6 階段解析完成前,管線中位於該分支指令之後已擷取的指令數為:
因此,每次分支預測錯誤會造成 5 個指令的無用工作(須將管線中該 5 個錯誤路徑上的指令清除)。
【答案】 5 個指令
5.2
程式正確執行路徑上的指令總數為 。
- 分支指令數量為 。
- 分支預測錯誤率為 ,預測錯誤的分支次數為 。
- 每次預測錯誤會額外擷取 5 個錯誤路徑的指令。
總擷取指令數為正確路徑指令數加上錯誤路徑擷取數:
【答案】
第 6 題10 分
- (10% total) A byte-addressable system with 16-bit address ships with a three-way set associative, write-back cache. The cache implements a true LRU replacement policy using the minimum number of replacement policy bits necessary to implement it. The tag store requires a total of 264 bits of storage. What is the block size of the cache?
登入後即可作答並保存紀錄。
核心觀念
本題考查快取位址切割與標籤儲存容量計算:
- 位址長度: bits。
- 系統為 byte-addressable,因此位移欄位表示區塊內的「位元組數」。
- 三路組合式快取:每組有 個 cache line。
- Write-back cache 每個 cache line 需要 1 個 dirty bit。
- 每個 cache line 需要 1 個 valid bit。
- 三路 true LRU 的狀態共有 種,因此至少需要
bits,而且這 bits 是每組共用,不是每個 cache line 各有 bits。
解題方法
設:
- 區塊大小為 bytes,因此 block offset 為 bits。
- 組數為 組,因此 set index 為 bits。
- Tag 長度為 bits。
位址切割關係為
所以
三路組合式快取共有
個 cache line。
每個 cache line 的 tag store 儲存:
- Tag: bits
- Valid bit: bit
- Dirty bit: bit
因此每個 cache line 需要
bits。
所有 cache line 的儲存量為
每組的 LRU 欄位需要 bits,總共 組,因此 LRU 儲存量為
題目給定 tag store 總容量為 bits:
整理得
代入 :
兩邊除以 :
因為
可得 。因此
區塊大小為
快速驗算
當 block size 為 bytes 時:
第 7 題10 分
- (10% total) A byte-addressable processor is connected to a single memory channel that has a single rank of DRAM. The physical address space is 32 bits, and the processor uses the following mapping shown in Table 3, to index the DRAM. Each DRAM row has a certain number of columns, where a column has the same size of a cache line. The processor uses 64-byte cache lines. The Columns is 6 bits and the Cache Line Offset is also 6 bits. In addition, the row size is 4 KB.
Table 3 Mapping from the physical address to DRAM
| MSB | LSB | |||
|---|---|---|---|---|
| Rows | Banks | Columns | Cache Line Offset |
Table 4 shows the memory request queue that has 4 pending memory request at time 0.
Assuming that
- A row buffer hit takes 50 cycles
- A row buffer conflict takes 250 cycles.
- Requests going to different banks can be processed by the banks in parallel.
- All the row buffers are closed at times 0.
- The controller cannot issue two requests at the same time. Each request takes 10 cycles to process, so it takes 10 cycles between issuing two separate requests to the memory.
- The controller employs First Ready-First Come First Serve (FR-FCFS) scheduling policy.
Table 4. the state of the memory request queue at time 0.
| Request | Physical Address |
|---|---|
| A (oldest) | 0x0000-4000 |
| B | 0x0000-1040 |
| C | 0x0000-3040 |
| D (youngest) | 0x0000-4a00 |
If it takes 320 cycles to finish processing all four requests in the memory, at least how many banks does this rank of DRAM have?
登入後即可作答並保存紀錄。
1. 實體位址拆解(Address Mapping)
實體位址共 32 bits,由 LSB 至 MSB 的欄位分配如下:
- Cache Line Offset:6 bits(bits ,對應 的 cache line)
- Columns:6 bits(bits ,共 個 column,與 的 row size 一致)
- Banks:假設有 bits(bits ,對應 個 banks)
- Rows:剩餘高位元(bits )
由於 Cache Line Offset 與 Columns 合計佔用低位元 12 bits(即十六進位最低 3 位數),將 Table 4 中 4 筆要求的實體位址依此拆解:
| Request | Physical Address | 高 20 位元(Rows + Banks, bits ) | 低 12 位元(Columns + Offset, bits ) |
|---|---|---|---|
| A (oldest) | 0x0000-4000 | 0x00004(二進位 ...00100) | 0x000 |
| B | 0x0000-1040 | 0x00001(二進位 ...00001) | 0x040 |
| C | 0x0000-3040 | 0x00003(二進位 ...00011) | 0x040 |
| D (youngest) | 0x0000-4a00 | 0x00004(二進位 ...00100) | 0xa00 |
2. 依 Bank 數逐一驗證
DRAM 的 Bank 數通常為 2 的冪次():
(1) 若只有 1 個 Bank()
所有 4 個要求皆進入同一個 Bank。時間 時 Row Buffer 全關閉,第一個要求必為 Miss(250 cycles),後續即使 D 與 A 同列為 Hit(50 cycles),B 與 C 仍各為不同的 Row(各 250 cycles),總時間遠大於 320 cycles,不可行。
(2) 若有 2 個 Banks(,以 bit 12 決定 Bank)
- Bank 0(bit 12 = 0):包含 A(Row
0x00002)與 D(Row0x00002)。 - Bank 1(bit 12 = 1):包含 B(Row
0x00000)與 C(Row0x00001)。
觀察 Bank 1:B 與 C 落在同一個 Bank,但屬於不同的 Row(Row 0 與 Row 1),因此兩者皆會發生 Row Buffer Conflict(各需 250 cycles)。僅 Bank 1 就至少需要:
(15% total) Please answer the following questions.
第 8.1 題4 分
Give two disadvantages of static code scheduling.
登入後即可作答並保存紀錄。
核心觀念
靜態程式碼排程是由編譯器在編譯期間重新安排指令順序,以減少資料相依造成的停滯,並提升處理器管線的使用率。排程時,編譯器依據目標處理器的延遲與資源資訊安排指令;程式執行後,處理器不會再依實際執行情況重新調整這些指令。
解題方法
題目要求列出兩項缺點,可從兩個面向回答:一是編譯期間掌握的資訊有限,二是排程可能使產生的程式碼變大。
-
難以配合執行時的變化:編譯器無法預先得知實際的分支結果、快取未命中等執行狀況,因此排程不能依執行時資訊調整。若實際延遲與編譯器採用的假設不同,排程效果就會下降。
-
可能增加程式碼大小:為了填補管線停滯,編譯器可能插入空操作(NOP)、複製指令或展開迴圈。這會增加程式碼量,並提高指令快取壓力;
第 8.2 題4 分
Give two disadvantages of dynamic code scheduling.
登入後即可作答並保存紀錄。
核心觀念
動態指令排程是在執行期間由處理器硬體追蹤指令相依性,讓已具備執行條件的指令先執行;因此,指令可能依照與程式順序不同的次序完成。這種做法能減少等待,但需要額外硬體,也讓處理器狀態管理更複雜。《Computer Architecture: A Quantitative Approach》
解題方法
題目要求列出兩項缺點,可分別從硬體成本與例外處理切入。兩者都直接來自動態排程的執行方式:硬體必須管理多條未完成指令,而指令又可能不按程式順序完成。
兩項缺點
-
硬體複雜度與成本增加
處理器需要追蹤指令相依性與執行狀態,並提供保留站(reservation stations)、暫存器重新命名(register renaming)等機制。這會增加硬體設計與驗證難度,也可能提高晶片面積與耗電量。 -
例外處理較困難
指令可能以不同於程式順序的次序執行或完成。若較新的指令已更新處理器狀態,較舊的指令才發生例外,處理器就必須避免留下不符合程式順序的狀態。
第 8.3 題4 分
What are two mechanisms that dynamic code scheduling uses to mitigate the shortcomings of static code scheduling, and why does each mechanism help?
登入後即可作答並保存紀錄。
核心觀念
本題考查動態指令排程如何補足靜態指令排程的限制。靜態排程由編譯器在執行前安排指令順序;但執行時的資料就緒狀態與指令延遲可能受快取未命中等因素影響,編譯器無法預先掌握。因此,動態排程由處理器在執行期間根據實際狀況安排指令。
解題方法
題目要求說明兩種機制及其作用,可從動態排程處理的兩類問題切入:指令等待尚未就緒的操作數,以及暫存器名稱造成的假相依。
-
亂序執行(out-of-order execution)
處理器追蹤各指令的操作數是否就緒,並讓已就緒的指令先執行,即使它在程式順序中排在較前方、但正等待資料的指令之後。這能利用等待期間執行其他指令的機會,降低停滯,也能因應執行時才出現的延遲。常見實作會使用保留站(reservation stations)保存等待中的指令與其操作數狀態。 -
暫存器重新命名(register renaming)
處理器以不同的實體暫存器保存不同版本的結果,避免多條指令因共用同一個架構暫存器名稱而被不必要地綁在一起。
第 8.4 題3 分
What types of dependencies can occur during out-of-order execution?
登入後即可作答並保存紀錄。
核心觀念
亂序執行允許處理器在指令尚未依程式順序完成時,先執行已具備條件的後續指令。執行順序可以調整,但程式原有的相依性必須保留,否則結果會改變。
相依性分為資料相依與控制相依:
- 資料相依:一條指令的資料使用或寫入,與另一條指令的資料存取有關。
- 控制相依:一條指令是否執行,取決於分支指令的結果。
解題方法
判斷相依性時,檢查指令是否讀取或寫入相同的暫存器或記憶體位置,再依讀寫順序分類:
-
真實資料相依(RAW,Read After Write):後一條指令要讀取前一條指令寫入的值。
必須等 產生 的新值後才能取得正確運算元。這是必須保留的資料相依,暫存器重新命名無法消除此相依。
-
反相依(WAR,Write After Read):後一條指令要寫入前一條指令讀取的位置。
必須先讀取原本的 , 才能寫入新的 。若 提前寫入, 便會讀到錯誤的值。這是名稱相依,可用暫存器重新命名消除。
-
輸出相依(WAW,Write After Write):兩條指令寫入相同的位置,且必須維持原有寫入順序。