CPSC-663: Real-ime Systems Cyclic Schedules: General Structure Scheduling decision is made periodically: Frame Scheduling decision is made periodically: choose which job to execute perorm monitoring and enorcement operations decision points Major Cycle: Frames in a hyperperiod. major cycle hyperperiod H Frame Size Constraints Frames must be suiciently long so that every job can start and complete within a single rame: 1 max ei he hyperperiod must have an integer number o rames: 2 H " divides" H For monitoring purposes, rames must be suiciently small that between release time and deadline o every job there is at least one rame: t t t+ t+2 t +D i t +p i t+3 3 2 t' t D t' t gcd p, 2 gcd p, D i i i i 1
CPSC-663: Real-ime Systems Frame Sizes: Example ask set: 1 2 3 p i e i D i 15, 1, 14 20, 2, 26 22, 3, 22 H 660 1 2 3 i : ei H i : 2 gcd pi, Di 3 2,3,4,5,6,10,.. 2,3,4,5,6 possible values or : 3,4,5,6 Slicing and Scheduling Blocks Slicing 1 2 3 p i e i D i 4, 1, 4 5, 2, 5 20, 5, 20 1 3 5 4?! slice 3 1 2 31 32 33 4, 5, 20, 20, 20, 1, 2, 1, 3, 1, 4 5 20 20 20 1 3 3 4 4 scheduling block 1 2 3 1 1 2 1 3 2 1 2 1 2 3 3.. 0 4 8 12 16 20 H 2
CPSC-663: Real-ime Systems Cyclic Executive Input: "Stored schedule: Lk or k 0,1,,F-1; " "Aperiodic job queue. ASK CYCLIC_EXECUIVE: t 0; /* current time */ k 0; /* current rame */ CurrentBlock : empty; BEGIN LOOP IF <any slice in CurrentBlock is not completed> take action; CurrentBlock : Lk; 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> CONINUE; WHILE <the aperiodic job queue is not empty> wake up the irst job in the queue; sleep until the aperiodic job completes; remove the just completed job rom the queue; END WHILE; sleep until next clock interrupt; END LOOP; END CYCLIC_EXECUIVE; What About Aperiodic Jobs? ypically: " Scheduled in the background. heir execution may be delayed. But: Aperiodic jobs are typically results o external events. hereore: he sooner the completion time, the more responsive the system Minimizing response time o aperiodic jobs becomes a design issue. Approach: Execute aperiodic jobs ahead o periodic jobs whenever possible. his is called Slack Stealing. 3
CPSC-663: Real-ime Systems Slack Stealing Lehoczky et al., RSS 87 x k " "Amount o time allocated to slices executed during rame F k. s k " "Slack during rame F k : s k : - x k. he cyclic executive can execute aperiodic jobs or s k amount o 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 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: Jd,e s c s c+1 s l d F c-1 F c F c+1 F l F l+1 l s i i c S c, l : otal amount o slack in Frames F c,, F l. Acceptance est: "IF Sc,l < e HEN reject job; ELSE accept job; schedule execution; END; how?! 4
CPSC-663: Real-ime Systems Scheduling o Accepted Jobs Static scheduling: Schedule as large a slice o the accepted job as possible in the current rame. Schedule remaining portions as late as possible. Mechanism: Append slices o accepted job to list o periodic-task slices in rames where they are scheduled. Problem: Early commit. Alternatives: Rescheduling upon arrival. Priority-driven scheduling o sporadic jobs. EDF-Scheduling o Accepted Jobs 1 periodic tasks 2 3 N... acceptance test reject priority queue processor aperiodic 5
CPSC-663: Real-ime Systems Acceptance est or EDF-Scheduled Sporadic Jobs Sporadic Job J with deadline d arrives: est 1: "est whether current amount o slack beore d is " "enough to accommodate J. * " "I not, reject! est 2: "est whether sporadic jobs still in system with " "deadlines ater d will miss deadline i J " "is accepted. ** " "I yes, reject! Accept! * "Deine SJ i : "Amount o slack up to time d i ater J i has " " "been scheduled. ** "Update all SJ i with d i > d, that is, Accept. est or EDF Spor. Jobs Implementation Deine S i,k : slack in Frames F i,..., F k Precompute all S i,k in irst major cycle Initial amounts o slack in later cycles can be computed as S i+jf,k+j F S i,f + S 1,k + j -js 1,F Compute current slack o 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 or newly arriving job. I negative, reject. Whenever job with earlier deadline arrives, decrease this value. I negative, reject new job. 6
CPSC-663: Real-ime Systems Static Scheduling o Jobs in Frames Layout o task schedule or cyclic executive can be ormulated as a schedule or jobs in a hyperperiod. his can be ormulated as a network low problem. J 1 F 1 J 2 F 2 Source e i J i............ F j Sink J n-1 J n F m-1 F m Pros and Cons o Pros: Conceptual simplicity iming constraints can be checked and enorced at rame boundaries. Preemption cost can be kept small by having appropriate rame sizes. Easy to validate: Execution times o slices known a priori. Cons: Diicult to maintain. Does not allow to integrate hard and sot deadlines. 7
CPSC-663: Real-ime Systems Putting the Cyclic Executive into Practice. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada Implementation approaches or a Cyclic Executive: Solutions and Diiculties Naive solution using the DELAY statement Using an interrupt rom a hardware clock Dealing with lost or buered interrupts Handling rame overruns Naive Solution Using the DELAY Statement Source:. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada 8
CPSC-663: Real-ime Systems Using an Interrupt rom a Hardware Clock Source:. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada Dealing with Lost or Buered Interrupts Source:. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada 9
CPSC-663: Real-ime Systems Handling Frame Overruns I ABORION: Source:. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada Handling Frame Overruns II EXCEPIONS: Source:. P. Baker, Alan Shaw, he Cyclic Executive Model and Ada 10