Earliest-deadline-first schedule
Simulate an EDF scheduler tick by tick, draw the timeline and count missed deadlines. A hard embedded C problem (RTOS scheduling), run and graded in the…
hard · RTOS scheduling · rtos · scheduling · simulation
Earliest-deadline-first always runs the job whose deadline is soonest. Simulate it from tick 0 for ticks ticks (at most 8 tasks):
- At every tick that is a multiple of a task's period, it releases a job needing
cticks, due at the next release. If the task's previous job still had work left at that moment, it missed its deadline: count one miss and drop its remaining work. - Then run, for one tick, the job with the earliest deadline (ties go to the lower task index). Write
'A' + task indexintoout[tick], or'.'if nothing is ready.
End out with '\0' and return the number of missed deadlines.
Starter code
int edf_timeline(const edf_task_t *tasks, int n, int ticks, char *out) {
for (int i = 0; i < ticks; i++) out[i] = '.';
out[ticks] = '\0';
return 0;
}Example tests
Two tasks with spare time
const edf_task_t ts[] = { { 1, 4 }, { 2, 6 } };
char out[32];
int m = edf_timeline(ts, 2, 12, out);
printf("%s %d\n", out, m);Expected output:
ABB.A.BBA... 0Overloaded, one deadline missed
const edf_task_t ts[] = { { 2, 3 }, { 2, 4 } };
char out[32];
int m = edf_timeline(ts, 2, 12, out);
printf("%s %d\n", out, m);Expected output:
AABBAABBAAAB 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.
- 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.