10.02.2013 Views

Scheduling Aperiodic and Sporadic Jobs in Priority- Driven Systems

Scheduling Aperiodic and Sporadic Jobs in Priority- Driven Systems

Scheduling Aperiodic and Sporadic Jobs in Priority- Driven Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Schedul<strong>in</strong>g</strong> <strong>Aperiodic</strong> <strong>and</strong><br />

<strong>Sporadic</strong> <strong>Jobs</strong> <strong>in</strong> <strong>Priority</strong>-<br />

<strong>Driven</strong> <strong>Systems</strong><br />

Outl<strong>in</strong>e<br />

Liu: Chapter 7<br />

Ingo S<strong>and</strong>er<br />

<strong>in</strong>go@kth.se<br />

IL2212 Embedded Software 1<br />

l� System Model <strong>and</strong> Assumptions<br />

l� <strong>Schedul<strong>in</strong>g</strong> <strong>Aperiodic</strong> <strong>Jobs</strong><br />

l� <strong>Schedul<strong>in</strong>g</strong> <strong>Sporadic</strong> <strong>Jobs</strong><br />

IL2212 Embedded Software 2<br />

1


Assumptions<br />

l� S<strong>in</strong>gle Processor<br />

l� Independent preemptable periodic tasks<br />

l� Parameters of all periodic tasks are known<br />

l� Periodic tasks meet their deadl<strong>in</strong>es<br />

l� <strong>Aperiodic</strong> <strong>and</strong> sporadic jobs are <strong>in</strong>dependent<br />

of each other<br />

l� Parameters of sporadic jobs become known<br />

after release<br />

System Model<br />

Rejected <strong>Jobs</strong><br />

<strong>Sporadic</strong><br />

<strong>Jobs</strong><br />

<strong>Aperiodic</strong><br />

<strong>Jobs</strong><br />

Periodic<br />

<strong>Jobs</strong><br />

Acceptance<br />

Test<br />

IL2212 Embedded Software 3<br />

In each queue jobs are sorted<br />

based on priority<br />

Processor<br />

IL2212 Embedded Software 4<br />

2


<strong>Schedul<strong>in</strong>g</strong> Algorithms<br />

l� <strong>Aperiodic</strong> jobs<br />

l� are always accepted<br />

l� Scheduler tries to complete aperiodic jobs as<br />

soon as possible<br />

<strong>Schedul<strong>in</strong>g</strong> Algorithms<br />

l� <strong>Sporadic</strong> jobs<br />

IL2212 Embedded Software 5<br />

l� Scheduler decides, if job can be accepted or must<br />

be rejected<br />

l� Job is accepted <strong>and</strong> scheduled, if all other scheduled<br />

jobs still meet their deadl<strong>in</strong>es<br />

l� Otherwise job is rejected<br />

IL2212 Embedded Software 6<br />

3


<strong>Schedul<strong>in</strong>g</strong> Algorithm<br />

l� A schedul<strong>in</strong>g algorithm is correct, if it only<br />

produces correct schedules of the system<br />

l� A correct schedule is a schedule where<br />

periodic tasks <strong>and</strong> accepted sporadic tasks<br />

always meet their deadl<strong>in</strong>es<br />

IL2212 Embedded Software 7<br />

Optimality of Algorithms<br />

l� An aperiodic job schedul<strong>in</strong>g algorithm is<br />

optimal if it m<strong>in</strong>imizes either<br />

l� the response time of the aperiodic job at the head<br />

of the aperiodic job queue, or<br />

l� the average response time of all the aperiodic<br />

jobs for the given queue<strong>in</strong>g discipl<strong>in</strong>e<br />

IL2212 Embedded Software 8<br />

4


Optimality of Algorithms<br />

l� A sporadic job schedul<strong>in</strong>g algorithm is<br />

optimal, if it<br />

l� accepts each sporadic job newly offered to the<br />

system <strong>and</strong> schedules the job to complete <strong>in</strong> time<br />

if <strong>and</strong> only if the new job can be correctly<br />

scheduled <strong>in</strong> time by some means<br />

