Optimal Harmonic Period Assignment With Constrained Number of Distinct Period Values

Harmonic periods have been of great importance in the design of real-time applications due to their high schedulability, predictability, and ease of analysis. Therefore, period assignment is an important part of the design process of many real-time systems. This includes various applications such as radar dwell tasks, robotics, and industrial control applications, where tasks are specified using period ranges and worst-case execution times. In this paper, we study the issue of assigning a fixed number of harmonic periods from period ranges to maximize utilization in real-time systems. In the existing period assignment approaches, the number of different harmonic period values in the solution was not addressed. In this work, we show that, in real-time systems in which the number of available task periods is restricted, such a constraint is crucial for efficient system design. We formally define the problem in the context of existing harmonic period assignment research. We show that this problem is at least weakly NP-hard and devise an optimal algorithm and suboptimal heuristics. Based on an extensive evaluation on synthetically generated task sets, we conclude that our approach is efficient and applicable in a variety of real-world scenarios.


I. INTRODUCTION
In traditional industrial control systems, timeliness, stability and predictability are very important properties. Moreover, in safety-critical control systems, these properties are condicio sine qua non as they are required according to generic safety standards such as IEC 61508 and domain-specific safety standards, e.g., EN 50128 in the railway domain and ISO 26262 in the automotive domain. Efficiency and accuracy of the control algorithm depends to a large extent on the timeliness of underlying embedded computing platforms. Consequently, strict requirements are imposed on the design of operating systems as the controlling procedures have to be prompt and correct. In this context, selecting adequate sample times, i.e., task periods, is crucial for an appropriate behavior of a system.

A. RELATED WORK
Period assignment is a well-studied topic in real-time system design, since the choice of periods in sporadic or periodic task sets has a direct effect on system schedulability, efficiency The associate editor coordinating the review of this manuscript and approving it for publication was Shafiqul Islam . and utilization. Additionally, harmonic period assignment is of special interest as it is well-known that any harmonic task set with processor utilization less or equal to one is schedulable by a rate-monotonic scheduler [1]. Research in this domain can be divided into three groups with respect to the particular focus of the research.
The first research area includes papers focused on the schedulability of real-time systems with arbitrary period selection, i.e., periods of task sets are not constrained to harmonic values. Early research in this context was done by Seto at al. in [2]. The authors devised algorithms for discovering feasible integer periods in fixed-priority systems with a fixed rate-monotonic and an arbitrary priority assignment. Moreover, in their approach periods are upper-bounded by the slowest task rate required by an application. According to authors in [3], the approach taken in [2] seems to be inefficient due to the combinatorial explosion for larger task sets. On the other hand, in [3], authors precisely formulate the feasibility region in the rate space and devise optimization algorithm for any convex objective. In their approach, periods are not constrained to be integers, while fixed-priority scheduling is assumed. However, there are no additional constraints regarding the period range for tasks in systems.
The second research area includes papers that exploit the harmonic relations between the periods of tasks in systems for determining schedulability. For instance, Han and Tyan in [4] devise a sufficient schedulability bound which is better than the one proposed by Liu and Layland [5]. The approach is based on two previously introduced algorithms Sr and DCT investigated in the context of distance-constrained real-time systems [6]. Similarly, an exact polynomial-time schedulability test for harmonic task sets with any fixed-priority assignment was devised in [7]. It is worth noting that the problem of determining schedulability of sporadic task sets with arbitrary periods is NP-hard [8].
The third research area includes papers which are focused on harmonic period assignment with period ranges. In recent research [9], authors determined that two classical harmonic period optimization problems labeled UHPA (utilizationmaximizing harmonic period assignment) and CHPA (costminimizing harmonic period assignment) are in the NP-hard complexity class. Additionally, they devised approximation algorithms for the relaxed version of the CHPA problem, i.e., the constraints on period ranges are removed. We formally define these problems later in the paper as our research is focused on a variant of the UHPA problem with additional constraints on period values. In [10], the authors introduce the notion of harmonic projection and devise an exponential time (in size of a task set) algorithm for determining harmonic periods for tasks with period ranges. Additionally, they devise period assignment algorithms such that the resulting utilization of a task set is equal to the lower or the upper bound utilization value. They expand on their work in [11]. We highlight the similarities and the differences with our approach later in the paper. Period selection and assignment were investigated in the context of minimizing the hyperperiod of task set in systems in which periods are closely harmonically related [12]. Similarly, in [13], the authors investigate the minimization of the hyperperiod by non-harmonic period assignment from period ranges.
The common motivation in the period assignment research is the real-time system and optimal controller co-design, in which the problem of selecting adequate sample times is directly linked to the problem of determining optimal periods [14]. In such approaches, the LQG (linear-quadratic-Gaussian) plant model is used [15], [16]. Moreover, the period assignment of harmonic period values is of great importance in many applications such as radar dwell tasks [17], mobile robotics [18], integrated modular avionics [19], and automotive applications [20].

B. MOTIVATION AND NEW CHALLENGES
As an additional motivation and rationale for imposing additional constraints on the classical harmonic period assignment problem, i.e., a variant of the UHPA, we focus on safety-critical software from real-world industrial scenarios as it serves as the primary motivation for this research. Safetycritical embedded software for control applications typically has a modular composition in which each module, task or runnable executes with a predefined period which is determined off-line as a part of the application design. For instance, ANSYS SCADE Suite [21], HIMA SILworX [22] and KONČAR Grap Designer [23] provide automatic code generation based on a set of application modules. The application designer determines a range of periods for every module, i.e., task, in the application. In order to ensure function correctness, tasks have to be executed with periods belonging to their specified range. Moreover, it is in the interest of application and system designers that every task in the system executes with the highest possible frequency, i.e, the lowest possible period as this will ensure a higher quality of service, and consequently increase utilization. Thus, utilization is maximized. The number of tasks in an application can grow and be arbitrarily high. However, in many systems, e.g., the KONČAR Grap [23] operating system, or engine management systems [20] in automotive applications, the number of available periods, i.e., rates, is fixed or bounded and cannot be increased due to the specific architecture of the hardware and the operating system. For instance, the maximum number of different period values may be fixed to 4, or restricted to the interval from 4 to 8. It is worth noting that previous research regarding harmonic period assignment does not address the number of distinct period values in the solution of the period assignment problem. Our approach can be used by system and application designers to determine the optimal choice of task periods, even when the number of available periods in the system is limited.

