Overview
Curated: · Written: · Reviewed:
Real-Time Embedded Systems
In one line
Real-time means bounded: every job must finish before its deadline in the worst case, not on average. Reach for it whenever a late result changes physical behaviour, and prove the bound with worst-case analysis on target hardware, not with a benchmark.
Key definitions
- Hard real-time: a missed deadline is a system failure (PWM update, attitude loop).
- Firm real-time: a late result is discarded; the system survives.
- Soft real-time: value decays with lateness (telemetry, UI).
- WCET: upper bound on one job's execution time on this hardware, with this cache state and these inputs.
- Blocking (B): time a task waits on a lock held by a lower-priority task.
- Jitter: variation in latency or response time across events.
Formulas and complexity
Response-time analysis, iterated until R_i converges or exceeds D_i:
The task set is schedulable when R_i is at most D_i for every task. Rate-monotonic assigns higher priority to shorter periods (deadline equals period). EDF can reach 100% utilization for independent preemptible tasks; fixed priority cannot.
How it works
The delay from event to effect is a pipeline, and each stage has its own owner and fix.
- The preemptive scheduler always runs the highest-priority ready task, so higher-priority interference is analyzable.
- ISRs stay short. Variable work goes to a task through an ISR-safe queue or event flag.
- A low-priority lock holder blocks a high-priority task. Priority inheritance bounds that blocking to the critical section length.
- A watchdog turns hangs into resets. It only protects you if it is fed by evidence that the control loop progressed.
When to use and when not to
| Option | Choose when | Watch out for |
|---|---|---|
| Fixed priority (RM/DM) | Periods are fixed and each task must be analyzed on its own | Adding a task can break schedulability; overload hits low-priority tasks first |
| EDF | You need near-full utilization or deadlines vary per job | One overload cascades misses across tasks; harder to certify |
| Bare-metal superloop with ISRs | Few tasks and one deadline path | Every new path reopens the timing analysis by hand |
| Full RTOS | Many tasks, blocking IPC, need for inheritance | Adds scheduler overhead and lock behaviour to analyze |
| Heap allocation on the control path | Almost never | Fragmentation makes malloc latency unbounded |
Traps interviewers probe
- "Real-time means fast." Fix: state the bound and what a miss does. A guaranteed 100 ms response can be real-time; a 1 ms average with a 500 ms tail is not.
- Benchmarks as WCET. Fix: measure with adversarial inputs and cold and warm caches, add margin, and use response-time analysis for the bound. Samples can fail to disprove a bound, but they cannot establish one.
- Unbounded priority inversion. Fix: priority inheritance or a priority ceiling, short critical sections, and no blocking calls inside locks. Mars Pathfinder reset repeatedly until inheritance was enabled on the bus mutex.
- Watchdog fed from a timer tick. Fix: feed only after checking that the control loop and its inputs progressed. A tick-fed watchdog hides a dead loop.
- Adding a task without re-running analysis. Fix: repeat the response-time calculation for every task whose interference changed, then check margin.
Interview tips
Opening: classify the task by the consequence of a miss, then name the bound. For example: "This is hard real-time. A miss means the PWM update is late, so I need a WCET and a worst-case response time below the period."
Expect these follow-ups:
- How do you prove the task set is schedulable? (Response-time analysis with blocking and interference, on target hardware.)
- What is priority inversion and why does inheritance fix it? What does inheritance cost?
- Where does the time go between a sensor edge and the actuator? (Interrupt latency, ISR, context switch, task, output.)
- How do ISR and task share data safely? (Atomics or a critical section, plus explicit buffer ownership.)
- How do you handle DMA and cache coherency? (Clean or invalidate at ownership transfers, and barriers.)
- How does the watchdog know the system is healthy?
30-second outline:
- Classify the task by what a miss physically causes.
- Name the bound: WCET plus blocking plus higher-priority interference.
- Say how you prove it: response-time analysis, adversarial inputs, cold and warm caches, margin.
- Name the risks: unbounded inversion, ISR overrun, heap use on the control path, a watchdog that hides a hang.
- Say what you watch in the field: deadline-miss counters, reset causes, queue depth, stack margin.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.