North-Holland
Microprocessing and Microprogramming 27 (1989) 775-782
775
Real-Time Schedulingwith both Preemption and Nonpreemption Requirements Xiaoping Yuan and Ashok K. Agrawala * D e p a r t m e n t of Computer Science University of Maryland College Park, MD 20742
Abstract
A new problem of real-time scheduling with both preemption and nonpreemption requirements is identffied in this paper. We propose two efficient, dynamic and static, algorithms as a solution to the problem, which maximizes the schedulability. The dynamic approach mainly arranges tasks according to the relationship between the preempting and preempted tasks, while the static approach only considers the status of the resources to be accessed.
I
I n t r o d u c t i o n and P r o b l e m F o r m a t i o n
The preemptive real-time scheduling is based on the assumption that the tasks can arbitrarily preempt each other.
The major work on real-time scheduling problems as reported in the literature makes the assumption that the tasks being scheduled either can be preempted or cannot be preempted. This assumption is made on task by task basis and the interdependencies that may exist among the tasks are not taken into account. For example, two tasks requiring a mutually exclusive use of a resource such as a tape drive or a line printer, may not preempt each other while the tasks not making use of such resources may have no such restrictions. In this paper we study the scheduling of tasks for which the preemption requirements are defined on a pairwise basis either independently or on the basis of their use of common resources. Scheduling algorithms are presented for both of
Scheduling algorithms, such as the earliest-deadline-first,leastlaxity-first, and periodic rate monotonic algorithms [Liu73], have been proposed for these problems. The nonpreemptive real-time scheduling takes the other extreme. A task can not be preempted until it finishes its execution on the CPU. But a nonpreemptive system becomes much lower in flexibility and schedulability than the preemptive one, and searching for an optimal solution has been shown to be an NP-complete problem [Gare79]. On the other hand, for the preemptive scheduling such a solution can be found in polynominal time [Liu73, Mok83]. Furthermore, a nonpreemptive system can not keep all the resources working concurrently. In general cases, a pre-
these cases. *This work is supported in part by contract DASG-60-87-C-0066 from U.S. Army Strategic Defense Command to the Department of Computer Science, Universityof Maryland at College Park. The views, opinions, and/or finding containedin this report are those of authors and should not be constructed a~ an official position, policy,or decisionof the Army, unless so designated by other officialdocumentation.
X. Yuan,A.K. Agrawala / Real-Time Scheduling with both Preemption and Nonpreemption
776
emptive system shows much better average response time for
ale is deadlock-free, irrespective of the preemption depen-
real-time tasks and higher system utilization and through-
dencies among tasks. Mutual exclusion mechanisms such as
put than a nonpreemptive one [Zhao87a, Zhao87b]. Work in
semaphores and monitors are not needed in this kind of sys-
[Chu87, Ma82, Zhao87b] and most of the operations research
tem, since the scheduler has pre-decided the execution order
literature on scheduling primarily consider the problem of
which should not result in any contention for resources. We consider an algorithm as optimal, if it can always find
nonpreemptive scheduling. When a set of tasks have interdependencies such that
a feasible schedule to a set of tasks if such a schedule exists.
some tasks can preempt some other tasks, but not the rest,
For the semi-preemptive real-time scheduling, achieving an
we call the scheduling of these tasks to be semi-preemptive
optimal solution can be as easy as for a preemptive real-time
real-time scheduling.
scheduling, if there is no overlaps among time windows of
The semi-preemptive schedul]ng is defined by the follows
tasks accessing a common resource with the nonpreemptive
four rules. First, in this class, we assume the CPU to be
mutually exclusive requirement. But the work can also be
a special preemptable resource for which we schedule real-
as difficult as for nonpreemptive real-time scheduling, if all
time tasks. A task accessing any other resources must also
the tasks need to access one common resource with the non-
access the CPU at the same time. In the sequel, we use the
preemptive mutually exclusive requirement, and their time
term resource to indicate any resources except the CPU in
windows are randomly overlapped. In this paper, we propose
the uniprocessor real-time scheduling.
two algorithms for handling semi-preemptive scheduling of
Second, all the tasks can be CPU-preempted, as long as
tasks.
the preempting tasks do not access the resources still held by the CPU-preempted tasks with nonpreemptive, mutually exclusive access requirements. The preempting tasks are all those tasks running on the CPU between the current task's
II
Tools and Data Structures
preempted point and execution resuming point in time. A real-time task can be a preempting and preempted task at the same time. Third, optimal solutions for preemptive real-time schedul-
The environment for the semi-preemptive real-time scheduling permits intermittent or batch task arrivals. A task, Ti, can be symbolically represented as follows,
ing are used as a basic scheduling policy with the consider-
Ti:-< ei, ri, dl >
ation of the nonpreemptive mutually exclusive requirements in the semi-preemptive real-time scheduling. In other words,
where computation time cl is the time used to run the task in
a task will be preempted according to the basic policy. But
the worst case. Task Ti can not start to run before ready time
selection of the next running task is determined according
ri, but must finish before deadline dl. We also use notation
the resource access requirements of both tasks.
window, represented by symbol w~, to show the time interval
Fourth, as in most real-time systems, a schedule for the
between rl and di, w~ = [ri, d~]. A real-time task is shown in
task execution is created. A dispatcher initiates tasks to run
Fig. 1. In the rest of the paper, task T~ will be represented
according to such a plan.
by task i for short.
The semi-preemptive real-time scheduling exploits the ad-
The goal of the real-time scheduling is to schedule tasks
vantages of both, the optimal preemptive real-time schedul-
in a uniprocessor system to meet their deadlines. The task
ing and the nonpreemptive real-time scheduling. The schedul-
request to resources may come with nonpreemptive mutually
ing approach used has to assure that the resulting sched-
exclusive requirements to resources or preemptive ones.
X. Yuan, A.K. Agrawala / Real-Time Scheduling with both Preemption and Nonpreemption
777
towards some resource which may also be requested by task
j.
task i
For static semi-preemptive scheduling approach, a n x m
C I
I
t
I
I
I
r
d
task-resource reference table, R, is defined to show the rela-
time |
tionship between tasks and resources, where m is the number of resources in the system, such that, O if task i does not access resource j , 1 if task i can access resource j
Figure 1: An
example of real-time task.
Ri.j =
with preemption,
There are two approaches to handle the semi-preemptive 2 if task i accesses resource j real-time scheduling. One is called a dynamic semi-preemptive
with a nonpreemption requirement.
scheduling approach. In this approach, the real-time scheduler does not keep track of how many resources exist in the system. User should indicate all the tasks in the system which may request the same resources as the user's task does (the similar assumption can be also found in real-time scheduling research [LeinS0, Lein82]). Sometimes, users may not be able to know other tasks in the system. But they must submit
In case a task can access a resource with preemption, the task's execution on CPU can be preempted by any other tasks. In case that a task accesses a resource with nonpreemptive mutually exclusive requirement, its execution can only be preempted by tasks which do not access the same resource.
types, characteristics, and resource requests of these tasks to allow the scheduler to identify these tasks. The scheduler maintains a task-task interference table to keep track of the resource-access relation between every pair of tasks. The dynamic approach is especially suitable for dynamic resources, such as, temporary data, files, and buffers. Another approach is called a static semi-preemptive scheduling approach. In this approach, all the resources are used by tasks are given to the system. Any action of deletion or addition of a resource to the system should also notify the scheduler. The scheduler keeps a task-resource reference table to keep track of the relation between tasks and resources.
III
Strategy
We first introduce basic notations for semi-preemptive realtime scheduling algorithms. A task slice is a portion of a task computation time in a schedule. The length of the task slice S L depends on the strategies of scheduling. The maximum length of a task slice is the computation time of the task. One execution of a task can consists of several slices. A start time, s, is associated with each slice. The start time indicates when the slice begins. A finish time, f , of a slice is defined as s + S L , the sum of the slice start time and slice length. A schedule is a list of slices sequenced according to their start
For the dynamic semi-preemptive scheduling, a n × n task interference table, I, is defined to keep the information of nonpreemptive mutually exclusion between any two tasks,
times in increasing order. In the algorithms, a variable called C S T represents the current scheduling time for the current schedule of the CPU.
such that,
A free task set F T is used to contain the tasks such that 1 if task i can not be preempted by task j Ii.j =
for sharing a resource, 0 otherwise;
Vi E F T (r~ < C S T < d~). In other words, tasks in F T are "free" to be executed in the sense of time window boundary. A preempted task set P T is created to keep CPU-preempted
where task i can not be preempted by task j means that
tasks, P T C F T . When a task is preempted by the scheduler,
task i has a nonpreemptive mutually exclusive requirement
the task identification is also copied into PT. The
suspended
778
X. Yuan,A.K. Agrawala / Real-Time Scheduling with both Preemption and Nonpreemption
task Set ST keeps the tasks which are suspended because
If the current selected task is a preempted one, it should
the resources they request are held by other CPU-preempted
be removed from preempted task set PT. If there is a pre-
tasks, and the preempted tasks have nonpreemptive accessing
empted task holding a resource required by the current se-
requirements towards the resources. A suspended task can be
lected task, the current task has to be removed from free task
resumed, only when all the preempted tasks holding the same
set F T to suspended task set ST. Since no task is confirmed,
resources as the suspended task requests finish their execu-
the selecting process has to be repeated.
tions. The rest unscheduled tasks are kept in a task queue,
As soon as a task is confirmed, a time slice is allocated
TQ, in the order of nondecreasing ready times of these tasks.
to it. The slice length, SL, is the minimum of the task's
We use e~(t) to indicate the remaining computation time for
computation time and the ready time of the first task in task
task i at time t.
queue TQ.
The dynamic and static semi-preemptive real-time scheduling algorithms basically follow the optimal preemptive earliestdeadline-first policy.
scheduling decision.
Other heuristics can also be used to
replace the current one for different real-time applications. The dynamic algorithm consists of initialization, insert-
ing, resetting, selecting, and updating. All the task sets and queue are initiated in the initialization phase. The inserting is a process of inserting tasks into task queue TQ, when there
The new current scheduling time, CST~,~, is
updated to C S T + SL. The C S T n ~ is the time for the next
The updating is done to reorder different sets, after one task is totally scheduled in the current selecting. A task is totally scheduled, if S L = c(CST). The task is removed from free task set F T . Suspended task set S T is also checked to see whether any task there can be released to free task set FT.
are new tasks to be scheduled. The resetting is the step of putting tasks from task queue
TQ into free task set FT. The tasks are ready to be scheduled, since current scheduling time C S T , is within their time
windows.
A d y n a m i c semi-preemptive scheduling algorithm 1. (Initialization) Initiate TQ = F T = P T = S T = ~, and set C S T to the current system time. 2. (Inserting) For any new intermittently arriving task, in-
The selecting step chooses a task from free task set F T to be the current selected one for the schedule. A task with the earliest deadline from free task set F T is the candidate. If the
sert it into TQ according to the order of nondecreasing ready times at the time the task arrives. Repeat step 3, 4 and 5, until run out of tasks.
current selected task is different from the latest running one, the latest running one is preempted, and put into preempted
3. (Resetting) Examine tasks from the front of TQ to put
task set P T , if it has not finished its execution. The current
these tasks into F T if their ready times are less than
selected task is compared with all the tasks in preempted task
or equal to C S T , until the first task whose ready time
set P T to check whether there is a task holding resources
is greater than C S T has been met.
required by the current selected task.
If there is no task
holding the resources, the current task is confirmed to be scheduled in the current scheduling time, C S T . There is no task in free task set F T with an earlier deadline than the
4. (Selecting) Repeat the following procedure until one task's execution is confirmed. If there is no (selected) executable task, update C S T to be the ready time of the first task in TQ.
current confirmed one, except that there may exist some in
task queue TQ and suspended task set ST.
(a) Select a task from F T with the earliest deadline.
X. Yuan,A.K. Agrawala / Real-Time Scheduling with both Preemption and Nonpreemption
779
(b) If the selected task i is different from the latest
task has not finished its execution, the latest running task is
running task at the current C S T , preempt the lat-
preempted. The status of lth resource is set to H E L D , if the
est running task, and copy the task into P T .
latest running task has a nonpreemptive mutually exclusive
(c) Compare the new selected task with all the tasks
access requirement to it.
IfVk E P T Ik,~ = 0 unless k = i, then
If the current selected task is a preempted one, reset all
the i's execution is confirmed; if i E P T , i is also
the resources held by it to F R E E for its reuse. The task is
removed from P T ( P T ~
also removed from preempted task set P T .
in P T .
= P T - {i}).
The next step in selecting is to check whether the status (d) If 3k E P T Ik,~ = 1, i is suspended by putting i into the suspended task set S T (STnew = S T U { i } ) and remove it from the free task set F T (FT~e~ = F T - {i}). No task is confirmed, and continue with 4(a).
of all the resources required by the current selected task is free. If so, the current selected task is confirmed. Otherwise,
the task is removed from free task set F T to suspended task set S T , and the selecting process is continued until one task is confirmed. A time slice is allocated to the current confirmed
Compute the time span allocated to the selected task i. The length of the slice S L = n~n{c~(CST), rk : k is
task just as the dynamic algorithm does.
The static seml-preemptlve scheduling algorithm
the first task in T Q } . 1. (Initialization) Initiate S T A T U S [ i ] = F R E E , for i =
CSTne~o = C S T + S L .
I,..., m. 5. (Updating) If S L = c { ( C S T ) , the current selected task will finish its execution at time CSTne,~, should be re-
Initiate T Q = F T = P T = S T = ¢, and set C S T to the current system time.
moved from free task set F T (FTne~ = F T - {k}). 2. (Inserting) For any new arriving task, insert it into T Q If 3i E S T Vk E P T Ik,{ = O, remove i from S T , and according to the order of nondecreasing ready times at put it into F T . the time the task arrives. The complexity of the dynamic algorithm is O ( n 2) for scheduling n tasks.
Repeat step 4, 5 and 6, until run out of tasks. 3. (Resetting) Examine tasks from the front of T Q to put
The static semi-preemptive approach is different from the dynamic, since another data structure called S T A T U S is set up for resources to monitor their current states. Instead of
these tasks into F T if their ready times are less than or equal to C S T , until the first task whose ready time is greater than C S T has been met.
checking the interference between tasks, the algorithm will schedule a task by referring to the status of resources the
task's execution is confirmed. If there is no (selected)
task requests. The static algorithm also consists of initialization, inserting, resetting, selecting, and updating. The inserting, initialization, resetting and updating are basically similar to the ones in the dynamic algorithm. The selecting is to choose a task with the earliest deadline from free task set F T .
4. (Selecting) Repeat the following procedure until one
If the current selected task is
different from the latest running task and the latest running
executable task, update C S T to be the ready time of the first task in TQ. (a) Select a task from F T with the earliest deadline. (b) If the selected task i is different from the latest running task k at the current C S T and task k is not finished, set S T A T U S [ l ] = H E L D for Vl Rkj = 2, and copy task k into preempted task set PT.
X. Yuan, A.K. Agrawala / Real-Time Scheduling with both Preemption and Nonpreemption
780
(c) If the selected task i is also in P T , set S T A T U S [ k ]
T h e o r e m 1 For a set of tasks, the schedule, $1, created by
for Vk Ri,k = 2, and remove i from P T ,
the semi-preemptive scheduling algorithm dominates the one,
= FREE (PT,~
= P T - {i}).
$2, created by the nonpreemptive earliest-deadline-first algo-
(d) Check the new selected task i, such that if Vk Ri,k > 0 --+ S T A T U S [ k ]
= FREE,
the i's exe-
cution is confirmed; otherwise, i is suspended by putting i into suspended task set S T (STnew = S T U {i}) and remove it from the free task set F T ( F T ~ o = F T - {i}). Continue with 5(a).
rithm. Proof" We use a construction method to prove S~ dominates $2. Examine $2 from the left to right, starting from the beginning of the schedule. For the first pair of tasks, i and j , where i is immediately in front of j , but i's deadline is greater
Compute the time span allocated to the selected task
than j ' s and i does not have nonpreemptive mutually exclu-
i. The length of the slice S L = m i n { e i ( C S T ) , r k : k is
sive requirement to a resource task j also accesses to. The
the first task in T Q } .
situation can only happen when the start time of i is less
CST,~,o = C S T + S L .
than the ready time of j . There are two cases to examine.
5. (Updating) If S L = c i ( C S T ) , the current selected task will finish its execution at time C S T ~ , o , and should be removed from free task set F T ( F T ~
= F T - {k}).
If qi E S T Vk Ri,k > 0 --* S T A T U S [ k ]
= FREE,
remove i from S T , put it into F T .
First, at the ready time point of task j , if task i is scheduled, i can be preempted into two parts at that point, j is scheduled at its ready time, and another part of i can be inserted aSter j. The modified schedule is still feasible, since the inserting j into i will not affect rest of the schedule, and i has deadline greater than j.
The complexity of the static algorithm is O ( m l n + m 2 n ) for scheduling n tasks with ml resources, where m2 is the average size of preempted task set P T .
Second, at the ready time of j , if another task, namely k, is scheduled, k must have ready time greater than i but less
than j , and deadline less than i. If k has deadline greater than j , and k does not have nonpreemptive mutually exclusive requirement to a resource task j also accesses to, k will also be preempted into two parts at the point of the ready time
IV
Analysis of Algorithms
of j , and insert j at its ready time. The other part of k and i on the right of the ready time will be pushed right at
In order to compare our algorithms with the optimal preemptive earliest-deadline-first and nonpreemptive earliest-deadlinefirst algorithms, we first introduce a concept of dominance [Ersc83] Definition
the distance of cj. The new schedule will still be feasible, since both k and i have deadlines greater than j , and the original schedule before the current change is feasible. If k has the deadline less than j , or k can not be preempted by j
1 For two schedules, $1 and $2, S1 d o m i n a t e s
because of the nonpreemptive resource requirement, the point to insert j is at the finish time of k, if there is only i scheduled
$2 if and only if: $2 f e a s i b l e ~
S1 feasible.
behind. Otherwise, this second case can be repeated to decide where to insert j .
Based on the dominance, we have the following theorem
Since the above process can be repeated until the end
to compare the semi-preemptive scheduling and nonpreemp-
of $2. Every new modified schedule is feasible during the
tive scheduling.
construction. The final constructed schedule is $1.
[]
X. Yuan,A.K. Agrawala/ Real-Time Schedulingwith both Preemptionand Nonpreemption
781
schedule is restored.
Since the preemptive earliest-deadline-first algorithm can not be used in the situation of nonpreemptive mutually ex-
The computation time for backtracking one task is at
clusive requirements applied, the semi-preemptive scheduling algorithm can not be compared with the preemptive earliestdeadline-first algorithm in that situation. In case that all the
most O(nl!), where nl is the number of tasks whose time window are overlapped with the current backtracked task's.
tasks can preempt each other, we have following theorem. VI
Final
Remark
T h e o r e m 2 If all the tasks can preempt each other, the semi-preemptive scheduling algorithm is optimal.
In this paper, we identify a semi-preemptive scheduling requirement for real-time systems. The common approaches
In other words, the semi-preemptive scheduling algorithm is such as preemptive and nonpreemptive reaLtime scheduling equivalent to the preemptive earliest deadline algorithm when are not suitable for solving this problem. The mechanisms all the tasks can preempt each other.
used to solve the problem in general purpose computer systems are not applicable to the real-time systems. Therefore,
V
Further
Extension
we propose a dynamic and a static approaches to handle
In the both algorithms introduced in section III, a preemp-
such a problem.
The schedulability characteristics of our
tive earliest-deadline-first policy is used to schedule tasks. If
algorithm is the same as the optimal preemptive earliest-
some of the tasks can not be freely preempted, the earliest-
deadline-first algorithm, if all the tasks are preemptable. If
deadline-first policy is no longer optimal any more. Some
tasks have nonpreemptive mutually exclusive resource access
heuristics should be taken to improve the algorithms. The
requirements, the schedule created by our algorithms domi-
following algorithm is a heuristic backtracking algorithm for
nates the schedule created by the corresponding nonpreemp-
those tasks unschedulable in both dynamic and static algo-
tive earliest-deadline-first algorithm.
rithms References
A Heuristic Backtracking Algorithm • If task i is unschedulable
[ChuB7]
Chu, W. W. and Lan, L. M-T., "Task Allocation and Precedence Relation for Distributed Real-
1. Remove the latest scheduled task slice from the
Time Systems", IEEE Trans. on Comput., Vol.
schedule one by one, until task i can be feasibly scheduled.
C-36, No. 6, pp. 667-679, June 1987. [Ersc83]
2. Reschedule the removed tasks (all the removed
Erschler, J., Fontan, G., Merce, C., and Roubellat, F., "A New Dominance Concept in Scheduling n
slices of one task are combined together as one unJobs on a Single Machine with Ready Times and finished task) by using the corresponding dynamic Due Dates", Operations Research, Vol. 31, No. 1, or static algorithms. pp. 114-127, Jan. 1983. 3. If there is a backtracking for these removed tasks, the upper bound of removing tasks can not reach the latest advanced task (otherwise, the process will fall an infinite loop). 4. If there is a removed task unschedulable, the first advanced task, i.e. i is rejected, and the original
[Gaxe79]
Garey, M. R. and Johnson, D. S., Computers and Intractability, a Guide to the Theory of NPCompleteness, W. H. Freeman Company, San Francisco, 1979.
X. Yuan,A.K. Agrawala / Reel-Time Scheduling with both Preemption and Nonpreemption
782
[~nSO]
Lelnbaugh, D. W., "Guaranteed Response Times
System", I E E E lt'ans, on Comput., Vol. C-31, No.
in a Hard-Real-Time Environment", IEEE Trans.
1, pp. 41-47, Jan. 1982.
on Soft. Eng., Vol. SE-6, No. 1, pp. 85-91, Jan.
1980. [Lein82]
Leinbangh, D. W. and Yamini, M., "Guaranteed Response Times in a Distributed Hard-Real-Time Environment", In Proc. IEEE Real-Time Syst. Syrup., pages 157-169, Dec. 1982.
[Uu73]
Liu, C. L. and Layland, J., "Scheduling Algorithm for Multiprogramming in a Hard Real-Time Environment", Journal of the ACM., Vol. 20, pp. 46-61, Jan. 1973.
[Mok83] Mok, A. K., "Fundamental Design Problems for the Hard Real-time Environments", May 1983, MIT Ph.D. Dissertation. [Zhao87a] Zhao, W., l~ma~nritham, K., and Stankovic, J. A., "Preemptive Scheduling under Time and Resource Constraints", I E E E Trans. on Camput., Vol. C-36, No. 8, pp. 949-960, Aug. 1987. [Zhao87b] Zhao, W., Ramamritham, K., and Stankovic, J. A., "Scheduling Tasks with Resource requirements in a Hard l~al-Time System", IEEE Trans.
[Ma82]
Ma, P. It., Lee, E. Y. S., and Tsuchiya, M., "A
on Soft. Eng., Vol. SE-13, No. 5, pp. 564-577, May
Task Allocation Model for Distributed Computing
1987.