115 年 國立中正大學資訊工程學系碩士班《計算機系統》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊
📄 以下 2 題共用同一段題幹

Consider a 32-bit, byte-addressable system with a single cache that has the following specifications: total cache size = 4 KB4\ \mathrm{KB} (40964096 bytes) and cache block size = 1616 bytes. You will compare three cache organizations that all share the same total capacity and block size but differ in placement: (1) direct-mapped, (2) 4-way set-associative, and (3) fully-associative. Assume the cache is initially empty (all lines invalid). For the associative caches (4-way and fully-associative), assume LRU replacement. For writes, assume a write-back, write-allocate policy (i.e., on a write miss, the block is brought into the cache, and modified blocks are written back upon eviction).

The main memory size is increased significantly (e.g., from 4 GB4\ \mathrm{GB} to 16 GB16\ \mathrm{GB}).

第 1. 題30 分

Process the following 10 memory accesses in order, where each access is either a read (R) or write (W) to the given byte address:

(1) R 0x123456780x12345678
(2) R 0x1234567C0x1234567C
(3) W 0x123456700x12345670
(4) R 0x123466780x12346678
(5) R 0x123476780x12347678
(6) W 0x123486780x12348678
(7) R 0x123456740x12345674
(8) R 0x123496780x12349678
(9) R 0x1234667C0x1234667C
(10) W 0x1234867C0x1234867C

For each cache organization (direct-mapped, 4-way set-associative, and fully-associative), determine whether each of the 10 accesses is a cache hit or cache miss, and report the total number of hits and misses for that organization.

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

這一題的完整詳解

核心觀念

快取以「區塊」為單位存取。區塊大小為 1616 bytes,因此位移欄位需要

log⁡216=4 bits\log_2 16=4\text{ bits}

先將每個位址除以 1616,得到區塊位址;同一個區塊內的讀寫都命中同一筆快取資料。

快取共有 4096/16=2564096/16=256 個快取區塊:

  • 直接對映:有 256256 條快取列,區塊位址的低 88 bits 決定索引。
  • 4-way 組合關聯:有 256/4=64256/4=64 組,區塊位址的低 66 bits 決定組索引;同組超過 4 個區塊時,以 LRU 淘汰最久未使用者。
  • 全關聯:沒有組索引,區塊可放入任一快取列;本題只涉及 5 個不同區塊,容量足以容納全部。

解題方法

將不同區塊依首次出現順序標記如下:

標記區塊位址對應記憶體位址
A0x12345670x12345670 至 0x1234567F
B0x12346670x12346670 至 0x1234667F
C0x12347670x12347670 至 0x1234767F
D0x12348670x12348670 至 0x1234867F
E0x12349670x12349670 至 0x1234967F

10 次存取的區塊序列為:

A, A, A, B, C, D, A, E, B, DA,\ A,\ A,\ B,\ C,\ D,\ A,\ E,\ B,\ D

A 至 E 的區塊位址低 8 bits 都是 0x67,因此直接對映時會全部競爭同一條快取列。它們的低 6 bits 也都相同,因此在 4-way 組合關聯時會全部落在同一組。

逐次判定

次數區塊直接對映4-way 組合關聯全關聯
1AMissMissMiss
2AHitHitHit
3AHitHitHit
4BMissMissMiss
5CMissMissMiss
6DMissMissMiss
7AMissHitHit
8EMissMissMiss
🔒

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

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

免費註冊

第 2. 題5 分

In Problem 1, if the main memory size is increased significantly (e.g., from 4 GB4\ \mathrm{GB} to 16 GB16\ \mathrm{GB}), is it mandatory to increase the total cache size (currently 4 KB4\ \mathrm{KB}) for the system to function correctly?

(A) Increase
(B) Decrease
(C) No Change Required

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

這一題的完整詳解

核心觀念

快取容量決定可儲存多少資料區塊;主記憶體容量則決定可用的位址範圍。兩者相關,但主記憶體變大不代表必須增加快取容量。

題目指定位址為 32 位元、以位元組定址,因此可表示的位址數為 2322^{32},可定址範圍為 4 GB4\ \mathrm{GB}。若主記憶體擴大到 16 GB=23416\ \mathrm{GB}=2^{34} 位元組,系統須能使用 34 位元實體位址,或其他可涵蓋該範圍的位址擴充機制。增加快取容量並不能取代位址擴充。

解題方法

快取區塊大小為 1616 位元組,因此區塊內位移需要:

log⁡216=4 位元\log_2 16 = 4 \text{ 位元}

快取資料容量為 4 KB=40964\ \mathrm{KB}=4096 位元組,總區塊數為:

409616=256 個區塊\frac{4096}{16}=256 \text{ 個區塊}

主記憶體增大時,快取仍可維持相同的資料容量與區塊大小。若實體位址由 32 位元擴充為 34 位元,改變的是快取標籤(tag)所需的位元數,索引與區塊內位移所需的位元數不變:

