Real-Time Systems, COSC-4301-01, Lecture 4 Stefan Andrei 4/13/2015 COSC-4301-01, Lecture 4 1 Reminder of the last lecture Sporadic tasks Scheduling nonpreemptable tasks Scheduling nonpreemptable sporadic tasks Scheduling nonpreemptable tasks with precedence constraints Communicating periodic tasks: deterministic rendezvous model 4/13/2015 COSC-4301-01, Lecture 4 2 Overview of This Lecture Multiprocessor scheduling Available scheduling tools Available real-time operating systems 4/13/2015 COSC-4301-01, Lecture 4 3 Multiprocessor scheduling Generalizing the scheduling problem from a uniprocessor to a multiprocessor system increases the problem complexity since we now have to tackle the problem of assigning tasks to specific processors. In fact, for two or more processors, no scheduling algorithm can be optimal without a priori knowledge of the: 1. 2. 3. 4/13/2015 Deadlines Computation times Start times of the tasks. COSC-4301-01, Lecture 4 4 Scheduling single-instance tasks Given n identical processors and m tasks at time i, m > n, our objective is to ensure that all tasks complete their execution by their respective deadlines. If m ≤ n (i.e., the number of tasks does not exceed the number of processors), the problem is trivial since each task has its own processor. 4/13/2015 COSC-4301-01, Lecture 4 5 Schedule representation Static schedule representations: Dynamic schedule representations: Gantt charts Timing diagrams Scheduling game boards [Dertouzos, Mok; 1989] Example of two-processor system (n=2) for three single-instance tasks: 4/13/2015 J1: S1 = 0, c1 = 1, D1 = 2 J2: S2 = 0, c2 = 2, D2 = 3 J3: S3 = 0, c3 = 4, D3 = 4 COSC-4301-01, Lecture 4 6 A Gantt chart for Example of slide 5 The below figure shows the Gantt chart of a feasible schedule for this task set. 4/13/2015 Figure 3.23 from [Cheng; 2005], page 66 COSC-4301-01, Lecture 4 7 A timing diagram for Example of slide 5 The below figure shows the timing diagram of a feasible schedule for this task set: 4/13/2015 Figure 3.24 from [Cheng; 2005], page 67 COSC-4301-01, Lecture 4 8 A game board for Example of slide 5 The below figure shows the scheduling game board representation of this task set at time i=0. The x-axis shows the laxity of a task and the yaxis shows its remaining computation time. Figure 3.25 from [Cheng; 2005], page 66 4/13/2015 COSC-4301-01, Lecture 4 9 Scheduling single-instance tasks with game board Let C(i) denote the remaining computation time of a task at time i, and let L(i) denote the laxity (slack) of a task at time i (i.e., L(i)=D(i)-C(i)-S(i)). On the L-C plane of the scheduling board, executing any n of the m tasks in parallel corresponds to moving at most n of the m tokens one division (time unit) downward and parallel to the C-axis. Thus, for tasks executed: L(i+1) = L(i), C(i+1)=C(i)-1 Tokens corresponding to the remaining tasks that are not executed move to the left toward the C-axis. Thus, for tasks not executed: 4/13/2015 L(i+1) = L(i)-1, C(i+1)=C(i) COSC-4301-01, Lecture 4 10 Rules for the Scheduling Game Board Each configuration of tokens on the L-C plane represents the scheduling problem at a point in time. The rules for the scheduling game are: Initially, the starting L-C plane configuration with tokens representing the tasks to be scheduled is given. At each step of the game, the scheduler can move at most n tokens one division downward toward the horizontal axis. The rest of the tokens move leftward toward the vertical axis. Any token reaching the horizontal axis can be ignored (it has completed its execution). The scheduler fails if any token crosses the vertical axis into the second quadrant before reaching the horizontal axis. The scheduler wins if no failure occurs. 4/13/2015 COSC-4301-01, Lecture 4 11 EDF scheduler fails (ex. From slide 5) Example of two-processor system (n=2) for three single-instance tasks: J1: S1 = 0, c1 = 1, D1 = 2 J2: S2 = 0, c2 = 2, D2 = 3 J3: S3 = 0, c3 = 4, D3 = 4 J1 and J2 have earlier absolute deadline, so they are assigned to start. Figure 3.26 from [Cheng; 2005], page 68 4/13/2015 COSC-4301-01, Lecture 4 12 LL scheduler wins (ex. From slide 5) At time 0, J3 has the lowest laxity, so it is assigned to start. The other one can be J1 (since it has same laxity as J2). Figure 3.27 from [Cheng; 2005], page 69 4/13/2015 COSC-4301-01, Lecture 4 13 Conflict-Free Task Sets For two or more processors, no deadline scheduling algorithm can be optimal without a priori knowledge of the deadlines, computations times, and start times of the tasks. If no such a priori knowledge is available, optimal scheduling is possible if the set of tasks does not have subsets of conflict with each another [Dertouzos, Mok; 1989]. A special case is that in which all tasks have unit computation times (then EDF algorithm is optimal even for the multiprocessor case). 4/13/2015 COSC-4301-01, Lecture 4 14 Conflict-Free Task Sets We divide the scheduling game board in 3 regions: R1(k)={Jj: Dj ≤ k} R2(k)={Jj: Lj ≤ k and Dj > k} R3(k)={Jj: Lj > k} where k is the number time units. Surplus computing power function: 4/13/2015 F(k,i)=kn-ΣR1Cj-ΣR2(k-Lj), for every positive integer k. COSC-4301-01, Lecture 4 15 A Necessary Condition for ConflictFree Task Sets F(k,i) provides a measure of the surplus computing power of the multiprocessor system in terms of available processor time units between a given time instant i and k time units into the future. A necessary condition for scheduling to meet the deadlines of a set of tasks whose start times are the same (at time i=0) is: 4/13/2015 For all k>0, F(k,0) ≥ 0. COSC-4301-01, Lecture 4 16 A Sufficient Condition for ConflictFree Task Sets Schedulability test 9: 4/13/2015 For a multiprocessor system, if a schedule exists that meets the deadlines of a set of singleinstance tasks whose start times are the same, then the same set of tasks can be scheduled at run-time even if their start times are different and not known a priori. Knowledge of pre-assigned deadlines and computation times alone is enough to schedule using LL-algorithm. COSC-4301-01, Lecture 4 17 Scheduling single-instance tasks. Example Let us consider the following preemptable single-instance task set: J1: S1 = 0, c1 = 1, D1 = 2 J2: S2 = 0, c2 = 2, D2 = 4 J3: S3 = 0, c3 = 4, D3 = 5 1. 2. 3. 4. 4/13/2015 how many processors do the above tasks set need to execute? check the applicability of EDF-scheduling method. draw a game board and check the applicability LL-scheduling method. check the applicability of schedulability test 9. COSC-4301-01, Lecture 4 18 Scheduling single-instance tasks. Example One processor does not suffice as at least one job will miss its deadline. Hence, there is a need of 2 processors to execute the given task set. 4/13/2015 COSC-4301-01, Lecture 4 19 Scheduling game board. EDF strategy. Initial state 4/13/2015 COSC-4301-01, Lecture 4 20 Scheduling game board. Time t=1(EDF) By EDF algorithm, J1 and J2 execute first since their absolute deadlines are earlier than J3. 4/13/2015 COSC-4301-01, Lecture 4 21 Scheduling game board. Time t=2(EDF) Since J2 reaches horizontal axis, it is completed. 4/13/2015 COSC-4301-01, Lecture 4 22 Scheduling game board. Time t=5(EDF) J2 completes its execution at time t=5. 4/13/2015 COSC-4301-01, Lecture 4 23 Scheduling game board. LL strategy. To check whether LL strategy works, we consider the scheduling board at the initial state (slide 20). At time t=0, both J1 and J3 have laxity 1. Hence J1 and J3 move downward (vertically) and J2 moves to the left (horizontally). 4/13/2015 COSC-4301-01, Lecture 4 24 Scheduling game board. Time t=1 (LL) At time t=1, J1 completes execution so the remaining tasks are J2 and J3. 4/13/2015 COSC-4301-01, Lecture 4 25 Scheduling game board. Time t=2 (LL) At time t=2, J2 and J3 again move downward. 4/13/2015 COSC-4301-01, Lecture 4 26 Scheduling game board. Time t=3 (LL) 4/13/2015 COSC-4301-01, Lecture 4 27 Scheduling game board. Time t=4 (LL) 4/13/2015 COSC-4301-01, Lecture 4 28 Schedulability test 9 applied to our example Since there is an LL schedule for the above task set, it means the task set can be scheduled at run-time even if their start times are different and not known a priori (using the LL-algorithm). 4/13/2015 COSC-4301-01, Lecture 4 29 Scheduling Periodic Tasks LL scheduler is optimal for a set of singleinstance tasks satisfying a sufficient condition. This makes it possible to schedule tasks without knowing their release times in advance. This LL scheduler is no longer optimal for periodic tasks. 4/13/2015 COSC-4301-01, Lecture 4 30 A Sufficient Condition for Scheduling Periodic Tasks Schedulability test 10: 4/13/2015 Given a set of k independent, preemptable (at discrete time instants), and periodic tasks on a multiprocessor system with n processors with U=c1/p1+…+ck/pk≤n, let T=GCD(p1, …, pk), and t=GCD(T,T(c1/p1), …, T(ck/pk)). A sufficient condition for feasible scheduling of this task set is t is integral. COSC-4301-01, Lecture 4 31 Scheduling Periodic Tasks. Example 1 Consider two processors (n=2) and four tasks (period = deadline): J1: c1=32, p1=40 J2: c2=3, p2=10 J3: c3=4, p3=20 J4: c4=7, p4=10. U=32/40+3/10+4/20+7/10=2 ≤ n T=GCD(40, 10, 20, 10) = 10 t=GCD(10, 10(32/40), 10(3/10), 10(4/20), 10(7/10)) = GCD(10, 8, 3, 2, 7)=1. Since 1 is integral, a feasible schedule exists for this tasks set (according to Schedulability test 10). 4/13/2015 COSC-4301-01, Lecture 4 32 A Feasible Schedule for Example 1 The tasks are assigned to processor 1 and “fill it up” until we encounter a task that cannot be scheduled on this processor. 4/13/2015 Figure 3.28 from [Cheng; 2005], page 71 COSC-4301-01, Lecture 4 33 Scheduling Periodic Tasks. Example 2 Let us consider the following preemptable, periodic, and independent task set: J1: c1=40, p1=50 J2: c2=4, p2=10 J3: c3=5, p3=25 J4: c4=6, p4=10. 1. 2. 3. 4. 4/13/2015 compute the utilization rate. check the applicability of schedulability test 10. find a feasible schedule for the above task set. if the above tasks are non-preemptable, is there any feasible schedule for it? COSC-4301-01, Lecture 4 34 Scheduling Periodic Tasks. Example 2 U = 2, hence two processors are needed to schedule the above task set. T = GCD(50, 10, 25, 10) = 5 t = GCD(T, T(c1/p1), T(c2/p2), T(c3/p3), T(c4/p4)) = GCD(5, 5*40/50, 5*4/10, 5*5/25, 5*6/10) = 1. Since the value of t is integral, a feasible schedule exists for this task. 4/13/2015 COSC-4301-01, Lecture 4 35 Scheduling Periodic Tasks. Example 2 Scheduling for preemptable task set using two processors and RM Scheduling algorithm: 4/13/2015 COSC-4301-01, Lecture 4 36 Scheduling Periodic Tasks. Example 2 Scheduling for non-preemptable task set using two processors: 4/13/2015 COSC-4301-01, Lecture 4 37 Available scheduling tools A variety of tools are available for scheduling and schedulability analysis of real-time tasks. Three of these are: 4/13/2015 PERTS (also called RAPID RMA) is downloadable from http://www.tripac.com/ PerfoRMAx is downloadable from http://www.aonix.com/ TimeWiz is downloadable from (n.t., obsolete) http://www.timesys.com/ COSC-4301-01, Lecture 4 38 Available real-time operating systems The goals of conventional, non-real-time operating systems are to provide a convenient interface between the user and the computer hardware while attempting to maximize average throughput, to minimize average time for tasks, and to ensure the fair and correct sharing of resources. However, meeting task deadlines is not an essential objective in non-real-time operating systems since its scheduler usually does not consider the deadlines of individual tasks when making scheduling decisions. 4/13/2015 COSC-4301-01, Lecture 4 39 Available real-time operating systems For real-time applications in which task deadlines must be satisfied, a real-time operating system (RTOS) with an appropriate scheduler for scheduling tasks with timing constraints must be used. Since the late 1980s, several experiments as well as commercial RTOSs have been developed, most of which are extensions and modifications of existing operating systems such as UNIX. Most current RTOSs conform to the IEEE POSIX standard and its real-time extensions. 4/13/2015 COSC-4301-01, Lecture 4 40 Commercial real-time operating systems LynxOS (http://www.lynx.com/) is Lynux’s hard RTOS based on the LINUX. It is scalable, Linux-compatible, and highly deterministic. RTMX O/S (http://www.rtmx.com/) has support for X11 and motif on M68K, MIPS, SPARC and PowerPC processors. VxWorks and pSOSystem (http://www.winddriver.com/products/html/os.ht ml) are Wind River’s RTOS’s with a flexible, scalable, and reliable architecture for most CPU platforms. 4/13/2015 COSC-4301-01, Lecture 4 41 Summary Multiprocessor scheduling Available scheduling tools Available real-time operating systems 4/13/2015 COSC-4301-01, Lecture 4 42 Reading suggestions From [Cheng; 2002] Chapter 3, sections 3.3, 3.4, 3.5 Chapters 3, 10 and 11 of [Kopetz; 1997] Chapter 2 of [Stankovic, Spuri, Ramamritham, Buttazzo; 1998] 4/13/2015 COSC-4301-01, Lecture 4 43 Coming up next SAT-based Scheduling 4/13/2015 COSC-4301-01, Lecture 4 44 Thank you for your attention! Questions? 4/13/2015 COSC-4301-01, Lecture 4 45