Real-Time Scheduling Priority-Driven Scheduling Fixed-Priority [Some parts of this lecture are based on a real-time systems course of Colin Perkins http://csperkins.org/teaching/rtes/index.html] 1 Current Assumptions Single processor Fixed number, n, of independent periodic tasks i.e. there is no dependency relation among jobs Jobs can be preempted at any time and never suspend themselves No aperiodic and sporadic jobs No resource contentions Moreover, unless otherwise stated, we assume that Scheduling decisions take place precisely at release of a job completion of a job (and nowhere else) Context switch overhead is negligibly small i.e. assumed to be zero There is an unlimited number of priority levels 2 Fixed-Priority Algorithms Consider a set of tasks T = {T1, . . . , Tn} Any fixed-priority algorithm schedules tasks according to fixed priorities assigned to tasks, w.l.o.g. assume T1 T2 · · · Tn i.e. T1 has the highest priority, Tn has the lowest priority Define T↑i := {Tk | Tk Ti} 3 Utilization Utilization ui of a periodic task Ti with period pi and execution time ei is defined by ui := ei/pi The fraction of time a periodic task with period pi and execution time ei keeps a processor busy Total utilization UT of a set of tasks T = {T1, . . . , Tn} is defined as the sum of utilizations of all tasks of T, i.e. by UT := n i=1 ui U is a schedulable utilization of an algorithm ALG if all sets of tasks T satisfying UT ≤ U are schedulable by ALG. Maximum schedulable utilization UALG of an algorithm ALG is the supremum of schedulable utilizations of ALG. 4 Critical Instant – Informally To be able to further analyze fixed-priority algorithms we need to consider a notion of critical instant Intuitively, a critical instant is the time instant in which the system is most loaded, and has its worst response time Schedulability of a set of tasks is determined by response times of jobs released at critical instants 5 Critical Instant – Formally Definition 1 A critical instant tcrit of a task Ti is a time instant in which a job Ji,k in Ti is released so that Ji,k either does not meet its deadline, or has the maximum response time of all jobs in Ti Denote by Wi the response time of such Ji,k Theorem 2 In a fixed-priority system where every job completes before the next job in the same task is released, a critical instant occurs when one of its jobs Ji,k is released at the same time with a job from every higher-priority task. Note that the situation described in the theorem does not have to occur if tasks are not in phase. So we use critical instants either to study tasks in phase, or to get upper bounds on schedulability as follows: Set phases of all jobs in T↑i to zero, which gives a new set of tasks T Determine the response time w of the first job Ji,1 in Ti Then w ≥ Wi, the response time of a job in the original set T released at the critical instant 6 Optimality of RM for Simply Periodic Tasks Definition 3 A set {T1, . . . , Tn} is simply periodic if for every pair Ti, Tk satisfying pi < pk we have that pk is an integer multiple of pi Example 4 The helicopter control system from the first lecture Theorem 5 A set T of n simply periodic, independent, preemptable tasks with Di = pi is schedulable on one processor according to RM iff UT ≤ 1. i.e. on simply periodic tasks RM is as good as EDF 7 Optimality of DM (RM) among Fixed-Priority Algs. Theorem 6 A set of independent, preemptable periodic tasks with Di ≤ pi that are in phase can be feasibly scheduled on one processor according to DM if it can be feasibly scheduled by some fixed-priority algorithm. Proof. Assume a fixed-priority feasible schedule with T1 · · · Tn. Consider the least i such that the relative deadline Di of Ti is larger than the relative deadline Di+1 of Ti+1. Swap the priorities of Ti and Ti+1. The resulting schedule is still feasible. DM is obtained by using finitely many swaps. Note: If the assumptions of the above theorem hold and all relative deadlines are equal to periods, then RM is optimal among all fixed-priority algorithms. 8 Fixed-Priority Algorithms: Schedulability We consider two schedulability tests: Schedulable utilization URM of the RM algorithm. Time-demand analysis based on response times of jobs released at critical instants 9 Schedulable Utilization for RM Theorem 7 Let us fix n ∈ N and consider only independent, preemptable periodic tasks with Di = pi. If T is a set of n tasks satisfying UT ≤ n(21/n − 1), then UT is schedulable by RM algorithm. For every U > n(21/n − 1) there is a set T of n tasks satisfying UT ≤ U that is not schedulable by RM. 10 Schedulable Utilization for RM It follows that the maximum schedulable utilization URM over independent, preemptable periodic tasks satisfies URM = inf n n(21/n − 1) = lim n→∞ n(21/n − 1) = ln 2 ≈ 0.693 Note that UT ≤ n(21/n − 1) is a sufficient but not necessary condition for schedulability of T 11 Proof Sketch of Theorem 7 For the proof we need the following notions: A set of tasks is difficult-to-schedule if it is schedulable by RM but any increase in execution time and/or decrease in period makes the set unschedulable A set of tasks is most-difficult if its total utilization is smallest among all difficult to schedule sets Step 1. Show that for every difficult-to-schedule set there is another one whose utilization cannot be larger and 1. is in phase 2. satisfies pn ≤ 2p1 from this moment on we may concentrate on sets T satisfying 1. and 2. Step 2. For a fixed set of periods p1, . . . , pn, find the most-difficult set T with these periods, which gives U[p1, . . . , pn] := UT Step 3. Find T with the “most-difficult” values of periods p1, . . . , pn, that is minimize U[p1, . . . , pn], and show that UT = n(21/n − 1) 12 Proof Sketch of Theorem 7 – Step 2. Most-difficult in phase set with pn ≤ 2p1: 0 p1 2p1 0 p2 0 p3 0 pn−1 0 pn ... T3 T2 T1 Tn Tn−1 ek = pk+1 − pk for k = 1, . . . , n − 1 en = pn − 2 n−1 k=1 ek = 2p1 − pn 13 Time-Demand Analysis Assume that Di ≤ pi for every i. Compute the total demand for processor time by a job released at a critical instant of a task, and by all the higher-priority tasks, as a function of time from the critical instant Check if this demand can be met before the deadline of the job: Consider one task Ti at a time, starting with highest priority and working to lowest priority Focus on a job Ji,c in Ti, where the release time, t0, of that job is a critical instant of Ti At time t0 + t for t ≥ 0, the processor time demand wi(t) for this job and all higher-priority jobs released in [t0, t] is bounded by wi(t) = ei + i−1 k=1 t pk ek for 0 < t ≤ pi 14 Time-Demand Analysis Compare the time demand, wi(t), with the available time, t: If wi(t) ≤ t for some t ≤ Di, the job Ji,c released at critical instant of Ti meets its deadline, t0 + Di If wi(t) > t for all 0 < t ≤ Di, then the task probably cannot complete by its deadline; and the system likely cannot be scheduled using a fixed priority algorithm (Note that this condition is only sufficient as the expression for wi(t) relies on the fact that jobs of all higher priority tasks are released at the critical instant t0) Use this method to check that all tasks are schedulable if released at their critical instants; if so conclude the entire system can be scheduled 15 Time-Demand Analysis Example: T1 = (3, 1), T2 = (5, 1.5), T3 = (7, 1.25), T4 = (9, 0.5) 16 Time-Demand Analysis The time-demand function wi(t) is a staircase function Steps in the time-demand for a task occur at multiples of the period for higher-priority tasks The value of wi(t) − t linearly decreases from a step until the next step If our interest is the schedulability of a task, it suffices to check if wi(t) ≤ t at the time instants when a higher-priority job is released and at Di Our schedulability test becomes: Compute wi(t) Check whether wi(t) ≤ t for some t equal either to Di, or to j · pk where k = 1, 2, . . . , i and j = 1, 2, . . . , Di/pk 17 Time-Demand Analysis Time-demand analysis schedulability test is more complex than the schedulable utilization test but more general: Works for any fixed-priority scheduling algorithm, provided the tasks have short response time (Di ≤ pi) Can be extended to tasks with arbitrary deadlines Still more efficient than exhaustive simulation Only a sufficient test (as well as the utilization test for fixedpriority systems) 18 Real-Time Scheduling Priority-Driven Scheduling Aperiodic Tasks 19 Current Assumptions Single processor Fixed number, n, of independent periodic tasks Jobs can be preempted at any time and never suspend themselves No resource contentions Aperiodic jobs exist They are independent of each other, and of the periodic tasks They can be preempted at any time There are no sporadic jobs (for now) Jobs are scheduled using a priority driven algorithm 20 Scheduling Aperiodic Jobs Consider: A set T = {T1, . . . , Tn} of periodic tasks An aperiodic task A Recall that: A schedule is feasible if all jobs with hard real-time constraints complete before their deadlines ⇒ This includes all periodic jobs A scheduling algorithm is optimal if it always produces a feasible schedule whenever such a schedule exists, and if a cost function is given, minimizes the cost ⇒ We consider a cost function which to a schedule assigns the average response time of aperiodic jobs We assume that the periodic tasks can be scheduled using a priority-driven algorithm 21 Background Scheduling of Aperiodic Jobs Aperiodic jobs are scheduled and executed only at times when there are no periodic jobs ready for execution Advantages Clearly produces feasible schedules Extremely simple to implement Disadvantages Not optimal since it is almost guaranteed to delay execution of aperiodic jobs in favour of periodic ones Example: T1 = (3, 1), T2 = (10, 4) 22 Polled Execution of Aperiodic Jobs We may use a polling server A periodic job (ps, es) scheduled according to the periodic algorithm, generally as the highest priority job When executed, it examines the aperiodic job queue If an aperiodic job is in the queue, it is executed for up to es time units If the aperiodic queue is empty, the polling server self-suspends, giving up its execution slot The server does not wake-up once it has self-suspended, aperiodic jobs which become active during a period are not considered for execution until the next period begins Simple to prove correctness, performance less than ideal – executes aperiodic jobs in particular timeslots 23 Polled Execution of Aperiodic Jobs Example: T1 = (3, 1), T2 = (10, 4), poller = (2.5, 0.5) Can we do better? Yes, polling server is a special case of periodic-server for aperiodic jobs 24 Periodic Severs – Terminology periodic server = a task that behaves much like a periodic task, but is created for the purpose of executing aperiodic jobs A periodic server, TS = (pS, eS) pS is a period of the server eS is the (maximal) budget of the server The budget can be consumed and replenished; the budget is exhausted when it reaches 0 (Periodic servers differ in how they consume and replenish the budget) A periodic server is backlogged whenever the aperiodic job queue is non-empty idle if the queue is empty eligible if it is backlogged and the budget is not exhausted When a periodic server is eligible, it is scheduled as any other periodic task with parameters (pS, eS) 25 Periodic Severs Each periodic server is thus specified by consumption rules: How the budget is consumed replenishment rules: When and how the budget is replenished Example – polling server: consumption rules: Whenever the server executes, the budget is consumed at the rate one per unit time. Whenever the server becomes idle, the budget gets immediately exhausted replenishment rule: At each time instant k · pS replenish the budget to eS 26 Deferrable Sever Consumption rule: The budget is consumed at the rate of one per unit time whenever the server executes Unused budget is retained throughout the period, to be used whenever there are aperiodic jobs to execute (i.e. instead of discarding the budget if no aperiodic job to execute at start of period, keep in the hope a job arrives) Replenishment rule: The budget is set to eS at multiples of the period i.e. time instants k · pS for k = 0, 1, 2, . . . (Note that the server is not able tu cumulate the budget over periods) We consider both Fixed-priority scheduling Dynamic-priority scheduling (EDF) 27 Deferrable Server – RM Here the tasks are scheduled using RM. Is it possible to increase the budget of the server to 1.5 ? 28