Simvik

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:

-1

Under 100 % busy, yet a deadline is missed

task_t t[2] = { { 2, 5 }, { 4, 7 } };
printf("%d\n", first_miss(t, 2));

Expected output:

1

Learn it first

More RTOS scheduling problems