114 年 國立陽明交通大學資訊工程學系碩士班《計算機系統》
第 1 題4 分
In virtual memory management, which of the following are features of paging?
(A) To increase the size of the physical memory.
(B) To divide a process's address space into fixed-size blocks and load only necessary pages into physical memory.
(C) To reduce the CPU clock speed.
(D) To prevent processes from accessing each other's memory spaces.
登入後即可作答並保存紀錄。
核心觀念
分頁(paging)將行程的虛擬位址空間切成固定大小的頁(page),並將實體記憶體切成相同大小的頁框(frame)。作業系統透過頁表記錄虛擬頁面對應到哪個實體頁框;採用需求分頁時,只需在頁面被需要時才載入,不必一次把整個行程放進實體記憶體。
每個行程有自己的頁表。硬體進行位址轉換時,會依目前行程的頁表查找,並依頁表中的權限設定檢查存取,因此分頁機制也能支援行程間的記憶體隔離。
解題方法
逐項判斷敘述是否符合分頁的目的或機制。要留意「增加實體記憶體」與「讓程式可使用比實體記憶體更大的虛擬位址空間」是不同概念;後者是虛擬記憶體帶來的效果,並不代表實體記憶體容量真的增加。
選項分析
第 2 題4 分
Which of the following statements on memory management are true?
(A) Managing memory via the slab allocator not only minimizes internal and external fragmentations but also efficiently handles the frequent allocation and deallocation of kernel objects.
(B) As page tables are per-process data structures, the page table and other register values, such as the instruction pointer, are together stored in the process control block of each process.
(C) The x86 64-bit CPU architecture currently provides a 48-bit virtual address with support for page sizes of 4 KB, 2 MB, or 1 GB. Larger page sizes help reduce the overhead of page table traversal.
(D) After enabling the memory-management unit (MMU), the user program never accesses real physical addresses. That is, the user program can only work on the virtual address space.
登入後即可作答並保存紀錄。
核心觀念
本題考查核心記憶體配置、行程控制區塊(PCB)、x86-64 分頁,以及記憶體管理單元(MMU)的位址轉換。
- Slab allocator:依核心物件的大小建立快取,從 slab 中快速配置與回收固定大小的物件。
- PCB 與頁表:頁表存放在主記憶體中;PCB 通常保存頁表的位置或相關識別資訊,以及行程的執行狀態。
- 分頁大小:較大的頁面可用較少的頁表項目描述相同容量的記憶體,降低頁表遍歷開銷。
- MMU 位址轉換:程式使用虛擬位址,MMU 將虛擬位址轉成實體位址,再存取主記憶體。
解題方法
逐項核對敘述是否符合上述機制。判斷時特別留意用詞是否過度絕對,例如「頁表存於 PCB」與「頁表資訊由 PCB 指向」並不相同。
選項分析
(A) 正確。 Slab allocator 會依核心物件類型與大小管理物件快取,讓核心頻繁配置、釋放物件時可直接重用 slab 中的空閒位置,減少一般配置方式造成的內部與外部碎片,並提升配置效率。
第 3 題4 分
Which of the following statements on virtual memory are true?
(A) If the required page data is not in memory, the user process raises a page fault and the CPU runs the page fault handler to transfer the corresponding data into memory.
(B) Adopting copy-on-write during process creation allows the parent and child processes initially to share the same pages. If either process writes to a shared page, a copy of the page is created.
(C) In Linux, swap space is used for pages not associated with a file (known as anonymous memory); these pages include the stack and heap for a process.
(D) In x86 systems, when a CPU encounters a virtual address that results in a TLB miss, the operating system performs page table walking for translating a virtual address to a physical address.
登入後即可作答並保存紀錄。
核心觀念
虛擬記憶體透過頁表將虛擬位址對應到實體頁框。存取某頁時,若該頁不在主記憶體,處理器會發生頁面錯誤(page fault),交由作業系統核心處理。若頁面只是未載入,核心可從檔案或交換空間(swap space)讀入;若存取違反權限,則可能終止程序。
寫入時複製(copy-on-write, COW)則讓多個程序先共用同一實體頁,直到其中一方嘗試寫入,才複製出獨立頁面。
解題方法
逐一檢查敘述中的責任分工與適用範圍:頁面錯誤由誰觸發、COW 如何建立副本、Linux 哪些頁面會使用交換空間,以及 x86 的位址轉譯由硬體還是作業系統負責。
選項分析
(A) 錯誤。
當指令存取的頁面不在記憶體時,處理器偵測到頁表項目顯示該頁未駐留,會產生頁面錯誤例外,轉入核心的頁面錯誤處理程式。核心判斷原因後,才可能將所需資料載入記憶體並更新頁表。
此選項把觸發者說成「使用者程序 raises a page fault」,容易混淆程序造成的記憶體存取與例外的實際觸發機制:程序執行存取指令,頁面錯誤則由處理器偵測並產生。依題目公布答案的判定,這項敘述不正確。
第 4 題4 分
Which of the following statements on processes are true?
(A) A process control block serves as the repository for all the data needed to start, or restart, a process. It contains scheduling information, local variables, and kernel data structure.
(B) Interrupts cause the operating system to change a CPU core from its current task and to run a kernel routine. The system needs to save the current context of the process running on the CPU core so that it can restore that context when its processing is done.
(C) Traditional UNIX systems identify the init process as the root of all child processes. In UNIX systems, a process clones itself to create new processes. Thus, all the processes in the system are the descendants of the init process, either directly or indirectly.
(D) A user program must use system calls to access files stored in storage devices. But a program can directly access the allocated heap data from memory without the help from operating systems.
登入後即可作答並保存紀錄。
核心觀念
本題考查作業系統的程序管理,以及使用者程式透過系統呼叫與作業系統互動的界線:
- **程序控制區塊(PCB)**保存作業系統管理程序所需的資訊,例如程序狀態、排程資訊、暫存器內容、記憶體管理資訊與 I/O 狀態。
- 中斷處理會讓 CPU 暫停目前的執行流程,轉去執行核心的中斷服務程式;作業系統須保存足以恢復原執行流程的處理器狀態。
- 在傳統 UNIX 程序模型中,程序可透過
fork建立子程序;init是一般程序樹的根。 - 使用者程式存取檔案等受作業系統管理的資源,須透過系統呼叫;已配置的記憶體則可由程式直接讀寫。
解題方法
逐項檢查敘述中的關鍵資訊是否屬於作業系統的程序管理機制。特別要區分:
- PCB 保存的「程序管理資訊」與程序執行時使用的「區域變數」。
- 存取核心管理資源時所需的系統呼叫,與程式在自己的位址空間中讀寫記憶體。
選項分析
- (A) 錯誤。 PCB 的確保存排程資訊,也保存程序重新執行所需的處理器狀態等資料;但區域變數通常存放在程序的堆疊或其他使用者空間記憶體中,不屬於 PCB 的內容。
第 5 題4 分
Consider a system with the following resource allocation state. There are five processes – and three resource types. The resource allocation tuple means instances of resource type 1, instances of resource type 2, and instances of resource type 3.
| Process | Max Demand | Allocated | Available |
|---|---|---|---|
Given the current system state, which of the following are true when checking the safety of granting Process a request of according to the Banker's Algorithm?
(A) After granting the request, the system will remain in a safe state.
(B) If the system enters an unsafe state, there is still the possibility that no deadlock will actually occur.
(C) There are enough resources available to grant the request.
(D) The current system state is unsafe.
登入後即可作答並保存紀錄。
核心觀念
銀行家演算法先檢查請求是否符合兩項條件:
若符合,便假設核准請求,更新 Available、Allocation 與 Need,再用安全性演算法檢查是否存在一個安全序列。存在安全序列代表系統處於安全狀態。
「不安全」不等於「已死結」;它表示系統無法保證所有程序都能依序完成。
解題方法
先計算各程序的剩餘需求:
| 程序 | 原始 Need |
|---|---|
請求 ,逐項比較可得:
請求未超過 的剩餘需求,也未超過目前可用資源,因此可以進入安全性檢查。假設核准後:
- 的
- 的
從 開始,依序可讓 完成:
第 6 題4 分
Which of the following statements are true regarding interrupt handling in operating systems?
(A) Interrupts are signals that inform the processor of an event that needs immediate attention.
(B) Interrupts can only be generated by hardware, not software.
(C) When an interrupt occurs, the processor stops executing the current program and transfers control to the interrupt handler.
(D) Interrupts are prioritized, meaning the operating system may choose to delay handling a lower-priority interrupt in favor of a higher-priority one.
登入後即可作答並保存紀錄。
核心觀念
中斷(interrupt)是讓處理器暫停目前程式的執行流程,轉去處理事件的機制。處理器通常會先保存必要的執行狀態,再依中斷向量轉交給對應的中斷處理常式(interrupt handler);處理完成後,便能恢復原程式。
中斷可依來源與性質分類。硬體裝置可提出中斷請求;軟體也可透過指令產生軟體中斷。多個中斷同時待處理時,系統可依優先權安排處理順序,並延後較低優先權的中斷。
解題方法
逐項核對敘述是否符合中斷的定義、來源與處理方式。注意「轉交中斷處理常式」代表目前程式暫停,並非程式永久終止;中斷來源也不限於硬體。
選項分析
第 7 題4 分
Following is the memory map of the Linux utility program /usr/bin/cat. Which of the following statements are true?
🖼️【此處有附圖,見下方】
Memory map:
00400000-0040b000 r-xp 00000000 fd:01 1234567 /usr/bin/cat
0060a000-0060b000 r--p 0000a000 fd:01 1234567 /usr/bin/cat
0060b000-0060c000 rw-p 0000b000 fd:01 1234567 /usr/bin/cat
00e7a000-00e9b000 rw-p 00000000 00:00 0 [heap]
7f8b6c000000-7f8b6c021000 rw-p 00000000 00:00 0
7f8b6c021000-7f8b70000000 ---p 00000000 00:00 0
7f8b71a8d000-7f8b71aa3000 r-xp 00000000 fd:01 2345678 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8b71aa3000-7f8b71ca2000 ---p 00016000 fd:01 2345678 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8b71ca2000-7f8b71ca3000 r--p 00015000 fd:01 2345678 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f8b71ca3000-7f8b71ca4000 rw-p 00016000 fd:01 2345678 /lib/x86_64-linux-gnu/libgcc_s.so.1
7ffc445e7000-7ffc44608000 rw-p 00000000 00:00 0 [stack]
7ffc446da000-7ffc446dd000 r--p 00000000 00:00 0 [vvar]
7ffc446dd000-7ffc446df000 r-xp 00000000 00:00 0 [vdso]
fffffffff6000000-fffffffff6010000 --xp 00000000 00:00 0 [vsyscall]
(A) The CPU architecture is 32-bit.
(B) The program contains C library code.
(C) If we put shellcode on a buffer allocated by `malloc()`, the shellcode will be non-executable.
(D) The program has three child processes.
登入後即可作答並保存紀錄。
核心觀念
Linux 程序的記憶體映射會列出虛擬位址範圍、權限與對應檔案。權限欄中的 r、w、x 分別代表可讀、可寫、可執行;[heap] 是動態配置記憶體所在區域。記憶體映射也能顯示程序載入了哪些共享函式庫,但不能單靠映射列出子程序數量。
解題方法
圖中列出 /usr/bin/cat 的程式區段、[heap]、[stack],以及 /lib/x86_64-linux-gnu/libgcc_s.so.1 的映射。位址包含 7f...、7ffc... 等超過 32 位元範圍的值;堆積區權限為 rw-p,沒有執行權限。圖中沒有提供子程序數量。
選項分析
- (A) 錯。 位址範圍遠超過 32 位元可表示的範圍,而且函式庫路徑標示為
x86_64,顯示這是 64 位元環境,不是 32 位元。 - **(B) 對。
第 8 題4 分
Which of the following statements about the Round Robin (RR) scheduling algorithm are correct?
(A) It can lead to starvation of certain processes.
(B) It ensures quicker process completion for all processes.
(C) Decreasing the RR time quantum will increase the turnaround time.
(D) It ensures that all processes receive equal CPU time.
登入後即可作答並保存紀錄。
核心觀念
Round Robin(RR,循環先占)讓就緒佇列中的行程依序執行,每次最多使用一個時間片 。時間片用完仍未完成的行程會被中斷,並排到就緒佇列尾端;已完成的行程則離開佇列。
RR 的重點是輪流分配 CPU,讓就緒行程有機會取得執行時間。時間片太短會增加行程切換次數;切換需要額外時間,可能拉長行程的周轉時間。周轉時間是從行程提交到完成所經過的時間。
解題方法
逐項判斷 RR 是否會造成飢餓、是否保證行程更快完成、時間片大小對切換開銷的影響,以及 RR 如何分配 CPU。判斷時間片的影響時,須把行程切換所花的時間納入考量。
選項分析
(A) 錯誤。 在一般 RR 假設下,只要行程持續留在就緒佇列中,就會輪到它取得 CPU 時間。若就緒行程數有限且排程器持續運作,RR 不會讓特定行程無限期等候,因此不會造成飢餓。
第 9 題4 分
Which of the following statements on process schedulers and threads are true?
(A) Context switching is typically faster between threads than between processes. The reason is that threads share resources, including page table and user stack, of the process to which they belong.
(B) In Linux, Completely Fair Scheduler (CFS) allocates a larger time quantum to higher-priority processes. Processes with the same priority will receive the same time quantum.
(C) The dispatcher involved in the process scheduler switches process contexts between the current and the next-scheduled user processes in the user mode so as to minimize the dispatching latency.
(D) In contrast, during thread creation, the new thread shares many data structures, like memory space and file descriptors, with the parent process instead of copying them.
登入後即可作答並保存紀錄。
核心觀念
本題考查行程(process)與執行緒(thread)的資源共享方式,以及作業系統的排程與派遣流程。
同一行程中的執行緒共享行程的位址空間、程式碼、全域資料與開啟檔案等資源,但各執行緒有自己的暫存器狀態、程式計數器與堆疊。行程切換通常還須切換位址空間;同一行程內的執行緒切換通常不必更換位址空間,因此開銷較小。
解題方法
逐項核對敘述中的關鍵詞:執行緒是否共享該資源、排程器如何分配 CPU 時間,以及派遣器在哪個執行模式完成切換。選項若把共享資源範圍或切換所在模式說錯,即為錯誤。
選項分析
- (A) 錯誤。 同一行程中的執行緒通常共用位址空間與頁表,因此執行緒切換通常比行程切換快。不過,各執行緒有自己的使用者堆疊(user stack),並非共享堆疊。此選項將「使用者堆疊」列為共享資源,理由不成立。
第 10 題4 分
Which of the following statements on I/O systems are true?
(A) For most computers, the bootstrap is stored in Non-Volatile Memory (NVM) flash memory firmware on the system motherboard and mapped to a known memory location.
(B) In Linux, if the requested file is not already open, the directory structure is searched to locate the file by its name. The directory structure may reside in memory or on the storage devices.
(C) In Linux, page cache usually caches file in DRAM because DRAM is faster than storage devices and data can be retained in DRAM after the system powers down.
(D) To concurrently support multiple types of file systems, Virtual File System (VFS) layer separates file-system-generic operations from their implementation by defining a VFS interface.
登入後即可作答並保存紀錄。
核心觀念
I/O 系統會透過開機韌體初始化電腦,並由作業系統管理檔案與儲存裝置。Linux 的檔案系統設計中,目錄查找、頁面快取與虛擬檔案系統(VFS)各自負責不同工作:
- 開機韌體:開機所需的初始程式須儲存在斷電後仍能保留內容的非揮發性記憶體。
- 路徑查找:作業系統依據檔名與目錄路徑尋找檔案;查找所需的目錄資訊可在記憶體快取,也可從儲存裝置讀取。
- 頁面快取:利用較快的主記憶體暫存檔案資料,減少存取儲存裝置的次數。
- VFS:提供通用的檔案操作介面,讓核心能以一致方式處理不同檔案系統。
解題方法
逐項檢查敘述是否符合上述機制,特別留意記憶體是否具備斷電保留資料的能力。DRAM 是揮發性記憶體,斷電後無法保留資料;這是判斷選項 (C) 的關鍵。
選項分析
第 11 題4 分
In a pipelined processor, a program has instructions belonging to load and store instructions. This program spends of its execution time for load instructions and of its execution time for store instructions. Since the data cache miss rate is high in this program, the processor architect proposes a new data cache architecture that improves the execution time of load instructions ( faster) and execution time of store instructions ( faster). Then, this new processor will achieve speedup. Which statements are correct when using the processor with this new cache architecture?
(A) This new cache architecture helps increase the processor's clock frequency.
(B) The value of cycle per instruction (CPI) becomes small after using this new cache architecture in the processor.
(C) This new cache architecture increases the instruction counts (ICs).
(D) This new cache architecture helps reduce the cache miss penalty.
登入後即可作答並保存紀錄。
核心觀念
這題考阿姆達爾定律,以及處理器效能公式:
某部分執行時間加速 倍後,整體加速比為:
其中 是該部分原本占總執行時間的比例。題目給的「載入與儲存指令占指令數 」和「載入、儲存各占執行時間的比例」是不同資訊;計算整體加速比時要使用執行時間比例。
解題方法
載入指令占總執行時間 ,加速 倍;儲存指令占 ,加速 倍;其餘 的執行時間不變。因此:
整體加速比為:
這與題目所述的 加速相符。
選項分析
第 12 題4 分
A directed-mapped data cache has a memory address length of 32 bits. The sizes of the tag, index, and offset fields in this directed-mapped cache are 26 bits, 4 bits, and 2 bits, respectively. The processor executes Program 1 and observes that its cache miss rate is high. What kind of cache misses causes such a problem when using a directed-mapped cache in this processor?
Program 1:
🖼️【此處有附圖,見下方】
addi $t0, $0, 3
loop: beq $t0, $0, done
lw $t1, 0x4($0)
lw $t2, 0x8($0)
lw $t3, 0xC($0)
lw $t4, 0x10($0)
addi $t0, $t0, -1
j loop
done:
(A) Compulsory cache miss
(B) Conflict cache miss
(C) Capacity cache miss
(D) Cold start cache miss
登入後即可作答並保存紀錄。
核心觀念
直接映射快取的每個主記憶體區塊只能放在指定的快取列。快取第一次讀取某個區塊時,因為區塊尚未載入而發生的 miss,稱為強制性 miss,也稱為冷啟動 miss。
解題方法
從原卷可讀到快取位址欄位為 tag 26 位元、index 4 位元、offset 2 位元;程式在迴圈中依序讀取位址 0x4、0x8、0xC、0x10,迴圈執行三次。
區塊大小為 bytes,快取共有 列。四個讀取位址的快取列索引分別為 1、2、3、4,因此它們不會互相競爭同一列。若快取一開始為空,第一次讀取這四個位址時各 miss 一次;後兩輪重複讀取相同位址,則會命中。因此 12 次資料讀取中有 4 次 miss,miss rate 為 。
選項分析
第 13 題4 分
A data cache usually has multiple cache blocks. The set-associative cache includes tag, index, and offset fields to manage each cache block. What are the impacts when increasing the size of cache blocks in a data cache?
(A) The large cache block facilitates the usage of temporal locality on the data cache.
(B) Large cache miss penalty.
(C) Reducing the tag overhead.
(D) Decreasing the cache miss rate.
登入後即可作答並保存紀錄。
核心觀念
快取區塊(cache block)是主記憶體與快取之間搬移資料的基本單位。區塊變大時,一次快取未命中會載入更多相鄰資料,因此可能利用空間區域性:程式存取某個位址後,接著也可能存取附近位址。
快取的未命中率與未命中代價是不同指標:
- 未命中率:存取時未命中的比例。
- 未命中代價:發生未命中後,等待資料載入所需的時間。
若快取總容量固定,區塊變大也會使快取可容納的區塊數變少,並讓單一區塊佔用更多儲存空間。
解題方法
逐項判斷區塊變大對區域性、未命中代價與標籤開銷的影響。判斷未命中率時,採用題目所考的典型效果:較大的區塊能帶入更多相鄰資料,降低空間區域性所造成的未命中;但此效果通常只在區塊大小適當時成立。
選項分析
第 14 題4 分
A data cache in a processor employs a 2-way set-associative cache where the word size is 32 bits. The sizes of the tag, index, and offset fields in this set-associative cache are 26 bits, 4 bits, and 2 bits, respectively. Which statements are correct when this processor executes Program 2?
Program 2:
addi $t0, $0, 4
loop: beq $t0, $0, done
lw $t1, 0x6($0)
lw $t2, 0x46($0)
addi $t0, $t0, -1
j loop
done:
(A) The cache miss rate is .
(B) Increasing the size of the cache can reduce the cache miss rate.
(C) The cache miss rate will increase when using the directed-mapped cache where its tag, index, and offset sizes are 27 bits, 3 bits, and 2 bits, respectively.
(D) The cache miss rate will increase when using the fully associative cache.
登入後即可作答並保存紀錄。
核心觀念
快取的區塊大小由位移欄位(offset)決定:
每個區塊含一個 32-bit word。區塊編號為 ;索引欄位決定映射到哪個 set,標籤欄位用來辨認該 set 中的區塊。
快取未命中率的計算方式是:
解題方法
程式先將 $t0 設為 4。每次迴圈執行兩次 lw,接著遞減 $t0;因此迴圈執行 4 次,總共有 次資料快取存取。
兩個載入位址的區塊編號為:
兩者的 set 索引都是區塊編號除以 的餘數:
第 15 題4 分
A processor runs at 4 GHz and has a CPI of 1.4 without including the stall cycles due to cache misses. Load and store instructions count for of all instructions. The processor has an I-cache and a D-cache. The hit time is 1 clock cycle. The I-cache has a miss rate. The D-cache has a miss rate on load and store instructions. The miss penalty is 50 ns, which is the time to access and transfer a cache block between main memory and the cache. Which of the following statements are correct?
(A) The miss penalty of this processor is 200 clock cycles.
(B) The average memory access time (AMAT) for instruction access is 6 clock cycles.
(C) The number of stall cycles per instruction is 10 clock cycles.
(D) The overall IPC of this processor is 0.096.
登入後即可作答並保存紀錄。
核心觀念
快取未命中造成的平均停滯週期,可用「每條指令的平均未命中次數 × 未命中懲罰」計算。指令快取每條指令都要取指;資料快取則只有負載與儲存指令會存取。
未命中懲罰以時鐘週期表示時:
平均記憶體存取時間(AMAT)則為:
解題方法
處理器頻率為 ,因此每秒有 個時脈週期。主記憶體未命中懲罰為 秒,換算成週期數:
計算每條指令的快取停滯週期:
- **I-cache:**每條指令取指一次,平均停滯為 個週期。
第 16 題4 分
Which of the following statements are true?
(A) In 2's complement, the value 0 has a unique representation.
(B) In IEEE 754 single-precision format, the value 0 has two different representations.
(C) Overflow will never occur when adding two 2's complement numbers of different signs.
(D) Storing the 32-bit number 0xABCDD CBA in memory results in the same outcome regardless of whether little endian or big endian is used.
登入後即可作答並保存紀錄。
核心觀念
本題考查二補數表示法、IEEE 754 浮點數的正負零、二補數加法溢位,以及大小端序的記憶體排列。
解題方法與選項分析
(A) 正確。
在固定位元數的二補數表示法中, 只有一種表示法:所有位元皆為 。例如 8 位元的 為 00000000,沒有另一種負零表示法。
(B) 正確。
IEEE 754 單精度浮點數的零有兩種表示法: 與 。兩者的指數欄與尾數欄皆為 ,但符號位元不同:
- :
0x00000000 - :
0x80000000
第 17 題4 分
Given an IEEE 754 single-precision representation format in the table below and the bias value is 127. Which of the following statements are correct?
(A) The number has the single-precision representation:
Sign , Exponent , Fraction .
(B) The number has the single-precision representation:
Sign , Exponent , Fraction .
(C) The smallest positive single-precision normalized number is .
(D) The smallest positive single-precision denormalized number is .
🖼️【此處有附圖,見下方】
| S | Exponent (8 bits) | Fraction (23 bits) |
|---|
| Exp. | Fraction | Meaning |
|---|---|---|
| 0 | 0 | 0 |
| 0 | Non-zero | de-normalized number |
| 1–254 | Anything | floating-point number |
| 255 | 0 | infinity |
| 255 | Non-zero | NaN (Not a number) |
登入後即可作答並保存紀錄。
核心觀念
IEEE 754 單精度格式由 1 個符號位元、8 個指數位元與 23 個尾數欄位組成,偏移值為 。指數欄位全為 時,尾數為 表示零,尾數非零表示非規格化數;指數欄位為 到 時表示規格化數;指數欄位全為 時表示無限大或 NaN。
解題方法
依原卷圖,選項 (B) 的數值是 。將各數值化為二進位並套用單精度的指數範圍與尾數規則,即可判斷表示方式是否正確。
選項分析
(A)
,其指數為 ,加上偏移值後為 ;尾數欄位為 。負數的符號位元通常寫作 。不過,選項寫的是「Sign 」:若將它解讀為負號或符號值,選項可接受;若嚴格視為符號欄位的位元值,則應為 ,不能寫成 。因此此選項有記號歧義。
(B)
先正規化:
此數小於最小規格化正數,須用非規格化格式表示,其數值形式為 。令其等於原數:
第 18 題4 分
Consider the following code sequence executing on a 5-stage pipelined processor. The processor has both the hazard detection unit and the forwarding unit for data hazard. Assume that the code sequence starts executing at clock cycle 1. At clock cycle 8, where do the two ALU inputs come from?
add x28, x31, x29
ld x31, 32(x29)
and x30, x29, x31
sd x5, 20(x30)
sub x5, x5, x30
or x29, x29, x30
🖼️【此處有附圖,見下方】
(A) Both are from ID/EX.
(B) One is from ID/EX and one is from EX/MEM.
(C) One is from ID/EX and one is from MEM/WB.
(D) One is from EX/MEM and one is from MEM/WB.
登入後即可作答並保存紀錄。
核心觀念
五級管線依序為 IF、ID、EX、MEM、WB。ld 的資料要到 MEM 階段末才可用;若下一條指令立刻讀取該暫存器,危障偵測單元會插入一個停滯週期。轉送單元則會在後續指令進入 EX 時,將較新的結果從 EX/MEM 或 MEM/WB 轉送給 ALU。
解題方法
原卷圖中列出的指令順序為 add、ld、and、sd、sub、or;圖示也包含危障偵測單元與轉送路徑。ld x31, 32(x29) 緊接著被 and x30, x29, x31 使用,因此需停滯一個週期。管線排程如下(「泡泡」表示插入的空操作):
| 指令 | 第 1 週期 | 第 2 週期 | 第 3 週期 | 第 4 週期 | 第 5 週期 | 第 6 週期 | 第 7 週期 | 第 8 週期 |
|---|---|---|---|---|---|---|---|---|
add x28, x31, x29 | IF | ID | EX | MEM | WB | |||
ld x31, 32(x29) | IF | ID | EX | MEM | WB | |||
and x30, x29, x31 | IF | ID | ID | EX | MEM | WB | ||
sd x5, 20(x30) | IF | IF | ID | EX | MEM |
第 19 題4 分
Consider a pipeline CPU with five stages: IF, ID, EX, MEM, WB. Stall cycles due to mis-predicted branches increase the CPI of the pipeline. Given a code sequence with instruction mix as follows: R-type: , beq: , and lw & sw: . Assume branch prediction accuracy is and there are no data hazards and cache misses. It is clear that the system suffers from extra CPIs due to mis-predicted branches. Which of the following statements about the extra CPI are correct?
(A) The extra CPI is 0.4 if the mis-predicted branch outcomes are corrected in the MEM stage.
(B) The extra CPI is 0.6 if the mis-predicted branch outcomes are corrected in the MEM stage.
(C) The extra CPI is 0.4 if the mis-predicted branch outcomes are corrected in the ID stage.
(D) The extra CPI is 0.2 if the mis-predicted branch outcomes are corrected in the ID stage.
登入後即可作答並保存紀錄。
核心觀念
分支預測錯誤會使處理器清除錯誤路徑上已進入管線的指令,造成額外停滯週期。額外 CPI 可由下式計算:
題目中只有 beq 是分支指令,因此分支指令比例為 ;預測正確率為 ,所以預測錯誤率為 。
解題方法
分支在某階段確認方向時,該階段之前已進入管線的錯誤路徑指令需要被清除。因此,修正階段越晚,錯誤預測造成的停滯週期越多。
- **在 MEM 階段修正:**分支指令到達 MEM 時,後續錯誤路徑指令已分別進入 IF、ID、EX,共須清除 條指令,停滯 個週期。
第 20 題4 分
Consider the 2-bit predictor shown in the figure below, and assume the predictor starts at the top-left state (i.e., the “strongly predict taken” state). Given the branch outcome sequence: N, T, N, N, T, where T = taken and N = not-taken, which of the following statements are correct?
🖼️【此處有附圖,見下方】
(A) The accuracy rate is .
(B) The overall accuracy rate is if the pattern repeats twice (i.e., N, T, N, N, T, N, T, N, N, T).
(C) The overall accuracy rate is if the original pattern repeats three times.
(D) The overall accuracy rate is about if the original pattern repeats 10000 times.
登入後即可作答並保存紀錄。
核心觀念
二位元分支預測器以四個狀態記錄分支傾向:強預測跳躍()、弱預測跳躍()、弱預測不跳躍()、強預測不跳躍()。
每次分支都要先依目前狀態預測,再依實際結果更新狀態。準確率為:
同一序列重複出現時,預測器會延續上一輪的結束狀態,不會重設為初始狀態。
解題方法
依原圖,上方兩個狀態都預測 ,下方兩個狀態都預測 。狀態依序沿「左上、右上、右下、左下」排列;實際結果為 時往強預測不跳躍方向移動一格,為 時往強預測跳躍方向移動一格,最兩端則有自我迴圈。
圖中的完整轉移關係如下:
| 目前狀態(圖中位置) | 預測 | 實際為 時的下一狀態 | 實際為 時的下一狀態 |
|---|---|---|---|
| (左上) | |||
| (右上) | |||
| (右下) | |||
| (左下) |
針對每輪的實際序列 ,逐次模擬:
| 輪次 | 各次分支「預測前」的狀態 | 預測序列 | 各次是否正確 | 結束狀態 | 命中數 |
|---|---|---|---|---|---|
| 第一次 | 錯、對、錯、錯、錯 |
Consider the following RAID 5 configuration using four identical disks (Disk 0–3). The specification of each disk is:
Capacity: 1 TB
Read throughput: 100 MB/s
Write throughput: 100 MB/s
🖼️【此處有附圖,請對照原卷】
RAID 5 layout:
| Disk 0 | Disk 1 | Disk 2 | Disk 3 |
|---|---|---|---|
| A1 | A2 | A3 | Ap |
| B1 | B2 | Bp | B3 |
| C1 | Cp | C2 | C3 |
| Dp | D1 | D2 | D3 |
第 21 題
How much data can be stored in the disk array?
(A) 1 TB
(B) 2 TB
(C) 3 TB
(D) 4 TB
登入後即可作答並保存紀錄。
核心觀念
RAID 5 使用分散式同位元(parity)提供單一磁碟故障容錯。每個 stripe 中有一份同位元資料,其餘磁碟空間存放資料;同位元會分散在不同磁碟,不會固定占用同一顆磁碟。
解題方法
圖中共有 4 顆磁碟,每顆容量為 1 TB。版面顯示同位元依序分散於 Disk 3、Disk 2、Disk 1、Disk 0;每個 stripe 都有 3 個資料區塊和 1 個同位元區塊。因此,陣列容量中相當於 1 顆磁碟的空間用於同位元,資料可用容量為:
第 22 題
What is the maximum read throughput when an application reads data from the disk array?
(A) 100 MB/s
(B) 200 MB/s
(C) 300 MB/s
(D) 400 MB/s
登入後即可作答並保存紀錄。
核心觀念
RAID 5 以分散式同位元保護資料。每個 stripe 會在 顆磁碟中放置 個資料區塊與 個同位元區塊。一般讀取資料時不必讀取同位元區塊,因此以同一個 stripe 的資料讀取量計算,讀取頻寬由 顆資料磁碟提供。
解題方法
圖中每一列代表一個 stripe,例如第一列由 Disk 0、Disk 1、Disk 2 儲存資料,Disk 3 儲存同位元;後續各列則輪替同位元位置。四顆磁碟各有 的讀取吞吐量。
讀取同一個 stripe 的資料時,三顆資料磁碟可同時讀取,同位元所在磁碟不需參與。因此最大讀取吞吐量為:
選項分析
第 23 題
What is the maximum number of failed disks that can be tolerated?
(A) 0
(B) 1
(C) 2
(D) 3
登入後即可作答並保存紀錄。
核心觀念
RAID 5 以分散式同位元(parity)提供容錯能力。每個 stripe 的資料分散在多顆磁碟上,並以 XOR 同位元資訊保存一份冗餘;單一磁碟故障時,可利用其餘磁碟上的資料與同位元重建遺失內容。
解題方法
圖中第 23 題詢問 RAID 5 最多可容忍幾顆磁碟故障。題目給定 4 顆磁碟,版面顯示同位元位置在各列輪替;每個 stripe 都只有一份同位元冗餘。
因此,故障 1 顆磁碟時,該磁碟遺失的資料或同位元可由其餘磁碟重建。若同時故障 2 顆磁碟,單一同位元資訊不足以一般性地還原兩份遺失內容,所以 RAID 5 最多容忍 1 顆磁碟故障
第 24 題
Assume that none of the disk data is cached in memory. What is the minimum number of disks that need to be involved in a write to the disk array?
(A) 1
(B) 2
(C) 3
(D) 4
登入後即可作答並保存紀錄。
核心觀念
RAID 5 以 XOR 計算同一 stripe 的同位元資料,並將同位元分散在不同磁碟。更新單一資料區塊時,必須同步更新該 stripe 的同位元區塊,才能維持容錯能力。
解題方法
原卷頁圖可讀到第 24 題是在問磁碟資料未快取時,寫入磁碟陣列至少要涉及幾顆磁碟;題目所列配置為四顆磁碟組成的 RAID 5,同一列中的資料與同位元分布在不同磁碟。
採用單一資料區塊的「讀取-修改-寫回」方式:先讀出舊資料與舊同位元,計算新同位元,再寫回新資料與新同位元。以 XOR 表示,新同位元可寫為:
Assume a custom CPU adopting multi-level page tables, where the page size, virtual address space size, and page table entry size are set to 32 KB, B, and 16 B, respectively. This custom CPU only has one register to hold the physical address of the topmost level of the multi-level page tables.
第 25 題
What is the minimum number of levels for this multi-level page table?
(A) 3
(B) 4
(C) 5
(D) 6
登入後即可作答並保存紀錄。
核心觀念
虛擬位址分成「頁內位移」與「虛擬頁號」。多層頁表以虛擬頁號的位元作為各層索引;每張頁表可容納的頁表項目數,決定每一層最多能索引多少位元。
解題方法
頁面大小為 ,因此頁內位移占 位元。虛擬位址空間大小為 ,虛擬位址共 位元,故虛擬頁號占:
每個頁表項目為 。一頁頁表可容納:
個頁表項目,所以每一層最多使用 位元作為索引。要索引完整的 位元虛擬頁號,所需層數至少為:
第 26 題
If the number of levels is set to the minimum, what is the maximum number of pages in the bottom level?
(A)
(B)
(C)
(D)
登入後即可作答並保存紀錄。
核心觀念
多層頁表每一層以虛擬頁號的一部分作為索引。頁表頁面大小為 B,每個頁表項目(PTE)為 B,因此一個頁表頁面可容納:
個頁表項目,也就是每層最多可用 個位元索引。虛擬位址空間共有 B,頁面大小為 B,因此虛擬頁數為:
換言之,虛擬頁號需要 個位元。
解題方法
若頁表層數為 ,最多能涵蓋的虛擬頁號位元數為 。要涵蓋全部 個位元,最少層數為:
在這個最少層數的配置中,底層頁表每頁仍有 個項目,對應 個虛擬頁。涵蓋全部 個虛擬頁所需的底層頁表頁數為:
第 27 題
If the number of levels is set to the minimum, how many pages are there in the top level?
(A) 4
(B) 3
(C) 2
(D) 1
登入後即可作答並保存紀錄。
核心觀念
多層頁表以虛擬頁號的各段索引逐層查表。每張頁表的項目數由頁面大小除以頁表項目大小決定;若每層都使用一整張頁表,則每層最多可涵蓋固定數量的索引組合。
解題方法
頁面大小為 B,頁表項目大小為 B,因此每張頁表可容納:
虛擬位址空間有 B,每頁為 B,所以虛擬頁數為:
每一層最多提供 個索引位置。若共有 層,最多可索引 個虛擬頁。要涵蓋全部 個虛擬頁,最少層數為:
A pipelined processor contains a 64 KB L1 data cache, where the memory address length is 32 bits and the block size is 64 bytes. This data cache employs a 4-way set-associative cache architecture. The size of physical memory on this processor is 4 GB.
第 28 題
How many cache blocks are in the 64 KB L1 data cache?
(A) 0.5K cache blocks
(B) 1K cache blocks
(C) 1.5K cache blocks
(D) 2K cache blocks
登入後即可作答並保存紀錄。
核心觀念
快取區塊數由快取容量除以每個區塊的大小:
題目中的 64 KB 是資料快取總容量,區塊大小為 64 bytes。4-way set-associative(四路組合)會影響組數與位址切分,不會改變快取區塊總數。
解題方法
以 換算:
第 29 題
How many bits are used in the tag of such a data cache?
(A) 14 bits
(B) 15 bits
(C) 17 bits
(D) 18 bits
登入後即可作答並保存紀錄。
核心觀念
快取位址會分成標籤(tag)、索引(index)與區塊位移(block offset)三部分:
區塊位移用來定位區塊內的位元組;索引用來選擇快取集合;標籤則用來判斷該集合中是否存有要求的記憶體區塊。
解題方法
位址長度為 32 位元,區塊大小為 64 bytes,因此區塊位移需要:
快取共有 64 KB,採 4-way set-associative,每個區塊為 64 bytes。集合數為:
因此索引需要:
第 30 題
Which fields in the data cache will increase when increasing the length of the memory address from 32 bits to 64 bits?
(A) Tag
(B) Index
(C) Offset
(D) Valid bit
登入後即可作答並保存紀錄。
核心觀念
快取位址通常分成 Tag(標籤)、Index(索引)、Offset(區塊位移)。在快取容量、區塊大小與組相連度固定時,Index 和 Offset 的位數由快取組態決定;位址長度增加時,增加的位元會落在 Tag。
解題方法
先由快取組態算出 Index 與 Offset:
因此:
Tag 位數為位址長度扣除 Index 與 Offset:
Consider the execution of the following code on a 5-stage pipelined processor shown in the figure below. The processor includes both a hazard detection unit and a forwarding unit for data hazards, though these components are not shown in the figure. Assume the code sequence starts execution at clock cycle 1.
ld x31, 32(x5)
sub x30, x31, x5
ld x31, 20(x30)
add x29, x29, x30
or x5, x5, x30
🖼️【此處有附圖,請對照原卷】
第 31 題
What instruction is in the EXE stage at clock cycle 5?
(A) ld
(B) sub
(C) add
(D) bubble
登入後即可作答並保存紀錄。
核心觀念
五階段管線依序為 IF(取指)、ID(解碼/讀暫存器)、EX(執行)、MEM(記憶體存取)與 WB(寫回)。載入指令 ld 的資料要到 MEM 階段後才可供後續指令使用;若緊接的指令在 EX 階段需要該資料,危障偵測單元會插入一個 bubble,並暫停取指與解碼一個週期。轉送單元無法消除這種立即的載入使用危障。
解題方法
圖中是五階段管線;題目程式的前兩條指令是 ld x31, 32(x5) 與 sub x30, x31, x5。sub 需要前一條 ld 載入的 x31,因此必須停一個週期。各週期的 EX 階段如下:
| 時脈週期 | EX 階段 |
|---|---|
| 1 | 空 |
| 2 | 空 |
| 3 | ld x31, 32(x5) |
| 4 | bubble |
| 5 | sub x30, x31, x5 |
第 32 題
What instruction is in the MEM stage at clock cycle 5?
(A) ld
(B) sub
(C) add
(D) bubble
登入後即可作答並保存紀錄。
核心觀念
五階段管線依序為 IF(取指)、ID(解碼/讀暫存器)、EX(執行)、MEM(存取記憶體)與 WB(寫回)。載入指令的資料要到 MEM 階段結束後才可供後續指令使用;因此,緊接在 ld 後且使用其載入結果的指令,即使有轉送單元,仍須停一個時脈週期。
解題方法
圖中列出的指令順序是 ld x31, 32(x5)、sub x30, x31, x5、ld x31, 20(x30)、add x29, x29, x30、or x5, x5, x30。第一個 ld 載入 x31,緊接的 sub 立即使用 x31,形成載入使用資料相依,故管線需插入一個 bubble。
管線在週期 4 停住 sub,並在 EX 階段插入 bubble。週期 5 時,sub 進入 EX、第二個 ld 在 ID,而週期 4 插入的 bubble 進入 MEM:
第 33 題
What instruction is in the WB stage at clock cycle 5?
(A) ld
(B) sub
(C) add
(D) bubble
登入後即可作答並保存紀錄。
核心觀念
五階段管線依序為:取指令(IF)、指令解碼與讀取暫存器(ID)、執行(EX)、存取記憶體(MEM)、寫回暫存器(WB)。
即使處理器具有轉送(forwarding),緊接在載入指令後、使用其載入結果的指令,仍會造成 load-use hazard,需要停頓一個週期。停頓時凍結 PC 與 IF/ID,並在 EX 插入氣泡;已進入後方階段的指令仍持續前進。
解題方法
圖中以 IF/ID、ID/EX、EX/MEM、MEM/WB 四組管線暫存器分隔五個階段,最右側為寫回路徑。依題意,處理器另有危障偵測與轉送單元,且第一條指令從第 1 週期開始取指令。
將前三條指令標記為:
- :
ld x31, 32(x5) - :
sub x30, x31, x5 - :
ld x31, 20(x30)
需要使用 載入的 x31,因此兩者之間有 load-use hazard。前五個週期如下:
| 時脈週期 | IF | ID | EX | MEM | WB |
|---|---|---|---|---|---|
| 1 | — | — | — | — | |
| 2 | — | — | — | ||
| 3 | — | — |
第 34 題
What are the values of signals ALUsrc and MemToReg, respectively, at clock cycle 5?
(A) 0, 0
(B) 0, 1
(C) 1, 0
(D) 1, 1
登入後即可作答並保存紀錄。
核心觀念
五階段管線依序為 IF(取指)、ID(解碼)、EX(執行)、MEM(存取記憶體)、WB(寫回)。ALUsrc 控制 EX 階段 ALU 第二個輸入的來源:取暫存器值時為 0,取立即數時為 1;MemToReg 控制寫回資料的來源:取 ALU 結果時為 0,取記憶體讀值時為 1。
解題方法
圖中列出五個階段與指令序列;第一個 ld 後緊接著使用 x31 的 sub,形成 load-use 資料相依,因此 hazard detection unit 會讓 sub 停一個週期。到第 5 個時脈,第一個 ld 在 WB、sub 在 EX:
| 時脈 | 第一個 ld | sub |
|---|---|---|
| 1 | IF | — |
| 2 | ID | IF |
| 3 | EX | ID |
| 4 | MEM | ID(停滯) |
| 5 | WB | EX |