免費詳解 / 交大 / 硬體 / 105

105 交大資工所考古題解答|硬體逐題詳解

105 交大資工所硬體考古題的逐題詳解,共 29 題,免費公開。

逐題詳解

14 分

Which of the following statements are true?

(a) Threads within the same process share the same heap and stack.

(b) Bootstrap program is loaded at power-up or reboot and typically stored in RAM.

(c) A two phase locking protocol for atomic transactions has two phases. One phase obtains locks but not release any locks and another release locks but not obtain any new locks.

(d) Caching is an important structure that performed at many levels in a computer.

(e) A process is a program in execution. It is a unit of work within the system. Program is an active entity, process is a passive entity.

(a) 同一 process 的 thread 共用 heap(與 code、data),各自有自己的 stack → F

(b) bootstrap program 存在 ROM/EEPROM(firmware),不是 RAM → F

(c) 2PL:growing phase 只取 lock、shrinking phase 只放 lock → T

(d) caching 在 computer 的許多層級都用到 → T

(e) process 是執行中的 program,是 active entity;program 是 passive entity,敘述顛倒 → F

(c), (d)

24 分

Which of the following statements are true?

(a) Computer system can be divided into four components including hardware, operating system, application programs and users.

(b) Most operating systems have three general methods used to pass parameters including passing in registers, storing in a block and pushing onto a stack.

(c) A CPU-bound process spends more time doing computations and consists of many short CPU bursts.

(d) The goal of multi-threads is to utilize CPU in maximum. Hence, we should create threads as much as possible.

(e) It is important that the short-term scheduler select a good process mix of I/O-bound and CPU-bound processes.

(a) hardware、OS、application programs、users 四個部分 → T

(b) system call 傳參數的三種方法:register、block(table)、stack → T

(c) CPU-bound process 是少數幾個長的 CPU burst;多個短 burst 是 I/O-bound → F

(d) thread 不是越多越好,過多會增加切換與同步成本 → F

(e) 挑選 I/O-bound 與 CPU-bound 混合的是 long-term scheduler,不是 short-term → F

(a), (b)

34 分

Which of the following statements are true?

(a) An I/O-bound process spends more time doing I/O than computations and consists of a few long CPU bursts.

(b) The long-term scheduler selects processes among the processes that are ready to execute and allocates the CPU to one of them.

(c) In UNIX, the fork() system call is used to load a new program into the process' memory space.

(d) Remote procedure call (RPC) abstracts procedure calls between processes on networked systems.

(e) Main memory is a volatile storage device that loses its contents when power is turned off.

(a) I/O-bound 是許多短的 CPU burst → F

(b) 選 ready process 並分配 CPU 的是 short-term scheduler(CPU scheduler) → F

(c) 載入新 program 的是 exec,fork 是複製 process → F

(d) RPC 把跨網路的 procedure call 抽象化 → T

(e) main memory 是 volatile → T

(d), (e)

44 分

Which of the following statements are true?

(a) Dual-mode operation allows OS to protect itself and other system components. If OS doesn't have dual-mode operation, every user can modify the kernel system without permissions.

(b) DMA is used for high-speed I/O devices to transfer blocks of data from buffer storage directly to main memory without CPU intervention.

(c) The user program can deals with both of logical addresses and physical addresses.

(d) Message passing is the only mechanism of inter-process communication.

(e) If a system does not employ either deadlock-prevention or deadlock-avoidance, there is no other method to figure out the deadlock problem.

(a) dual-mode 讓 OS 保護自己;沒有的話使用者程式可以改動 kernel → T

(b) DMA 的定義 → T

(c) user program 只看到 logical address,physical address 由 MMU 轉換 → F

(d) IPC 還有 shared memory → F

(e) 還有 deadlock detection 與 recovery → F

(a), (b)

54 分

Which of the following statements are true?

(a) A multithreaded process has a program counter, pointing to the next instruction to execute for all threads.

(b) The short-term scheduler controls the degree of multiprogramming.

(c) In UNIX, the exec() system call is used to creates a new process.

(d) Blocking is considered synchronous. Non-blocking is considered asynchronous.

(e) A ready process cannot do I/O or anything else that might block it.

(a) 每個 thread 各有自己的 program counter → F