IL2212 Embedded Software 9<br />

<strong>Schedul<strong>in</strong>g</strong> <strong>Aperiodic</strong> <strong>Jobs</strong><br />

l� In the follow<strong>in</strong>g several different algorithms to<br />

schedule aperiodic jobs are discussed<br />

l� Assumption here:<br />

l� No sporadic jobs<br />

IL2212 Embedded Software 10<br />

5


Background Execution<br />

l� <strong>Aperiodic</strong> jobs are only scheduled <strong>and</strong><br />

executed at times, when there is no periodic<br />

or sporadic job ready for execution<br />

Background Execution<br />

T 1<br />

T 2<br />

0 3 6 9<br />

0 3 6 9<br />

Background A<br />

A<br />

0.1<br />

0.8<br />

IL2212 Embedded Software 11<br />

T 1 = (3,1), T 2 = (10,4)<br />

IL2212 Embedded Software 12<br />

6


Background Execution<br />

l� Advantage: simple algorithm<br />

l� Disadvantage: aperiodic jobs are often<br />

executed very late<br />

l� Possible improvement: slack steal<strong>in</strong>g (as<br />

shown <strong>in</strong> chapter 5 for clock-driven systems)<br />

l� slack steal<strong>in</strong>g can greatly improve the<br />

performance, but is much more complex <strong>in</strong><br />

priority-driven systems<br />

Periodic Server<br />

IL2212 Embedded Software 13<br />

l� A task that behaves more or less like a<br />

periodic task <strong>and</strong> is created to execute<br />

aperiodic jobs is called a periodic server<br />

l� A periodic server is def<strong>in</strong>ed partially by<br />

execution time e S <strong>and</strong> period p S<br />

l� The parameter e S is the execution budget of<br />

the server<br />

l� The ratio u S = e S / p S is the size of the server<br />

IL2212 Embedded Software 14<br />

7


Periodic Server<br />

l� When the server is scheduled <strong>and</strong> executes<br />

aperiodic jobs, it consumes its budget at the<br />

rate of 1 per time unit<br />

l� The budget is exhausted, when it reaches 0<br />

l� A time <strong>in</strong>stant when the budget is replenished<br />

(reloaded) is called replenishment time<br />

Periodic Server<br />

IL2212 Embedded Software 15<br />

l� A periodic server is backlogged whenever the<br />

aperiodic job queue is non-empty<br />

l� It is idle when the queue is empty<br />

l� The server is eligible for execution only when<br />

it is backlogged <strong>and</strong> has non-zero budget<br />

IL2212 Embedded Software 16<br />

8


Poll<strong>in</strong>g Server<br />

l� A poll<strong>in</strong>g server (p s , e s ) is a periodic server<br />

l� When executed, it executes an aperiodic job,<br />

if the aperiodic job queue is non-empty<br />

l� Poller suspends execution or is suspended<br />

by the scheduler either<br />

l� when it has executed for e s , or<br />

l� when the aperiodic job queue becomes empty<br />

Poll<strong>in</strong>g Server<br />

l� Consumption Rules<br />

IL2212 Embedded Software 17<br />

l� The budget is immediately consumed when the<br />

server is not scheduled<br />

l� Replenishment Rules<br />

l� The budget is replenished to e s at the beg<strong>in</strong>n<strong>in</strong>g of<br />

each period<br />

l� Example: Liu, Figure 7.2b, p.193<br />

IL2212 Embedded Software 18<br />

9


Poll<strong>in</strong>g Server<br />

T 1 = (3,1), T 2 = (10,4), Poller =(2.5, 0.5)<br />

Poller<br />

T 1<br />

T 2<br />

0 2.5 5.3<br />

9<br />

0 3 6 9<br />

0 3 6 9<br />

A<br />

0.1<br />

0.8<br />

Poll<strong>in</strong>g Server<br />

IL2212 Embedded Software 19<br />

l� <strong>Aperiodic</strong> jobs that arrive after the release<br />

time of the poller must wait until next poll<strong>in</strong>g<br />