C. CONTRIBUTIONS AND ORGANIZATION
There are five main contributions in this paper. We define utilization-maximizing harmonic period assignment with a constrained number of distinct period values referred to as UDHPA (i). We show that the already studied UHPA problem is Turing reducible to the UDHPA problem. Additionally, using the complexity results for the UHPA problem from [9], we determine that the UDHPA problem is at least weakly NP-hard by reduction from the well-known partition sum problem (ii). We devise an optimal and heuristic algorithms for the UDHPA problem, provide time-complexity analysis, and show the effectiveness of the approach with extensive evaluation on a large number of synthetically generated instances, which correspond to real-world motivational scenarios (iii). We use our optimal algorithm and heuristics to solve instances of the UHPA problem and compare them to the existing approaches (iv). Moreover, we provide a numerical example that illustrates a real-world period assignment problem (v). The rest of the paper is organized as follows.
In section II, we introduce the system model. In section III, firstly we revisit existing harmonic period assignment problems, and then define the UDHPA problem. In section IV, we analyze the complexity of the UDHPA problem. In section V, we devise an optimal algorithm for the UDHPA problem. In section VI, we evaluate our approach. Finally, in section VII, we state the concluding remarks.

II. SYSTEM MODEL
In this paper, system S is represented as a set T of n periodic tasks with no initial offset, i.e., a synchronous task set [24]. We use a task model which is common for the period assignment with period ranges proposed in [9], [10], and [11]. Therefore, task τ i is represented as a tuple τ i = {C i , I i }, where C i is the worst-case execution time (WCET) of τ i , and I i is the period range of allowed period values for τ i . Period ] is determined by the minimal p min i and the maximal p max i allowed period value. Actual period value of task τ i is denoted as T i . This is the value which is assigned to a task by solving a period assignment problem. Additionally, T i is the deadline of τ i , i.e., implicit-deadline task sets are considered. We assume that the WCET is a real number, i.e., C i ∈ R, and that task periods are integers, i.e., T i , p min i , p max i ∈ N. Moreover, periods are in harmonic relation, i.e., Definition II.1 determines the correctness of period assignment.
Definition II.1. Correct Period Assignment. Period assignment for task τ i is correct iff period value T i assigned to task τ i is such that p min It is worth noting that the correctness of period assignment does not guarantee the feasibility of a task set. The feasibility of a harmonic task set is often expressed using the utilization of a task set, i.e., U = U i = C i T i ≤ 1.

A. CLASSICAL HARMONIC PERIOD ASSIGNMENT PROBLEMS
First off, we describe existing harmonic period assignment problems which are analyzed and discussed in the literature [9]- [11]. Inputs of these problems are tasks described with worst-case execution times C i and period ranges The outputs are period values T i assigned to each task. The utilization-maximizing harmonic period assignment (UHPA) problem is formulated as follows: As it can be seen, actual periods T i are allowed to be in range I i and have to be in harmonic relation. It is worth noting that in the related literature (e.g., [9]) period values T i are not restricted to the integer values. However, the period ratios of the two consecutive integers T i T j are required to be integers. The second common problem formulation in the literature is the cost-minimizing harmonic period assignment (CHPA) problem which can be formulated as: The CHPA problem is common in control co-design applications [15] where the goal function is a linear function of task periods. In the goal function, the weight w i determines the contribution of each period to the total cost.

B. FORMULATION OF HARMONIC ASSIGNMENT PROBLEM WITH A CONSTRAINED NUMBER OF DISTINCT PERIOD VALUES
In this paper, we solve the utilization-maximizing harmonic period assignment problem with a constrained number of different period values. In the previous problems, the number of different period values in the solution is not constrained. For instance, an optimal solution can have any number of different period values, from only one up to n. As argued in the motivation of the paper, the number of different period values can be smaller than the number of tasks in the system. To address this, we formulate the problem in which the number of different period values is constrained, i.e., fixed.
Such an approach enables a more flexible system design as it allows the system designer to regulate the number of distinct period values in the system. This is elaborated further using the numerical example in section VI-D. Now, we proceed to formulate such a problem. Firstly, we introduce the vector p which contains m different period values, where m ≤ n. Secondly, we introduce the period assignment matrix X which contains mapping of period value p j to period value T i of task τ i . Value x ij of the binary matrix X is determined as follows: x ij = 1, period value p j is assigned to task τ i , i.e., T i ← p j 0, otherwise In case m = n, one period value p j maps to only one period value T i , i.e., this is one to one mapping. In case m ≤ n, period value p j can be mapped to many tasks, i.e., generally, this is one to many mapping. However, period value p j has to be mapped to at least one period value T i . If p j is not mapped to at least one task, then the number of different period values in the resulting period assignment would not be equal to m, and this is the requirement of the problem.
To express this formally, we introduce the constraints given with equations (2) and (3). First, we restrict the assignment of only one period value p j to period value T i of task τ i : VOLUME 8, 2020 The constraint (2) ensures that the i-th row of matrix X can contain only one non-zero element, i.e., only one p j is mapped to T i . Secondly, every period value p j has to be assigned to at least one task: The constraint (3) ensures that the j-th column of matrix X has to contain at least one non-zero element, i.e., every period value p j has to be assigned to a task. The latter constraints do not ensure the correctness of a period assignment. For instance, a period value which is too high or too low can be assigned to a task. To ensure that a period assignment is correct (Def. II.1), we have to restrict the assignment to period values from interval [p min i , p max i ]. The correctness criteria can be expressed as: The latter logical expression can be translated to an arithmetic expression using the translation for logical implication to a linear constraint: At this point, we introduce the binary constraint matrix A with n · m elements a ij . Value a ij is determined as follows: To ensure the correctness of a period assignment, x ij ⇒ a ij has to hold. Using the arithmetic counterpart for implication given with (5), the correctness criteria can be expressed as: With the latter constraints in place, the problem can be formally expressed as: where k j is the integer ratio of two consecutive period values p j and p j−1 . We refer to this problem as the utilizationmaximizing harmonic period assignment with a constrained number of different period values (UDHPA). The outputs of the UDHPA problem are period vector p and period assignment matrix X. These two variables determine period T i for each task in system. Similarly as in the classical problems, the inputs of the problem are tasks represented with worstcase execution times C i and period ranges I i . The additional input in the UDHPA problem is the number of distinct period values in the solution m.

