Chapter 1 -- Introduction - Arizona State University
Download
Report
Transcript Chapter 1 -- Introduction - Arizona State University
CSE 522
Real-Time Scheduling (2)
Computer Science & Engineering Department
Arizona State University
Tempe, AZ 85287
Dr. Yann-Hang Lee
[email protected]
(480) 727-7507
1
Priority-Driven Scheduling of Periodic Tasks
Why priority-driven scheduling
use priority to represent urgency
easy implementation of scheduler (compare priorities and
dispatch tasks)
tasks can be added or removed easily
no direct control of execution instant
How can we analyze the schedulability if we don’t
know when a task is to be executed
Let’s begin a deterministic case in one processor
independent periodic tasks
deadline = period
preemptable
no overhead for context switch
2
Priority-Driven Schedules
Assign priority when jobs arrive
static -- all jobs of a task have a fixed priority
dynamic -- different priorities to individual jobs of a task
relative priorities don’t change while jobs are waiting
Static priority schedules
Rate-monotonic -- the smaller a task priority, the higher its priority
Deadline-monotonic
Dynamic priority schedules
EDF -- earliest deadline first
LSTF -- least slack time first
Schedulable utilization:
a scheduling algorithm can feasibly schedule any sets of priority tasks if
the total utilization is equal to or less than the schedulable utilization of
the algorithm
3
EDF Schedule
A optimal algorithm under single processor and preemptable tasks
How do we know a set of periodic tasks are schedulable under EDF
?
If we know the schedulable utilization SU of EDF, then any sets of
tasks are schedulable when U SU
Theorem: A set of n periodic tasks can be scheduled by EDF iff
n
ei
U 1
i 1 pi
Proof
the only-if part is obvious
the if part --- show if there is a job misses its deadline, then U > 1
4
EDF Schedule
Let the 1st unschedulable job be Ji,c that misses its deadline at t
and the processor is never idle during [0,t]
how much execution we have done before t
Case 1: no type D jobs and let’s ignore type C jobs
(t k )
(t i )ei
ei
ek
t
e
t
(
) tU
k
pi
pk
pi k i pk
k i
Case 2: if type D jobs exist and are executed before r
let t’ be the latest instant that type D jobs execute
how much execution we have done in [t’, t]
B
A
0
r
Ji,c is released
C
D
t
Ji,c misses its deadline
5
Extension of EDF Schedulable Utilization
If Di pi, EDF is schedulable iff U 1
What can we do if Di < pi
density of task k : k = ek / min(pk,Dk)
EDF is schedulable if the total density is equal to or less than 1
proof: if there is a job missing its deadline, then the total density > 1
there is no “only-if” part ---- if the total density > 1, EDF may or may not
schedulable
If Di pi, LSTF is schedulable iff U 1
Predicable for single-processor preemptive schedule of
independent tasks
Robust
independent of phases
periods are lower bound applicable to sporadic tasks with minimum
separations
6
General EDF Feasibility Analysis
Processor demand: all processing request during a
period [ti, t2), i.e.,
Loading factor:
h[t1 ,t2 )
u[t1 ,t2 )
C
k
t1 rk , d k t 2
h[t1 ,t2 )
t 2 t1
Each set of real-time jobs is feasibly scheduled by
EDF iff
u sup u[t1 ,t2 ) 1
0t1 t 2
How to compute loading factor?
7
Sporadic Tasks under EDF
minimum separation Ti ≠ Di
Worst possible scenario: arrives synchronously at
the maximum rate
A sporadic task set is feasibly scheduled by EDF iff
u u 1
Need to show that
h[t1 ,t2 )
t 2 t 1 Di
(1
)Ci h[0,t2 t1 )
Di t 2 t 1
Ti
Hybrid task sets (with both periodic and sporadic
task) are schedulable under EDF if
n
Ci
1
i 1 minDi , Ti
8
EDF Schedulability Test
If Di ≤ Ti and synchronous task sets
loading factor u[0,t)≤1 for all t
L: synchronous busy period, can be compute iteratively by
n
L( 0 ) Ci
i 1
( m 1)
L
L( m )
Ci
i 1 Ti
n
Test loading factor at deadline instants that are less than L
9
EDF Scheduling Example
L0=7, L1=9, L2=11, L3=14,
L4=16
the set of points to be
tested: D={4,5,7,10,13,16}
Task(i)
Period
1
2
3
6
2
4
8
2
5
9
3
7
t
h
u
4
2
0.5
5
4
0.8
7
7
1
10
9
0.9
13
11
0.85
16
16
1
WCET Deadline
10
Example of EDF Schedule
A digital robot with EDF schedule
control loop: ec 8ms at 100Hz
BIST: eb 50ms
8 50
given
u c ub 1
10 pb
BIST can be done every 250ms
Add a telemetry task to send and receive messages with et
15ms
if BIST is done every 1000ms
given
u c ub
8
50 15
1
10 1000 Dt
the telemetry task can have a relative deadline of 100ms
sending or receiving must be separated at least 100ms
11
Rate-Monotonic Algorithm
A base case: no additional overhead, simple periodic tasks
with pi =Di
Assign priorities according their periods
Ti has a higher priority that Tk if i < k ( pi < pk )
Is RM optimal? if there is a feasible fixed-priority schedule, then RM
is feasible
How do we know RM is feasible schedulability test
Results:
RM is optimal if pi Di
sufficient condition utilization test
n
U
i 1
ei
n(21/ n 1)
pi
a complete test what is the worst response time given all possible
arrivals and preemptions
12
Critical Instant
Critical instant of Ti: a job of Ti arriving at the instant has a
maximum response time
If we can find the critical instant of Ti, then
check whether all jobs of Ti meet their deadlines
let’s increase ei until the maximum response time = Di
schedulable utilization
In-phase instant is critical: all higher priority tasks are released
at the same instant of Ji,c (assume all jobs are completed before
the next job of the same task is released.)
which T2 has the maximum response time
T1
T2
T1, T2
T2
T1
13
Schedulability Test: Time-Demand Analysis
Consider in-phase instant only
If Ji is done at t, then the total work must be done in [0,t] is
(from Ji and all higher priority tasks)
t
w i (t ) ei ek
k 1 pk
i 1
t
w(t)
Can we find a t Di such that
wi(t) t
cannot check all t [0, Di]
check all arrival instants and Di
The completion time of Ji satisfies
t
t ei ek
k 1 pk
i 1
time
Di
14
Schedulability Test
EDF has a schedulable utilization of 1, how about RMS
If Di=pi, the schedulable utilization exists
if U n ( 21/n - 1 ), done
else do time-demand analysis
if Di < pi, do time-demand analysis
if Di > pi, there may be more than one jobs of task i in the
system
examine all jobs of task i in a level-i busy interval (in-phase)
the following equations represent:
t
w i , j (t ) j ei ek
k 1 pk
i 1
for ( j 1)pi t w i , j (t )
t w i , j (t ( j 1)pi ) ( j 1)pi
15
Schedulable Utilization of RMS
Must be less than 1
Let’s consider two tasks and deadline=period
T2 can only be executed when T1 is not in the system
Let p2 < 2p1. What is the maximum schedulable e2
If p2 < p1+e1, max(e2)=p1-e1
Else, max(e2)=p2-2e1
U=e1/p1+(p1-e1)/p2
U=e1/p1+(p2-2e1)/p2
p2
maximal e2
p2
T1
T1
0
p1
T1
2p1
16
Schedulable Utilization of RMS
Given e1, p1, and p2, plot U
The minimum U occurs when
p2=p1+e1
where
U= e1/p1+(p1-e1)/(p1+e1)
U
1
p2=p1
2p1
What is the minimum U
take the derivative wrt to p1 and set dU/dp1=0
we will get e1=(21/2-1)p1 and U=0.828…
17
Schedulable Utilization of RMA
U n ( 21/n - 1 )
Is there a case that is feasible and gives the minimal
schedulable utilization
When pn 2 p1
processor must be busy in [0,pn]
become unscheduable if increase ei
processor will be idle if increase pi
T1
T2
T3
T4
T5
p5
18
Schedulable Utilization of RMA
What do we have from the timeline diagram
ek = pk+1 - pk for k=1,2,..,n-1
en = pn - 2(e1 + e2 + . . . . + en-1 ) =2p1 - pn
U (
p
p2
p
2p
1) ( 3 1) .... ( n 1) ( 1 1)
p1
p2
pn 1
pn
q2,1 q3,2 ..... qn,n 1
2
n
q2,1q3,2 ..... qn,n 1
Can we increase e1 and decrease ek by the same amount
still schedulable for the 1st arrival of all tasks
utilization is higher
Can we decrease e1 and increase ek
When will U be minimum
----- when q2,1=q3,2= . . . = 2/n
19
Schedulable Utilization of RMA
When pn > 2pk and schedulable
construct a new task set that is schedulable and pn > 2pk
the original set has a higher utilization
Tk
lpk
Tn
Tk
Tn
pn
20
Schedulability: RT Test
Theorem: for a set of independent, periodic tasks, if each
task meets its first deadline, with worst-case task
phasing, the deadline will always be met.
Response Time (RT) test: let an = response time of task i.
an may be computed by the following iterative formula:
an
ei e j
j 1 p j
i 1
an 1
i
where a0 e j
j 1
Test Terminates when an+1 = an
Task i is schedulable if its response time is before its
deadline: an ≤ pi
21
Sample Problem: UB Test
e
p
U
Task 1
20
100
0.200
Task 2
40
150
0.267
Task 3
100
350
0.286
Total utilization is
.200 + .267 + .286 = .753 < U(3) =.779
The periodic tasks in the sample problem are
schedulable according to the UB test.
22
Example: Applying RT Test (1)
If we increase the compute time of ז1 from 20 to 40; is
the task set still schedulable?
Utilization for the first task : 40/100=0.4 < U(1)
Utilization of first two tasks: 0.667 < U(2) = 0.828
First two tasks are schedulable by UB test
Utilization of all three tasks: 0.953 > U(3) = 0.779
UB test is inconclusive
Need to apply RT test
23
Example: Applying RT Test (2)
Use RT test to determine if ז3 meets its first
deadline:
i=3
3
a0 e j e1 e2 e3 40 40 100 180
j 1
2
a0
a0
a1 ei e j e3 e j
j 1 p j
j 1 p j
180
180
100
( 40 )
( 40 ) 100 80 80 260
100
150
i 1
24
Example: Applying RT Test (3)
a1
260
260
a2 ei e j 100
( 40 )
( 40 ) 300
100
150
j 1 p j
i 1
a2
300
300
a3 ei e j 100
( 40 )
( 40 ) 300
100
150
j 1 p j
i 1
a3 = a2 = 300
Done!
Task is schedulable using RT test.
a3 = 300 < p3 = 350
25
Modeling Task Switching
Ui
ei 2S
pi
C1
0
1
100
C1
2
C1
C1
C1 C1
200
C1
C1
C2
C1
C2
C1
S
e2
S
C2
3
S
40
e1
S
S
40
time
p1
p2
2p1
Two scheduling actions per task
(start of period and end of period)
26
Schedulability with Interrupts
Interrupt processing can be inconsistent with rate
monotonic priority assignment.
interrupt handler executes with high priority despite its period
interrupt processing may delay execution of tasks with shorter
periods
Effects of interrupt processing must be taken into
account in schedulability model.
Task(i)
Period(p)
WCET(e)
Priority
Deadline(D)
3
1
2
4
200
60
HW
200
100
20
High
100
150
40
Medium
150
350
40
Low
350
27
UB Test with ANY FIXED PRIORITY
Test is applied to each task.
Determine effective utilization (fi) of each task i using
when di=pi
fi =
Preemption form the
tasks that can hit more
than once (with period
less that pi)
e j ei
1
pi pi
jHn p j
Execution of a
task under test
e
k
kH1
Preemption from tasks
That can hit only once
(with period greater than
pi )
Compare effective utilization against bound, U(n).
n = num(Hn) + 1
num(Hn) = the number of tasks in the set Hn
28
UB Test with Interrupt Priority
Test is applied to each task.
Determine effective utilization (fi) of each task i using
when di<pi (ei must be done within di, not pi)
fi =
Preemption form the
tasks that can hit more
than once (with period
less that di)
jH n
ej
ei
1
p j di di
Execution of a
task under test
e
kH1
k
Preemption from tasks
That can hit only once
(with period greater than
di )
Compare effective utilization against bound, U(n).
n = num(Hn) + 1
num(Hn) = the number of tasks in the set Hn
29
UB Test with Interrupt Priority: 3
For 3, no tasks have a higher priority:
H = Hn =H1 = { }.
f3 =
0
e3
0 U(1 )
p3
Note that utilization bound is U(1): num(Hn) = 0.
e3
60
f3 = p 200 0.3 1.0
3
30
UB Test with Interrupt Priority: 1
For 1, 3 has a higher priority: H = {3}; Hn = {};
H1 = {3}.
f1 = 0
e1 1
ek U(1 )
p1 p1 k 3
Note that utilization bound is U(1): num(Hn) = 0.
e1 e3
20
60
0.800 1.0
f1 =
p1 p1 100 100
31
UB Test with Interrupt Priority: 2
For 2
: H={1, 3}; Hn={1 }; H1={3 };
ej
e
1
f2
2
p2 p2
j 1 p j
e
k
U( 2 )
k 3
Note that utilization bound is U(2): num(Hn) = 1.
f2
e1 e2 e3
20
40
60
0.867 0.828
p1 p2 p3 100 150 150
32
UB Test with Interrupt Priority:
For 4
: H={1, 2, 3}; Hn={1 , 2, 3 }; H1={};
f4
ej
e4
0 U( 4 )
p4
j 1 ,2 ,3 p j
Note that utilization bound is U(4): num(Hn) = 3.
e1 e2
e3
e4
f4
p1 p2
p3
p4
20
40
60
60
0.882 0.756
100 150 200 350
33
Is There a RT Analysis for EDF
Does a critical instant exist?
releasing task instance i at the start of the busy period may
not lead to its worst-case response time.
i arrives at a with deadline d, is finished in t2
t1 the last time no pending
instances with arrival time
earlier than ti and deadline
≤d
[t1, t2) –the busy period of
instances with deadlines ≤
d
“shift left” all instances of
other tasks to start at t1
increase busy period
34
RT Analysis for EDF (1)
Deadline busy period where WCET happens:
only tasks with deadlines less than and equal to d get
executed
started at 0 for the instance of i arrived at a: Li(a)
higher priority workload
Li (a )
a Di D j
Wi (a, Li (a )) min(
,1
)C j
Tj
j i , D j a Di
Tj
Then, an iterative formula for Li(a)
L(i 0) (a )
0
L(i m 1) (a )
Wi (a, L(i m ) (a )) (1
The response time is:
rti (a ) max{Ci , Li (a ) a}
a
T )Ci
i
rti max a 0 {rti (a )}
35
RT Analysis for EDT (2)
Choice of “a”:
Li(a) > a (arrives before deadline busy period ends)
a+Di coincides with the absolute deadlines of other tasks
in the interval [0, L-Ci), L is the busy period of synchronous
arrivals
n
a A ( {kT j D j Di : k 0}) {0, L}
j 1, j i
36
Summary of Feasibility Analysis (1)
A set of tasks {Ci, Di, Ti,, i}
Dynamic priority -- EDF is optimal
Di ≥ Ti -- utilization bound on slide #4 (iff)
Di < Ti -- all loading factor less than 1 on slide 7 (iff)
Synchronous or Sporadic – busy period analysis and testing
algorithm on slide #9 (iff)
Asynchronous – if the cooresponding synchronous task set is
schedulable.
worst case execution time – slide #34
necessary condition: U ≤ 1
sufficient condition: ∑(Ci / min{Di , Ti }) ≤ 1
37
Summary of Feasibility Analysis (2)
Static priority
Rate monotonic – optimal if Di ≥ Ti
Deadline monotonic – optimal if Di < Ti
Necessary condition: U ≤ 1
Synchronous
Sufficient condition
RM and DM -- ∑(Ci / min{Di , Ti }) ≤ n(21/n-1 ) (slide #12)
fixed priorities – effective utilization for each task ≤ n(21/n-1 ) (slide
#28)
worst case response time (i.e. 1st arrival) ≤ Di (slide #21) (iff)
Asynchronous
the conditions for synchronous case are sufficient
38
Project outline submissions
5 late submissions; one on March 31
One submitted as assignment 3
RTOS for
Real-time
AFDX
RTSJ Scheduling
Toyota
Real-time
automotive Communication Avionics
and
for
Others
UA
Hypervisor
Systems
on CAN bus Network
SCJ
multicore
8
5
8
2
16
9
12
3