(b) 控制 degree of multiprogramming 的是 long-term scheduler → F

(c) 新 process 由 fork 產生,exec 只是替換 process 的 memory image → F

(d) blocking = synchronous,non-blocking = asynchronous(send/receive 的分類) → T

(e) ready 狀態還沒拿到 CPU,不能執行任何指令,當然不能做 I/O 或被阻塞 → T

(d), (e)

64 分

Which of the following are true about SAN (storage area network) vs. NAS (network attached storage)?

(a) both are accessed via network

(b) NAS operates at block level while SAN operates at file level

(c) CIFS/SMB and NFS are examples of NAS protocols

(d) For databases, SAN is often the preferred choice over NAS

(e) Almost any machine running Microsoft Windows with LAN connectivity can be configured to access a NAS

(a) 都經網路存取 → T

(b) SAN 是 block level、NAS 是 file level,敘述顛倒 → F

(c) CIFS/SMB、NFS 是 NAS 的協定 → T

(d) 資料庫要 block-level 的低延遲存取,通常選 SAN → T

(e) Windows 機器只要有 LAN 就能設定存取 NAS → T

(a), (c), (d), (e)

74 分

A UNIX file system uses 4KB (4096 bytes) blocks and 4-byte disk address. Each inode contains 12 direct entries, 1 singly-indirect entry, and 1 doubly-indirect entry. The maximum file size would be about \(X\) MB (1MB = 1,048,576 bytes). Let \(R_0=X\bmod5\), \(R_1=X\bmod4\), and \(R_2=X\bmod3\). Select the values of \(R_0\), \(R_1\), and \(R_2\) from following. (for instance, if \(X=256\), \(R_0=1\), \(R_1=0\), and \(R_2=1\), you should select a and b)

(a) 0 (b) 1 (c) 2 (d) 3 (e) 4

一個 index block 放 \(4096/4=1024\) 個 pointer

direct:\(12\times4\text{ KB}=48\text{ KB}\);single indirect:\(1024\times4\text{ KB}=4\text{ MB}\);double indirect:\(1024\times1024\times4\text{ KB}=4096\text{ MB}\)

\(\text{總和}=4096+4+\tfrac{48}{1024}\approx4100.05\text{ MB}\),\(X\approx4100\)

\(R_0=4100\bmod5=0\);\(R_1=4100\bmod4=0\);\(R_2=4100\bmod3=2\)(\(4098=3\cdot1366\))

值的集合 \(\{0,2\}\)(照題目的例子,選出現過的值)

(a), (c)

84 分

Which of the following RAID configurations improve disk I/O performance during normal operation and also provide fault tolerance for single disk failure?

(a) RAID 0 (b) RAID 1 (c) RAID 1+0 (d) RAID 0+1 (e) RAID 5

(a) RAID 0 只有 striping,沒有 fault tolerance → F

(b) RAID 1 只是鏡射,沒有 striping,平時的 I/O 效能沒有提升(寫入還要寫兩份) → F

(c) RAID 1+0:mirror 之上再 stripe,效能與容錯都有 → T

(d) RAID 0+1:stripe 之上再 mirror → T

(e) RAID 5:striping+分散 parity,單碟故障可恢復 → T

(c), (d), (e)

94 分

Which of the following are true about using contiguous allocation in filesystem:

(a) Filesystem is prone to internal fragmentation