IV. PROBLEM ANALYSIS: TURING REDUCIBILITY AND COMPLEXITY A. TURING REDUCTION FROM UHPA TO UDHPA
In order to show that the UHPA problem is Turing reducible to the UDHPA problem, we show that an oracle for the UDHPA problem can be used to solve the UHPA problem. Formally, this is stated with the following lemma.
Lemma IV.1. The UHPA problem can be solved by solving the UDHPA problem n times.
Proof: If we consider the UHPA problem, an optimal solution has an arbitrary number of distinct period values which can be lower than the number of tasks in the system. In the UDHPA problem, however, the number of distinct period values is fixed. Therefore, to solve the UHPA problem using an algorithm for the UDHPA problem, one has to solve the UDHPA problem for every number m of distinct period values from interval [1, n]. To better illustrate this, we provide pseudo-code Alg. 1. Proof: In Lemma IV.1, we can see that the UHPA problem is solved by invoking the oracle for the UDHPA problem in polynomial time, which proves the theorem.

B. COMPLEXITY ANALYSIS
To derive the complexity of the UDHPA problem, we use the UHPA complexity results from [9]. To show that the UHPA problem is at least weakly NP-hard, the authors provided many-one reduction from the partition sum problem (PART) to the UHPA problem. In other words, they provided a polynomial-time algorithm for reducing any given instance of the PART problem to an instance of the UHPA problem. Their proof can be directly applied to the UDHPA problem. For completeness and clarity, here we reproduce important parts of the proof. For the complete proof, refer to section 3 in [9]. Firstly, we define the number partitioning problem (PART).
Definition IV.1. The PART Problem. Let A = {a 1 , . . . , a n } be a set of n items with an associated size function s : A → N which assigns a positive integer to each item. The problem is to determine whether A can be partitioned into two sets, A 1 and A 2 , such that the total size of items in A 1 equals that of A 2 . More formally, let S, S 1 , and S 2 denote the sum of items for A, A 1 , and A 2 , respectively. That is, Then, the problem is to decide whether A can be partitioned into A 1 and A 2 (i.e., An instance of this problem is said to be a positive one if such a partitioning exists [9]. The PART problem is known to be NP-complete, but solvable in pseudo-polynomial time [25]. At this point, we reproduce the polynomial-time method for transforming any given instance of the PART problem to an instance of the UHPA problem. To show that the proof is applicable to UDHPA problem as well, we show that the transformation of any PART instance to an instance of the UHPA is a transformation to an instance of the UDHPA problem as well.
Definition IV.2. PART Transformation. For any instance of the PART problem, the corresponding UHPA problem is specified by a set of n+2 tasks. The WCET of τ i is determined as: Period ranges for each τ i are determined as: Proposition IV.1. An UHPA instance obtained using PART transformation is an UDHPA instance with m = 2.
Proof: Any instance of the PART problem is transformed to an instance of UHPA problem with period ranges such that the allowed harmonic period values are either 1 or 2. There are always exactly two different period values in the resulting UHPA problem. Therefore, any such instance is an UDHPA instance with two different period values, i.e., m = 2.
Lemma IV.2. 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 PART transformation has a solution in which U = 1 [9].
The latter lemma is proven in [9]. It is worth noting that it applies to the UDHPA problem as well, since we know from Theorem IV.1. that every instance of the UHPA problem obtained using PART transformation can be solved with an oracle for the UDHPA problem with m = 2, i.e., there is one to one mapping between instances of the UHPA and UDHPA problem with fixed m = 2.
Theorem IV.2. The UDHPA problem is at least weakly NP-hard.
Proof: Using the PART transformation and Lemma IV.2. we can reduce any PART instance to a corresponding UHPA instance. Additionally, using Proposition IV.1 and Theorem IV.1 we see that this transformation is valid for the UDHPA problem as well. Therefore, any algorithm used for solving the UDHPA problem can be used for solving any instance of the PART problem after the PART transformation. Therefore, the UDHPA problem is at least hard as the PART problem. Moreover, the UDHPA problem is at least weakly NP-hard.

V. AN OPTIMAL ALGORITHM FOR THE UDHPA PROBLEM
The UDHPA problem cannot be easily solved by using existing mixed-integer or integer programming solvers. The utilization of the system, i.e., the goal function is a non-linear, i.e., signomial, function. Methods for solving mixed-integer signomial problems exist, but do not guarantee to find a global solution [26].
In our approach, we enumerate possible solutions to find an optimal solution of the problem. We split the UDHPA problem into two independent parts: 1) enumeration of potential harmonic period sets -we refer to this part as period enumeration (PE), 2) assignment of periods from a harmonic period set to tasks -we refer to this part as task assignment (TA).
In the first part, we enumerate the possible harmonic period sets which can be used for task assignment in the system. This is possible as we constrained periods to integer values. Still, in the worst case, enumerating all the possible harmonic period sets can lead to a combinatorial explosion due to the exponential growth in the period search space. Therefore, we introduce several propositions which drastically reduce search space in most use cases. In the second part, we assume that harmonic period set p is known. It can be seen that the goal function of the UDHPA problem with known period values is linear, which makes such problem an integer linear program, i.e., zero-one linear program. We refer to the relaxed version of the UDHPA problem, i.e., an assignment problem with a known harmonic period set, as the task assignment (TA) problem. The TA problem can be expressed as follows: In the TA problem, only the mapping of period values to tasks has to be determined, since harmonic period set p is known in advance. In our approach, we exploit this observation. Firstly, we enumerate possible harmonic period values sets, and then solve the TA problem for each harmonic period set.

