Real-Time Scheduling Scheduling of Reactive Systems Priority-Driven Scheduling 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 Fixed-priority Algorithms – Rate Monotonic Best known fixed-priority algorithm is rate monotonic (RM) scheduling that assigns priorities to tasks based on their periods The shorter the period, the higher the priority The rate is the inverse of the period, so jobs with higher rate have higher priority RM is very widely studied and used The deadline monotonic (DM) algorithm assigns priorities to tasks based on their relative deadlines the shorter the deadline, the higher the priority 4 Rate Monotonic vs Deadline Monotonic T1 = (50, 50, 25, 100), T2 = (0, 62.5, 10, 20), T3 = (0, 125, 25, 50) Priorities: T2 T3 T1 DM is optimal: 50 100 150 200 250 0 62.5 125 187.5 250 0 125 250 20 82.5 145 207.5 50 175 T3 T2 T1 RM is not optimal: 50 100 150 200 250 0 62.5 125 187.5 250 0 125 250 20 82.5 145 207.5 50 175 T3 T2 T1 5 Dynamic-priority Algorithms Best known is earliest deadline first (EDF) that assigns priorities based on current deadlines At the time of a scheduling decision, the job queue is ordered by earliest deadline Example 1 T1 = (2, 1) and T2 = (5, 2.5) 0 1 2 3 4 5 6 7 8 9 10 T2 T1 6 Summary of Algorithms In what follows we consider Dynamic-priority algorithms: EDF Fixed-priority algorithms: RM and DM 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 7 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. That is 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. 8 Real-Time Scheduling Priority-Driven Scheduling Dynamic-Priority 9 Optimality of EDF Theorem 2 Let T be a set of independent, preemptable periodic tasks with Di ≥ pi. The following statements are equivalent: 1. T can be feasibly scheduled on one processor 2. total utilization UT of T is equal to or less than one 3. T is schedulable using EDF (i.e. UEDF = 1) Proof. 1.⇒2. We prove that UT > 1 implies that T is not schedulable (whiteb.) 2.⇒3. Whiteboard ... 3.⇒1. Trivial 10 Optimality of EDF – proof – 2.⇒3. 11 Optimality of EDF – proof – 2.⇒3. 12 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 3 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! 13 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 14 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 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 .... 15