period<br />

l� Execution budget is not preserved<br />

l� Simple to prove correctness<br />

IL2212 Embedded Software 20<br />

10


B<strong>and</strong>width-Preserv<strong>in</strong>g Servers<br />

l� A b<strong>and</strong>width-preserv<strong>in</strong>g server is a periodic<br />

server<br />

l� Compared to poll<strong>in</strong>g server b<strong>and</strong>width<br />

preserv<strong>in</strong>g servers try to preserve their<br />

budget when they are not executed<br />

l� Additional rules for consumption <strong>and</strong><br />

replenishment<br />

IL2212 Embedded Software 21<br />

B<strong>and</strong>width-Preserv<strong>in</strong>g Servers<br />

l� A backlogged b<strong>and</strong>width-preserv<strong>in</strong>g server is<br />

ready for execution when it has budget<br />

l� Scheduler keeps track of the consumption of<br />

the server budget<br />

l� If budget is exhausted server becomes idle<br />

IL2212 Embedded Software 22<br />

11


B<strong>and</strong>width-Preserv<strong>in</strong>g Servers<br />

l� Scheduler moves server back to ready<br />

queue, when budget is replenished <strong>and</strong><br />

server is backlogged<br />

l� If a new aperiodic job arrives an idle server<br />

becomes backlogged <strong>and</strong> is put <strong>in</strong>to the<br />

ready queue when it has budget<br />

Deferrable Server<br />

IL2212 Embedded Software 23<br />

l� Simplest b<strong>and</strong>width preserv<strong>in</strong>g server<br />

l� Consumption rule<br />

l� The execution budget of the server is consumed<br />

at the rate of one unit per time whenever the<br />

server executes<br />

l� Replenishment rule<br />

l� The execution budget of the server is set to e s at<br />

multiples of its period<br />

l� Server is not allowed to cumulate budget<br />

from period to period<br />

IL2212 Embedded Software 24<br />

12


Deferrable Server (RMS)<br />

T DS = (3,1), T 1 = (2,3.5,1.5), T 2 =(6.5, 0.5)<br />

T DS<br />

T 2<br />

0 2.8 5.3<br />

9<br />

T 1<br />

2 3 6 9<br />

0 3 6 9<br />

1.7<br />

Budget<br />

1.0<br />

0.5<br />

2.8<br />

A<br />

IL2212 Embedded Software 25<br />

Schedulability of Deferrable<br />

Servers<br />

l� Time Dem<strong>and</strong> Analysis can be used to determ<strong>in</strong>e<br />

whether all jobs rema<strong>in</strong> schedulable <strong>in</strong> the presence<br />

of a deferrable server<br />

l� Time Dem<strong>and</strong> Function (if deferred server has<br />

highest priority)<br />

Block<strong>in</strong>g<br />

Server<br />

IL2212 Embedded Software 26<br />

13


Deferrable Server<br />

Time Dem<strong>and</strong> Analysis<br />

Time Dem<strong>and</strong><br />

6<br />

5<br />

4<br />

3<br />

2<br />

1<br />

0<br />

T DS = (3,1), T 1 = (2,3.5,1.5), T 2 =(6.5, 0.5)<br />

w 1 (t)<br />

w 2 (t)<br />

y(t) = t<br />

1 2 3 4 5 6 7 8<br />

Deferrable Server<br />

Time<br />

IL2212 Embedded Software 27<br />

Schedulability of Deferrable<br />

Servers<br />

l� There is no known schedulability utilization<br />

that ensures the schedulability of a fixedpriority<br />

system <strong>in</strong> which a deferrable server is<br />

scheduled at an arbitrary priority<br />

l� Some special cases are discussed <strong>in</strong> the<br />

book (Liu p.201)<br />

IL2212 Embedded Software 28<br />

14


Limitations of Deferrable<br />

Servers<br />

l� Deferrable servers may be scheduled longer<br />

than its execution time <strong>in</strong> a time <strong>in</strong>terval as<br />

long as its period<br />

l� Lower priority task may be delayed longer by<br />

