RMS and EDF Scheduling
1
Priority-driven Preemptive Scheduling
Assumptions & Definitions
• Tasks are periodic
• No aperiodic or sporadic tasks
• Job (instance) deadline = end of period
• No resource constraints
• Tasks are preemptable
• Laxity (Slack) of a Task
• Ti = d i
– (t + c i
’) where di: deadline; t
C’ i t : current time; c i
’ : remaining computation time.
d i
Laxity
2
Rate Monotonic Scheduling (RMS)
• Schedulability check (off-line)
- A set of n tasks is schedulable on a uniprocessor by the RMS algorithm if the processor utilization
(utilization test) c i is the execution time and p i is the period,
The term n(2 1/n -1) approaches ln 2 , (
0.69 as n
).
- This condition is sufficient, but not necessary.
3
RMS (cont.)
• Schedule construction (online)
- Task with the smallest period is assigned the highest priority (static priority).
- At any time, the highest priority task is executed.
4
RMS Scheduler Example 1
Task set: T i
= (c i
, p i
) [computation time, period]
T1 = (2,4) and T2 = (1,8)
Active
Tasks :
{T1, T2}
Schedulability check:
2/4 + 1/8 = 0.5 + 0.125 = 0.625 ≤ 2(√2 -1) = 0. 82
Active
Tasks :
{T2}
Active
Tasks :
{T1}
0
T
1
1
2
T
2
1
3 4
T
1
2
6 8
5
RMS scheduler – Example 2
Active
Tasks :
{T1, T2}
Task set: T i
= (c i
, p i
)
T1 = (2,4) and T2 = ( 4 ,8)
Schedulability check:
2/4 + 4 /8 = 0.5 + 0.5 = 1.0 > 2(√2 -1) = 0. 82
Active
Tasks :
{T2}
Active
Tasks :
{T2, T1}
Active
Tasks :
{T2}
0
T
1
1
2
T
2
1
3 4
T
1
2
6
T
2
1
8
Some task sets that FAIL the utilization-based schedulability test are also schedulable under RMS
6
• T
1
=(1,2) and T
2
=(2.5,5)
7
• Schedulability check (off-line)
A set of n tasks is schedulable on a uniprocessor by the EDF algorithm if the processor utilization.
• This condition is both necessary and sufficient.
Least Laxity First (LLF) algorithm has the same schedulability check.
8
EDF/LLF (cont.)
• Schedule construction (online)
– EDF/LLF: Task with the smallest deadline/laxity is assigned the highest priority (dynamic priority).
– At any time, the highest priority task is executed.
• It is optimal (i.e., whenever there is a feasible schedule, EDF can always compute it) when preemption is allowed and no resource constraint is considered.
– Given any two tasks in a feasible schedule, if they are not scheduled in the order of earliest deadline, you can always swap them and still generate a feasible schedule.
9
EDF scheduler - Example
Task set: T i
= (c i
, p i
, d i
)
T1 = (1,3,3) and T2 = (4,6,6)
Active
Tasks :
{T1, T2}
Schedulability check:
1/3 + 4/6 = 0.33 + 0.67 = 1.0
Active
Tasks :
{T2}
Active
Tasks :
{T2, T1}
Active
Tasks :
{T1}
0
T
1
1
1
T
2
1
3
T
2
1
5
T
1
2
6
Unlike RMS, Only those task sets which pass the schedulability test are schedulable under EDF
10
T
1
0
T
2
0
Process Period, T WCET, C
T
T
2
1
5
7
2
4
EDF schedule
T
1
0 5
T
2
0
RMS schedule
7
10
14
15 20
21
25
28
30
5
7
10
Deadline miss
15
14
20
21
25
28
30
35
11
35
35
35
Resource sharing
• Periodic tasks
• Task can have resource access
• Semaphore is used for mutual exclusion
• RMS scheduling
12
Background – Task State diagram
• Ready State: waiting in ready queue
• Running State: CPU executing the task
• Blocked: waiting in the semaphore queue until the shared resource is free
• Semaphore types – mutex (binary semaphore), counting semaphore
13
Task State Diagram scheduling
Activate
READY RUN
Termination
Preemption
Signal free resource
WAITING
Process/Task state diagram with resource constraints
Wait on busy resource
14
Priority inversion is an undesirable situation in which a higher priority task gets blocked (waits for CPU) for more time than that it is supposed to, by lower priority tasks.
Example:
• Let T
1
, T
2
, and T
3 be the three periodic tasks with decreasing order of priorities.
• Let T
1 and T
3 share a resource S.
15
Priority Inversion - Example
• T3 obtains a lock on the semaphore S and enters its critical section to use a shared resource.
• T1 becomes ready to run and preempts T3. Then, T1 tries to enter its critical section by first trying to lock S .
But, S is already locked by T3 and hence T1 is blocked.
• T2 becomes ready to run. Since only T2 and T3 are ready to run, T2 preempts T3 while T3 is in its critical section.
Ideally, one would prefer that the highest priority task
(T1) be blocked no longer than the time for T3 to complete its critical section. However, the duration of blocking is, in fact, unpredictable because task T2 got executed in between.
16
Priority Inversion example request for resource S and gets blocked
T1
Highest priority
T
1
Resource S is available and T1 is scheduled lower priority task
T
1 here
T2 completes
T2
Medium priority
T3 is the only active task
K1
T
3 Least priority
0
T1 and T3 share resource
S
Preempted by higher priority task T1
K2
T
3
L1
T
2
T3 completes
Preempted by higher priority task T2
Total blocking time for task T1 = (K2+K3) + (L1)
T
3
17
Priority inheritance protocol solves the problem of priority inversion.
Under this protocol, if a higher priority task T is blocked by a lower priority task
T
L needed by T
H priority of T
H
.
, T
L
T
L temporarily inherits the
H
, because is currently executing critical section
When blocking ceases (i.e., T
L section), T
L exits the critical resumes its original priority.
Unfortunately, priority inheritance may lead to deadlock.
18
Resource access control - example
Task Ti c i p i c i x c i y
T1
T2
T3
2
4
2
8 2
12 0
6 1
0
4
1 c i z
0
0
0
T2 and T3 have access to a shared resource R c i x : Task duration before entering the critical section c i y c i z
: Critical section duration
: Task duration after the critical section ci = c i x + c i y + c i z
By RMS, T3 > T1 > T2
19
Schedules
RMS Schedule
Locks R
Preempted by T3 Release R
0
Task Ti c i
T3 p i
T1
2 c i x c i y
4 c i z
T2 T3 T2
6 7 8
T1
10
T2 T3
11 12
Priority inversion of T3 by T1
T3
14
T2
16
T1
T2
T3
2 8 2 0
4 12 0 4
2 6 1 1
0
0
0
RMS Schedule with Priority Inheritance Protocol
Direct blocking of T3 by T2
0
T3 T1 T2 T3 T2 T3 T1 T3 T2
Inheritance blocking of T1 by T2
20
Priority Inheritance Protocol – Deadlock
Assume T2 has higher priority than T1
21
• Priority ceiling protocol solves the priority inversion problem without getting into deadlock.
• For each semaphore, a priority ceiling is defined, whose value is the highest priority of all the tasks that may lock it.
• When a task T i attempts to execute one of its critical sections, it will be suspended unless its priority is higher than the priority ceiling of all semaphores currently locked by tasks other than T i
.
• If task T i is unable to enter its critical section for this reason, the task that holds the lock on the semaphore with the highest priority ceiling is said to be blocking T i and hence inherits the priority of T i
.
22
Priority Ceiling Protocol - properties
• This protocol is the same as the priority inheritance protocol, except that a task T i can also be blocked from entering a critical section if any other task is currently holding a semaphore whose priority ceiling is greater than or equal to the priority of task T i
.
23
• For the previous example, the priority ceiling for both CS
1 and CS
2 is the priority of T
2
.
• From time t
0 as before. to t
2
, the operations are the same
• At time t
3
, T
2
T
1
T
2
. attempts to lock CS
1 blocked since CS
2
, but is
(which has been locked by
) has a priority ceiling equal to the priority of
• Thus T
1 inherits the priority of T
2 and proceeds to completion, thereby preventing deadlock situation.
24
Scheduling tasks with precedence relations
Conventional task set
{T1, T2} Scheduler
T1 T2
Modify task parameters in order to respect precedence constraints task set with precedence constraints
Scheduler
25
Modifying the task parameters for RMS
• While using the RMS scheduler the task parameters (ready time) need to be modified in order to respect the precedence constraints
Ti Tj
• R j*
≥ Max (R j
, R i*
) where R i* is the modified ready time of the task T i
• Priority Prio i
≥ Prio j
26
Modifying ready times for RMS: example
T3
2
T1
1
T5
3
T4
1
T2
2
Initial Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
0
2
2
7
5
T4
T5
0
0
1
3
10
12
27
Modifying the Ready times for RMS
R3’ = max(R1, R3)
T3
2
R1 = 0
T1
1
T5
3
R5’ = max(R3’, R4’,R5)
T4
1
T2
2
R2 = 5
R4’ = max(R1, R2,R4)
Initial Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
0
2
2
7
5
T4
T5
0
0
1
3
10
12
28
Modified Ready times for RMS
R1 = 0
T1
1
T3
2
R3’ = 0
T5
3
T4
1
R5’ = 5
T2
2
R2 = 5
R4’ = 5
Modified Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
0
2
2
7
5
T4
T5
5
5
1
3
10
12
29
Assigning task priorities for RMS
R1 = 0
T1
1
T3
2
R3’ = 0
T5
3
T4
1
R5’ = 5
T2
2
R2 = 5
Assume all tasks of a connected component have the same period.
Therefore, as per RMS all tasks will have a tie.
We assign priorities to break the ties.
R4’ = 5
Task
Modified Task Parameters
R i
C i
D i
Priority
T1 0 1 5 3
T2 5
T3 0
2
2
7
5
4
2
T4 5
T5 5
1
3
10
12
1
0
30
Modifying task parameters for EDF
• While using the EDF scheduler the task parameters need to be modified in order to respect the precedence constraints
Ti Tj
• R j*
• D i*
≥ Max (R j
, (R i*
≥ Min (D i
, (D j*
+ C i
))
– C j
))
31
Modifying the Ready times for EDF
R1 = 0
T1
1
R3’ = max(R1 + C1, R3)
T3
2
T5
3
R5’ = max(R3’+C3,
R4’+C4,R5)
T4
1
T2
2
R2 = 5
R4’ = max(R1+C1, R2+C2,R4)
Initial Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
0
2
2
7
5
T4
T5
0
0
1
3
10
12
32
Modifying the Ready times for EDF
R1 = 0
T1
1
T3
2
R3’ = 1
T5
3
T4
1
R5’ = 8
T2
2
R2 = 5
R4’ = 7
Modified Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
1
2
2
7
5
T4
T5
7
8
1
3
10
12
33
Modifying the Deadlines for EDF
D2’ = Min( (D4’ – C4), (D3’ – C3), D1)
D1 = 5
T1
D1’ = 3
1
T2
2
D2’ = Min( (D4’ – C4), D2)
T3
2
T5
3
T4
1
D5 = 12
Modified Task Parameters
Task R i
C i
D i
T1 0 1 5
T2
T3
5
1
2
2
7
5
T4
T5
7
8
1
3
10
12
D3’ = Min( (D5 – C5), D3)D4’ = Min( (D5 – C5), D4)
34
Modifying the Deadlines for EDF
T3
2
T1
D1’ = 3
1
D3’ = 5
T5
3
T4
1
D5 = 12
T2
2
D2’ = 7
D4’ = 9
Modified Task Parameters
Task R i
C i
D i
T1 0 1 3
T2
T3
5
1
2
2
7
5
T4
T5
7
8
1
3
9
12
35