3.1 CPU Scheduling Criteria: Turnaround Time, Waiting Time, Response Time & Throughput
💡 Core Intuition
🍳 The Everyday Analogy: The Single-Doctor Outpatient Clinic
Imagine a busy outpatient medical clinic managed by one single specialist doctor (the CPU) and an administrative receptionist:
The Outpatient Clinic Analogy Pipeline
Mapping real-world clinic workflows to CPU scheduling architecture
Clinic Waiting Room
Patients (processes) queue up upon arrival awaiting checkup.
Head Receptionist
Evaluates patient arrival order and medical urgency to allocate the doctor.
Doctor's Cabin
The doctor (CPU) actively examines patient until prescription or lab test.
- Arrival Time (): Time at which patient enters the waiting room.
- Burst Time (): Amount of doctor consultation time required by the patient to finish treatment.
- Response Time (): Time it takes for the doctor to start responding to the patient for the first time.
- Waiting Time (): Sum of periods spent waiting idly in the clinic waiting room.
- Completion Time (): Time at which patient finishes treatment and exits the clinic.
- Turnaround Time (): Total elapsed time from clinic arrival to final departure ().
The Scheduling Dilemma: Preemptive vs. Non-Preemptive Care
- Non-Preemptive Doctor: Once the doctor is allocated to a patient, the patient keeps the doctor until releasing the cabin willingly. Even if an urgent case arrives, they must wait until the current patient finishes.
- Preemptive Doctor: The doctor can be interrupted. A patient leaves the cabin willingly or can be forced out if a higher-priority trauma case arrives or their consultation time slice expires.
💻 Bridging to Computer Science
In an operating system, the Short-Term Scheduler (STS) acts as the receptionist, evaluating the Ready Queue every few milliseconds to allocate the CPU Core (the doctor).
Because different workloads have contrasting requirements, computer scientists evaluate algorithms using precise Scheduling Criteria—benchmarks that quantify efficiency, responsiveness, and fairness.
📚 Core Deep-Dive & Concepts
1. Preemptive v/s Non-Preemptive Scheduling
Every CPU scheduling algorithm belongs to one of two fundamental execution philosophies:
Preemptive v/s Non-Preemptive Scheduling
Ground truth comparison based on process CPU release behavior
Non-Preemptive Scheduling
- •A process will leave CPU only: 1. When process completes its execution [Termination State].
- •A process will leave CPU only: 2. When process wants to perform some I/O operation [Waiting / Blocked State].
- •Zero race conditions inside kernel scheduling queues.
- •Classical Examples: FCFS, Non-Preemptive SJF, Non-Preemptive Priority.
Preemptive Scheduling
- •1. When a process completes its execution [Termination].
- •2. When process wants to perform some I/O operation [Waiting / Blocked].
- •3. In case, a new process has high priority.
- •4. In case, the time quantum expires.
Non-Preemptive Scheduling
Definition: Under Non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU willingly.
A process will leave the CPU only under two conditions:
- When process completes its execution [Termination state].
- When process wants to perform some I/O operation [Waiting State / Blocked State].
- Classical Examples: First-Come, First-Served (FCFS), Non-Preemptive Shortest Job First (SJF), Non-Preemptive Priority Scheduling.
Preemptive Scheduling
Definition: Under Preemptive scheduling, once the CPU has been allocated to a process, a process will leave the CPU willingly or it can be forced out.
A process running under preemptive scheduling will leave the CPU under four circumstances:
- When a process completes its execution.
- When process wants to perform some I/O operation.
- In case, a new process has high priority.
- In case, the time quantum expires.
- Classical Examples: Round Robin (RR), Shortest Remaining Time First (SRTF), Preemptive Priority Scheduling, Multilevel Feedback Queue (MLFQ).
2. The 4 CPU Scheduling Decision Circumstances
Formal OS theory structures the kernel dispatch points into four distinct lifecycle transition circumstances:
The 4 CPU Scheduling Decision Circumstances
The four lifecycle transition points where the kernel scheduler makes a dispatch decision
1. Running ➔ Waiting
Non-Preemptive (Willingly)- Condition: Process wants to perform some I/O operation or invokes waitpid().
- Kernel Action: Process voluntarily surrenders the CPU; PCB moved to I/O queue.
2. Running ➔ Ready
Preemptive (Forced Out)- Condition: In case, the time quantum expires via hardware timer interrupt.
- Kernel Action: Process is forced out of the CPU; PCB returned to Ready Queue.
3. Waiting ➔ Ready
Preemptive (Higher Priority)- Condition: In case, I/O completes and a new process has high priority.
- Kernel Action: Newly awakened high-priority process preempts current task.
4. Running ➔ Terminated
Non-Preemptive (Willingly)- Condition: When process completes its execution.
- Kernel Action: Process finishes execution and calls exit(); CPU assigned to next job.
- When scheduling takes place only under circumstances 1 and 4, the scheduling scheme is strictly Non-Preemptive. The process surrenders the CPU willingly.
- When scheduling can occur under circumstances 2 or 3, the scheduling scheme is Preemptive. The process can be forced out.
3. Scheduling Criteria
"Different CPU scheduling algorithms have different properties, and the choices of a particular algorithm may favour one class of process over another. So, in order to efficiently select a scheduling algorithm, the following criteria should be taken into consideration:"
- CPU Utilization: Keeping the CPU as busy as possible.
- In a real system, CPU utilization should range from (lightly loaded) to (heavily loaded).
- Throughput: If the CPU is executing a process, then work is being done. One measure of work is the number of processes that are completed per time unit, called throughput.
- Waiting Time: Waiting time is the sum of periods spent waiting in the ready queue.
- Response Time: Is the time it takes to start responding, not the time it takes to output the response.
- Turnaround Time: Total time elapsed from submission to completion.
"The CPU scheduling algorithm does not affect the amount of time during which a process executes I/O; it affects only the amount of time that a process spends waiting in the ready queue."
Desirable Optimization Goals
It is desirable to:
- Maximize: CPU Utilization and Throughput
- Minimize: Turnaround Time, Waiting Time, and Response Time
CPU Scheduling Optimization Goals
Maximizing throughput and utilization while minimizing turnaround, waiting, and response delays
Maximize (Higher is Better)
- •CPU Utilization: Keep the CPU core as busy as possible (target: 40% to 90%).
- •Throughput: Maximize the number of processes completed per unit time.
Minimize (Lower is Better)
- •Turnaround Time (TAT): Minimize total time from submission to completion.
- •Waiting Time (WT): Minimize total periods spent waiting in the ready queue.
- •Response Time (RT): Minimize the time it takes to start responding.
4. Terminology of CPU Scheduling
Operating systems record the following standard time benchmarks for every process:
1. Arrival Time ()
Definition: Time at which process enters a ready state (enters the ready queue).
2. Burst Time ()
Definition: Amount of CPU time required by process to finish its execution.
3. Completion Time ()
Definition: Time at which process finishes its execution.
4. Turnaround Time ()
Definition: Total elapsed time from arrival to completion.
5. Waiting Time ()
Definition: Sum of periods spent waiting in the ready queue.
6. Response Time ()
Definition: The time it takes to start responding (the interval from arrival to the first CPU allocation).
- In Non-Preemptive algorithms, once a process gets the CPU, it runs without interruption. Therefore, Response Time is identical to Waiting Time ().
- In Preemptive algorithms, a process may get the CPU quickly but suffer preemption repeatedly, causing Waiting Time to exceed Response Time ().
5. Gantt Chart Mechanics & Step-by-Step Derivation
A Gantt Chart is a horizontal bar chart illustrating the chronological schedule of the CPU core over advancing time units.
Consider three processes scheduled non-preemptively:
| Process ID | Arrival Time () | Burst Time () |
|---|---|---|
Execution Order:
- At : arrives and executes for Runs from to .
- At : finishes. Both (arrived at ) and (arrived at ) are ready. By arrival order, executes for Runs from to .
- At : finishes. executes for Runs from to .
CPU Execution Gantt Chart: Three-Process Schedule
Timeline showing non-preemptive execution from t = 0 to t = 12 ms
Tabulation of Derived Metrics:
| Process | Completion () | Turnaround () | Waiting () | Response () | ||
|---|---|---|---|---|---|---|
- Average Turnaround Time ():
- Average Waiting Time ():
- Throughput:
- CPU Utilization:
📐 Architecture / Visual Blueprint
Process Scheduling Milestones & Domain Interactions
The architectural blueprint below illustrates how a process transitions across memory and execution domains, tracing the exact moments where time metrics () are captured:
Process Lifecycle Scheduling Milestones: Time Benchmark Architecture
Tracking Arrival, First Dispatch (Response), Ready Queue Waits, and Final Completion
🏭 In The Real World: Production Case Study
How the Linux Completely Fair Scheduler (CFS) Quantifies Scheduling Latency
Modern production operating systems like Linux replace fixed time quanta with dynamic latency guarantees in the Completely Fair Scheduler (CFS):
Linux CFS Production Latency Balancing Knobs
How the Linux kernel prevents context thrashing while guaranteeing bounded response time
Target Latency (sched_latency_ns)
- •Scheduling Window: Period during which all currently active tasks are guaranteed to run at least once.
- •Dynamic Timeslice: Each process receives roughly (sched_latency_ns / N) milliseconds.
- •Smooth Multi-Tasking: Scales smoothly with light to moderate system workloads.
Minimum Granularity (min_granularity_ns)
- •Context Floor: Prevents timeslices from shrinking below viable execution boundaries under heavy load.
- •Anti-Thrashing Barrier: Stops the CPU from burning 90% of clock cycles swapping hardware registers.
- •Latency Extension: When task count N is huge, target latency automatically expands to (N × min_granularity).
1. Dynamic Slice Computation
When tasks are runnable, CFS dynamically computes each process slice as:
However, if grows large (e.g., 500 runnable threads), the calculated slice would shrink to microseconds, wasting excessive CPU cycles on register swapping. To prevent this, Linux enforces sched_min_granularity_ns as an absolute execution floor.
2. Cloud & Kubernetes CPU Throttling (cfs_quota_us)
In container runtimes (Docker, Kubernetes), CPU limits are enforced using CFS bandwidth quotas:
cpu.cfs_period_us: The evaluation window (default: ).cpu.cfs_quota_us: The maximum CPU time the container may consume within that window (e.g., for CPU core).
If a container exhausts its quota before the period expires, Linux preempts and freezes its threads until the next period, directly spiking Response Time () and tail latency in production microservices.
🎯 Exam & Interview Pitfall Check
Question 1: Define Preemptive and Non-Preemptive scheduling. Under which four specific CPU scheduling circumstances does the operating system make scheduling decisions, and which of these classify an OS as strictly non-preemptive? Answer:
- Non-Preemptive: Under Non-preemptive scheduling, once the CPU has been allocated to a process, the process keeps the CPU until it releases the CPU willingly.
- Preemptive: Under Preemptive scheduling, once the CPU has been allocated to a process, a process will leave the CPU willingly or it can be forced out.
- The 4 Circumstances:
- Circumstance 1: When process wants to perform some I/O operation (Running Waiting).
- Circumstance 2: In case, the time quantum expires (Running Ready).
- Circumstance 3: In case, a new process has high priority / I/O completes (Waiting Ready).
- Circumstance 4: When process completes its execution (Running Terminated).
- When scheduling occurs strictly under Circumstances 1 and 4, the system is non-preemptive. If decisions occur under 2 or 3, the system is preemptive.
Question 2: Prove mathematically why Turnaround Time () equals the sum of Waiting Time () and Burst Time (). In what scenario is Response Time () strictly equal to Waiting Time? Answer:
- By fundamental scheduling definitions:
- Rearranging: Total elapsed time consists strictly of time spent waiting in the ready queue () plus active execution time on the CPU ().
- Condition for : Response Time equals Waiting Time strictly in Non-Preemptive scheduling algorithms. Once a process gets the CPU, it runs to completion without interruption, so its first response wait equals its total waiting time.
Question 3: What is Throughput in CPU scheduling? Why does a higher number of completed processes not always indicate a superior scheduling algorithm? Answer:
- Throughput: If the CPU is executing a process, then work is being done. One measure of work is the number of processes completed per unit time.
- It depends on job mix: a system completing many tiny 1ms jobs has higher numeric throughput than one completing heavy 100ms simulations, even though the latter may have higher CPU utilization. Prioritizing short jobs to boost throughput can cause starvation for larger jobs.
- The "CPU Scheduling Affects I/O" Trap: Interviewers often ask: "Does a faster CPU scheduling algorithm reduce I/O wait time?"
- Trap: No! Core operating system theory dictates: "The CPU scheduling algorithm does not affect the amount of time during which a process executes I/O; it affects only the amount of time that a process spends waiting in the ready queue."
- The "Zero Arrival Time" Assumption: In standard scheduling problems, engineers often mistakenly assume all processes arrive at .
- Always verify : If arrives at and no process exists at , the CPU sits idle from to . Forgetting idle gaps corrupts all downstream Completion Time and Average Waiting Time calculations.
- Response Time vs. Waiting Time in Round Robin: In Round Robin, candidates frequently confuse and .
- stops the instant the process runs its first time slice.
- continues to accumulate during every subsequent preemption round until final completion.