Simvik

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 c ticks, 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 index into out[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... 0

Overloaded, 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 1

Learn it first

More RTOS scheduling problems