A. ENUMERATING PERIOD VALUES
To determine m different period values, we start by choosing the values for the lowest period, i.e., p 1 . Subsequent period values are determined by choosing the integer ratios k j > 1 of two consecutive integer values p j and p j−1 . Possible values for the first period depend on two specific values which can be determined from task period ranges. The first value is p min min , which is the minimal lower bound in all period ranges, i.e., min p min i . The second value is p max min , which is the minimal upper bound in all period ranges, i.e., min p max . Proof: To prove this, we consider cases in which p 1 is not in the proposed interval and show that at least one of the constraints is violated. Firstly, let us assume that p 1 has a value which is lower than p min min . As the period value has to be assigned to at least one task, i.e., n i=1 x ij ≥ 1, j ∈ [1, m], there is no feasible solution to the UDHPA problem, since period value p 1 cannot be assigned to task τ i with the minimal lower bound p min i = p min min , or to any other task. Secondly, if p 1 is greater than the minimal upper bound p max min , it is not possible to assign any period value to task τ i with p max i = p max min due to the violation of the period range constraint. Therefore, for any feasible solution to the UDHPA problem, p 1 is within the interval [p min min , p max min ]. Similarly, as we have restricted the possible choices of p 1 , we can restrict the choice of any subsequent period values p j . We introduce another specific value for the given period ranges, p max max , which denotes the maximal upper bound among the upper bounds of all tasks, i.e., max p max i .

Proposition V.2. A Bound on Choice of p j .
In any feasible solution, there is no period value such that p j > p max max . Proof: If p j > p max max , it is not possible to assign p j to any task, since the range constraints will be violated. Therefore, in any feasible solution, every period p j is less than or equal to p max max . Using the specific values obtained from period ranges, it is possible to determine the maximum number of distinct period values which can appear in the solution. The following proposition is useful as it restricts the period enumeration search space.
Proposition V. 3 for i in range p min min to p max min do if j ==m+1 then 12: Solve Task Assignment( p, T ) 13: return 14: end if 15: for k j in range 2 to p max max p j ·2 m−j do according to Prop. V.4 16: p j ← k j · p j−1 17:

Period Enumeration
Step( p, p max max , j + 1) 18: end for 19: end function the number of different harmonic period sets with m distinct period values corresponds to the number in which the basic case is reached. We further analyze the number of solutions with regard to m in section VI in the context of feasibility evaluation. Now, we analyze time complexity of the period enumeration algorithm. Firstly, it is worth noting that the asymptotic analysis with regard to m is not of any interest, since we know from Proposition V.3 that m is bounded and that there are no feasible solutions for higher values of m. Therefore, we analyze time complexity with regard to the highest period in the input p max max , as it is obvious that the number of steps in the algorithm increases when p max max increases (see loop bound in line 15 in Alg. 2). To provide an asymptotic upper bound on the time complexity of Alg. 2, we study a similar enumeration problem referred to as the DIVENUM problem.
Definition V.1. The DIVENUM Problem. The enumeration problem, which we call DIVENUM, is to output all mtuples (k 1 , . . . , k m ) such that: We can see that the DIVENUM problem is in fact very similar to the PE problem, since in both problems we are looking for a set of m factors such that their product is lower than the specified bound, χ and p max max , respectively. In the PE problem, each factor k j is greater than one. On the other hand, in the DIVENUM problem, k j is a positive integer including one. Therefore, we know that the number of steps required to enumerate solutions to the DIVENUM problem is always higher than the number of steps in the PE problem. For the sake of completeness and clarity, we provide Alg. for k m+1−j in range 1 to χ do 7: Divisor Enumeration( χ k m+1−j , j − 1) 8: end for 9: end function In Alg. 3, we see that the number of steps T (χ, m) required to enumerate all m-tuples of positive integers with product less than or equal to χ is given with: where T (χ , 0) is the number of elementary operations in the basic case. For any bound x, we know that: Moreover, for T (x, 2) we have the following: We can see that this is in fact a finite partial sum of the harmonic series: where 3) can be expressed as: Next, we can bound T (x, 3): By induction, we get that T (χ , m) = χ H m−1 χ . Moreover, harmonic numbers can be approximated with an integral: Therefore, an upper bound on the time complexity for the DIVENUM problem is given with O(χ log m−1 (χ)). Moreover, the time complexity of the PE algorithm is in O(p max max log m−1 (p max max )).

