[10%] Explain the following term in English. For each term, please use less than 100 words.
(a) [2%] Power Wall (b) [2%] GPGPU (c) [2%] Restartable instruction (d) [2%] Write-allocate policy (e) [2%] NUMA
(a) Power Wall:Chip power (dynamic power \(P\approx\tfrac12CV^2f\)) and the heat it produces are limited by what air cooling can remove. Supply voltage can no longer be lowered, so raising the clock rate raises power too much; since about 2004 designers stopped scaling frequency and moved to multiple cores.
(b) GPGPU (general-purpose computing on a GPU):Using a graphics processor, with hundreds or thousands of simple cores running the same program on many threads (SIMT), to do non-graphics, data-parallel work (CUDA, OpenCL).
(c) Restartable instruction:An instruction that can be stopped by an exception such as a page fault, have the fault handled, and then be re-executed from its start with the correct result. Demand paging needs it, so the machine must not leave partial side effects.
(d) Write-allocate policy:On a write miss, the block is first fetched from the next level into the cache, then the write is done in the cache. It is usually paired with write-back; the alternative, no-write-allocate, writes straight to memory without loading the block.
(e) NUMA (non-uniform memory access):A shared-address-space multiprocessor in which the access time to a memory word depends on where the word is: the processor's local memory is faster than remote memory attached to other processors.
五個名詞如上,每個 100 字以內
210%
[10%] Suppose we have developed new versions of a processor with the following characteristics.
Version
Voltage
Clock rate
Version 1
1.2 V
810 MHz
Version 2
1 V
1 GHz
(a) [5%] How much has the dynamic power been reduced if the capacitive load does not change?
(b) [5%] Assuming that the capacitive load of version 2 is 80% the capacitive load of version 1, find the voltage for version 2 if the dynamic power of version 2 is reduced by 20% from version 1.
[5%] Translate the following C code to MIPS instructions. Assume that the variables \(c\) and \(d\) are assigned to registers $s0 and $s1, respectively. Assume that the base address of the arrays \(A\) and \(B\) are in registers $s6 and $s7, respectively.
[20%] Assume an instruction pipeline for a high-speed, load/store processor with the following instruction classes:
ALU
ALUop Rdst, Rsrc1, Rsrc2
ALUimmediate
ALUiop Rdst, Rsrc1, imm
Load
MEMop Rdst, n(Rsrc)
Store
MEMop n(Rsrc2), Rsrc1
Conditional branch
BRop Rsrc1, Rsrc2, offset
Jumps
JMP Rdst
Each instruction takes one machine word. The only memory-addressing mode supported is base register plus a signed offset. Conditional branches compare the two branch source operand values using the ALU. The branch target address is computed on a separate address generation adder contained in the control unit of the machine. Register file writes occur in the first half of a cycle and register file reads occur in the second half.
The machine uses virtual memory address, with separate instruction and data TLBs. It also has a physical addressed (tagged) direct mapped L1 Icache and a physically addressed set associate L1 Dcache (Accesses that miss in the L1 cache cause the instruction pipeline to stall.) The ALU used during the EX cycle is pipelined and takes one cycle to complete an addition/subtraction/logical operations and two cycles to complete a multiplication. The time taken by the key components (that already includes the pipeline register write time, the interconnect delay, and any necessary multiplexors) is as follows:
I or D TLB access
1 ns
Icache access
2 ns
Instruction decode
1 ns
Address adder
1 ns
Dcache access
2 ns
ALU pipe stage
2 ns
RegFile read/write
2 ns per 2 port access (e.g. a 2-read and 2-write port RegFile takes 2 ns, a 4-read-4-write port RegFile takes 4 ns, etc.)
Answer the following questions about your pipeline.
(a) [7%] Draw the shortest possible instruction pipeline (i.e. the pipeline with the fewest stages) while ensuring that there are no structural hazards. For your pipeline, give a name for each stage along with a short description of what activities occur during that stage.
(b) [3%] What is its clock rate?
(c) [5%] Give a MIPS instruction example of two different data hazards that can be solved by forwarding (both data hazards should be different in that the forwarding is handled from different pipeline register stages). For each, explain which data are forwarded.
(d) [5%] Give a MIPS instruction example of two different data hazards that cannot be solved by forwarding. For each, indicate how many stalls are incurred before the hazard is resolved.
(a) [5%] In the LRU page-replacement algorithm, how many page faults would occur when we have 'one', 'two', 'three' page frames? Please indicate the number of page faults individually. Assume that all frames are initially empty, and therefore your first access to each unique page will cause one fault.
(b) [5%] In the optimal page-replacement algorithm, how many page faults would occur when we have 'one', 'two', 'three' page frames? Please indicate the number of page faults individually. Assume that all frames are initially empty, and therefore your first access to each unique page will cause one fault.
(a) LRU:每次踢最久沒用的
1 frame:相鄰兩個 reference 都不同,每次都 fault → 20
2 frames:
ref
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
frame 1
1
1
3
3
2
2
5
5
2
2
2
2
7
7
3
3
1
1
3
3
frame 2
2
2
4
4
1
1
6
6
1
1
3
3
6
6
2
2
2
2
6
fault
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
3 frames:
ref
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
frame 1
1
1
1
4
4
4
5
5
5
1
1
1
7
7
7
2
2
2
2
2
frame 2
2
2
2
2
2
2
6
6
6
6
3
3
3
3
3
3
3
3
3
frame 3
3
3
3
1
1
1
2
2
2
2
2
6
6
6
1
1
1
6
fault
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
(b) OPT:每次踢「最久以後才會再用到(或不再用到)」的
1 frame:20
2 frames:
ref
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
frame 1
1
1
3
4
4
1
5
6
6
1
1
3
3
3
3
3
1
1
3
6
frame 2
2
2
2
2
2
2
2
2
2
2
2
7
6
6
2
2
2
2
2
fault
F
F
F
F
F
F
F
F
F
F
F
F
F
F
F
3 frames:
ref
1
2
3
4
2
1
5
6
2
1
2
3
7
6
3
2
1
2
3
6
frame 1
1
1
1
1
1
1
1
1
1
1
1
3
3
3
3
3
3
3
3
6
frame 2
2
2
2
2
2
2
2
2
2
2
2
7
7
7
2
2
2
2
2
frame 3
3
4
4
4
5
6
6
6
6
6
6
6
6
6
1
1
1
1
fault
F
F
F
F
F
F
F
F
F
F
F
(a) LRU:20、18、15 (b) OPT:20、15、11
710%
[10%] Choose the correct answers for each of the following 5 questions.
(a) [2%] The Banker's Algorithm is proposed to support the technique of: (1) deadlock detection (2) deadlock recovery (3) deadlock avoidance (4) deadlock identification
(b) [2%] For two processes accessing a shared variable, Peterson's algorithm must satisfy: (1) semaphores (2) mutual exclusion (3) synchronization (4) progress (5) bounded-waiting
(c) [2%] Indefinite blocking may occur if we add and remove processes from the list associated with a semaphore in ________ order. (1) first in, first out (2) first in, last out (3) last in, first out (4) last in, last out
(d) [2%] A CPU-bound process ________. (1) infrequently requests I/O operations and spends more of its time performing computational work (2) frequently requests I/O operations and spends more of its time performing computational work (3) infrequently requests I/O operations and spends less of its time performing computational work (4) frequently requests I/O operations and spends less of its time performing computational work
(e) [2%] ________ increases CPU utilization by organizing jobs (code and data) so that the CPU always has one to execute. (1) Multithreading (2) CPU scheduling (3) Swapping (4) Multiprogramming
(c) semaphore 的 waiting list 用 LIFO,先等的 process 可能一直被後來的插隊,永遠輪不到(starvation) → (3)
(d) CPU-bound:很少 I/O、大部分時間在計算 → (1)
(e) 讓 CPU 隨時有 job 可跑 → multiprogramming → (4)
(a) 3 (b) 2、4、5 (c) 3 (d) 1 (e) 4
815%
[15%] To create a new process from processes, the multitasking operating systems such as Unix-like systems provide a "fork" system call. The fork function will create a copy of itself to a child process, and then other programs are executed in the child process.
(a) [5%] In the following example with the fork function, how many lines of "NCKU" will be shown in the console?
int main(int agrc, char **argv)
{
int i;
for (i=0; i<5; i++)
{
fork();
}
printf("NCKU\n");
return 0;
}
(b) [5%] In the following example with the fork function, how many lines of "NCKU" will be shown in the console?
int main(int agrc, char **argv)
{
int i;
for (i=0; i<10; i++)
{
printf("NCKU\n");
fork();
}
return 0;
}
(c) [5%] In the following example with the fork function, what content will be printed in the console?
int main(int agrc, char **argv)
{
int x=0, i=0;
for (i=0; i<3; i++)
{
fork();
x=x+5;
}
printf("x = %d\n", x);
return 0;
}
每次 fork() 讓 process 數目變 2 倍(父與子都從 fork 後面繼續跑同一段迴圈)
x = 15
x = 15
x = 15
x = 15
x = 15
x = 15
x = 15
x = 15
(a) 32 行 (b) 1023 行 (c) 8 行 x = 15
915%
[15%] The following implementation in Java is created for a specific system utility.
(a) [7%] Could you figure out what is the system utility that can be provided from 'Manager' class? Please also simply discuss its corresponding methodology.
(b) [8%] Consider 'Manager' is used in the multi-threading mode. Is the implementation logically risky? If it is risky, please clearly point out those incorrect methods or lines, and also revise the code (written in Java). If it is not risky, please clarify your answer.
public interface ObjA
{
/* check if the object is expired */
public boolean isExpired();
/* return the key in the string type */
public String getIdentifier();
}
1 public class Manager {
2 private static java.util.HashMap map = new java.util.HashMap();
3 private static Object lock = new Object(); /* This object 'lock' can act as a semaphore */
4
5 static { /* The following code will create a background thread invoked periodically */
6 try {
7 Thread th_1 = new Thread(new Runnable() {
8 int sleepTime = 5000;
9 public void run() {
10 try {
11 while (true) { /* Sets up an infinite loop */
12 /* An iterator is used to look through all objects */
13 java.util.Iterator keys = map.keySet().iterator();
14 while (keys.hasNext()) {
15 /* Retrieve each individual key */
16 String key = (String) keys.next();
17 ObjA value = (ObjA) map.get(key);
18 if (value.isExpired()) {
19 map.remove(key);
20 }
21 }
22 Thread.sleep(sleepTime); /* thread will sleep 5000 ms */
23 }
24 } catch (Exception e) {
25 e.printStackTrace();
26 }
27 } /* End of the run method */
28 }); /* End of the thread code */
29
30 th_1.start(); /* Starts the thread */
31 } catch (Exception e) {
32 e.printStackTrace();
33 }
34 } /* End static block */
35
36 /* put object into the map */
37 public static void putObjA(ObjA object) {
38 map.put(object.getIdentifier(), object);
39 }
40 /* return the object if the key is found in the map */
41 public static ObjA getObjA(String identifier) {
42 ObjA obj = null;
43 /* 'synchronized(lock)' can ensure that no more than one thread can lock the object
44 'lock' simultaneously */
45 synchronized (lock) {
46 obj = (ObjA) map.get(identifier);
47 }
48 if (obj == null)
49 return null;
50 if (obj.isExpired()) {
51 map.remove(identifier);
52 return null;
53 } else {
54 return obj;
55 }
56 }
57 }