Download presentation
Presentation is loading. Please wait.
Published bySibyl Curtis Modified over 9 years ago
1
12/19/2015COSC-4301-01, Lecture 31 Real-Time Systems, COSC-4301-01, Lecture 3 Stefan Andrei
2
12/19/2015 COSC-4301-01, Lecture 3 2 1-2 Reminder of Last Lecture Real-Time Scheduling and schedulability analysis Schedulability test Schedulability utilization Optimal scheduler Determining computation time Uniprocessor scheduling Scheduling preemptable and independent tasks Fixed-priority schedulers: RM, DM Dynamic-priority schedulers: EDF, LL
3
12/19/2015 COSC-4301-01, Lecture 3 3 Overview of this lecture Sporadic tasks Scheduling nonpreemptable tasks Scheduling nonpreemptable sporadic tasks Scheduling nonpreemptable tasks with precedence constraints Communicating periodic tasks: deterministic rendezvous model Chapter 3 of [Cheng; 2002], Sections 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5
4
12/19/2015 COSC-4301-01, Lecture 3 4 Sporadic tasks Sporadic tasks may be released at any time instant, but a minimum separation exists between releases of consecutive instances of the same sporadic task. Can be modeled by periodic tasks with periods equal to the minimum separation. In this way, we can re-use the previous scheduling algorithms.
5
12/19/2015 COSC-4301-01, Lecture 3 5 Sporadic tasks (comparison with periodic tasks) Unlike periodic tasks, sporadic tasks are released irregularly or may not be released at all. So, even though the scheduler allocates a time slice to the periodic equivalent of a sporadic task, this sporadic task may not actually be released. When this sporadic task does request service, it immediately runs if its release time is within its corresponding scheduled time slice. Otherwise, it waits for the next scheduled time slice for running its periodic equivalent.
6
12/19/2015 COSC-4301-01, Lecture 3 6 Example 1 Two periodic tasks J 1 and J 2 arriving at time 0, and one sporadic task J 3 with minimum separation time of 60. J 1 : c 1 = 10, p 1 = 50 J 2 : c 2 = 15, p 2 = 80 J 3 : c 3 = 20, p 3 = 60 A RM schedule is given below: Figure 3.9 from [Cheng; 2005], page 56
7
12/19/2015 COSC-4301-01, Lecture 3 7 The second approach Treat sporadic tasks as one periodic task J S with the highest priority and a period chosen to accommodate the minimum separations and computation requirements of this collection of sporadic tasks. Any sporadic task may run within the time slices assigned to J S while the other periodic tasks run outside of these time slices. Example: J S : c S = 20, p S = 60 Figure 3.10 from [Cheng; 2005], page 57
8
12/19/2015 COSC-4301-01, Lecture 3 8 The third approach Deferred server (DS) [Lehosczky, Sha, Strosnider; 1987] DS is similar to second approach, with the modification: The periodic task corresponding to the collection of sporadic tasks is the deferred server. When no sporadic task waits for service during a time slice assigned to sporadic tasks, the processor runs the other (periodic) tasks. If a sporadic task is released, then the processor preempts the currently running task and runs the sporadic task for a time interval up to the total time slice assigned to sporadic tasks.
9
12/19/2015 COSC-4301-01, Lecture 3 9 Deferred server technique. Example J S : c S = 20, p S = 60 Deferred server scheduler allocates 20 time units to sporadic tasks every 60 time units. Suppose a sporadic task J 1 arrives with c 1 = 30 at time 20. Since only 20 time units are available in each period of 60 time units, it is scheduled to run from time 20 and preempted at time 40 (periodic tasks may run for the rest of 20 units). Then at time 60 (the start of second period of 60 time units), J 1 is scheduled to run for the other remaining 10 time units.
10
12/19/2015 COSC-4301-01, Lecture 3 10 Deferred server technique. Example (cont) Suppose a sporadic task J 2 arrives with c 2 = 50 at time 100 (because J 1 is also a sporadic task that uses 10 time units from the time of 20 units allocated to 60-120). Since only 10 time units are still available in the second period of 60 time units, it is immediately scheduled to run (for period 60-120, only 20 units are deferred to sporadic tasks). At time 110, it is preempted (other periodic tasks may run). At time 120, J 2 runs for 20 time units, and at time 180, J 2 runs for the remaining 20 time units. Figure 3.11 from [Cheng; 2005], page 57
11
12/19/2015 COSC-4301-01, Lecture 3 11 Analytical approach of sporadic tasks For a deferred server with an arbitrary priority in a system of tasks scheduled using RM algorithm, no schedulable utilization is known that guarantees a feasible scheduling of the system. However, for the special case in which DS has the shortest period among all tasks (that is, DS has the highest priority), a schedulable utilization exists: Schedulability Test 7 [Lehosczky, Sha, Strosnider; 1987], [Strosnider, Lehosczky; 1995]
12
12/19/2015 COSC-4301-01, Lecture 3 12 Schedulability test 7 Let p S and c S be the period and allocated time for the DS. Let U S =c S /p S be the utilization of the server. A set of n independent, preemptable, and sporadic tasks with relative deadlines the same as the corresponding periods on a uniprocessor such that p S p S + c S, is RM-schedulable if the total utilization of this task set is at most U(n) = (n-1) [((U S +2)/(U S +1)) (1/(n-1)) -1].
13
12/19/2015 COSC-4301-01, Lecture 3 13 Schedulability test 7. Example 1 J 1 : c 1 = 10, p 1 = 50 J 2 : c 2 = 15, p 2 = 70 J S : c S = 10, p S = 40 U S =c S /p S = 0.25 p S < p 1 < …< p n < 2p S holds (n=2). p n > p S + c S holds. U(n) = (n-1) [((U S +2)/(U S +1)) (1/(n-1)) -1]=0.80 The total utilization of this task set is U=0.664, that is less than U(n). According to Schedulability test 7, the above task set is RM-schedulable.
14
12/19/2015 COSC-4301-01, Lecture 3 14 Schedulability test 7. Example 2 Let us consider the following preemptable task set (J S is a sporadic task): J 1 : S 1 = 0, c 1 = 1, p 1 = d 1 = 5 J 2 : S 2 = 0, c 2 = 2, p 2 = d 2 = 7 J S : S S = 0, c S = 1, p S = d S = 4 1. compute the utilization rate. 2. check the applicability of RM-scheduling method based on schedulability test 7. 3. run the RM-scheduler for the above task set.
15
12/19/2015 COSC-4301-01, Lecture 3 15 Schedulability test 7. Example 2 U = 0.735… According to schedulability test 7, the following conditions should be hold: p s <p 1 <p 2 <…< p n < 2p s translates to 4 < 5 < 7 < … < 8 (TRUE) p n > p s + c s translates to 7 > 4 + 1 (TRUE) Also, U(n) = (n-1) [((U S +2)/(U S +1))(1/(n-1))-1], where U S =1/4=0.25. Therefore U(n) = 0.80, so U < U(n) (TRUE) Hence, schedulability test 7 can be applied to the above task set.
16
12/19/2015 COSC-4301-01, Lecture 3 16 Schedulability test 7. Example 2 The RM schedule is: 0 5 101520253035 Js J2 J1
17
12/19/2015 COSC-4301-01, Lecture 3 17 Scheduling non-preemptable tasks So far we have assumed that tasks can be preempted at any integer time instants. In practice, tasks may contain critical sections that cannot be interrupted. Examples of critical sections: Access and modify shared variables; Use shared resources (e.g., disks, printer). An important goal is to reduce task waiting time and context-switching time – [Lee, Cheng; 1994].
18
12/19/2015 COSC-4301-01, Lecture 3 18 Scheduling non-preemptable tasks Using fixed-priority schedulers for non-real-time tasks may potentially lead to the priority inversion problem [Sha, Rajkumar, Lehoczky; 1990] which occurs when a low-priority task with a critical section blocks a higher-priority task for an unbounded or long period of time. The EDF and LL algorithms are no longer optimal if the tasks are not preemptable. However, if all the tasks start at time 0, then EDF technique is still optimal. So, an EDF algorithm may fail to meet a deadline of a task set S even if another scheduler can produce a feasible schedule for S (if starting time is not 0).
19
12/19/2015 COSC-4301-01, Lecture 3 19 Optimality for non-preemptable tasks Without preemption, we cannot transform a non-EDF schedule into an EDF schedule by interchanging computation blocks of different tasks. No priority-based scheduling algorithm is optimal for non-preemptable tasks with arbitrary start times, computation times, and deadlines, even on a uniprocessor [Mok; 1984].
20
Scheduling non-preemptive task sets When preemption is not allowed, the scheduling problem is known to be NP- complete. However, if only non-idling schedulers are considered (all tasks have their start times = 0), the problem is again tractable: (Theorem 3.4, page 30 from [Stankovic et. Al., 1997]) Non-preemptive non-idling EDF is optimal. 12/19/2015 COSC-4301-01, Lecture 3 20
21
12/19/2015 COSC-4301-01, Lecture 3 21 Scheduling non-preemptable sporadic tasks We transform the sporadic tasks into equivalent periodic tasks. A sporadic task (c, d, p) can be transformed into and scheduled as a periodic task (c’, d’, p’) if the following conditions hold: d ≥ d’ ≥ c c’ = c p’ ≤ d – d’ + 1 A proof can be found in [Mok; 1984].
22
12/19/2015 COSC-4301-01, Lecture 3 22 Schedulability test 8 [Mok; 1984] Let M = M P M S be the set of all non-preemptable tasks, where M P is the set of periodic tasks, and M S is the set of sporadic tasks. Let the nominal (initial) laxity l i of task T i be d i -c i. Each sporadic task T i be (c i, d i, p i ) is replaced by an equivalent periodic task T’ i = (c’ i, d’ i, p’ i ) as follows: c’ i = c i, d’ i = c i, p’ i = min(p i, l i +1). If we can find a feasible schedule for the resulting set M’ of periodic tasks, we can schedule M without knowing in advance the start (release or request) time of the sporadic tasks in M S.
23
12/19/2015 COSC-4301-01, Lecture 3 23 Schedulability test 8. Example Let us consider the following non- preemptable task set (J S is a sporadic task): J 1 : S 1 = 0, c 1 = 2, p 1 = d 1 = 5 J 2 : S 2 = 0, c 2 = 2, p 2 = d 2 = 8 J S : S S = 0, c S = 2, p S = d S = 8 1. compute the utilization rate. 2. check the applicability of RM-scheduling method based on schedulability test 8.
24
12/19/2015 COSC-4301-01, Lecture 3 24 Schedulability test 8. Example U = 0.9 The laxity: l = d s - c s = 8 – 2 = 6. Now, replacing the sporadic task J s = (c s, d s, p s ) with equivalent periodic task J s’ = (c s’, d s’, p s’ ), where c s’ = c s =2, d s’ = c s =2, p s’ =min(p s, l s + 1) = min(8, 6+1) =7. So, the new sporadic task as an equivalent periodic task is J S’ : S S’ = 0, c S’ = 2, p S’ =7, d S’ = 2.
25
12/19/2015 COSC-4301-01, Lecture 3 25 Schedulability test 8. Example Let us check the condition for schedulability test 8. d>=d’ means 8>=2 (TRUE) c’=c means 2=2 (TRUE) p’ <= d-d’+1 means 7 <= 8-2+1 (TRUE) Since all the conditions hold true, schedulability test 8 can be applied to the above task set.
26
12/19/2015 COSC-4301-01, Lecture 3 26 Scheduling non-preemptable tasks with precedence constraints We introduce precedence and mutual exclusion (nonpreemption) constraints to the scheduling problem for single-instance tasks (tasks that are neither periodic nor sporadic) on a uniprocessor. A task precedence graph shows the required order of execution of a set of tasks. A node represents a task (e.g., T i ) and directed edges (e.g., ) indicate the precedence relationships between tasks. An edge T i T j means that T i must complete before T j can start. For a task T i, incoming edges from predecessor tasks indicate all these predecessor tasks have to complete execution before T i can start execution; outgoing edges to successor tasks indicate that T i must finish execution before the successor tasks can start execution.
27
12/19/2015 COSC-4301-01, Lecture 3 27 Scheduling algorithm A for tasks with precedence constraints A topological ordering of the tasks in a precedence graph shows one allowable execution order of these tasks. Suppose we have a set of n one-instance tasks with deadlines, all ready at time 0 and with precedence constraints described by a precedence graph. Algorithm A: 1. Sort the tasks in the precedence graph in topological order (so tasks with no in-edges come first). If two or more tasks can be listed next, select the one with the earliest deadline, ties are broken arbitrarily; 2. Execute tasks one at a time following this topological order.
28
12/19/2015 COSC-4301-01, Lecture 3 28 Algorithm A. Example 1 Consider the set of tasks {T 1, T 2, T 3, T 4, T 5, T 6 } with the following: precedence constraints: T 1 T 2, T 1 T 3, T 2 T 4, T 2 T 6, T 3 T 5, T 3 T 4, T 4 T 6 Computation times and deadlines: T 1 : c 1 = 2, d 1 = 4, T 2 : c 2 = 3, d 2 = 7, T 3 : c 3 = 2, d 3 = 10, T 4 : c 4 = 8, d 4 = 18, T 5 : c 5 = 6, d 5 = 24, T 6 : c 6 = 4, d 6 = 28.
29
12/19/2015 COSC-4301-01, Lecture 3 29 Algorithm A. Example 1 (cont) The precedence graph is: Figure 3.14 from [Cheng; 2005], page 60 The EDF-schedule for tasks with precedence constraints is: Figure 3.16 from [Cheng; 2005], page 61
30
12/19/2015 COSC-4301-01, Lecture 3 30 Algorithm B Is a variation of Algorithm A by: Considering the task with the latest deadline first Shifting the entire schedule toward 0. Algorithm B: 1. Sort the tasks according to their deadlines in non-decreasing order and label the tasks such that d 1 ≤ d 2 ≤ … ≤ d n. 2. Schedule task T n in the time interval [d n – c n, d n ] 3. While there is a task to be scheduled do Suppose S is the set of all unscheduled tasks whose successors have been scheduled. Schedule as late as possible the task with the latest deadline in S. 4. Shift the tasks toward time 0 while maintaining the execution order indicated at step 3.
31
12/19/2015 COSC-4301-01, Lecture 3 31 Refinement of Algorithm B Given a task set T={T 1, …, T n }, let us denote by set i the “starting execution time” for T i: task T i executes in time interval [set i, set i + c i ], where c i is its computation time; 1. Sort the tasks according to their deadlines in non-decreasing order and label the tasks such that d 1 ≤ d 2 ≤ … ≤ d n. 2. set n = d n – c n ; // Schedule T n in the time interval [d n – c n, d n ] 3. for (i = n – 1; i > 0; i--) set i = min{d i – c i, set i+1 – c i }; 4. shift = set 1 ; 5. for (i = 1; i <= n; i++) { 1. old_set i = set i ; 2. set i = set i – shift; // Schedule T n in the interval [set i, set i +c i ] 3. if (i < n) shift = shift + set i+1 – (old_set i + c i ); 6. }
32
12/19/2015 COSC-4301-01, Lecture 3 32 Algorithm B. Example 1 We re-consider the same example from slide 19, so the first three steps of Algorithm B gives: Figure 3.15 from [Cheng; 2005], page 61 The schedule for tasks with precedence constraints after shifting tasks is: Figure 3.16 from [Cheng; 2005], page 61
33
12/19/2015 COSC-4301-01, Lecture 3 33 Algorithms A, B. Example 2 Let us consider the set of non-preemptable tasks T = {J 1, J 2, J 3, J 4 } with the following: precedence constraints: J 1 J 2, J 1 J 3, J 2 J 4, J 3 J 4 computation times and deadlines: J 1 : c 1 = 2, d 1 = 5, J 2 : c 2 = 3, d 2 = 7, J 3 : c 3 = 2, d 3 = 10, J 4 : c 4 = 8, d 4 = 18, 1. compute the task precedence graph. 2. investigate the applicability of Algorithms A and B to T.
34
12/19/2015 COSC-4301-01, Lecture 3 34 Algorithms A, B. Example 2 The task precedence graph is:
35
12/19/2015 COSC-4301-01, Lecture 3 35 Algorithm A. Example 2 The EDF schedule for this task set with the precedence constraints:
36
12/19/2015 COSC-4301-01, Lecture 3 36 Algorithm B. Example 2 According to Algorithm B, the tasks are sorted in non decreasing order and tasks are labeled such that d 1 < d 2 < … < d n and tasks are scheduled in interval [d n -c n ]. Running the refinement of Algorithm B, we get: set 4 = 10, set 3 = 8, set 2 = 4, set 1 = 2 shift = 2, set 1 = 0, shift = 2, set 2 = 2, shift = 3, set 3 = 5, shift = 3, set 4 = 7.
37
12/19/2015 COSC-4301-01, Lecture 3 37 Communicating periodic tasks: deterministic rendezvous model Allowing tasks to communicate each other complicates the scheduling problem. Interprocess communication leads to precedence constraints not only between tasks but also between blocks within these tasks. Example: Ada programming language provides the primitive rendezvous() to allow one task to communicate with another at a specific point during the task execution. Ada is used in the implementation of a variety of embedded and real-time systems, including airplane avionics.
38
12/19/2015 COSC-4301-01, Lecture 3 38 Deterministic rendezvous model If a task A wants to communicate with task B, then task A executes rendezvous( B ). Task A then waits until task B executes a corresponding rendezvous( A ). As a result, this pair of rendezvous() imposes a precedence constraint between the computations of tasks A and B by requiring all the computations prior to the rendezvous() primitive in each task be completed before the computations prior to the rendezvous() primitive in the other task can start. To simplify the scheduling strategy, we consider the execution time of a rendezvous() primitive is zero or that its execution time is included in the preceding computation block.
39
12/19/2015 COSC-4301-01, Lecture 3 39 Deterministic rendezvous model (cont) A one-instance task can rendezvous with another one-instance task. However, it is semantically incorrect to allow a periodic task and a sporadic task to rendezvous with each other since the sporadic task may not run at all, causing the periodic task to wait forever for the matching rendezvous. Two periodic tasks may rendezvous with each other, but there are constraints on the lengths of their periods to ensure correctness.
40
12/19/2015 COSC-4301-01, Lecture 3 40 Deterministic rendezvous model (cont) Two tasks are compatible if their periods are multiples of each other. To allow two (periodic) tasks to communicate in any form, they must be compatible. One attempt to schedule compatible and communicating tasks is to use the EDF scheduler to execute the ready task with the nearest deadline that is not blocked due to a rendezvous. The solution [Mok; 1983] to this scheduling problem starts by building a database for the runtime scheduler so that EDF algorithm can be used with dynamically assigned task deadline.
41
12/19/2015 COSC-4301-01, Lecture 3 41 Deterministic rendezvous model (cont) Let L be the longest period. Since the communicating tasks are compatible, L is the same as the LCM (Lowest Common Multiple) of these tasks’ periods. We denote a chain of scheduling blocks generated in chronological order for task T i in interval (0, L) by T i (1), T i (2), …, T i (m i ).
42
12/19/2015 COSC-4301-01, Lecture 3 42 Deterministic rendezvous model (cont) If there is a rendezvous constraint with T i targeting T j between T i (k) and T i (k + 1), T j (l) and T j (l + 1), then the following precedence relations are specified: T i (k) T j (l + 1), T j (l) T i (k + 1), Within each task, the precedence constraints between blocks are: T i (1) T i (2) … T i (m i ).
43
12/19/2015 COSC-4301-01, Lecture 3 43 Deterministic rendezvous model. Example T 1 : c 1 = 1, d 1 = p 1 = 12. T 2 : c 2, 1 = 1, c 2, 2 = 2, d 2 = 5, p 2 = 6. T 3 : c 3, 1 = 2, c 3, 2 = 3, d 3 = p 3 = 12. T 2 must rendezvouz with T 3 after the first scheduling block. T 3 must rendezvouz with T 2 after the first and second scheduling blocks.
44
12/19/2015 COSC-4301-01, Lecture 3 44 Deterministic rendezvous model. Example’s solution L = 12 The precedence constraints between blocks are: T 2 (1) T 2 (2) T 2 (3) T 2 (4) T 3 (1) T 3 (2) Rendezvous constraints with T 2 (1) targeting T 3 (1): T 2 (1) T 3 (2), T 3 (1) T 2 (2) Rendezvous constraints with T 2 (2) targeting T 3 (2): T 2 (2) T 3 (3), T 3 (2) T 2 (3)
45
12/19/2015 COSC-4301-01, Lecture 3 45 Deterministic rendezvous model. Example’s solution The EDF scheduler will provide the schedule (the first and second occurrences of T 2,1 stands for T 2 (1) and T 2 (3), respectively, etc): Figure 3.18 from [Cheng; 2005], page 63 The solution is infeasible because T 2 (2) should be before 5 time units, and T 2 (4) should be before 5+6=11 time units.
46
12/19/2015 COSC-4301-01, Lecture 3 46 Deterministic rendezvous model (cont) Algorithm for revising the deadlines to fix the previous infeasibility decision: 1. Sort the scheduling blocks in [0, L] in reverse topological order, so the block with the latest deadline appears first. 2. Initialize the deadline of the k-th instance of T i,j with (k-1)p i +d i. 3. Let S and S’ be scheduling tasks. Then revise d S = min(d S, {d S’ - c S’ : S S’}). 4. Use the EDF scheduler to schedule the blocks with the revised deadlines.
47
12/19/2015 COSC-4301-01, Lecture 3 47 Deterministic rendezvous model. Example’s second solution We consider the previous example. The initial deadlines for T 1, T 3,1, T 3,2, T 2,3, T 2,4, T 2,1, T 2,2 are 12, 12, 12, 11, 11, 5, and 5, respectively (in topological order). Since T 3 (1) T 2 (2) is a rendezvous constraint, then deadline of T 3,1 is revised to 5-2=3. Similarly, since T 3 (2) T 2 (3) is a rendezvous constraint, then deadline of T 3,2 is revised to 11- 1=10.
48
12/19/2015 COSC-4301-01, Lecture 3 48 Deterministic rendezvous model. Example’s second solution The revised deadlines for T 1, T 3,1, T 3,2, T 2,3, T 2,4, T 2,1, T 2,2 are now 12, 3, 10, 9, 11, 3, and 5, respectively. Using again the EDF scheduler, we get the following feasible schedule: Figure 3.19 from [Cheng; 2005], page 64
49
12/19/2015 COSC-4301-01, Lecture 3 49 Summary Sporadic tasks Scheduling nonpreemptable tasks Scheduling nonpreemptable sporadic tasks Scheduling nonpreemptable tasks with precedence constraints Communicating periodic tasks: deterministic rendezvous model
50
12/19/2015 COSC-4301-01, Lecture 3 50 Reading suggestions Chapter 3 of [Cheng; 2002], Sections 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5 Chapters 3, 10 and 11 of [Kopetz; 1997] Chapter 2 of [Stankovic, Spuri, Ramamritham, Buttazzo; 1998]
51
12/19/2015 COSC-4301-01, Lecture 3 51 Coming up next Multiprocessor scheduling Available scheduling tools Available real-time operating systems Chapter 3 of [Cheng; 2002], Sections 3.3, 3.4, 3.5
52
12/19/2015 COSC-4301-01, Lecture 3 52 Thank you for your attention! Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.