Real-Time Scheduling: Edf and RM: Daniel Mosse University of Pittsburgh
Real-Time Scheduling: Edf and RM: Daniel Mosse University of Pittsburgh
EDF and RM
Daniel Mosse
University of Pittsburgh
Aug 2, 2004
Acronyms
Aug 2, 2004
RT Scheduling
What should the system know, in addition to NRT tasks?
Two approaches:
OS supports RT. How can this info be transmitted to the OS?
Support for RT is outside, extra tool; OS supports fixed
priority scheduling. What are the advantages and
disadvantages?
Aug 2, 2004
Aug 2, 2004
State Diagram
create
IO
completed
end
process
completed
Aug 2, 2004
IO
completed
ready
schedule
running
Daniel Mosse ([email protected])
blocked
IO
requested
admission
control
process
submitted
process
started
IO
completed
end
process
completed
process
returns
IO
completed
ready
create
Aug 2, 2004
temporary
suspension
schedule
running
Daniel Mosse ([email protected])
blocked
IO
requested
Types of RT Scheduling
Source: Kopetz
Aug 2, 2004
Priorities as Scheduling
In both dynamic scheduling algorithms that we consider here
(EDF and RM), the priorities of the tasks are a guide for the
scheduler to dispatch the task
In EDF, it is the explicit deadline that functions as the
priority, and therefore the programmer or system
integrator has to know about deadlines
In RM, the period of the task determines the priority, and
therefore the system integrator has to have global
knowledge of all tasks periods (so that s/he can determine
whether a task is higher or lower priority)
In any case, the priorities can be manipulated in an explicit
or implicit manner by the programmer or system integrator
Aug 2, 2004
Aug 2, 2004
Pi
EDF (cont)
Did you notice the characteristic of EDF: the priority of the
tasks is not fixed, relative to each other
Again, compare with daily tasks: which has priority?
For example, let there be 2 tasks ready in the system
Aug 2, 2004
EDF (cont)
The same math for a single task also works for multiple
tasks:
A schedule is feasible iff U < 1, that is, ci/ pi 100%
Aug 2, 2004
Aug 2, 2004
RM admission control
Let us consider the easy and good case for RM: harmonic
periods (that is, all periods are multiples of each other)
In this case, the admission control for RM is the same as it
is for EDF
A schedule is feasible iff U < 1, that is, ci/ pi 100%
Note that the task with the shorter period will also be the
task with the earliest deadline at any given time
Aug 2, 2004
RM (cont)
Which scheduling policy is more efficient? Can RM be any
more efficient than EDF? Can RM be any more efficient than
EDF?
Depends on how one looks at efficiency, which can be
defined as less dispatching (context switching) overhead,
can be defined as higher resource utilization without
considering overhead, or a combination thereof
In general, RM may allow for less CPU to be used. Example:
Wasted CPU
Aug 2, 2004
RM (cont)
So, in general, the CPU cannot be fully utilized when tasks
are scheduled following RM, and the admission control has to
reflect this issue.
This is because RM is for fixed-priority tasks (tasks
priorities do not change in time, theyre always the same, and
therefore their relative priority is also the same)
Liu and Layland devised a test to check whether task sets
could be scheduled:
If ci/ pi n ( 21/n 1), then all n tasks will meet their
deadlines
Aug 2, 2004
Implementing RM in hardware
Good for control systems, in which sensors are separate
devices: temperature, pressure, RPM, acceleration, smell,
etc
Devices also must be able to send signals to the CPU to
activate the tasks on a periodic basis
Associate each device to an interrupt priority, according to
the inverse of the period
Tasks are handled by a PIC (programmable interrupt
controller) which activates interrupt service routines (ISRs)
The tasks must be cooperative, since they will execute on
the same stack (like threads, but not really threads)
Advantages: Low context switch overhead, no scheduling
overhead, low memory allocation overhead, highly
collaborative
Aug 2, 2004
Aug 2, 2004
Aug 2, 2004
R2 = P2 / P1 C1 + C2.
Is this correct? Why or why not?
What is/are the condition/s we have to check?
How many periods do we have to check this condition?
May also be called fixed point computation, since all this is
done when response time does not increase anymore
Aug 2, 2004
Aug 2, 2004
Aug 2, 2004
R1 = C1 = 1 but R2?
R02 = 2+1= 3, at least; that is larger than P1
R12 = ceil(3/2) 2 = 2 * 2 = 4
R22 = ceil(4/2) 2 = 2 * 2 = 4
Since R12 = R22 the task is accepted. on to the next task
priority
Aug 2, 2004
Resource Sharing
When resources are shared (resources can be anything
threads use, such as memory locations, variables, devices,
etc), there has to be a synchronization mechanism
Usually, semaphores and/or lock variables are used (rarely
monitors are used: do not pause this program for a special
monitors insert in the last slide)
Semaphores may cause priority inversion: a high priority
task is blocked by a low priority task (same with nonpreemptive scheduling)
Aug 2, 2004
Priority Inversion
High pr task misses
its deadline
blocks on mutex
becomes active
other tasks
Source: Bettati
10
ek
+ = F X (i )
pi
k =1 p k
i
Aug 2, 2004
Source: Bettati
Priority Inheritance
Jobs that are not blocked are scheduled according
to the scheduling algorithm
Priority Inheritance:
Basic strategy for controlling priority inversion:
Let be the priority of J
and be the priority of J
and <
then the priority of J is set to whenever J is blocked by J
Priority Inheritance is transitive
Aug 2, 2004
T1
T2
T3
T3 blocks T1 here
T3s prio=T1s prio
Aug 2, 2004
T3 blocks T2 here
Aug 2, 2004
Source: Tindell00
Priority Ceiling?
The Priority Ceiling Protocol solves the deadlock problem by
raising the priority of the task to the highest priority of all
the tasks that may lock the resource in question
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
When a task blocks other tasks (directly or indirectly), it
inherits the highest of their priorities
Aug 2, 2004
Aug 2, 2004
Source: Tindell00
Aug 2, 2004
Overheads
Up to now, we have an ideal
system, with the instantaneous preemption, context
switch, scheduling, etc
How can one incorporate these overheads in the feasibility
tests? How much will they influence the issue?
Its not free, but as CPUs gets faster it gets cheaper compared
to real time
In RM, the tasks with higher priority will always run, and the
tasks with lower priority will suffer
Not fair, since offending task may be high-priority task
Predictable: high-priority tasks are more important (are they?)
Aug 2, 2004
A
D
B
E
F
Aug 2, 2004
Aug 2, 2004
Summary
Dynamic Scheduling is a Good Thing, when your system is
somewhat predictable (periodic)
Allows for flexibility, but designers have to beware of
Priority Inversion
Deadlocks
Overhead
Aug 2, 2004