12.07.2015 Views

Clock-driven (or Static) Scheduling (Baker and Shaw and Chapter 5 ...

Clock-driven (or Static) Scheduling (Baker and Shaw and Chapter 5 ...

Clock-driven (or Static) Scheduling (Baker and Shaw and Chapter 5 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Classification of <strong>Scheduling</strong> Alg<strong>or</strong>ithms


Schedule TableOur scheduler will schedule periodic jobs using a staticschedule that is computed offline <strong>and</strong> st<strong>or</strong>ed in a table T.» Each entry (t k , T(t k )) gives a decision time t k , when schedulingdecision is made, <strong>and</strong> name of task T(t k ).» T(t k ) = T i , if T i is to be scheduled at time t k , <strong>and</strong>I, if no periodic task is scheduled at time t k» F<strong>or</strong> most of this chapter, we assume the table is given.» Later, we consider one alg<strong>or</strong>ithm f<strong>or</strong> producing the table.• Note: This alg<strong>or</strong>ithm need not be highly efficient.» We will schedule aperiodic jobs (if any are ready) in intervalsnot used by periodic jobs.


<strong>Static</strong>, Timer-<strong>driven</strong> <strong>Scheduling</strong>


ExampleConsider a system of four tasks,T 1 = (4, 1), T 2 = (5, 1.8), T 3 = (20, 1), T 4 = (20, 2)Consider the following static schedule:The first few table entries would be: (0, T 1 ), (1, T 3 ),(2, T 2 ), (3.8, I), (4, T 1 ), … (19.8, I)


FramesLet us refine this notion of scheduling…To keep the table small, we divide the time line intoframes <strong>and</strong> make scheduling decisions only at frameboundaries.» Each job is executed as a procedure call that must fit within aframe.» The phase of each periodic task is a nonnegative integermultiple of the frame size.» Multiple jobs may be executed in a frame, but the table is onlyexamined at frame boundaries (the number of “columns” in thetable = the number of frames per hyperperiod).» In addition to making scheduling decisions, the scheduler alsochecks f<strong>or</strong> various err<strong>or</strong> conditions, like task overruns, at thebeginning of each frame.We let f denote the frame size.


Frame Size ConstraintsWe want frames to be sufficiently long so that every jobcan execute within a frame nonpreemptively. So,f ≥ max 1≤i≤n (e i ).To keep table small, f should divide H. Thus, f<strong>or</strong> at leastone task T i ,⎣p i /f⎦ −p i /f = 0.Let F = H/f. (Note: F is an integer.) Each interval oflength H is called a maj<strong>or</strong> cycle. Each interval oflength f is called a min<strong>or</strong> cycle.There are F min<strong>or</strong> cycles per maj<strong>or</strong> cycle.


Frame Constraints (Cont.)We want the frame size to be sufficiently small so that between therelease time <strong>and</strong> deadline of every job, there is at least one frame.• A job released “inside” a frame is not noticed by the scheduleruntil the next frame boundary.• M<strong>or</strong>eover, if a job has a deadline “inside” frame k + 1, itessentially must complete execution by the end of frame k.Thus, 2f − gcd(p i , f) ≤ D i .


ExampleConsider a system of four tasks, T 1 = (4, 1), T 2 = (5, 1.8),T 3 = (20, 1), T 4 = (20, 2)By first constraint, f ≥ 2.Hyperperiod is 20, so by second constraint, possible choicesf<strong>or</strong> f are 2, 4, 5, 10, <strong>and</strong> 20.Only f = 2 satisfies the third constraint. The following is apossible cyclic schedule:


Job SlicesWhat do we do if the frame size constraints cannot be met?Example: Consider T = {(4, 1), (5, 2, 7), (20, 5)}. By first constraint,f ≥ 5, but by third constraint, f ≤ 4!Solution: “Slice” the task (20, 5) into subtasks, (20, 1), (20, 3), <strong>and</strong>(20, 1). Then, f = 4 w<strong>or</strong>ks. Here’s a schedule:


Summary of Design DecisionsThree design decisions:» choosing a frame size,» partitioning jobs into slices, <strong>and</strong>» placing slices in frames.In general, these decisions cannot be madeindependently.We will look at an alg<strong>or</strong>ithm f<strong>or</strong> making thesedecisions later.


Pseudo-code f<strong>or</strong> Cyclic Executive


Improving Response Times ofAperiodic JobsIntuitively, it makes sense to give hard real-timejobs higher pri<strong>or</strong>ity than aperiodic jobs.However, this may lengthen the response time ofan aperiodic job.Note that there is no point in completing a hardreal-time job early, as long as it finishes by itsdeadline.


Slack StealingLet the total amount of time allocated to allthe slices scheduled in frame k be x k .Definition: The slack available at thebeginning of frame k is f − x k .Change to scheduler:» If the aperiodic job queue is nonempty, letaperiodic jobs execute in each frame wheneverthere is nonzero slack.


Example


Implementing Slack StealingUse a pre-computed “initial slack” table.» Initial slack depends only on static quantities.Use an interval timer to keep track of availableslack.» Set the timer when an aperiodic job begins to run. If itgoes off, must start executing periodic jobs.» Problem: Most OSs do not provide sub-millisecondgranularity interval timers (as we shall see).» So, to use slack stealing, temp<strong>or</strong>al parameters must beon the <strong>or</strong>der of 100s of msecs. <strong>or</strong> secs.


<strong>Scheduling</strong> Sp<strong>or</strong>adic JobsSp<strong>or</strong>adic jobs arrive at arbitrary times.They have hard deadlines.Implies we cannot hope to schedule every sp<strong>or</strong>adic job.When a sp<strong>or</strong>adic job arrives, the scheduler perf<strong>or</strong>ms anacceptance test to see if the job can be completed by itsdeadline.We must ensure that a new sp<strong>or</strong>adic job does not causea previously-accepted sp<strong>or</strong>adic job to miss its deadline.We assume sp<strong>or</strong>adic jobs are pri<strong>or</strong>itized on an earliestdeadline-first(EDF) basis.


Acceptance TestLet σ (i, k) be the initial total slack in frames i through k, where 1 ≤ i≤ k ≤ F. (This quantity only depends on periodic jobs.)Suppose we are doing an acceptance test at frame t f<strong>or</strong> a newlyarrivedsp<strong>or</strong>adic job S with deadline d <strong>and</strong> execution cost e.Suppose d occurs within frame l + 1, i.e., S must complete by the endof frame l.Compute the current total slack in frames t through l usingσ c (t, l) = σ (t, l) −∑ d k≤d (e k − ξ k )The sum is over previously-accepted sp<strong>or</strong>adic jobs with equal <strong>or</strong>earlier deadlines. ξ k is the amount of time already spent executing S kbef<strong>or</strong>e frame t.


Acceptance Test (Continued)We’ll specify the rest of the test “alg<strong>or</strong>ithmically”…To summarize, the scheduler must maintain the following data:• pre-computed initial slack table σ(i, k);• ξ k values to use at the beginning of the current frame t;• the current slack σ k of every accepted sp<strong>or</strong>adic job S k ;• a queue of accepted sp<strong>or</strong>adic jobs in a nondecreasing <strong>or</strong>der oftheir deadlines.


Executing Sp<strong>or</strong>adic TasksAccepted sp<strong>or</strong>adic jobs are executed like aperiodic jobsin the <strong>or</strong>iginal alg<strong>or</strong>ithm (without slack stealing).» Remember, when meeting a deadline is the main concern, thereis no need to complete a job early.» One difference: The aperiodic job queue is in FIFO <strong>or</strong>der,while the sp<strong>or</strong>adic job queue is in EDF <strong>or</strong>der.Aperiodic jobs only execute when the sp<strong>or</strong>adic job queueis empty.» As bef<strong>or</strong>e, slack stealing could be used when executingaperiodic jobs (in which case, some aperiodic jobs couldexecute when the sp<strong>or</strong>adic job queue is not empty).


Example


S 1 is released at time 3.» Must be scheduled in frames 2, 3, <strong>and</strong> 4.» Acceptance test – at the beginning of frame 2:• Slack time (4) is less than execution time – job is rejected.S 2 is released at time 5.» Must be scheduled in frames 3 through 7.» Acceptance test – at the beginning of frame 3:• Slack time is 5.5 – job is accepted.• First part (2 units) executes in current frame.S 3 is released at time 11.» Must be scheduled in frames 4 <strong>and</strong> 5.» S 3 executes ahead of S 2» Acceptance test – at the beginning of frame 4:• Slack time is 2 (is enough both f<strong>or</strong> S 3<strong>and</strong> the part of S 2) – job is accepted• First part (1 unit) S 3executes in current frame, followed by the second part of S 2S 4 is released at time 14.» Acceptance test – at the beginning of frame 5:• Slack time is 4.5 (accounted f<strong>or</strong> slack committed by S 2<strong>and</strong> S 3) – job is rejected• Remaining p<strong>or</strong>tion of S 3completes in current frame, followed by the part of S 2• Remaining p<strong>or</strong>tions of S 2execute in the next two frames


Practical ConsiderationsH<strong>and</strong>ling frame overruns.» Main Issue: Should offending job be completed <strong>or</strong> ab<strong>or</strong>ted?Mode changes.» During a mode change, the running set of tasks is replaced by anew set of tasks (i.e., the table is changed).» Can implement mode change by having an aperiodic <strong>or</strong>sp<strong>or</strong>adic mode-change job. (If sp<strong>or</strong>adic, what if it fails theacceptance test???)General W<strong>or</strong>kloads <strong>and</strong> Multiprocess<strong>or</strong>s.» Like uniprocess<strong>or</strong>s, but table probably takes longer to precompute.


Pseudo-code f<strong>or</strong> Mode Changertask MODE CHANGER (oldMode, newMode):fetch the deleteList of periodic tasks to be deleted;mark each periodic task in the deleteList;inf<strong>or</strong>m the cyclic executive that a mode change has commenced;fetch the newTaskList of periodic tasks to be executed in newMode;allocate mem<strong>or</strong>y space f<strong>or</strong> each task in newTaskList <strong>and</strong> create each of these task;fetch the newSchedule;perf<strong>or</strong>m acceptance test on each sp<strong>or</strong>adic job in the system acc<strong>or</strong>ding to thenewSchedule,if every sp<strong>or</strong>adic job in system can complete on time acc<strong>or</strong>ding to the newSchedule,inf<strong>or</strong>m the cyclic executive to use the newSchedule;else,compute the latestCompletionTime of all sp<strong>or</strong>adic jobs in system;inf<strong>or</strong>m the cyclic executive to use the newSchedule atmax (latestCompletionTime, thresholdTime);


Multi-rate Control SystemsM<strong>or</strong>e complicated control systems have multiple sens<strong>or</strong>s <strong>and</strong>actuat<strong>or</strong>s <strong>and</strong> must supp<strong>or</strong>t control loops of different rates.Example 2: Helicopter flight controller.Note: Having only harmonic rates simplifies the system.


Netw<strong>or</strong>k Flow Alg<strong>or</strong>ithm (INF) f<strong>or</strong>Computing <strong>Static</strong> SchedulesInitialization: Compute all frame sizes in acc<strong>or</strong>dance with the secondtwo frame-size constraints:⎣p i /f⎦−p i /f = 02f − gcd(p i , f) ≤ D iAt this point, we ign<strong>or</strong>e the first constraint, f ≥ max 1≤i≤n (e i ). Recallthis is the constraint that can f<strong>or</strong>ce us to “slice” a task into subtasks.Iterative Alg<strong>or</strong>ithm: F<strong>or</strong> each possible frame size f, we compute anetw<strong>or</strong>k flow graph <strong>and</strong> run a max-flow alg<strong>or</strong>ithm. If the flow thusfound has a certain value, then we have a schedule.


Flow GraphDenote all jobs in the maj<strong>or</strong> cycle of F frames asJ 1 , J 2 , …, J N .Vertices:» N job vertices, denoted J 1 , J 2 , …, J N.» F frame vertices, denoted 1, 2, …, F.» source <strong>and</strong> sink.Edges:»(J i , j) with capacity f if J i can be scheduled in frame j.»(source, J i ) with capacity e i .»(f, sink) with capacity f.


Illustration of Flow Graph


Finding a ScheduleThe maximum attainable flow value is clearly∑ i=1,…,N e i . This c<strong>or</strong>responds to the exact amount ofcomputation to be scheduled in the maj<strong>or</strong> cycle.If a max flow is found with value ∑ i=1,…,N e i , thenwe have a schedule.If a job is scheduled across multiple frames, thenwe must slice it into c<strong>or</strong>responding subjobs.


Example


ExampleExample: Consider T = {(4, 1), (5, 2, 7), (20, 5)}. By second <strong>and</strong>third constraints, f = 2 <strong>and</strong> 4!F<strong>or</strong> the first iteration of the Netw<strong>or</strong>k Flow Alg<strong>or</strong>ithm frame size is 4.Maximum flow of the graph is 18, which is the total execution timeof all jobs in a hyperperiod.Flow of edges represent a schedule of the tasks:


Example


Non-independent TasksTasks with precedence constraints are no problem.» We can enf<strong>or</strong>ce precedence constraint like “J i precedes J k ” bysimply making sure J i ’s release is at <strong>or</strong> bef<strong>or</strong>e J k ’s release, <strong>and</strong>J i ’s deadline is at <strong>or</strong> bef<strong>or</strong>e J k ’s deadline.» If slices of J i <strong>and</strong> J k are scheduled in the wrong <strong>or</strong>der, we canjust swap them.Critical sections pose a greater challenge.» We can try to “massage” the flow-netw<strong>or</strong>k schedule into onewhere nonpreemption constraints are respected.» Unf<strong>or</strong>tunately, there is no known efficient, optimal alg<strong>or</strong>ithm f<strong>or</strong>doing this (the problem is actually NP-hard).


Pros <strong>and</strong> Cons of Cyclic ExecutivesMain Advantage: CEs are very simple ⎯ youjust need a table.» F<strong>or</strong> example, additional mechanisms f<strong>or</strong> concurrencycontrol <strong>and</strong> synchronization are not needed. In fact,there’s really no notion of a “process” here ⎯ justprocedure calls.» Can validate, test, <strong>and</strong> certify with very highconfidence.» Certain anomalies will not occur.» F<strong>or</strong> these reasons, cyclic executives are thepredominant approach in many safety-criticalapplications (like airplanes).


Aside: <strong>Scheduling</strong> Anomalies(Section 4.8.1 of Liu)Here’s an example: On a multiprocess<strong>or</strong>, decreasing a job’sexecution cost can increase some job’s response time.Example: Suppose we have one job queue, preemption, but nomigration.


Pros <strong>and</strong> Cons (Continued)Disadvantages of cyclic executives:» Very brittle: Any change, no matter how trivial,requires a new table be computed!» Release times of all jobs must be fixed, i.e., “realw<strong>or</strong>ld”sp<strong>or</strong>adic tasks are difficult to supp<strong>or</strong>t.» Temp<strong>or</strong>al parameters essentially must be multiples of f.» F could be huge!» All combinations of periodic tasks that may executetogether must a pri<strong>or</strong>i be analyzed.» From a software engineering st<strong>and</strong>point, “slicing” oneprocedure into several could be err<strong>or</strong>-prone.


ReadingsT.P.<strong>Baker</strong> <strong>and</strong> A.<strong>Shaw</strong>. “The Cyclic Executive Model <strong>and</strong> Ada.” In Proc. ofIEEE Real-Time Systems Symposium, pp. 120-129, Madrid, Spain, 1988.<strong>Chapter</strong> 5 of Liu. <strong>Clock</strong>-Driven <strong>Scheduling</strong>.Section 4.8.1 of Liu. Anomalous Behavi<strong>or</strong> of Pri<strong>or</strong>ity-Driven Systems.T.H. C<strong>or</strong>men, C.E. Leiserson, R.L. Rivest, C. Stein. Introduction toAlg<strong>or</strong>ithms, Second Edition. McGraw-Hill&MIT Press, 2001/2.ISBN: 0-07-013151-1 (0262032937)(www.introductiontoalg<strong>or</strong>ithms.com)Reference in Liu’s book: Goldberg, A. V. “Process<strong>or</strong> efficientimplementation of a maximum flow alg<strong>or</strong>ithm”, Inf<strong>or</strong>mation ProcessingLetter, vol.38, pp.179–185, May 1991.(http://www.st<strong>or</strong>mingmedia.us/cgibin/96/9643/A964323.php?pageNo=5&categ<strong>or</strong>yID=53&masterCateg<strong>or</strong>yID=24)The same auth<strong>or</strong>: Andrew V. Goldberg. “Recent Developments in MaximumFlow Alg<strong>or</strong>ithms” (Invited Lecture). SWAT 1998: 1-10(http://link.springer.de/link/service/series/0558/bibs/1432/14320001.htm)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!