CPSC-663: Real-me Systems n-depth Precompute statc schedule o-lne e.g. at desgn tme: can aord expensve algorthms. Idle tmes can be used or aperodc jobs. Possble mplementaton: able-drven Schedulng table has entres o type t k, Jt k, where t k : decson tme Jt k : job to start at tme t k Input: Schedule t k, Jt k k 0,,,N- ask Scheduler: : 0; k : 0; <set tmer to expre at tme t 0 > BEGIN LOOP <wat or tmer nterrupt> : +; k: mod N; <set tmer to expre at tme DIV N*H + t k > IF Jt k- s empty HEN wakeupaperodc ELSE wakeupjt k- END LOOP END Scheduler; Cyclc Schedules: General Structure Schedulng decson s made perodcally: rame Schedulng decson s made perodcally: choose whch job to execute perorm montorng and enorcement operatons decson ponts Major Cycle: Frames n a hyperperod. major cycle hyperperod H
CPSC-663: Real-me Systems Frame Sze Constrants Frames must be sucently long so that every job can start and complete wthn a sngle rame: max e he hyperperod must have an nteger number o rames: 2 H " dvdes" H For montorng purposes, rames must be sucently small that between release tme and deadlne o every job there s at least one rame: t t t+ t+2 t +D t +p t+3 3 2 t' t D t' t gcd p, 2 gcd p, D Frame Szes: Example ask set: p e D 5, 22,, 2, 3, 4 26 22 H 660 2 3 : H e : 2 gcd p, D 3 2,3,4,5,6,0,.. 2,3,4,5,6 possble values or :3,4,5,6 2
CPSC-663: Real-me Systems Slcng and Schedulng Blocks Slcng 2 3 p e D 4,, 4 5, 2, 5 5, 20 3 5 4?! slce 3 2 3 32 33 4, 5,, 2,, 3,, 4 5 20 20 20 3 3 4 4 schedulng block 2 3 2 32 2 2 33.. 0 4 8 2 6 20 H Cyclc Executve Input: Stored schedule: Lk or k 0,,,F-; Aperodc job queue. ASK CYCLIC_EXECUIVE: k 0; /* current rame */ BEGIN LOOP accept clock nterrupt at tme k*; IF <the last job s not completed> take acton; CurrentBlock : Lk; k : k+ mod F; IF <any slce n CurrentBlock s not released> take acton; WHILE <CurrentBlock s not empty> execute the rst slce n t; remove the rst slce rom CurrentBlock; END WHILE; WHILE <the aperodc job queue s not empty> execute the rst job n the queue; remove the just completed job; END WHILE; END LOOP; END CYCLIC_EXECUIVE; 3
CPSC-663: Real-me Systems What About Aperodc Jobs? ypcally: Scheduled n the background. her executon may be delayed. But: Aperodc jobs are typcally results o external events. hereore: he sooner the completon tme, the more responsve the system Mnmzng response tme o aperodc jobs becomes a desgn ssue. Approach: Execute aperodc jobs ahead o perodc jobs whenever possble. hs s called Slack Stealng. Slack Stealng Lehoczky et al., RSS 87 x k Amount o tme allocated to slces executed durng rame F k. s k Slack durng rame F k : s k : - x k. he cyclc executve can execute aperodc jobs or s k amount o tme wthout causng jobs to mss deadlnes. Example: 0 4.5 8 0.5 2.0 2 6 20 4 9.5 0.5 4
CPSC-663: Real-me Systems Sporadc Jobs Remnder: Sporadc jobs have hard deadlnes; the release tme and the executon tme are not known a pror. Worst-case executon tme known when job s released. Need acceptance test: Jd,e s c s c+ s l d F c- F c F c+ F l F l+ S c, l : otal amount o slack n Frames F c,, F l. l s c Acceptance est: IF Sc,l < e HEN reject job; ELSE accept job; schedule executon; END; how?! Statc schedulng: Schedulng o Accepted Jobs Schedule as large a slce o the accepted job as possble n the current rame. Schedule remanng portons as late as possble. Mechansm: Append slces o accepted job to lst o perodc-task slces n rames where they are scheduled. Problem: Early commt. Alternatves: Reschedulng upon arrval. Prorty-drven schedulng o sporadc jobs. 5
CPSC-663: Real-me Systems EDF-Schedulng o Accepted Jobs perodc tasks 2 3 N... acceptance test reject prorty queue aperodc processor Acceptance est or EDF-Scheduled Sporadc Jobs Sporadc Job J wth deadlne d arrves: est : est whether current amount o slack beore d s enough to accommodate J. I not, reject! est 2: est whether sporadc jobs stll n system wth deadlnes ater d wll mss deadlne J s accepted. I yes, reject! Accept! * Dene SJ : Amount o slack up to tme d ater J has been scheduled. ** Update all SJ wth d > d, that s, such that d > d : S J S J e 6
CPSC-663: Real-me Systems Pros and Cons o Pros: Conceptual smplcty mng constrants can be checked and enorced at rame boundares. Preempton cost can be kept small by havng approprate rame szes. Easy to valdate: Executon tmes o slces known a pror. Cons: Dcult to mantan. Does not allow to ntegrate hard and sot deadlnes. 7