Scheduling cyclic tasks with binary periods

Scheduling cyclic tasks with binary periods

Inform+ion fZg=&ymg Information Processing Letters 65 (1998) 173-178 Scheduling cyclic tasks with binary periods ’ Jerzy R. Nawrocki *, Adam Cza...

657KB Sizes 0 Downloads 101 Views

Inform+ion fZg=&ymg Information

Processing

Letters 65 (1998)

173-178

Scheduling cyclic tasks with binary periods



Jerzy R. Nawrocki *, Adam Czajka, Wojciech Complak InstytutInformatyki, Politechniku Poznanska, ul. Piotrowo 3a, 60-965 Poznan. Poland Received 25 October 1997; revised 4 December Communicated by W.M. Turski

1997

Abstract We show that static scheduling of cyclic non-preemptable tasks with binary periods which are to be executed on one processor is strongly NP-hard. To solve the problem a simple but efficient heuristic strategy is proposed. @ 1998 Elsevier Science B.V. Keywords: Real-time

systems;

Scheduling;

Cyclic tasks; Combinatorial

problems;

1. Introduction In real-time systems, e.g. in an air craft controller, there are many tasks which are executed in parallel. Most demanding are so called hard real-time tasks. Each hard real-time task is assigned a deadline and its execution must complete before the deadline. Usually hard real-time tasks are vital to the system and missing the deadline can lead even to a disaster. Many of hard real-time tasks are cyclic (there are also sporadic tasks but they can be transformed into cyclic ones [ 81) . A cyclic task is assigned a period p and it must be repeated every p units of time, i.e., it must be executed within each interval of time [ kp; (k + 1)~)) and (k + 1)p is the deadline for the k = 0,1,2,... kth instance of the task. Now the problem arises, how to schedule hard real-time cyclic tasks to meet all the deadlines. Two approaches are possible: * Corresponding author. Email: [email protected]. ’ This work was financially supported by KBN grant ST1 1C 040 12. 0020-0190/98/$19.00 @ 1998 Elsevier Science B.V. All rights reserved. PII SOOZO-0190(98)00221-4

Computational

complexity

dynamic scheduling (scheduling decisions are made at run-time; a good example is the highest priority first approach, where priority can be either static or dynamic), static scheduling (a timetable is computed at compile time and it is used by a dispatcher at run-time; the timetable sho:vs which task should be executed at the moment; the table’s size is the least common multiple of all the periods) . To make scheduling, testing and debugging simpler, a class of cyclic tasks with binary periods has been introduced and studied in the literature [ 2,5-7,9]. For these tasks periods are no longer random values but they have to form a geometrical progression with the quotient equal to 2 (there can be 0, 1 or more tasks having a given period). Thus, there is a so-called basic period PO, and for task c its period pi equals to 2jpa for some j = 0, 1,2,. . .. The MAFT distributed system [6,7] and implementations of MILSTD-1553 communications protocol (see [ 9, lo] ) are

J.R. Nawrockillnfonnarion Processing Letters 65 (1998) 173-178

174

examples of systems in which the idea of restricting periods to binary progression has been applied in practice. The problem of scheduling cyclic tasks with binary periods was considered already in the mid 70-ties by Gonzalez and Soh [ 51. However, they have made two assumptions that radically simplified the problem. They have assumed that pr = pa and for every task z (i > 1): l pi = 2pi-I, l

Ed

+e;


The last assumption is very strong. In such a case our heuristic, which is presented in Section 3, becomes an optimal strategy. A similar problem was investigated by Schweitzer, Dror, and Trudeau 191. The main difference between their approach and the approach applied in the paper is that they do not allow tasks to be placed on the border between basic periods. It seems that such a constraint is too restrictive. It means that no task can have its duration time (i.e., execution time) longer than the basic period pe. Recently Cai and Kong [2] have shown that scheduling periodic tasks on a uniprocessor system when each task ‘I;:+1 has a period K;p; (i > 1, K; is a positive integer) is strongly NP-hard. HOWever, the assumption that K; can be any positive integer is essential in their proof. In our paper we have shown that even if K; E { 1,2}, the problem remains strongly NP-hard. They have also proposed a linear (in the number of task instances) scheduling algorithm, but their algorithm can schedule only such tasks Tt, . . . ,T;, . . . , T, that pi = 2pi_t, i.e., for every period pi there is only one task of that period. The approach presented in the paper, when compared with those discussed in [ 2,5,9], is the most general. We can schedule tasks which are too big to be scheduled by algorithms presented in [5,9]. Moreover, we allow several tasks of the same period this is forbidden in [2,5]. In the next section we show that static scheduling of cyclic non-preemptable tasks with binary periods which are to be executed on one processor is strongly NP-hard. It means that there is practically no chance to find a polynomial or pseudo-polynomial algorithm for it. Thus, in Section 3 a heuristic strategy is proposed which is simple but, according to evaluation presented in Section 4, quite efficient.

2. Complexity periods

of scheduling

tasks with binary

In this section, first the problem of scheduling tasks with binary periods will be specified, then it will be shown that the problem is NP-hard, and finally it will be proved (by extending the proof of the first theorem) that the problem is strongly NP-hard. In the case of cyclic tasks each task has to be repeated (executed) a number of times. Each single execution of a task is called a task’s instance. For cyclic tasks of periods pt , ~2,. . . , pn it is sufficient to consider the time horizon equal to the least common multiplier (lcm) of pt , p2, . . . , pn. If every period equals 2jpo for some natural j, then lcm( {pl , ~2, . . . , p,)) = and a task of period pi has F; = max{pl,p2,. . . ,p,} instances, i.e., it has to be ex~2, . . . , p,}/pi ecuted Fi times within the time horizon. The problem of scheduling tasks with binary periods (STBP problem for short) can be specified in the following way:

max{pt ,

STBP problem (Scheduling tusks with binary periads) Given. A set of non-preemptable cyclic tasks T,, , . . , T,, which are to be executed on one processor. Each ?;: is characterised by a period pi = 2jpo (PO is the smallest period, j E (0, 1,2,. . . , .I}) and execution time ei (~0, e; are real numbers greater than zero). For each task z, deadline d; = p; and ready time is zero. Let max{pt,pz,. . . ,p,} = H (H stands for horizon of time), and fi = H/pi. There are no precedence constraints. Question. Can every T; be scheduled within its period pi, i.e., does there exist a function S( i, k) (S( i, k) stands for starting time of the kth instance of task Z) such that l every instance of T; starts within its period (instances are numbered from 1) :

.

vkz l
vi:.E{l,...,n} (k l

lIpi

<

S(i,k)

<

kpi,

every instance of T; finishes before the next period 0fC: vi:.E{l,...,n}

(k-

vkzI
l)pi < S(i,k)

fe;

< kp;

J.R. Nawrocki/Inforfnation 0.5

Tl

z s(a)

0.5

IT2j-FjTl/ PO

Tl T21Tl

T3 PO

PO

Processing

_F$ PO

tasks do not overlap: 73r:O
S(

il , kl ) < ei,

&O
3kz:l
3kl:lQh

1. The STBP problem

175

z s(a)

Fig. 1. An outline of a feasible schedule for an instance of the STBP problem obtained by transformation from the partition problem.

l

Letters 65 (1998) 173-178

PO

PO

PO

PO

Fig. 2. In a feasible schedule the second and the third instance of Tl have to surround T3.

the restrictions concerning tasks TI, T2, and T3 also are obeyed. Now assume the answer to the STBP problem is YES. It will be shown that the answer to the corresponding instance of the partition problem is also YES. First let us note the following properties:

? is NP-hard.

Proof. Since tasks are periodic and in period 2Jpo there are 2J instances of task T, that have to be considered, it is not clear whether the problem belongs to NP or not. Thus, we can only show that the problem is NP-hard. We will do it by presenting a polynomial transformation from the partition problem to the STBP problem. An instance of the partition problem consists of a finite set of elements A and each element a has an integer size s(a). The question is whether A can be split into A’ and A - A’ in such a way that total size of elements belonging to A’ is the same as for A - A’ (see e.g. [ 41) . Given an instance of the partition problem one can build a corresponding instance of the STBP problem in the following way. Three auxiliary tasks are introduced: l Tl of period p1 = po and el = 1, l T2 of period p2 = 2~0 and e2 = 1, l T3ofperiodp3=4poande3=2po-2el =2po-2, Moreover, for every element a E A of size s(a) a task of period 4~0 and of execution time s(a) is introduced. Period po equals el + e2 + 0.5 CaEA s(a) = 2 + 0.5 CaEA s(a). Assume the answer to the partition problem is YES. Then, for the transformed problem, one can build the schedule shown in Fig. 1. It is a feasible schedule, i.e., it gives a positive answer to the question. The point is that if one can partition the set into two disjoint subsets A’ and A - A’ of the same total size 0.5 CaEA s(a), then one can “place” elements corresponding to A’ in a shadowed area named L (L for Left) and elements corresponding to A - A’ will be in a shadowed area named R (R for Right). It is easy to check that all

Property 2. For a feasible schedule task T3 cannot start earlier than at po + el. Proof. If T3 started at 0, then it would finish at 2~0 - 2 and the first instance of Tl would miss its deadline. So, assume T3 started immediately after Tl. Then T2 or the second instance of Tl would miss its deadline it is so, because el + e3 + el + e2 > 2~0. Assume that T3 starts not earlier than at el + e2 and before po + el . Then the second instance of TI will not be able to finish before its deadline, because x + e3 + el > 2~0 foreveryxE [el +ez;po+el). 0 Property 3. For a feasible start later than at po + el.

schedule task T3 cannot

Proof. Assume T3 started at po + el + x and n E (0;po). Then T3 would finish at po + el + x + e3, i.e., at 3~0 - el + x. It means that the third instance of Tl would miss its deadline (which is 3~0). So, consider T3 starting at 2~0 + el + x where x > 0 (this would give the third instance of TI a chance to finish before its deadline) and let T3 finish before its deadline. Because e3 = 2~0 - 2, one cannot execute T3, the second instance of T2, the third and the fourth instance of Tl during last two periods po. q From Properties 2 and 3 follows that T3 has to start atpo+el . To schedule the second and the third instance of Tl before their deadlines they have to surround T3 like in Fig. 2. Moreover, area denoted “First”) on the figure has to contain the first instance of Tl ( TI must appear once within the period PO) and the first instance of T2 (T2 must appear once within the period 2~0, but there is no

J.R. Nawrocki/lnforlnation

176

Tl T2

Processing

B

TI 71 T2

T3

Tl

B

Letters 65 (1998) I73-I 78

Tl T2

B

-

.‘ Tl

B

TI Tl T2

T3

*

l

PO

PO

PO

PO

PO

PO

PO

PO

Fig. 3. A solution to the binary periods problem for m’=4 when the answer to the 3-partition

place within the second PO, so it has to appear within the first PO). Thus, the total size of tasks corresponding to elements of A and allocated in “First” cannot be greater than po - el - e2 = po - 2 = 0.5 CaEA s(a), Since the total size of tasks corresponding to elements of A and assigned to “First” and “Last” is CaE s(a), it means that the total size of elements of A placed in “Last” is greater or equal 0.5 CaE s(a). Thinking in the similar way one will come to the conclusion that the total size of tasks corresponding to elements of A and placed in “First” is greater or equal to 0.5 CoEA s(a). From the above two paragraphs it follows that the total size of tasks corresponding to elements of A and placed in “First” is 0.5 CaEA s(a). Thus, the answer to the partition problem is YES. This ends the proof of the theorem. 0 A

A

The way in which we have proved Theorem 1 shows that the problem remains NP-hard even if the set of periods is limited to {pa, 2pa,4pa}. Theorem 4. The STBP problem is strongly NP-hard. Proof. A transformation from the 3-partition problem [ 1,4] will be shown. An instance of the 3-partition problem consists of a natural number B and a set A containing 3m elements. Each element u E A has a natural size s(a) such that B/4 < s(a) < B/2 and the total size of elements belonging to A is mB. The question is whether A can be partitioned into m disjoint subsets Al, AZ, . . . , A, such that total size of elements belonging to each subset is B. It follows that each subset must contain 3 elements. If m = 1, the 3-partition problem is trivial. Let 2’-’ < m < 2’. Set m’ = 2’. The instance of the STBP problem corresponding to an instance of the 3-partition problem resembles an instance presented in the proof of Theorem 1 (see Fig. 1) - this is, in fact, the same instance but repeated m’/2 times and period po equals B + er + e2 = B + 2. The period po will be called

problem is YES

a basic period. Tasks TI, T2 and T3 are defined as in the proof of Theorem 1: TI has period p1 = p. and ei = 1, T2 has period p2 = 2pa and e2 = 1, T3 has period p3 = 4pa and es = 2pa - 2ei = 2pa - 2. The set A is augmented to A’ by adding ml - m elements of size B, i.e., for a E A’ \ A s(a) = B these elements have to occupy extra space provided by approximating m with m’. For every element a E A’ there is a task of period 2m’po. Its execution time is s(a). Assume the answer to the 3-partition problem is YES. Then one can use a schedule pattern similar to that presented in Fig. 3. Shadowed rectangles represent empty “bins”, each of size B. m’ -m bins will be filled in with tasks of size B. The remaining m bins can be used for placement of m triples of elements of A such that total size of each triple is B. Thus, the answer to the STBP problem is YES. Assume the answer to the STBP problem is YES. There are 2m’ instances of task TI, m’ instances of T2, and m’/2 instances of T3. Let us number instances of tasks Tl, T2 and T3, and instances of the basic period with integers 0, 1,2,. . .. Thinking in a way similar to that presented in the proof of Theorem 1 one can prove the following properties: In a feasible schedule instance k of task T3 (0 < k 6 m’/2 - 1) cannot start earlier and cannot start later than at 4kpo + po + el . Instance k of T3 have to be surrounded by instance 4k + 1 and 4k + 2 of Tl - compare with Fig. 3. It means that instance 4k+ 1 and 4k+2 of basic period are completely occupied with tasks Tl and Ts. Within instance 4k of basic period the following tasks have to be executed: instance 4k of T,, instance 2k of T2, and some tasks corresponding to elements of A’. Since et = e2 = 1 and po = B + 2, the total size of tasks corresponding to elements of A’ and executed within instance 4k of basic period is not greater than B. The same is with instance 4k + 3 of basic period.

J.R. Na wrockilhfonnation Processing Letters 65 (I 998) 173-I 78

Let a shadowed basic period denote a basic period within which one can execute tasks corresponding to elements of A’, i.e., it is a basic period number 4k or 4k + 3. The number of shadowed basic periods is m’. Since the total size of tasks corresponding to elements of A’ is m’B, the total size of tasks corresponding to A’ and executed within one shadowed basic period must be B. Thus, the answer to the 3-partition problem is YES. Obviously, the transformation presented above is polynomial one (m’ is never greater then 2m). Fig. 3 shows a schedule for a case when m’ = 4 and the answer to the 3-partition problem is YES. 0 l

3. A heuristic strategy Since the STBP problem is strongly NP-hard, there is, practically, no chance to find a polynomial or pseudo-polynomial time algorithm. Below a heuristic strategy is presented that solves the problem in O( z2> time, where z is the number of task instances. Algorithm 1. Input: The number of tasks ~1,the smallest period PO, and a sequence of (2j, ei) describing for a task Ti its period pi = 2jpe and execution time ei. Output: A timetable being a sequence of pairs (t, i) sorted according to the increasing order oft. A pair (t, i) says that at moment t task I;: is scheduled. Steps: 1.

Sort tasks according to the non-decreasing order of their periods (2jpa). Tasks of the same period 2jpe form a level j and max is the maximum value of j. 2. For every level j from 1 to mux do the following: 2.1. Sort tasks belonging to level j according to non-increasing order of their processing time (LPT rule). 3. For every level j from 1 to mux do the following: 3.1. For every task of level j schedule its 2max-j instances with starting time k2jpo and deadline (k+ 1)2jpo for k E [0, 2mM-j- l] using the first fit strategy, which considers virtual gap sizes (see the explanation below). In Step 3.1 tasks are scheduled at the earliest possible moment. In the future such a task, if necessary, can be moved right. To enable this, each task instance is

Tl:

n

n s=3 e=3

T2:

1 I

n

n

s=3 e=3

I

S=l e=3

T4.

111

I

n s=3 e=3

s=3 e=3

I

I

I

s=3 e=O

n s=l e=3

,:

s=3 e=O

,(

s=2 e=O

s=l

e=l

T3:

L-L--

l

I

I s=l e=o

Fig. 4. An illustration of scheduling the tasks from ExampIe 5.

assigned an attribute r specifying how far a given task instance can be moved. By moving a task instance following a gap one can extend such a gap. For each gap an attribute e is computed which tells how far a given gap can be extended towards the right. Let p denote placement of a task (i.e., the moment corresponding to its beginning), let s denote size of a gap or task and d - deadline of a task. Then one can compute the e attribute of each gap by going from right to left and using the following rules: l For the last gap g: g.e = 0. l If a gap g precedes a task t, then g.e = t.r. l For a task t preceding a gap g: t.r = min{g.s + g.e, t.d - t.p - t.s} l For a task t preceding a task t’: t.r = min{t’.r, t.d - t.p - t.s} The first fit strategy takes into account the virtual size (i.e., g.s + g.e) instead of the physical size of a gap (i.e., g.s), however gaps with physical size g.s equal to zero are not considered. Example 5. Assume basic period po is 4 time units and there are 4 tasks which are to be scheduled: Tl of period po and size 1, T2 of period 2pe and size 2, T3 and T4 of period 4~0 and size equal to 2 and 5, respectively. After sorting the tasks according to their periods and LPT one will get the following lists: (1) period po: (TI) (2) period 2~0: (T2) (3) period 4~0: (T4, T3) Because the size of TJ is greater than the size of T3, T4 precedes Ts on the third list. The scheduling activities performed during Step 3 of the algorithm are depicted in Fig. 4. The tasks will be considered in

178

J.R. Nawrocki/Infonnation

Processing

the following order: Tl, T2, T4, Tj. Since the maximal period is 4pe and TI has period PO, four instances of TI will be scheduled at the earliest possible moment (in Fig. 4 they are represented as white boxes). Next, 2 instances of T2 are scheduled with period 2pa (the corresponding boxes are light shadowed). An interesting moment is when the instance of T4 is scheduled (strongly shadowed box). It cannot be placed in the first gap, because the gap is too small (its size is 1 + 3 = 4, while Ts’s size is 5). So, the second gap is inspected. Its virtual size is 3 + 3 and that gap is taken. But the real size of the gap is 3. Thus, the gap is extended by 2 time units and 3 tasks are moved right: the last instance of T, is moved by 1, the last instance of T2 is moved by 2, and the 3rd instance of TI is moved by 2. To allocate T3 (black box) the first gap is used - its virtual size is equal to the size of Ts. However, the real size s is smaller than the task’s size, so all the tasks following the gap have to be moved by 1 time unit.

4. Evaluation

of the heuristic strategy

First let us notice that none of the algorithms presented in [2,5,9] can schedule the instance of the STBP problem discussed in Example 5, but the algorithm presented in Section 3 can do it. Moreover we have used our strategy to solve a practical problem of scheduling tasks for F-16 aircraft [9,10]. Using our heuristic one can schedule the tasks with basic period po equal to 276 while the best solution presented in [9] requires po to be not shorter than 278. Obviously, the two above cases are not representative. To examine the quality of the algorithm on randomly generated instances of the STBP problem we have used the exact algorithm proposed by Xu and Parnas [ 111. Let V denote utilisation of processor time by all the instances of all the tasks (0 < V 6 1) ,p,}/pg. We have tested the andL=max{pt,p2,... heuristic strategy for L = 8,16,32 and for average number of tasks per basic period equal to 2 and 3. It has proved that for V not greater than 0.9 the algorithm could schedule every randomly generated instance of the STBP problem which was schedulable (i.e., the algorithm of Xu and Parnas could find a feasible schedule for it). Evaluation of the heuristic strategy for L equal to 64 and above was impossible, because the

Letters 65 (1998)

173-l 78

algorithm of Xu and Parnas required too much time (each instance of the STBP problem has to be transformed to an instance of the Xu-Parnas problem and the size of the transformed instance grows exponentially with L). More details can be found in [ 31.

Acknowledgements The authors are grateful to Jacek Blazewicz, Moshe Dror, Maciej Drozdowski, Roger Kieckhafer, Reinhard Wilhelm, and to an anonymous reviewer for their comments and valuable remarks.

References r11 J. Blazewicz, K.H. Ecker, G. Schmidt, J. Weglarz, Scheduling Computer and Manufacturing Processes, Springer, Berlin, 1996. 121 Y. Cai, MC. Kong, Nonpreemptive scheduling of periodic tasks in uni- and multiprocessor systems, Algorithmica 15 (1996) 572-599. cyclic tasks with [31 A. Czajka, J.R. Nawrocki, Scheduling binary periods: a simple heuristic strategy and its evaluation (in preparation). [41 M.R. Garey, D.S. Johnson, Computers and Intractability: A Guide to the Theory of NP-Completeness, W.H. Freeman and Company, San Francisco, CA, 1979. [51 M.J. Gonzalez Jr, J.W. Soh, Periodic job scheduling in a distributed processor system, IEEE Trans. Aerospace and Electronic Systems 12 (1976) 530-535. [61 R.M. Kieckhafer, C.J. Walter, A.M. Finn, PM. Thambidurai, The MAFT architecture for distributed fault-tolerance, lEEE Trans. Comput. 37 (1988) 398-405. 171 R.M. Kieckhafer, Fault-tolerant real-time task scheduling in the MAFT distributed system, in: Proc. 22nd Hawaii Intemat. Conf. on System Science, 1989. systems 181 A.K. Mok, The design of real-time programming based on process models, in: Proc. IEEE Real-Time Systems Symp., 1984. 191 P.J. Schweitzer, M. Dror, P. Trudeau, The periodic loading problem: formulation and heuristics, INFOR 26 ( 1988) 4062. 1101 D.E. Sundstrom, W.B. Anderson, S.A. Alford Jr, F-16 Multiplex: a system perspective, in: Proc. 2nd AFSC Multiplex Data Bus Conf., 1978. IllI 1. Xu, D.L. Parnas, Scheduling processes with release times, deadlines, precedence and exclusion relations, IEEE Trans. Software Engineering 16 (1990) 360-369.