Deadlines
A real-time task is late if it finishes after its deadline, even when the answer is right. Each of our three periodic tasks wakes every period, needs some work time (the longest it can ever take), and must finish before its next wake-up.
Rate monotonic scheduling gives the shortest period the highest priority: H gets 3, M gets 2, L gets 1. In our example they run as Linux SCHED_FIFO threads: the CPU always runs the highest-priority ready thread and preempts lower ones at once.
Add up work divided by period: U = 0.675. Liu and Layland proved rate monotonic meets every deadline when U is at most 0.780 for three tasks. EDF, earliest deadline first, can go up to 1. But both assume tasks never wait for each other.
Priority inversion
Now add a lock. At 0 ms only L is awake. It locks the bus mutex and starts its 3 ms of bus work. Our mutex is a plain one, with no priority tricks.
At 1 ms H wakes up. It outranks L, so the CPU switches to H at once. L is paused in the middle of its bus work and still owns the lock.
At 2 ms H needs the bus and calls lock, but L owns it. H must sleep until L unlocks. That is fine so far: L only has 2 ms of bus work left.
At 3 ms M wakes. It needs no lock, and it outranks L, so it preempts L and runs for 8 ms. H waits on L, and L waits on M: the highest-priority task is stuck behind a medium one. This is priority inversion.
M finishes at 11 ms. L does its last 1 ms of bus work and unlocks at 12 ms, which wakes H. H finishes at 13 ms, 2 ms after its deadline. The utilisation test said it was safe.
Priority inheritance
Same run, with priority inheritance. At 2 ms H blocks on the lock, and the kernel lends its priority 3 to L, the owner. At 3 ms M wakes but cannot preempt L now. L finishes its bus work.
L unlocks at 4 ms and drops back to priority 1. H gets the lock and finishes at 5 ms, 6 ms early. M runs afterwards. H now waits at most one critical section of L, never for M.
On Linux a program asks for this when it makes the mutex: PTHREAD_PRIO_INHERIT. The kernel then boosts the owner while a higher thread waits. Mars Pathfinder kept resetting in 1997 until engineers switched on the same kind of option in its VxWorks mutex.
What happens
;; step 1/11 · deadlines task period work deadline H control 10 ms 2 ms end of its period M video 20 ms 8 ms end of its period L logger 40 ms 3 ms end of its period H steers the machine; needs the bus for 1 ms M encodes video; never touches the bus L writes a log over the bus for 3 ms real time = predictable, not fast (Berkeley CS162)
The three tasks and their times are our own example, chosen so the numbers are small. The scheduler rules (fixed priorities, preemption, a lock that blocks, priority inheritance) are the ones POSIX and Linux SCHED_FIFO follow. The figure plays one 13 ms window, from L waking at 0 ms. In a full run each task wakes again every period; the deadline shown is the one for H's first wake-up, at 1 + 10 = 11 ms.