114 年 國立臺灣大學資訊工程學系碩士班《計算機結構與作業系統》

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

第 1 題5 分

Which ONE of the following statements is correct for the critical-section problem? Assume there are several concurrent processes, each of which has one critical section. Memory variables shared among these processes are protected by the critical section from concurrent updates.
a. Memory barriers can prevent concurrent updates by enforcing mutual exclusion to the shared memory.
b. Atomic instructions can prevent concurrent updates by completing the load and store instructions to the shared memory.
c. Semaphores can allow more than one process to update the shared memory.
d. Mutex locks acquire the lock before updating the shared memory and release the lock after updating the shared memory when the locks are mandatory to assure mutual exclusion.
e. None of all.

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

這一題的完整詳解

核心觀念

本題旨在考驗作業系統(Operating Systems)中**臨界區段問題(Critical-Section Problem)與同步機制(Synchronization Primitives)**的核心觀念與運作機制。

解決臨界區段問題必須同時滿足以下三個條件:

  1. 互斥(Mutual Exclusion):若有行程在臨界區段內執行,則其他行程皆不得進入其臨界區段。
  2. 進展(Progress):若沒有行程在臨界區段內執行,且有行程想要進入,則只有不在剩餘區段(Remainder Section)執行的行程可以參與決定誰下一個進入臨界區段,且此決定不可無限期延遲。
  3. 有限等待(Bounded Waiting):行程提出進入臨界區段的請求後,在該請求被允許之前,其他行程進入臨界區段的次數必須有上限。

為達成互斥並保護共享記憶體變數免於併發更新(Concurrent Updates)導致的競態條件(Race Condition),常見的硬體與軟體同步工具包括:

  • 記憶體屏障(Memory Barriers / Fences):強制記憶體操作的執行順序,避免編譯器或 CPU 亂序執行(Out-of-Order Execution),確保記憶體可見性與一致性。
  • 原子指令(Atomic Instructions):硬體提供的不可中斷操作(如 TestAndSet、CompareAndSwap),作為建立高階同步工具的基礎構造塊(Building Blocks)。
  • 號誌(Semaphores):提供 wait()(或 PP)與 signal()(或 VV)操作。分為二元號誌(Binary Semaphore)與計數號誌(Counting Semaphore)。
  • 互斥鎖(Mutex Locks):專門用於實現互斥鎖定的高階同步機制,擁有者(Owner)在進入臨界區段前取得鎖(Acquire),離開後釋放鎖(Release)。

解題方法

本題為單選題,解題切入點為比對各選項所述同步工具的功能定義與運作邏輯,確認何者能正確描述保護共享記憶體併發更新的互斥機制。

在標準的臨界區段程式結構中:

do {
    // 1. 進入區段 (Entry Section):取得存取權/鎖
    /* acquire lock / wait(mutex) */

    // 2. 臨界區段 (Critical Section):更新共享記憶體
    /* Update shared memory variables */

    // 3. 退出區段 (Exit Section):釋放存取權/鎖
    /* release lock / signal(mutex) */

    // 4. 剩餘區段 (Remainder Section)
    /* Other operations */
} while (true);

當使用鎖定機制保障互斥性時,行程必須在進入臨界區段更新共享記憶體前取得鎖定,並於更新完成離開時釋放鎖定。


選項分析

🔒

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

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

免費註冊

第 2 題5 分

Which ONE of the following statements is correct for the redundant array of inexpensive disks (RAID)?
a. Reliability of the storage system is increased by the parallelism of the multiple disks.
b. RAID 5 uses the block-interleaved distributed parity check to increase the reliability.
c. If the MTBF of a single drive is 100,000 hours and the mean time to repair is 10 hours, the mean time to data loss of a mirrored drive (two disks) system is 5,700 years.
d. RAID 10 refers to a combination of RAID levels that are stripped first and mirrored later.
e. None of the above.

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

這一題的完整詳解

核心觀念

本題旨在考驗對**獨立磁碟冗餘陣列(RAID, Redundant Array of Inexpensive Disks)的定義、各等級(RAID Levels)架構特性、嵌套式 RAID 組合順序,以及儲存系統可靠度(Reliability)與平均資料遺失時間(MTTDL, Mean Time to Data Loss)**的數學推導。

  1. RAID 等級定義:

    • RAID 0:區塊拆分條帶化(Striping),提升效能但無冗餘(No Redundancy)。
    • RAID 1:磁碟鏡像(Mirroring),提供完全備份。
    • RAID 4:區塊級條帶化 + 獨立奇偶校驗碼磁碟(Block-interleaved dedicated parity)。
    • RAID 5:區塊級分散式奇偶校驗碼(Block-interleaved distributed parity),將 Parity 區塊均勻分散於陣列中各磁碟,解決 RAID 4 的 Parity 磁碟寫入瓶頸。
    • RAID 01 vs. RAID 10:嵌套式 RAID 架構。RAID 01 (RAID 0+1) 為先條帶化再鏡像(Striped first, mirrored later);RAID 10 (RAID 1+0) 為先鏡像再條帶化(Mirrored first, striped later)。
  2. 可靠度與 MTTDL 計算:

    • 平行處理(Parallelism)若無容錯機制,會隨磁碟數量增加而降低系統可靠度。
    • 在雙磁碟鏡像系統(RAID 1)中,平均資料遺失時間 MTTDLMTTDL 的公式為:
      MTTDL=MTTFsingle22×MTTRMTTDL = \frac{MTTF_{\text{single}}^2}{2 \times MTTR}
      其中 MTTFsingleMTTF_{\text{single}} 為單一磁碟的平均無故障時間(Mean Time To Failure),MTTRMTTR 為平均修復時間(Mean Time To Repair)。

解題方法

本題為標準的觀念辨析與數值驗算題,解題切入點如下:

  1. 檢視 RAID 各等級之標準語義定義,比對 RAID 5 的區塊層級與 parity 配置方式。
  2. 代入 RAID 1 的 MTTDLMTTDL 算式,進行精確的時間單位換算與數值驗算。
  3. 區分 RAID 10 與 RAID 01 在子陣列組合順序上的結構差異。
  4. 釐清「平行處理(Parallelism)」與「冗餘(Redundancy)」對系統故障率的根本影響。