組織方式區塊數/組數索引位元數34 位元位址下的標籤位元數
直接對映256 個區塊log⁡2256=8\log_2 256=834−8−4=2234-8-4=22
🔒

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

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

免費註冊

第 3. 題5 分

Our favorite program runs on Computer A in 10 seconds. Computer A uses a 5-stage pipeline, has an average CPI of 1.01.0, and operates at a clock rate of 2 GHz2\ \mathrm{GHz}. A computer designer is considering a new machine, Computer B, with the goal of reducing the execution time of this program to 6 seconds.

Computer B uses a deeper 10-stage pipeline. The increased pipeline depth allows for a higher clock rate; however, it also introduces additional pipeline overhead, such as larger branch misprediction penalties. As a result, the average CPI of Computer B increases to 1.21.2. The clock rate of Computer B is not yet determined.

Assume that the instruction count of the program is identical on Computer A and Computer B. Determine the clock rate that Computer B must achieve in order to meet the 6-second execution time target.

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

這一題的完整詳解

核心觀念

處理器的執行時間由指令數、平均每指令週期數(CPI)與時脈頻率共同決定:

執行時間=指令數×平均 CPI時脈頻率\text{執行時間} = \frac{\text{指令數}\times\text{平均 CPI}}{\text{時脈頻率}}

題目指出兩台電腦執行相同程式,因此指令數不變。Computer B 的 CPI 已知為 1.21.2,只要求出它達成目標執行時間所需的時脈頻率。

解題方法

先利用 Computer A 的資料求出程式的指令數。其時脈頻率為 2 GHz=2×109 Hz2\ \mathrm{GHz}=2\times10^9\ \mathrm{Hz},平均 CPI 為 1.01.0,執行時間為 1010 秒:

指令數=執行時間×時脈頻率平均 CPI=10×2×1091.0=20×109\text{指令數} = \frac{\text{執行時間}\times\text{時脈頻率}}{\text{平均 CPI}} = \frac{10\times 2\times10^9}{1.0} = 20\times10^9
🔒

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

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

免費註冊

第 4. 題10 分

Modern ARM processors often use a big.LITTLE architecture to reduce energy consumption by executing only performance-critical code on high-power cores while running the remaining code on energy-efficient cores. Consider an ARM-based SoC with one big core and one LITTLE core, where only one core is active at any time. The LITTLE core consumes 2 W2\ \mathrm{W} when active, while the big core consumes 8 W8\ \mathrm{W} when active. When a core is inactive, its power consumption can be ignored.

A given program takes 10 seconds to complete when executed entirely on the LITTLE core. Profiling shows that 30%30\% of the execution time is performance-critical code that can benefit from the big core. The big core executes this portion 4×4\times faster than the LITTLE core. There is no overhead for switching between cores.

The program is executed using the following strategy:

a. The performance-critical portion runs on the big core.
b. The remaining portion runs on the LITTLE core.

What is the average power consumption (in watts) of the program when executed using the ARM big.LITTLE strategy described above?

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

這一題的完整詳解

核心觀念

平均功率是程式執行期間消耗的總能量除以總執行時間:

Pavg=EtotalTtotalP_{\text{avg}}=\frac{E_{\text{total}}}{T_{\text{total}}}

各核心消耗的能量則為功率乘上該核心的執行時間:

E=P×TE=P\times T

題目給的「30%30\% 執行時間」以程式全程在 LITTLE 核心執行時的時間為基準,因此效能關鍵部分原本需 10×30%=310\times 30\%=3 秒;大核心快 44 倍,執行時間便是原來的 14\frac{1}{4}。

解題方法

程式全程在 LITTLE 核心需 1010 秒。效能關鍵部分在 LITTLE 核心上原需:

10×0.30=3 秒10\times 0.30=3\ \text{秒}

改由大核心執行後,所需時間為:

34=0.75 秒\frac{3}{4}=0.75\ \text{秒}

剩餘部分仍由 LITTLE 核心執行,時間為:

10×0.70=7 秒10\times 0.70=7\ \text{秒}
🔒

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

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

免費註冊

第 5. 題10 分

CPU Scheduling & I/O Performance: CPU scheduling strategies significantly affect I/O system throughput.

a. Explain why it is crucial to let I/O-bound processes acquire the CPU as early as possible to maximize I/O throughput.

b. Using the Multilevel Feedback Queue algorithm as an example, explain how it dynamically identifies I/O-bound processes and adjusts their priorities to achieve this goal.

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

這一題的完整詳解

核心觀念

本題考的是 I/O 密集型(I/O-bound)行程與 CPU 密集型(CPU-bound)行程的差異,以及多層回饋佇列(Multilevel Feedback Queue, MLFQ)如何利用行程的執行行為調整排程優先權。

