Part 6 of 6 · 3 min read
Exercises
Easy
Easy 1: Compute the three times (20 minutes)
A process arrives at 4, first runs at 9, needs 6 units of CPU and runs without interruption. Give its finish, turnaround, waiting and response times.
Done when: finish 15, turnaround 11, waiting 5, response 5.
Hint
Finish = first run + CPU time when there is no interruption.
Easy 2: Classify the processes (20 minutes)
Classify each as CPU-bound or I/O-bound: a compiler, a chat client, a video encoder, a database waiting for disk reads.
Done when: four labels with one reason each.
Hint
A process that waits for something outside the processor is I/O-bound.
Easy 3: When does the scheduler run? (20 minutes)
For each event, say which of the four situations it is: a read blocks, a timer interrupt fires, a disk read finishes, exit is called.
Done when: the answers 1, 2, 3 and 4 in that order.
Hint
A timer interrupt changes running to ready.
Medium
Medium 1: Table for a new workload (30 minutes)
Processes P (arrival 0, CPU 4), Q (arrival 2, CPU 6), R (arrival 3, CPU 1) run in arrival order without interruption. Draw the timeline and give each process's turnaround, waiting and response time, and the three averages.
Done when: timeline P 0 to 4, Q 4 to 10, R 10 to 11; average turnaround (4 + 8 + 8) ÷ 3 = 6.67; average waiting (0 + 2 + 7) ÷ 3 = 3.00; average response 3.00.
Hint
Waiting = turnaround − CPU time.
Medium 2: Count the switches (30 minutes)
Run the spinner and sleeper test from section 1 on your machine. Read voluntary_ctxt_switches and nonvoluntary_ctxt_switches for both.
Done when: a table of four counters, with a sentence on which kind of switch each program caused.
Hint
Both counters are in /proc/self/status.
Medium 3: Utilisation (30 minutes)
A system runs processes for 72 seconds, spends 3 seconds in the dispatcher, and idles for the rest of a 100-second window. Give the utilisation of the processor for running processes and the fraction lost to dispatching.
Done when: 72 per cent running and 3 per cent dispatching, with idle time of 25 seconds.
Hint
Divide each time by the 100-second window.
Hard
Hard 1: Write a metrics calculator (60 minutes)
Write a program (Python or C) that reads lines of name, arrival, CPU time and start, finish times, and prints the turnaround, waiting and response time of each process and the averages. Test it on the example workload.
Done when: averages 10.25, 5.75 and 5.75 for the first-come order.
Hint
Turnaround needs the finish time, and response needs the first start time.
Hard 2: Measure the switch cost (60 minutes)
Using the ping-pong program of Level 1, page 5, measure the cost of a switch on your machine. Then compute what fraction of a 10-millisecond time slice that cost is.
Done when: a figure in microseconds and a percentage below 0.1 per cent for slices of 10 milliseconds.
Hint
Switch cost = time of the ping-pong divided by the number of switches.
Hard 3: Which goal wins? (60 minutes)
For a phone, a web server, a weather simulation and a car brake controller, choose the main measure from this page, name one measure that can be sacrificed, and justify each in two sentences.
Done when: four rows with a main goal, a sacrificed goal and a reason.
Hint
Use the table in section 4 as a starting point.