Clock Driven
Clock Driven
1
R. Bettati
Cyclic Schedules: General Structure
Scheduling decision is made periodically:
Scheduling decision is made periodically:
choose which job to execute
perform monitoring and enforcement operations
Major Cycle: Frames in a hyperperiod.
Frame f
decision points
hyperperiod H
major cycle
R. Bettati
Frame Size Constraints
Frames must be sufciently long so that every job can start and
complete within a single frame:
The hyperperiod must have an integer number of frames:
For monitoring purposes, frames must be sufciently small that
between release time and deadline of every job there is at least
one frame:
) max( ) 1 (
i
e f !
) " " ( ) 2 ( H divides f H f
i i
i
i
D f p f
f p t t
D t t f
! "
# "
! " "
) , gcd( 2 ) 3 (
) , gcd( '
) ' ( 2
t
t+f t+2f t+3f
t t+D
i
t+p
i
CPSC-663: Real-Time Systems Clock-Driven Scheduling
2
R. Bettati
Frame Sizes: Example
Task set:
660
) 22 , 3 , 22 (
) 26 , 2 , 20 (
) 14 , 1 , 15 (
3
2
1
=
=
=
=
H
T
T
T
6 , 5 , 4 , 3 : for values possible
6 , 5 , 4 , 3 , 2 ) , gcd( 2 : ) 3 (
,.. 10 , 6 , 5 , 4 , 3 , 2 ) 2 (
3 : ) 1 (
f
f Di f pi f i
f H f
f e f i
i
!
= ! " # $
= !
% ! % $
p
i
e
i
D
i
R. Bettati
Slicing and Scheduling Blocks
Slicing
?!
4 ) 3 (
5 ) 1 (
) 20 , 5 , 20 (
) 5 , 2 , 5 (
) 4 , 1 , 4 (
3
2
1
!
"
#
$ %
& %
=
=
=
f
f
T
T
T
4
4 ) 3 (
3 ) 1 (
) 20 , 1 , 20 (
) 20 , 3 , 20 (
) 20 , 1 , 20 (
) 5 , 2 , 5 (
) 4 , 1 , 4 (
33
32
31
2
1
=
!
"
#
$ %
& %
=
=
=
=
=
f
f
f
T
T
T
T
T slice
T
3
1 3
1
1 1 1 1 2 2 2 2 3
3
3
2
0 4 8 12 16 20
..
scheduling block
H
p
i
e
i
D
i
CPSC-663: Real-Time Systems Clock-Driven Scheduling
3
R. Bettati
Cyclic Executive
Input: Stored schedule: L(k) for k = 0,1,,F-1;
Aperiodic job queue.
TASK CYCLIC_EXECUTIVE:
t = 0; /* current time */ k = 0; /* current frame */
CurrentBlock := empty;
BEGIN LOOP
IF <any slice in CurrentBlock is not completed> take action;
CurrentBlock := L(k);
k := k+1 mod F; t := t+1;
set timer to expire at time tF;
IF <any slice in CurrentBlock is not released> take action;
wake up periodic task server to handle slices in CurrentBlock;
sleep until periodic task server completes or timer expires;
IF <timer expired> CONTINUE;
WHILE <the aperiodic job queue is not empty>
wake up the first job in the queue;
sleep until the aperiodic job completes;
remove the just completed job from the queue;
END WHILE;
sleep until next clock interrupt;
END LOOP;
END CYCLIC_EXECUTIVE;
R. Bettati
What About Aperiodic Jobs?
Typically:
Scheduled in the background.
Their execution may be delayed.
But:
Aperiodic jobs are typically results of external events.
Therefore:
The sooner the completion time, the more responsive the system
Minimizing response time of aperiodic jobs becomes a design issue.
Approach:
Execute aperiodic jobs ahead of periodic jobs whenever possible.
This is called Slack Stealing.
CPSC-663: Real-Time Systems Clock-Driven Scheduling
4
R. Bettati
Slack Stealing (Lehoczky et al., RTSS87)
x
k
Amount of time allocated to slices executed during frame F
k
.
s
k
Slack during frame F
k
: s
k
:= f - x
k
.
The cyclic executive can execute aperiodic jobs for s
k
amount of
time without causing jobs to miss deadlines.
Example:
4 8 12 16 20 0
1.5 0.5 2.0
4 9.5 10.5
R. Bettati
Sporadic Jobs
Reminder: Sporadic jobs have hard deadlines; the release time and
the execution time are not known a priori.
Worst-case execution time known when job is released.
Need acceptance test:
J(d,e)
F
c-1
F
c
F
c+1
F
l
F
l+1
s
c
s
c+1
s
l
d
!
=
=
l
c i
i
s l c S ) , ( : Total amount of slack in Frames F
c
, , F
l
.
Acceptance Test: IF S(c,l) < e THEN
reject job;
ELSE
accept job;
schedule execution;
END;
how?!
CPSC-663: Real-Time Systems Clock-Driven Scheduling
5
R. Bettati
Scheduling of Accepted Jobs
Static scheduling:
Schedule as large a slice of the accepted job as possible in the
current frame.
Schedule remaining portions as late as possible.
Mechanism:
Append slices of accepted job to list of periodic-task slices in
frames where they are scheduled.
Problem: Early commit.
Alternatives:
Rescheduling upon arrival.
Priority-driven scheduling of sporadic jobs.
R. Bettati
EDF-Scheduling of Accepted Jobs
...
T
1
T
2
T
3
T
N
priority
queue
aperiodic
processor
reject
acceptance
test
periodic
tasks
CPSC-663: Real-Time Systems Clock-Driven Scheduling
6
R. Bettati
Acceptance Test for EDF-Scheduled Sporadic Jobs
Sporadic Job J with deadline d arrives:
Test 1: Test whether current amount of slack before d is
enough to accommodate J. (*)
If not, reject!
Test 2: Test whether sporadic jobs still in system with
deadlines after d will miss deadline if J
is accepted. (**)
If yes, reject!
Accept!
(*) Dene S(J
i
) : Amount of slack up to time d
i
after J
i
has
been scheduled.
(**) Update all S(J
i
) with d
i
> d , that is,
R. Bettati
Accept. Test for EDF Spor. Jobs (Implementation)
Dene
S
i,k
: slack in Frames F
i
, ..., F
k
Precompute all S
i,k
in rst major cycle
Initial amounts of slack in later cycles can be computed as
S
i+jF,k+jF
= S
i,F
+ S
1,k
+ (j-j)S
1,F
Compute current slack of job with release time in F
c-1
and deadline
in F
l+1
:
S
new
c,l
= S
c,l
!
(dk<d)
e
k
(c)
Implementation:
Initially compute S
c,l
for newly arriving job. If negative, reject.
Whenever job with earlier deadline arrives, decrease this value.
If negative, reject new job.
CPSC-663: Real-Time Systems Clock-Driven Scheduling
7
R. Bettati
Static Scheduling of Jobs in Frames
Layout of task schedule for cyclic executive can be formulated as a
schedule for jobs in a hyperperiod.
This can be formulated as a network ow problem.
F
1
F
2
F
j
F
m-1
F
m
Sink
J
1
J
2
J
i
J
n-1
J
n
Source
.
.
.
.
.
.
.
.
.
.
.
.
e
i
f
R. Bettati
Pros and Cons of Clock-Driven Scheduling
Pros:
Conceptual simplicity
Timing constraints can be checked and enforced at frame
boundaries.
Preemption cost can be kept small by having appropriate frame
sizes.
Easy to validate: Execution times of slices known a priori.
Cons:
Difcult to maintain.
Does not allow to integrate hard and soft deadlines.
CPSC-663: Real-Time Systems Clock-Driven Scheduling
8
R. Bettati
Putting the Cyclic Executive into Practice
T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada
Implementation approaches for a Cyclic Executive: Solutions and
Difculties
Naive solution using the DELAY statement
Using an interrupt from a hardware clock
Dealing with lost or buffered interrupts
Handling frame overruns
R. Bettati
Naive Solution Using the DELAY Statement
Source: T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada
CPSC-663: Real-Time Systems Clock-Driven Scheduling
9
R. Bettati
Using an Interrupt from a Hardware Clock
Source: T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada
R. Bettati
Dealing with Lost or Buffered Interrupts
Source: T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada
CPSC-663: Real-Time Systems Clock-Driven Scheduling
10
R. Bettati
Handling Frame Overruns (I)
ABORTION:
Source: T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada
R. Bettati
Handling Frame Overruns (II)
EXCEPTIONS:
Source: T. P. Baker, Alan Shaw, The Cyclic Executive Model and Ada