Lecture 6: Real-Time Scheduling Advanced Operating System Fall 2012
Real-Time Scheduling A real-time task is defined to be one in which there is a hard deadline to meet; failure to meet the deadline can lead to disaster. Example of real-time task include process control such as a nuclear reactor, automatic flight control, etc. Real-time tasks can be classified as periodic or aperiodic. Periodic: the processes are considered to be periodic if they require CPU at constant intervals (periods). Each periodic process has a fixed processing time ei once it acquires the CPU, a deadline di when it must be serviced by the CPU, and a period pi. The relationship of the processing time, the deadline and the period can be expressed as 0≤ei ≤di ≤pi. The rate of a periodic task is 1/pi. Aperiodic tasks are tasks that come in at random times. However, when it makes a request, it is guaranteed that it will not make a request until some time p later.
Real-Time CPU Scheduling Periodic: the processes are considered to be periodic if they require CPU at constant intervals (periods). Each periodic process has a fixed processing time ei once it acquires the CPU, a deadline di when it must be serviced by the CPU, and a period pi. The relationship of the processing time, the deadline and the period can be expressed as 0≤ei ≤di ≤pi. The rate of a periodic task is 1/pi.
Aperiodic tasks Aperiodic tasks are tasks that come in at random times. However, when it makes a request, it is guaranteed that it will not make a request until some time p later.
Rate-Monotonic Scheduling The rate-monotonic scheduling algorithm schedules periodic tasks using a static priority policy with preemption. If a lower-priority process is running and a higher-priority process becomes available to run, it will preempt the lower-priority process. For each process, its priority=1/pi(inverse of the period). The rationale behind this policy is to assign a higher priority to tasks that require the CPU more often. Assumption: the processing time of a periodic process is the same for each CPU burst. Severe constraints: processes must be periodic, independent and have deadline equal to period. All processes have an initial release at time 0.
Rate-Monotonic Scheduling: example Ti si di pi ei T1 2 3 1 T2 4 1.2 T3 0.3 Si: initial start time di: relative deadline pi: period i ei: maximum execution time Priority: T1: 1/3; T2: ¼; T3: ¼; T1: 0, 3, 6, 9, 12, … T2: 1, 5, 9, 13, … T3: 0, 4, 8, 12, … T1 T2 T3 /// 1 2.2 2.5 3.0 4.0 4.3 5.0 6.0 7.0 7.2 8.0 8.3 9.0 10 11.2 12 …
Rate-Monotonic Scheduling Rate-Monotonic scheduling algorithm is considered optimal in the sense that if a set of processes cannot be scheduled by this algorithm, it cannot be scheduled by any other algorithm that assigns static priorities. Despite being optimal, then rate-monotonic scheduling has a limitation: CPU utilization is bounded, and it is not always possible to fully maximize CPU resources. The worst-case CPU utilization for scheduling N processes is As the number of processes approaches infinity, CPU utilization falls approximately 69%. Feasibility test: Two processes: CPU utilization is bounded about 83%. Sufficient condition: If there are two processes to be scheduled and the combined CPU utilization is less than 83%, then the Rate-Monotonic scheduling algorithm is guaranteed to schedule them so that they can meet their deadline. Otherwise, it is inclusive. The above condition is not necessary condition: Example Task 1: Execution time: 2, Period: 4; Task 2: Execution time: 4, Period: 8. Can be scheduled by DM scheduling algorithm, CPU utilization is 100%.
Earliest-Deadline-First Scheduling (EDF) Earliest-Deadline-First scheduling dynamically assigns priorities according to deadline. The earliest the deadline, the higher the priority. Algorithm: At each moment of time t, schedule the task whose deadline is closest to t. Ties can be resolved arbitrarily. EDF scheduling does not require that processes be periodic, nor must a process require a constant amount of CPU time per burst. The only requirement is that a process announce its deadline to the scheduler when it becomes runnable. EDF scheduling is theoretically optimal – theoretically, it can schedule processes so that each process can meet its deadline requirements and CPU utilization will be 100 percent. In practice, however, it is impossible to achieve this level of CPU utilization due to the cost of context switching between processes and interrupt handling.
Earliest-Deadline-First Scheduling (EDF): Example Ti di pi ei T1 2 3 1 T2 4 1.2 T3 0.3 T1 makes a request at some unpredictable time. But if it makes a request at time t, then it is guaranteed that it will not make a request again at time t+3. The current request is expected to complete at time t+2, and it will take 1 time unit to finish. T1: 0, 3, 6, 9, 12, … T2: 1, 5, 9, 13, … T3: 0, 4, 8, 12, … T1 T2 T3 /// 1 2.2 2.5 3.0 4.0 4.3 5.0 6.0 7.0 7.2 8.0 8.3 9.0 10 11.2 12 …
Example: Ti si di pi ei T1 50 25 T2 80 35 50 25 T2 80 35 Rate-monotonic scheduling: misses deadlines Earliest-Deadline-First scheduling:
Feasibility Test for EDF alg.: Necessary condition: is a necessary (but not sufficient condition) for a feasible schedule. Example: Since we can have feasible schedule for the above example, this condition holds. Sufficient condition: is a sufficient (but not necessary condition) for a feasible schedule. Example: Since in the above example, we have: ½+1.2/3+ 0.3/4=0.5+0.4+0.075=0.975, sufficient condition holds, so we are sure that there exists feasible schedule. If it satisfies necessary condition, but fails sufficient condition, we cannot be sure. However, there is a procedure to determine. Too complicated to explain.
Feasibility Test for EDF alg.: We can always test the feasibility by constructing a schedule using EDF algorithm from 0 until some time T and check if all deadlines within [0, T] are met and certain condition satisfied. Two cases: Suppose si=sj=0 for any i and j, run EDF alg from 0 to T=LCM{p1, p2, …, pn}, if all deadlines are met, then feasible; otherwise, not feasible. Suppose si≠sj for any i and j, construct a schedule from time 0 until time t2=S+2T, where S=max{s1, s2, …, sn}, and T=LCM{p1,p2,…, pn}, if all deadlines in [0, t2] are met, then feasible; otherwise, not feasible.
Deadline-Monotonic Algorithm (DM) Working for both periodic tasks and Aperiodic tasks. Fixed-priority Uses relative deadlines: the shorter the relative deadline, the higher the priority RM and DM are identical if the relative deadline is proportional to its period Otherwise DM performs better in the sense that it can sometimes produce a feasible schedule when RM fails, while RM always fails when DM fails Feasibility Test: T = {T1, T2, ..., Tn}, ordered by priority (i < j, i < j) Sufficient condition: for any i: 1≤i ≤n,
DM example t1 : e1 = 2, d1 = 3, p1 = 5 t2 : e2 = 2, d2 = 6, p2 = 15
Reference Leung, J. Y-T. and J. Whitehead, "On the Complexity of Fixed-Priority Scheduling of Periodic, Real-Time Tasks," Performance Evaluation, 2:237-250, 1982. Also in Proc. of the 18th Annual Allerton Conference on Communication, Control, and Computing, 464-470, Urbana-Champaign, IL, 1980. Leung, J. Y-T. and M. L. Merrill, "A Note on Preemptive Scheduling of Periodic, Real-Time Tasks," Information Processing Letters, 11:115-118, 1980.
End of lecture 6 Thank you!