Test two task sets (C = execution time, T = period = deadline) under RMS: (a) (1, 4), (1, 5), (2, 10); (b) (1, 4), (2, 5), (2, 10).
A real-time OS guarantees that tasks finish by their deadlines. Learn hard, firm and soft systems, RTOS characteristics, task types, rate-monotonic and EDF scheduling with their utilisation tests, priority inversion, and clock synchronization: Cristian, Berkeley, NTP, Lamport and vector clocks.
In a real-time system the correctness of a computation depends not only on its logical result but also on the time at which the result is produced. Each task has a deadline. Real-time does not mean “fast”: a system that answers in 2 seconds every single time may be real-time, while one that usually answers in 1 ms but occasionally takes 5 s is not. Most real-time systems are embedded — part of a larger device such as a car, a pacemaker, a factory controller or a phone's baseband modem.
| Class | What a missed deadline means | Examples |
|---|---|---|
| Hard real-time | System failure — possibly catastrophic; every deadline must be met, guaranteed in advance | Airbag deployment, anti-lock brakes, pacemakers, fly-by-wire flight control, nuclear plant safety systems |
| Firm real-time | The late result is useless and is discarded, but occasional misses are tolerated | Video frames in a live stream, readings in a sensor-fusion pipeline, financial trading windows |
| Soft real-time | The result loses value gradually; misses degrade quality but are acceptable | Audio/video playback, VoIP calls, online games, multimedia |
General-purpose systems can support soft real-time work by offering real-time priority classes (Linux SCHED_FIFO and SCHED_RR, Windows' real-time priority class 16–31) that never age downward. Hard guarantees need an OS designed for bounded, predictable timing all the way down to interrupt handling.
Those five come from Stallings. Galvin's list stresses the mechanisms: preemptive, priority-based scheduling (the highest-priority ready task always runs, immediately), a preemptible kernel, and minimal interrupt latency (time from an interrupt's arrival to the start of its service routine) and dispatch latency (time to stop one task and start another). Dispatch latency has a conflict phase — preempting whatever runs in the kernel and making low-priority tasks release resources a high-priority task needs — followed by the dispatch itself. RTOS kernels also keep a small memory footprint, avoid demand paging for critical tasks, and provide precise timers and priority-inheritance locks.
A periodic task needs the CPU at constant intervals. It is described by its period p, its worst-case execution (processing) time t, and its relative deadline d, with 0 ≤ t ≤ d ≤ p; usually d = p, meaning each job must finish before the next is released. Its rate is 1/p and its CPU utilisation is t/p. The pattern of a task set repeats every hyperperiod — the LCM of the periods — so checking one hyperperiod checks the whole schedule.
Before accepting a task, an RTOS can apply admission control: it admits the task only if it can guarantee the deadline, rejecting it otherwise. Stallings groups real-time scheduling approaches as static table-driven (a precomputed timetable or cyclic executive), static priority-driven preemptive (rate-monotonic), dynamic planning-based (feasibility checked when a task arrives) and dynamic best-effort (no guarantee — most commercial systems).
Rate-monotonic scheduling (RMS), analysed by Liu and Layland in 1973, gives each periodic task a static priority inversely proportional to its period: the shorter the period (the higher the rate), the higher the priority. Scheduling is preemptive — a newly released higher-priority job interrupts a lower-priority one. RMS is optimal among static-priority algorithms: if any fixed-priority assignment can schedule a task set, RMS can.
Example: tasks (C, T) = (1, 4), (1, 5) and (2, 10) give U = 0.25 + 0.20 + 0.20 = 0.65 ≤ 0.780, so RMS meets every deadline. The test is sufficient but not necessary: a set with U above the bound may still be schedulable. Then apply the exact response-time analysis: the worst-case response time of task i solves Rᵢ = Cᵢ + Σ⌈Rᵢ / Tⱼ⌉·Cⱼ over all higher-priority tasks j; iterate from Rᵢ = Cᵢ until the value repeats, and the task is safe if Rᵢ ≤ Tᵢ.
Earliest-deadline-first (EDF) assigns priorities dynamically: whenever a job is released, the ready job with the earliest absolute deadline gets the CPU, preempting the running one if necessary. On a single processor with preemption, EDF is optimal — if any algorithm can meet all deadlines, EDF can — and for periodic tasks with deadlines equal to periods it succeeds if and only if U ≤ 1. It does not even require tasks to be periodic or to have constant execution times; each job just announces its deadline.
Least-laxity-first (LLF) is a related dynamic policy: laxity = deadline − current time − remaining execution time, the slack a job can still afford; the job with the least laxity runs. Proportional-share scheduling (Galvin) allocates T shares among all tasks, a task with N shares receiving N/T of the CPU, and uses admission control to refuse a task whose shares cannot be granted.
Priority inversion occurs when a high-priority task H waits for a resource (a mutex) held by a low-priority task L. That alone is unavoidable and short. The danger is a medium-priority task M that does not need the resource: it preempts L, so L cannot finish its critical section and release the lock, and H — the most important task — effectively waits for M. With several medium tasks the delay is unbounded.
The famous case is Mars Pathfinder (landed July 1997), running VxWorks. A low-priority meteorological task held a mutex guarding the information bus; a high-priority bus-management task needed it; medium-priority communication tasks kept preempting the low-priority one. A watchdog noticed the high-priority task had not run in time and reset the computer — repeatedly. Engineers diagnosed it from Earth and uploaded a patch enabling priority inheritance on that mutex.
| RTOS | Notes |
|---|---|
| VxWorks (Wind River) | Commercial; NASA Mars missions from Pathfinder onward, aerospace, defence and industrial control |
| QNX Neutrino | POSIX microkernel (owned by BlackBerry since 2010); car infotainment and driver-assistance systems, medical devices |
| FreeRTOS | Open source (MIT licence) for microcontrollers; created by Richard Barry in 2003, maintained by Amazon since 2017 |
| RTLinux | A small hard real-time kernel that runs Linux itself as its lowest-priority task; today mainline Linux also includes PREEMPT_RT (merged in kernel 6.12, 2024) |
| Others | Zephyr, RTEMS, ThreadX, µC/OS, VRTX, pSOS, LynxOS, INTEGRITY |
A distributed system has no global clock. Each computer counts oscillations of a quartz crystal, and no two crystals run at exactly the same rate. The difference between two clocks' readings at one instant is the clock skew; the rate at which a clock gains or loses relative to perfect time is its drift rate ρ — typically about 10⁻⁶, roughly 1 second every 11.6 days. To keep any two clocks within δ of each other, they must be resynchronised at least every δ / (2ρ) seconds, because they may drift in opposite directions. Synchronising with an external standard such as UTC (broadcast by radio stations and GPS satellites) is external synchronization; merely agreeing among themselves is internal synchronization.
Cristian's method assumes the request and reply take equal time. Clients repeat the exchange and trust the reply with the smallest RTT. A clock must never jump backwards — timestamps would stop increasing — so a fast clock is corrected by slewing: running it slightly slow until it is right. The step-through diagram on this page traces one exchange.
The Berkeley algorithm (Gusella and Zatti, for Berkeley UNIX, 1989) is for internal synchronization when no machine has a UTC receiver. A master (time daemon) polls every machine for its time, estimates each one's offset (allowing for the round trip as Cristian does), computes the average — a fault-tolerant average that ignores clocks far off the rest — and sends each machine the adjustment it must make, rather than a time value, so message delay does not distort it. The master adjusts its own clock too.
The Network Time Protocol (NTP), designed by David Mills (first specified in RFC 958, 1985; version 4 is RFC 5905, 2010), synchronises computers across the Internet to UTC through a hierarchy of strata. Stratum 0 devices are reference clocks (atomic clocks, GPS receivers); stratum 1 servers are directly attached to them; stratum 2 servers synchronise from stratum 1, and so on down to stratum 15, while 16 means unsynchronised. NTP runs over UDP port 123, typically achieving tens of milliseconds over the Internet and under a millisecond on a LAN. SNTP is a simplified client version; PTP (IEEE 1588) reaches sub-microsecond accuracy with hardware time-stamping.
Often processes do not need the true time — only an agreed order of events. Leslie Lamport (1978) defined the happened-before relation →: (1) if a and b are events in the same process and a occurs first, a → b; (2) if a is the sending of a message and b its receipt, a → b; (3) it is transitive — a → b and b → c give a → c. If neither a → b nor b → a, the events are concurrent (a ∥ b).
The guarantee is one-way: a → b ⇒ C(a) < C(b), but C(a) < C(b) does not imply a → b — the events may be concurrent. Breaking ties with process IDs, (C, process-id), turns the partial order into a total order that every process agrees on, which algorithms such as Ricart–Agrawala mutual exclusion and totally ordered multicast rely on.
Vector clocks (Fidge and Mattern, independently, 1988) capture causality exactly. Each of n processes keeps a vector V of n counters. Before a local event or a send, Pi increments V[i]; messages carry the whole vector; on receipt, Pj takes the component-wise maximum of its vector and the received one and then increments V[j]. Compare vectors element by element: V(a) < V(b) (every entry ≤, at least one <) if and only if a → b; if neither vector is ≤ the other, the events are concurrent. Version vectors in replicated databases use the same idea to detect conflicting updates.
| Lamport clock | Vector clock | |
|---|---|---|
| Size of a timestamp | One integer | n integers (one per process) |
| a → b implies | C(a) < C(b) | V(a) < V(b) |
| Converse holds? | No — cannot detect concurrency | Yes — V(a) < V(b) ⇔ a → b |
| Typical use | Total ordering of events (with tie-breaking) | Causality and conflict detection |
Try the problem first, then reveal the working one step at a time.
Test two task sets (C = execution time, T = period = deadline) under RMS: (a) (1, 4), (1, 5), (2, 10); (b) (1, 4), (2, 5), (2, 10).
Two tasks: T1 (C = 2, T = 5) and T2 (C = 4, T = 7), deadlines equal to periods. Show what happens under RMS and under EDF.
(a) A client sends a request at 10:00:00.000 (its clock) and receives the reply “10:00:03.200” at 10:00:00.080. What should it set its clock to, and how accurate is it? (b) A Berkeley master reads 10:00; slaves A, B and C report 10:08, 9:56 and 10:04. What adjustment does each machine receive?
P1 has events a (local), b (send m1 to P2), c (receive m3). P2 has d (receive m1), e (send m2 to P3). P3 has f (local), g (receive m2), h (send m3 to P1). Assign Lamport and vector timestamps. Are b and f ordered?
Compute the RMS bound for 4 tasks. Is the set (C, T) = (1, 5), (1, 6), (2, 10), (1, 8) guaranteed schedulable?
Three tasks have (C, T) = (2, 6), (3, 8) and (2, 12). Are they schedulable under EDF? Under RMS? Use response-time analysis if the Liu–Layland bound is inconclusive.
A client sends a time request at 08:15:20.100 by its clock and receives the reply 08:15:19.900 at 08:15:20.160. What time does Cristian's algorithm give, how far off was the client, and how should it correct itself?
A Berkeley master reads 3:00:00. Slaves report +12 s, −6 s and +300 s relative to it. The master ignores any clock more than 60 s from its own. What adjustment does each machine receive?
L (low priority) locks resource R at t = 0 and needs 3 time units inside its critical section. H (high) arrives at t = 1 and immediately requests R. M (medium, 5 units, does not use R) arrives at t = 2. When does H get R without and with priority inheritance?
10 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.