選項分析

  • a. 錯誤。
    單純多磁碟平行處理(Parallelism,如 RAID 0 的條帶化)僅能提升讀寫效能(Performance),反而會因為參與的硬碟數量增加而降低系統整體的可靠度(MTTFsystem=MTTFsingle/NMTTF_{\text{system}} = MTTF_{\text{single}} / N)。系統可靠度的提升來自於「冗餘(Redundancy)」(如鏡像或偶數檢查碼),而非「平行處理」。
🔒

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

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

免費註冊

第 3 題3 分

Which ONE of the following statements is correct? Please select the correct description for the output of the following program.

#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int value = 10;

int main() {
    pid_t pid;
    pid = fork();

    if (pid == 0) { // child process
        value = value + 10;
        printf("A = %d\n", value);
        return 0;
    } else if (pid > 0) { // parent process
        wait(NULL);
        printf("B = %d\n", value);
        return 0;
    }
}

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

這一題的完整詳解

核心觀念

  1. 行程創建與獨立位址空間(Process Creation & Separate Address Space)
    在 POSIX 標準作業系統中,執行 fork() 系統呼叫會建立一個全新的子行程(Child Process)。子行程會完整複製父行程(Parent Process)的位址空間(包含 Code Segment、Data Segment、Heap 與 Stack)。在邏輯上,父行程與子行程擁有各自獨立的記憶體空間,因此子行程對全域變數或區域變數所發生的任何數值修改,完全不會影響父行程中的變數數值。現代作業系統大多採用寫入時複製(Copy-on-Write, COW)技術優化記憶體,但語意上仍嚴格保證記憶體空間的隔離性。

  2. 行程同步與印出順序(Process Synchronization & Execution Order)
    wait(NULL) 系統呼叫會將父行程掛起(Block),直到其子行程執行完畢並終止(Terminate)為止。此機制不僅能防止子行程變成殭屍行程(Zombie Process),更能確保子行程的輸出必定早於父行程的輸出。


解題方法

本題需透過追蹤 fork() 呼叫後的父子行程執行流程與記憶體狀態變化來分析輸出結果:

// 關鍵程式碼片段與執行流追蹤
int value = 10; // 全域變數,位於 Data Segment

int main() {
    pid_t pid = fork();

    if (pid == 0) { // 子行程分支
        value = value + 10; // 修改子行程獨立的 Data Segment (value 變為 20)
        printf("A = %d\n", value); // 印出 A = 20
        return 0;
    } else if (pid > 0) { // 父行程分支
        wait(NULL); // 父行程阻塞,等待子行程結束
        printf("B = %d\n", value); // 印出 B = 10 (父行程的 value 仍為 10)
        return 0;
    }
}
  1. 初始狀態:
    全域變數 value 初始值為 1010。

  2. 執行 fork() 後的分支評估:

    • 子行程(Child Process):fork() 回傳值 pid == 0。
      • 子行程複製父行程的 value(初始值為 1010)。
      • 執行 value = value + 10;,此時子行程記憶體中的 value 更新為 2020。
      • 執行 printf("A = %d\n", value);,在標準輸出印出 A = 20。
      • 子行程執行 return 0; 結束行程。
🔒

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

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

免費註冊

第 4 題7 分

Consider a paging system with a page size of 2KB. The amount of physical memory is 64KB. Let P denote the number of bits required in the physical address. Let L denote the number of bits required in the logical address.

Conventionally, a single-level page table is stored in the memory. If the page table is implemented in the conventional way, a page table in the memory contains 1024 entries. The memory access time is 180 nanoseconds (ns). Assume that the hit ratio of the conventional page table is 60% and the average page fault service time is 30,000 microseconds (μ\mus). Therefore, the effective memory access time for the conventional approach with a single-level page table is X.

Alex would like to consider an "inverted page table" to improve the translation from a logical address to a physical address. After careful calculation, he found that the inverted page table requires N entries. Furthermore, Alex considers that translation look-aside buffer (TLB) hardware to implement the idea in the inverted page table. Searching TLB takes 30 nanoseconds (ns). Assume that the hit ratio of the inverted page table is 90%. The effective memory access time for Alex's approach with a TLB-implemented inverted page table is Y. So, Alex's approach improves the effective memory access time, where A< speedup (in terms of the effective memory access time) <B. Here, A and B are positive integers.

Choices:
(A) 2L+3P+5N+A'+B'=120
(B) A&BL<L=10,N=1000
(C) P+3N+2X-2B=2Y-295
(D) 3L+PN-4A+2B=1024
(E) None of the above.

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

這一題的完整詳解

頁面大小 2KB=2112\text{KB}=2^{11} 位元組,實體記憶體 64KB=21664\text{KB}=2^{16} 位元組。

  • 偏移位元 =11=11。
  • 實體頁框數 =64KB/2KB=32=64\text{KB}/2\text{KB}=32,框號需 log⁡232=5\log_2 32=5 位。
  • 因此實體位址位元 P=5+11=16P=5+11=16。

單層頁表有 10241024 個項目 ⇒ 邏輯頁數 2102^{10},頁號需 1010 位。

  • 邏輯位址位元 L=10+11=21L=10+11=21。

傳統單層頁表

  • 命中時需兩次記憶體存取:180ns180\text{ns} (讀頁表) + 180ns180\text{ns} (讀資料) = 360ns360\text{ns}。
  • 命中率 0.60.6,缺頁服務時間 30,000 μs=30,000,000ns30{,}000\ \mu\text{s}=30{,}000{,}000\text{ns}。
  • 平均有效存取時間
X=0.6⋅360+0.4⋅30,000,000=216+12,000,072=12,000,288ns  (≈12ms)X =0.6\cdot360 +0.4\cdot30{,}000{,}000 =216 +12{,}000{,}072 =12{,}000{,}288\text{ns}\;(≈12\text{ms})

倒置頁表
倒置表每一實體框一項 ⇒ N=32N=32。
TLB 檢查時間 30ns30\text{ns},命中率 0.90.9。

  • 命中:30ns30\text{ns} (TLB) + 180ns180\text{ns} (資料) = 210ns210\text{ns}。
🔒

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

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

免費註冊

第 5 題10 分

Given the following descriptions, which ONE of the following statements is correct? Please calculate the values of P, D, M, and F to select the correct statement.

Assume that we have a computer system with a 32-bit processor. The computer supports a paged virtual memory. The page size is 8KB. Each address referenced by the processor contains P bits for indexing the page number and D bits for indexing the page offset. Initially, three empty frames are given to execute a process. Assume that the processor of the computer references the following sequence of hexadecimal addresses to execute the process:

4DF6BC24
1CA54523
4DF6AC24
1CA55523
23A22260

