NivaarExam PrepOfficial exam papers ↗

19-Soft-A4 Real-Time Systems · May 2013

Question 3 of 6: FCFS vs. EDF Scheduling of Four Real-Time Tasks

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

National Exams — May 2013 — 04-Soft-A4 Real-Time Systems. Three-hour, closed-book exam (Casio or Sharp approved calculators only). Format: six questions of equal value (20% each); any five constitute a complete paper and only the first five as they appear in the answer book are marked. All six are solved below for completeness. Where a doubt exists as to interpretation, the candidate is expected to state assumptions — engineering assumptions used below are flagged in check callouts.

Reference texts: Jane W. S. Liu, Real-Time Systems (Prentice Hall, 2000) — task models, timing requirements, FCFS and EDF scheduling; Giorgio C. Buttazzo, Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications (Springer, 3rd ed.) — preemptive dynamic-priority scheduling and the optimality of EDF; Hermann Kopetz, Real-Time Systems: Design Principles for Distributed Embedded Applications (Springer, 2nd ed.) — distributed real-time control, network-induced delay and time-triggered protocols; Katsuhiko Ogata, Modern Control Engineering (Pearson, 5th ed.) — frequency-domain stability, phase margin and delay margin; Ian Sommerville, Software Engineering (Pearson, 10th ed.) — general software-engineering process context.

Question 3: FCFS vs. EDF Scheduling of Four Real-Time Tasks (20%)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. Four independent, single-instance (aperiodic) tasks, each with an arrival time $a_i$, a computation time $C_i$ and an absolute deadline $D_i$ (all in ms):

TaskArrival $a_i$Computation $C_i$Absolute deadline $D_i$
T10415
T20312
T3259
T4528

Find. (1) The FCFS schedule and timing diagram. (2) Whether FCFS meets every deadline. (3) The EDF schedule and timing diagram, and whether EDF meets every deadline.

Approach. FCFS is non-preemptive: tasks are queued in arrival order (T1 and T2 both arrive at $t=0$; T1 is served first, in the order listed) and each runs to completion once started. EDF is preemptive: at every arrival or completion event, the processor switches to whichever ready task has the earliest absolute deadline.

Part (1) — FCFS schedule. Running each task to completion in arrival order T1→T2→T3→T4:

  1. T1 runs $[0,4)$ — finishes at 4 (deadline 15, met).
  2. T2 runs $[4,7)$ — finishes at 7 (deadline 12, met).
  3. T3 arrived at $t=2$ but the CPU is busy until $t=7$; it runs $[7,12)$ — finishes at 12, but its deadline is 9: $\boxed{\text{T3 misses by 3 ms}}$.
  4. T4 arrived at $t=5$ but the CPU is busy until $t=12$; it runs $[12,14)$ — finishes at 14, but its deadline is 8: $\boxed{\text{T4 misses by 6 ms}}$.
FCFS schedule (non-preemptive, arrival order T1,T2,T3,T4)0123456789101112131415t (ms)T14D=15T23D=12T35D=9T42D=8^ = arrival | (red) = absolute deadline
Figure 2 — FCFS timing diagram. T3 and T4 both finish after their absolute deadlines (red markers).

Part (2) — does FCFS work? No. FCFS runs tasks strictly in arrival order with no regard for urgency, so it lets T1 and T2 — both arriving first but with the loosest deadlines (15 ms, 12 ms) — occupy the CPU while T3 (deadline 9 ms) sits ready and idle from $t=2$ onward, and later T4 (deadline 8 ms, the tightest of all four) waits behind everything. Two of the four tasks, T3 and T4, miss their deadlines. FCFS is deadline-blind and is unsuitable whenever tasks with tight deadlines can arrive after tasks with loose ones.

Part (3) — EDF schedule. At each decision point the scheduler picks the ready task with the smallest absolute deadline, preempting the running task if a more urgent one becomes ready:

  1. $t=0$: ready = {T1 (D=15), T2 (D=12)}. Run T2 (earlier deadline).
  2. $t=2$: T3 arrives (D=9), more urgent than T2's remaining work. Preempt T2 (1 ms done, 2 ms left) and run T3.
  3. $t=5$: T4 arrives (D=8), more urgent than T3 (D=9). Preempt T3 (3 ms done, 2 ms left) and run T4 to completion: finishes at $t=7$ (deadline 8, met).
  4. $t=7$: ready = {T1 (D=15), T2 (D=12, 1 ms left), T3 (D=9, 2 ms left)}. Resume T3, finishes at $t=9$ (deadline 9, met exactly).
  5. $t=9$: ready = {T1 (D=15), T2 (D=12, 1 ms left)}. Resume T2, finishes at $t=10$ (deadline 12, met).
  6. $t=10$: only T1 remains. Run T1 to completion: finishes at $t=14$ (deadline 15, met). $\boxed{\text{All four deadlines met under EDF.}}$
EDF schedule (preemptive, earliest absolute deadline first)0123456789101112131415t (ms)T14D=15T221D=12T332D=9T42D=8^ = arrival | (red) = absolute deadline
Figure 3 — EDF timing diagram. Every task's completion (end of its last segment) falls at or before its red deadline marker.
SchedulerFinish times (T1,T2,T3,T4)Deadlines met?
FCFS (non-preemptive, arrival order)4, 7, 12, 14No — T3 (by 3 ms), T4 (by 6 ms) miss
EDF (preemptive, earliest deadline first)14, 10, 9, 7Yes — all four met