Clock Driven
Clock Driven
Frame f
hyperperiod H
1
CPSC-663: Real-Time Systems Clock-Driven Scheduling
• Frames must be sufficiently long so that every job can start and
complete within a single frame:
(1) f ! max(ei )
2 f " (t '"t ) ! Di
t '"t # gcd( pi , f )
(3) 2 f " gcd( pi , f ) ! Di
(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
2
CPSC-663: Real-Time Systems Clock-Driven Scheduling
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
• 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.
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
l
S (c, l ) = ! si : Total amount of slack in Frames Fc, …, Fl.
i =c
• 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.
• Alternatives:
– Rescheduling upon arrival.
– Priority-driven scheduling of sporadic jobs.
5
CPSC-663: Real-Time Systems Clock-Driven Scheduling
T1
T2
periodic
tasks T3
...
TN
acceptance
test priority
queue processor
reject
aperiodic
6
CPSC-663: Real-Time Systems Clock-Driven Scheduling
• Define
Si,k : slack in Frames Fi, ..., Fk
• 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.
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:
– 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.
8
CPSC-663: Real-Time Systems Clock-Driven Scheduling
Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”
Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”
9
CPSC-663: Real-Time Systems Clock-Driven Scheduling
Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”
ABORTION:
Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”
10
CPSC-663: Real-Time Systems Clock-Driven Scheduling
EXCEPTIONS:
Source: T. P. Baker, Alan Shaw, “The Cyclic Executive Model and Ada”
11