Real-Time Scheduling Scheduling of Reactive Systems Priority-Driven Scheduling [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 vs Dynamic-Priority Algorithms A priority-driven scheduler is on-line i.e. it does not precompute a schedule of the tasks It assigns priorities to jobs after they are released and places the jobs in a ready job queue in the priority order with the highest priority jobs at the head of the queue At each scheduling decision time, the scheduler updates the ready job queue and then schedules and executes the job at the head of the queue i.e. one of the jobs with the highest priority Fixed-priority = all jobs in a task are assigned the same priority Dynamic-priority = jobs in a task may be assigned different priorities 3 Priority-Driven Algorithms Dynamic-priority: EDF = at the time of a scheduling decision, the job queue is ordered by the earliest deadline Fixed-priority: RM = assigns priorities to tasks based on their periods DM = assigns priorities to tasks based on their relative deadlines (In all cases, ties are broken arbitrarily.) We consider the following questions: Are the algorithms optimal? How to efficiently (or even online) test for schedulability? To measure abilities of scheduling algorithms and to get fast online tests of schedulability we use a notion of utilization 4 Utilization Utilization ui of a periodic task Ti with period pi and execution time ei is defined by ui := ei/pi ui is 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. If UT < UALG, then T is schedulable by ALG. If U > UALG, then there is T with UT ≤ U that is not schedulable by ALG. 5 Utilization – Example T1 = (2, 1) then u1 = 1 2 T1 = (11, 5, 2, 4) then u1 = 2 5 (i.e., the phase and deadline do not play any role) T = {T1, T2, T3} where T1 = (2, 1), T2 = (6, 1), T3 = (8, 3) then UT = 1 2 + 1 6 + 3 8 = 25 24 6 Real-Time Scheduling Priority-Driven Scheduling Dynamic-Priority 7 Optimality of EDF Theorem 1 Let T = {T1, . . . , Tn} be a set of independent, preemptable periodic tasks with Di ≥ pi for i = 1, . . . , n. The following statements are equivalent: 1. T can be feasibly scheduled on one processor 2. UT ≤ 1 3. T is schedulable using EDF (i.e., in particular, UEDF = 1) Proof. 1.⇒2. We prove that UT > 1 implies that T is not schedulable (whiteb.) 2.⇒3. Next slides and whiteboard ... 3.⇒1. Trivial 8 Proof of 2.⇒3. Notation: Given a set of tasks L, we denote by L the set of all jobs of the tasks in L. We prove ¬3.⇒ ¬2. assuming that Di = pi for i = 1, . . . , n (note that the general case immediately follows). Assume that T is not schedulable by EDF. We show that UT > 1. Suppose that a job Ji,k of Ti misses its deadline at time t = ri,k + pi. Let T be the set of all tasks whose jobs are released in [ri,k , t] (i.e., a task belongs to T iff at least one job of the task is released in [ri,k , t]). Let t− be the end of the latest interval before t in which either jobs of (T T ) are executed, or the processor is idle. Then ri,k ≥ t− since all jobs of (T T ) waiting for execution during [ri,k , t] have deadlines later than t (thus have lower priorities than Ji,k ). 9 Proof of 2.⇒3. (cont.) It follows that no job of (T T ) is executed in [t−, t], (by definition of t−) all jobs of T executed in [t−, t] are released in [t−, t] and have their deadlines in [t−, t], (since no job of T executes just before t−, and jobs with deadlines after t have lower priorities than Ji,k ) the processor is fully utilized in [t−, t]. (by definition of t−) Let G be the set of all jobs that are released in [t−, t] and have their deadlines in [t−, t]. Note that Ji,k ∈ G since ri,k ≥ t−. Since Ji,k misses its deadline, the processor should not be able to complete all jobs of G before t. Denote by EG the sum of all execution times of all jobs in G (the total execution time of G). It follows that EG > t − t− because otherwise, all jobs of G (in particular, Ji,k ) would complete in [t−, t]. 10 Proof of 2.⇒3. (cont.) How to compute EG? For T ∈ T , denote by R the earliest release time of a job in T during the interval [t−, t]. For every T ∈ T , exactly t−R p jobs of T belong to G. (For every T ∈ T T , exactly 0 jobs belong to G.) Thus EG = T ∈T t − R p e As argued above: t−t− < EG = T ∈T t − R p e ≤ T ∈T t − t− p e ≤ (t−t−) T ∈T u ≤ (t−t−)UT which implies that UT > 1. 11 Density and EDF What about tasks with Di < pi ? Density of a task Ti with period pi, execution time ei and relative deadline Di is defined by ei/ min(Di, pi) Total density ∆T of a set of tasks T is the sum of densities of tasks in T Note that if Di < pi for some i, then ∆T > UT Theorem 2 A set T of independent, preemptable, periodic tasks can be feasibly scheduled on one processor if ∆T ≤ 1. Note that this is NOT a necessary condition! (Example whiteb.) 12 Schedulability Test For EDF The problem: Given a set of independent, preemptable, periodic tasks T = {T1, . . . , Tn} where each Ti has a period pi, execution time ei, and relative deadline Di, decide whether T is schedulable by EDF. Solution using utilization and density: If pi ≤ Di for each i, then it suffices to decide whether UT ≤ 1. Otherwise, decide whether ∆T ≤ 1: If yes, then T is schedulable with EDF If not, then T does not have to be schedulable Note that Phases of tasks do not have to be specified Parameters may vary: increasing periods or deadlines, or decreasing execution times does not prevent schedulability 13 Schedulability Test for EDF – Example Consider a digital robot controller A control-law computation takes no more than 8 ms the sampling rate: 100 Hz, i.e. computes every 10 ms Feasible? Trivially yes .... Add Built-In Self-Test (BIST) maximum execution time 50 ms want a minimal period that is feasible (max one second) With 250 ms still feasible .... Add a telemetry task maximum execution time 15 ms want to minimize the deadline on telemetry period may be large Reducing BIST to once a second, deadline on telemetry may be set to 100 ms .... 14