EE5900 Advanced Embedded System For Smart Infrastructure: RMS and EDF Scheduling
EE5900 Advanced Embedded System For Smart Infrastructure: 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
C’i
• Laxity (Slack) of a Task
t di
• Ti = di – (t + ci’)
where di: deadline; Laxity
t : current time;
ci’ : remaining computation time.
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)
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: Ti = (ci, pi) [computation time, period]
T1 = (2,4) and T2 = (1,8)
Schedulability check:
2/4 + 1/8 = 0.5 + 0.125 = 0.625 ≤ 2(√2 -1) = 0. 82
Active Active
Active Tasks : Tasks :
Tasks : {T2} {T1}
{T1, T2}
0 2 3 4 6 8
5
RMS scheduler – Example 2
Task set: Ti = (ci, pi)
T1 = (2,4) and T2 = (4,8)
Schedulability check:
2/4 + 4/8 = 0.5 + 0.5 = 1.0 > 2(√2 -1) = 0. 82
0 2 3 4 6 8
Some task sets that FAIL the utilization-based schedulability test are also
schedulable under RMS
6
RMS is not optimal
• T1=(1,2) and T2=(2.5,5)
7
Earliest Deadline First (EDF)
• Schedulability check (off-line)
- A set of n tasks is schedulable on a
uniprocessor by the EDF algorithm if the
processor utilization.
9
EDF scheduler - Example
Task set: Ti = (ci, pi, di)
T1 = (1,3,3) and T2 = (4,6,6)
Schedulability check:
1/3 + 4/6 = 0.33 + 0.67 = 1.0
0 1 3 5 6
Unlike RMS, Only those task sets which pass the schedulability test are
schedulable under EDF
10
Comparison of RMS and EDF
Process Period, T WCET, C
T1 5 2
EDF schedule T2 7 4
T1
0 5 10 15 20 25 30 35
T2
0 7 14 21 28 35
RMS schedule
T1
0 5 10 15 20 25 30 35
Deadline miss
T2
0 7 14 21 28 35
11
Resource sharing
• Periodic tasks
• Task can have resource access
• Semaphore is used for mutual exclusion
• RMS scheduling
12
Background – Task State diagram
13
Task State Diagram
scheduling
Activate Termination
READY RUN
Preemption
Signal Wait on
free busy
resource resource
WAITING
14
Priority Inversion Problem
Example:
• Let T1 , T2 , and T3 be the three periodic tasks
with decreasing order of priorities.
• Let T1 and T3 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.
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
Makes a
request for
A higherResource S is
available and T1
priority task
resource S and waits for ais scheduled
gets blocked lower priority here
T1 task
Highest T1 T1
priority
T2 completes
L1
Preempted by
higher priority T3 completes
T2 T3 is the T2
task T1
Medium only
priority active Preempted by
task higher K3
priority
K1 K2 task T2
T3 T3 T3 T3
Least
priority 0
T1 and T3
share
resource Total blocking time for task T1 = (K2+K3) + (L1)
S
17
Priority Inheritance Protocol
Priority inheritance protocol solves the
problem of priority inversion.
T1 2 8 2 0 0
T2 4 12 0 4 0
T3 2 6 1 1 0
19
Schedules
Locks R
RMS Schedule Direct blocking of T3 by T2
Preempted by T3 Release R
T3 T1 T2 T3 T2 T1 T2 T3 T3 T2
0 2 4 6 7 8 10 11 12 14 16
T1 2 8 2 0 0
T2 4 12 0 4 0 RMS Schedule with Priority Inheritance Protocol
T3 2 6 1 1 0 Direct blocking of T3 by T2
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
• 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 Ti 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 Ti.
• If task Ti 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 Ti and hence inherits the priority of Ti.
22
Priority Ceiling Protocol - properties
23
Priority Celiling Protocol - Example
• For the previous example, the priority ceiling for
both CS1 and CS2 is the priority of T2.
24
Scheduling tasks with precedence relations
Conventional task
set
{T1, T2} 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
26
Modifying ready times for RMS: example
T1 T2
1 2
27
Modifying the Ready times for RMS
R1 = 0 R2 = 5
T1 T2
1 2
R4’ = max(R1, R2,R4)
28
Modified Ready times for RMS
R1 = 0 R2 = 5
T1 T2
1 2
29
Assigning task priorities for RMS
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
31
Modifying the Ready times for EDF
R1 = 0 R2 = 5
T1 T2
R4’ = max(R1+C1, R2+C2,R4)
1 2
R3’ = max(R1 + C1, R3)
Initial Task Parameters
R3 = 0
R3’ = 1 R4 = 0
Task Ri Ci Di
T3 T4 R4’ = 7
2 1 T1 0 1 5
T2 5 2 7
T3 0 2 5
T5 R5 = 0 T4 0 1 10
R5’ = 8
3
T5 0 3 12
R5’ = max(R3’+C3,
R4’+C4,R5)
32
Modifying the Ready times for EDF
R1 = 0 R2 = 5
T1 T2
1 2
33
Modifying the Deadlines for EDF
D2’ = Min( (D4’ – C4), (D3’ – C3), D1)
D1 = 5 D2 = 7
D1’ = 3 D2’ = 7
T1 T2 D2’ = Min( (D4’ – C4), D2)
1 2
D3’ = Min( (D5 – C5), D3) D4’ = Min( (D5 – C5), D4)
34
Modifying the Deadlines for EDF
D1’ = 3 D2’ = 7
T1 T2
1 2
35