Skip to main content

3.1 CPU Scheduling Criteria: Turnaround Time, Waiting Time, Response Time & Throughput

📚Module 03: CPU Scheduling AlgorithmsTopic 3.1⏱️12 min read
🎯High-Yield For:Computer Science Foundations • Systems Engineering • Technical Interviews

💡 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:

Architecture Flow

The Outpatient Clinic Analogy Pipeline

Mapping real-world clinic workflows to CPU scheduling architecture

💡 Hover or click any card for deep-dive operational details
🛋️Memory Buffer

Clinic Waiting Room

Kernel Ready Queue

Patients (processes) queue up upon arrival awaiting checkup.

→
Receptionist Calls
📋Kernel Arbiter

Head Receptionist

Short-Term Scheduler (STS)

Evaluates patient arrival order and medical urgency to allocate the doctor.

→
Dispatches To
🩺Execution Unit

Doctor's Cabin

Physical CPU Core

The doctor (CPU) actively examines patient until prescription or lab test.

  • Arrival Time (ATAT): Time at which patient enters the waiting room.
  • Burst Time (BTBT): Amount of doctor consultation time required by the patient to finish treatment.
  • Response Time (RTRT): Time it takes for the doctor to start responding to the patient for the first time.
  • Waiting Time (WTWT): Sum of periods spent waiting idly in the clinic waiting room.
  • Completion Time (CTCT): Time at which patient finishes treatment and exits the clinic.
  • Turnaround Time (TATTAT): Total elapsed time from clinic arrival to final departure (CT−ATCT - AT).

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

Cooperative

Non-Preemptive Scheduling

🤝
Dominant Architecture / DomainUnder 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 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.
"The process keeps the CPU until it releases the CPU willingly."
Forced Out

Preemptive Scheduling

⚡
Dominant Architecture / DomainUnder Preemptive scheduling, once the CPU has been allocated to a process, a process will leave CPU willingly or it can be forced out.
  • •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.
"A process will leave CPU willingly or it can be forced out."

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:

  1. When process completes its execution [Termination state].
  2. 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:

  1. When a process completes its execution.
  2. When process wants to perform some I/O operation.
  3. In case, a new process has high priority.
  4. 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.
The Kernel Classification Rule
  • 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:"

  1. CPU Utilization: Keeping the CPU as busy as possible.
    • In a real system, CPU utilization should range from 40%40\% (lightly loaded) to 90%90\% (heavily loaded).
  2. 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.
  3. Waiting Time: Waiting time is the sum of periods spent waiting in the ready queue.
  4. Response Time: Is the time it takes to start responding, not the time it takes to output the response.
  5. Turnaround Time: Total time elapsed from submission to completion.
The Core Invariance Rule of I/O Execution

"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

Maximize (Higher is Better)

📈
Dominant Architecture / DomainWork Output & Hardware Saturation
  • •CPU Utilization: Keep the CPU core as busy as possible (target: 40% to 90%).
  • •Throughput: Maximize the number of processes completed per unit time.
"Maximize CPU utilization and Throughput."
Minimize

Minimize (Lower is Better)

📉
Dominant Architecture / DomainLatency & User Delay Reduction
  • •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.
"Minimize Turn around time, Waiting time and Response time."

4. Terminology of CPU Scheduling​

Operating systems record the following standard time benchmarks for every process:

1. Arrival Time (ATAT)​

Definition: Time at which process enters a ready state (enters the ready queue).

2. Burst Time (BTBT)​

Definition: Amount of CPU time required by process to finish its execution.

3. Completion Time (CTCT)​

Definition: Time at which process finishes its execution.

4. Turnaround Time (TATTAT)​

Definition: Total elapsed time from arrival to completion.

TAT=Completion Time (CT)−Arrival Time (AT)\mathbf{TAT = \text{Completion Time } (CT) - \text{Arrival Time } (AT)} or\text{or} TAT=Waiting Time (WT)+Burst Time (BT)\mathbf{TAT = \text{Waiting Time } (WT) + \text{Burst Time } (BT)}

5. Waiting Time (WTWT)​

Definition: Sum of periods spent waiting in the ready queue.

WT=Turn around time (TAT)−Burst time (BT)\mathbf{WT = \text{Turn around time } (TAT) - \text{Burst time } (BT)} WT=(CT−AT)−BT\mathbf{WT = (CT - AT) - BT}

6. Response Time (RTRT)​

Definition: The time it takes to start responding (the interval from arrival to the first CPU allocation).

RT=(Time of First CPU Allocation)−AT\mathbf{RT = (\text{Time of First CPU Allocation}) - AT}

Non-Preemptive vs. Preemptive Waiting Mechanics
  • In Non-Preemptive algorithms, once a process gets the CPU, it runs without interruption. Therefore, Response Time is identical to Waiting Time (RT=WTRT = WT).
  • In Preemptive algorithms, a process may get the CPU quickly but suffer preemption repeatedly, causing Waiting Time to exceed Response Time (WT>RTWT > RT).

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 IDArrival Time (ATAT)Burst Time (BTBT)
P1P_10 ms0\text{ ms}4 ms4\text{ ms}
P2P_21 ms1\text{ ms}3 ms3\text{ ms}
P3P_32 ms2\text{ ms}5 ms5\text{ ms}

Execution Order:​

  • At t=0t = 0: P1P_1 arrives and executes for 4 ms4\text{ ms} →\to Runs from 00 to 44.
  • At t=4t = 4: P1P_1 finishes. Both P2P_2 (arrived at 11) and P3P_3 (arrived at 22) are ready. By arrival order, P2P_2 executes for 3 ms3\text{ ms} →\to Runs from 44 to 77.
  • At t=7t = 7: P2P_2 finishes. P3P_3 executes for 5 ms5\text{ ms} →\to Runs from 77 to 1212.
