Rts 4
Rts 4
Scheduling
P e r i o d i c Ta s k s
K i z h e p p a t t Vi p i n
Assumptions
Tasks are independent
Scheduling decisions are made as soon as jobs are released and completed online
scheduling, event triggered
, D )
( p ,e 1
1
1
Scheduler
Application 1
Application (software) requests the scheduler for scheduling a task and provides all
relevant parameters (period, execution time, relative deadline)
General Architecture
, D )
( p ,e 1
1
1
Scheduler J1,1
Priority Q
Application 1
T1
Accepted Tasks
Scheduler runs an acceptance test to check the feasibility and if accepted puts the
task into an accepted task list
The currently running jobs are kept in a priority queue and the first job in the
queue always gets executed
General Architecture
J2,1
Scheduler J1,1
Priority Q
)
T2
2
2 D
,e ,
T1
2
(p
Accepted Tasks
Application 2
General Architecture
J2,1
J1,1
Scheduler J3,1
) Priority Q
e ,D 3
, 3
(p 3 T3
T2
Application 3 T1
Accepted Tasks
When a higher priority job comes it may become first in the queue
J2,1
Scheduler J1,1
Priority Q
T3
T2
T1
Accepted Tasks
Job level fixed and task level dynamic priority algorithm assigns fixed priority to jobs but at
task level priority can vary at run-time
Priority of a job is fixed at the time of its release and it does not change
Priority of a task with respect to that of the other tasks changes as jobs are released and
completed
Job level and task level dynamic priority algorithm assigns different priorities to individual
jobs of each task
Priority of jobs can vary at run time when other jobs are released
Rate Monotonics (RM) Algorithm
Priorities assigned based on period lower the period, higher the priority
T2
T3
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
A system of periodic tasks is simply periodic if for every pair of tasks T i and Tk in the
system and pi < pk , pk is an integer multiple of pi
preemptive periodic tasks in the system (Liu & Layland utilization bound)
Eg: They are T1 = (50, 50, 25, 100), T2 = (0, 62.5, 10, 20), and T3 = (0, 125, 25, 50)
Task Priority P e D
T1 3 50 25 100
T2 1 62.5 10 20
T3 2 125 25 50
Deadline Monotonic (DM) Algorithm
When relative deadlines are arbitrary, DM performs better than RM In some cases
DM can produce a feasible algorithm, where RM cannot
Previous case with RM T1 has highest priority followed by T2 and then T3
EDF Algorithm
Dynamic priority algorithm
Priority based on the absolute deadline of jobs earlier the deadline, higher the
priority
Sufficient condition Even if this condition is not satisfied, we might be still able to
schedule
LST Algorithm
Dynamic priority algorithm
Priority based on the slack of jobs lesser the slack, higher the priority
Proof: Any feasible fixed priority schedule can be converted into DM schedule Use
the same steps used for EDF optimality proof
SCHEDULABILITY TEST FOR FIXED-PRIORITY TASKS
WITH SHORT RESPONSE TIMES
Assumptions
The response times of the jobs are smaller than or equal to their respective periods
every job completes before the next job in the same task is released Relative
deadline period
Utilization U 1
In T, all tasks are arranged based on their deadline in such a way that priority of Ti >
priority of Tj if i < j
Critical Instant
Input to schedulability test: sets {pi} and {ei } of periods and execution
times of the tasks in T
The test checks one task Ti at a time to determine whether the response times of all its
jobs are equal to or less than its relative deadline Di
We must first identify the worst-case combination of release times of any job Ji,c in Ti
and all the jobs that have higher priorities than Ji,c
This combination is the worst because the response time of a job Ji,c released under
this condition is the largest
Theorem:
In a fixed-priority system where every job completes before the next job in the same
task is released, a critical instant of any task Ti occurs when one of its job Ji,c is
released at the same time with a job in every higher-priority task, that is,
ri,c = rk,l for some l for every k = 1, 2, . . . , i − 1
Critical Instant
RM schedule of the three jobs, (2, 0.6), (2.5, 0.2), and (3, 1.2). Time 0 is critical instant
for both T2 and T3
T1
0 1 2 3 4 5 6 7 8 9 10 11 12
T2
0 1 2 3 4 5 6 7 8 9 10 11 12
T3
0 1 2 3 4 5 6 7 8 9 10 11 12
Response times of the jobs in (2.5, 0.2): 0.8, 0.3, 0.2, 0.2, 0.8
Response times of the jobs in (3, 1.2): 2, 1.8, 2, 2
Critical Instant
RM schedule of the three jobs, (2, 0.6), (1, 2.5, 0.2, 2.5), and (3, 1.2). Time 6 is critical
instant for both T2 and T3 since ф of T2 is 1
T1
0 1 2 3 4 5 6 7 8 9 10 11 12
T2
0 1 2 3 4 5 6 7 8 9 10 11 12
T3
0 1 2 3 4 5 6 7 8 9 10 11 12
Maximum response times of the jobs in (2.5, 0.2): 0.8
Response times of the jobs in (3, 1.2): 2
Time Demand Analysis
To determine whether a task can meet all its deadlines, we first compute the total
demand for processor time by a job released at a critical instant of the task and by all
the higher-priority tasks as a function of time from the critical instant
Then check whether this demand can be met before the deadline of the job. For this
reason, we name this test a time-demand analysis.
To carry out the time-demand analysis on T, we consider one task at a time, starting
from the task T1 with the highest priority in order of decreasing priority
Time Demand Analysis
Ti releases at time t0
At time t0+ t for t 0, the processor demand for this job and all higher priority jobs released
between [t0,t] is given by
i - 1
wi(t) = ei + k=1
t/pkek for 0 < t ≤ pi
Ti can meet its deadline t0 + Di if at some time t0 + t processor time t processor demand
time wi(t)
In other words Ti can meet its deadline if we can find a t in such a way that w i(t) ≤ t and t ≤
Di and Di ≤ pi
Time Demand Analysis
p e
T1 1 3 1
T2 2 5 1.5
T3 3 7 1.25
T4 4 9 0.5
U = 0.867
Liu-Leyland bound = 4(21/4 -1) = 0.757
Time Demand Analysis
Time
Time Demand Analysis
w1(t)
Time Demand Analysis
w1(t)
Time Demand Analysis
w1(t)
Time Demand Analysis
w1(t)
Time Demand Analysis
w2(t)
w1(t)
Time Demand Analysis
w2(t)
w1(t)
Time Demand Analysis
w2(t)
w1(t)
Time Demand Analysis
w2(t)
w1(t)
Time Demand Analysis
w2(t)
w1(t)
Time Demand Analysis
w3(t)
w2(t)
w1(t)
Time Demand Analysis
w4(t)
Time Demand Functions
w3(t)
w2(t)
w1(t)
Time Demand Analysis
w4(t)
Time Demand Functions
w3(t)
w2(t)
w1(t)
Time Demand Analysis
w4(t)
Time Demand Functions
w3(t)
w2(t)
w1(t)
Time Demand Analysis
p e
T1 1 3 1
T2 2 5 1.5
T3 3 7 1.25
T4 4 9 0.5
T5 5 10 1
U = 0.967
Time Demand Analysis
w5(t)
w4(t)
Time Demand Functions
w3(t)
w2(t)
w1(t)
Time Demand Analysis
You will notice time-demand function of Ti is a staircase function
The rises in the function occur at time instants which are integer multiples of periods
of higher-priority tasks
It is enough to do simulation until the largest period among tasks since we are starting
simulation from a critical instant
For RM that task has the lowest priority. So if we can schedule it released from a
critical instance, any job can be scheduled
For DM at least one job’s deadline will happen with in one period of the largest
task
Worst Case Simulation Method
SCHEDULABILITY TEST FOR FIXED-PRIORITY TASKS
WITH ARBITRARY RESPONSE TIMES
Relative deadlines are larger than their respective periods
Since the response time of a task may be larger than its period, it may have more than
one job ready for execution at any time
Ready jobs in the same task are scheduled on the FIFO basis
Busy Intervals
A level-πi (π is used to indicate priority) busy interval (t0, t ] begins at an instant t0
when
(1) all jobs in Ti released before the instant have completed and
(2) a job in Ti is released
The interval ends at the first instant t after t0 when all the jobs in Ti released since t0
are complete
In the interval (t0, t ], the processor is busy all the time executing
jobs with priorities πi or higher
All the jobs in Ti executed in the busy interval are released in the
interval, and at the end of the interval there is no backlog of jobs to be executed
afterwards
Busy Intervals
When computing the response times of jobs in Ti , we can consider every level-πi busy
interval independently from other level-πi busy intervals
A level-πi busy interval is in phase if the first jobs of all tasks that have priorities equal
to or higher than priority πi and are executed in this
interval have the same release time
Busy Intervals
To determine whether a task Ti is schedulable, we must examine all the jobs of Ti that
are executed in the first level-πi busy interval
If the response times of all these jobs are no greater than the relative deadline of Ti , Ti
is schedulable; otherwise, Ti may not be schedulable
General Time-Demand Analysis Method
Test one task at a time starting from the highest priority task T1 in order of decreasing
priority
To determine whether a task Ti is schedulable, assume that all the tasks are in phase
and the first level-πi busy interval begins at time 0
General Time-Demand Analysis Method
To test whether all the jobs in Ti can meet their deadlines (i.e., whether Ti is
schedulable), consider the subset Ti of tasks with priorities πi or higher
(i) If the first job of every task in Ti completes by the end of the first period of the
task, check whether the first job Ji,1 in Ti meets its deadline. Ti is schedulable if Ji,1
completes in time. Otherwise, Ti is not schedulable
General Time-Demand Analysis Method
(ii) If the first job of some task in Ti does not complete by the end of the first period of
the task, do the following:
(a) Compute the length of the in phase level-πi busy interval by solving the equation t
i
= k =1 t/pk ek iteratively
i
Start with t = k =1ek for next iteration use it as the t value in the right hand side
Continue this until you get same t value in the consecutive steps tl = tl+1 for some
iteration number l 1
Compute the maximum response times of all t /pi jobs of Ti in the in-phase level-πi
l
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w2,1(t)
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w3,1(t)
w2,1(t)
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25,3.5), and T3 = (5, 0.25,6) π1 = 1, π2 = 2, and π3 = 3
0=5.75
w3,1(t)
J2,1 completes at 3.25
w2,1(t) Response time = 3.25-
0=3.25
w1,1(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w1,2(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
w2,2(t)
w1,2(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25,3.5), and T3 = (5, 0.25,6) π1 = 1, π2 = 2, and π3 = 3
J3,2 completes at 6
Response time = 6-
Time Demand Functions
5=1
w1,2(t)
Time
General Time-Demand Analysis Method
T1 = (2, 1), T2 = (3, 1.25,3.5), and T3 = (5, 0.25,6) π1 = 1, π2 = 2, and π3 = 3
J3,2 completes at 6
Response time = 6-
Time Demand Functions
5=1
w1,2(t)
Time
General Time-Demand Analysis Method
Worst-case response time Wi,j of the j job of Ti in an in-phase level-πi busy period is
th
We can say the task Ti is schedulable if worst case response time among all its job in a
in-phase level-πi busy period (we can always take first level-πi) is less than its relative
deadline
Wi ≤ Di
General Schedulability through Simulation
T1 = (2, 1), T2 = (3, 1.25), and T3 = (5, 0.25) π1 = 1, π2 = 2, and π3 = 3
General Time-Demand Analysis Method
Worst-case response time Wi,j of the j job of Ti in an in-phase level-πi busy period is
th
We can say the task Ti is schedulable if worst case response time among all its job in a
in-phase level-πi busy period (we can always take first level-πi) is less than its relative
deadline
Wi ≤ Di
Practical Factors
Till now we assumed
T1 = (, 4,1)
T2 = (, 5, 1.5)
T3 = (9,2)
U = 0.772
3*(2 (1/3)
– 1) = 0.779
Nonpreemptability
W2(t)
W1(t)
Non-preemptability
Now consider T3 is non-preemptible
When the jobs J1,1 and J2,1 become ready at ε, the first job J3,1 of T3 is executing
Since J3,1 cannot be preempted, both J1,1 and J2,1 get blocked and they have to wait until
J3,1 completes
0 1 2 3 4 5 6 7 8 9 10 11 12
One way to check this is to add the priority inversion duration (2 units) during the
calculation of time demand of higher priority tasks
Nonpreemptability
W2(t)
W1(t)
Effect of Nonpreemptability on Schedulability
We use θi (θi ≤ ei ) to denote the maximum execution time of the longest non-
preemptable portion of jobs in the task Ti
bi(np) = max(θk)
i+1 ≤ k ≤ n
wi(t) = ei + bi + i - 1
k=1
t/pk ek for 0 < t ≤ min(Di,pi)
i-1
wi,j(t) = jei + bi + k=1 (t+ri,j)/pkek - ri,j
Self Suspension
While executing, a job may invoke some external operation, for example, an I/O
operation
Self-blocking or self-suspension occurs when the job is suspended and waits until such
an operation completes before its execution can continue
While it waits, the operating system removes it from the ready queue
and places it in a blocked queue
We assume that the maximum amount of time each external operation takes to
complete and, hence, the maximum duration of each self-suspension, is known
Schedulability Under Self Suspension
Hence, the time from the instant when the job is ready to its deadline
is only Di − x, not Di
Condition 2: Different jobs of task Ti may self suspend for different amount of time
T1 = (4,2.5)
T2 = (3,7,2)
T1
Deadline is broken
T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
No self suspension
T1
T2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Self suspension for 1.5 units for J1,1
Schedulability Under Self Suspension
i - 1
bi(ss) = max self suspension of Ti + k=1 min(ek,max self suspension of Tk)
The reason is that every time a job suspends itself, it loses the processor
if each job in a task Ti can self-suspend for a maximum number Ki times after it
starts execution, its total blocking time bi is given by
T3
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Context Switches
We can account for the context-switch overhead in a schedulability test by including
the time spent for the two context switches at the start and completion of each job as
part of the execution time of the job
Include the context-switch time in the execution time of the preempting job
ei = ei + 2*CS
If some job self-suspends, the job incurs two more context switches each time it self-
suspends
ei = ei+2(Ki + 1)CS
Limited Priority Levels
A real-life system can support only a limited number of priority levels
When tasks in a fixed-priority system have nondistinct priorities, a job Ji,j of Ti may be
delayed by a job of an equal priority task Tk
Jobs of equal priorities are scheduled either on a FIFO basis or on a round-robin basis
Let TE(i) denote the subset of tasks, other than Ti , that have the
same priority as Ti and TH(i) the subset of tasks with higher priority In the worst case
Hence every job is inserted into ready job queue as soon as it becomes ready
We mostly implement the scheduler as clock driven and the execution of the scheduler
is triggered by a timer interrupt
When scheduler executes, it moves the jobs in the pending queue to the ready job
queue and places them there in order of their priorities
Tick Scheduling
The time the scheduler takes to move the jobs introduces additional scheduling
overhead
We can model the scheduler as a periodic task T0 whose period is p0 (tick size)
Its execution time e0 is the amount of time the scheduler takes to service the clock
interrupt
Deadline is broken
Tick Scheduling
Additional time demand introduced by tick scheduling in a fixed-priority system by
modified task parameters in the computation of the time-demand function of task Ti :
1. include the task T0 = (p0, e0) in the set of higher-priority tasks;
2. add (Kk + 1)CS0 to the execution time ek of every higher-priority task Tk (i.e., for k =
1, 2, . . . , i ), where Kk is the number times Tk may self-suspend;
3. for every lower-priority task Tk , k = i + 1, . . . , n, add a task (pk ,CS0) in the set of
higher-priority tasks; and
4. make the blocking time bi(np) due to nonpreemptability of Ti to
(max + 1)p0
i+1≤ k ≤ n
where θk is the maximum execution time of non-preemptable sections of the
lowerpriority task Tk