The working-set model is implemented in the system. The size of the working-set window is W=6. Generally, processes tend to have locality of memory references. Alex found over the sizes of working sets resulting from the above sequence of referenced addresses. He found that the maximal size of working sets over the referenced assistance is M. Therefore, Alex designed a priority-based page replacement algorithm according to the locality principle. To implement his algorithm, he quantifies "referenced likelihood for each page" as the ratio of the total number of references to the page within the working-set window to the size of the working-set window. Note that the pages referenced within the working-set window include the page that the processor is currently attempting to reference. When 6 hexadecimal addresses is referenced, the algorithm needs to track the referenced likelihood for each page. If a page fault happens, the page with the minimal referenced likelihood is selected to be replaced. If multiple pages have the same referenced likelihood, the Least recently used (LRU) algorithm is used to break the tie. So, the total number of page faults arising from the sequence of hexadecimal addresses referenced by the processor is F.

Choices:
(A) 2P+5D+M'+F'=1000
(B) D+M+D'+F'=42
(C) P+2D+2M+F=34
(D) MDP+3F+4P=500
(E) None of the above.

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

這一題的完整詳解

步驟與計算

  1. 位元分割

    • 頁面大小 8KB=2138\text{KB}=2^{13},故頁位元 D=log⁡28192=13D=\log_2 8192=13。
    • 處理器位址長度 3232 位元,故頁號位元 P=32−D=19P=32-D=19。
  2. 頁號求得
    頁號 = 位址右移 1313 位 (即除以 213=81922^{13}=8192)。

0x4DF6BC24→159 6690x1CA54523→3 6660x4DF6AC24→159 6690x1CA55523→3 6660x23A22260→4 561\begin{aligned} 0x4DF6BC24 &\rightarrow 159\,669\\ 0x1CA54523 &\rightarrow 3\,666\\ 0x4DF6AC24 &\rightarrow 159\,669\\ 0x1CA55523 &\rightarrow 3\,666\\ 0x23A22260 &\rightarrow 4\,561 \end{aligned}
  1. 工作集大小 MM
    工作集視窗 W=6W=6,因總參考次數 5<65<6,每一步的工作集即已出現的不同頁號數量:

    • 1, 2, 2, 2, 3 → 最大工作集大小 M=3M=3。
  2. 頁錯誤次數 FF

    • 初始 3 個空框架。
    • 依序載入 159669、3666、4561,只有在第一次、第二次、第五次參考時缺頁。
    • 故 F=3F=3。
🔒

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

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

免費註冊

第 6 題5 分

🖼️【此處有附圖,請對照原卷】
The following figure shows an example data structure used for opening a file from file systems in user space, kernel memory, and secondary storage in operating systems. The number in the circle represents one operation in the computing systems.

Select the correct statement(s) for the above figure:
(A) Operation will be conducted to ensure that there is no duplicated file in the same directory.
(B) Operation refers to the file descriptor to the system-wide open-file table to create an entry.
(C) When the file 'foo.txt' does not exist in the file system, Operation is called to create a new entry in the directory structure.
(D) When the file 'foo.txt' has been open in the system, Opertion is will not be called.
(E) When the file 'foo.txt' has not been open in the file system, Opertion creates an entry to store the File Control Block of the file.

🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 5 頁

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

這一題的完整詳解

本題考查作業系統中檔案開啟與管理的流程,特別是檔案描述符、系統開檔表、目錄結構和檔案控制區塊 (FCB) 等概念。題目附圖顯示了一個從使用者空間到核心、再到次級儲存的檔案開啟流程圖,其中標註了編號的操作。

首先解析圖中標號的意義:
圖中顯示了從 "user space" 發起 "Opening file" 的操作。

  1. Operation 1: 看起來是檢查目錄結構 (Directory Structure) 中的檔案是否存在或進行查找。
  2. Operation 2: 看起來是建立一個 "system-wide open-file table" 的條目。
  3. Operation 3: 看起來是建立一個 "per-process open-file table" 的條目,並返回一個 "file descriptor" 給使用者空間。
  4. Operation 4: 看起來是從次級儲存 (Secondary Storage) 載入檔案資訊到核心記憶體中的檔案控制區塊 (File Control Block, FCB)。FCB 包含了檔案的所有元數據。

現在分析各個選項:

(A) Operation 1 will be conducted to ensure that there is no duplicated file in the same directory.
- Operation 1 是在目錄結構中查找檔案。檔案系統通常不允許在同一個目錄下存在同名的檔案。當嘗試創建一個新檔案時,Operation 1 會檢查是否存在同名檔案以防止重複。但是,僅僅是「開啟 (opening)」檔案時,Operation 1 的主要目的是查找檔案是否存在並獲取其元數據,而不是確保沒有重複檔案。確保沒有重複檔案是在檔案「創建 (creation)」時的檢查。因此,這個敘述不完全精確。

(B) Operation 3 refers to the file descriptor to the system-wide open-file table to create an entry.
- Operation 3 是在「per-process open-file table」中創建一個條目,並將其索引(即檔案描述符,file descriptor)返回給使用者行程。它指向的是系統級開檔表 (system-wide open-file table) 中的一個條目,而不是直接在系統級開檔表「創建」條目。系統級開檔表的條目是由 Operation 2 創建的。因此,這個敘述不正確。

🔒

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

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

免費註冊

第 7 題5 分

Given a set of 5 processes, the arrival time of the i-th process Pi is A[i], and the burst time of the i-th process Pi is B[i], as shown below:

ProcessArrival Time, A[i]Burst Time, B[i]
P1010
P203
P305
P404
P502

Perform round-robin scheduling for these five processes. Assume that the average waiting time of all processes is a x10a+bx10b+cx10c+dx10dx 10^a + b x 10^b + c x 10^c + d x 10^d. Select the correct description(s).
Choices:
(A) a + b + c + d = 8.
(B) b + d = 2c.
(C) b + d = 3.
(D) 5b = c.
(E) a x c = 5.

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

這一題的完整詳解

核心觀念

本題考驗作業系統(Operating System)中 CPU 排程演算法(CPU Scheduling Algorithms)的 輪轉排程法(Round-Robin Scheduling, RR),以及行程時間指標的推導與代數系統化簡。