B. SOLVING THE TA PROBLEM
The TA problem is solved by enumeration of all possible period to task assignments with respect to the given harmonic period set. First off, we devise polynomial-time algorithms which yield the lower and upper bounds for the goal function, i.e., the utilization of the system. Then, by using these bounds, we devise an algorithm for the optimal task assignment.

1) BOUND ALGORITHMS
In order to determine the bounds, we relax constraints n i=1 x ij ≥ 1, j ∈ [1, m] to allow that some period values remain unused in the solution. We refer to this problem as TA*. In such a scenario, an algorithm that produces a lower bound of the utilization assigns the highest correct period to every task (note: correct with respect to Definition II.1). We refer to this assignment as the HPF (highest period first) assignment, and it is depicted with Alg. 4. Similarly, the LPF VOLUME 8, 2020 (lowest period first) assignment yields an upper bound of the TA* problem. To obtain the LPF assignment using the Alg. 4, period values p have to be iterated from the lowest to the highest period value (line 6 in Alg. 4). Formally, the properties of the HPF assignment are stated in the continuation (Proposition V.5 and V.6). The properties of the LPF assignment are analogous with respect to an upper bound of utilization. for i in range 1 to n do 5: assigned ← false 6: for j in range m down to 1 do 7: if p min i ≤ p j ≤ p max i then 8: x ij ← 1 9: U ← U + C i p j 10: assigned ← true 11: break 12: end if 13: end for 14: if not assigned then 15: correctness ← false 16: break 17: end if 18: end for 19: return (correctness, U , X) 20: end function Proposition V.5. The highest period first (HPF) assignment yields the tight lower bound for the TA* problem.

Algorithm 4 HPF Algorithm
Proof: Without loss of generality, we observe one task τ i from task set T and two correct periods p j and p k such that p j < p k . Assume that U 0 is utilization of task set T without τ i and that to each task a period value is assigned correctly. We observe two possible period assignments for τ i . In the first case, T i ← p j , and system utilization is U = U 0 + C i p j . In the second case, T i ← p k , and system utilization is U = U 0 + C i p k . As p j < p k , it follows that C i p k < C i p j , and consequently U < U . Therefore, assignment to higher period p k for each τ i will yield a lower bound of utilization. Moreover, this lower bound is tight.
Proposition V.6. The highest period first (HPF) period assignment yields a lower bound of utilization for the TA problem.
Proof: Proposition V.5 guarantees that the HPF will yield minimal utilization in the case when there are no restrictions on the number of the distinct period values which have to appear in the solution. The HPF algorithm tries to assign the highest period value to each task, but this is not possible if we have restriction on the number of distinct period values as all of the period values have to be used. Therefore, if the highest correct period value cannot be assigned to the task, the lower period value will be assigned to the task and consequently utilization will increase. Therefore, the HPF assignment yields a lower bound of the utilization for the TA problem. However, in this case, this bound may not be tight.
Both, the HPF and the LPF, have polynomial-time complexity, which is evident from Alg. 4. For each task in a task set, i.e., in n steps, the highest or the lowest period is chosen in at most m steps. Therefore, the time complexity of these algorithms is O(n · m). Note that these algorithms are not suitable for solving UDHPA instances as they do not guarantee that the number of used values in the solution will be equal to m, i.e., some period values from p may remain unused. However, in cases when there is restriction only on the maximal number of period values, i.e., solution can have any number of period values from 1 to m max , usage of these algorithms is appropriate. Moreover, usage of these algorithms is appropriate for UHPA instances as in the UHPA problem there are no constraints on the number of period values. In such cases, we first use period enumeration to find appropriate period sets, and HPF or LPF approach to find corresponding task assignments. Time complexity of the approach is pseudo-polynomial with regard to p max max as time complexity of PE algorithm is in O(p max max log m−1 (p max max )), and polynomial regarding n, as time complexity of HPF and LPF is in O(m · n)

2) THE OPTIMAL TASK ASSIGNMENT ALGORITHM
An optimal algorithm for enumeration of task assignments is depicted with Alg. 5. We refer to this algorithm as optimal task assignment (OTA). Prior to explaining the optimal task assignment algorithm, we explain how the bounds calculated by the HPF and the LPF algorithm are used. Moreover, we explain how the number of distinct period values is tracked during the enumeration process.

a: BOUNDS OF UTILIZATION
Using the HPF and the LPF assignment, we construct the vector of lower bounds b l and the vector of upper bounds b u . These vectors are used to prune infeasible or suboptimal branches in the enumeration of task assignments. These vectors contain upper and lower bounds of subsets of task set T . In this context, the i-th subset of task set T is set T i = {τ i , τ i+1 , . . . , τ n }. Therefore, the i-th value of vectors b l and b u can be expressed as: where U HPF (T i ) corresponds to the utilization obtained by the HPF assignment for task set T i . Similarly, U LPF (T i ) corresponds to the utilization obtained by the LPF assignment for task set T i . It is worth noting that the first values of both vectors, namely b l 1 and b u 1 , correspond to the lower bound and the upper bound of task set T , i.e., T = T 1 . Values b l n+1 = 0 and b l n+1 = 0 are introduced for valid comparison in the last step of recursion (see line 28 in Alg. 5).