⏱️

CPU Execution Gantt Chart: Three-Process Schedule

Timeline showing non-preemptive execution from t = 0 to t = 12 ms

P1Burst: 4ms
P2Burst: 3ms
P3Burst: 5ms
04
7
12
Avg Turnaround6.67 ms
Avg Waiting Time2.67 ms
Throughput0.25 jobs/ms
CPU Utilization100%

Tabulation of Derived Metrics:​

ProcessATATBTBTCompletion (CTCT)Turnaround (TAT=CT−ATTAT = CT - AT)Waiting (WT=TAT−BTWT = TAT - BT)Response (RTRT)
P1P_10044444−0=44 - 0 = \mathbf{4}4−4=04 - 4 = \mathbf{0}0−0=00 - 0 = \mathbf{0}
P2P_21133777−1=67 - 1 = \mathbf{6}6−3=36 - 3 = \mathbf{3}4−1=34 - 1 = \mathbf{3}
P3P_32255121212−2=1012 - 2 = \mathbf{10}10−5=510 - 5 = \mathbf{5}7−2=57 - 2 = \mathbf{5}
  • Average Turnaround Time (TAT‾\overline{TAT}): TAT‾=4+6+103=203≈6.67 ms\overline{TAT} = \frac{4 + 6 + 10}{3} = \frac{20}{3} \approx \mathbf{6.67\text{ ms}}
  • Average Waiting Time (WT‾\overline{WT}): WT‾=0+3+53=83≈2.67 ms\overline{WT} = \frac{0 + 3 + 5}{3} = \frac{8}{3} \approx \mathbf{2.67\text{ ms}}
  • Throughput: Throughput=3 processes12 ms=0.25 processes/ms=250 processes/sec\text{Throughput} = \frac{3\text{ processes}}{12\text{ ms}} = \mathbf{0.25\text{ processes/ms}} = \mathbf{250\text{ processes/sec}}
  • CPU Utilization: CPU Utilization=12−012×100%=100%\text{CPU Utilization} = \frac{12 - 0}{12} \times 100\% = \mathbf{100\%}

📐 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 (AT,RT,WT,CTAT, RT, WT, CT) are captured:

Architecture Flow

Process Lifecycle Scheduling Milestones: Time Benchmark Architecture

Tracking Arrival, First Dispatch (Response), Ready Queue Waits, and Final Completion

📋Kernel Ready Queue (Memory)
⚡Physical CPU Core Execution
1First Dispatch
2Quantum Expire
3Final Run
📥Clock: t = AT
Arrival Time (AT)
Enters Ready Queue
⚡RT = t - AT
First CPU Grant (RT)
First Instruction Run
⏳WT = TAT - BT
Preempt / Wait (WT)
Accumulating Wait Time
🏁TAT = CT - AT
Completion Time (CT)
Process Terminates
💡Click or hover any card or transition arrow above to inspect deep-dive operational mechanics

🏭 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

Bounded Latency

Target Latency (sched_latency_ns)

🎯
Dominant Architecture / Domainsysctl: kernel.sched_latency_ns (Default: 6ms - 24ms)
  • •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.
"Every runnable thread receives an equitable slice within this target window."
Thrashing Guard

Minimum Granularity (min_granularity_ns)

🛡️
Dominant Architecture / Domainsysctl: kernel.sched_min_granularity_ns (Default: 0.75ms - 3ms)
  • •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).
"Guarantees a lower bound on execution so processes make measurable computational progress."

1. Dynamic Slice Computation​

When NN tasks are runnable, CFS dynamically computes each process slice as: Timeslice=sched_latency_nsN\text{Timeslice} = \frac{\text{sched\_latency\_ns}}{N} However, if NN 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: 100,000 μs=100 ms100{,}000\,\mu\text{s} = 100\text{ ms}).
  • cpu.cfs_quota_us: The maximum CPU time the container may consume within that window (e.g., 50,000 μs50{,}000\,\mu\text{s} for 0.50.5 CPU core).

If a container exhausts its quota before the 100 ms100\text{ ms} period expires, Linux preempts and freezes its threads until the next period, directly spiking Response Time (RTRT) and tail latency in production microservices.


🎯 Exam & Interview Pitfall Check​

Core Conceptual Questions

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:

  1. 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.
  2. 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.
  3. The 4 Circumstances:
    • Circumstance 1: When process wants to perform some I/O operation (Running →\to Waiting).
    • Circumstance 2: In case, the time quantum expires (Running →\to Ready).
    • Circumstance 3: In case, a new process has high priority / I/O completes (Waiting →\to Ready).
    • Circumstance 4: When process completes its execution (Running →\to Terminated).
  4. 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 (TATTAT) equals the sum of Waiting Time (WTWT) and Burst Time (BTBT). In what scenario is Response Time (RTRT) strictly equal to Waiting Time? Answer:

  1. By fundamental scheduling definitions: TAT=CT−ATTAT = CT - AT WT=TAT−BTWT = TAT - BT
  2. Rearranging: TAT=WT+BTTAT = WT + BT Total elapsed time consists strictly of time spent waiting in the ready queue (WTWT) plus active execution time on the CPU (BTBT).
  3. Condition for RT=WTRT = WT: 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:

  1. 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.
  2. 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.
Common Interview Traps
  • 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 t=0t = 0.
    • Always verify ATAT: If P1P_1 arrives at t=2t = 2 and no process exists at t=0t = 0, the CPU sits idle from t=0t = 0 to t=2t = 2. 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 RTRT and WTWT.
    • RTRT stops the instant the process runs its first time slice.
    • WTWT continues to accumulate during every subsequent preemption round until final completion.

💬

Discussion & Doubts