1. 輪轉排程法(Round-Robin Scheduling, RR)

  • 機制:RR 排程為搶佔式(Preemptive)排程演算法,系統將 CPU 時間劃分為固定長度的時間區段,稱為時間切片(Time Quantum / Time Slice, qq)。
  • 佇列管理:系統維護一個先進先出(FIFO)的 Ready Queue。當新行程抵達或被搶佔時,會被放入佇列尾端;CPU 總是挑選佇列前端的行程執行。
  • 搶佔規則:若行程在單次時間切片 qq 內未執行完畢,系統會觸發定時器中斷(Timer Interrupt),將該行程搶佔並移至 Ready Queue 尾端,再由下一個行程接續執行。

2. 行程時間指標與計算公式

  • 完成時間(Completion Time, CiC_i):行程 PiP_i 結束執行的時間點。
  • 轉返時間(Turnaround Time, TATiTAT_i):行程從抵達到執行完成的總時間差:
    TATi=Ci−A[i]TAT_i = C_i - A[i]
  • 等待時間(Waiting Time, WiW_i):行程在 Ready Queue 中等待 CPU 的累計時間:
    Wi=TATi−B[i]=Ci−A[i]−B[i]W_i = TAT_i - B[i] = C_i - A[i] - B[i]
  • 平均等待時間(Average Waiting Time, AWT\text{AWT}):所有行程等待時間的算術平均值:
    AWT=1n∑i=1nWi\text{AWT} = \frac{1}{n} \sum_{i=1}^{n} W_i

解題方法

步驟一:分析題目資訊與甘特圖(Gantt Chart)推導

題目給定 5 個行程,抵達時間皆為 A[i]=0A[i] = 0,Burst Time 分別為 B[1]=10,B[2]=3,B[3]=5,B[4]=4,B[5]=2B[1]=10, B[2]=3, B[3]=5, B[4]=4, B[5]=2。

在完整題目規範中,進行輪轉排程必須指定時間切片 qq。若以常規時間切片 q=1q = 1 為例,行程初始佇列順序為 [P1,P2,P3,P4,P5][P_1, P_2, P_3, P_4, P_5],執行甘特圖如下:

  • t=0→5t = 0 \to 5:P1,P2,P3,P4,P5P_1, P_2, P_3, P_4, P_5 依序各執行 11 單位時間。
    • 各行程剩餘 Burst Time:P1(9),P2(2),P3(4),P4(3),P5(1)P_1(9), P_2(2), P_3(4), P_4(3), P_5(1)。
  • t=5→10t = 5 \to 10:P1,P2,P3,P4,P5P_1, P_2, P_3, P_4, P_5 依序各執行 11 單位時間。
    • 行程 P5P_5 於 t=10t = 10 執行完畢,完成時間 C5=10C_5 = 10。
    • 剩餘行程 Burst Time:P1(8),P2(1),P3(3),P4(2)P_1(8), P_2(1), P_3(3), P_4(2)。
  • t=10→14t = 10 \to 14:P1,P2,P3,P4P_1, P_2, P_3, P_4 依序各執行 11 單位時間。
    • 行程 P2P_2 於 t=12t = 12 執行完畢,完成時間 C2=12C_2 = 12。
    • 剩餘行程 Burst Time:P1(7),P3(2),P4(1)P_1(7), P_3(2), P_4(1)。
  • t=14→17t = 14 \to 17:P1,P3,P4P_1, P_3, P_4 依序各執行 11 單位時間。
    • 行程 P4P_4 於 t=17t = 17 執行完畢,完成時間 C4=17C_4 = 17。
    • 剩餘行程 Burst Time:P1(6),P3(1)P_1(6), P_3(1)。
  • t=17→19t = 17 \to 19:P1,P3P_1, P_3 依序各執行 11 單位時間。
    • 行程 P3P_3 於 t=19t = 19 執行完畢,完成時間 C3=19C_3 = 19。
    • 剩餘行程 Burst Time:P1(5)P_1(5)。
  • t=19→24t = 19 \to 24:P1P_1 獨佔執行剩餘的 55 單位時間。
    • 行程 P1P_1 於 t=24t = 24 執行完畢,完成時間 C1=24C_1 = 24。

步驟二:計算等待時間與平均等待時間

根據 Wi=Ci−A[i]−B[i]W_i = C_i - A[i] - B[i],計算各行程等待時間:

  • W1=24−0−10=14W_1 = 24 - 0 - 10 = 14
🔒

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

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

免費註冊

第 8 題5 分

Given a set of 5 periodic processes, which all arrive at time 0, as shown below:

ProcessRelative DeadlinePeriodBurst Time
P1105010
P2101205
P3580010
P4102010
P5104010

Perform the deadline-monotonic scheduling. Select the correct description(s).
(A) Deadline monotonic algorithm and rate monotonic algorithm have the same schedulability for this task set.
(B) The worst-case response time (from the arrival time to the time of the completion of a process) of P2 is 20.
(C) Process P4 is schedulable.
(D) If we increase the burst time of P3 by X time units, the worst-case response time of P3 will also be increased by X time units.
(E) All the tasks remain schedulable when the burst time of process P1 is set to 8.

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

這一題的完整詳解

核心觀念

  1. 即時系統排程(Real-Time Scheduling):
    • Deadline-Monotonic (DM) 排程演算法:屬於靜態優先級(Static Priority / Fixed Priority)搶佔式排程。優先級分配原則為相對截止時間(Relative Deadline, DiD_i)越短者,優先級越高。
    • Rate-Monotonic (RM) 排程演算法:優先級分配原則為週期(Period, TiT_i)越短者,優先級越高。當任務的相對截止時間等於週期(Di=TiD_i = T_i)時,DM 與 RM 等價;但若 Di≤TiD_i \le T_i,DM 為最佳靜態優先級排程演算法(Optimal Static Priority Scheduling Algorithm)。
  2. 最差回應時間分析(Worst-Case Response Time, WCRT Analysis):
    • 任務 PiP_i 的回應時間 RiR_i 為從到達時間(Arrival Time)至執行完成時間(Completion Time)的時間差。
    • 當所有任務同時於 t=0t=0 到達時(Critical Instant),PiP_i 的最差回應時間公式為迭代式:
      Ri(k+1)=Ci+∑j∈HP(i)⌈Ri(k)Tj⌉CjR_i^{(k+1)} = C_i + \sum_{j \in HP(i)} \left\lceil \frac{R_i^{(k)}}{T_j} \right\rceil C_j
      其中 CiC_i 為任務 PiP_i 的 Burst Time(執行時間),HP(i)HP(i) 表示優先級高於 PiP_i 的任務集合(Higher-Priority Tasks)。
  3. 可排程性(Schedulability):
    • 任務 PiP_i 為可排程(Schedulable),若且唯若其最差回應時間不超過相對截止時間,即 Ri≤DiR_i \le D_i。
    • 若任務集中存在至少一個任務滿足 Ri>DiR_i > D_i,則該任務集不可排程(Unschedulable)。