b: USAGE OF EVERY PERIOD IN THE ASSIGNMENT
To ensure that every period value p j is used in a task assignment at least once, we have to track the number of used period values when constructing a task assignment. Therefore, we introduce the binary vector l with values l j such that: Additionally, d is the number of currently assigned period values, i.e., d = m j=1 l j . As all of the period values have to be used at least once, in a valid task assignment d must be equal to m.
Here follows a detailed explanation of the OTA algorithm depicted with Alg. 5. For brevity and ease of representation, variables U max , X max , X, l j , and d, flag feasible, and bounds b l , b u are assumed to be global. U max is the current maximal value obtained for assignment matrix X max , and flag feasible indicates the feasibility of the problem. Global variable X is current assignment matrix. The local variable u represents utilization at step i.
In the first part of the algorithm, i.e., Task Assignment function, we use the HPF assignment to determine the lower bound of utilization prior to enumerating all task assignments (lines 2 to 8 in Alg. 5). If the obtained lower bound is greater than one or the assignment is not correct, there is no need for enumeration of task assignments (line 6 in Alg. 5). In this way, we efficiently prune a lot of period sets for which the task assignment is infeasible.
In the second part of the algorithm, i.e., Task Assignment Step function, task assignments are enumerated in a recursive manner. In the basic case (lines 12 to 18), we test if the utilization of the current task assignment u is larger than the current maximal value U max , and update the solution X max accordingly. In other cases, period values are conditionally assigned to the tasks (lines 21 to 36).
At the beginning of the loop, we check if the value p j is assigned to any task at the previous recursion steps. If l j is 0 at step i, value p j is not assigned to any task τ k such that k < i. On the other hand, if value p j is used for the first time at step i, we set values of l j and auxiliary variable ul to 1 (lines 22 to 25). The auxiliary variable ul keeps track of ''locking'' period value p j at step i. Therefore, at the end of the loop (lines 32 to 35), if p j was used for the first time at step i, we have to reset (''release'') l j and ul.
Next, we break down two groups of conditions in their respective if statements (line 26 and 28). The first if statement checks validity of assignment. The first condition, i.e., p min i ≤ p j ≤ p max i corresponds to the correctness criteria (Def. II.1). In the second condition, m − d is the number of unused periods from the input period set p, and n − i is the number of tasks to which the period is not assigned. The condition requires that the number of unused periods is less than or equal to the number of tasks to which a period value is not assigned. In other words, if it is not possible to assign every period value in the next recursion steps, p j cannot be assigned to τ i . In line 27, period p j is assigned to task τ i , i.e., utilization for the next recursion step is incremented by C i p j . The second if statement (line 28) serves to test the feasibility and the bounds of the assignment. Condition u ≤ 1 ensures feasibility of the assignment. The second condition, i.e., u + b l i+1 ≤ 1, checks if the sum of the current utilization and minimal utilization of task subset T i+1 is less than or equal to one. If this condition is false, we know that there is no assignment for which the final utilization will be less than one, because b l i+1 is a lower bound. Similarly, the third condition, i.e., u + b u i+1 ≥ U max , checks if the sum of the current utilization and maximal utilization of task subset T i+1 is greater than or equal to current maximal value U max . If this condition is not true, we know that there is no assignment for which the final utilization is greater than the current maximal value U max , because b u i+1 is a upper bound. The time complexity of the OTA algorithm is evidently exponential in the number of tasks n. In the worst-case, when bounds are ineffective, one of the m period values will be assigned to each task. Therefore, the time complexity of the OTA algorithm is in O(m n ). To find an optimal solution to an UDHPA instance, we have to use the OTA algorithm for each period set obtained using the PE algorithm. Complexity of such an approach is again pseudo-polynomial with regard to p max max , since the time complexity of the PE algorithm is in O(p max max log m−1 (p max max )), and exponential with regard to n, since the time complexity of the OTA algorithm is in O(m n ).

VI. EVALUATION
To further investigate the UDHPA problem and our approach, we perform an extensive evaluation of the developed algorithms on synthetically generated task sets. Firstly, we show how the difficulty of the problem changes with regard to utilization, the number of distinct period values, the width of period ranges and the number of tasks in a task set. Furthermore, we show how our approach can be used for UHPA problem instances and compare it with existing approaches. As the parameters used for synthetically generating task sets correspond to the parameters of task sets in motivational scenarios, we show that our approach can be efficiently used in plenty of real-world scenarios. Moreover, we provide a small numerical example that illustrates the benefits of our approach in motivational real-world scenarios.

A. TASK SET GENERATION
We generate task sets using the UUnifast algorithm [27], which is commonly used in measuring the performance of algorithms in real-time systems. Using the UUnifast algorithm we generate utilizations of task sets with regard to p max i of tasks in a set. Therefore, the target utilization for VOLUME 8, 2020 Task Assignment Step( p, 1, 0) 10: end function 11: function Task Assignment Step( p, i, u) 12: if i == n + 1 then 13: if u > U max then 14: feasible ← true 15: U max ← u 16: X max ← X 17: end if 18: return 19: end if 20: ul ← 0 21: for j in range 1 to m do 22: if l j == 0 then 23: l j ← 1 24: ul ← 1 25: end if 26: if p min We generate task sets with utilization U min from interval [0.2, 0.9] with an increment of 0.025. Moreover, p down = 1, p up = 2048, and σ = 0.4. We generate 1000 task sets per utilization factor, i.e., a total of 29 · 1000 = 29000 task sets. Every task set consists of n = 20 tasks. These are the default task set generation parameters unless noted otherwise. When it comes to algorithm runtime measurements, it is worth noting that our implementations of algorithms are written in C++. Additionally, the specifications of the computing platform are given in Table 1. Furthermore, we terminated an algorithm if we obtained the utilization value in the interval [1 − 10 −7 , 1].

