Scheduling criteria and formulas
Scheduling criteria and formulas
Recorded by Dr. Krithika L.B. Slot m2-sched-criteria
How the scheduler is judged, how to draw Gantt charts and compute waiting and turnaround times, and how FCFS, SJF and Priority scheduling behave.
By the end of this session you should be able to:
Process execution alternates between CPU bursts (computing) and I/O bursts (waiting for a device). Measured burst lengths follow a curve with many short CPU bursts and a few long ones: I/O-bound programs have many short bursts, CPU-bound programs a few long ones. Scheduling exists to fill the CPU whenever the running process starts an I/O burst.
The short-term scheduler must choose a new process when the running process:
wait()),If scheduling happens only in cases 1 and 4, it is non-preemptive (cooperative): once a process has the CPU it keeps it until it blocks or exits. Otherwise it is preemptive: the OS can take the CPU away. Preemption gives better response time but means a process can be interrupted while updating shared data — another reason for Module 3.
The dispatcher gives control to the chosen process: context switch, switch to user mode, jump to the right instruction. The time it takes is the dispatch latency.
Keep the CPU as busy as possible (40% lightly loaded – 90% heavily loaded).
Number of processes completed per time unit.
Submission to completion: TAT = CT − AT.
Time spent in the ready queue: WT = TAT − BT.
Submission to first run: RT = first start − AT.
AT arrival time · BT burst time · CT completion time · TAT turnaround · WT waiting · RT response. A Gantt chart is a bar showing which process runs in each time interval. Always draw it first, then fill the table.
The process that requests the CPU first gets it first — a simple FIFO queue. Non-preemptive.
P1 = 24, P2 = 3, P3 = 3 ms, all arriving at time 0.
Order P1, P2, P3: Gantt P1 [0–24] P2 [24–27] P3 [27–30]. WT = 0, 24, 27 → average 17 ms.
Order P2, P3, P1: Gantt P2 [0–3] P3 [3–6] P1 [6–30]. WT = 6, 0, 3 → average 3 ms. Same work, six times less waiting.
Convoy effect: short processes stuck behind one long CPU-bound process — like cars behind a truck. FCFS is simple and fair in arrival order but gives poor average waiting time and is bad for time-sharing.
Give the CPU to the process with the smallest next CPU burst (FCFS breaks ties). SJF is provably optimal: it gives the minimum average waiting time for a given set of processes, because moving a short job before a long one reduces the short job's wait by more than it increases the long job's wait.
P1 = 6, P2 = 8, P3 = 7, P4 = 3, all at time 0.
Order by burst: P4 [0–3] · P1 [3–9] · P3 [9–16] · P2 [16–24].
WT: P1 = 3, P2 = 16, P3 = 9, P4 = 0 → average 7 ms (FCFS in order P1..P4 would give 10.25 ms).
The scheduler cannot know the length of the next CPU burst. It predicts it with an exponential average of previous bursts:
\[ \tau_{n+1} = \alpha\, t_n + (1-\alpha)\, \tau_n, \qquad 0 \le \alpha \le 1 \]
where tn is the actual length of the n-th burst and τn the previous prediction. With α = 0.5, τ0 = 10 and actual bursts 6, 4, 6, 4: τ1 = 8, τ2 = 6, τ3 = 6, τ4 = 5. α = 0 ignores history's latest value; α = 1 uses only the last burst.
Each process has a priority number; the CPU goes to the highest priority (in this course, smaller number = higher priority). SJF is a special case where priority = predicted burst. Priorities can be internal (memory needs, I/O ratio) or external (importance, payment).
(burst, priority): P1 (10, 3), P2 (1, 1), P3 (2, 4), P4 (1, 5), P5 (5, 2), all at time 0.
Gantt: P2 [0–1] · P5 [1–6] · P1 [6–16] · P3 [16–18] · P4 [18–19].
WT: P1 = 6, P2 = 0, P3 = 16, P4 = 18, P5 = 1 → average 8.2 ms.
Problem: a low-priority process may wait forever while higher-priority ones keep arriving (indefinite blocking or starvation). Solution — aging: gradually raise the priority of processes that wait a long time, e.g. improve priority by 1 every 15 minutes, so eventually every process runs.
| Algorithm | Picks | Strength | Weakness |
|---|---|---|---|
| FCFS | Earliest arrival | Simple, no starvation | Convoy effect, high average WT |
| SJF | Shortest next burst | Optimal average WT | Burst must be predicted; long jobs may starve |
| Priority | Highest priority | Expresses importance | Starvation (fix with aging) |
Scheduling criteria and formulas
Recorded by Dr. Krithika L.B. Slot m2-sched-criteria
FCFS, SJF and Priority — worked examples
Recorded by Dr. Krithika L.B. Slot m2-fcfs-sjf-priority
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0FCFS: WT 0, 8, 12 → 6.67. SJF order P3, P2, P1: WT P3 = 0, P2 = 2, P1 = 6 → 2.67.
The length of the next CPU burst is not known in advance; it has to be predicted, e.g. by exponential averaging of past bursts.
0.5 × 4 + 0.5 × 12 = 8.
In FCFS, many short processes wait behind one long CPU-bound process, lowering CPU and device utilisation.
It increases the priority of a process the longer it waits, so eventually it reaches the top priority and runs.
All three algorithms let a process keep the CPU until it blocks. For interactive systems we must be able to take the CPU away. Next: preemptive and multilevel scheduling.
Continue to 2.5 — Round Robin, SRTF, preemptive priority, MLQ and MLFQ →