解題方法

Step 1: 確定 DM 與 RM 下的優先級排序

整理題目所給定之各任務參數:

  • P1:D1=10,T1=50,C1=10P_1: D_1 = 10, T_1 = 50, C_1 = 10

  • P2:D2=10,T2=120,C2=5P_2: D_2 = 10, T_2 = 120, C_2 = 5

  • P3:D3=5,T3=800,C3=10P_3: D_3 = 5, T_3 = 800, C_3 = 10

  • P4:D4=10,T4=20,C4=10P_4: D_4 = 10, T_4 = 20, C_4 = 10

  • P5:D5=10,T5=40,C5=10P_5: D_5 = 10, T_5 = 40, C_5 = 10

  • DM 優先級(依 DiD_i 由小到大排序):
    D3=5<D1=D2=D4=D5=10D_3 = 5 < D_1 = D_2 = D_4 = D_5 = 10。
    P3P_3 擁有嚴格最小的相對截止時間,故 P3P_3 具有最高優先級。

  • RM 優先級(依 TiT_i 由小到大排序):
    T4(20)<T5(40)<T1(50)<T2(120)<T3(800)T_4 (20) < T_5 (40) < T_1 (50) < T_2 (120) < T_3 (800)。
    優先級順序為 P4>P5>P1>P2>P3P_4 > P_5 > P_1 > P_2 > P_3。

Step 2: 驗證關鍵任務之 WCRT 與可排程性

  1. P3P_3 在 DM 下的 WCRT:
    由於 P3P_3 為最高優先級任務,HP(P3)=∅HP(P_3) = \emptyset,不受任何其他任務搶佔:
    R3=C3=10R_3 = C_3 = 10
    因為 R3=10>D3=5R_3 = 10 > D_3 = 5,P3P_3 錯過截止時間。因此,P3P_3 不可排程,整個任務集在 DM 下為不可排程(Unschedulable)。
🔒

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

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

免費註冊

第 9 題5 分

Please select the correct description(s).
(A) A system with two processing cores can always get a double speedup.
(B) For process execution, it is possible to have concurrency without parallelism.
(C) The threads API can be used in multithreaded C programs for thread creation and synchronization. When the parent thread calls the pthread_join function, it waits for the child thread to terminate. It is asynchronous thread.
(D) A process transits from a waiting state to a running state when it is assigned CPU for execution.
(E) If the binding of instructions and data to memory addresses (i.e., address binding) is done at the compile time, it is called "dynamic binding".

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

這一題的完整詳解

核心觀念

