THINK FIRST·CODE LATER

← All labs

RM vs. EDF: simulate the hyperperiod

Problem

Simulate periodic tasks on one CPU over one hyperperiod (the least common multiple of the periods), in steps of 1 time unit.

Input: first line RM or EDF; then name C T per line. Every task releases a job at times 0, T, 2T, …; the job needs C units and its deadline is its next release time.

At each step:

  1. For every task released at time t (t > 0) whose previous job is unfinished, record a miss — NAME missed its deadline at t=T (K units left) — and drop that job.
  2. Release new jobs (if t < hyperperiod).
  3. Run one unit of the highest-priority unfinished job: RM — shortest period first; EDF — earliest absolute deadline first; ties go to the task listed first in the input. If none, the CPU is idle.

Print RM over hyperperiod H: | T1 0-2 | T2 2-5 | ... | (merged segments, idle for idle time), then the miss lines in time order, then Deadline misses: n.

Input:

EDF
T1 2 5
T2 4 7

Output:

EDF over hyperperiod 35: | T1 0-2 | T2 2-6 | T1 6-8 | T2 8-12 | T1 12-14 | T2 14-15 | T1 15-17 | T2 17-20 | T1 20-22 | T2 22-26 | T1 26-28 | T2 28-30 | T1 30-32 | T2 32-34 | idle 34-35 |
Deadline misses: 0

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os5-2-data-1.txt

EDF
T1 2 5
T2 4 7
What your program must print for os5-2-data-1.txt
EDF over hyperperiod 35: | T1 0-2 | T2 2-6 | T1 6-8 | T2 8-12 | T1 12-14 | T2 14-15 | T1 15-17 | T2 17-20 | T1 20-22 | T2 22-26 | T1 26-28 | T2 28-30 | T1 30-32 | T2 32-34 | idle 34-35 |
Deadline misses: 0

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os5-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os5-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.