(b) The space overhead of file allocation record is minimal (only need to track a file's starting location and its length)

(c) Very easy to increase the size of a file dynamically

(d) Sequential access to file is efficient

(e) Random access to file is efficient

(a) contiguous allocation 的問題是 external fragmentation → F

(b) 只記起點與長度 → T

(c) 擴大檔案要有相鄰的空間,常得搬移 → F

(d) 循序存取,磁頭幾乎不用移動 → T

(e) 起點加位移直接算出位置 → T

(b), (d), (e)

104 分

It is now a common practice to execute potentially vulnerable code in a child process. For instance, a web browser may spawn a child process for running flash player. Which of the following could be the motivations?

(a) Separating the memory address space so that malicious code would not be able to corrupt the memory content of the main program

(b) Preventing malicious code from accessing the system resources (e.g. opened files, sockets) used by the main program

(c) Unnecessary privileges can be stripped away from the child process so that malicious code would not be able to invoke certain system calls

(d) Child process can run with a different user ID so that access control can be applied to prevent malicious code from accessing critical files on the system

(e) Reduce the memory usage of the main program so that denial-of-service attack will be much harder to carry out

(a)(b) child 有自己的 address space 與 file descriptor 表,隔離主程式的記憶體與資源 → T

(c) child 可以降權(如 sandbox 限制 system call) → T

(d) child 可用不同 user ID,靠 OS 的 access control 擋住惡意碼 → T

(e) 多開一個 process 並不會減少主程式的記憶體使用,也不是防 DoS 的目的 → F

(a), (b), (c), (d)

114 分

Which of the following statements are correct?

(a) Writing programs with a set of powerful instructions is the shortcut to yield high performance.

(b) The number of pipeline stages affects latency, not throughput; thus pipelining improves the performance of a processor by decreasing the latency of a job (i.e., an instruction) to be done.

(c) For a given program, its average cycles per instruction (CPI) is affected not only by the instruction set architecture, but also by the compiler used.

(d) By reducing the clock frequency of a processor from 2 GHz to 1.5 GHz, and also reducing its supply voltage from 1.25 Volt to 1 Volt, the overall power consumption of this processor will be reduced by 40% theoretically.

(e) Hexadecimal integer value 0xABBCCBBA has identical storage sequence in the (byte-addressable) memory no matter the machine is big-endian or little-endian.

(a) 強大的指令不一定快,效能看 \(\text{IC}\times\text{CPI}\times T\) → F

(b) pipeline 提高 throughput,單一指令的 latency 反而略增 → F

(c) 同一個 program,compiler 影響指令的選擇與排程,CPI 也會變 → T

(d) \(P\propto V^2f\):\(\left(\tfrac{1}{1.25}\right)^2\times\tfrac{1.5}{2}=0.64\times0.75=0.48\),降低 52%,不是 40% → F

(e) byte 序列 AB BC CB BA,反轉是 BA CB BC AB,不是回文 → F

(c)

124 分

Consider a byte-addressable memory hierarchy with 44-bit addresses. The memory hierarchy adopts a 4-way set associative cache of 64 KB, with every block in a set containing 64 bytes. Which of the following statements are correct?

(a) Among an address of 44 bits, the least-significant 6 bits is the "offset".

(b) Among an address of 44 bits, the most-significant 30 bits is the "tag".

(c) The total number of bits required to store the entire cache (including valid bits, tags, and data) is \((1+30+64\times4\times8)\times2^8=532{,}224\) (bits).

(d) By increasing the block size while using the same size of storage for data, the total number of bit required to storage the entire cache will decrease.

(e) Given the following sequence of access addresses: (0E1B01AA050)16, (0E1B01AA073)16, (0E1B2FE3057)16, (0E1B4FFD85F)16, (0E1B01AA04E)16, assuming that the cache is initially empty, there will be three sets containing exactly one referenced block at the end of the sequence.

block 64 B → offset 6 bits;set 數 \(=\dfrac{64\text{ KB}}{4\times64\text{ B}}=256\) → index 8 bits;tag \(=44-8-6=30\) bits

(a)(b) → T

(c) 每個 block 都要有 valid(1)、tag(30)和 data(512 bits):\(1024\text{ 個 block}\times(1+30+512)=556{,}032\) bits;題目的式子把 valid 與 tag 只算每個 set 一份(沒有 \(\times4\)),算出 532,224 → F

(d) 資料總量不變、block 變大 → block 數變少,valid/tag 的總 bit 數減少,整個 cache 的 bit 數下降 → T

(e) index = 位址 bit 6–13(\(\text{addr}\gg6\),取低 8 位)

位址block(addr≫6)set
0E1B01AA0500x386C06A81129
0E1B01AA0730x386C06A81129(同一個 block)
0E1B2FE30570x386CBF8C1193
0E1B4FFD85F0x386D3FF6197
0E1B01AA04E0x386C06A81129(同一個 block)

三個不同的 block 落在三個不同的 set,各含恰好一個被存取的 block → T

(a), (b), (d), (e)

134 分

Which of the following statements (about virtual memory and page table) are correct?

(a) For virtual memory, write-through is more practical than write-back.

(b) For virtual memory, full associativity is typically used for minimizing page fault rate.

(c) Given a 32-bit virtual address space with 2 KB per page and 4 bytes per page table entry, the total page table size is 8 MB.

(d) It is possible to miss in cache and translation look-aside buffer (TLB), but hit in page table.

(e) It is possible to miss in TLB, but hit in cache and page table.

(a) 對 disk 的寫入太慢,virtual memory 用 write-back → F

(b) page 可放在任何 frame(fully associative),降低 page fault rate → T

(c) \(2^{32}/2^{11}=2^{21}\) 個 entry \(\times4\text{ B}=8\text{ MB}\) → T

(d) TLB miss 後在 page table 查到 translation,之後 cache 也可能 miss → T

(e) TLB miss、page table hit 後,資料剛好在 cache → T

(b), (c), (d), (e)

144 分

Which of the following statements are correct?

(a) It is possible that increasing block size could increase the overall miss rate.

(b) It is possible to decrease the occurrence of capacity misses by increasing block size.

(c) It is possible to decrease the occurrence of conflict misses by increasing associativity.

(d) It is possible to "eliminate" the occurrence of conflict misses by further increasing associativity.

(e) It is possible that increasing associativity could increase the overall miss rate.

(a) block 太大,block 數變少、miss penalty 變大,miss rate 反而可能上升 → T

(b) capacity miss 是 cache 總容量不夠,增大 block 不增加容量 → F

(c) 提高 associativity 減少 conflict miss → T

(d) fully associative 就沒有 conflict miss → T

(e) 一般教科書的結論是 associativity 增加使 miss rate 下降或不變;官方維持不選 (e) → F

特殊的 access pattern 搭配 LRU 時,提高 associativity 理論上可以讓 miss 增加;這題官方維持 ACD

(a), (c), (d)

154 分

Which of the following statements are correct?

(a) RAID (redundant array of inexpensive/independent disks) not only enhances the reliability/availability of data storage, but also boosts the performance of data access.

(b) RAID 0 provides fault tolerance by replicating data to mirror disks.

(c) The advantage of RAID 4 over RAID 3 is on the byte-level striping/interleaving of data across disks, so as to allow more parallel data accesses.

(d) The advantage of RAID 5 over RAID 4 is on the distribution of parity blocks across disks, so as to avoid a single parity disk from being the bottleneck.

(e) The advantage of RAID 6 over RAID 5 is on the higher degree of fault tolerance through more disk redundancy.

(a) RAID 提升可靠度也提升效能 → T

(b) 複製到 mirror 的是 RAID 1;RAID 0 沒有容錯 → F

(c) RAID 4 是 block-level striping;RAID 3 是 byte-level → F

(d) RAID 5 把 parity 分散,避免單一 parity disk 成為瓶頸 → T

(e) RAID 6 有兩份 parity,可容忍兩顆碟壞 → T

(a), (d), (e)

164 分

以下 16–20 題的 NCTU1:ARM 在新竹成立 CPU 設計中心,你要設計新 CPU NCTU(Next-generation Compute Terabit Unit)。各邏輯方塊的延遲如下,其他方塊的延遲可忽略:

Main controlI-memAdderRegistersALUSign-extendD-mem
50 ps100 ps50 ps40 ps50 ps10 ps100 ps

NCTU1 是基本的標準 5-stage pipeline(IF/ID/EX/MEM/WB,圖同教科書的 pipelined datapath,ALU control decoder 在 EX stage 以虛線圈起)。所有指令比例:ALU 40%、beq 30%、lw 25%、sw 5%。

16. Which of following statements can be true for ideal NCTU1 (assume there is no stalls, where all instructions are executed ideally)?

(a) The best clock rate of NCTU1 is 10GHz.

(b) The MIPS (million instructions per second) can be reached up to 10000.

(c) All pipeline registers between stages have the same width (number of bits).

(d) The pipeline clock cycle time is equal to the average of all stage latencies.

(e) The longest instruction will be lw instruction. Reducing number of lw instructions in a program can improve the NCTU1 system throughput (e.g. CPI or instructions executed per second).

各 stage 的延遲:IF 100(I-mem);ID 約 50(main control 50、registers 40,並行);EX 50(ALU);MEM 100(D-mem);WB 約 40

cycle time = 最慢 stage = 100 ps

(a) \(1/100\text{ ps}=10\text{ GHz}\) → T

(b) ideal CPI = 1:\(10\text{ GHz}/1=10000\text{ MIPS}\) → T

(c) 各級 pipeline register 存的訊號不同,寬度不同 → F

(d) cycle time 是最大值,不是平均 → F

(e) pipeline 中每道指令每個 cycle 都完成一道,ideal 的 throughput 由 clock 決定,減少 lw 沒有改善 → F

(a), (b)

174 分

17. Ideal execution does not exist at all. Which of following statements can be true for improving NCTU1?

(a) The pipe stages look unbalanced. The ideal CPI can be reduced to less than 1 if we move around the building blocks for better balance.

(b) The overall performance can be always improved by making the pipeline deeper as the cycles are shorter.

(c) Solve the load-use data hazard (load instructions followed by a dependent instruction) by inserting a hazard detection unit at the ID stage.

(d) Increase the register file with more read ports (three reads and a write) to avoid instruction conflicts.

(e) If ALU control decoder (marked by dashed circle) needs to take 50ps, moving the ALU control to the ID stage can improve NCTU1 for allowing more concurrent activities.

(a) 重新平衡 stage 能縮短 clock cycle,但單一 pipeline 的 ideal CPI 不會小於 1 → F

(b) pipeline 越深,hazard 與 branch penalty 越大,不「總是」更快 → F

(c) load-use hazard 靠 ID stage 的 hazard detection unit 偵測並 stall 一拍 → T

(d) conflict 不是出在 register file 的 read port 數 → F

(e) ALU control 放在 EX 時 EX stage = 50(control)+50(ALU)= 100 ps,與其他 stage 的最大值相同,搬到 ID 對 cycle time 沒有幫助 → F

(c)

184 分

18. For the statements on right (i is $r8 and A is $r10), you solve the pipeline dependency of NCTU1 as the textbook. How many cycles totally are needed for NCTU1 to execute them all? (you may need to insert NOP if necessary.)

// C or C++
A[i] += 10;
A[i] *= 2;

// MIPS
add  $r1, $r8, $r10
lw   $r2, 4($r1)
addi $r2, $r2, 10
multi $r2, $r2, 2
sw   $r2, 12($r1)

(a) Total 9 cycles ideally if we don't consider hazard problems.

(b) Total 19 cycles if there is no forwarding unit and no hazard detection unit, and we use NOPs.

(c) Total 11 cycles if there is a forwarding unit and no hazard detection unit for load-use.

(d) Total 10 cycles if there are forwarding unit and hazard detection unit for load-use.

(e) The forwarding unit will not be used in the lw instruction (load-use scenario) when hazard detection unit is triggered.

5 道指令,每道都依賴前一道的結果(\(\$r1\)、\(\$r2\) 的相鄰相依),其中 lw→addi 是 load-use

(a) ideal:\(5+4=9\) cycles → T

(b) 沒有 forwarding 也沒有 hazard detection:每個相鄰相依之間要塞 NOP(regfile 同 cycle 先寫後讀要 2 個 NOP):4 處相依 \(\times2=8\) 個 NOP,\((5+8)+4=17\) cycles,不是 19 → F

(c) 有 forwarding、沒有 hazard detection:lw→addi 要由編譯器塞 1 個 NOP,\((5+1)+4=10\) cycles,不是 11 → F

(d) forwarding+hazard detection:lw→addi stall 1 拍,\(5+1+4=10\) cycles → T

(e) stall 一拍之後,lw 的資料仍要靠 forwarding 從 MEM/WB 送到 EX,forwarding unit 照樣用到 → F

cycle12345678910
addIFIDEXMEWB
lwIFIDEXMEWB
addiIFIDstallEXMEWB
multiIFstallIDEXMEWB
swIFIDEXMEWB

(d) 的逐週期表:addi 在 cycle 5 停一拍,sw 在 cycle 10 結束,共 10 cycles

(a), (d)

194 分

19. Now we hope to design a reduced low cost version using fewer stages, a new 4-piped CPU called NCTU2. We can remove MEM stage and put the memory access in parallel with the ALU. Which of following statements will be true for NCTU2?

(a) It is feasible except all load/store instructions with nonzero offsets, whereas we have to convert them into register-based only (no offset). Specifically, convert lw $r3, 30($r5) into addi $r1, $r5, 30 ; lw $r3, ($r1)

(b) The NCTU2 has better overall system throughput, as instructions take less cycles to complete.

(c) The NCTU2 will have a worse clock rate, as its cycle time is longer than that of NCTU1.

(d) NCTU2 still needs a stall hazard detection unit for load-use condition.

(e) The data forwarding unit is still needed for NCTU2.

(a) 記憶體位址不再經過 ALU 計算,load/store 只能用 register 當位址,offset 要先用 addi 算出 → T

(b) pipeline 滿載時 throughput 由 clock 決定,每道指令少走一個 cycle 只改變 latency,而且多了 addi(指令數增加) → F

(c) cycle time 由最慢的 stage 決定,NCTU2 仍是 100 ps(記憶體存取與 ALU 並行),沒有變長 → F

(d) lw 的資料在記憶體存取結束時才有,緊接著的相依指令在下一 cycle 進 EX,資料可由 forwarding 送到,不必 stall → F

(e) 相鄰的 ALU 指令仍有相依,forwarding 還是需要 → T

(a), (e)

204 分

Branches share a significant portion of program execution. In current NCTU1, branch outcomes are determined at MEM stage. It's one of the key problems.

20. Which of following statements can be true for NCTU1 by considering branches only?

(a) The CPI with all branch stalls is 1.9 for NCTU1 (assume no other stalls).

(b) If the NCTU1 is designed with deeper pipelined stages, the branch control hazard becomes harder to solve.

(c) Assuming branches are not taken can continue execution down the sequential instruction stream and thus improve the NCTU1 without changing hardware.

(d) If the branch handling is moved to the EXE stage, it can improve CPI without increasing the cycle time.

(e) If more hardware resources such as forwarding comparator are provided, the branch resolving can be perfectly moved to the IF stage while still maintaining the normal pipelining mechanism.

(a) branch 在 MEM 決定,penalty 3 個 cycle:\(\text{CPI}=1+0.3\times3=1.9\) → T

(b) pipeline 越深,branch 決定得越晚、penalty 越大 → T

(c) 預測 not taken 要在猜錯時 flush 已抓進來的指令,需要額外硬體(flush 控制) → F

(d) 搬到 EX 需要 ALU 比較(或額外比較器),EX stage 變長,可能拉長 cycle time;這題官方維持 AB → F

(e) 在 IF 時指令還沒解出來,不可能「完美」決定 → F

(a), (b)

215 分(題組 A:21–22 全對)

題組 A Now we have a new NCTU3 derived from NCTU1, where the branch handling is moved to the ID stage.

21. Which of following statements will be true?

(a) It needs more hardware costs such as extra adder for subtraction and a forwarding unit.

(b) The branch target address adder has to be replicated.

(c) The good thing is that it improves CPI without increasing cycle time.

(d) The branch only CPI of new NCTU3 will become 1.1.

(a) 在 ID 就要比較兩個 register:需要額外的比較(減法)電路與送進 ID 的 forwarding → T

(b) branch target adder 本來就在 ID 附近,不必複製 → F

(c) ID stage 多了 forwarding 與比較,stage 變長,cycle time 可能增加 → F

(d) penalty 變 1 個 cycle:\(\text{CPI}=1+0.3\times1=1.3\),不是 1.1 → F

(a)

22題組 A

22. Even with NCTU3, we hope to improve the branch problem further. Which of following statements is NOT true?

(a) Delayed branch is a mechanism to delay the effect of branch. Branch delay slot in NCTU3 is 1. It also needs no extra hardware resources in NCTU3.

(b) Compiler can help in filling delay slots. If compiler can find any safe instruction for 50% of branches, the CPI can be reduced to 1.15.

(c) Predicting branch as not-taken is a good mechanism and it needs no extra hardware resources in NCTU3.

(d) Branch prediction buffer is good to predict the branch outcome, but it does not help in predicting the branch target.

(a) ID 判定 → 1 個 delay slot,不用額外硬體 → T

(b) penalty 0.3×1 的一半由 compiler 補上:\(\text{CPI}=1+0.3\times0.5=1.15\) → T

(c) 預測 not taken 猜錯時要 flush(如 IF.Flush),需要額外的控制硬體 → 敘述不成立(NOT true)

(d) branch prediction buffer 只預測 taken/not taken,target 要靠 branch target buffer → T

(c)

235 分(題組 B:23–24 全對)

題組 B Given a 16-byte cache (byte-addressable, initially empty) and a sequence of access addresses: (2)10, (14)10, (0)10, (17)10, (12)10, (3)10, please derive the corresponding hit/miss sequence for each of the following cache designs.

23. 8 bytes per block, direct-mapped. How many of these six accesses are "hit"? (a) 0 (b) 1 (c) 2 (d) 3 (e) 4

16 B ÷ 8 B = 2 個 block;\(\text{block}=\lfloor a/8\rfloor\),\(\text{index}=\text{block}\bmod2\)

位址blockindex結果
200miss
1411miss
000hit
1720miss(換掉 block 0)
1211hit
300miss(block 0 被 block 2 換掉)

hit 兩次

(c)

24題組 B

24. 4 bytes per block, 2-way set associative. (a) 0 (b) 1 (c) 2 (d) 3 (e) 4(位址序列同第 23 題)

16 B ÷ 4 B = 4 個 block,2-way = 2 個 set;\(\text{block}=\lfloor a/4\rfloor\),\(\text{set}=\text{block}\bmod2\)

位址blockset結果set 內容
200miss{0}
1431miss{3}
000hit{0}
1740miss{0, 4}
1231hit{3}
300hit{0, 4}

hit 三次(位址 0、12、3)

(d)

255 分(題組 C:25–27 全對)

題組 C Considering the banker's algorithm, there is a system with 5 processes (P0–P4) and 3 types of resources (A–C). Resource A has 10 instances, resource B has 5 instances and resource C has 7 instances. At the beginning, the following snapshot of the system has been taken (Available = 3 3 2):

PIDAllocation(A B C)Max(A B C)
P00 1 07 5 3
P12 0 03 2 2
P23 0 29 0 2
P32 1 12 2 2
P40 0 24 3 3

25. Please list a sequence of processes satisfies the safety criteria. (a) ⟨P0, P2, P1, P4, P3⟩ (b) ⟨P1, P4, P2, P3, P0⟩ (c) ⟨P2, P0, P3, P1, P4⟩ (d) ⟨P3, P1, P4, P0, P2⟩ (e) ⟨P4, P3, P0, P2, P1⟩

PIDAllocationMaxNeed = Max − Allocation
P00 1 07 5 37 4 3
P12 0 03 2 21 2 2
P23 0 29 0 26 0 0
P32 1 12 2 20 1 1
P40 0 24 3 34 3 1

Available = (3,3,2);依序檢查每個選項:第一個 process 的 Need 必須 \(\le\) Available

(a) P0 的 Need (7,4,3) \(\gt\) (3,3,2) → F;(c) P2 的 Need (6,0,0) \(\gt\) (3,3,2) → F;(e) P4 的 Need (4,3,1):A 要 4 \(\gt3\) → F

(b) P1 (1,2,2) \(\le\) (3,3,2) ✓ → Available (5,3,2);P4 (4,3,1) ✓ → (5,3,4);P2 (6,0,0):A 要 6 \(\gt5\) → F

(d) P3 (0,1,1) ✓ → (5,4,3);P1 (1,2,2) ✓ → (7,4,3);P4 (4,3,1) ✓ → (7,4,5);P0 (7,4,3) ✓ → (7,5,5);P2 (6,0,0) ✓ → (10,5,7) → safe

(d)

26題組 C

26. Suppose that the process P1 request 1 additional resource A and 2 addition resources C. Can this request be immediately granted? (a) Yes (b) No (c) Maybe(題組 C 的表同第 25 題)

\(\text{Request}_1=(1,0,2)\):\(\le\text{Need}_1=(1,2,2)\) ✓;\(\le\text{Available}=(3,3,2)\) ✓

假裝分配:Available \(=(2,3,0)\),\(\text{Alloc}_1=(3,0,2)\),\(\text{Need}_1=(0,2,0)\)

檢查 safe:P1 (0,2,0) ✓ → (5,3,2);P3 (0,1,1) ✓ → (7,4,3);P4 (4,3,1) ✓ → (7,4,5);P0 (7,4,3) ✓ → (7,5,5);P2 (6,0,0) ✓ → safe,可以立即分配

(a) Yes

27題組 C

27. Suppose that the process P4 request 2 additional resources B. Can this request be immediately granted? (a) Yes (b) No (c) Maybe(題組 C 的表同第 25 題)

\(\text{Request}_4=(0,2,0)\):\(\le\text{Need}_4=(4,3,1)\) ✓;\(\le\text{Available}=(3,3,2)\) ✓

假裝分配:Available \(=(3,1,2)\),\(\text{Alloc}_4=(0,2,2)\),\(\text{Need}_4=(4,1,1)\)

檢查 safe:P3 (0,1,1) ✓ → (5,2,3);P1 (1,2,2) ✓ → (7,2,3);P4 (4,1,1) ✓ → (7,4,5);P0 (7,4,3) ✓ → (7,5,5);P2 (6,0,0) ✓ → safe,可以立即分配

(a) Yes

285 分(題組 D:28–29 全對)

題組 D Assume you are the system administrator (root) of a UNIX workstation. There are four users nancy, john, frank, and charlene on the workstation. User nancy and john belong to the student group, while user frank and charlene belong to the faculty group.

[root@localhost /]# id frank
uid=1004(frank) gid=1004(frank) groups=1004(frank),1005(faculty)
[root@localhost /]# id charlene
uid=1001(charlene) gid=1001(charlene) groups=1001(charlene),1005(faculty)
[root@localhost /]# id john
uid=1002(john) gid=1002(john) groups=1002(john),1006(student)
[root@localhost /]# id nancy
uid=1003(nancy) gid=1003(nancy) groups=1003(nancy),1006(student)
[root@localhost /]# umask -S

28. We would like to create a directory /project for nancy and john to store their files for a course project. They both need to be able to create new files under the project directory. Specifically, we only allow the administrator and users of the student group to access files in the project directory. To achieve this, which of the following command would suffice?

(a) chown -R root /project; chgrp -R student /project; chmod -R 770 /project

(b) chown -R root /project; chgrp -R faculty /project; chmod -R 770 /project

(c) chown -R frank /project; chgrp -R student /project; chmod -R 770 /project

(d) chown -R root /project; chgrp -R student /project; chmod -R 700 /project

(e) chown -R student /project; chgrp -R student /project; chmod -R 770 /project

要求:只有 root 與 student 群組可以進入並建立檔案 → owner root、group student、權限 770(others 無權限)

(a) owner root、group student、770 → T

(b) group 設成 faculty,nancy、john 進不去 → F

(c) owner 是 frank,faculty 的 frank 也能存取 → F

(d) 700:group 沒有權限,nancy、john 無法建立檔案 → F

(e) student 是 group 名稱不是使用者,chown -R student 會失敗 → F

(a)

29題組 D

29. User nancy adds a file quicksort.cpp under the project directory. The project directory now looks like the following:

[nancy@localhost project]$ ls -al
total 12
drwxrwx---. 2 root  student 4096 Dec 19 17:00 .
drwxr-xr-x. ... root root   4096 Dec 19 16:15 ..
-rw-rw-r--. 1 nancy nancy      5 Dec 19 16:32 quicksort.cpp

User nancy does not want other users in the student group to have read or write access to the file. Which of the following command can be used by nancy to achieve this?

(a) chmod 666 quicksort.cpp

(b) chmod 600 quicksort.cpp

(c) chgrp root quicksort.cpp

(d) This is not possible because the project directory is associated with the student group.

(e) This is not possible because nancy is not the system administrator. She cannot use the chmod / chgrp commands.

檔案的 owner 是 nancy、group 是 nancy;student 群組的其他成員(如 john)屬於「others」,目前有 r--

(a) 666 讓大家都能寫 → F

(b) 600:只有 owner 能讀寫,others(含 john)都不行 → T

(c) nancy 不是 root,不能把 group 改成她不屬於的 root → F

(d)(e) 檔案的 owner 可以自己 chmod,與目錄的 group 無關 → F

(b)

109–115 的詳解也是這樣寫的。

國立陽明交通大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 579 頁,逐題推導。

購買 · NT$ 850 看交大其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com