Response-time analysis
Compute worst-case response times under fixed-priority scheduling and check every deadline. A hard embedded C problem (RTOS scheduling), run and graded in…
hard · RTOS scheduling · rtos · rate-monotonic · schedulability
Periodic tasks run under preemptive fixed-priority scheduling; tasks[0] has the highest priority. A task's worst-case response time R is its own execution time plus the time stolen by every higher-priority task released while it waits:
R = C_i + sum over j < i of ceil(R / T_j) * C_j
R appears on both sides, so iterate: start with R = C_i and recompute until the value stops changing. If it ever exceeds the task's period, the task misses its deadline.
Fill response[i] with each task's worst-case response time, or 0 if it misses its deadline. Return true if every task meets its deadline.
Starter code
bool rm_schedulable(const rt_task_t *tasks, size_t n, uint32_t *response) {
bool ok = true;
for (size_t i = 0; i < n; i++) {
uint32_t r = tasks[i].c;
for (size_t j = 0; j < i; j++) r += tasks[j].c; // one preemption each
response[i] = r <= tasks[i].t ? r : 0;
if (r > tasks[i].t) ok = false;
}
return ok;
}Example tests
A schedulable set
rt_task_t t[] = { { 1, 4 }, { 2, 6 }, { 3, 12 } };
check(t, 3);Expected output:
1 1 3 10An overloaded set
rt_task_t t[] = { { 2, 4 }, { 3, 6 }, { 1, 8 } };
check(t, 3);Expected output:
0 2 0 0Learn 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.
- 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.
- Ventilator: will every task meet its deadline? · Prove the ventilator's tasks are schedulable with response-time analysis, not just a utilisation total.