Professional Documents
Culture Documents
Class 5 RTOS-Real Time Systems-August 2021
Class 5 RTOS-Real Time Systems-August 2021
Tech, PhD
Guest Faculty - WILP
BITS Pilani Real Time Operating Systems
Pilani Campus
Real - Time Operating Systems
Scheduling Aperiodic
and Sporadic Jobs
in Priority-Driven Systems
2
Agenda
• Notations and Assumptions
• System Model
• Scheduling Algorithms
• Definitions: Correctness
• Optimality of Algorithms
• Algorithms for Scheduling Aperiodic Jobs
1. Bandwidth-preserving algorithms
2. Slack-stealing algorithms.
3
Agenda
Simple approaches
– Background Scheduling
– Interrupt-Driven Scheduling
– Slack Stealing
– Polled Execution
Bandwidth-preserving servers
Deferrable server, Sporadic servers, Constant
utilization servers
Total bandwidth servers, Weighted fair queuing
servers
4
Agenda
Algorithms for Scheduling Sporadic Jobs
1. Acceptance Tests for Deadline-Driven Systems
2. Acceptance Tests for Fixed-Priority Systems
Sporadic Server
Fixed-Priority Sporadic Server
Sporadic Dynamic-Priority Servers
Summary
5
Notations and Assumptions
• Single processor system; independent
preemptable periodic tasks scheduling
using a priority-driven algorithm
• Parameters of all periodic tasks are known
• In the absence of aperiodic and sporadic jobs,
periodic tasks meet deadlines
• Aperiodic and sporadic jobs are
independent of each other
• Parameters of sporadic jobs become
known
6
after release
Assumption
The operating system maintains three
priority queues:
– Periodic jobs,
– Aperiodic jobs,
– Sporadic jobs, preceded by an acceptance test.
7
System Model
8
Scheduling Algorithms
• Aperiodic jobs
- are always accepted
–Aim to complete each aperiodic job as soon as
possible, without causing periodic tasks or
accepted sporadic jobs to miss deadlines
9
Scheduling Algorithms
Sporadic jobs
– Scheduler decides, if job can be accepted or
must be rejected
– Accepting the job implies that the job will
complete within its deadline, without causing
any periodic task or previously accepted
sporadic job to miss its deadline
– Do not accept a sporadic job if cannot
guarantee it will meet its deadline
10
Definitions: Correctness
A scheduling algorithm supporting
aperiodic or sporadic jobs is a correct
algorithm if it only produces correct
schedules for the system
A correct schedule is one where all
periodic tasks, and any sporadic tasks that
have been accepted, meet their deadlines
11
Optimality of Algorithms
An aperiodic job scheduling algorithm is
optimal if it minimizes either:
– The response time of the aperiodic job at the
head
of the aperiodic job queue
– The average response time of all the aperiodic
jobs for the given queuing discipline
12
Optimality of Algorithms
A sporadic job scheduling algorithm is optimal
if it accepts a new sporadic job, and schedules
that job to complete by its deadline, if and only
if the new job can be correctly scheduled to
complete in time
– An optimal algorithm always produces a feasible
schedule job accepted
– Note: this is different from the definition of optimal
on-line algorithms discussed previously, as that
definition required that all offered jobs had to be
accepted and completed in time
13
Scheduling Aperiodic Jobs
Consider the simple case: scheduling
aperiodic jobs along with a system of
periodic jobs
– Ignore sporadic jobs for now
• Two simple approaches:
– Execute the aperiodic jobs in the background
– Execute the aperiodic jobs by interrupting the
periodic jobs
14
Background Scheduling of Aperiodic Jobs
Aperiodic jobs are only scheduled and executed at times,
when there is no periodic or sporadic job ready for
execution
Advantages
– Clearly produces correct schedules
– Extremely simple to implement
• Disadvantages
– Not optimal since it is almost guaranteed to delay
execution of aperiodic jobs in favour of periodic and
sporadic jobs, giving unduly long response times for the
aperiodic jobs
15
Background Execution
16
Interrupt Scheduling of
Aperiodic Jobs
How can we improve the response time for
aperiodic jobs?
Whenever an aperiodic job arrives, the
execution of periodic tasks is interrupted, and
the aperiodic job is executed.
– Reduces response times of aperiodic jobs
– But likely not correct, and will often cause
periodic /sporadic tasks in the system to miss some
deadlines
17
Slack Stealing for Aperiodic Jobs
Neither background or interrupt driven execution ideal
A better alternative is slack stealing
– Periodic jobs are be scheduled to complete before their
deadline; there may be some slack time between
completion of the periodic job and its deadline
– Since we know the execution time of periodic jobs, can
move the slack time earlier in the schedule, running
periodic jobs ‘just in time’ to meet their deadlines
– Execute aperiodic jobs in the slack time, ahead of
periodic jobs
• Reduces response time for aperiodic jobs and is correct,
but more complex and difficult
18
Polled Execution for Aperiodic Jobs
Another common way to schedule aperiodic jobs is using a polling
server
– A periodic job (ps, es) scheduled according to the periodic
algorithm,generally as the highest priority job
– When executed, it examines the aperiodic job queue
• If an aperiodic job is in the queue, it is executed for up to es
time units
• If the aperiodic queue is empty, the polling server self-
suspends, giving up its execution slot
• The server does not wake-up once it has self-suspended,
aperiodic jobs which become active during a period are not
considered for execution until the next period begins
19
Background Execution
Advantage: simple algorithm
Disadvantage: aperiodic jobs are often
executed very late
Possible improvement: slack stealing (as
shown in chapter 5 for clock-driven
systems)
slack stealing can greatly improve the
performance, but is much more complex in
priority-driven systems
20
Periodic Server
A task that behaves more or less like a
periodic task and is created to execute
aperiodic jobs is called a periodic server
– A periodic server is defined partially by
execution time eS and period pS
The parameter eS is the execution budget
of the server
The ratio uS = eS / pS is the size of the
server
21
Periodic Server
When the server is scheduled and executes
aperiodic jobs, it consumes its budget at
the rate of 1 per time unit
The budget is exhausted, when it reaches 0
A time instant when the budget is
replenished (reloaded) is called
replenishment time
22
Periodic Server
A periodic server is backlogged whenever
the periodic job queue is non-empty
It is idle when the queue is empty
The server is eligible for execution only
when it is backlogged and has non-zero
budget
23
Polling Server
A polling server (ps, es) is a periodic server
When executed, it executes an aperiodic job,
if the aperiodic job queue is non-empty
Poller suspends execution or is suspended by
the scheduler either
– when it has executed for es, or
– when the aperiodic job queue becomes empty
24
Polling Server
Consumption Rules
– The execution budget of the server is
consumed at the rate of one per unit time
whenever the server executes.
Replenishment Rules
– The budget is replenished to es at the
beginning of each period
Example: Liu, Figure 7.2b, p.193
25
Polling Server
26
Polling Server
Aperiodic jobs that arrive after the release
time of the poller must wait until next
polling period
– Execution budget is not preserved
Simple to prove correctness
27
Bandwidth-Preserving Servers
A deficiency of the polling server algorithm
is that if the server is scheduled when it is
not backlogged, it loses its execution budget
until it is replenished when it is next
released
– An aperiodic job arriving just after the polling
server has been scheduled and found the aperiodic
job queue empty will have to wait until the next
replenishment time
28
Bandwidth-Preserving Servers
Cont..
Want to preserve execution budget of the server
when it finds an empty queue, to execute an
aperiodic job that arrives later in the period, if
doing so will not affect the correctness of the
schedule
30
Bandwidth-Preserving Servers
How do such servers work?
A backlogged bandwidth-preserving server
is ready for execution when it has budget
Scheduler keeps track of the consumption
of the server budget
If budget is exhausted server becomes idle
31
Bandwidth-Preserving Servers
Cont..
Scheduler moves server back to ready
queue, when budget is replenished and
server is backlogged
If a new aperiodic job arrives an idle server
becomes backlogged and is put into the
ready queue when it has budget
32
Bandwidth-Preserving Servers
Cont..
Many types of bandwidth-preserving
server:
– Deferrable servers
– Sporadic servers
– Constant utilization servers
– Total bandwidth servers
– Weighted fair queuing servers
33
Deferrable Server
Simplest bandwidth preserving server
– Improves response time of aperiodic jobs,
compared to polling server
Consumption rule :
– The execution budget of the server is
consumed at the rate of one unit per time
whenever the server executes
– Unused budget is retained throughout the
period, to be used whenever there are
aperiodic jobs to execute
• Instead of discarding the budget if no aperiodic job
to execute at start of period, keep in the hope a job
34
arrives
Deferrable Server Cont..
Replenishment rule:
– The budget is set to eS at multiples of the
period
• i.e. time instants k⋅pS, for k = 0, 1, 2, …
– Note: the server is not allowed to carry over
budget from period to period
35
Deferrable Server (RMS): Example
The deferrable server TDS =(3, 1) has the highest priority.
The periodic tasks T1 = (2.0, 3.5, 1.5) and T2 = (6.5, 0.5)
and the server are scheduled rate-monotonically. Suppose
that an aperiodic job A with execution time 1.7 arrives at
time 2.8.
37
Deferrable Server (RMS):
Example Cont.
38
Deferrable Server (EDF): Example
1. At time 2.8, the deadline of the deferrable server is 3.0.
Consequently, the deferrable server executes at the
highest-priority beginning at this time.
2. At time 3.0, when the budget of the deferrable server is
replenished, its deadline for consuming this new unit of
budget is 6. Since the deadline of J1,1 is sooner, this job
has a higher priority. The deferrable server is preempted.
3. At time 3.7, J1,1 completes. The deferrable server
executes until time 4.7 when its budget is exhausted.
4. At time 6 when the server’s budget is replenished, its
deadline is 9, which is the same as the deadline of the job
J1,2. Hence, J1,2 would have the same priority as the
server.
39
Deferrable Server(EDF):
Example
40
Schedulability of Deferrable Servers
Time Demand Analysis can be used to
determine whether all jobs remain
schedulable in the presence of a deferrable
server
Time Demand Function (if deferred server
has highest priority)
41
Schedulability of Deferrable
Servers
To determine whether the task Ti is
schedulable, we simply have to check
whether wi(t) ≤ t for some t ≤ Di.
Remember, this is a sufficient condition,
not necessary i.e. if this condition is not
true, the system may not be schedulable
42
Schedulability of Deferrable
Theorem Servers
In a fixed-priority system in which the relative deadline of every
independent, preemptable periodic task is no greater than its period
and there is a deferrable server (ps , es) with the highest priority
among all tasks, a critical instant of every periodic task Ti occurs at
time t0 when all the following are true.
1. One of its jobs Ji,c is released at t0.
2. A job in every higher-priority task is released at the same time.
3. The budget of the server is es at t0, one or more aperiodic jobs
are released at t0,and they keep the server backlogged hereafter.
4. The next replenishment time of the server is t0 + es .
43
Deferrable Server
Time Demand Analysis
44
Schedulability of Deferrable
Servers
There is no known schedulability
utilization that ensures the schedulability
of a fixedpriority system in which a
deferrable server is scheduled at an
arbitrary priority
Some special cases are discussed in the
book (Liu p.201)
45
Schedulability of Deadline-
Driven Systems in the Presence
of Deferrable Server
It is easier to reason about the schedulability of a deadline-driven
system with a deferrable server
– – The deadline of a deferrable server is its next replenishment
time
– – A periodic task Ti in a system of N independent, preemptable,
periodic tasks is schedulable with a deferrable server with period
pS, execution budget eS and utilization uS, according to the EDF
algorithm if:
49
A simple Fixed-Priority
Sporadic Server
Definitions (Liu p.205)
– tr denotes the latest actual replenishment time
– tf denotes the first instant after tr at which the
server begins to execute
– te denotes the latest effective replenishment
time
50
A simple Fixed-Priority Sporadic
Server
Definitions (Liu p.205)
– At any time t, BEGIN is the beginning instant of the
earliest busy interval among the latest contiguous
sequence of busy intervals of the higher priority
subsystem TH that started before t
– END is the end of the latest busy interval in the above
defined sequence if this interval ends before t and
equal to its infinity if the interval ends after t
Server Busy Interval: Begins when an aperiodic job
arrives at an empty aperiodic job queue and ends when
the queue becomes empty again
51
Fixed-Priority Simple Sporadic
Server
Consumption Rules (Liu p.206)
– At any time t after tr, the server’s execution
budget is consumed at the rate of 1 per unit
time until the budget is exhausted when either
one of the following to conditions are true.
When these conditions are not true, the server
holds its budget
• C1 The server is executing
• C2 The server has executed since tr and END < t
52
Fixed-Priority Simple Sporadic
Server
Replenishment Rules (Liu p.206)
– R1 Initially when the system begins execution
and each time when the budget is replenished,
the execution budget = es, and tr = the current
time
– R2 At time tf , if END = tf , te = max(tr,
BEGIN). If END < tf , te = tf . The next
replenishment time is set at te + ps
53
Fixed-Priority Simple Sporadic Server
Replenishment Rules (Liu p.206)
R3 The next replenishment occurs at the next
replenishment time, except under the
following conditions. Under these
conditions, replenishment is done at times
stated below
a) If the next replenishment time te + ps is earlier than tf,
the budget is replenished as soon as it is exhausted
b) If the system T becomes idle before the next
replenishment time te + ps and becomes busy again at
tb, the budget is replenished at min(te + ps , tb)
54
Simple Fixed-Priority Sporadic
Server
55
Fixed-Priority Sporadic Server
Sporadic server is more complex than polling or
deferrable servers due to more complex
consumption and replenishment rules
Main advantage: schedulability easy to
demonstrate
A sporadic server can be treated like a periodic
task when we check for schedulability
System with sporadic server may be schedulable
while the corresponding deferrable server is not
More complex sporadic servers exist (Liu: 7.3.2)
56
Sporadic Dynamic-Priority
Servers
Sporadic servers can also be used for
dynamic-priority (deadline-driven) systems
Rules have to be adapted to EDF or LST
Also here sporadic server can be treated as
normal task for schedulability analysis
57
Other Bandwidth Preserving
Servers
Other bandwidth preserver algorithms are
based on general processor sharing (GPS)
algorithms (deadline-driven algorithms)
Examples:
– Constant utilization server
– Total bandwidth server
– Weighted round-robin server
58
Schedulability of Sporadic Jobs
in Deadline-Driven Systems
Theorem :
A system of independent, preemptable
sporadic jobs is schedulable according to the
EDF algorithm if the total density of all
active jobs in the system is no greater than 1
at all times.
59
Constant Utilization Server
Algorithm
The server is defined by its size, which is its
instantaneous utilization ˜ us ; this fraction of
processor time is reserved for the execution of
aperiodic jobs. As with deferrable servers, the
deadline d of a constant utilization server is
always defined. The server is eligible and ready
for execution only when its budget is nonzero.
When the server is ready, it is scheduled with the
periodic tasks on the EDF basis.
60
Constant Utilization Server
Algorithm
Replenishment Rules of a Constant Utilization Server of Size ˜ us
R1 Initially, es = 0, and d = 0.
R2 When an aperiodic job with execution time e arrives at time t to
an empty aperiodic job queue,
(a) if t < d, do nothing;
(b) if t ≥ d, d = t + e/ ˜ us, and es = e.
R3 At the deadline d of the server,
(a) if the server is backlogged, set the server deadline to d + e/ ˜ us
and es = e;
(b) if the server is idle, do nothing.
61
Total Bandwidth Server
Algorithm
The total bandwidth server algorithm
improves the responsiveness of a constant
utilization server by allowing the server to
claim the background time not used by
periodic tasks. This is done by having the
scheduler replenish the server budget as
soon as the budget is exhausted if the
server is backlogged at the time or as soon
as the server becomes backlogged.
62
Preemptive Weighted Fair-
Queueing Algorithm
Scheduling Rule: A WFQ server is ready
for execution when it has budget and a
finish time. The scheduler assigns
priorities to ready WFQ servers based their
finish numbers: the smaller the finish
number, the higher the priority.
Consumption Rule: A WFQ server
consumes its budget only when it executes
63
Scheduling Sporadic Jobs
Sporadic jobs
Scheduler decides, if job can be accepted
or must be rejected
– Job is accepted and scheduled, if all other
scheduled jobs still meet their deadlines
– Otherwise job is rejected
Sporadic job is denoted by Si(ri, di, ei)
64
Acceptance Test in Fixed-
Priority System
Sporadic server can be used to execute
sporadic jobs in a fixed-priority system
The sporadic server (ps, es) has es units of
processor time every ps units of time
65
Acceptance Test in Fixed-
Priority Systems
For each new sporadic job S (r, d, e) it
must be checked, if
– new job can be scheduled together with the
sporadic jobs that have deadline before d
– sporadic jobs with deadline larger or equal to d
can still be scheduled
Acceptance test is quite complex, but may
still be feasible for many systems
66
Acceptance Test in Fixed-
Priority Systems
Accepted sporadic jobs are ordered among
themselves on EDF basis
For the first sporadic job S1(t, ds,1,es.1)
the server has at least floor((ds,1 – t)/ps) es
units of processor time available
Thus first job is accepted, if the slack of
the job σs,1(t) = floor((ds,1 – t)/ps) es –
es,1 is larger than or equal to 0.
67
Acceptance Test in Fixed-
Priority Systems
When there are already n accepted sporadic
jobs in the system, the scheduler computes the
slack σs,i of Si according to
70
Summary
Algorithms for Scheduling Sporadic Jobs
1. Acceptance Tests for Deadline-Driven Systems
2. Acceptance Tests for Fixed-Priority Systems
Servers can be used for the efficient
scheduling of aperiodic and sporadic jobs
Servers have consumption and replenishment
rules, which can be arbitrarily complex
Implementation overhead can be significant
71