Ventilator: will every task meet its deadline?
Prove the ventilator's tasks are schedulable with response-time analysis, not just a utilisation total. A hard embedded C problem (RTOS scheduling), run and…
hard · RTOS scheduling · response-time-analysis · rate-monotonic · deadlines · product
Product: ICU ventilator (Medical)
Requirement. The ventilator's pressure loop, valve driver and display share one CPU under a fixed-priority RTOS. The safety case must show that every task finishes before its next period, in the worst case.
Tasks are given highest priority first. For each task i, its worst-case response time R is the smallest fixed point of
R = C[i] + sum over higher-priority tasks j of ceil(R / T[j]) × C[j]
Start with R = C[i] and repeat until R stops changing; if it ever exceeds T[i], the task misses its deadline.
Return the index of the first task that misses, or -1 if all meet their deadlines.
Starter code
int first_miss(const task_t *t, size_t n) {
uint32_t u = 0;
for (size_t i = 0; i < n; i++) u += t[i].c_us * 1000 / t[i].t_us;
return u <= 1000 ? -1 : (int)n - 1;
}Example tests
The ventilator's three tasks
task_t t[3] = { { 200, 1000 }, { 1000, 5000 }, { 10000, 50000 } };
printf("%d\n", first_miss(t, 3));Expected output:
-1Under 100 % busy, yet a deadline is missed
task_t t[2] = { { 2, 5 }, { 4, 7 } };
printf("%d\n", first_miss(t, 2));Expected output:
1Learn it first
- RTOS scheduling and timing · Preemption, context switches, ticks and rate-monotonic analysis.
More RTOS scheduling problems
- Drift-free periodic wake-up · Compute how long a periodic task should sleep so its period never drifts.
- Response-time analysis · Compute worst-case response times under fixed-priority scheduling and check every deadline.
- Find the highest ready priority · Pick the highest priority from a 32-bit ready bitmap.
- Rate-monotonic utilisation test · Decide from CPU utilisation whether a task set is schedulable under rate-monotonic priorities.
- Priorities with round-robin · Choose the next task to run, sharing the CPU in turns among tasks of equal priority.
- Earliest-deadline-first schedule · Simulate an EDF scheduler tick by tick, draw the timeline and count missed deadlines.
- Priority inversion, tick by tick · Simulate a preemptive scheduler with a shared mutex, and see what priority inheritance changes.