The idea: let the deadline set the priority

A real-time system runs periodic tasks: every T ticks a task releases a job that needs C ticks of CPU before its deadline, here the next release. Rate-monotonic scheduling gives each task one fixed priority, shorter period first, and proves on paper whether every deadline is met. Its set B, τ1 (C = 2, T = 5) and τ2 (C = 4, T = 7), fails: the CPU is busy only 97.1% of the time (U = 2/5 + 4/7 = 0.971), yet τ2 misses its deadline at tick 7. This page runs the same jobs under two dynamic-priority rules, where each job's priority comes from its own deadline, and counts what each rule costs.

Set B over ticks 0 to 14, drawn twice. Rate-monotonic: τ1 runs 0–1, τ2 runs 2–4, at tick 5 τ1's second job takes the CPU, and τ2 still has one tick left at its deadline 7, so it runs late at 7 and misses. Earliest deadline first: at tick 5 τ2 has deadline 7 and τ1 deadline 10, so τ2 keeps the CPU and is done at 6; τ1 runs 6–7 and meets its deadline 10
The two rules differ at one tick: at tick 5 RM looks at the period and preempts τ2; EDF looks at the deadlines and lets τ2 finish.

Earliest deadline first

Earliest deadline first (EDF) gives the CPU, at every tick, to the ready job with the nearest absolute deadline. A task has no fixed rank: τ1's job due at 10 loses to τ2's job due at 7, but τ1's job due at 20 beats τ2's job due at 21. On set B (Demo: EDF meets every deadline, set B) the critical moment is tick 5. τ1 releases its second job with deadline 10, while τ2's first job, due at 7, has one tick left. EDF keeps τ2, which finishes at 6, and τ1 runs 6–7, well before 10. Over the whole hyperperiod H = lcm(5, 7) = 35 ticks no job is late, the CPU is idle only at tick 34, and there are just 2 preemptions. Under RM (Demo: RM misses on set B) the same jobs give one miss and 5 preemptions.

This is no luck. Liu and Layland proved in 1973 that on one CPU, with deadlines equal to periods, EDF meets every deadline if and only if U = Σ C/T ≤ 1. No other scheduler can do better: if any order of the jobs works, EDF finds one. Fixed priorities only guarantee success under a lower bound (0.828 for two tasks); between that and 1 they may fail, as set B shows.

Least slack time

The slack (or laxity) of a job is how long it can still wait and finish in time: slack = d − t − C left, the deadline minus now minus the work left. Least slack time (LST, also called least laxity first) runs the job with the smallest slack. It is optimal on one CPU too, and it meets every deadline of set B (Demo: least slack, set B). The catch is that slack changes all the time. A waiting job's slack falls by one each tick; the running job's slack stays the same, because it does one tick of work in one tick of time. So two jobs with close slack keep overtaking each other, and the scheduler must recompute slack every tick.

Slack of τ1's and τ2's jobs under least slack time, ticks 0 to 8 of set B. At t = 0 both have slack 3 and τ1 runs (earlier deadline). At t = 1 τ1 still has 3 but waiting τ2 has dropped to 2, so τ2 runs. At t = 2 both are at 2 and τ1 runs again. τ2 then runs ticks 3 to 5 with slack 1, τ1's second job runs 6 and 7, and τ2's second job runs at 8
A waiting job's slack falls while the running job's stays level, so the lead changes hands and the CPU with it.

Counting preemptions

A preemption here means the job that ran in the last tick is unfinished and another job takes the CPU. Each one costs a context switch and cold caches on a real machine. On the same 35 ticks of set B (Demo: compare RM, EDF, LST on set B):

policydeadline missespreemptionspriority computed
RM1 (τ2 at 7)5once per task, offline
EDF02once per job, at its release
LST08every tick, for every ready job

EDF often preempts less than RM, because a newly released job usually has a later deadline than the one already running. LST pays for its constant re-ranking with extra switches, which is why real systems use EDF and not LST.

Overload and the domino effect

EDF's guarantee stops at U = 1. Set O asks for more than the CPU has: τ1 (C = 2, T = 3), τ2 (2, 6) and τ3 (2, 10), U = 2/3 + 1/3 + 1/5 = 1.2. On the page a late job is not dropped; it keeps running, as an overrunning task would. Under EDF a late job has the earliest deadline of all, because its deadline is already in the past. So it runs first and pushes the next jobs past their own deadlines, which then run first in turn: the domino effect (Demo: overload, EDF domino effect). The first miss is τ2 at 12, and by tick 30 there are 11 misses spread over all three tasks. Least slack behaves the same way, with 13 misses. Rate-monotonic misses only 3 deadlines, all of τ3 (Demo: overload, RM sheds τ3 only): τ1 and τ2 together use 2/3 + 2/6 = 1 of the CPU, so τ3 never runs, but the two higher-priority tasks never notice the overload.

Bar chart of deadline misses per task for set O, U = 1.2, over 30 ticks. RM: τ1 0, τ2 0, τ3 3, total 3. EDF: τ1 5, τ2 4, τ3 2, total 11. LST: τ1 7, τ2 4, τ3 2, total 13
Under overload, fixed priorities choose who loses (only τ3); EDF and LST let the misses spread to every task (Demo: overload, all three compared).

