0% found this document useful (0 votes)
348 views

Clock Driven

Clock-driven scheduling pre-computes a static schedule offline using algorithms to determine a schedule table with entries of (tk, J(tk)) where tk is the decision time and J(tk) is the job to start. The scheduler uses this table to lookup the job to execute at each timer interrupt by indexing the table with the current frame number. Slack stealing allows aperiodic and sporadic jobs to execute ahead of periodic jobs by using any available slack time between the actual and maximum execution time of periodic tasks within a frame.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
348 views

Clock Driven

Clock-driven scheduling pre-computes a static schedule offline using algorithms to determine a schedule table with entries of (tk, J(tk)) where tk is the decision time and J(tk) is the job to start. The scheduler uses this table to lookup the job to execute at each timer interrupt by indexing the table with the current frame number. Slack stealing allows aperiodic and sporadic jobs to execute ahead of periodic jobs by using any available slack time between the actual and maximum execution time of periodic tasks within a frame.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

CPSC-663: Real-Time Systems Clock-Driven Scheduling

Clock-Driven Scheduling (in-depth)

• Pre-compute static schedule


off-line (e.g. at design time): Task Scheduler:
i := 0; k := 0;
can afford expensive
<set timer to expire at time t0>
algorithms.
BEGIN LOOP
• Idle times can be used for <wait for timer interrupt>
aperiodic jobs. i := i+1;
• Possible implementation: k:= i mod N;
<set timer to expire at time
Table-driven (i DIV N)*H + tk >
• Scheduling table has entries IF J(tk-1)is empty
of type (tk, J(tk)) , where THEN wakeup(aperiodic)
tk : decision time ELSE wakeup(J(tk-1))
END LOOP
J(tk) : job to start at time tk
END Scheduler;
• Input: Schedule (tk, J(tk))
k = 0,1,…,N-1

Cyclic Schedules: General Structure

• Scheduling decision is made periodically:

Frame f

• Scheduling decision is made periodically: decision points


– choose which job to execute
– perform monitoring and enforcement operations

• Major Cycle: Frames in a hyperperiod.


major cycle

hyperperiod H

1
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Frame Size Constraints

• Frames must be sufficiently long so that every job can start and
complete within a single frame:
(1) f ! max(ei )

• The hyperperiod must have an integer number of frames:


( 2) f H ( f " divides" H )

• For monitoring purposes, frames must be sufficiently small that


between release time and deadline of every job there is at least
one frame:

t t’ t+f t+2f t’+Di t’+pi t+3f

2 f " (t '"t ) ! Di
t '"t # gcd( pi , f )
(3) 2 f " gcd( pi , f ) ! Di

Frame Sizes: Example


• Task set:
pi ei Di
T1 = ( 15, 1, 14 )
T2 = ( 20, 2, 26 ) H = 660
T3 = ( 22, 3, 22 )

(1) $i : f % ei ! f %3
( 2) f H ! f = 2,3,4,5,6,10,..
(3) $i : 2 f # gcd( pi, f ) " Di ! f = 2,3,4,5,6

! possible values for f : 3,4,5,6

2
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Slicing and Scheduling Blocks


pi ei Di
• Slicing T1 = ( 4, 1, 4 )
(1) % f &5 #
T2 = ( 5, 2, 5 ) " ?!
(3) % f $4 !
T3 = ( 20, 5, 20 )

slice T1 = ( 4, 1, 4 )
T3
T2 = ( 5, 2, 5 )
(1) % f &3 #
T31 = ( 20, 1, 20 ) "f =4
(3) % f $4 !
T32 = ( 20, 3, 20 )
T33 = ( 20, 1, 20 )

scheduling block

1 2 31 1 2 1 32 1 2 1 2 33 …..

0 4 8 12 16 20
H

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;

3
CPSC-663: Real-Time Systems Clock-Driven Scheduling

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.

Slack Stealing (Lehoczky et al., RTSS’87)

xk Amount of time allocated to slices executed during frame Fk.


sk Slack during frame Fk: sk := f - xk.

• The cyclic executive can execute aperiodic jobs for sk amount of


time without causing jobs to miss deadlines.
• Example:

0 4 1.5 8 0.5 2.0 12 16 20

4 9.5 10.5

4
CPSC-663: Real-Time Systems Clock-Driven Scheduling

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) sc sc+1 sl d

Fc-1 Fc Fc+1 Fl Fl+1

l
S (c, l ) = ! si : Total amount of slack in Frames Fc, …, Fl.
i =c

• Acceptance Test: IF S(c,l) < e THEN


reject job;
ELSE how?!
accept job;
schedule execution;
END;

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.

5
CPSC-663: Real-Time Systems Clock-Driven Scheduling

EDF-Scheduling of Accepted Jobs

T1
T2
periodic
tasks T3
...
TN
acceptance
test priority
queue processor
reject

aperiodic

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!

• (*) Define S(Ji) :Amount of slack up to time di after Ji has


been scheduled.
• (**) Update all S(Ji) with di > d , that is,

6
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Accept. Test for EDF Spor. Jobs (Implementation)

• Define
Si,k : slack in Frames Fi, ..., Fk

• Precompute all Si,k in first major cycle


• Initial amounts of slack in later cycles can be computed as
Si+jF,k+j’F = Si,F + S1,k + (j’-j)S1,F

• Compute current slack of job with release time in Fc-1 and


deadline in Fl+1:
Snewc,l = Sc,l – S (dk<d)ek(c)

• Implementation:
– Initially compute Sc,l for newly arriving job. If negative,
reject.
– Whenever job with earlier deadline arrives, decrease this
value. If negative, reject new job.

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 flow problem.

J1
F1
J2
F2
...
...

ei Ji Fj f
Source Sink
...

...

Jn-1 Fm-1
Jn Fm

7
CPSC-663: Real-Time Systems Clock-Driven Scheduling

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:
– Difficult to maintain.
– Does not allow to integrate hard and soft deadlines.

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


Difficulties

– Naive solution using the DELAY statement

– Using an interrupt from a hardware clock

– Dealing with lost or buffered interrupts

– Handling frame overruns

8
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Naive Solution Using the DELAY Statement

Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”

Using an Interrupt from a Hardware Clock

Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”

9
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Dealing with Lost or Buffered Interrupts

Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”

Handling Frame Overruns (I)

ABORTION:

Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”

10
CPSC-663: Real-Time Systems Clock-Driven Scheduling

Handling Frame Overruns (II)

EXCEPTIONS:

Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”

11

You might also like