Scheduling with Relative Timing Constraints Manas Saksena, Richard Gerber and Ashok Agrawala Department of Computer Science University of Maryland College Park, MD 20742 fmanas,rich,
[email protected]
1 Introduction Real-time systems often possess relative timing constraints, in which operations are temporally dependent
on each other. These constraints are usually described in (or derived from) the system speci cation, which contains clauses such as 1. Move the robot arm within 10s of an object being detected. 2. Wait at least 50s between sending two messages.
Timing speci cations are event-based, and they establish many such minimum/maximum constrained relationships between occurrences of events [2, 9]. However, when a speci cation is realized in an application program, eventdriven constraints are usually translated into equivalent relationships between the start and nish times of tasks. This helps ease the process of scheduling the tasks, and then dispatching them to guarantee that the constraints will hold. Many experimental real-time languages such as DPS [10], Flex [11], MPL [13] and RTC [16] provide constructs in the language in which such constraints may be speci ed. TCEL [8] uses a similar syntax but provides dierent semantics, consistent with the event based speci cation. These languages are suciently powerful to express the functionality of any real-time application. Unfortunately, modern scheduling techniques are incapable of statically guaranteeing such constraints, and thus, rely on run time exceptions, whenever a constraint cannot be met. We are addressing the problem of scheduling a set of tasks for which relative timing constraints must be ensured. Most of the previous work in real-time scheduling has concentrated on scheduling a set of tasks with ready times and deadlines. Such constraints impose constant intervals in which the each task must be executed. For such a set of constraints, it is sucient to schedule using the worst case execution time estimates. However, for
scheduling with relative constraints, the non-determinism in execution times must be taken into account to ensure that the timing constraints are satis ed. We incorporate this non-determinism in our model, and simply assume that execution time can be bounded from above and below. This is a realistic assumption, especially since several tools have been developed to generate these bounds [12,14,15]. Han and Lin have considered the problem of nonpreemptive scheduling of a partially ordered task set, with unit execution times for tasks. In addition to the absolute constraints, relative deadlines are also allowed [7]. For general partial orders, the problem has been shown to be NP-Complete. However, for the special case of multi-level chains of tasks, where only the head task in each chain has an absolute deadline, and each task has a deadline relative to its immediate predecessor, an O(n2) time algorithm has been presented. Similar results have been obtained for tasks with relative separation constraints [5]. In other work [6], Han and Lin propose a new task model in which a distance constraint must be satis ed between successive invocations of a task. Schedulability conditions for such task sets are analyzed based on pin-wheel scheduling.
1.1 Computational Model
Our problem set consists of a set of transactions f?1; ?2; : : :; ?m g. A transaction ?i consists of an ordered set of tasks fi1 ; : : :; i g that must execute in sequence whenever the transaction is invoked. Each task i has a lower bound (li ) and an upper bound (ui ) on its execution time. The actual execution time (ei ) of a task is unknown until after the task nishes its execution. Timing Constraints: Consider a single transaction ?. For the tasks f1 ; : : :; n g in ?, the start times (si 's) and nish times (fi 's) of the tasks are the variables on which the timing constraints are speci ed. The constraint set is of the form Ax b, where A is an m 2n matrix, x is a 2n n
j
j
j
j
dimensional column vector [s1; f1 ; s2; f2 ; : : :; sn ; fn]T and b is an m-dimension column vector of constants. These include ready time constraints (si c) and deadline constraints (fi c) on a single task, as well as relative constraints (e.g., f3 s1 + 7).
2 Single Transaction Scheduling We rst consider the problem of scheduling a set of tasks in a single transaction. The goal is to derive a mechanism which will statically ensure that all timing constraints will be satis ed during execution. Since the order of execution is pre-determined, the problem reduces to nding actual start times of the tasks such that the constraints remain satis ed. Since the system is non-preemptive, (i.e., fi = si + ei ), the constraints may be rewritten using the variables for start times and execution times. The challenge of the problem lies in the fact that the actual execution time of a task is unknown until after the task nishes. Thus, at the time of dispatching a given task, the actual execution times of future tasks are unknown. We say that a task set is schedulable if there exists any method which can successfully dispatch the tasks in ?. Let C represent the logical interpretation of the timing constraints. The formal de nition of schedulability is as follows: De nition 2.1 (Schedulability) A task set is schedulable if the following predicate holds. sched def = 9 s1 8 e1 2 [l1 ; u1] : : : 9 sn 8 en 2 [ln ; un] C That is, sched holds i there exists a dispatching mechanism which, in determining each si , relies only on the execution times of the tasks already run. Note that if all of the execution times are known constants, the problem reduces to nding a solution for a system of linear inequalities. Well known techniques (e.g., linear programming) exist to solve such a system of constraints and the result would be a pre-determined calendar in which the start times are real-valued constants. When execution times are not constants, a static schedule with constant start times may not exist, even though the task set may be schedulable. In general, the start time of a task may depend on the start times and execution times of its predecessor tasks. This leads to the notion of a parametric calendar, in which the start times are represented as functions ( Figure 1).
2.1 Parametric Dispatching
To solve this problem, we have developed a technique called parametric dispatching, where the dispatcher uses a parametric calendar generated oine. The dispatch functions for the tasks are generated so that they maintain schedulability; i.e., sched holds if and only if our method successfully produces a parametric calendar. For a given set of constraints, there may not be a unique parametric calendar, i.e., a unique choice for each dispatch function. Thus for each task i we store two functions: Fimin and Fimax (as in Figure 1). The two functions yield the lower and upper bounds, respectively, allowed for the value si . Even in cases where a static calendar can be generated, we claim that the parametric method is a superior way to dispatch real-time tasks. Certainly many applications can take advantage of the additional exibility, especially those that include a mix of hard real-time tasks and noncritical background processes. For example, a calendar such as that in Figure 1 will, before dispatching a task, report the minimum and maximumamount of \slack" available. Our approach is to attack the dispatching problem in two phases { the rst phase is run oine, and the second is run online. Oine Component: During the oine component, the timing constraints are analyzed to produce a calendar. If no such calendar exists (i.e., if sched is not true), then the algorithm detects and reports this. Online Component: During the online component, the calendar evaluator determines the upper and lower bounds on the start time for each task. For a given task i, this involves applying the functions Fimin and Fimax , to the execution times and start times for tasks 1; : : :; i ? 1. A suitable start time must then be selected by the dispatcher within the upper and lower bounds so obtained. This decision can be based on information such as whether there are non real-time tasks waiting to run. Example 2.1 As an illustration, consider a transaction consisting of 4 tasks. The execution time bounds (i.e., l1 ; u1; : : :; l4; u4) are as follows: 4 e1 8 10 e3 13 6 e2 11 3 e4 9 The constraints on the tasks are given by the inequalities in Table 1. In addition, we include the following constraints to represent the sequential ordering de ned on the tasks: 0 s 1 s2 + e 2 s 3 s1 + e1 s2 s3 + e3 s4
F1min () min F (s1 ; e1) 2
s1 F1max () s2 F2max (s1 ; e1) .. .
.. .
Fnmin (s1 ; e1 ; s2; e2 ; : : :; sn?1; en?1) sn Fnmax (s1 ; e1; s2 ; e2; : : :; sn?1; en?1) Figure 1: Parametric Calendar s4 + e 4 s4 + e 4 s2 + e2 + 18 s3 + e 3
56 s3 + e3 + 12 s4 s1 + e1 + 31
(Task 4 nishes at or before time=56) (Task 4 nishes within 12 msec of task 3 nishing) (Task 4 starts no earlier than 18 msec of task 2 nishing) (Task 3 nishes within 31 msec of task 1 nishing)
Table 1: Constraints for the Example The given task set is schedulable, and the parametric calendar generated for the task set as a result of our oine algorithm is shown in Figure 2.
2.2 Generating a Parametric Calendar
We have developed a technique to generate a parametric calendar based on variable elimination. The oine algorithm successively eliminates variables from the set of constraints, generating at each stage a new set of constraints with one less variable. It rst eliminates the innermost universal quanti er, and produces a re ned set of constraints, C 0 , in which no en occurs. At this stage the following essential property holds: C 0 () (8 en 2 [ln; un] :: C ). Now the functions Fnmin and Fnmax can be derived from lower bounds and upper bounds respectively on sn in C 0 , since all such bounds will be in terms of values known at the time sn is chosen. Next, the algorithm removes the innermost existential quanti er, and produces a new set of constraints, C 00, in which sn has now been eliminated. Again, we have that C 00 () (9 sn :: C 0 ). Thus the algorithm works its way from the inside out, progressively eliminatingquanti ers until, at the end, only constraints on s1 remain. If at any stage a set of constraints is detected to be inconsistent, it means that the original task set is not schedulable { that is, sched is false. If no inconsistencies are detected, the algorithm successfully generates the parametric calendar. For universal variable elimination, the variable ei is substituted in each constraint by li or ui, depending on the constraint form. The existential quanti er elimination is done using the Fourier-Motzkin variable elimination tech-
nique for linear programming [1]. Intuitively, the FourierMotzkin elimination results in a shadow of an n dimensional convex object on n ? 1 dimensions. The details of the variable elimination method and the proofs of correctness are described in [4]. Complexity Results: For arbitrary constraints, generating (and even applying) an Fimin or Fimax can, in the worst-case, have exponential cost. However, we have identi ed a class of standard constraints for which this complexity is substantially reduced, and in fact, is polynomial. Fortunately, these constraints can describe almost any type of real-time property that one would nd in a real-time speci cation. These constraints specify the maximum or minimum permissible temporal distance between the start or nish time of a task i and the start or nish time of a task j. We also include absolute constraints on the start or nish time of a task in the standard form. All the constraints in Example 2.1 are in standard form. A set of standard constraints leads to an oine algorithm with complexity O(n3), where n is the number of tasks. The associated online complexity of applying an Fimin or Fimax is O(n). Intuitively, this occurs since the number of non-redundant constraints in standard form is bounded by O(n2 ), and the set of standard constraints is closed under variable elimination.
3 Multiple Transaction Scheduling Now we examine the problem of scheduling multiple transactions. Again, we restrict our discussion to nonpreemptive scheduling. Recall that constraints are placed
0 s1 + e 1 s2 + e2 + 5 max(s3 + e3 ; s2 + e2 + 18)
s1 s2 s3 s4
10 min(s1 + e1 + 2; 18) min(s1 + e1 + 18; 34) min(s3 + e3 + 3; 47)
Figure 2: Parametric Calendar for Example sa fa sa fa
c c c c
sb fb sb sb
? sa ? sa ? sa ? fa
c c c c
Table 2: Restricted Standard Constraints within transactions, and not between them. Obviously, for n transactions our problem is a generalization of nonpreemptive scheduling with ready times and deadlines, a well known NP-Complete problem [3]. Thus our approach is to simplify the problem, in order to gain a better understanding of it. Simpli cation 1: First we restrict our problem to scheduling a constant c number of transactions (to simplify the problem even further, we assume c = 2). It is assumed that each transaction is individually schedulable. In any algorithm that solves this problem, each stage is going to involve a choice of which task to select, and a choice of which time to start it. Clearly, these choices may depend on the execution times of the predecessor tasks, thus leading to a very large search space. Generating and/or verifying the timing constraints for such a schedule is not at all straightforward task, and may, in fact, result in exponential cost. Simpli cation 2: We restrict our attention to cases where the transactions are schedulable if and only if a single dispatching order holds for all execution times. Given such an ordering, a parametric schedule could be constructed in an ecient manner as described in Section 2. In our treatment of single-transaction scheduling, we identi ed the standard constraints, for which an ecient solution was obtained. The following result holds for the class of restricted standard constraints, given in Table 2.
Theorem 3.1 A multiple transaction task set, con-
structed with restricted standard constraints, is schedulable for all execution times i it is schedulable for the worst-case execution times. Moreover, the ordering generated for the worst case suces for any execution scenario.
Proof Sketch: For the \if" part, consider a successful ordering generated for the tasks in transactions, and consider their start-time assignments. We note that this ordering and assignment will suce for any execution scenario. Restricted standard constraints are such that \holding" a task until this start time will be sucient. As for the \only if" part, note that in Table 2 nish times fa and fb with positive coecients are always on the lefthand-side of the \" sign. This means that the bounds are the tightest when execution times are at their maximum. Thus the problem reduces to a deterministic scheduling problem with relative constraints, similar to the ones tackled in [5] and [7]. In this manner, scheduling becomes a two stage process: Find a schedule for the task set, substituting ui for
each ei . If no schedule exists then the original task set is unschedulable. If a schedule exists, then consider the sequence of tasks for which the schedule exists. Apply the single transaction scheduling algorithm for this sequence (after adding new precedence constraints de ned by the sequence) to generate a parametric calendar. As a consequence, we can generate a parametric calendar for a multiple transaction task set. As mentioned before, the use of a parametric calendar adds exibility to the dispatching mechanism, which is particularly useful for systems with a mix of critical and non-critical tasks. We have shown that the original problem can be reduced to deterministic scheduling with relative constraints. However, there still remains the problem of actually generating the ordering! Unfortunately, at this point in our investigation, we have not found an ecient algorithm that will do this. Thus, we present the following open problem. Open Problem: Assume that there are two transactions, with n tasks apiece, and with a set of restricted standard constraints on each transaction. (Note that there are at most O(n2 ) nonredundant constraints for each transaction.) Is there a a polynomial-time algorithm
which will produce a schedulable ordering if and only if such an ordering exists? Simpli cation 3: Finally, we consider two transactions that are each constrained only by ready times (si c) and deadlines (si c). We present the sketch of a lineartime algorithm which will successfully compose the two transactions. Further, the algorithm results in a minimum length schedule. At each stage the algorithm examines the tasks at the head of the two transactions. If both tasks can start at the current time, then the one with earlier deadline is chosen. If not, then the task which can start earlier is chosen, unless choosing it prevents the other task from nishing within its deadline. The task is added to the schedule, and the current time is updated to its scheduled nish time. The algorithm's correctness follows from the following proof sketch. Proof Sketch: Due to the total order on the transactions, tasks within a transaction have strictly increasing (eective) ready times and strictly increasing (eective) deadlines. The algorithm's correctness follows from the fact that the sequence selected is dominant [17]. The algorithm proceeds by re ning the dominant set of sequences, by (1) initially considering all consistent sequences dominant, and (2) re ning this set until one sequence is produced. At each stage, by choosing a task and adding it to the schedule, the algorithm restricts the dominant set of sequences. In the end, the order chosen by the algorithm is the only sequence in the dominant set. The dominance property is maintained at each stage of the algorithm. This follows from the fact that if a feasible schedule exists, then a modi ed schedule in which a task is selected and placed rst is also feasible, and is of lesser or equal length.
4 Concluding Remarks In this paper, we have presented our ongoing work on the scheduling of hard real-time tasks with relative timing constraints. Such constraints frequently occur in realtime speci cations, and contemporary real-time languages provide constructs to express them. We have developed the notion of parametric dispatching to enforce such timing constraints and guarantee them oine. Future work will entail resolving the open problems, developing heuristics for general cases, and implementing the parametric dispatching algorithm. Moreover, we intend to unite our scheduling results with our programming language results [8], which will provide a \vertically integrated" environment for developing real-time systems.
References
[1] G. B. Dantzig and B. C. Eaves. Fourier-Motzkin Elimination and its Dual. Journal of Combinatorial Theory (A), 14:288{ 297, 1973. [2] B. Dasarathy. Timing Constraints of Real-Time Systems: Constructs for Expressing Them, Methods of Validating Them. IEEE Transactions on Software Engineering, SE-11(1):80{86, January 1985. [3] M. R. Garey and D. S. Johnson. Computers and Intractability, a Guide to the Theory of NP-Completeness. W. H. Freeman Company, San Francisco, 1979. [4] R. Gerber, W. Pugh, and M. Saksena. Parametric Dispatching of Hard Real-Time Tasks. Technical Report CS-TR-2985, UMIACS-TR-92-118, University of Maryland, Department of Computer Science, October 1992. [5] C. C. Han and K. J. Lin. Job scheduling with temporaldistance constraints. Technical Report UIUCDCS-R-89-1560, University of Illinois at Urbana-Champaign, Departmentof Computer Science, 1989. [6] C. C. Han and K. J. Lin. Scheduling distance-constrained realtime tasks. In Proceedings, IEEE Real-time Systems Symposium, pages 300{308, Phoenix, Arizona, December 1992. [7] C. C. Han and K. J. Lin. Scheduling real-time computations with separation constraints. Information Processing Letters, 12:61{66, May 1992. [8] Seongsoo Hong and Richard Gerber. Compiling real-time programs into schedulable code. In Proceedings of the ACM SIGPLAN '93 Conference on Programming Language Design and Implementation, 1993. To appear. [9] F. Jahanian and A.K. Mok. Safety analysis of timing properties in real-time systems. IEEE Transactions on Software Engineering, SE-12(9):890{904, September 1986. [10] I. Lee and V. Gehlot. Language Constructs for Real Time Programming. In Real Time Systems Symposium, pages 57{ 66. IEEE, 1985. [11] K. J. Lin and S. Natarajan. Expressing and Maintaining Timing Constraints in FLEX. In Real-Time Systems Symposium, December 1988. [12] A. Mok, P. Ameransinghe, M. Chen, and K. Tantisirivat. Evaluating Tight Execution Time Bounds of Programs by Annotations. In Proc. 6th IEEE Workshop on Real-Time Software and Operating Systems, pages 74{80, 1989. [13] V. Nirkhe, S. Tripathi, and A. Agrawala. Language Support for the Maruti Real-Time System. In Real-Time Systems Symposium, December 1990. [14] C. Park and A. C. Shaw. Experiments with a Program Timing Tool Based on Source Level Timing Schema. In Proceedings IEEE Real-Time Systems Symposium, pages 72{81, December 1990. [15] P. Puschner and C. Koza. Calculating the Maximum Execution Time of Real-Time Programs. Journal of Real Time Systems, 1(2):159{176, September 1989. [16] V. Wolfe, S. Davidson, and I. Lee. RTC: Language support for real-time concurrency. In Proceedings of the 12th IEEE Realtime Systems Symposium, pages 43{52, San Antonio, Texas, December 1991. [17] X. Yuan and A. K. Agrawala. A Decomposition Approach to Nonpreemptive Scheduling in Hard Real-Time Systems. In Proceedings IEEE Real-Time Systems Symposium, Dec. 1989.