Documente Academic
Documente Profesional
Documente Cultură
9/7/15
9/7/15
9/7/15
9/7/15
9/7/15
RTS CHARACTERISTICS
Time constraints : Deadlines
New Correctness Criteria : logical correctness
of results + time constraints
Issues
Architecture: Is the architecture suitable?
safety
reliability
fault- tolerance
9/7/15
a set of tasks
task precedence constraints
resource requirements
task characteristics
Deadlines
9/7/15
Task Precedence
A task is said to precede another task, if :
the first task must complete before the second task can
start
9/7/15
10
9/7/15
11
9/7/15
Minimum separation
instances may be 0
between
two
consecutive
12
Scheduling Algorithms
Uniprocessor, Multiprocessor Scheduling
Uniprocessor:
Rate Monotonic,
Deadline First, Deadline Monotonic etc.
Earliest
9/7/15
13
Scheduling Algorithms :
Classification
Preemptive:
The running task can be interrupted at any time
to assign the processor to ANOTHER task,
according to a predefined policy
Non- Preemptive:
a) With Non- Preemptive algorithms, a task, once
started, is executed by processor until
completion
b) All scheduling decisions taken after this tasks
execution
9/7/15
14
Classification Contd.
Static: sch. Decisions are based on fixed
parameters, assign to tasks before their activation
15
Classification Contd.
Optimal: minimizes some given cost function
defined over the task set.
Heuristic:
a) Searches for a feasible schedule Using an OBJECTIVE
FUNCTION(Heuristic Function)
b) Do NOT guarantee to find an optimal schedule
9/7/15
16
Scheduling AnOMaLiEs
In General / Fast Computing :
Increase of computational Power in the supporting
Hardware always RESULTS an Improvement on the
performance of a task set
9/7/15
17
NO!!!
I.
18
Uniprocessor Algorithms
RM
EDF
DM
EDD
LDF
And few more
priority
Uniprocessor
9/7/15
20
RM (Rate Monotonic)
Optimal static-priority scheduling
It assigns priority according to period
A task with a shorter period has a higher
priority
Executes a job with the shortest period
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
21
RM (Rate Monotonic)
Executes a job with the shortest period
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
22
RM (Rate Monotonic)
Executes a job with the shortest period
Deadline Miss !
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
23
Response Time
Response time
Duration from released time to finish time
T1(4,1)
T2(5,2)
T3(10,2)
9/7/15
10
15
10
15
24
Response Time
Response time
Duration from released time to finish time
Response Time
T1(4,1)
T2(5,2)
T3(10,2)
9/7/15
10
15
10
15
25
Response Time
Response Time (ri)
ri
ri ei
ek
TkHP (Ti ) pk
T (4,1)
1
T (5,2)
2
T (10,2)
3
9/7/15
10
10
26
RM - Schedulability Analysis
Real-time system is schedulable under RM
if and only if ri pi for all task Ti(pi,ei)
9/7/15
27
RM Utilization Bound
Real-time system is schedulable under RM
if
Ui n (21/n-1)
9/7/15
28
9/7/15
29
RM Scheduling
Let:- e:: execution time; p:: period such that p1 p2 . pn
Start with n = 2: T1 and T2 ; so that total utilization
U=
3(21/3 1)
9/7/15
30
RM Scheduling - Example
T1(1,4), T2(1,5), T3(1,10)
satisfied)
Now,
= 3 (21/3-1) 0.78
Since, U (0.55) is 0.78, So sufficient condition(Liu and Laylands
condition )also satisfied
9/7/15
31
RM Utilization Bound
Real-time system is schedulable under RM if
Ui n (21/n-1)
9/7/15
32
Optimal
Dynamic-priority
scheduling algo
task
Uniprocessor
whose
absolute
case
of
Deadline
Monotonic
33
there
are
no
34
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
35
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
36
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
37
T1(4,1)
T2(5,2)
T3(7,2)
9/7/15
10
15
10
15
38
10
15
10
15
39
EDF Summary
9/7/15
40
9/7/15
41
Schedulability Test
U=
P = lcm (P1Pn)
Let:
hT(t) be the SUM of the execution times of all
tasks in set T whose absolute deadlines are less
than t
9/7/15
42
9/7/15
43
T1
0
T2
3
T3 T4
5 6 7
Better schedules :
T1
0
9/7/15
T3
3
5 6 7
T1
0
T4
3
5 6 7
44
t = 0:
t =7:
T2 completes and T3 starts
10
30
execution
T1
T2
t = 17:
execution
T3
5
10
t = 23:
9/7/15
10
T3 completes and T1
starts
25
T1 completes
Real Time Systems
45
EDF- Example
Example: Periodic tasks:
Two tasks: T1(2,5) and T2(4,7)
U=?
Schedulable Under :
RMA?
EDF?
9/7/15
46
Example contd.
Schedule under EDF
1a
2a
1b
2
22
9/7/15
5
25 26
2b
6 7
28
2
c
1c
8
10
1d
12
2c
1e
14
15
2d
17
1f
20 21
47
RM vs. EDF
Rate Monotonic
Simpler implementation, even in systems
without explicit support for timing constraints
(periods, deadlines)
Predictability for the highest priority tasks
EDF
Full processor utilization
Misbehavior during overload conditions
9/7/15
48
on
Time
e
deadli
ne
ty
T1
50
50 (1)
25
100
T2
62.5
(2)
10
20
T3
125 (3)
25
50
9/7/15
49
DM Algorithm Contd.
When the relative deadline of every task is
proportional to its period, RM and DM algorithms
are identical
When the relative deadlines are arbitrary, DM
algorithm performs better
DM can produce a feasible schedule when RM
algorithm fails, While RM algorithm always fails
when the DM algorithm fails
9/7/15
50
//
Notation Classifies all algorithms using these 3
fields
9/7/15
51
Notation //
: describes machine environment on which task
set has to be scheduled(Uniprocessor, multiprocessor)
9/7/15
52
Notation //
Example:
1/prec/Lmax : denotes the problem of scheduling a set of
tasks on a Uniprocessor machine with precedence
constraints and the objective is to minimize the maximum
lateness
If no additional constraints are indicated in the second field then ,
preemption is allowed at any time and tasks have arbitrary arrivals
53
Jacksons Algorithm
The Problem considered by this algo. is:
1/sync/Lmax
Here:
All tasks consists of a single job, have syn. arrival times,
BUT can have diferent execution times and deadlines
Tasks are independent, cant have precedence relations
and cant share resources in exclusive mode
54
9/7/15
55
EDD Algorithm
Consider a set of 5 tasks, simultaneous activated
at t=0:
J1
J2
J3
J4
J5
ei
Di
10
56
EDD Contd.
Note:
The optimality of EDD algo. CAN NOT Guarantee
the Feasibility of the schedule for a task set.
It ONLY guarantees that:
if there exists a feasible schedule for a task set,
then EDD will Find it
9/7/15
57
9/7/15
58
LDF Contd.
iii. Repeat until all tasks are in the stack
iv. The stack represents the order in which tasks
should be scheduled
.
9/7/15
LDF is optimal
59
LDF: Example
9/7/15
60
61
Example Contd.
Ti
Ei
Di
20
21
27
28
Assumption:
Deadline is specified for each task, such that there will be
enough time to execute its children in the task graph by their
deadlines even if a task completes at its deadline
9/7/15
62
Algorithm PREC
Tasks are numbered so that D1 D2 D3 Dn
1. Schedule task Tn in the interval , [Dn-en, Dn]
2. While ( all the tasks have not been scheduled),
let A be the set of as-yet-unscheduled tasks all
successors if any, have been scheduled
of whose
9/7/15
63
9/7/15
64
Handling CriticalContd.
Assumptions
Once a task starts, it continues until it
finishes
It can be preempted by some higher priority
task
It can be blocked by lower priority task that
holds the lock on a critical section that it
needs
9/7/15
65
9/7/15
66
t0 :
J3 begins execution
t1 :
J3 enters S
t2 :
J1 released, it preempts J3 and start executing
t3 :
J1 wants to enter S, S is locked by J3 which is
suspended, J1 is blocked and J3 continues in S
t4 :
J2 is released which preempts J3
t5 :
J2 completes, J3 resumes
t6 :
J3 exits S; J1 preempts J3
9/7/15
67
Indefinite Contd.
preempt J3
(try to lock S)
blocked by J3
indefinite
!
blocking
J1
preempt J3
J2
lock S
J3
tim
e
9/7/15
t0
t3
t1
t4
t2
68
Solution:
Use of Priority Inheritance Protocol (PIP):
If THigh is blocked by TLow , TLow temporarily inherits
the priority of THigh. When blocking ceases, TLow
resumes its original priority
For previous example of Priority Inversion Problem:
At time t3, when J3 blocks J1, J3 inherits the higher
priority of J1
So, when J2 is released at t4, It can not interrupt J3
As a result , J1 is not indirectly blocked by J2
9/7/15
69
Problems in PIP
1. Deadlocks
Due to crossing nested semaphores
2. Long Blocking Delays
Due to
a. Transitive Blocking
Blocking by indirectly involved semaphores which
are accessed in nested form by blocking jobs
b. Chain Blocking
Blocking can occur sequentially whenever
accessing each semaphore
9/7/15
70
:
:
:
:
:
J1,
t5 :
J2 starts execution
J2 locks S1
J1 is initiated, it preempts J2
J1 locks S2
J1 attempts to lock S1 but blocked. Now J2 inherits priority of
starts execution
J2 tries to lock S2, it cannot do so, since J1 has a lock on it
71
PIP : DeadlockingContd.
J1 = {..., P(S2) ..., P(S1),...,V(S1) ...,V(S2),...}
J2 = {..., P(S1) ..., P(S2),...,V(S2) ...,V(S1),...}
preempt J2
lock
S2
crossing
nested
semaphores
(try to lock
S1)
blocked by J2
J1
lock
S1
(try to lock
S2)
blocked by J1
J2
tim
t0
e
t1
t2
t3
t4
t5
deadlock!
9/7/15
72
(attempt
S1)to lock
blocked by J3 lock
S1
(attempt
S2)to lock
blocked by J2
complete
unlock
lock unlock
S2
S1
S2
J1
preempt J3 lock
S2
unlock
S2
J2
complete
complete
unlock
S1
lock
S1
J3
time
9/7/15 t0
t1
t2
t3
t4
t5
Real
t6Time Systems
t7
t8
t9
t13
73
9/7/15
74
9/7/15
75
Basic Idea:
Priority ceiling of a semaphore is:
The priority of the highest priority task that
may use the semaphore
9/7/15
76
a
critical section(CS) if there exists any semaphore
currently held by some other task whose priority
ceiling is greater than or equal to the priority of T
i.e.,
Additional condition for allowing a job J to start a
new critical section is:
only if Js priority is higher than all priority ceilings of
all the semaphores locked by jobs other than J
9/7/15
77
9/7/15
T1> T2> T3
78
PCP Example:
4 real time tasks: J1,J2,J3,J4 Sharing two CS: S1, S2 such that:
S1: J1, J2, J3
S2: J1, J4
9/7/15
79
9/7/15
80
PCP Advantage #1
Prevent deadlocks :
J1 = {..., P(S0) ..., V(S0),...}
J2 = {..., P(S1) ..., P(S2),...,V(S2) ...,V(S1),...}
J3 = {..., P(S2) ..., P(S1),...,V(S1) ...,V(S2),...}
lock S0
nested crossing
semaphores
unlock S0
complete
preempt J3
J1
lock S2
preempt J3
J2
(attempt to lock
S1)
blocked by J3
lock S2
unlock S2
unlock S1
complete
lock S1
complete
J3
time
9/7/15 t 0
t1
t2
t3
t4
t 5 Real
t 6 Time
t 7 Systems
t8
t9
t10
t11
t12
t13 t14
t15 81
PCP Advantage #2
preempt J3
complete
J1
lock S1unlock S1
preempt J3
unlock S2
complete
lock S2
(attempt to lock
S2)
blocked by J3
J2
complete
unlock S1
lock S1
J3
time
9/7/15t 0
t1
t2
t3
t4
t 5 Systems
Real Time
t6
t7
t8
t9
t10
t11
t12
t13
82
PCP Advantage #3
Prevent Chain Blocking :
unlocklock
S2
S1
unlockcomplete
S2
J1
to lock
preempt J3 (attempt
S2)
blocked by J3
lock
S2
unlock complete
S2
J2
complete
unlock
S1
lock
S1
J3
t0 t1
t2
t3
t4
t5
t6
t7
t8
t9
t10
t11 t12
t13
83
Practice Problem:
S1
S2
9/7/15
T1 T4
T2, T4, T5
P(T1)
P(T2)
84
TH
9/7/15
85
TI
CS
TH
Ceil(S1)= 10
CSV= 10
9/7/15
TL
CS
1
P(TH) = 8
CS
2
TH
87
shared
88
Example:
Inversions
Diferent
Types
of
A systems has 6 Tasks and 3 CS: S1, S2 and S3; such that:
P(T1) > P(T2)> P(T3)>P(T4) >P(T5) >P(T6)
The exact resource requirements of these tasks & the duration(in
msec) for which the tasks needs the resources can be shown as:
T
1
T
2
T
3
30
20
S1
10
T
4
50
S2
10
T
5
40
S3
10
T
6
9/7/15
89
Example Contd.
Challenge: Computing the diferent types of inversions that each task
might have to undergo in the worst case
Solution:
The ceiling of any CS S can be calculated as:
Ceil(S) = max ( P{Ti}) ; such that Ti may need S
9/7/15
90
Example Contd.
a. For task T1:
. T1 can sufer direct- inversion by T3(10 sec due to S1), OR , by T6(10 sec
due to S1)
. T1 will not sufer any inheritance- related inversion or deadlock- avoidance
inversion since it is the highest priority task
b. For task T2:
. T2 can sufer direct- inversion by T4(40 sec due to S2)
. T2 can also sufer inheritance- related inversion on account of T3(10 sec )
when T3 acquired S1 and T1 waits for S1, OR, on account of T6(10 sec )
when T6 acquired S1 and T1 waits for S1
.
9/7/15
91
Example Contd.
c. For task T3:
. Direct inversion: by T6(10 sec due to S1)
. Inheritance- related inversion: on account of T4(40 sec) when T4
acquired S2 and T2 waits for S2, OR, on account of T6(10 sec ) when
T6 acquired S1 and T1 waits for S1
. Deadlock- avoidance inversion: by T4(40 sec), OR, by T6(10 sec )
d. For task T4:
. Direct inversion: T4 will not sufer any direct inversion since it does
not share any resource with a lower priority task
. Inheritance- related inversion: on account of T6(10 sec ) when T6
acquired S1 and T1 waits for S1
. Deadlock- avoidance inversion: by T6(10 sec )
9/7/15
92
Example Contd.
e. For task T5:
. Direct inversion: T5 will not sufer any direct inversion since it does not
share any resource with a lower priority task
. Inheritance- related inversion: on account of T6(10 sec ) when T6
acquired S1 and T1 waits for S1
. Deadlock- avoidance inversion: T5 will not sufer any direct inversion
since it does not require any shared resource(CS)
f. For task T6:
. T6 will not sufer any priority inversion, as it is the lowest priority task
9/7/15
representing
93
Example Contd.
Direct
Avoidance
Task
T2
T2
T3
T3
T4
T4
T5
Inheritance
T5
T6
T6
T2
T3
T4
T5
T6
T1
10
10
T2
40
10
10
10
10
T3
10
40
10
40
10
T4
10
10
T5
10
Inversion Table
9/7/15
94
In RM scheduling:
even when a task set fails Liu and Laylands
Test, we should not conclude that it is not schedulable
under RM algorithm. We need to test further to check if the
task set is RM schedulable
9/7/15
95
Lehoczkys Test
Lehoczkys test can be expressed as:
A set of periodic real-time task is RM schedulable
under any task phasing, if all the tasks meet
their respective first deadlines under zero
phasing
The Worst Case Response time for a task occurs when it is in
phase with its higher priority tasks
96
Lehoczkys Test
T1{10, 30} and T2{60,120}
P{T1}> P{T2}
T1
T2
10
a)
T1
20
T2
30
40
T1
T2
60
T1 is in
90 phase with T2,
Response Time = 90 msec
T2
b)
T1
80
T2
30
T1
70
T2
50
60
97
Let:
we have tasks set: {T1 T2 T3 Ti} ; such that P{T1} > P{T2}.... > P{Ti}
Let the task Ti arrives at time t= 0
During the first instance of the task T i , 3 instances of the task T1have
occurred
1Ti
1T1
1T1
1T1
Each time T1 occurs, Ti has to wait since T1 has higher priority then Ti
9/7/15
98
99
Lehoczkys Contd.
This is total time required to execute all the tasks with
higher priority then Ti for which Ti would have to wait
Thus, the task Ti would meet its first deadline, if:
ei +
pi
That is,
if the sum of (the execution times of all the higher priority
tasks occurring before Ti s first deadline) and
(the
execution time of the task Ti itself) is less then equal to its
period, then the task Ti would complete before its first
deadline
9/7/15
100
Lehoczkys Contd.
9/7/15
di
101
Example:
Solution:
1. Ordering all tasks acc. to Priority : T1 > T2> T3
2. Try the sufficiency test for RMA Schedulability( Liu and Laylands
Test):
the task set is schedulable if
Ui
3 (21/3-1) 0.78
9/7/15
102
Example Contd.
3. Now, try Lehoczkys Test:
. Ordering all tasks acc. to decreasing order of Priority : T1 >
T2> T3
Testing for T1:
since e1 < d1 here, thus T1 would meet its first deadline
. Since all the tasks meet their respective first deadlines, the
task set is RMA schedulable according to Lehoczkys result
9/7/15
103
Practice
3 periodic real time tasks : T1(20, 100), T2(30,
150), T3(90,200) to be run on a uni-processor.
Determine whether the task is schedulable under
RMA.
Use lehoczkys test.
9/7/15
104
Handling Overload
Conditions
Problem: scheduling RT tasks in overloading
conditions
overloading conditions: Situations in which the
computational demand requested by the task set
exceeds the time available on the processor, and hence
not all tasks can complete within their deadlines
9/7/15
105
Handling Contd.
106
Handling Contd.
2. Transient overloads due to Execution Overruns:
9/7/15
When the total utilization factor of the task set is greater then 1
Can happen either because of:
a. The execution requirements of the task set was not correctly estimated
b. Some unexpected activation of new periodic tasks
c. Some of the current tasks increased their activation rate to react to
some changes in the environment
107
Ready Queue
Run
2.Guaranteed:
Includes those algorithms with Admission Control, in which
the load on the processor is controlled by an Acceptance Test
executed at each task interval
9/7/15
108
Guarante
e Routine
Ready
Queue
Run
accepted
rejected
3. Robust Scheduling:
9/7/15
109
Plannin
g
Ready
Queue
Rejection
Scheduling Policy
Run
Policy
Reject
Queue
9/7/15
110
Advantages:
operates in normal and overload conditions with excellent
performance
able to predict not only deadline misses but also the size of
the overload, its duration, and its overall impact on the
system
9/7/15
111
RED Contd.
In RED:
1. Each task Ji{Ci,Di,Mi,Vi) is characterized by 4 parameters:
Deadline Tolerance:
The amount of time by which a task is permitted to be late; that is, the
amount of time that a task may execute after its deadline and still produce a
valid result
9/7/15
112
RED Contd.
2. The primary deadline plus the deadline tolerance
provides a sort of secondary deadline, and used to
run the acceptance test in overload conditions
NOTE: having a tolerance greater than zero is different than having a
longer deadline
113
RED Contd.
5. The guarantee test performed in RED is formulated in
terms of residual laxity
Residual Laxity (Li ): of a task is defined as the interval
between its estimated finishing time (fi) and its primary
(absolute) deadline (Di)
6. Each residual laxity can be efficiently computed using the
result of the following Lemma:
Lemma:
Given a set J = {J1, J2, J3..Jn} of active aperiodic tasks ordered
by increasing primary (absolute) deadline, the residual laxity Li
of each task Ji at time t can be computed as
114
RED Contd.
where
L0 = 0,
D0 = t (the current time)
Ci{t} is the remaining worst-case computation time of task J i at
time t
Proof:
By definition, a residual laxity is Li = Di- fi.
Since tasks in the set J are ordered by increasing deadlines, task
Ji is executing at time t, and its estimated finishing time is given
by the current time plus its remaining execution time (f1 = t +
C 1)
As a consequence, L1 is given by:
L1 = D1- f1 = D1- t
9/7/15
- C1
115
RED Contd.
Any other task Ji, with i > 1, will start as soon as Ji-i
completes and will finish Ci units of time after its start :{fi
= fi-i + Ci}
Hence, we have:
Li = D i- f i
= Di- fi-1 Ci
= Di- {di-1 - Li-1} - Ci
= Li-1 + {Di- di-1} - Ci
9/7/15
116