a deferrable server than by a periodic task<br />

with same period <strong>and</strong> execution time<br />

Deferrable server does not behave as a periodic task<br />

<strong>Sporadic</strong> Server<br />

l� B<strong>and</strong>width preserv<strong>in</strong>g server<br />

IL2212 Embedded Software 29<br />

l� More complex consumption <strong>and</strong><br />

replenishment rules ensure that each<br />

sporadic server with period p s <strong>and</strong> budget e s<br />

never dem<strong>and</strong>s more processor time than the<br />

periodic task (p s , e s ) <strong>in</strong> any time <strong>in</strong>terval<br />

IL2212 Embedded Software 30<br />

15


A simple Fixed-<strong>Priority</strong><br />

<strong>Sporadic</strong> Server<br />

l� Def<strong>in</strong>itions (Liu p.205)<br />

l� t r denotes the latest actual replenishment time<br />

l� t f denotes the first <strong>in</strong>stant after t r at which the<br />

server beg<strong>in</strong>s to execute<br />

l� t e denotes the latest effective replenishment time<br />

A simple Fixed-<strong>Priority</strong><br />

<strong>Sporadic</strong> Server<br />

l� Def<strong>in</strong>itions (Liu p.205)<br />

IL2212 Embedded Software 31<br />

l� At any time t, BEGIN is the beg<strong>in</strong>n<strong>in</strong>g <strong>in</strong>stant of the earliest<br />

busy <strong>in</strong>terval among the latest contiguous sequence of<br />

busy <strong>in</strong>tervals of the higher priority subsystem T H that<br />

started before t<br />

l� END is the end of the latest busy <strong>in</strong>terval <strong>in</strong> the above<br />

def<strong>in</strong>ed sequence if this <strong>in</strong>terval ends before t <strong>and</strong> equal to<br />

its <strong>in</strong>f<strong>in</strong>ity if the <strong>in</strong>terval ends after t<br />

l� Server Busy Interval: Beg<strong>in</strong>s when an aperiodic job<br />

arrives at an empty aperiodic job queue <strong>and</strong> ends<br />

when the queue becomes empty aga<strong>in</strong><br />

IL2212 Embedded Software 32<br />

16


Fixed-<strong>Priority</strong> Simple <strong>Sporadic</strong><br />

Server<br />

l� Consumption Rules (Liu p.206)<br />

l� At any time t after t r , the server’s execution budget<br />

is consumed at the rate of 1 per unit time until the<br />

budget is exhausted when either one of the<br />

follow<strong>in</strong>g to conditions are true. When these<br />

conditions are not true, the server holds its budget<br />

l� C1 The server is execut<strong>in</strong>g<br />

l� C2 The server has executed s<strong>in</strong>ce t r <strong>and</strong> END < t<br />

IL2212 Embedded Software 33<br />

Fixed-<strong>Priority</strong> Simple <strong>Sporadic</strong><br />

Server<br />

l� Replenishment Rules (Liu p.206)<br />

l� R1 Initially when the system beg<strong>in</strong>s execution<br />

<strong>and</strong> each time when the budget is replenished,<br />

the execution budget = e s , <strong>and</strong> t r = the current<br />

time<br />

l� R2 At time t f , if END = t f , t e = max(t r , BEGIN). If<br />

END < t f , t e = t f . The next replenishment time is<br />

set at t e + p s<br />

IL2212 Embedded Software 34<br />

17


Fixed-<strong>Priority</strong> Simple <strong>Sporadic</strong><br />

Server<br />

l� Replenishment Rules (Liu p.206)<br />

l� R3 The next replenishment occurs at the next<br />

replenishment time, except under the follow<strong>in</strong>g<br />

conditions. Under these conditions,<br />

replenishment is done at times stated below<br />

a) If the next replenishment time t e + p s is earlier than t f ,<br />

the budget is replenished as soon as it is exhausted<br />

b) If the system T becomes idle before the next<br />

replenishment time t e + p s <strong>and</strong> becomes busy aga<strong>in</strong> at<br />

