View
46
Download
0
Category
Preview:
DESCRIPTION
CSE 522 Real-Time Scheduling (2) . Computer Science & Engineering Department Arizona State University Tempe, AZ 85287 Dr. Yann -Hang Lee yhlee@asu.edu (480) 727-7507. Priority-Driven Scheduling of Periodic Tasks. Why priority-driven scheduling use priority to represent urgency - PowerPoint PPT Presentation
Citation preview
1
CSE 522 Real-Time Scheduling (2)
Computer Science & Engineering DepartmentArizona State University
Tempe, AZ 85287
Dr. Yann-Hang Leeyhlee@asu.edu(480) 727-7507
2
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
3
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
4
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
Proof the only-if part is obvious the if part --- show if there is a job misses its deadline, then U > 1
11
n
i i
i
peU
5
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
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]
Ji,c is released Ji,c misses its deadline0 tr
A BC
D
tUpe
pete
pt
pett
ik k
k
i
ik
ik k
k
i
ii
)()()(
6
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
7
General EDF Feasibility Analysis
Processor demand: all processing request during a period [ti, t2), i.e.,
Loading factor:
Each set of real-time jobs is feasibly scheduled by EDF iff
How to compute loading factor?
21
21,
),[tdrt
kttkk
Ch
12
),[),[
21
21 tth
u tttt
1sup ),[0
2121
tttt
uu
8
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
Need to show that
Hybrid task sets (with both periodic and sporadic task) are schedulable under EDF if
1uu
),0[12
),[ 12
12
21)1( tti
ttD i
itt hC
TDtth
i
1,min1
n
i ii
i
TDC
9
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
Test loading factor at deadline instants that are less than L
i
n
i i
mm
n
ii
CT
LL
CL
1
)()1(
1
)0(
10
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 WCET Deadline
1 6 2 4
2 8 2 5
3 9 3 7
t h u4 2 0.55 4 0.87 7 110 9 0.913 11 0.8516 16 1
11
A digital robot with EDF schedule control loop: ec 8ms at 100Hz BIST: eb 50ms given
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
the telemetry task can have a relative deadline of 100ms sending or receiving must be separated at least 100ms
150108
b
bc puu
115100050
108
t
bc Duu
Example of EDF Schedule
12
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
a complete test what is the worst response time given all possible arrivals and preemptions
)12( /1
1
nn
i i
i npeU
13
T1 T2 T1, T2 T2 T1
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
14
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)
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
k
i
k kii e
ptetw )(
1
1
k
i
k ki e
ptet
1
1
tw(t)
time Di
15
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:
)()1( for )( ,
1
1, twtpje
ptejtw jiik
i
k kiji
iiji pjpjtwt )1())1((,
16
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 U=e1/p1+(p1-e1)/p2
Else, max(e2)=p2-2e1 U=e1/p1+(p2-2e1)/p2
T1 T1 T1
0 p1 2p1
p2
p2maximal e2
17
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)
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…
p2=p1 2p1
U
1
18
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
19
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
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
nqqq
qqq
pp
pp
pp
ppU
nnnn
nn
n
1,2,31,21,2,31,2
1
12
3
1
2
.....2.....
)12()1(....)1()1(
Schedulable Utilization of RMA
20
Tk
Tn
Tk
Tn
pn
lpk
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
21
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:
Test Terminates when an+1 = an Task i is schedulable if its response time is before its
deadline: an ≤ pi
i
1jj0j
1i
1j j
ni1n ea where e
paea
22
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.
23
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
24
Example: Applying RT Test (2)
Use RT test to determine if 3ז meets its first deadline: i = 3
2608080100)40(150180)40(
100180100
epaee
paea
1801004040eeeea
j
2
1j j
03j
1i
1j j
0i1
321
3
1jj0
25
Example: Applying RT Test (3)
a3 = a2 = 300 Done!
Task is schedulable using RT test. a3 = 300 < p3 = 350
300)40(150300)40(
100300100e
paea
300)40(150260)40(
100260100e
paea
j
1i
1j j
2i3
j
1i
1j j
1i2
26
Modeling Task Switching
C1
S
C1
C2
C1
C2
1
2
3
C1
40 40
0 100 200
C1C1 C1
e1 S
C2C1 C1
C1
S e2 S S
timep1 p2 2p1
i
ii p
S2eU
Two scheduling actions per task(start of period and end of period)
27
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 200 60 HW 200
1 100 20 High 100
2 150 40 Medium 150
4 350 40 Low 350
28
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 =
q Compare effective utilization against bound, U(n).n = num(Hn) + 1
num(Hn) = the number of tasks in the set Hn
1n Hk
kii
i
Hj j
j ep1
pe
pe
Preemption form the tasks that can hit more than once (with period less that pi)
Execution of a task under test
Preemption from tasks That can hit only once(with period greater than pi )
29
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 =
q Compare effective utilization against bound, U(n).n = num(Hn) + 1
num(Hn) = the number of tasks in the set Hn
1
1Hk
kii
i
Hj j
j edd
epe
n
Preemption form the tasks that can hit more than once (with period less that di)
Execution of a task under test
Preemption from tasks That can hit only once(with period greater than di )
30
UB Test with Interrupt Priority: 3
For 3, no tasks have a higher priority: H = Hn =H1 = { }.
f3 =
Note that utilization bound is U(1): num(Hn) = 0.
)1(U0pe0
3
3
f3 = 0.13.020060
pe
3
3
31
UB Test with Interrupt Priority: 1
For 1, 3 has a higher priority: H = {3}; Hn = {}; H1 = {3}.
f1 = )1(Uep1
pe0
3kk
11
1
Note that utilization bound is U(1): num(Hn) = 0.
f1 = 0.1800.010060
10020
pe
pe
1
3
1
1
32
UB Test with Interrupt Priority: 2
For 2 : H={1, 3}; Hn={1 }; H1={3 };
Note that utilization bound is U(2): num(Hn) = 1.
)2(Uep1
pe
pe
f3k
k22
2
1j j
j2
828.0867.015060
15040
10020
pe
pe
pef
3
3
2
2
1
12
33
UB Test with Interrupt Priority:
For 4 : H={1, 2, 3}; Hn={1 , 2, 3 }; H1={};
Note that utilization bound is U(4): num(Hn) = 3.
)4(U0pe
pe
f4
4
3,2,1j j
j4
756.0882.035060
20060
15040
10020
pe
pe
pe
pef
4
4
3
3
2
2
1
14
34
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
35
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
Then, an iterative formula for Li(a)
The response time is:
jj
ji
DaDij j
iii C
TDDa
TaLaLaW
ij
)1,)(min())(,(,
ii
mii
mi C
TaaLaWaL )1())(,()( )()1(
})(,max{)( aaLCart iii
0)()0( aLi
)}({max 0 artrt iai
36
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
},0{})0:{(,1
LkDDkTAa ijj
n
ijj
37
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
38
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
Toyota UA
RTOS for automotive Systems
Real-time Communication
on CAN bus
AFDX Avionics Network
Real-time Hypervisor
RTSJ and SCJ
Scheduling for
multicoreOthers
8 5 8 2 16 9 12 3
Project outline submissions
5 late submissions; one on March 31 One submitted as assignment 3
Recommended