Lab 7 / 15 · Timing · A/B
RTOS Scheduling and Priority Inversion
Three tasks fight over one CPU; flip on priority inheritance and see whether the high-priority task still gets stuck.
Scheduling policy
The medium-priority task never touches the lock; it is just 'busy'. The busier it is the less chance the low-priority task gets to release the lock when inheritance is off.
Readouts
A simplified model: single core, fixed priorities, time slicing only among equal priorities. The magnitudes reference a real FreeRTOS but do not replace measurement.
What problem this lab solves
Interviews ask «how do you fix priority inversion». Most people can recite the words «priority inheritance» but have never seen what it actually changes. This experiment puts three tasks on one timeline: who runs, who waits on the lock, and how long the high-priority task is stuck — visible at a glance.
How to read the figure
Three rows are three tasks, the horizontal axis is time, and only one row runs at any instant. Red is the high-priority task: the moment it becomes ready it should preempt everything. If it starts late, look at the row above it — a low-priority task is holding the lock. Flip the switch to «inheritance on»: the low-priority task temporarily rises to its level and the middle priority can no longer cut in. The hatched region is exactly how long the high-priority task was stuck.
Hands-on
First turn inheritance off and read the «high priority stuck» milliseconds; turn it on and see how far it drops. Then stretch the middle task's execution time and watch the stuck time grow with it when inheritance is off — that is what «unbounded» really means.
Done playing — where next
Related topics
Next labs (in play-learn order)
QoS and Callback Backlog
Drag publish rate, callback time, and queue depth, and watch latency climb from 3 ms to hundreds of milliseconds.
8 min
The Jitter Bill of a 1kHz Control Loop
The same control loop on stock Linux vs PREEMPT_RT — how many microseconds apart, made visible.
6 min
CAN vs EtherCAT: What Actually Differs
Two buses running side by side — one fights for every frame, the other arrives like a train on schedule.
5 min