t b , the budget is replenished at m<strong>in</strong>(t e + p s , t b )<br />

IL2212 Embedded Software 35<br />

Simple Fixed-<strong>Priority</strong> <strong>Sporadic</strong><br />

Server<br />

l� Example: Liu, Figure 7-8, p.207<br />

IL2212 Embedded Software 36<br />

18


T 1<br />

T 2<br />

T S<br />

Simple Fixed-<strong>Priority</strong> <strong>Sporadic</strong><br />

Server - Example<br />

T3 0 3 6 9 12 15 18 21 24<br />

1.0<br />

2.0<br />

2.0<br />

Budget<br />

1.5<br />

1.0<br />

0.5<br />

3<br />

T 1 = (3,0.5), T 2 = (4,1), T 3 = (19,4.5) T S =(5, 1.5)<br />

A1<br />

C1<br />

C1<br />

C2<br />

7<br />

A2<br />

C1<br />

C1<br />

C2<br />

0 3 6 9 12 15 18 21 24<br />

15.5<br />

C1<br />

C1<br />

A3<br />

IL2212 Embedded Software 37<br />

Simple Fixed-<strong>Priority</strong> <strong>Sporadic</strong><br />

Server - Example<br />

t t r t f t e BEGIN END<br />

3.5 0 3.5 3 3 3.5 R2: t e = max(0,3.0)<br />

=> t r + = te + t s = 8.0<br />

3.5<br />

5.0<br />

IL2212 Embedded Software 38<br />

C1<br />

C2<br />

C2<br />

C1: Server executes<br />

C2: Queue Empty, higher<br />

priority jobs idle<br />

8 R3: Replenishment<br />

9.5 8 9.5 3 8 9.5 R2: t e = max(8,8)<br />

=> t r + = te + t s = 13.0<br />

19


Simple Fixed-<strong>Priority</strong> <strong>Sporadic</strong><br />

Server - Example<br />

t t r t f t e BEGIN END<br />

13.5 13 13.5 13 12 13.5 R2: t e = max(13,12)<br />

=> t r + = te + t s = 18.0<br />

13.5 System T idle!<br />

R3b: t r + = m<strong>in</strong>(te + p s , t b )= 15.0,<br />

s<strong>in</strong>ce system (T 1 ) becomes<br />

busy at 15<br />

15.5 15 15.5 15 15.5 R2: t e = max(15,15)<br />

=> t r + = te + t s = 20.0<br />

18.5 System T idle!<br />

R3b: t r + = m<strong>in</strong>(te + p s , t b )= 19.0,<br />

s<strong>in</strong>ce system (T 3 ) becomes<br />

busy at 19<br />

IL2212 Embedded Software 39<br />

Fixed-<strong>Priority</strong> <strong>Sporadic</strong> Server<br />

l� <strong>Sporadic</strong> server is more complex than poll<strong>in</strong>g or<br />

deferrable servers due to more complex<br />

consumption <strong>and</strong> replenishment rules<br />

l� Ma<strong>in</strong> advantage: schedulability easy to demonstrate<br />

l� A sporadic server can be treated like a periodic task<br />

when we check for schedulability<br />

l� System with sporadic server may be schedulable<br />

while the correspond<strong>in</strong>g deferrable server is not<br />

l� More complex sporadic servers exist (Liu: 7.3.2)<br />

IL2212 Embedded Software 40<br />

20


<strong>Sporadic</strong> Dynamic-<strong>Priority</strong><br />

Servers<br />

l� <strong>Sporadic</strong> servers can also be used for<br />

dynamic-priority (deadl<strong>in</strong>e-driven) systems<br />

l� Rules have to be adapted to EDF or LST<br />

l� Also here sporadic server can be treated as<br />

normal task for schedulability analysis<br />

IL2212 Embedded Software 41<br />

Other B<strong>and</strong>width Preserv<strong>in</strong>g<br />

Servers<br />

l� Other b<strong>and</strong>width preserver algorithms are<br />

based on general processor shar<strong>in</strong>g (GPS)<br />

