Lec RT Sched Part1 v2 1x2
Lec RT Sched Part1 v2 1x2
(Working Draft)
Insup Lee
Department of Computer and Information Science
School of Engineering and Applied Science
University of Pennsylvania
www.cis.upenn.edu/~lee/
Sensor
Control-Law
Computation
Actuator
Multimedia
OS Scheduler
CPU
Spring ‘10 CIS 541 4
Fundamental Real-Time Issue
Real-Time Spectrum
No RT Soft RT Hard RT
Relative
deadline
Real-Time Task
Task : a sequence of similar jobs
o Periodic task (p,e)
Its jobs repeat regularly
Period p = inter-release time (0 < p)
Execution time e = maximum execution time (0 < e < p)
Utilization U = e/p
0 5 10 15
(4,1)
(5,2)
(7,2)
Real-Time Scheduling
Determines the order of real-time task executions
(4,1)
(5,2)
5 10 15
(7,2)
5 10 15
Spring ‘10 CIS 541 10
Optimality
Scheduling algorithm A is better than B if for every
task set T, B can schedule T implies A can schedule
T.
Real-Time Scheduling
Static scheduling
o A fixed schedule is determined statically
o E.g., Cyclic Executive
Static-priority scheduling
o Assign fixed priorities to processes
o A scheduler only needs to know about priorities
o E.g., Rate Monotonic (RM)
Dynamic-priority scheduling
o Assign priorities based on current state of the system
o E.g., Least Completion Time (LCT), Earliest Deadline First
(EDF), Least Slack Time (LST)
Spring ‘10 CIS 541 12
CYCLIC EXECUTIVE
Cyclic Executives
A cyclic executive is a program that deterministically interleaves the
execution of periodic tasks on a single processor. The order in which
the tasks execute is defined by a cyclic schedule.
Example:
A = (10, 1), B = (10, 3), C = (15, 2), D = (30,8) (30, 3) (30, 5)
A B C D A B C A B D
i i + 10 i +15 i + 20 i +30
frame 1 frame 2 frame 3
A major cycle containing 3 frames
Reference: “The Cyclic executive model and ADA” Proc. of RTSS, 1988,
by Baker and Shaw
t t+m t + 2m t + 3m t + 4m t+M
correct timing enforced at the end of each frame
Rules governing the choice of m for a given {(pi, ei , di )} of n tasks
o m di , i = 1, 2, … , n
o m ei , i = 1, 2, … , n
o M/n = integer (m divides pi for at least one i )
o there must be at least one frame in the interval between the release time and
deadline of every request.
2m - gcd (m, pi) di , for i = 1, 2, … , n
Mode changes
tm E
d
min time between arrival
too pessimistic - guarantees worst case
p = min (tm, d - e +1) -
performance by giving max time to the task
set aside time in minor cycles for execution of sporadic tasks
o does not guarantee worst case
SCHEDULING ANOMALY
T1 T3 T2
0 3 4 8 14
intentional idle time
Spring ‘10 CIS 541 21
T9 : 9 T5 : 4 T6 : 4 T7 : 4 T8 : 4
P1 T1 T9
P2 T2 T4 T5 T7
P3 T3 T6 T8
t
P2
P3
P4
Cases: e2 = 3 and e2 = 5
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 29
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 30
EDF (Earliest Deadline First)
Executes a job with the earliest deadline
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 31
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 32
EDF (Earliest Deadline First)
Optimal scheduling algorithm
o if there is a schedule for a set of real-time tasks,
EDF can schedule it.
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 33
Optimality of EDF
Optimality of the earliest deadline first algorithm for
preemptive scheduling on one processor
Given a task system T, if the EDF algorithm fails to find a
feasible schedule, then T has no feasible schedule, where
o feasible schedule = one in which all release time and
deadline constraints are met
T2’s deadline T1’s deadline
r1 , r2 T1 T2
d2 d1
can always be transform to
r1 , r2 T2 T2 T1
d2 d1
Intuitively:
o The lower the processor utilization, U, the easier it is to
meet deadlines.
o The higher the processor utilization, U, the more difficult it
is to meet deadlines.
Question: is there a threshold Ubound such that
o When U < Ubound deadlines are met
o When U > Ubound deadlines are missed
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 38
EDF - Schedulability Analysis
Real-time system is schedulable under EDF
if and only if dbf(t) ≤ t for all interval t
Baruah et al.
“Algorithms and complexity concerning the
preemptive
scheduling of periodic, real-time tasks on one
processor”, Journal of Real-Time Systems, 1990.
(2, 1)
(5, 3)
(2, 0.8)
(5, 3.5)
T1 T2 T3 T4
0 3 5 6 7
Better schedules :
T1 T3 T1 T4
0 3 5 6 7 0 3 5 6 7
Spring ‘10 CIS 541 41
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 43
RM (Rate Monotonic)
Executes a job with the shortest period
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 44
RM (Rate Monotonic)
Executes a job with the shortest period
Deadline Miss !
T1 (4,1)
T2 (5,2)
5 10 15
T3 (7,2)
5 10 15
Spring ‘10 CIS 541 45
RM – Utilization Bound
Real-time system is schedulable under RM if
∑Ui ≤ n (21/n-1)
RM – Utilization Bound
0.9
0.8
0.7
0.6
0.5
1 4 16 64 256 1024 4096
Response Time
Response time
o Duration from released time to finish time
T1 (4,1)
T2 (5,2)
5 10 15
T3 (10,2)
5 10 15
Spring ‘10 CIS 541 50
Response Time
Response time
o Duration from released time to finish time
Response Time
T1 (4,1)
T2 (5,2)
5 10 15
T3 (10,2)
5 10 15
Spring ‘10 CIS 541 51
Response Time
T1 (4,1)
T2 (5,2)
5 10
T3 (10,2)
5 10
Spring ‘10 CIS 541 52
RM - Schedulability Analysis
Real-time system is schedulable under RM
if and only if ri ≤ pi for all task Ti(pi,ei)
RM vs. EDF
Rate Monotonic
o Simpler implementation, even in systems without explicit
support for timing constraints (periods, deadlines)
o Predictability for the highest priority tasks
EDF
o Full processor utilization
o Misbehavior during overload conditions