Deadline First Algorithm - Dereje
Deadline First Algorithm - Dereje
Observe that at time 6, even if the deadline of task 3 is very close, the scheduler
decides to schedule task 2 . This is the main reason why 3 misses its deadline!
10
12
14
16
18
20
22
24
Again, the utilization is very high. However, no deadline miss in the hyperperiod.
1
Observe that at time 6, the problem does not appear, as the earliest deadline job
(the one of 3 ) is executed.
10
12
14
16
18
20
22
24
Given a task set of periodic or sporadic tasks, with relative deadlines equal to periods, the task set is schedulable by EDF if and only if
Theorem
N
U=
i=1
Ci 1 Ti
EDF is an optimal algorithm, in the sense that if a task set if schedulable, then it is schedulable by EDF. In fact, if U > 1 no algorithm can succesfully schedule the task set; if U 1, then the task set is schedulable by EDF (and maybe by other algorithms).
Corollary
In particular, EDF can schedule all task sets that can be scheduled by FP, but
not vice versa.
In general, EDF has less context switches In the previous example, you can try to count the number of context switches
in the rst interval of time: in particular, at time 4 there is no context switch in EDF, while there is one in FP.
Optimality of EDF We can fully utilize the processor, less idle times.
Less controllable if we want to reduce the response time of a task, in FP is only sufcient to
give him an higher priority; in EDF we cannot do anything; We have less control over the execution
More implementation overhead FP can be implemented with a very low overhead even on very small
hardware platforms (for example, by using only interrupts); EDF instead requires more overhead to be implemented (we have to keep track of the absolute deadline in a long data structure); There are method to implement the queueing operations in FP in O(1); in EDF, the queueing operations take O(log N), where N is the number of tasks.
Domino effect
In case of overhead (U > 1), we can have the domino effect with EDF: it means
that all tasks miss their deadlines.
10
12
14
16
18
20
22
24
As you can see, while 1 and 2 never miss their deadlines, 3 misses a lot of
deadline, and 4 does not execute!
10
12
14
16
18
20
22
24
However, it may happen that some task never executes in case of high overload,
while EDF is more fair (all tasks are treated in the same way).
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 9/38
periods.
However, the schedulability analysis formula become more
complex.
If all relative deadlines are less than or equal to the periods, a rst
U =
i=1
Ci 1 Di
time Di instead of Ti , we are increasing the utilization, U < U . If it is still less than 1, then the task set is schedulable. If it is larger than 1, then the task set may or may not be schedulable.
Lets start from the concept of demand function Denition: the demand function for a task i is a function of an interval [t1 , t2 ] that
gives the amount of computation time that must be completed in [t1 , t2 ] for i to be schedulable: cij dfi (t1 , t2 ) = aij t1 dij t2
df (t1 , t2 ) =
i=0
dfi (t1 , t2 )
10 12 14 16 18 20 22 24 26 28 30 32
10 12 14 16 18 20 22 24 26 28 30 32
10 12 14 16 18 20 22 24 26 28 30 32
10 12 14 16 18 20 22 24 26 28 30 32
Lets compute df () in certain intervals; df (7, 22) = 2 C1 + 2 C2 + 1 C3 = 9; df (3, 13) = 1 C1 = 1; df (10, 25) = 2 C1 + 1 C2 + 2 C3 = 7;
t1 , t2 > t1
df (t1 , t2 ) t2 t1
In the previous example: df (7, 22) = 9 < 15 OK; df (3, 13) = 1 < 9 OK; df (10, 25) = 7 < 15 OK; ... We should check for an innite number of intervals! We need a a way to simplify the previous condition.
offset),
t1 , t2 > t1 df (t1 , t2 ) df (0, t2 t1 )
In plain words, the worst case demand is found for intervals starting at 0. Denition: Demand Bound function:
dbf (L) L
U max(Ti Di ) L = 1U
Lets compute dbf () df (0, 4) = C1 = 1 < 4; df (0, 5) = C1 + C3 = 4 < 5; df (0, 6) = C1 + C2 + C3 = 6 6; df (0, 10) = 2C1 + C2 + C3 = 7 10;
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 17/38
Algorithm
Of course, it should not be necessary to draw the schedule to see if the system
is schedulable or not.
dbf (L) =
i=1
L Di Ti
+ 1 Ci
The algorithm works as follows: We list all deadlines of all tasks until L . Then, we compute the dbf for each deadline and verify the condition.
4 6 5
10
L dbf
4 1
5 4
6 6
10 7
Since, for all L < L we have dbf (L) L, then the task set is schedulable.
Another example
Ci 1 2 4.5 Di 2 4 8 Ti 4 5 15
1 2 3
U = 0.9; L = 9 7 = 63;
hint: if L is too large, we can stop at the rst idle time. The rst idle time can be found with the following recursive
equations:
N
W (0) =
i=1 N
Ci
W (k ) =
i=1
W (k 1) Ci Ti
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 20/38
Example
1 2 3
2 4 8
6 9
10 14
14
t dbf
2 1
4 3
6 4
8 8.5
10
14
In the schedule...
1 2 3
10
12
Synchronization protocols
Both the Priority inheritance Protocol and thr Stack Resource
Preemption levels
To compute the blocking time, we must rst order the tasks based
Preemption levels
With a graphical example:
1 2 0 2 4 6 8 10 12
Preemption levels
With a graphical example:
1 2 0 2 4 6 8 10 12
Notice that 1 > 2 ; 2 cannot preempt 1 (because its relative deadline is greater than
1 ).
algorithms as for FP + PI. In particular, the two fundamental theorems are still valid:
Each task can be blocked only once per each resource, and only for the
length of one critical section per each task.
table
At each row put a task, ordered by decreasing preemption levels At each column, put a resource In each cell, put the worst case duration ij of any critical section of task i
on resource Sj
The algorithm for the blocking time for task i is the same: Select the rows below the i-th; we must consider only those column on which it can be blocked (used by
itself or by higher priority tasks) Select the maximum sum of the k,j with the limitation of at most one k,j for each k and for each j .
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 27/38
Schedulability formula
In case of relative deadlines equal to periods, we have:
i
i = 1, . . . , N
j =1
Cj Bi + 1 Tj Ti
i = 1, . . . , N
N j =1
L < L
L Dj Tj L =
+ 1 Cj + Bi L U max(Ti Di ) 1U i
Complete example
Here we analyze a complete example, from the parameters of the tasks, and from the resource usage table, we compute the Bi s, and test schedulability.
1 2 3 4 Ci 2 5 4 9 Ti 10 15 20 45 Ui .2 .33 .2 .2 R1 1 2 0 3 R2 0 1 2 4 Bi ? ? ? ?
1 2 3 4
Ci 2 5 4 9
Ti 10 15 20 45
Ui .2 .33 .2 .2
R1 1 2 0 3
R2 0 1 2 4
Bi 3 ? ? ?
1 2 3 4
Ci 2 5 4 9
Ti 10 15 20 45
Ui .2 .33 .2 .2
R1 1 2 0 3
R2 0 1 2 4
Bi 3 5 ? ?
1 2 3 4
Ci 2 5 4 9
Ti 10 15 20 45
Ui .2 .33 .2 .2
R1 1 2 0 3
R2 0 1 2 4
Bi 3 5 4 ?
1 2 3 4
Ci 2 5 4 9
Ti 10 15 20 45
Ui .2 .33 .2 .2
R1 1 2 0 3
R2 0 1 2 4
Bi 3 5 6 0
i = 1, . . . , 4
j =1
Cj Bi + 1 Tj Ti
Task 1 :
C1 B1 + = .2 + .3 = .5 1 T1 T1
i = 1, . . . , 4
j =1
Cj Bi + 1 Tj Ti
Task 2 :
i = 1, . . . , 4
j =1
Cj Bi + 1 Tj Ti
Task 3 :
C1 C2 C3 B3 + + + = .2 + .333 + .2 + .2 = 0.9333 1 T1 T2 T3 T3
i = 1, . . . , 4
j =1
Cj Bi + 1 Tj Ti
Task 4 :
C1 C2 C3 C4 B4 + + + + = .2 + .3333 + .2 + .2 + 0 = .9333 1 T1 T2 T3 T4 T4
1 2 3 4
L(S1 ) U(S1 ) S1 L(S1 ) S1 L(S2 ) S2 L(S1 ) S1 0 2 4 6 U(S1 ) L(S2 ) S2 8 10 12 14 16 U(S2 ) U(S1 ) L(S2 ) U(S2 ) S2 U(S2 )
L1
U1 S1
L1 U1 S1
L1 U1 S1
L1 S1
U1 L2 S2
L1 S1
U1 L2
U2 S2
L2
U2 S2
L2 S2
U2
L1 S1
U1
L2 S2
U2
10
12
14
16
18
20
22
24
26
28
30
32
34
In the graph, L1 = Lock(S1 ), U1 = Unlock(S1 ), L2 = Lock(S2 ), U2 = Unlock(S2 ). The tasks start with an offset, because in the example we want to highlight the
blocking times at the beginning.
Complete Example
Now we analyze the previous example, assuming EDF+SRP.
1 2 3 4 Ci 2 5 4 9 Ti 10 15 20 45 Ui .2 .33 .2 .2 R1 1 2 0 3 R2 0 1 2 4 Bi ? ? ? ?
Let us rst assign the preemption levels. The actual value of the preemption levels is not important, as long as they
are assigned in the right order. To make calcumations easy, we set 1 = 4, 2 = 3, 3 = 2 , 4 = 1.
Schedule
L1
10
12
14
16
18
20
22
24
26
28
30
32
34
Schedule
L1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
Schedule
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
Schedule
L1
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Schedule
L1 S1
U1
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Schedule
L1 U1 S1
L1 S1
U1
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Schedule
L1 U1 S1
L1 U1 S1
L1 S1
U1
L2 U2 S2
U L2 S2
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Schedule
L1 U1 S1
L1 U1 S1
L1 S1
U1
L2 U2 S2
U L2 S2
L1 S1
U1
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Schedule
L1 U1 S1
L1 U1 S1
L1 U1 S1
L1 S1
U1
L2 U2 S2
L1 S1
U1 L2 U2 S2
U L2 S2
L2 S2
U1
L1 S1
U1
L2
U2
10
12
14
16
18
20
22
24
26
28
30
32
34
At this point, the system ceiling is raised to 1 (the ceiling of R1 ). Task 3 cannot
start executing, because 3 < 1 . Same for 2 .
The system ceiling goes back to 0. Now 2 can start. in this example, we assume that 2 locks R1 just before 1 arrives. Then, sys ceil
= 1 and 1 cannot preempt.
edf.tex Sistemi in tempo reale Giuseppe Lipari 19/6/2005 20:03 p. 36/38
Complete example
Same example of before, but with SRP instead of PI.