algorithms (deadl<strong>in</strong>e-driven algorithms)<br />

l� Examples:<br />

l� Constant utilization server<br />

l� Total b<strong>and</strong>width server<br />

l� Weighted round-rob<strong>in</strong> server<br />

l� Exact functionality not discussed <strong>in</strong> course,<br />

<strong>in</strong>stead see Liu: 7.4<br />

IL2212 Embedded Software 42<br />

21


<strong>Schedul<strong>in</strong>g</strong> <strong>Sporadic</strong> <strong>Jobs</strong><br />

l� <strong>Sporadic</strong> jobs<br />

l� Scheduler decides, if job can be accepted or must<br />

be rejected<br />

l� Job is accepted <strong>and</strong> scheduled, if all other scheduled<br />

jobs still meet their deadl<strong>in</strong>es<br />

l� Otherwise job is rejected<br />

l� <strong>Sporadic</strong> job is denoted by S i (r i , d i , e i )<br />

IL2212 Embedded Software 43<br />

Acceptance Test <strong>in</strong> Fixed-<br />

<strong>Priority</strong> System<br />

l� <strong>Sporadic</strong> server can be used to execute<br />

sporadic jobs <strong>in</strong> a fixed-priority system<br />

l� The sporadic server (p s , e s ) has e s units of<br />

processor time every p s units of time<br />

IL2212 Embedded Software 44<br />

22


Acceptance Test <strong>in</strong> Fixed-<br />

<strong>Priority</strong> <strong>Systems</strong><br />

l� For each new sporadic job S (r, d, e) it must<br />

be checked, if<br />

l� new job can be scheduled together with the<br />

sporadic jobs that have deadl<strong>in</strong>e before d<br />

l� sporadic jobs with deadl<strong>in</strong>e larger or equal to d<br />

can still be scheduled<br />

l� Acceptance test is quite complex, but may<br />

still be feasible for many systems<br />

IL2212 Embedded Software 45<br />

Acceptance Test <strong>in</strong> Fixed-<br />

<strong>Priority</strong> <strong>Systems</strong><br />

l� Accepted sporadic jobs are ordered among<br />

themselves on EDF basis<br />

l� For the first sporadic job S 1 (t, d s,1 ,e s.1 ) the<br />

server has at least floor((d s,1 – t)/p s ) e s units of<br />

processor time available<br />

l� Thus first job is accepted, if the slack of the<br />

job<br />

σ s,1 (t) = floor((d s,1 – t)/p s ) e s – e s,1<br />

is larger than or equal to 0.<br />

IL2212 Embedded Software 46<br />

23


Acceptance Test <strong>in</strong> Fixed-<br />

<strong>Priority</strong> <strong>Systems</strong><br />

l� When there are already n accepted sporadic jobs <strong>in</strong><br />

the system, the scheduler computes the slack σ s,i of<br />

S i accord<strong>in</strong>g to<br />

where ξ s,k is the execution time of the completed<br />

portion of the sporadic job S k<br />

IL2212 Embedded Software 47<br />

Acceptance Test <strong>in</strong> Fixed-<br />

<strong>Priority</strong> <strong>Systems</strong><br />

l� If the slack σ s,i for the new sporadic job is not less<br />

than 0, we have to check, if all accepted jobs can<br />

still meet their deadl<strong>in</strong>e<br />

l� For each sporadic job S k which has an equal or later<br />

deadl<strong>in</strong>e the S i we have to check, if the slack σ s,k is<br />

larger than the execution time of the new sporadic<br />

job e s,i<br />

l� The new sporadic job is only accepted, if this is the<br />

case for all accepted sporadic jobs<br />

IL2212 Embedded Software 48<br />

24


Summary<br />

l� Servers can be used for the efficient<br />

schedul<strong>in</strong>g of aperiodic <strong>and</strong> sporadic jobs<br />

l� Servers have consumption <strong>and</strong><br />

replenishment rules, which can be arbitrarily<br />

complex<br />

l� Implementation overhead can be significant<br />

IL2212 Embedded Software 49<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!