2.3 Real-Time Scheduling
2.3.2 Partitioned Multiprocessor Real-Time Scheduling
There are two fundamental approaches to applying priority-driven scheduling to a shared-memory multiprocessor: either all available processors are scheduled using one scheduler (with, conceptually speaking, a single, shared ready queue), or the set of processors is subdivided into smaller, disjoint sets of processors that are scheduled independently (by separate priority-driven schedulers, each with a local ready queue). The former approach is calledglobal scheduling, and the latter approach is called eitherclusteredorpartitioned scheduling, depending on the number of processors per set. Under partitioned scheduling, there is only one processor in each subdivision (called apartitionin this case), whereas there may be multiple processors per subdivision under clustered scheduling (and each subdivision is called acluster). We first consider partitioned scheduling, followed by global scheduling in Section 2.3.3 below. Finally, clustered scheduling, which can be understood either as a hybrid or as a generalization of global and partitioned scheduling, is discussed in Section 2.3.4.
Partitioned scheduling, first studied in the context of real-time systems by Dhall and Liu (1978), is the multiprocessor real-time scheduling approach most commonly used in practice. Its great appeal stems from the fact that each partition (i.e., each processor) can be scheduled and analyzed using existing uniprocessor techniques. We consider both FP andEDF partitioned schedulers,
namelypartitionedFP (P-FP) andpartitionedEDF (P-EDF).9However, the reuse of existing
uniprocessor scheduling theory comes at a price. To obtainmsimpler uniprocessor problems from a multiprocessor platform consisting ofmprocessors, the task set must first bepartitioned, that is, each task must be statically assigned to a partition such that no processor is overloaded. Solving this task assignment problem requires solving a bin-packing-like problem.
Bin-packing. The bin-packing problem is a classic intractable problem that is NP-hard in the strong sense (Garey and Johnson, 1979). Given a bin capacityV and a set ofnitemsx1, . . . , xnwith
corresponding sizesa1, . . . , an, the goal is to assign each item to a bin such that the number of bins is minimized, but without exceeding the capacity of any bin. The corresponding decision problem is to determine for a given numberB whether there exists a “packing” (i.e., item-to-bin assignment) such that the items fit intoBbins.
In the context of partitioned scheduling, the items are tasks and their respective sizes are given by their utilizations. Processors correspond to bins and each bin’s effective capacityV is dependent on the scheduling policy in use and the type of deadline constraint. In the case of implicit deadlines andEDF, each processor has a capacity of 1.0. Partitioning a task set is equivalent to solving a bin-packing problem in the sense that an implicit-deadline task set is feasible onmprocessors under partitioned scheduling if and only if there exists a “packing” of all tasks intom“bins.” In other words, the bin-packing decision problem can be reduced to task-set partitioning in polynomial time (by scaling item sizes and bin sizes), which implies that finding anoptimaltask assignment in all cases is intractable (unlessP =NP). Dhall and Liu (1978) formally proved that the task assignment problem is indeed NP-hard in the strong sense by showing that a solution can be used to solve the 3-partition problem (Garey and Johnson, 1979).
The practical implication is that we can use existing bin-packing heuristics to find valid task assignments. The literature on bin-packing heuristics is extensive and a comprehensive review is beyond the scope of this dissertation. Instead, we briefly summarize the heuristics most relevant to our work and refer the interested reader to (Coffmanet al., 1997). In the description of the heuristics below, letSjdenote the set of items assigned to thejthbin and letVjdenote the remaining capacity
9
In principle, it would also be possible to use different scheduling policies on different processors,e.g., some processors could be scheduled withEDFand some withFP, but this is currently not supported in LITMUSRT(and we are not aware of any research into such mixed-policy systems). Since our main interest is to compare schedulers under consideration of overheads, we only consider “pure”P-EDFandP-FP.
of thejthbin,i.e.,V
j =V −Pxi∈Sjai. Initially, there is only one (empty) bin, but additional bins can be added by the heuristic as required. Bins are indexed in the order in which they are created.
It is generally more difficult to pack large items (in relation to the bin sizeV) as smaller items are more likely to fit into the remaining capacity of partially used bins. Therefore, it is beneficial to pack items in order of decreasing size, which is easy to accommodate during off-line partitioning. We hence assume that the items have been sorted such thata1 ≥a2 ≥. . .≥anprior to applying one of the following placement heuristics.
First-fit decreasing. To place an itemxi, thefirst-fit heuristicconsiders each bin in index order and placesxiin the first bin where it fits. That is, itemxi is added toSj ifVj ≥aiandVl< aifor each l∈ {1, . . . , j−1}. If no suchjexists, thenxiis placed in a new empty bin that is appended to the packing. Asymptotically,i.e., for a large number of bins, the first-fit decreasing heuristic requires at most 119 ≈1.22times the number of bins used by an optimal solution (Johnson, 1973, 1974). For a small number of bins (less than 4), first-fit decreasing requires no more than 1.5 times the number of bins used by an optimal solution (Simchi-Levi, 1994).
Best-fit decreasing. In contrast to the first-fit heuristic, thebest-fit heuristicconsiders all bins and selects the bin that will have minimal remaining capacity after placing itemxi. LetL={l|Vl≥ai}
denote the set of bins that have sufficient remaining capacity. Itemxiis added toSj, wherej∈L, such thatVj ≤ Vl for eachl ∈ L(prior to placingxi, with ties broken arbitrarily). If no suchj
exists, thenxiis placed in a new empty bin. The best-fit heuristic is known to compare well to other
online bin-packing heuristics (Kenyon, 1996), usually deviating only little from an optimal solution (with regard to the number of required bins). As it is the case with the first-fit heuristic, the best-fit heuristic requires (asymptotically) at most 119 ≈1.22times the number of bins used by an optimal solution (Johnson, 1973, 1974), and yields results within a factor of 1.5 of the optimal solution for small numbers of bins (Simchi-Levi, 1994).
Worst-fit decreasing. As the name implies, the worst-fit heuristic is the inverse of the best-fit heuristic, that is, itemxiis placed to maximize the remaining capacity of the bin in which it is placed.
DefineLas above. Itemxiis placed in thejthbin, wherej∈L, such thatVj ≥V
lfor eachl∈L.
Again,xiis placed by itself into a newly-added bin if no suchjexists. The worst-case performance of the worst-fit decreasing heuristic is somewhat worse than that of either the first-fit or best-fit
Assigned bin using Item size first-fit best-fit worst-fit
0.0< ai ≤0.1 bin 1 bin 2 bin 3
0.1< ai ≤0.3 bin 1 bin 1 bin 3 0.3< ai ≤0.5 bin 3 bin 3 bin 3
1.00 0.75 0.50 0.25 0.00 fill le vel V1= 0.3 V2= 0.1 V3= 0.5 S1 S2 S3
Figure 2.13: Illustration of the first-fit, best-fit, and worst-fit bin-packing heuristics.
decreasing heuristics: asymptotically, the worst-fit decreasing heuristic uses at most 54 = 1.25times the number of bins used by an optimal solution (Johnson, 1973, 1974).
Example 2.6. Figure 2.13 shows three bins with remaining capacityV1 = 0.3, V2 = 0.1, and
V3= 0.5, respectively. The bin in which the next itemxiwill be placed depends on both its sizeai
and the choice of bin-packing heuristic, as indicated by the table in Figure 2.13. Supposeai = 0.1.
Then the first-fit heuristic would assignxitoS1, the best-fit heuristic would assignxitoS2, and the
worst-fit heuristic would chooseS3. For larger items, there are fewer candidate bins; forai >0.3,
any (reasonable) heuristic must assign the item to the third bin. ♦
Assigning tasks. The above “textbook” heuristics attempt to minimize the number of bins by assigning items to partially used bins whenever possible and only allocating a new bin when absolutely required. This is a slight mismatch to the problem of partitioning a task set onto a given multiprocessor platform, where the number of processorsmis fixed. That is, it is not immediately possible to just add another processor, nor is it of great benefit to leave present processors completely unallocated to real-time tasks.10 We therefore interpret these heuristics as follows: there are initially
mempty bins, and any attempt to allocate additional bins indicates that the heuristic failed to partition the task set. This has little impact on the first-fit and best-fit heuristics, which attempt to fully allocate processors before assigning tasks to idle processors, but causes the worst-fit heuristic to spread out the total utilization more-or-less evenly among all processors.
Spreading out the load among all processors is preferable for several reasons. First, there is little benefit to leaving available processors unused. Second, from an engineering point of view, it makes each processor more resilient to transient overloads. And third, some remaining “idle” capacity is required on each processor to compensate for the inflation of task utilizations caused
by overhead accounting (see Chapter 3). For these reasons, we use the worst-fit heuristic to assign tasks to processors. While it may appear counterintuitive to use a heuristic with a worse worst-case performance than either first-fit or best-fit, the worst-fit heuristic works well in practice and has been used successfully by us in (Brandenburg et al., 2008; Bastoni et al., 2010b, 2011). This choice is further supported by experiments carried out by L´opezet al. (2004a), who considered partitioning heuristics forP-FPscheduling where the Liu and Layland (1973)RMbound is used to check schedulability on each processor. They observed that there is no significant difference among placement heuristics when tasks are placed in order of decreasing utilization (as we do). They also formally showed that all “reasonable” placement heuristics yield the same utilization bound (for the described setup) when tasks are placed in order of decreasing utilization (L´opezet al., 2004a).
Limitations. While findingoptimaltask assignments is intractable in the general case, the above bin- backing heuristics typically find near-optimal solutions. That is, for task sets that can be partitioned ontomprocessors at all, it is usually possible to find a valid task assignment, and particularly for task sets that do not fully utilize a platform (i.e., if there is ample spare capacity). Unfortunately, there exist task sets with total utilization much less thanmthat cannot be partitioned ontomprocessors, even using an optimal assignment algorithm,i.e., one that minimizes the number of required processors. For example, consider the implicit-deadline task setτABJ ={T1, . . . , Tm+1}due to Andersson
et al. (2001), where, for eachTi ∈ τABJ,pi = 2andei = 1 +for some positive. The total
utilization ofτABJ isusum(τABJ) =Pm+1 i=1
1+
2 = (m+ 1)· 1+
2 . By design, no two tasks ofτABJ
can be assigned to the same processor because their combined utilization would exceed the capacity of a single processor,i.e.,2·1+
2 = 1 + >1for >0. Therefore,τABJ requires at leastm+ 1
processors and is thus not feasible onm processors under partitioned scheduling. However, for
→0,τABJ’s total utilization approachesm+1
2 . Recall from Section 2.2.3 that implicit-deadline task
sets are feasible onmprocessors if their total utilization does not exceedm. The existence of task sets with utilization (m+1)2 ·(1 +)that are infeasible under partitioning shows that, asymptotically,
i.e., for largem, partitioned scheduling can cause up to nearly 50 percent capacity loss, no matter which scheduling policy is employed on each processor and which partitioning heuristic is being used.
However, this is merely an upper bound,i.e., it leaves open the question whether all implicit- deadline task sets with total utilization at most m+12 are necessarily schedulable under partitioning. In the case ofP-EDF, the optimality ofEDFon a uniprocessor implies that any implicit-deadline task set that can be partitioned ontomprocessors is also HRT schedulable. L´opezet al. (2004b) showed that the desired utilization bound can in fact be realized with any of the bin-packing heuristics discussed in this section (among other heuristics).
Theorem 2.5 (L´opez et al., 2004b). An implicit-deadline task set τ is HRT schedulable under
P-EDFscheduling onmprocessors ifusum(τ) ≤ m+12 when using either the first-fit, best-fit, or
worst-fit decreasing heuristic.
In fact, L´opezet al. proved a more-general result, but the special case stated in Theorem 2.5 is sufficient for our purposes. Note that even the use of an optimal bin-packing algorithm could not yield a higher utilization bound due to the existence of hard-to-pack task sets such asτABJ
above (L´opezet al., 2004b). In this sense, the stated utilization bound is the best possible. However, it is merely a sufficient, but not an exact, schedulability test. It is thus generally preferable to test whether a given task set is schedulable (either HRT or SRT) by simply partitioning the task set (if possible) and by applying an exact test to each partition. This approach also works in the case of non-implicit deadlines.
SinceEDFis optimal on a uniprocessor andFPscheduling is not, one might reasonably expect a significantly worse utilization bound underP-FPscheduling. Surprisingly, this is not the case. Oh and Baker (1998) were the first to consider a utilization bound forP-FPscheduling. They showed that no priority assignment can ensure a utilization bound higher than(m+ 1)·1 + 2m1+1
−1
, which converges to m+12 for largem. Asymptotically, the upper bound on a utilization bound under P-FPscheduling matches the general upper bound on any partitioned scheduler and is not worse than the bound forP-EDF. For example, form= 24, theP-FPbound corresponds to≈0.516m, whereas theP-EDFbound yields m+12 ≈0.521m, a minuscule difference. Oh and Baker (1998) further showed that any implicit-deadline task setτ is HRT schedulable underP-FP scheduling when used with theRMpriority assignment ifusum(τ)≤(√2−1)·m≈0.414m, hence leaving a utilization difference of0.086mcompared to the theoretical upper limit. This gap was later closed by Andersson and Jonsson (2003), who proved the following result.
Theorem 2.6(Andersson and Jonsson, 2003). An implicit-deadline task setτ is HRT schedulable underP-FPscheduling ifusum(τ)≤ m
2.
A particular, specific-purpose task assignment algorithm must be used to realize the stated bound (Andersson and Jonsson, 2003). However, as it is the case withP-EDF, it is more practical to just partition a given task set (if possible) and apply response-time analysis to each partition due to the inexact nature of Theorem 2.6. The key observation here is thatP-EDFandP-FPscheduling have a utilization bound of approximatelym2 for largem. It is therefore not readily apparent which is preferable from a capacity-loss point of view. We explore this question in the case study presented in Chapter 4.