HEAD →CPUTIMER0 s1turnaround = finish - arrival2response = first_run - arrivalFINISHEDFIFOAAAAABBBBBCCCCCA 5A 0B 10B 5C 15C 10ROUND ROBINABCABCABCABCABCA 13A 0B 14B 1C 15C 2turnaroundresponseturnaroundresponse051015 sfirst 3 sABC
Back: the ready queue, the CPU and the timerFront: one timeline per scheduler, one cell per second, and its scoresJobs A, B, C: each second on the CPU drops a tile of the job's colourAt the back, the ready queue with three 5-second jobs, the CPU and the timer. In the middle, the two formulas and a tray for finished jobs. In front, a timeline per scheduler, one cell per second, with its scores. FIFO runs A, B, C to the end: average turnaround 10 s, average response 5 s. Round robin with a 1 s slice takes turns: response drops to 1 s, but turnaround rises to 14 s. Over the first 3 s round robin shares the CPU evenly; FIFO does not. The 1-second slice keeps the numbers easy, as in OSTEP's example. Real time slices are milliseconds long, and each must be a multiple of the timer-interrupt period.

Run to the end

  1. Three jobs, A, B and C, arrive together at time 0. Each needs 5 seconds of CPU. There is one CPU, so the scheduler, the part of the kernel that picks who runs next, must choose an order.

Taking turns

The trade-off

What happens

;; step 1/10 · jobs
job   arrives   needs
A     t = 0     5 s of CPU
B     t = 0     5 s of CPU
C     t = 0     5 s of CPU

total work    15 s on one CPU
the question  who runs next, and for how long?
to compare answers we need scores (metrics)

The 1-second slice keeps the numbers easy, as in OSTEP's example. Real time slices are milliseconds long, and each must be a multiple of the timer-interrupt period. The figure ignores the cost of each context switch. It is not zero: OSTEP notes that with a 10 ms slice and a 1 ms switch cost, about 10% of the CPU is wasted, and switching also loses warm caches. That is why slices cannot be made tiny.