I/O 密集型行程通常只需短暫使用 CPU,便會發出 I/O 請求並等待裝置完成;CPU 密集型行程則常持續執行較長時間。I/O 裝置與 CPU 可在不同工作上重疊運作,因此及早讓 I/O 密集型行程取得 CPU,可以使它更早發出 I/O 請求,減少裝置閒置時間,提升 I/O 系統的整體吞吐量。

解題方法

先追蹤 I/O 密集型行程的執行順序:

取得 CPU→發出 I/O 請求→等待 I/O→I/O 完成後回到就緒佇列\text{取得 CPU} \rightarrow \text{發出 I/O 請求} \rightarrow \text{等待 I/O} \rightarrow \text{I/O 完成後回到就緒佇列}

再觀察 MLFQ 如何從 CPU 使用行為推測行程類型:短時間使用 CPU 後主動等待 I/O 的行程,通常會保留較高優先權;長時間耗盡時間片的行程,則會逐漸被移到較低優先權佇列。

(a)為何要讓 I/O 密集型行程儘早取得 CPU?

I/O 密集型行程必須先使用 CPU,才能執行產生 I/O 請求的程式指令。它越早取得 CPU,就越早能啟動磁碟、網路或其他 I/O 裝置的工作。

I/O 裝置啟動後,行程會進入等待狀態;此時 CPU 可排程其他就緒行程,I/O 裝置則持續處理該請求。若 I/O 密集型行程長時間等候 CPU,裝置便無法及時收到下一個請求,可能出現閒置,降低每單位時間完成的 I/O 工作量。

因此,及早排程 I/O 密集型行程能縮短 I/O 請求的啟動延遲,增加 CPU 與 I/O 裝置重疊工作的機會,進而提高 I/O 吞吐量。

🔒

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

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

免費註冊

第 6. 題10 分

Copy-on-Write (COW) Mechanism: When using the Copy-on-Write mechanism to optimize the fork() system call:

a. Explain how the Page Table Entries (PTEs) for both the Parent and the Child should be configured immediately after fork() completes.

b. When the Child process attempts to write to a shared page, a Page Fault is triggered. How does the Kernel distinguish whether this Page Fault is caused by the Copy-on-Write mechanism or by an invalid memory access?

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

這一題的完整詳解

核心觀念

fork() 建立子行程時,核心不必立刻複製父行程的所有記憶體頁面。Copy-on-Write(COW,寫入時複製)讓父、子行程先共用同一批實體頁框;只有某一方嘗試修改頁面時,核心才複製該頁。

頁表項目(PTE)通常包含頁面是否存在、是否可寫、使用者/核心權限等資訊。核心也可利用 PTE 中的軟體保留位元,標記頁面為 COW。

解題方法

a. fork() 完成後的 PTE 設定

對父行程中原本可寫的頁面,核心讓父、子行程的 PTE 都指向同一個實體頁框,並將兩邊的可寫權限關閉;核心另外將這些 PTE 標記為 COW。概念如下:

PTE 項目父行程子行程
實體頁框指向共用頁框指向同一共用頁框
存在位元設為有效設為有效
可寫位元關閉關閉
COW 標記開啟開啟

核心會記錄共用頁框的參照數。由於頁面已從可寫改成唯讀,核心也須確保處理器不會繼續使用快取中的舊可寫權限,例如透過 TLB 失效處理。

原本就是唯讀的頁面可以繼續共用,但不應標成 COW;COW 標記只適用於原本可寫、因共用而暫時設為唯讀的頁面。

b. 區分 COW 頁錯誤與無效記憶體存取

🔒

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

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

免費註冊

第 7. 題30 分

Simple Reader-Writer Spinlock: Consider the following Simple Reader-Writer Spinlock implemented using atomic operations. Assume that atomic_sub(addr, val) atomically subtracts val from *addr and returns the old value (before subtraction). atomic_add performs atomic addition.

(a) Prove that mutual exclusion holds between a Writer and a Reader.

(b) Prove that multiple Readers can enter the Critical Section simultaneously (Concurrency).

#define MAXVAL 0x40000000

void init_spinlock(int* lock) {
*lock = MAXVAL;
}

void writer_lock(int* lock) {
while (1) {
int oldVal = atomic_sub(lock, MAXVAL);
if (oldVal == MAXVAL) return; // Successfully acquired lock
else atomic_add(lock, MAXVAL); // Failed, rollback
}
}

void reader_lock(int* lock) {
while (1) {
int oldVal = atomic_sub(lock, 1);
if (oldVal > 0) return; // Successfully acquired lock
else atomic_add(lock, 1); // Failed, rollback
}
}

void reader_unlock(int* lock) {
atomic_add(lock, 1);
}

void writer_unlock(int* lock) {
atomic_add(lock, MAXVAL);
}

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

這一題的完整詳解
載入中…

其他考古題