# CS 3360 Written Assignment 1 >[!author] Author: Jackson Wu *Due: 11:59pm **Thursday**, Feb. 6, 2025* *Instructor: Kecheng Yang ([email protected])<br>Doctoral Instructional Assistant: Ishrak Ratul ([email protected])* *Notes: Please be aware that when we say "X every Y," the " X " is included in the "Y." E.g., in "we take 2 days off every week," the " 2 days" are included in the "week"; by contrast, it does NOT mean that we work for an entire week (or, 7 days) and then take 2 days off.* 1 >**Noted. e.g. "YYXXYYY" is one valid pattern that satisfies "X every Y".** --- ## Problem 1 [12 pts] Answer the following questions: >[!question] >(a) What are the five states of a process? [10 pts] Yang's pointers suggested an intuitive approach instead of memorizing, so I'll attempt to group states under umbrellas: ![[ Excalidraw/1300 CS 3360 Written Assignment 1.excalidraw.svg ]] [[Excalidraw/1300 CS 3360 Written Assignment 1.excalidraw|()]] >[!caution] ![[ Excalidraw/1237 CS 3360 Written Assignment 1.excalidraw.svg ]] >**Safer, textbook answer:** > ``` New: being created Ready: can run (waiting on the CPU only) Running: executing instructions on the CPU Waiting (Blocked): Waiting for an event (i.e., something other than CPU being available) to happen >user input, I/O, child processes to finish, etc. Terminated: has finished ``` --- >[! Question] > (b) If a process is currently doing computations on a (discrete) GPU in a typical computing system, what state the process is currently in? [2 pts] >[!answer] >In a traditional computing systems perspective, >even if we assume the discrete GPU can run in parallel, tthe CPU is still the primary orchestrator. > >Discussing process states = fundamentally about the CPU's "conveyor belt" (instruction pipeline) > >> From this perspective, I would presume the current state to be **blocked(waiting for non-CPU)** --- ## Problem 2 [16 pts] >[!scenario] >Consider the following two alternatives in which keyboard interrupts can be handled. **Scenario** **1:** Each character typed causes an interrupt service routine to execute for 0.01 millisecond (to copy the character typed from the keyboard to memory). You can assume that a computer user is typing at an average rate of 200 characters per minute. **Scenario 2**: Every 50 milliseconds an interrupt service routine executes for 0.1 milliseconds and copies any buffered data from the keyboard to memory. >[!My Interpretation] $ \begin{eqnarray}\text{Scenario one:}\\ \text{ISR(Interrupt Service Routine)}_\text{Keyboard ->Memory} = 0.01 \ \text{ms} \\ \\ \\ \text{assume char per minute} = 200 \ \text{CPM} \\ \\ \end{eqnarray} $ $ \begin{eqnarray} \text{Scenario two:} \\ \text{ISR}_{\text{Keyboard->Memory}} \ \ \ \text{Invoked every 50 ms} = 0.1 \text{ms} \end{eqnarray} $ >[!question] 2a >What percentage of the CPU time would be used in handling interrupts in each scenario? >[!caution] Interpretation cont.. >![[ Excalidraw/1345 CS 3360 Written Assignment 1.excalidraw.svg ]] >![[ Excalidraw/1753 CS 3360 Written Assignment 1.excalidraw.svg ]] >![[ Excalidraw/1336 CS 3360 Written Assignment 1.excalidraw.svg ]] [[Excalidraw/1336 CS 3360 Written Assignment 1.excalidraw|()]] [[Excalidraw/1753 CS 3360 Written Assignment 1.excalidraw|()]] >[!question] 2b >(b) Give one advantage of scenario 1 over scenario 2. [4 pts] >[!answer] Answer >Scenario 1 handles each character immediately, so the latency from typing to processing is lower. Each character is copied right away, so the system responds instantly. Not to mention avoiding periodic interrupts when no keys are pressed. >>In Scenario 2, characters are buffered and copied every 50 ms, so there might be up to 50 ms delay before a character is processed. So advantage of Scenario 1 is lower latency for each character and overhead. --- >[!question] 2c (c) Give one advantage of scenario 2 over scenario 1. [4 pts] >[!answer] Answer >Scenario 1 uses less CPU time overall. So why would Scenario 2 be better? > Maybe the advantage is not in CPU time but in something else. For example, in Scenario 1, if the user types a burst of characters, say 10 characters in a quick succession, each will trigger an interrupt. If the CPU is busy, maybe some characters could be lost or there's higher latency. Whereas in Scenario 2, the characters are buffered, and even if the system is busy, the periodic interrupt will pick up all buffered characters at once. > > So the advantage of Scenario 2 is that it can prevent data loss under heavy load because the keyboard controller buffers the data, and the ISR copies it periodically. Whereas in Scenario 1, if interrupts are disabled for too long, characters might be missed. So maybe that's an advantage. ## Problem 3 [12 pts] A network card in a computer is connected to a switch with a link capable of delivering 10 Mbps (Megabits per second). The network card receives an average of 10 packets every 50 milliseconds from a streaming connection. Assume that each packet is 1000 Bytes. Answer the following questions: >[!question] 3(a) >What is the relationship between Byte and bit? [4 pts] >[!a] Answer >1 Byte is 8 bits. That's the standard relationship. >[!question] 3(b) >(b) What is the average throughput achieved by this streaming connection only? Assume no packets are dropped. Answer in terms of packages per second and Mbps, respectively. >[!answer] Answer >Average throughput in packets per second and Mbps. The network card receives 10 packets every 50 milliseconds. Each packet is 1000 Bytes. The link is 10 Mbps. > First, compute packets per second. 10 packets every 50 ms is equivalent to 10 / 0.05 seconds = 200 packets per second. > Then, Mbps. Each packet is 1000 Bytes. 1000 Bytes = 8000 bits. So per packet, 8000 bits. 200 packets per second is 200 * 8000 bits per second. 200 * 8000 = 1,600,000 bits per second. 1,600,000 bps = 1.6 Mbps. --- >[!question] 3c >(c) What is the utilization of the network link? [4 pts] >[!answer] Answer >Link is 10 Mbps, and the streaming connection uses 1.6 Mbps. Utilization is 1.6 / 10 = 0.16 = 16%. ## Problem 4 [24 pts] Consider a program that performs the following steps repeatedly: 1. Use the CPU for 4 milliseconds. 2. By issuing an I/O, use the disk for 14 milliseconds. 3. Use the CPU for 10 milliseconds. 4. By issuing an I/O, use network for 18 milliseconds. ``` Assume that each step depends on data obtained from the previous step (e.g., step 3 cannot start before step 2 is completed. Also assume that each resource (CPU or disk or network) can be used by one process at a time and that there is no bus contention. ``` Answer the following questions: >[!question] 4a >(a) Draw 3 time-line diagrams (horizontal axis is the time line; one line for each resource. That is, 3 parallel rows in the resulted figure.) that illustrate the utilizations of the CPU, disk, and network over the execution of two iterations of the program above by a single process. [ 6 pts ] >[!caution] Answer >![[svgviewer-output.svg]] >[!question] 4b (b) What are the average utilizations of the CPU, disk and network over these two iterations? (Please note that the "total time" should be the same across all resources, from the entire system starts until all work on any resource has been done.) [6 pts] >[!answer] Answer >CPU: (28 ms / 92 ms) ≈ **30.43%** > > Disk: (28 ms / 92 ms) ≈ **30.43%** > > Network: (36 ms / 92 ms) ≈ **39.13%** >[!question] c&d (c \& d) Assume that there are two independent processes in a multiprogramming system (i.e., when a process utilizes a resource, another process can utilize a different one in the same time) and each process runs one iteration of the program above. Answer parts (a) and (b) for this case showing which part belongs to which process. You can ignore the time spent in context switching. [12 pts] >[!caution] Answer >![[svgviewer-output(2).svg]] >>Each process does ONE iteration (not two like in parta) > Since they can run concurrently when using different resources, Process 2 can start its CPU work (4ms) right after Process 1 moves to disk >>both processes still need to use the CPU for their second CPU phase (10ms each) >>>Process 2's disk operation (14ms) cannot start until: >Process 2 finishes its first CPU work (4ms) >AND Process 1 finishes using the disk >TwoProcess Utilizations: >Overall time finishes at 64 ms >CPU busy 28 ms 28/64=43.75% >Disk busy 28 ms 28/64=43.75% >Network busy 36 ms 36/64=56.25% ## Problem 5 [20 pts] Consider 5 processes, A, B, C, D and E, arriving to a system with a single CPU according to the table below. Each process has an arrival time and service time (time needed on the CPU). Assume the CPU services these processes in a First-in-First-Out (FIFO) fashion. Also assume that the CPU is used $100 \%$ of the time during the service time of any process. | | Arrival Time | Service Time (Execution Time) | | :-------: | :----------: | :---------------------------: | | Process A | 0 sec | 2 sec | | Process B | 1 sec | 3 sec | | Process C | 7 sec | 6 sec | | Process D | 8 sec | 1 sec | | Process E | 10 sec | 4 sec | >[!question] 5(a) >How long would it take until all the processes are done? (I.e., how many seconds after time 0 all the 5 processes are finished?) >[!answer] >all processes are done at t = 18 seconds with E as last process finish. --- >[!question] 5(b) >Draw the utilization of the CPU over time. (I.e., time as $x$-axis and utilization as $y$ axis) [4 pts] >[!caution] ![[svgviewer-output(3).svg]] --- >[!question] 5(c) >What is the average utilization of the CPU? [4 pts] >[!answer] >busy time / total time could've been busy = 16/18 = about 88.9% --- >[!question] 5(d) >What is the overall system throughput in processes done per second? [4 pts] >[!answer] >Throughput = # procs completed per unit time == 5/18 >.278 procs per second. --- >[!question] 5(e) >What is the average turnaround time for all processes? [4 pts] >[!answer] finishing time minus its arrival time >The result, in respective order: >2 >4 >6 >6 >8 >>Averaging them up, 26/5 = 5.2 seconds average turnaround --- ## Problem 6 [16 pts] Consider two learning management systems (let's denote them by A and B, e.g., Canvas or TRACS). Both systems go down for maintenance for a total of 2 hours every month. System A goes down once per month for 2 hours, whereas system $B$ goes down 6 times per month for 20 minutes each time. Assume each month is exactly 30 days. Answer the following questions: >[!question] 6(a) >What is the availability of System A? [4 pts] >[!answer] >**System A** goes down once per month for 2 hours >Possible uptime within unit of time: 720 >With the downtime, bring it down to 718. >718/720 == 99.7% $ \text{Availability(conceptual)} = \frac{TotalWorkDone}{TotalWorkCould'veDone} $ --- >[!question] 6(b) >What is the availability of System B? [4 pts] >[!answer] >**System B** goes down 6 times per month for 20 minutes each >6×20 minutes=120 minutes=2 hours >That makes the uptime, just like the above answer on 6(a), 718. >The availability is the same: 99.7% (718/720) --- >[!question] 6(c) >What is the MTBF of System A? [4 pts] $ Avail = \frac{MTBF}{MTBF+MTTR} $ >[!answer] >Algebraically solve MTBF as the X >0.9972(X+2)=X >I used Wolfram. ![[Pasted image 20250206230741.png]] --- >[!question] 6(d) >What is the MTBF of System B? [4 pts] >[!answer] >0.9972(MTBF+1/3) = MTBF >![[Pasted image 20250206230933.png]]