GOAT EngineerPreparing your learning space…

System Design · Concept Library · Free article

Who Gets the CPU Next?

Compare FIFO and round-robin through the response, waiting and completion time of the same jobs.

A CPU scheduler chooses which ready job runs. FIFO keeps the first job on the core until it finishes in this model, which can leave a tiny job behind a long one. Round-robin gives each ready job a bounded quantum before moving unfinished work to the queue tail. That improves response for waiting jobs, but frequent preemption can spend time switching instead of completing useful work.

Ready is different from running and blocked

A running task currently occupies a CPU core. A ready task has the information and resources it needs to run, but is waiting for a core. A blocked task is waiting for an event such as device completion, so giving it a core would not make that wait finish.

On one core, at most one task runs at an instant. The scheduler chooses from the ready queue. Changing that policy changes who waits even when the sum of useful CPU work stays the same.

The lab's scheduling workloads contain CPU work only, so jobs are ready after arrival until they run. The following I/O lesson adds a real blocked interval.

The fixed convoy workload: one tick is a teaching unit, not a measured millisecond
Job in the labImage-service taskArrival tickCPU work
longBatch resize0 (first in the tie)8 ticks
tinyThumbnail0 (second in the tie)2 ticks
shortMetadata13 ticks

Think of CPU work as loop iterations grouped into equal-cost chunks. If the resize loop needs eight chunks, a pause after chunk two leaves six. Pausing does not restart the loop or throw its array away: a context switch saves enough execution state to continue later. For this lesson, the three loops are independent, and none waits on a file or another job. The metadata job has not arrived at tick zero; it is neither ready nor blocked on I/O yet.

FIFO is simple, but the first long job can form a convoy

First in, first out, shortened to FIFO, selects the earliest ready job. In this teaching model the selected job keeps the core until it finishes. The eight-tick resize and two-tick thumbnail both arrive at tick zero, with the resize first in the tie order, so the thumbnail's first response waits eight ticks even though it needs little work.

This is a convoy effect: short work waits behind a long CPU occupant. FIFO is predictable and avoids quantum-driven preemption, but arrival order can dominate responsiveness. It may still be appropriate for a batch queue where completion throughput matters more than interactive response.

Round-robin bounds one turn with a quantum

Round-robin lets a job run for at most a quantum, a fixed amount of CPU time. If the job remains unfinished when that turn ends, the scheduler places it at the ready-queue tail. With a two-tick quantum, the long resize runs for two ticks, then the thumbnail gets a turn and can finish.

The useful work has not disappeared. The long job still needs its remaining six ticks. The policy improved the thumbnail's response and completion while extending the long job's completion. Saying that round-robin is faster would hide whose time changed.

Enable JavaScript to compare the two choices in the compact concept diagram. The worked examples explain the same process boundary, scratch ownership, CPU schedule or pending-I/O consequence without requiring the interactive.

One core, zero switch cost: hand-check both schedules
PolicyCPU intervals (start inclusive, end exclusive)Tiny responseTiny turnaroundBatch turnaround
FIFOlong 0 to 8; tiny 8 to 10; short 10 to 138 ticks10 ticks8 ticks
Round-robin, quantum 2long 0 to 2; tiny 2 to 4; short 4 to 6; long 6 to 8; short 8 to 9; long 9 to 132 ticks4 ticks13 ticks

The metadata job arrives during the first resize turn, so it joins the queue before the resize is put back at tick two. In the round-robin row, the last long interval contains two two-tick turns with no other job left to run. All 13 useful ticks still execute. The thumbnail finishes six ticks earlier, while the batch finishes five ticks later. That is the trade-off the diagram should let you see.

Response, waiting and completion answer different questions

Timing from one recorded schedule
MeasureDefinition in this modelQuestion
Response timefirst run tick minus arrival tickHow long before this job first receives CPU?
Turnaround timefinish tick minus arrival tickHow long until all of this job is done?
Waiting timeticks spent ready but not runningHow long was runnable work queued?
Useful CPU timeticks executing job workHow much declared computation ran?
Switch costticks charged when a quantum preemptsHow much modeled time did scheduling consume?

A policy can improve response without improving every completion time. It can also keep every job making progress while finishing the whole workload later because of switch overhead. Report the measure tied to the user need.

Two cores change the capacity boundary. Three independent four-tick jobs require twelve core-ticks of useful work. One core needs twelve elapsed ticks. Two cores can finish two jobs together, then the third, for eight elapsed ticks under FIFO. Useful work stays twelve core-ticks.

A finish timestamp and a turnaround duration are different. Metadata finishes at tick 13 under FIFO but arrived at tick 1, so its turnaround is 12 ticks. It first runs at tick 10, giving a response of 9 ticks. With CPU-only jobs, waiting equals turnaround minus useful work: 12 minus 3 is 9. Once blocking I/O is included, device waiting must also be subtracted; it is not time spent in the ready queue.

A tiny quantum can spend the schedule on switching

Preemption requires the system to preserve one execution context and resume another. Real cost can include kernel work and indirect cache effects. The lab uses a declared direct cost of zero, one or two ticks at each quantum preemption, including a renewed turn when nobody else is ready. This simplified dispatcher pauses both modeled cores during that cost and charges no cost for ordinary completion-to-next-job dispatch. Real per-core switching does not generally stop every core. Use this convention to compare these traces, not to estimate a machine's latency.

With a one-tick quantum and a two-tick switch cost, a four-tick job is interrupted three times before it finishes. The model can spend more ticks switching than running that job. Raising the quantum reduces switches, but delays the next ready job's turn. There is no universally best quantum independent of workload and objective.

Linux documents FIFO and round-robin as real-time scheduling policies with priority rules. Our lab borrows their basic queue and quantum ideas, not Linux's entire scheduler, priority model or default policy.

Ungraded transfer checks

A job is ready while the CPU is idle. What should you investigate?
The scheduler or admission model is preventing eligible work from running. It is not blocked on an external event under the stated state.
Does a shorter quantum remove CPU work?
No. It changes turns and can add switching cost. The jobs still require the same useful work.
Why can the thumbnail improve while the batch job finishes later?
Round-robin gives the thumbnail an earlier turn by interrupting the batch job. The batch keeps remaining work and may also pay switch overhead.
Can two cores halve every workload?
No. Work must be independently runnable, and serial dependencies or blocked operations can leave a core idle.

Your turn: repair four CPU schedules

Make the tiny job respond, reduce excessive switching, use a second core for independent work and preserve batch completion while improving response. Pin a result before changing policy so the comparison retains the same workload.

A scheduler chooses among ready jobs. FIFO keeps the running job until it finishes in this model. Round-robin limits each turn with a quantum, improving response for waiting jobs while adding context-switch cost when the quantum expires.

Open The CPU scheduling workbench. Editable controls require JavaScript; the article and model limits remain readable here.

Sources and model limits

  • Linux scheduling overview documents FIFO and round-robin real-time policies and quantum behavior.
  • OSTEP scheduling introduction derives turnaround and response trade-offs from small workloads.
  • The workbench has three jobs, one or two cores and an 80-tick bound. It omits priorities, migration, cache state, interrupts, deadlines and the Linux normal scheduler.

Published by GOAT Engineer. Continue with system calls and blocking I/O. Privacy policy · [Contact](mailto:[email protected]).

By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.