Professional Documents
Culture Documents
Multiple-Resource Periodic Scheduling Problem: How Much Fairness Is Necessary?
Multiple-Resource Periodic Scheduling Problem: How Much Fairness Is Necessary?
5 5 2 5 6 5 5 5 3 6 5 2 5 4 6 5 5 2 5 6 5 5 5 3 6 5 2 5 4 6
0 5 6 10 12 15 18 20 24 25 30
a. A proportional fair schedule
1 2 3 4 1 1 2 3 4 1 2 1 3 4 1 2 3 4 1 2 3 5 1 2 3 4
4 5 6 5 5 6 4 5 5 6 4 5 5 6 4 5 6 4 5 6
0 5 6 10 12 15 18 20 24 25 30
b. A boundary fair schedule
Figure 1. Different fair schedules for the example; the dot lines are period boundaries
The remainder of this paper is organized as follows. Sec- • C1: A resource can only be allocated to one task at any
tion 2 defines the boundary fairness and related concepts time, that is, resources can not be shared concurrently;
and gives a motivating example. Section 3 presents a BF al- • C2: A task can only be allocated at most one resource
gorithm and its complexity analysis. The correctness of the at any time, that is, tasks are not parallel and thus can-
BF algorithm is presented in Section 4. Experimental re- not occupy more than one resource at any time.
sults are reported in Section 5. Closely related work is dis-
Assume that the least common multiple of all tasks’ pe-
cussed in Section 6 and Section 7 gives out our conclusion.
riod is LCM and the first instance of each task is avail-
able at time 0. Because of the periodic property of the prob-
2. Preliminaries lem, we only consider the schedule from time 0 to time
LCM . We define a set of period boundary time points
In this section, we formally state the multiple-resource
as B = {b0 , . . . , bf }, where b0 = 0, bf = LCM and
periodic scheduling problem, and define the boundary fair-
∀c, ∃(i, k), bc = k · pi and bc < bc+1 (c = 0, . . . , f − 1).
ness as well as related notations. An example is also pre-
Define time unit (or slot) t as the real interval between
sented to illustrate the idea of boundary fairness.
time t − 1 and time t (including t − 1, excluding t), t ∈
The system consists of m identical resources and n pe-
{1, 2, 3, . . .}. For convenience, we use [bk , bk+1 ) to denote
riodic tasks, {T1 , . . . , Tn }, where each task Ti = (ci , pi ) time units between two boundaries, bk and bk+1 , including
is characterized by its resource requirement ci and its pe-
time unit bk and excluding time unit bk+1 . Define alloca-
riod pi . ci and pi are integer multiples of a system unit time. tion error for task Ti at boundary time bk as the difference
The deadline for each task instance is the task’s next period between bk · wi and the time units allocated to Ti before bk .
boundary. The weight for task Ti is defined as wi = pcii ,
n A periodic schedule is boundary fair if and only if the ab-
and the system utilization is U = i=1 wi . Without loss solute value of the allocation error for any task Ti at any
of generality, we assume that wi < 1 (notice that actu- boundary time bk is less than one time unit.
ally 0 < wi ≤ 1; if wj = 1, we can dedicate one re-
source to Tj and consider the remaining tasks on the re- Lemma 1 For the multiple-resource periodic scheduling
maining resources). We also assume that the system utiliza- problem, if the system utilization, U , is no bigger than m,
tion U = m, the number of resources available1 . the number of resources, a boundary fair schedule exists.
The multiple-resource periodic scheduling problem is to Proof If U ≤ m, a proportional fair (Pfair) schedule is
construct a periodic schedule for the above tasks, which al- known to exist for the multiple-resource periodic schedul-
locates exactly ci time units of a resource to task Ti within ing problem [4]. From the definitions, we know that any
each interval [(k−1)·pi , k·pi ) for all k ∈ {1, 2, 3, . . .}, sub- Pfair schedule is also a boundary fair schedule (a Pfair
ject to the following constraints [5]: schedule also conforms to the allocation error requirements
at boundaries). That is, a boundary fair schedule exists if
U ≤ m.
1 If m − 1 < U < m, we can add one dummy task Tn+1 = (c, p)
n+1 ♦
such that i=1
wi = m. If U ≤ m − 1, we can just use U re- To illustrate the idea of boundary fairness, we first con-
sources [11]. sider an example task set that has 6 tasks: T1 = (2, 5),
the BF algorithm and 30 for the P F algorithm [4]. Fur- • After allocation, ni=1 RWik+1 = 0 (which means
thermore, the schedule generated by BF (Figure 1b) will resources are fully allocated) and ∀i |RWik+1 | < 1
also incur less context switches than the schedule gener- (which means the schedule is fair).
ated by P F (Figure 1a).
These observations will be used to present the correctness
From this example, we can see that when allocating the
of our algorithm as shown in the next section.
resources in [bk , bk+1 ):
• The summation of the mandatory units is less than or 4. Analysis of the BF Algorithm
equal
n to the time units available (see Lemma 3):
k+1
i=1 m i ≤ (bk+1 − bk ) · m; First, we recall that P Wik = RWik−1 + (bk − bk−1 ) ·
• There are enough eligible tasks to claim the remain- wi − mki (where mki = max{0, RWik−1 + (bk − bk−1 ) ·
ing units if any (see Lemma 4): wi }), and RWik = P Wik − oki . For convenience, we define
the number of eligible tasks ≥ (b k+1 − bk ) · m −
some notations. Three task sets are defined as in [4]:
n k+1
i=1 mi ; AS k = {Ti |RWik < 0} : ahead task set at bk ;
PS k−1 PS k o k=0 PS k
Figure 2. Task transitions from bk−1 to bk . UFxk−1
Tx
tx t
UFyk−1
Ty
From these definitions, we can get task transitions be-
tween bk−1 and bk as shown by Figure 2. For example, ty t
∀Ti ∈ P AS k , Ti was ahead at bk−1 and got no manda- bk−1 bk
tory unit. Moreover, Ti will get no optional unit (since it
Punctual time point for tasks
is not an eligible task) and still be ahead at bk . That is,
P AS k ⊆ AS k−1 and P AS k ⊆ AS k . For task Ti ∈ Figure 3. Urgency factors for different tasks.
AS k−1 , it is also possible for Ti to have enough work de-
mand during [bk−1 , bk ) and belong to P S k or P BS k . For
task Ti ∈ P BS k , Ti may get an optional unit to become
ahead or get no optional unit and remain behind at b k . Lemma 2 If ∃Tx ∈ P AS k , ok−1x = 1, and ∀Ty ∈ ES k−1
From the BF algorithm, we can easily get the following (x = y), then αk−1 (Ty ) = − and U Fyk−1 ≥ U Fxk−1 >
properties of the defined task sets. bk −bk−1 . ♦
Property 1 For the defined task sets: To prove that the BF algorithm correctly generates a
(a) If Ti ∈ BS k−1 and mki = 0, Ti ∈ P BS k ; boundary fair schedule, first we show that two conditions
(b) If αk−1 (Ti ) = + and Ti ∈ AS k , mki + oki = bk − bk−1 ; are always satisfied during allocating [bk−1 , bk ): (1) the
(c) ∀Ti ∈ P AS k , mki = oki = 0 and RWik−1 < RWik < 0; summation of all tasks’ mandatory integer units is at most
(d) If Ti ∈ BS k−1 and mki = oki = 0, Ti ∈ BS k and
equal to the available time units on the m resources; (2)
0 < RWik−1 < RWik ;
(e) If Ti ∈ AS k and mki = oki = 0, Ti ∈ AS k−1 and
there are enough eligible tasks to claim any available op-
αk−1 (Ti ) = − ; tional units. The proof for these conditions is by contradic-
(f) If Ti ∈ BS k and mki = bk − bk−1 , Ti ∈ BS k−1 and tion, that is, if any one of these two conditions is not met,
αk−1 (Ti ) = + ; we can show that there will be at least one task ahead and
(g) If Ti ∈ AS k−1 ∩ AS k and mki + oki = bk − bk−1 , RWik < one task behind in every one of the previous boundaries;
RWik−1 < 0; this will contradict the fact that there is at least one bound-
Define two task sets P W AS (possibly-wrong ahead AS k−2 , from Property 1c, we have ∀Tx ∈ P W AS k−2 ,
set) and P W BS (possibly-wrong behind set) for bound- mxk−1 = oxk−1 = mkx = okx = 0. Therefore:
ary bk−1 as follows: k
k
P Wi > P Wi
P W AS k−1 = {Tx |Tx ∈ P AS k }; Ty ∈P BS k Ty ∈BS k−2
P W BS k−1 = {Ty |(Ty ∈ BS k−1 )AN D(mky ≥ 1)};
> RWik−1 > RWik−2
k−1 k−1 ∈BS k−2 ∈BS k−2
Notice that, both P W AS and P W BS are not Ty
Ty
empty. Otherwise, if PW AS k−1 = ∅, we have i P Wik ≥ = − RWik−2 ≥ − RWik−2
0, which contradicts i P Wik ≤ −1. If P W BS k−1 = ∅, Tx ∈AS k−2 Tx ∈P AS k−1
we have ∀Ti ∈ BS k−1 , mki = 0. From Property 1a, ≥ − RWik−2 > − P Wik
Ti ∈ P BS k and BS k−1 ⊆ P BS k . Therefore: Tx ∈P AS k Tx ∈P AS k
k
P Wi ≥ k k−1
>0
P Wi > RWi that is, i P Wik > 0, which is a contradiction.
Ti ∈P BS k Ti ∈BS k−1 Ti ∈BS k−1 So, both P W AS k−2 and P W BS k−2 are not empty.
Similarly, this will lead to either:
Notice that P AS k ⊆ AS k−1 , therefore:
(i) ∀Tx ∈ P W AS k−2 , Tx ∈ P AS k−2 ; or
k−1
RWi < k−1
RWi < P Wik < 0 (ii) ∀Ty ∈ P W BS k−2 , mk−2 y = bk−2 − bk−3 ;
Ti ∈AS k−1 Ti ∈P AS k Ti ∈P AS k
If (b) is true, ∀Ty ∈ P W BS k−1 , mk−1
y = bk−1 − bk−2 .
By assumption, i RWik−1 = 0. Since ∀Ti ∈ P S k−1 , From Property 1f, Ty ∈ BS k−2 and αk−2 (Ty ) = + . Define:
RWik−1 = 0, thus Ti ∈AS k−1 RWi
k−1
= P W AS k−2 = {Tx |(Tx ∈ AS k−2 )AN D(∃Ty ∈ P W BS k−2 ,
k−1
− Ti ∈BS k−1 RWi . Therefore: α(Tx , k − 3) < α(Ty , k − 3))};
P W BS k−2 = P W BS k−1 = ∅;
k
P Wi > k−1
RWi =
Ti ∈P BS k Ti ∈BS k−1
If P W AS k−2 = ∅, then ∀Tx ∈ AS k−2 and
∀Ty ∈ P W BS k−2 , α(Tx , k − 3) ≥ α(Ty , k − 3).
− RWik−1 > − P Wik
Thus αk−2 (Tx ) = αk−2 (Ty ) = + . Since mky ≥ 1,
∈AS k−1 ∈P AS k
Ti Ti
whatever the value of αk−1 (Tx ) is, we will have
k
Tx ∈ (P BS k ∪ P S k ). Notice that P AS k = ∅, we
hence > 0 that contradicts i P Wik ≤ −1.
i P Wi
k−1 have ∃Tz ∈ ((BS k−2 − P W BS k−2 ) ∪ P S k−2 ),
So, both P W AS and P W BS k−1 are not empty.
Tz ∈ P AS k ⊆ AS k−1 (i.e., ok−1 z = 1). Note that
From Lemma 2 and the BF algorithm, we will get either: αk−2 (Tz ) < + (otherwise, Tz ∈ P W BS k−2 , a contradic-
(a) ∀Tx ∈ P W AS k−1 , Tx ∈ P AS k−1 ; or tion). Since ∀Tx ∈ AS k−2 , αk−2 (Tx ) = + (i.e., Tx ’s pri-
(b) ∀Ty ∈ P W BS k−1 , mk−1
y = bk−1 − bk−2 ; ority is higher than Tz ’s) and mk−1
x < bk−1 − bk−2 ,
Otherwise, ∃Tx ∈ P W AS k−1 and ∃Ty ∈ P W BS k−1 there will be ok−1
x = 1 and Tx ∈ AS k−1 (notice
40 50 2.5
40
35 30 2
20
30 1.5
10
25 0 1
20 30 40 50 60 70 80 90 100 20 30 40 50 60 70 80 90 100
the maximum period the number of tasks
Figure 4. The number of scheduling points of Figure 5. The per-invocation and overall exe-
BF vs. P D cution time (in cycles) of BF and P D
However, both priority comparison functions have the same algorithms on the SimpleScalar micro-architecture simula-
complexity of O(1) and we do not expect P D2 can improve tor [7]. As mentioned before, to select k highest priority
on P D too much, especially when both of them are imple- tasks from n tasks, the task selection function can be im-
mented in O(n) where P D can effectively limit the search plemented in O(n) [6]. However, our implementation uses
space as discussed in this paper while P D2 cannot. a simple search technique with a complexity of O(k · n).
In our experiments, each task set contains 20 to 100 tasks For the P D algorithm, we implement its constant time
and the period for a task is uniformly distributed within the priority comparison function. To limit the search space of
minimum and maximum periods considered. The minimum the task selection function, tasks are first divided into 7 pri-
task period is set as 10. For each data point, we averaged ority categories [5] with the complexity of O(n); then the
the results for 100 randomly generated task sets. First, we tasks are selected from high priority category to low prior-
vary the maximum period from 20 to 100 and show the re- ity category; if not all tasks in a category can be selected,
duction of scheduling points of BF compared with P D. the O(k · n) task selection function is used within that cate-
The scheduling points for BF are the period boundaries of gory. In this way, we effectively reduced the number of pri-
all tasks which are independent of tasks’ resource require- ority comparison needed by the P D algorithm. While the
ment, while there are LCM scheduling points for P D. The complexity of implemented P D algorithm is still O(m · n),
results are shown in Figure 4; these results are conserva- where m is the number of resources, the results (see below)
tive since we discarded all task sets with LCM > 232 . are almost linear with the number of tasks.
From Figure 4, we can see that the number of schedul- Similarly, for BF , eligible tasks are first divided into 3
ing points of our BF algorithm varies from 25% to 48% of categories based on their characters (corresponding to + ,
the P D algorithm. For a fixed maximum period, when there 0 and − ) for the current boundary time. We implement
are more tasks in a task set, a time point is more likely to the constant time priority comparison function as described
be a period boundary and there are more scheduling points in Section 3 and the implemented BF algorithm has an
for BF . For a task set with fixed number of tasks, the pe- overall complexity of O(n2 ). Note that at most n − 1 op-
riods of tasks are more separated with higher maximum tional units need to be allocated per-invocation for BF .
period and thus there are less period boundaries and thus Figure 5 shows the execution time (in cycles) of each
scheduling points for BF . Even when there are 100 tasks scheduling instance. We fix the maximum period as 100
in a task set, BF has only 48% scheduling points compared and the resource requirement of a task (ci ) is uniformly dis-
with P D. For applications in real-time systems, tasks are tributed between 1 and its period (pi ); thus, on average, the
more harmonic than randomly generated task sets and more number of resources is around half of the number of tasks.
scheduling points reduction is expected. For example, in a From Figure 5 we can see that BF uses more cycles per-
harmonic task set, the number of scheduling points for BF invocation than P D (note that, the actual per-invocation cy-
is LCM/mini (pi ). In the future, we will characterize this cles of the implemented P D algorithm is almost linear with
issue more accurately. the number of tasks) and BF becomes worse as the number
Next, we compare the run-time overhead of our BF al- of tasks increases. However, as shown through the dotted
gorithm with that of the P D algorithm by running both line (which corresponds to the Y-axis on the right side of