B. EVALUATION ON UDHPA INSTANCES
In this section, we evaluate our optimal approach which consists of the PE algorithm (Alg. 2) and the OTA algorithm (Alg. 5) on UDHPA instances with regard to different problem parameters m, σ and n.
Firstly, we evaluate our approach with regard to different number of distinct period values in the solution m. Fig. 1 shows the number of feasible systems for different utilization factors and for a different number of distinct period values in the solution. It can be seen that, for m = 5, we obtain the highest number of feasible solutions. For higher values of m, the number drops, and we know from Proposition V.3 that the maximum value of distinct period values for the system to be feasible equals log 2 2048 1 + 1 = 12. Since the number of feasible systems for m > 8, m < 3 is lower than for m = 8, we did not include these graphs in Fig. 1. Moreover, Fig. 2 shows the average number of enumerated period sets with regard to m. It can be seen that, for higher values of different period values m, the number of harmonic period sets is reduced. Thus, increasing the number of different period values reduces the number of potentially feasible systems. On the other hand, although the number of enumerated period sets is higher for lower m in Fig. 2, feasibility is reduced for lower m as it is more difficult to find a lower number of harmonic period values that satisfy the correctness criteria (Def. II.1) for each task in the system. Fig. 3 shows the average resulting utilization for each utilization factor and a different number of distinct period values. In this particular evaluation, we set the resulting utilization of infeasible systems to zero. In this way, we do not lose information about the overall feasibility of systems. Again, it can be seen that, for m = 5, we have the best result. Dashed lines in the figure denote the utilization lower bound obtained by the HPF assignment for the corresponding number of distinct period values. Fig. 4 shows the average utilization of feasible systems. Here, we averaged the resulting utilization of feasible systems for every m in interval [3,8]. Additionally, Fig. 4 shows the lower bound and the upper bound obtained by the HPF and the LPF assignment, respectively. It can be seen that the resulting utilization of our optimal approach is very close to the upper  bound for lower utilization values. When the upper bound is higher than 1, our optimal approach yields the highest possible utilization values lower or equal to 1. Fig. 5 shows the average runtime per task set of our implementation of the algorithm for each utilization factor and a different number of distinct period values. It can be seen that, on average, the algorithm for larger numbers of different period values has a higher runtime. This is mostly due to a higher number of potential task assignments in solving the TA problem. Additionally, it is worth noting that the average runtime for m = 8 is lower than for m = 7 and m = 6. For m = 8, there is a smaller number of enumerated period sets, and therefore fewer TA problem instances have to be solved.
Figs. 6-8 show the effect of the period width σ on the overall feasibility, utilization and average runtime. We use the same parameters in task set generation as in the previous evaluation. However, in this case, the number of distinct period values is fixed, i.e., m = 5, and the period range  width values σ from interval [0.2, 0.7] are used. Additionally, 100 task sets for each utilization factor and for each σ are generated, which totals to 29 · 6 · 100 = 17400 task sets. Fig. 6 shows the feasibility for each utilization factor and for different period widths. It can be seen that, for higher σ , i.e., lower period range width, feasibility drops significantly. This is to be expected as the correctness constraints are more strict and there is less chance of finding a potentially feasible harmonic period set.
In Fig. 7, we again show the average resulting utilization per utilization factor assuming that the utilization of infeasible system equals zero. Larger period range width increases the number of feasible enumerated period sets, and consequently utilization is higher as the task assignments with high utilization can be discovered.
In Fig. 8, we see, that for a larger period range width, i.e., σ = 0.2, runtime is of an order of magnitude higher  than a smaller period range width. As we already mentioned, the number of feasible solutions is higher for larger period range width and more enumerated period sets have to be explored. Thus, the runtime is increased. It is worth noting that runtime graphs for σ ∈ [0.4, 0.7] cannot be distinguished, as they are much lower than the average runtime for σ = 0.2.
Finally, we perform the evaluation of our optimal algorithm with regard to the size of a task set. In the previous evaluation, we have fixed the number of tasks in a set to 20. For the purpose of this evaluation, we have fixed the period range width, i.e., σ = 0.4 and the number of distinct period values, i.e., m = 5. For Figs. 9-10, we have generated 200 task sets for each utilization factor and for each n ∈ [20,30,40,50], which totals to 29 · 4 · 200 = 23200 task sets. Fig. 9 shows the number of feasible task sets with regard to n. It can be seen that, by increasing n, feasibility drops. This is the effect of adding more period range constraints in the systems for each  task. Intuitively, it will be more difficult to find an appropriate period assignment with a higher number of constraints. For the same reason, the total average utilization is reduced when n is increased as depicted in Fig. 10. For the runtime evaluation with regard to n, we have set the utilization factor to U min = 0.6 and generated 200 task sets for every fifth number of tasks in range [20,100], i.e., a total of 200 · 17 = 3400 task sets. In Fig. 11, the PE + OTA graph corresponds to our optimal approach. The PE + EXH graph corresponds to an approach which consists of the PE algorithm (Alg. 2) and an exhaustive search of task assignments, which does not employ utilization bounds and pruning rules devised in section V-B2. We can see that the runtime of exhaustive search rises exponentially with the number of tasks, which is an expected behavior, since, at worst, time complexity is in O(m n ) (evaluation is not performed for n ≥ 70). On the other hand, we see that the runtime of the PE + OTA approach has  a reduced growth rate due to the usage of devised utilization bounds and pruning rules.

