Optimal harmonic period assignment: complexity results and approximation algorithms
 217 Downloads
Abstract
Harmonic periods have wide applicability in industrial realtime systems. Rate monotonic (RM) is able to schedule task sets with harmonic periods up to 100% utilization. Also, if there is no release jitter and execution time variation, RM and EDF generate the same schedule for each instance of a task. As a result, all instances of a task are interfered by the same amount of workload. This property decreases the jitters that happen during sampling and actuation of the tasks, and hence, it increases the quality of service in control systems. In this paper, we consider the problem of optimal period assignment where the periods are constrained to be harmonic and the task set is required to be feasible. We study two variants of this problem. In the first one, the objective is to maximize the system utilization, while in the second one, the goal is to minimize the total weighted sum of the periods. First, we assume that an interval is determined a priori for each task from which its period can be selected. We show that both variants of the problem are (at least) weakly NPhard. This is shown by reducing the NPcomplete number partitioning problem to the mentioned harmonic period assignment problems. Afterwards, we consider a variant of the second problem in which the periods are not restricted to a special interval. We present two approximation algorithms with polynomialtime complexity for this problem and show that the maximum relative error of these algorithms is bounded by a factor of 1.125. Our evaluations show that, on the average, results of the approximation algorithms are very close to an optimal solution.
Keywords
Harmonic tasks Period assignment Realtime schedulability Hard realtime1 Introduction
Selecting appropriate timing parameters for the tasks such that performance objectives and design constraints are met is an important step in the design of realtime systems. Specifically, in the realtime systems with periodic tasks, selecting suitable periods influences a number of prominent properties including the system schedulability (Seto et al. 1998; Bini et al. 2008), jobs’ response times (Bini and Di Natale 2005), and the related jitters (Wu et al. 2010). Harmonic periods, namely the periods that pairwise divide each other (Han and Tyan 1997), exhibit specific characteristics which help the designers to achieve better solutions with respect to the mentioned properties. For instance, schedulability analysis of the task sets with constraineddeadlines can be done efficiently (i.e., in polynomial time) when the periods are harmonic (Bonifaci et al. 2013). This is particularly important because in the general case the problem is hard for both fixedpriority (Eisenbrand and Rothvoß 2008) and dynamicpriority (Ekberg and Yi 2015) scheduling policies. Furthermore, while the uniprocessor schedulable utilization of the fixedpriority scheduling policy can be lower than \(70 \%\) (Liu and Layland 1973) for some periodic task sets, the respective value for the harmonic task sets is \(100 \%\) (Han and Tyan 1997).
Harmonic periods have been widely used in industrial applications ranging from radar dwell tasks (Shih et al. 2003) and robotics (Li et al. 2003; Taira et al. 2005; Mizuuchi et al. 2007; BusquetsMataix et al. 1996) to control systems with nested feedback loops (Fu et al. 2010). If periods are harmonic, it will be possible to apply optimal fault tolerant mechanisms as mentioned in Kwak and Yang (2012). In the integrated modular avionics (IMA), harmonic periods facilitate the problem of assigning tasks to the partition servers (Easwaran et al. 2009). Consequently, they reduce the size of the hyperperiod which facilitates the construction and storage of the offline schedule table used in IMA systems because then a smaller portion of RAM (or flash memory) of the system is consumed by the offline table. It is an important requirement for the systems with a limited memory such as Atmel UC3A0512 microcontroller that is used for mission critical space applications (Ruiz 2005).
Because of the mentioned advantages, finding harmonic periods for a given task set which satisfy performance requirements in the system is an important problem for many realtime systems. In Han and Tyan (1997) two algorithms called Sr and DCT have been introduced to find the largest harmonic periods which are pairwise smaller than a given set of periods. These algorithms were later used in period assignment for radar tasks (Shih et al. 2003). However, they are not designed to tackle with period ranges or to find the smallest harmonic periods with a feasible utilization. In Nasri et al. (2014) and Nasri and Fohler (2015) two pseudopolynomial time algorithms are proposed to verify the existence of a harmonic period assignment for a given set of period ranges. However, the essential complexity of the problem of finding the harmonic periods such that a design objective, such as the total utilization, is optimized is not explored. In a recent work, Xu et al. (2016) has proposed an optimal solution to find a set of harmonic periods that have the minimum total distance from a given set of periods. The proposed solution, however, has exponential computational complexity.
In the domain of control systems, Eker et al. (2000) have proposed a method to assign the period of each task such that the task set utilization remains under a certain value and a cost function that reflects the effect of task’s period on the control cost is minimized. The proposed solution, however, is limited to the cost functions that are convex. The problem of minimizing control cost using an online or offline period assignment method has been considered by Henriksson and Cervin (2005) and Bini and Cervin (2008), respectively. However, these approaches neither try nor guarantee that the resulting periods are harmonic.
In this paper, we discuss the computational complexity of finding feasible harmonic periods for a given set of realtime tasks where the goal is to maximize the total utilization while the periods must be selected from a given set of intervals. We show that the problem is NPhard by transforming the wellknown number partitioning problem to the harmonic period assignment problem. We establish the same complexity result for a variant of the problem in which the goal is to minimize the weighted sum of the periods. Additionally, we present two polynomialtime approximation algorithms for a variant of the second problem in which the periods are not bounded to any interval. We derive a tight bound of 1.125 for the maximum error of our algorithms with respect to an optimal algorithm. Simulation results show that, on average, this error is smaller than 1.125, which means that the approximation algorithm behaves very close to the optimal one. It is worth noting that the complexity of this variant of the problem, i.e., the one with unrestricted periods, is still unknown.
Our results can be used in the design of control systems in which the control performance is expressed (or can be approximated) by a linear function of the periods. In these systems, jitters in the sampling and actuation can adversely affect the quality of control (QoC) (Bini and Cervin 2008). These jitters can be efficiently reduced if the control tasks use harmonic periods because then each time the task is released, the same set of high priority tasks are released in the system. In this paper, we evaluate our period assignment solution for control systems and compare the results with an optimal nonharmonic period assignment.
This paper is an extended version of “On the Problem of Finding Optimal Harmonic Periods” by Mohaqeqi et al. (2016) that was published in RTNS 2016. The main additional contributions are as follows. In this paper, we establish the computational complexity of the problem of finding feasible harmonic periods from a set of given period ranges, where the goal is to minimize the weighted sum of the periods. In the RTNS paper, the hardness of finding feasible harmonic periods was studied only for the case of maximizing the total system utilization. Moreover, in the previous paper, the approximation error bound that we had for our approximation solutions was 2 while in this paper we have derived the tight error bound of our algorithms and show that this bound is \(\frac{9}{8} = 1.125\). Finally, we have added more experiments and considered the effect of more parameters on the relative error of our algorithms, e.g., the effect of weight of the periods in the goal function of the optimization. Furthermore, in order to assess the complexity and scalability of the proposed methods in practice, we have reported the average number of operations required by each algorithm to find harmonic periods. We have also expanded control evaluations, considering more realistic plants and realtime tasks with variable execution times.
The remainder of the paper is organized as follows; Sect. 2 introduces the notations and formally describes the considered harmonic period assignment problems. The complexity proofs are presented in Sect. 3. Next, the approximation algorithms for finding harmonic periods are presented in Sect. 4 and are evaluated in Sect. 5. A summary of the paper and a discussion on the related open problems are given in Sect. 6. Finally, the conclusion and future work are presented in Sect. 7.
2 Notations and definitions
We consider a set of n realtime tasks \(\tau _1,\ldots ,\tau _n\) with the set of worstcase execution times (WCETs) \({\mathbf {c}}=\{C_1,C_2,\ldots ,C_n\}\). Further, for each task \(\tau _i\), an interval \(I_i=[I^s_i,I^e_i]\) is given as the period range. The period of each task \(\tau _i\), which is denoted by \(T_i\), must be selected from \(I_i\). The utilization of \(\tau _i\) is defined as \(U_i=C_i / T_i\). In addition, the total utilization of the system is defined as the sum of all utilizations: \(U = \sum _{i=1}^n U_i\). We use \({\mathbb {N}}\) to denote the set of positive integers.
A set of periods is said to be harmonic if the pairwise periods divide each other. More specifically, the set of periods \(\{T_1,T_2,\ldots , T_n\}\) is harmonic if for every \(T_i\) and \(T_j\), either \(T_i / T_j \in {\mathbb {N}}\), or \(T_j / T_i \in {\mathbb {N}}\). A set of harmonic tasks is feasible if and only if \(U \le 1\). While the period ratios of harmonic tasks are required to be integer, it is assumed that the values of individual periods are not restricted to be integer.
The goal is to assign a set of harmonic periods to the task set such that some design objective is optimized. For example, for control applications, the objective could be to assign the smallest feasible periods (Bini and Cervin 2008). In this paper, we consider two harmonic period assignment problems as specified below.
Problem 1
In the subsequent sections, we refer to this problem as the utilizationmaximizing harmonic period assignment (UHPA) problem. This problem targets finding a feasible (and schedulable) set of harmonic periods which allows highly utilizing the resource. Regarding existing solutions to this problem, two pseudopolynomial algorithms to verify the existence of a harmonic assignment are already introduced in Nasri et al. (2014) and Nasri and Fohler (2015) though none of them guarantee that the resulting assignment has \(U \le 1\). In the current work, we try to shed some light on the inherent complexity of the problem.
In the second problem, the goal is to minimize the weighted sum of the selected periods, as defined below.
Problem 2
In the following, this problem is referred to as the costminimizing harmonic period assignment (CHPA) problem. CHPA can be used in the design of control systems in which the control performance is expressed as a linear function of the periods. While more complex metrics could lead to better results, a weighted sum of periods is a simple approximation, which is also used in the literature. For instance, in Cervin et al. (2002), it is argued that linear cost functions are reasonable approximations for plants that are sampled reasonably fast.
Moreover, if periods are not harmonic (even if there are harmonic groups), the jobs’ response time may vary, and then, (i) calculating the responsetime jitter becomes an issue (see Eisenbrand and Rothvoß 2008), and, (ii) the cost function now also depends on the jitter, making the overall design problem harder. In contrast, for those applications in which execution times are constant, in the described problems, jitters are forced to be 0 by forcing the periods to be harmonic. Thus, it both allows more accurate description of the controller cost function and less jitter.
In this paper, we provide a lower bound on the computation complexity of CHPA. Also, we propose two approximation algorithms for this problem, when Constraint (2b) is relaxed, that is, when \(I_i = [0,\infty ]\), for \(1 \le i \le n\). We use CHPA\(^\infty \) to denote this relaxed version of the problem.
3 Complexity results
In this section, we study the computational complexity of UHPA and CHPA problems. In order to show the hardness of these problems, we present a polynomial time algorithm for reducing any given instance of the number partitioning (PART) problem to an instance of these problems. We first review the PART problem. Then, the transformation method for each problem is described.
3.1 Number partitioning problem
This section reviews the number partitioning (PART) problem which is known as a (weakly) NPcomplete problem.^{1}
Definition 1
Theorem 1
(Hardness of the PART problem Gent and Walsh 1998) The PART problem is NPcomplete. However, it can be solved in pseudopolynomial time.
3.2 Complexity of UHPA
For the complexity analysis, we present a polynomial time method for transforming any given instance of the PART problem to an instance of UHPA. We show that an instance of PART is a positive one (i.e., the set A can be partitioned to the desired sets \(A_1\) and \(A_2\)) if and only if the corresponding UHPA problem has a solution with the total utilization of one. The method is specified in the following.
Lemma 1
A given instance of the PART problem is positive (i.e., the given set can be partitioned) if and only if the UHPA problem instance obtained from the abovementioned transformation method has a solution with \(U=1\).
Proof
Equation (12) holds if and only if in the PART problem there exists a subset of A whose total size of items equals to S / 2. This means that the set A can be partitioned into two subsets \(A_1\) and \(A_2\) with \(S_1=S_2\). As a result, the answer to the PART problem is positive if and only if \(U=1\) in the UHPA problem. \(\square \)
Theorem 2
The UHPA problem is at least weakly NPhard.
Proof
The proposed transformation method can reduce any instance of the PART problem to an UHPA problem in polynomial time. As a result, if there exists a solution approach to the UHPA problem with a complexity better than a pseudopolynomial time algorithm, then there exists an algorithm for the PART problem with the same computational complexity as shown in Lemma 1. As a result, the UHPA problem is at least as hard as the PART problem. According to this fact, and also using Theorem 1, it is implied that the UHPA problem is at least weakly NPhard. \(\square \)
3.3 Complexity of CHPA
Let \(\{T_1, T_2, \ldots , T_{n+2} \}\) denote a possible period assignment. We define J as the weighted sum of these periods, namely \(J=\sum _{i=1}^{n+2} w_i T_i\). Also, assume \(J^*\) to denote the optimal (i.e., minimum) value of J while the problem constraints are satisfied. We show, for the constructed instance of CHPA, that we have \(J^*=2\) if and only if the instance of the PART problem is a positive one. For this purpose, we use the following lemma.
Lemma 2
Proof
Now we establish a relation between the PART problem and the corresponding instance of CHPA.
Lemma 3
A given instance of the PART problem is positive if and only if \(J^*=2\) in the constructed instance of CHPA.
Proof
We first show that if the given PART problem is a positive instance, then the optimal period assignment satisfies \(J^*=2\). To observe this property, let \(A_1\) and \(A_2\) denote the sets related to a solution of the PART problem. We assign the period of the tasks such that \(T_i=1\) if \(a_i\in A_1\) and \(T_i=2\) if \(a_i \in A_2\), for \(1\le i \le n\). As the total size of the items in \(A_1\) is equal to that of \(A_2\), we will have \({\mathbb {C}}_1={\mathbb {C}}_2={\mathbb {C}}/2=2/3\). Subsequently, from (18), it follows that \(J=2\). According to Lemma 2, this means \(J^*=2\).
Next, we show that if \(J^*=2\), then the given instance of the PART problem is positive. We first notice that, due to (18) and as \({\mathbb {C}}=4/3\), the equality \(J^*=2\) implies \({\mathbb {C}}_1=2/3\). Also, since \({{\mathbb {C}}}_1+{\mathbb {C}}_2={\mathbb {C}}\), we get \({\mathbb {C}}_2=2/3\), too. This means that the set of WCETs can be divided into two sets with equal sum. Referring to (13) and (14) for determining the value of WCETs, it is implied that the set of numbers in the original PART problem is divisible into two sets of which the sum of the numbers are equal. Consequently, the instance of the PART problem is positive, which completes the proof. \(\square \)
Theorem 3
CHPA is at least weakly NPhard.
Proof
Any given instance of the PART problem can be transformed to an instance of CHPA in polynomial time using the presented method. Suppose CHPA to be subject to a solution approach with a complexity better than pseudopolynomial time. According to Lemma 3, this implies that the original instance of the PART problem can be decided by an algorithm with a complexity better than pseudopolynomial time, which contradicts with Theorem 1. As a consequence, CHPA is at least weakly NPhard. \(\square \)
4 Approximate solution
In this section, we deal with the problem of optimal harmonic period assignment, in which the goal is to minimize a weighted sum of the periods while we ensure that the periods are harmonic and the utilization is smaller than or equal to 1, referred to as the CHPA\(^\infty \) problem. As a reference case we use the optimal solution for the relaxed problem, when the periods are not constrained to be harmonic. We then propose two approximation algorithms for the problem—one with linear and one with quadratic complexity—and show that the error factor of the approximations is bounded by 1.125.
4.1 Optimal solution for the relaxed problem
We start by relaxing the harmonic constraint (namely (2c)) and let the period ratios to be any arbitrary value. As expressed in the following lemma, this relaxed version of the problem can be solved in linear time.
Lemma 4
Proof
The proof has been previously presented by Cervin et al. (Sect. 3.5 of Cervin et al. 2002). It is worth noting that, although in Cervin et al. (2002) \(C_i\)s are assumed as average execution times, the problem we consider here is mathematically the same as the one in Cervin et al. (2002). As a result, the proof holds for our case as well. \(\square \)
Corollary 1
Let \(U^*\) denote the total utilization of the task set when periods are assigned according to (22). Then, it holds that \(U^*=1\).
Proof
4.2 A linearcomplexity approximate solution
In this section, we present an approximation algorithm for the harmonic case, based on the optimal solution obtained above.
4.2.1 The approximation algorithm
4.2.2 A trivial error bound
We first give a trivial error bound by showing that the periods can no more than double when using the approximation algorithm.
Lemma 5
Proof
Corollary 1
Proof
Since the cost J depends linearly on the periods, it follows from Lemma 5 that the cost will less than double. Finally, the rescaling step can only make the periods smaller and can hence only give a lower cost. \(\square \)
4.3 A tight error bound for Algorithm 1
Now, we derive a tight upper bound on the error of the approximation algorithm.
Theorem 4
The worstcase relative error of Algorithm 1 is \(\frac{9}{8}\).
Proof
Example 1
Assume two tasks, with execution times \(C_1=C_2=0.5\) and weights \(w_1 = 0.501\) and \(w_2 = 0.499\). The optimal periods are \(T_1^* = 0.999\) and \(T_2^* = 1.001\) with the optimal cost \(J^* = 1.000\). Applying Algorithm 1, we obtain the harmonic periods \(T_1 = 0.750\) and \(T_2 = 1.500\) with the cost \(J=1.124\).
4.4 A more effective approximation algorithm
The approximation error of Algorithm 2 will not be larger than that of Algorithm 1 because in the worstcase, Algorithm 2 returns an assignment which starts from \(T_1 \leftarrow T_1^*\). In all other cases, the final result of Algorithm 2 can only be better than Algorithm 1 due to the condition in Line 17. Consequently, the relative error of Algorithm 2 with respect to the optimal period assignment is upperbounded by that of Algorithm 1.
According to our experimental results (shown in the next section), both algorithms produce nearoptimal results and the difference in their performance is small. However, it is worth noting that their computational complexity is different: Algorithm 2 is \(O(n^2)\) while Algorithm 1 is lineartime, i.e., O(n).
5 Experimental results
In this section, we evaluate the performance and effectiveness of our proposed approximation algorithms presented in Sect. 4. In Sect. 5.1 we measure the efficiency of our approximation algorithms in finding harmonic periods using synthetic task sets while in Sect. 5.2 we measure the effectiveness of our algorithms for a set of benchmark control applications.
5.1 Measuring efficiency of the algorithms
5.1.1 The effect of WCET
In the first experiment, we consider the effect of relative ratio of WCET values, i.e., \(C_{i} / C_{i1}\). The parameter of experiment is the maximum ratio between any two consecutive WCET values (sorted in an ascending order). For this experiment we assume a task set with 10 tasks (later in Sec. 5.1.2 we will evaluate the effect of different number of tasks). The WCET of each task is selected randomly with uniform distribution so that \(C_i \in [C_{i1}, k C_{i1}]\) where \(C_1 \in [1, 10]\) and k is the maximum WCET ratio. We assume all tasks have the same weight, i.e., \(\forall i, w_i = 1\). For each value of k we generate 10,000 random task sets and report the average, maximum, and minimum relative errors that are seen in those task sets.
When \(\sigma \) is small, e.g., smaller than 1, WCETs are selected from a narrower range which means that they are more similar to each other. As discussed in Sect. 4, when WCETs are similar, Algorithm 1 has a large relative error as it can be seen in Fig. 3a and c. In this situation, however, both Algorithm 2 and the optimal algorithm are able to find harmonic periods with small error because since the WCETs are similar, \(T_i^*\) values are almost the same which means that the optimal harmonic assignment will be the one that assigns one period to all tasks. Since Algorithm 1 starts by assigning \(T_1^*\) as \(T_1\), it may not be able to assign the same period to all other tasks, and hence, it will suffer from larger errors. We will study this particular case later in Sect. 5.1.4.
From \(\sigma = 0.1\) to 1.6 we see a decreasing pattern in the relative error of Algorithm 1. The reason is that since we select 10 values from the range \([10, 10^{1.6}]\), the chance that the resulting WCETs have larger relative ratio increases with the increase in \(\sigma \). Consequently, the relative error of Algorithm 1 decreases since the situation becomes better.
With the increase in \(\sigma \) after \(\sigma =1.6\), WCET values increase as they can be selected from a larger range. This increase in the average values of WCETs affect the result of \(\sum _{i=1}^{n} \sqrt{w_i C_i}\) which in turn leads to have large \(T_i^*\) (since they are obtained from (22)). In addition, if \(\sum _{i=1}^{n} \sqrt{w_i C_i}\) is a large value, the effect of \(\sqrt{C_i/w_i}\) on \(T_i^*\) decreases, particularly because \(\sqrt{x}\) function does not grow as fast as x. Consequently, \(T_i^*\) values become large and become relatively close to each other. Due to this effect, the relative error of our algorithms remains almost constant as it can be seen for large values of \(\sigma \) in Fig. 3a and large values of WCET ratio in Fig. 2a.
5.1.2 The effect of the number of tasks
Next, we consider the effect of the number of tasks, i.e., n on the relative error of the algorithms. The WCET of each task is selected randomly with a uniform distribution from interval [1, 500] while n varies from 5 to 30. In this experiment we assume that all weights are equal to 1.
Figure 4a demonstrates the average relative error as a function of the number of tasks. As it is shown, Algorithm 2 still performs as good as the optimal algorithm and is able to find harmonic periods with the minimum error. Figure 4b–d confirm the fact that the algorithms provide predictable assignments where the maximum observed relative error is very close to the average and the minimum observed relative error. It is worth noting that when n increases, the number of values selected from the range increase which in turn increases \(\sum _{i=1}^{n} \sqrt{w_i C_i}\). Thus the same effect that happened for the large \(\sigma \) values in Fig. 3 happens here as well.
5.1.3 The effect of weights
In the next experiment, we evaluate the effect of weights on the relative error of the algorithms. For this experiment we have 10 tasks and the WCETs are selected with a uniform distribution from range [1, 500]. The weight of each task is selected with uniform distribution from [0.1, W] where W shows the maximum weight and is the parameter of the experiment.
Figure 6a shows the average relative error of the algorithms. When the maximum weight is 0.1, all weights are equal (because the weights will all be 0.1. In that case, Algorithm 2 performs the same as the optimal algorithm. However, by the increase in the length of intervals from which the weights are selected, Algorithm 2 is no longer able to find harmonic periods with the minimum cost because it does not consider the effect of weights when it finds harmonic assignments through Lines 5–15. In other words, Algorithm 2 focuses on finding the closest harmonic values and cannot consider the effect of weights. As a result, its decisions will gradually become similar to Algorithm 1 which is ignorant towards the weights too.
5.1.4 The effect of similar WCET
As it was mentioned in Sect. 4, the maximum error of Algorithm 1 appears when \(T^*\) values are almost similar. To study this extreme case we conduct another experiment in which we select the execution times from [10,000, 10,001] for \(n=10\) tasks. Figure 7a shows the average relative error of the algorithms as a function of the weights. As it can be seen, for the case where the weights are equal, Algorithm 1 has the largest error. This diagram also shows that the increase in the weights reduces the relative error of Algorithm 1 because they cancel the effect of a harmonic assignment. Moreover, As it can be seen in Fig. 7c, the error bound that we have presented in Theorem 4 is tight since there exists task sets whose relative error is \( \frac{9}{8} = 1.125\).
Unlike Algorithm 1 that is not efficient when WCETs are similar, Algorithm 2 becomes more efficient because as long as the weights are not different from each other, e.g., for \(W=0.1\) to 0.3, the ratio between the optimal harmonic periods will be 1 (almost in all cases). As a result, the assignment with the smallest error will be the one that assigns the largest value of \(T_i^*\) to all tasks. However, when the weights increase, this assignment will not be the best one anymore, and hence, Algorithm 2’s decisions deviate from the optimal one.
5.2 Measuring the effectiveness of the algorithms for control systems
In this subsection, the two algorithms for period harmonization are evaluated in control system examples. To allow for a large number of cases to be investigated, the Jitterbug MATLAB toolbox (Cervin et al. 2003) is used throughout to design the controllers and to evaluate the resulting performance. We first study a simple example in detail and then present results for 100 sets of randomly generated plants.
5.2.1 A simple codesign example

Initial LQG design Each controller is designed without regard for the scheduling, assuming a constant control delay of \(C_i\).

Delayaware LQG design The delay of each controller is assumed constant and given by the approximate responsetime formula from Bini and Cervin (2008). Based on this, a standard LQG controller compensating for the fixed delay is designed.

Harmonic LQG design Using Algorithms 1 and 2, two sets of harmonic periods are calculated. For each resulting task set, we assign task release offsets to minimize the control delay and design a standard LQG controller for the remaining constant delay. These two sets of controllers are evaluated with or without offset.
Results for the simple example
\( T_1 \)  \( T_2 \)  \( T_3 \)  Constant exec. times  Random exec. times  

Initial (\( J^{\text {init}} \))  0.322  0.463  0.665  5.57  4.43 
Delayaware (\( J^{\text {da}} \))  0.322  0.463  0.665  5.13  4.55 
Algorithm 1, no offset (\( J^{\text {h1}} \))  0.260  0.520  1.04  5.63  5.38 
Algorithm 2, no offset (\( J^{\text {h2}} \))  0.286  0.571  0.571  5.27  4.69 
Algorithm 1, with offset (\( J^{\text {h1o}} \))  0.260  0.520  1.04  4.86  4.44 
Algorithm 2, with offset (\( J^{\text {h2o}} \))  0.286  0.571  0.571  4.58  4.09 
The execution time is rarely constant in realtime systems. It is seen that also for the random execution times, Algorithm 2 with release offsets produces the smallest overall cost.
In the next section, a larger evaluation is performed using randomly generated plant dynamics, showing the variability and confidence of the results obtained.
5.2.2 Randomly generated examples
 Family A: All plants have two real or complex stable poles. They are drawn fromwhere \( \tau = 10^{2\alpha } \), \( K = 2\times 10^{\beta } \), \( \zeta = 2\gamma \), and \( \alpha ,\,\beta ,\,\gamma \in \text {unif}(0,\,1) \).$$\begin{aligned} P_A (s) = \dfrac{K}{\tau ^2 s^2+2\zeta \tau s+1}, \end{aligned}$$(32)
 Family B: All plants have two real or complex stable poles and one integrator. They are drawn fromwhere \( \tau = 10^{2\alpha } \), \( K = 0.3\times 10^{\beta } \), \( \zeta = 2\gamma \), and \( \alpha ,\,\beta ,\,\gamma \in \text {unif}(0,\,1) \).$$\begin{aligned} P_B (s) = \dfrac{K}{\tau s\left( \tau ^2 s^2+2\zeta \tau s+1 \right) }, \end{aligned}$$(33)
 Family C: All plants have two real or complex stable poles, one stable or unstable zero and one integrator. They are drawn fromwhere \( \tau = 10^{2\alpha } \), \( K = 1.3\times 10^{\beta } \), \( \zeta = 2\gamma \), \( T_z = 10^{\eta 2} \), and \( \alpha ,\,\beta ,\,\gamma ,\,\eta ,\,\lambda \in \text {unif}(0,\,1) \).$$\begin{aligned} P_C (s) = \dfrac{K\left[ 1\text {sgn}(\lambda 0.5)\tau T_z s\right] }{\tau s\left( \tau ^2 s^2+2\zeta \tau s+1 \right) }, \end{aligned}$$(34)
 Family D: All plants have two real or complex stable poles, one stable or unstable pole and one integrator. They are drawn fromwhere \( \tau = 10^{2\alpha } \), \( K = 10^{\beta } \), \( \zeta = 2\gamma \), \( T_p = 10^{\eta +1} \), and \( \alpha ,\,\beta ,\,\gamma ,\,\eta ,\,\lambda \in \text {unif}(0,\,1) \).$$\begin{aligned} P_D (s) = \dfrac{K}{\tau s\left( \tau ^2 s^2+2\zeta \tau s+1 \right) \left[ 1\text {sgn}(\lambda 0.5)\tau T_p s\right] }, \end{aligned}$$(35)
25 sets of three plants are randomly generated for each family, and the cost functions are normalized so that 1 corresponds to continuoustime control. The initial sampling periods are again calculated using evaluation of the sensitivity towards an increase in period, Eq. (31). The jitter margin was calculated for all 300 controllers, and in no case was it smaller than 67% of the initial period, indicating that all controllers were reasonably robust.

Initial LQG cost \( J^\text {init} \). The LQG controllers are designed for \( T_i^{\text {init}} \) as the period and \( C_i \) as the constant delay. For each task, we calculate the first 100 response times to estimate the response time distribution. Using this distribution as the delay distribution in Jitterbug, the LQG cost \( J_i^\text {init} \) is evaluated.

Delayaware LQG cost \( J^\text {da} \). We again design the LQG controller with \( T_i^{\text {init}} \) as the period but now with the approximate delay from Bini and Cervin (2008). The first 100 response times are used to calculate the response time distribution. Then the distribution is used in the Jitterbug evaluation.

Harmonic LQG cost \( J^\text {h1} \), \( J^\text {h2} \), \( J^\text {h1o} \), and \( J^\text {h2o} \). We use \( T_i^\text {init} \) as the initial period and Algorithms 1 and 2 to evaluate the two harmonic task period sets with full utilization. For the no offset case, the LQG controller is designed using a constant delay, equal to the the response time. For the offset case, the LQG controller is designed using a constant delay, equal to the difference between the response time and the start latency. The LQG cost is evaluated with an offset which is equal to the start latency. \( J^\text {h1} \) stands for the LQG cost using Algorithm 1 with no offset, and \( J^\text {h1o} \) stands for the LQG cost using Algorithm 1 with offset. \( J^\text {h2} \) and \( J^\text {h2o} \) are defined similarly.
Average costs under constant execution times
Family A  Family B  Family C  Family D  

\( J^{\text {init}} \)  4.83  4.69  4.38  4.36 
\( J^{\text {da}} \)  4.70  4.53  4.22  4.17 
\( J^{\text {h1}} \)  4.89  4.67  4.36  4.37 
\( J^{\text {h2}} \)  4.75  4.53  4.25  4.21 
\( J^{\text {h1o}} \)  4.60  4.31  4.05  4.05 
\( J^{\text {h2o}} \)  4.45  4.20  3.99  3.92 
Average costs under random execution times \( \left[ 0.5C , \, C \right] \)
Family A  Family B  Family C  Family D  

\( J^{\text {init}}\)  4.29  4.07  3.82  3.79 
\( J^{\text {da}}\)  4.33  4.12  3.87  3.84 
\( J^{\text {h1}} \)  4.54  4.30  4.05  4.11 
\( J^{\text {h2}} \)  4.42  4.23  3.97  3.93 
\( J^{\text {h1o}} \)  4.23  3.96  3.74  3.75 
\( J^{\text {h2o}} \)  4.13  3.91  3.71  3.66 
We consider two options for the execution time: a constant one equal to C and a random one which is uniformly distributed in \( \left( 0.5C,\,C\right) \). The costs, averaged over 25 generated plant sets for each family, are shown in Tables 2 and 3. As seen from the results, the initial LQG costs are slightly better than the costs of harmonic LQG without offset, and worse than the harmonic LQG with offset. The costs for the harmonization of Algorithm 2 are smaller than those of Algorithm 1, while the computation of Algorithm 2 is more timeconsuming.
6 Discussions
The complexity of different harmonic period assignment problems
\(\max U \)  \(\min \sum {{w_i} T_i}\)  

Restricted range  NPhard in the weak sense (at least)  NPhard in the weak sense (at least) 
Unrestricted range  There exists poly.time algorithm  Unknown (there exists poly.time approximation) 
An interesting observation in our experiments is that, when all tasks incorporate the same weight, Algorithm 2 is as good as the optimal solution based on an exhaustive search. It remains as an open question whether the DCTbased algorithm is really an optimal solution to assign harmonic periods in this situation or not. If it is the case, then CHPA\(^\infty \) can be solved in polynomialtime using Algorithm 2 for the special case of equal weights.
7 Conclusion
In this paper, we have discussed the hardness of the harmonic period assignment problem in cases where periods must be selected from a given range and the goal is to find a harmonic assignment which maximizes the utilization. We have shown that this problem is weakly NPhard. It was also shown that the same result holds when the objective is to minimize the weighted sum of periods. We have also considered the problem of minimizing the weighted sum of harmonic periods where there is no lower and upper bound on the valid periods. While the computational complexity of this version of the problem is unknown, we presented two polynomialtime approximation algorithms for it. We have shown that the upper bound of the error of these algorithms with respect to the results of an optimal period assignment algorithm is upper bounded by 1.125. Our algorithms can be used to increase the quality of control in control systems. We have evaluated the proposed algorithms using synthetic task sets as well as benchmark control applications. The results have shown that even though the guaranteed bounded error is 1.125, the second algorithm is as good as the optimal solution based on an exhaustive search when all tasks are assigned the same weight.
As our future work, we intend to investigate the optimality of our second algorithm in the mentioned special case. Moreover, we try to provide efficient solutions, either using approximation algorithms or heuristics to solve the first problem where periods are bounded to a specified set of intervals. A solution to this problem can be further used in the design space exploration in order to simplify parameter assignment phase. Also we plan to provide a new method to obtain the space of feasible periods for RM.
Footnotes
 1.
A problem is weakly NPcomplete if it is NPcomplete and it has a pseudopolynomial time solution.
References
 Bini E, Cervin A (2008) Delayaware period assignment in control systems. In: IEEE realtime systems symposium, pp 291–300Google Scholar
 Bini E, Di Natale M (2005) Optimal task rate selection in fixed priority systems. In: Realtime systems symposium, pp 399–409Google Scholar
 Bini E, Di Natale M, Buttazzo G (2008) Sensitivity analysis for fixedpriority realtime systems. RealTime Syst 39(1):5–30CrossRefzbMATHGoogle Scholar
 Bonifaci V, MarchettiSpaccamela A, Megow N, Wiese A (2013) Polynomialtime exact schedulability tests for harmonic realtime tasks. In: Realtime systems symposium, pp 236–245Google Scholar
 BusquetsMataix JV, Serrano JJ, Ors R, Gil P, Wellings A (1996) Using harmonic tasksets to increase the schedulable utilization of cachebased preemptive realtime systems. In: Workshop on realtime computing systems and applications, pp 195–202Google Scholar
 Cervin A, Eker J, Bernhardsson B, Årzén KE (2002) Feedbackfeedforward scheduling of control tasks. RealTime Syst 23(1):25–53CrossRefzbMATHGoogle Scholar
 Cervin A, Henriksson D, Lincoln B, Eker J, Årzén KE (2003) How does control timing affect performance? IEEE Control Syst Mag 23(3):16–30CrossRefGoogle Scholar
 Easwaran A, Lee I, Sokolsky O, Vestal S (2009) A compositional scheduling framework for digital avionics systems. In: IEEE conference on embedded and realtime computing systems and applications, pp 371–380Google Scholar
 Eisenbrand F, Rothvoß T (2008) Staticpriority realtime scheduling: response time computation is NPhard. In: Realtime systems symposium, pp 397–406Google Scholar
 Ekberg P, Yi W (2015) Uniprocessor feasibility of sporadic tasks with constrained deadlines is strongly coNPcomplete. In: Euromicro conference on realtime systems, pp 281–286Google Scholar
 Eker J, Hagander P, Årzén KE (2000) A feedback scheduler for realtime controller tasks. Control Eng Pract 8(12):1369–1378CrossRefGoogle Scholar
 Fu Y, Kottenstette N, Chen Y, Lu C, Koutsoukos XD, Wang H (2010) Feedback thermal control for realtime systems. In: IEEE realtime and embedded technology and applications symposium, pp 111–120Google Scholar
 Gent LP, Walsh T (1998) Analysis of heuristics for number partitioning. Comput Intell 14(3):430–451MathSciNetCrossRefGoogle Scholar
 Han CC, Tyan HY (1997) A better polynomialtime schedulability test for realtime fixedpriority scheduling algorithms. In: Realtime systems symposium, pp 36–45Google Scholar
 Henriksson D, Cervin A (2005) Optimal online sampling period assignment for realtime control tasks based on plant state information. In: IEEE conference on decision and control, pp 4469–4474Google Scholar
 Kwak S, Yang JM (2012) Optimal checkpoint placement on realtime tasks with harmonic periods. J Comput Sci Technol 27(1):105–112CrossRefzbMATHGoogle Scholar
 Li H, Sweeney J, Ramamritham K, Grupen R, Shenoy P (2003) Realtime support for mobile robotics. In: IEEE realtime and embedded technology and applications symposium, pp 10–18Google Scholar
 Liu CL, Layland JW (1973) Scheduling algorithms for multiprogramming in a hardrealtime environment. J ACM 20(1):46–61MathSciNetCrossRefzbMATHGoogle Scholar
 Mizuuchi I, Nakanishi Y, Sodeyama Y, Namiki Y, Nishino T, Muramatsu N, Urata J, Hongo K, Yoshikai T, Inaba M (2007) An advanced musculoskeletal humanoid kojiro. In: IEEERAS international conference on humanoid robots, pp 294–299Google Scholar
 Mohaqeqi M, Nasri M, Xu Y, Cervin A, Årzén KE (2016) On the problem of finding optimal harmonic periods. In: International conference on realtime networks and systems, pp 171–180Google Scholar
 Nasri M, Fohler G (2015) An efficient method for assigning harmonic periods to hard realtime tasks with period ranges. In: Euromicro conference on realtime systems, pp 149–159Google Scholar
 Nasri M, Baruah S, Fohler G, Kargahi M (2014) On the optimality of RM and EDF for nonpreemptive realtime harmonic tasks. In: Realtime networks and systems, pp 331–340Google Scholar
 Nasri M, Fohler G, Kargahi M (2014) A framework to construct customized harmonic periods for realtime systems. In: Euromicro conference on realtime systems, pp 211–220Google Scholar
 Ruiz JF (2005) GNAT pro for onboard missioncritical space applications. In: AdaEurope international conference on reliable software technologies, pp 248–259Google Scholar
 Seto D, Lehoczky JP, Sha L, Shin KG (1996) On task schedulability in realtime control systems. In: IEEE realtime systems symposium, pp 13–21Google Scholar
 Seto D, Lehoczky JP, Sha L (1998) Task period selection and schedulability in realtime systems. In: Realtime systems symposium, pp 188–198Google Scholar
 Shih CS, Gopalakrishnan S, Ganti P, Caccamo M, Sha L (2003) Scheduling realtime dwells using tasks with synthetic periods. In: IEEE realtime systems symposium, pp 210–219Google Scholar
 Taira T, Kamata N, Yamasaki N (2005) Design and implementation of reconfigurable modular humanoid robot architecture. In: IEEE/RSJ international conference on intelligent robots and systems, pp 3566–3571Google Scholar
 Wu Y, Buttazzo G, Bini E, Cervin A (2010) Parameter selection for realtime controllers in resourceconstrained systems. IEEE Trans Ind Inform 6(4):610–620CrossRefGoogle Scholar
 Xu Y, Årzén KE, Bini E, Cervin A (2014) Response time driven design of control systems. In: 19th IFAC world congress, pp 6098–6104Google Scholar
 Xu Y, Cervin A, Årzén KE (2016) Harmonic scheduling and control codesign. In: IEEE conference on embedded and realtime computing systems and applications, pp 182–187Google Scholar
Copyright information
Open AccessThis article is distributed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted use, distribution, and reproduction in any medium, provided you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license, and indicate if changes were made.