本題涵蓋作業系統(Operating Systems)與計算機結構(Computer Architecture)的四大核心主題:

  1. 平行度與性能分析(Parallelism and Amdahl's Law):系統核心數與加速比(Speedup)的非線性關係,以及硬體開銷與不可平行化程式碼對效能的限制。
  2. 併行與平行(Concurrency vs. Parallelism):兩者的定義區別。併行是指多個任務在重疊的時間區段內皆能取得進展(可透過單核心時分複用實現);平行則是指多個任務在同一實體時間點同時執行(必須具備多核心或多處理器硬體)。
  3. 執行緒模型與同步(Threading API and Synchronization):POSIX Threads (pthread) 中的同步執行緒(Synchronous threading,如使用 pthread_join() 等待子執行緒)與非同步執行緒(Asynchronous threading)之定義差別。
  4. 行程狀態轉移模型(Process State Transitions):標準五態模型(New, Ready, Running, Waiting, Terminated)中各狀態間的轉移條件(Waiting 狀態完成 I/O 或事件後應轉入 Ready 狀態,再由排程器派發至 Running 狀態)。
  5. 記憶體位址綁定(Address Binding):編譯時期(Compile time)、載入時期(Load time)與執行時期(Execution / Run time)綁定之分類。編譯時期與載入時期位址綁定屬於靜態綁定(Static binding);僅有執行時期位址綁定才稱為動態綁定(Dynamic binding)。

解題方法

針對觀念選錯/選對題,切入點為比對作業系統權威教材(如 Silberschatz 之 Operating System Concepts)之定義與邏輯推論:

  1. 分析 (A):檢視關鍵字「always」,代入阿姆達爾定律(Amdahl's Law)公式 S=1(1−P)+PNS = \frac{1}{(1-P) + \frac{P}{N}} 與系統實際維護開銷(通訊、同步、排程),判斷是否能達成絕對的雙倍加速。
  2. 分析 (B):釐清 Concurrency(併行)與 Parallelism(平行)的層次差異,驗證單核心系統交錯執行行程是否符合「Concurrent without Parallel」。
  3. 分析 (C):核對 Pthreads API 之行為與觀念定義,pthread_join() 係使父執行緒進入阻塞狀態直到子執行緒結束,此行為定義為 Synchronous Threading(同步執行緒)。
  4. 分析 (D):繪製五態行程轉移圖(Process State Diagram),確認 Waiting 狀態發生事件完成時的正確轉移方向( Waiting →\rightarrow Ready →\rightarrow Running)。
  5. 分析 (E):比對記憶體管理中編譯時期位址綁定(Compile-time address binding)對應的是 Static binding 還是 Dynamic binding。

選項分析

  • (A) 錯誤
    根據阿姆達爾定律(Amdahl's Law),若程式中存在不可平行化的序列區段(比例為 1−P1-P),其加速比上限為 S=1(1−P)+PNS = \frac{1}{(1-P) + \frac{P}{N}} 其中 N=2N=2 為核心數。即便 P=1P=1(完全可平行化),在實際系統中亦會因執行緒建立開銷、同步鎖定競爭、快取一致性(Cache Coherence)開銷及記憶體頻寬瓶頸,導致加速比小於 22。因此「總是能獲得雙倍加速(always get a double speedup)」之敘述完全不成立。
🔒

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

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

免費註冊

第 10 題8 分

Given the following C snipped and the disassembly of the resulting object of the code for the x86-64 platforms. Assume the function, up(l,u), up is in %rsi. Answer the value of CN and the full declaration of the structure np_struct.

HINT: for an instruction lea (a, b, num), c, the result of (b*num + a) is moved to c.

extern struct np_struct;
typedef struct {
    int n;
    int m;
    void *up;
} u_struct;

int main() {
    u_struct local;
    local.n = 0;
    local.m = 0;
    local.up = NULL;

    int_np_struct *np_val;
    int *np_val2;
    // ... some initialization of np_val and np_val2 ...
    // These are not shown, assuming they are valid pointers when used.
}

void func(long l, u_struct u, long *up) {
    int n;
    int m;
    u_struct *up_local = &u; // Assume &u is passed from caller
    // The snippet is for the following C code segment:
    // int n_val;
    // int m_val;
    // u_struct *up_next;
    // n_val = up_local->n;
    // m_val = up_local->m;
    // up_next = up_local->up;
    // ...
    // The disassembly only shows the part for accessing u_struct fields.
}

Disassembly:

mov    0x120(%rsi), %ecx           // line 1
add    %ecx, %ecx                  // line 2
lea    (%rsi,%rcx,8), %rdx         // line 3
mov    0x8(%rdx), %rax             // line 4
mov    (%rdx), %r8                 // line 5
mov    0x8(%rsi), %rcx             // line 6
mov    0x0(%rcx), %r9              // line 7
mov    0x8(%rcx), %r10             // line 8
retq                               // line 9

Choices:
(A) CN = 8, nt_struct = {long idx, long idx1, int x4};
(B) CN = 7, nt_struct = {long idx, long idx1, int x5};
(C) CN = 8, nt_struct = {long idx, int idx1, long x5};
(D) CN = 7, nt_struct = {long idx, long idx1, long x3};
(E) None of the above.

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

這一題的完整詳解

解題重點

  1. mov 0x120(%rsi),%ecx 取得位於 %rsi+0x120 的 32‑bit 整數,記為 cnt。
  2. add %ecx,%ecx 使 cnt 變為 2·cnt。
  3. lea (%rsi,%rcx,8),%rdx 等價於 %rdx = %rsi + (2·cnt)·8 = %rsi + cnt·16,可視為 以 16 為元素大小的陣列索引。
  4. mov (%rdx),%r8 取該元素的 第 0 個 8‑byte 欄位。
  5. mov 0x8(%rdx),%rax 取 第 1 個 8‑byte 欄位。
🔒

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

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

免費註冊

第 11 題5 分

Two different compilers were used to compile the same program. When compiler A, the program executed 1.0E9 instructions and took 1.5 seconds to complete. With compiler B, the program executed 1.5E9 instructions and took 1.8 seconds to complete. Assume the processor has a clock cycle time of 1ns.
(A) The average CPI of the program produced by compiler A is 1.5.
(B) The average CPI of the program produced by compiler B is 1.5.
(C) Assume that the compiled program now run on two new distinct processors. If the execution times on the two processors are the same, the clock of the processor running compiler A's code is 1.37x faster than the clock of the processor running compiler B's code.
(D) Assume that a new compiler, C, is developed using 4.0E8 instructions and achieves an average CPI of 0.8. The speedup of using the new compiler versus compiler A is less than 4.7x.
(E) The speedup of using compiler C described in (D) versus compiler B is less than 4x.

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

這一題的完整詳解

核心觀念

本題的核心為計算機結構中最基礎且最重要的 CPU 效能公式(CPU Performance Equation) 與 效能加速比(Speedup):

  1. CPU 執行時間公式:

    CPU Time=Instruction Count (IC)×CPI×Clock Cycle Time (Tc)=IC×CPIClock Rate (f)\text{CPU Time} = \text{Instruction Count (IC)} \times \text{CPI} \times \text{Clock Cycle Time } (T_c) = \frac{\text{IC} \times \text{CPI}}{\text{Clock Rate } (f)}
    • IC\text{IC}:程式執行的總指令數(Instruction Count)
    • CPI\text{CPI}:每條指令所需的平均時脈週期數(Cycles Per Instruction)
    • TcT_c:時脈週期時間(Clock Cycle Time),單位為秒(s\text{s})
    • ff:時脈頻率/速率(Clock Rate),f=1Tcf = \frac{1}{T_c},單位為赫茲(Hz\text{Hz})
  2. 加速比(Speedup)公式:

    Speedup=Execution TimeoldExecution Timenew=CPU TimebaseCPU Timetarget\text{Speedup} = \frac{\text{Execution Time}_{\text{old}}}{\text{Execution Time}_{\text{new}}} = \frac{\text{CPU Time}_{\text{base}}}{\text{CPU Time}_{\text{target}}}

解題方法

根據題意整理基準處理器與各編譯器的已知條件:

  • 處理器時脈週期時間:Tc=1 ns=1.0×10−9 sT_c = 1\text{ ns} = 1.0 \times 10^{-9}\text{ s}(時脈頻率 f=1 GHz=1.0×109 Hzf = 1\text{ GHz} = 1.0 \times 10^9\text{ Hz})
  • 編譯器 A(Compiler A):
    • 指令數 ICA=1.0×109\text{IC}_A = 1.0 \times 10^9
    • 執行時間 CPU TimeA=1.5 s\text{CPU Time}_A = 1.5\text{ s}
  • 編譯器 B(Compiler B):
    • 指令數 ICB=1.5×109\text{IC}_B = 1.5 \times 10^9
    • 執行時間 CPU TimeB=1.8 s\text{CPU Time}_B = 1.8\text{ s}

選項分析

選項 (A)

由效能公式推導編譯器 A 的平均 CPI:

CPU TimeA=ICA×CPIA×Tc\text{CPU Time}_A = \text{IC}_A \times \text{CPI}_A \times T_c 1.5=1.0×109×CPIA×10−9  ⟹  CPIA=1.51.5 = 1.0 \times 10^9 \times \text{CPI}_A \times 10^{-9} \implies \text{CPI}_A = 1.5

因此編譯器 A 的平均 CPI 為 1.51.5。
此選項正確。


選項 (B)

由效能公式推導編譯器 B 的平均 CPI:

CPU TimeB=ICB×CPIB×Tc\text{CPU Time}_B = \text{IC}_B \times \text{CPI}_B \times T_c 1.8=1.5×109×CPIB×10−9  ⟹  CPIB=1.81.5=1.21.8 = 1.5 \times 10^9 \times \text{CPI}_B \times 10^{-9} \implies \text{CPI}_B = \frac{1.8}{1.5} = 1.2

因此編譯器 B 的平均 CPI 應為 1.21.2,而非 1.51.5。
此選項錯誤。


選項 (C)

設執行編譯器 A 程式碼的處理器為 Processor A(時脈頻率為 fAf_A),執行編譯器 B 程式碼的處理器為 Processor B(時脈頻率為 fBf_B)。

兩者所消耗的總時脈週期數(Clock Cycles)分別為:

  • CyclesA=ICA×CPIA=1.0×109×1.5=1.5×109 cycles\text{Cycles}_A = \text{IC}_A \times \text{CPI}_A = 1.0 \times 10^9 \times 1.5 = 1.5 \times 10^9\text{ cycles}
🔒

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

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

免費註冊

第 12 題6 分

Assume the individual stages of the datapath have the following latencies:
IF: 150ps, ID: 250ps, EX: 50ps, MEM: 200ps, WB: 100ps

Assume the instructions executed by the processor break down as follows:
ALU: 45%; BEQ: 20%; LW: 20%; SW: 15%

Choices:
(A) The clock cycle time in a pipelined processor is 350 ps.
(B) The total latency of an LW instruction in a non-pipelined processor is 850 ps.
(C) The total latency of an LW instruction in a pipelined processor is 1250 ps.
(D) The utilization of the data memory is 35% (Assume there are no stalls or hazards).
(E) The utilization of the data memory is 35% (Assume there are no stalls or hazards).

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

這一題的完整詳解

核心觀念

  1. 流水線時脈週期(Pipelined Clock Cycle Time):
    在流水線架構中,時脈週期取決於延遲最長(最慢)的階段(Bottleneck Stage):
    Tclock, pipelined=max⁡(TIF,TID,TEX,TMEM,TWB)T_{\text{clock, pipelined}} = \max(T_{\text{IF}}, T_{\text{ID}}, T_{\text{EX}}, T_{\text{MEM}}, T_{\text{WB}})

  2. 非流水線指令總延遲(Non-pipelined Instruction Latency):
    在非流水線單週期處理器中,指令的總延遲為該指令所需經過的所有階段延遲之和:
    Latencynon-pipelined=∑Trequired stages\text{Latency}_{\text{non-pipelined}} = \sum T_{\text{required stages}}

  3. 流水線指令總延遲(Pipelined Instruction Latency):
    在流水線處理器中,指令經過所有階段所需的總時間,為「階段數 ×\times 時脈週期」:
    Latencypipelined=Nstages×Tclock, pipelined\text{Latency}_{\text{pipelined}} = N_{\text{stages}} \times T_{\text{clock, pipelined}}

  4. 資料記憶體使用率(Data Memory Utilization):
    資料記憶體僅在 MEM 階段被存取。因此,使用率為執行記憶體存取指令(LW 與 SW)的比例總和:
    UtilizationData Memory=PLW+PSW\text{Utilization}_{\text{Data Memory}} = P_{\text{LW}} + P_{\text{SW}}


解題方法

已知各階段延遲:
TIF=150 psT_{\text{IF}} = 150 \text{ ps}, TID=250 psT_{\text{ID}} = 250 \text{ ps}, TEX=50 psT_{\text{EX}} = 50 \text{ ps}, TMEM=200 psT_{\text{MEM}} = 200 \text{ ps}, TWB=100 psT_{\text{WB}} = 100 \text{ ps}

指令混合比例:
ALU=45%\text{ALU} = 45\%, BEQ=20%\text{BEQ} = 20\%, LW=20%\text{LW} = 20\%, SW=15%\text{SW} = 15\%

關鍵推導步驟:

  1. 求流水線時脈週期 Tclock, pipelinedT_{\text{clock, pipelined}}:
    Tclock, pipelined=max⁡(150,250,50,200,100)=250 psT_{\text{clock, pipelined}} = \max(150, 250, 50, 200, 100) = 250 \text{ ps}

  2. 求 LW 指令在非流水線處理器中的總延遲:
    LW 指令需要經過完整 5 個階段(IF, ID, EX, MEM, WB):
    LatencyLW, non-pipelined=150+250+50+200+100=750 ps\text{Latency}_{\text{LW, non-pipelined}} = 150 + 250 + 50 + 200 + 100 = 750 \text{ ps}

🔒

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

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

免費註冊

第 13 題5 分

Consider a processor with a load delay slot: this means that the value loaded into a destination register (Rd) is not available for use in the instruction immediately following the load. Assume the following code sequence runs on this processor (with RISC-V ISA).

addi x3, x0, 0x18  // x3 = 24
lw   x4, 0(x3)     // x4 = Mem[x3+0]
addi x3, x0, 0x18  // x3 = 24
lw   x4, 0(x3)     // x4 = Mem[x3+0]

Suppose that MEM[32] = -4, and the load delay slot is ignored. What will be the value (in decimal) stored in the register x4 after all the code is executed?

Choices:
(A) 48
(B) 14
(C) -8
(D) 40
(E) None of the above.

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

這一題的完整詳解

步驟

  1. 第 1 條 addi x3, x0, 0x18 → x3 = 0x18 = 24。
  2. 第 2 條 lw x4, 0(x3) 以 x3 為基址取記憶體位址 24 的字,得到 x4 = MEM[24]。
  3. 第 3 條 addi x3, x0, 0x18 再次把 x3 設為 24(與第 1 條相同)。
🔒

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

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

免費註冊

第 14 題4 分

(Question Group A: 8points – 2 questions) Assume we have a 2-way set associative cache that employs a write-back policy and uses a perfect LRU mechanism to decide which block to evict. The tag store, which includes bits for valid status, dirty status, and LRU tracking, requires 2242^{24} bits of storage space. The cache implements virtual indexing with physical tagging. The system has a virtual address space of 1 MB, uses pages of 1 KB in size, and each cache block is 8 bytes long. Answer the following questions.

What is the size of the cache's data store?
(A) 1KB
(B) 2KB
(C) 4KB
(D) 8KB
(E) None of the above.

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

這一題的完整詳解

解題步驟

  1. 設快取有 SS 個集合(set),每組 2 個快取列(way)。
  2. 每列需儲存
  • valid 位元 1
  • dirty 位元 1
  • LRU 追蹤:對 2‑way 只需 1 位元每組,等效於每列 0.5 位元,於計算上取整為每列 1 位元(最保守估計)。
    因此每列至少需 3 位元(V、D、LRU)作為「標籤儲存」的最小需求。
  1. 標籤儲存總位元數給定為 224=16 777 2162^{24}=16\,777\,216 位元。
    每列 3 位元 → 列數

列數=2243=5 592 405 列\text{列數}= \frac{2^{24}}{3}=5\,592\,405\ \text{列}

🔒

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

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

免費註冊

第 15 題4 分

【題組共用題幹】(Question Group A: 8points – 2 questions) Assume we have a 2-way set associative cache that employs a write-back policy and uses a perfect LRU mechanism to decide which block to evict. The tag store, which includes bits for valid status, dirty status, and LRU tracking, requires 2242^{24} bits of storage space. The cache implements virtual indexing with physical tagging. The system has a virtual address space of 1 MB, uses pages of 1 KB in size, and each cache block is 8 bytes long. Answer the following questions.

How many bits of the virtual index come from the virtual page number?
(A) 1 bit
(B) 2 bits
(C) 3 bits
(D) 4 bits
(E) None of the above.

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

這一題的完整詳解

計算步驟:

  1. 位元組大小

    • 每個快取區塊 = 8 B → 區塊位元組位元 (block offset) = log⁡28=3\log_2 8 = 3 bit。
    • 每頁大小 = 1 KB = 2102^{10} B → 頁面位元組位元 = 1010 bit。
  2. 虛擬位址結構(20 bit)

VPN⏟10bit  PO⏟10bit=VPN⏟10bit  block offset⏟3bit  page offset (剩餘)⏟7bit\underbrace{\text{VPN}}_{10\text{bit}}\; \underbrace{\text{PO}}_{10\text{bit}}= \underbrace{\text{VPN}}_{10\text{bit}}\; \underbrace{\text{block\ offset}}_{3\text{bit}}\; \underbrace{\text{page\ offset (剩餘)}}_{7\text{bit}}
  1. 采用 virtual‑index / physical‑tag,因此索引位元只能取自虛擬位址的低位,且必須落在同一頁內。
    • 低 77 bit(頁面位元組位元中去掉區塊位元)必然屬於索引。
🔒

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

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

免費註冊

第 16 題8 分

Storing and re-loading data from the main memory during the loop cause a slowdown.

Assume that you have a new instruction called fmv.d that executes in a single cycle. This instruction performs register move operations. For instance: 'fmv.d rd, rs1' — writes the value of floating-point register rs1 into the floating-point register rd.

If the fmv.d instruction is used to optimize the code's performance by using registers to carry the data between iterations of the loop, how many clock cycles are needed to execute this code?

addiu x12, x10, x5
addiu x11, x11, 16

LOOP:
fld f0, -16(x11)
fld f1, 0(x11)
fadd.d f2, f0, f1
fsd f2, 0(x11)
addiu x11, x11, 8
ble x11, x12, LOOP

Here, an instruction's latency represents how many clock cycles must pass before another instruction can use its result. The floating point instructions have the following associated latencies (in cycles):
fadd.d = 4
fld = 6
fsd = 1

Choices:
(A) 15984
(B) 17587
(C) 25280
(D) 26583
(E) None of the above.

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

這一題的完整詳解

步驟概覽

  1. 迴圈次數
    起始位址 : x11 ← x11 + 16
    每次遞增 : x11 ← x11 + 8
    結束位址 : x12 = x10 + x5

    迴圈執行次數

N=x5−168+1=x58−1N = \frac{x5-16}{8}+1=\frac{x5}{8}-1

  1. 指令排程(使用 fmv.d)

    • 第一輪 必須從記憶體載入兩個浮點值:
      fld f0, -16(x11)、fld f1, 0(x11)
    • 之後每輪 只需載入一個新值 (fld f1) 並用 fmv.d 把前一次的結果搬到 f0。

    各指令延遲(cycle)

fmv.d=1,fld=6,fadd.d=4,fsd=1,addiu=1,ble=1\begin{aligned} &\text{fmv.d}=1,\quad \text{fld}=6,\quad \text{fadd.d}=4,\\ &\text{fsd}=1,\quad \text{addiu}=1,\quad \text{ble}=1 \end{aligned}
🔒

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

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

免費註冊

第 18 題6 分

Consider a computer system equipped with a single CPU with the following organization: It contains two cores, where each core implements superscalar processing with two functional units and can execute instructions out of order. The cores operate in single-threaded mode, meaning each core can only execute one thread at a time.

Two threads, X and Y, must be executed on this CPU. Each thread consists of the following sequence of operations. Unless noted or encountered a hazard, you can assume all operations take a single cycle to execute.

XY
A1: takes two cycles to executeB1: no dependencies
A2: depends on the result of A1B2: conflicts for a functional unit with B1
A3: conflicts for a functional unit with A1B3: no dependencies
A4: depends on the result of A2B4: depends on the result of B2

How many cycles will it take to execute these two threads? How many issue slots are wasted because of hazards?

(A) 4 cycles, 7 slots wasted
(B) 4 cycles, 3 slots wasted
(C) 5 cycles, 5 slots wasted
(D) 6 cycles, 7 slots wasted

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

這一題的完整詳解

核心觀念

本題考兩核心處理器的排程與功能單元衝突。每個核心每週期有兩個功能單元,因此最多可同時執行兩個操作;兩個核心分別執行執行緒 X、Y。

排程時要遵守:

  • 資料相依:後續操作必須等前一操作完成,才能執行。
  • 功能單元衝突:兩個操作需要同一功能單元時,不能重疊執行。
  • 超純量與亂序執行:每週期最多執行兩個操作;若操作彼此獨立且功能單元可用,可以同時執行。
  • 浪費的槽位:在四週期的總執行期間,每個核心每週期有兩個功能單元槽位。未執行操作的槽位計為浪費;執行兩週期的 A1 在第二週期仍占用一個功能單元槽位。

解題方法與排程

先分別排程兩條執行緒,再以較長的執行緒決定總週期數。

週期核心 1:執行緒 X核心 2:執行緒 Y
1A1(執行中)、空槽B1、B3
2A1(續行)、空槽B2、空槽
3A2、A3B4、空槽
4A4、空槽空槽、空槽

X 的 A1 需兩週期,因此 A2 必須等 A1 完成後才能執行。A3 與 A1 有功能單元衝突,也要等 A1 完成;第 3 週期 A2、A3 可同時執行。A4 依賴 A2,因此在第 4 週期執行。X 共需 4 週期。

Y 的 B1、B3 沒有相依,可在第 1 週期同時執行。B2 與 B1 有功能單元衝突,排在第 2 週期;B4 依賴 B2,排在第 3 週期。Y 共需 3 週期。

🔒

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

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

免費註冊

其他考古題