Which one to use

  • EDF when the load is known to stay at or below 1 and the CPU should be used fully. Linux offers it as SCHED_DEADLINE, with an admission test that refuses tasks that would push U past the limit, so overload cannot happen.
  • Fixed priorities (RM) when an overload must be possible but should hurt only the least important task. Most RTOS kernels work this way, and the analysis is on the rate-monotonic page.
  • LST mostly as a teaching tool and in some multiprocessor schemes; on one CPU it gives nothing EDF does not, at the price of more switches.

See also real-time scheduling on Linux (SCHED_FIFO, SCHED_RR and priority inversion), CPU scheduling (FCFS, SJF, round robin and CFS for ordinary processes), the cyclic executive, which fixes the whole schedule in a table before the system runs, and priority ceiling and the stack resource policy for tasks that share locks.

See also a time-triggered co-operative scheduler, the simpler non-preemptive way small microcontrollers run periodic tasks from one timer tick.

See also embedded software architectures for where fixed-priority preemption fits among simpler designs such as the super loop and the function queue.

What the page leaves out

One CPU, whole ticks, every task released at t = 0, deadlines equal to periods, and context switches that cost nothing. Tasks never block or share resources. A real LST scheduler would have to track slack continuously, not once per tick. The page does not cover the processor-demand test for deadlines shorter than periods, overload handling for EDF (dropping or skipping jobs, as in the RED and D-over algorithms), constant-bandwidth servers, or multiprocessor EDF.

On the mind map

Open the Operating Systems mind mapOperatingSystemsBoot and program start: from power on to main()Boot and program startProcesses and the kernel: how user code talks to the kernelProcesses and the kernelInterrupts and devices: hardware interrupts the CPUInterrupts and devicesScheduling and deadlock: who runs next, who gets whatScheduling and deadlockVirtual memory: every address is translatedVirtual memoryPhysical memory: who gets which bytes of RAMPhysical memoryFiles and storage: from open() down to the diskFiles and storageDisks and RAID: blocks down to platter or flashDisks and RAIDIsolation and security: limit what a process can doIsolation and securityContext switchContext switchswitch_mm loads CR3, switch_to swaps stacksCPU scheduling algorithmsCPU scheduling algorithmsFCFS, SJF, RR, CFS: compare waiting timeMultiprocessor SchedulingMultiprocessor SchedulingPer-CPU queues + stealing beat one lockMulti-Level Feedback QueueMulti-Level Feedback QueueUse your quantum, drop a levelLottery & strideLottery & strideTickets set shares; stride runs lowest passPreemptive vs cooperativePreemptive vs cooperativetimer forces a switch, or wait for yieldReal-time schedulingReal-time schedulingpriority inversion, fixed by inheritanceRate-monotonic analysisRate-monotonic analysisShort period = high priority; RTA decidesPriority ceiling and SRPPriority ceiling and SRPOne lower critical section, no deadlockEDF vs Least SlackEDF: any set with U ≤ 1; overload dominoesTime-triggered schedulerTime-triggered schedulerISR only flags; super loop runs, then sleepsCyclic executiveCyclic executivea timer runs a fixed frame tableSuper loop to RTOSSuper loop to RTOSUART worst: 13, 13, 8, 1 msLoad averageLoad averagedamped count of R and D tasksBanker's algorithmBanker's algorithmgrant only if a safe order still existsDeadlock detectionDeadlock detectionFind the cycle, then kill a victimOpen the Operating Systems mind mapOperating Systemswho runs next, who gets whatScheduling and deadlockContext switchContext switchswitch_mm loads CR3, switch_to swaps stacksCPU scheduling algorithmsCPU scheduling algorithmsFCFS, SJF, RR, CFS: compare waiting timeMultiprocessor SchedulingMultiprocessor SchedulingPer-CPU queues + stealing beat one lockMulti-Level Feedback QueueMulti-Level Feedback QueueUse your quantum, drop a levelLottery & strideLottery & strideTickets set shares; stride runs lowest passPreemptive vs cooperativePreemptive vs cooperativetimer forces a switch, or wait for yieldReal-time schedulingReal-time schedulingpriority inversion, fixed by inheritanceRate-monotonic analysisRate-monotonic analysisShort period = high priority; RTA decidesPriority ceiling and SRPPriority ceiling and SRPOne lower critical section, no deadlockEDF vs Least SlackEDF: any set with U ≤ 1; overload dominoesTime-triggered schedulerTime-triggered schedulerISR only flags; super loop runs, then sleepsCyclic executiveCyclic executivea timer runs a fixed frame tableSuper loop to RTOSSuper loop to RTOSUART worst: 13, 13, 8, 1 msLoad averageLoad averagedamped count of R and D tasksBanker's algorithmBanker's algorithmgrant only if a safe order still existsDeadlock detectionDeadlock detectionFind the cycle, then kill a victim
This page on the Operating Systems mind map · 78 pages in 9 branches · open it to see the whole map and test yourself in recall mode.