C. EVALUATION IN THE CONTEXT OF EXISTING UHPA APPROACHES
On the basis of Theorem IV.1, we know that the UHPA problem is Turing reducible to the UDHPA problem, and therefore we can simply employ our optimal algorithm for UHPA instances. To solve an UHPA instance, we need to solve the corresponding UDHPA instances for every possible number of distinct period values m, which is given with Proposition V.3. To optimally solve an UHPA instance, we use the PE algorithm in combination with the OTA algorithm for each m. In the UHPA problem, there is no restriction on the number of distinct period values. Thus, we can use the PE algorithm with the HPF algorithm to obtain the period assignment for each m. It is worth noting that it is possible that, while using the HPF algorithm, some values of the enumerated period set may remain unused. However, this is not a problem in the context of UHPA instances, since there are no restrictions on the number of different period values. We compare our approach with existing UHPA approaches in the literature, which are based on finding harmonic projections for given task period ranges [10], [11]. The algorithms employed in these approaches are generally of pseudo-polynomial time complexity, but in specific cases complexity can be reduced to linear or polynomial time. The approach in [10], referred to as forward search, consists of two parts, namely the graph construction algorithm (GCA), and a greedy heuristic for period assignment, which can yield low utilization (LU) or high utilization (HU). Here, we employ the LU heuristic as it increases the chance that the resulting harmonic period assignment will be feasible. The GCA part is analogous to our period enumeration part of the algorithm. Similarly, the HPF and OTA algorithms are counterparts to the LU heuristic. The approach from [11], referred to as backward search, is based on the harmonic period existence test and suboptimal heuristic period assignment. Figs. 12-16 show the performance of our approach in comparison with approaches from [10], [11]. We have generated task sets using the default task set generation parameters from the beginning of this section. Fig. 12 shows the number of feasible systems for different period assignment approaches. It can be seen that the number of feasible task sets is higher when our optimal approach (PE + OTA) and heuristic approach (PE + HPF) are used, than when forward search or backward search are used. The number of feasible systems when the PE + HPF or PE + OTA approaches are used is the same because both algorithms are optimal regarding feasibility. However, the HPF algorithm yields the solution with the lowest utilization. More precisely, it yields the lowest utilization for the TA* problem. As explained in section V-B1, the TA* problem does not restrict the number of different period values in the  solution, and therefore the utilization obtained using the HPF assignment is minimal. Fig. 13 shows the resulting utilization for different period assignment approaches. As expected, our optimal approach (PE + OTA) yields the highest utilization. Moreover, the period enumeration with the HPF assignment (PE + HPF) dominates forward search and backward search as well.
Finally, we present the runtime results in Figs. 14-16. In Fig. 14, it can be seen that the runtime for forward search and backward search is at least an order of magnitude lower than in our approach. Since the period ranges are relatively wide, i.e., σ = 0.4, both forward and backward search are time-efficient. Moreover, in Fig. 15, we can see that when the number of tasks in a set is increasing, runtime is higher for exhaustive search (PE + EXH) and our optimal approach (PE + OTA) than for the other approaches which cannot be distinguished in the figure. The PE + HPF approach is  efficient when the number of tasks is increasing, since the time complexity of the HPF algorithm is polynomial O(n · m) and the time complexity of the PE algorithm does not depend on the number of tasks in the system. However, in Fig. 16, we can see that the runtime of approaches which employ PE algorithm increases when the maximum period in the system p max max is increased. It is worth noting that although runtime can be significantly higher when our optimal approach (PE + OTA) and the heuristic approach (PE + HPF) are used, it is still relatively low, i.e., several milliseconds per task set. Since period assignment in practice is typically done off-line during the application design, this is more than acceptable.

D. NUMERICAL REAL-WORLD PERIOD ASSIGNMENT PROBLEM
To further emphasize and explain the benefits of our approach, we provide a numerical example of a small  real-world period assignment problem. As we have already stated in the introduction, the structure of safety-critical control applications is modular and often each module, i.e., task, is developed by a different application designer.
In the development process, based on the specific application requirements, application designers provide implementations of tasks with suggested execution rates, which are in this paper and related literature modelled with period ranges. It is in the interest of every application designer that their module executes with the highest possible execution rate, i.e., the smallest period, in order to achieve a higher quality of service for a particular part of the application. Based on the input from the application designers, the system designer has to determine periods which shall be used in the system to achieve the highest utilization, i.e., quality of service. Thus, utilization is maximized. Table 2 shows the task set with task parameters. Such a table is an input to the system designer. However, due to the specific architecture of the system, i.e., the operating system and the underlying hardware, the system designer is restricted regarding the number of distinct period values which can be used in the solution. In this example, the maximum number of different period values is 4. Therefore, any number of different period values smaller or equal to m max = 4 can be used. Table 3 shows the period values assigned to each task in the input. We can see that period enumeration with the optimal task assignment (PE + OTA) yields the most satisfying result, since it produces the maximal utilization and uses no more than 4 period values. In order to achieve this, the system designer has to solve UDHPA instances using the PE + OTA approach for m in the interval [1, m max = 4]. We can see that period enumeration using the HPF algorithm (PE + HPF) also yields a satisfying result as the number of the distinct period values is lower than m max . However, the utilization is lower than the value obtained using the OTA algorithm. The forward and the backward search do not yield satisfying results, since they do not restrict the number of distinct period values in the solution. Moreover, utilization factors are significantly lower than when using both the PE + OTA and the PE + HPF approaches.

VII. CONCLUSION
In this paper, we have defined the utilization-maximizing harmonic period assignment problem with a constrained number of distinct period values (UDHPA). The motivation for this problem arises from the observation of industrial control systems in which the number of different period values is either fixed or restricted. We have put the problem in the context of the already studied UHPA problem and show that the UHPA problem is Turing reducible to the UDHPA problem. Additionally, we show that UDHPA problem is at least weakly NP-hard. We have devised an optimal algorithm for the UDHPA problem and showed its efficiency on a large number of synthetically generated task sets. Moreover, we have used the developed algorithm for solving UHPA instances and explained the differences between our approach and the existing approaches. The key benefit of our approach lies in the fact that, for a large variety of synthetically generated UDHPA and UHPA instances, our algorithm is timeefficient and optimal, and therefore more than suitable for use in real-world system design. Furthermore, as we have shown on a numerical example, the existing approaches are not applicable in systems with a restricted number of different period values. Our future work will include the application of our algorithm to real-world scenarios and a further theoretical analysis of the relation between the optimal number of distinct period values and period ranges of tasks.