AUTOSAR Runnable Periods Optimization for DAG-Based Complex Automobile Applications

: When developing an automobile control application, its scheduling parameters as well as the control algorithm itself should be carefully optimized to achieve the best control performance from given computing resources. Moreover, since the wide acceptance of the AUTOSAR standard, where ﬁner-granular scheduling entities (called runnables) rather than the traditional real-time tasks are used, the number of scheduling parameters to be optimized is far greater than the traditional task-based control systems. Hence, due to the vast problem space, it is not feasible to reuse existing time-consuming search-based optimization methods. With this motivation, this paper presents an analytical codesign method for deciding runnable periods that minimize given control cost functions. Our solution approach, based on the Lagrange multiplier method, can ﬁnd optimized runnable periods in polynomial times due to its analytical nature. Moreover, our evaluation results for synthesized applications with varying complexities show that our method performs signiﬁcantly better (12% to 59% of control cost reductions) than a state-of-the-art evolutionary algorithm. To the best of our knowledge, this study is one of the ﬁrst attempts to ﬁnd runnable periods that maximize a given system’s control performance.


Introduction
AUTOSAR is the de facto standard software architecture for automobile control systems, covering a wide range of applications such as engine management, motor-driven power steering, and advanced driver assistance systems [1][2][3]. In the AUTOSAR standard, a control system is designed as a set of software components, which are the units of software packaging and deployment. Usually, multiple software components are connected and communicate through the AUTOSAR runtime environment (RTE). Each software component is also composed of a set of runnables, which are the smallest unit functions for software development and scheduling. Runnables communicate with each other within each software component and across different software components, using asynchronous message passing interfaces provided by the RTE. As a result, a system can be modeled as a directed acyclic graph (DAG) of runnables where data flow from sensors to actuators through the runnables in the DAG.
For runnable executions, each runnable is associated with an event source, which is usually a periodic timer, and runnables with the same periods are grouped into periodic tasks for scheduling on the AUTOSAR real-time operating system (RTOS). Runnable periods should be carefully optimized since they are control knobs for balancing the trade-off between a system's load and control performance. For example, imagine a system with extremely short runnable periods. The system will then be much too heavily loaded, hence not schedulable since the runnables should execute with extremely high frequencies. On the other hand, the short runnable periods, if realized, can produce a high control performance due to fast data flows and high control frequencies. At the opposite extreme, i.e., a system with extremely long runnable periods, it will be lightly loaded and hence easily schedulable; however, its control performance will be significantly degraded due to slow data flows and low control frequencies. In that sense, we need a method to find optimal runnable periods between those two extreme cases.
However, in the automotive industry, runnable periods are usually decided in an ad-hoc manner with time-consuming trials and errors [4], making it difficult to extract the optimal control performance out of given hardware resources. To cope with this problem, this paper formulates a runnable periods optimization problem for maximizing the control performance of a given system. Our previous work's initial approach was to use a simple combinatorial search method to find real optimal runnable periods [5]. However, our preliminary experiment revealed that even for a small system with a dozen runnables, since the optimization process cannot find solutions in polynomial times, it takes too much time, making it impractical for complex industry applications.
To deal with this scalability problem, our approach is to develop an analytical method that can find near-optimal solutions without time-consuming searches. For that, the first step is to pick an appropriate control performance model as the optimization objective. Among various models in the literature, we chose the linear control cost model from Bini and Cervin [6] that represents a control system's performance as an approximate linear cost function of its control period and delay [6]. This model has been used as a standard tool by many control-scheduling codesign studies [7][8][9][10]. The second step is to define the optimization constraint, that is, the schedulability constraint in our problem. Since the AUTOSAR standard assumes a priority-driven scheduling algorithm, we use the Liu and Layland (L&L) utilization bound method [11], which can be used for both the rate monotonic (RM) and the earliest deadline first (EDF) scheduling algorithms. For the explanation purpose, the EDF scheduling algorithm is mostly assumed throughout this paper, and later our method is extended to the RM scheduling algorithm.
Based on the control cost function and the schedulability constraint, our specific problem is to find the runnable periods that minimize the control cost while guaranteeing the schedulability constraint. Since the control cost function is a function of control period and delay, it should be transformed into a function of runnable periods. For that, we carefully investigate how runnable periods affect the temporal behavior, i.e., control period and delay, of a control system, and develop a generalized method for the transformation.
After the transformation, the Lagrange multiplier method is used to find the optimal runnable periods. Note that the Lagrange multiplier is a well-known optimization method for constrained optimization problems. As it provides an analytical method without any problem space search, our method can find the optimal runnable periods regardless of the size and the complexity of a target system. The detailed optimization process is explained in three steps beginning from the most uncomplicated application model to the general DAG model for the explanation purpose. Although our solution cannot find the real optimal solutions due to a heuristic applied during the optimization, our evaluation results for small systems show that the performance loss is marginal compared with the real optimal solutions. Moreover, even for large systems, our method performs better compared with a state-of-the-art optimization method. This paper's contributions can be summarized as follows: • We formulate a problem of AUTOSAR runnable periods optimization in the context of control-scheduling codesign, which we consider to be one of the first such attempts; • For the above problem, we present a Lagrange multiplier-based analytical method for DAG-based AUTOSAR control applications, which can find near-optimal solutions in polynomial times.
The rest of this paper is organized as follows: Next section provides related work. In Section 3, the background is given and the problem is described. Sections 4 and 5 introduce our preliminary works for limited application models. Then, Section 6 describes our analytical solution for the general DAG model. Section 7 evaluates our method. Finally, Section 8 concludes this paper.

Related Work
Periods selection problem. Control-scheduling codesign methods have been developed in the literature to improve a control system's performance through optimizing its scheduling parameters. In this regard, Seto et al.'s seminal work [12] first presented a periods selection problem assuming that the control performance can be expressed as an exponential decay function of sampling periods and that the tasks are scheduled under a dynamic-priority scheduling algorithm. The periods selection problem was extended to fixed-priority systems by finding the finite set of feasible period ranges using a branch and bound-based integer programming method [13]. Later, Bini and Di Natale [14] proposed a faster algorithm that finds a sub-optimal periods assignment, which can be used for task sets of practical size that are not solvable by previous methods due to high computing demands. Du et al. [15] presented an analytical solution using the Lagrange multiplier method and an online algorithm for overloaded situations. Fu et al. [9] developed a heuristic algorithm for multicore processors.
Delay-aware approaches. A common assumption of the above studies regarding the periods selection problem is that the control performance is only affected by sampling rates, i.e., task periods, of a control system. However, delays between sensing and actuation also have significant effects on control performance. With this motivation, Bini and Cervin [6] incorporated each task's delay into their optimization cost function. In their work, to find the optimal periods assignment, cost functions are approximated as linear functions of control period and delay, and the delay is also approximated assuming the fluid model scheduler. Through the approximations, they proposed an analytical solution. Xu et al. [16] extended this approach for systems with harmonic periods.
Periods and deadlines selection problem. Wu et al. [8] formulated an optimization problem for selecting both task periods and deadlines simultaneously for EDF-scheduled systems. They showed that we can upper bound the amount of delays and jitters each task can experience by regulating relative deadlines of tasks. The cost function is assumed to be a nonlinear function of period and deadline of each task. Based on that, a two-step approach was proposed, which first fixes periods and later tries to minimize deadlines exploiting unused resources. Tan et al. [10] proposed an algorithm that simultaneously adjusts periods and deadlines assuming EDF-scheduled linear-quadratic-Gaussian (LQG) controllers. They showed that their algorithm is more robust with various workloads than the previous method. Cha et al. [17] proposed a heuristic algorithm for the periods and deadlines selection problem with arbitrary nonlinear control cost functions for systems scheduled by the RM scheduling algorithm.
Cause-effect chain analysis. The above studies commonly assume independent real-time tasks, where there is no data dependency among tasks and each task is responsible for its dedicated control target plant. To deal with practical automobile control applications composed of tasks with complex dependencies, DAG-based control applications had been studied in the context of cause-effect chain analyses of real-time tasks [18][19][20][21]. Even though they are using tasks instead of runnables, their system model is similar to ours. However, they address the opposite direction of our optimization problem, which is to analyze end-to-end delays for a DAG of tasks with given periods. Besides, [22] analyzed end-to-end delays of an engine management system, which is given as a DAG of runnables.
AUTOSAR system optimization. In automobile control systems based on the AUTOSAR standard, each control application is designed as a DAG of fine-granular runnables with more complex data dependencies compared with traditional real-time task-based systems. In this context, Long et al. [23] developed a runnable placement and scheduling method considering the inter-runnable communication overhead in an electronic control unit (ECU). Monot et al. [24] proposed an algorithm for sequencing and scheduling runnables for multicore ECUs. Saidi et al. [25] studied the runnable-to-core mapping problem using the integer linear programming (ILP) technique.
Kehr et al. [26] developed a method for migrating a legacy AUTOSAR application to a multicore processor while minimizing energy consumption.
AUTOSAR runnable scheduling. However, the above studies about AUTOSAR applications commonly assume that runnable periods are given a priori, which is not valid in the industry practice. With this motivation, runnable periods optimization problem was first formulated in our previous research paper by Kim et al. [5], which proposed a combinatorial search method that is useful only for small systems due to its high computing demands. Choi et al. [27] partly solved the scalability problem using an analytical method only for limited application structures. These two papers are precursors to this paper and will be thoroughly explained even in more depth and detail in Sections 4 and 5 for the self-completeness of this paper. This paper then further extends our previous works by presenting a more general solution that applies to arbitrarily-shaped complex DAG-based AUTOSAR applications.

System Model
This paper assumes an automobile control application based on the AUTOSAR standard. Figure 1 shows an example system where the application is composed of N software components Each software component C i is also composed of |C i | runnables where |C i | denotes the number of runnables in C i . Note that a runnable is the smallest unit function in the AUTOSAR standard. As shown in the figure, runnables, denoted by r i s, are connected with directed edges representing data dependencies among them. Thus, the whole system can be thought of as a DAG of runnables without explicitly specifying which software component each runnable belongs to. A DAG G is formally defined as where the set of vertices V is a set of n nodes or runnables {r 1 , r 2 , · · · , r n } where n = ∑ N i=1 |C i | and E represents a set of directed edges or links among them. There exists a directed edge (r j , r k ) ∈ E if and only if the runnable r k has a data dependency on the runnable r j . Then, each i-th runnable r i is defined by a tuple where p i is its period and e i is the worst-case execution time. Among the runnables, we assume that r 1 , the sensor runnable, plays a special role of collecting data from sensors, and r n , the actuator runnable, is responsible for controlling actuators. Thus, G has only one source node r 1 and one sink node r n .
Our system model assumes that, in an ECU, there is only one CPU running a single control application described by G, where the ECU handles only a single control target plant, which is common in the automotive industry's federated architecture [28,29]. Note that e i s are given properties of the system, whereas p i s are controllable parameters. Thus, the runnable periods (p 1 , p 2 , · · · , p n ) should be decided before integrating the runnables on the AUTOSAR platform. Once p i s are decided, runnables with the same p i s are grouped and consolidated into RTOS tasks, which are scheduled following the scheduling strategy of the RTOS. For communications between runnables, an asynchronous sender-receiver communication is used [30]. In this communication method, a sender runnable periodically generates its output in a shared memory buffer with its own period, then a receiver runnable asynchronously reads the data in the memory buffer with its own period. When multiple writes occur to the same memory location without any reading operation from the receiver, the most recent data are always overwritten in the buffer. For further discussions afterward, we formally introduce the following definitions:

Definition 1. (Paths)
For a DAG G = (V, E), there is a finite number of directed paths from the source node r 1 to the sink node r n . We assume that there are m paths in G, which is denoted by Then, a path is formally defined as an ordered set of runnables beginning with r 1 and ending with r n in which all runnables are distinct and every pair of adjacent runnables is joined by a directed edge in E. From now on, for the notational convenience, when we refer to a path P ∈ P(G), it can denote the ordered set of runnable indexes (1 ≤ i ≤ n) as well as the runnables themselves depending on the context.

Definition 2. (Length)
For a path P ∈ P(G), its length is defined as which is the sum of runnable periods following a specific path P. When data flow through several paths in parallel, the speed of a data flow is collectively determined by the runnable periods in each path through which the data are flowing, considering our inter-runnable communication method.

Definition 3. (Weight)
For a path P ∈ P(G), its weight is defined as which is the sum of runnable execution times following a specific path P. Thus, a path's weight is a representative metric for the amount of computing resource demand of the path.

Definition 4. (Critical Path)
Given a DAG G with its paths P(G), its critical path is defined by the path found in argmax which is the path with the longest length. Without loss of generality, we assume that there is only one critical path in each DAG.

Definition 5. (Heaviest Path)
Given a DAG G with its paths P(G), its heaviest path is defined by the path found in argmax which is the path maximizing the sum of e i s for the runnables in the path. The intuition behind the heaviest path is that it indicates the path that consumes the maximum amount of CPU time for a single execution of paths. Without loss of generality, we assume that there is only one heaviest path in each DAG.

Control Performance Model
A control system's performance can be defined in many different aspects. For example, its robustness to external disturbances, control stability, and control error can be such performance metrics. In general, a control system's performance is affected by its timing behavior as well as the control algorithm itself [31]. In this paper, we assume that the control algorithm is given as a fixed system property. Thus, our control performance model is about how the system's temporal properties affect the control performance. More specifically, we consider two distinct temporal properties: control period and end-to-end delay of the target control system.
In the AUTOSAR timing extensions, two latency constraints are defined: (i) data age timing constraint and (ii) reaction time constraint [20,32,33]. The specification states that when an actuator command is periodically produced, its source input (sensing) value's age should be maintained within a specified timing constraint. The reaction time constraint is also considered when an external event, such as pressing a button, should be reacted within a specified timing constraint. In this paper, since we are considering periodic workloads, the data age timing constraint is considered.
Based on the timing model, there are several ways to build a control performance model. One is to measure the resulting performance of the system by artificially controlling the temporal parameters. Simulation tools [34,35] can also be used to predict the control performance when we cannot directly measure the system under investigation. To provide a more general model, Bini and Cervin [6] introduced a linear control cost function as where T is the control period, and ∆ is the end-to-end delay from the sensors to the actuators. Note that α and β are constants that define the characteristics of the control target plant. Figure 2 shows an example control cost function. The intuition behind it is that if we give control commands to the actuator more often (frequently), its control cost gets smaller, and in the same manner, if we decide the control command with more fresh (recent) sensor data with shorter delays, the cost gets smaller, again. In general, the cost function J can be a nonlinear function of T and ∆, however, it can be approximated as a linear function as in [6][7][8][9][10]16]. In this paper, we use this linear approximate control cost function as the optimization objective.

Control cost
Delay (Δ) Period (T) Figure 2. Control cost function, which is a linear function of the system's control period and delay [5].

Schedulability Constraint
The runnables {r 1 , r 2 , · · · , r n } are implemented as RTOS tasks, where runnables with the same period are grouped together and sequentially executed inside a task body when the task is scheduled on a CPU. As most RTOSes only support implicit deadline tasks, their relative deadlines (= periods) should be guaranteed to satisfy runnable-level periodic timing requirements, i.e., p i s. For that, in this paper, we use the L&L utilization bound method, which guarantees the schedulability of a given system if the system utilization is less than or equal to a specific threshold value (i.e., utilization bound) for each scheduling algorithm. For example, the RM scheduling algorithm's utilization bound is roughly 69.3%, and the EDF scheduling algorithm's utilization bound is 100% [11]. We chose to use EDF for its simplicity, where its schedulability condition can be formally expressed as follows: Although we mainly use the EDF scheduling algorithm throughout this paper, since most scheduling algorithms support the utilization bound method for the schedulability test, we can easily apply our optimization method to other scheduling algorithms like the RM scheduling algorithm. Section 6.5 will deal with this issue in more detail.

Problem Description
With the system and control performance models and the schedulability constraint presented above, our problem can be defined as follows: With a given AUTOSAR control system composed of DAG-structured runnables {r 1 , r 2 , · · · , r n } and a linear control cost function J(T, ∆) regarding the control target plant, find the optimal runnable periods (p 1 , p 2 , · · · , p n ) that minimize the control cost while satisfying the system's schedulability constraint. More formally, our problem is as follows: minimize p 1 ,p 2 ,··· ,p n J(T, ∆) subject to U(p 1 , p 1 , · · · , p n ) ≤ 1. (12) In this paper, we try to find the theoretically optimal real numbered runnable periods, without explicitly considering neither the grouping of runnables into predefined periodic tasks nor the scheduling granularity (e.g., integer constraints) of a specific RTOS. However, our solution can be used as a baseline foundation for further practical applications after considering the implementation details imposed by a specific RTOS.

LPG Model
Instead of directly going for a general solution, let us begin by solving our optimization problem for a subset of the DAG model, and later extend the solution step by step towards a generalized one. This section specifically deals with the linear path graph (LPG) model, which is for graphs with runnables {r 1 , r 2 , · · · , r n } such that the edges are given by Figure 3 shows an example LPG with n runnables and n − 1 edges between them.

Transformation of Control Cost Function
When solving the optimization problem in the LPG model's scope, the first step is to redefine the control cost function as a function of the free variables of the optimization problem, i.e., runnable periods (p 1 , p 2 , · · · , p n ). For the transformation of J(T, ∆) in Equation (10) into a function of runnable periods, our strategy is to define both T and ∆ using only runnable periods considering the LPG model's runnable execution and data flow patterns.
Control period T can be formally defined, from a plant's perspective, as a regular time interval between consecutive actuation instances. However, due to the jitter caused by preemption delays among concurrent runnables, the intervals may vary for each actuation instance. Thus, we consider the longest time interval as the worst-case period T. For LPG-based applications, T can be defined as double the actuator runnable r n 's period p n , which is The worst-case scenario happens when a certain instance of r n is scheduled at the beginning of its period, whereas, in the next instance, r n is scheduled at the very end of its period. Assuming that actuation commands are emitted at each completion of r n instances, the time interval between the actuation commands gets to the longest as possible in that particular scenario, which is 2p n . It can be argued that e n should be considered, and the exact worst-case time interval should be 2p n − e n . However, note that since e n is the worst-case execution time, real execution times can be much smaller than e n ; thus, for simplicity's sake, we do not take e n into consideration when defining T.
The end-to-end delay ∆ is defined as the time taken for new sensor data to go through runnables until arriving at the actuator. According to the data flow architecture of our system model, the sensor runnable r 1 sends out its output to its neighboring runnables with its own period p 1 . Then, the neighboring runnables also send out their outputs with their own periods. With these repeated transmissions, new sensor data originating from the source node r 1 gradually propagate through the runnables toward the sink node, i.e., the actuator runnable r n . After r n finally receives the updates, it can decide its actuation commands based on the new sensor data. In an LPG-based application where data flow through only a single path from r 1 to r n , the worst-case end-to-end delay ∆ can be calculated as The worst case happens as in the following: a runnable r i−1 emits its output for r i at a certain time t. Unfortunately, however, r i begins just right before t, reading the previous (old) output of r i−1 . Let us assume that r i is scheduled at the very beginning of its period at that time. Then, unfortunately again, the next instance of r i is scheduled at the very end of its period, reading the new data and emitting its output at the end of the period (i.e., t + 2p i ). In the above scenario, the time taken for the data to go through r i is double the r i 's period 2p i . Assuming this scenario happening for every runnable in the path, the end-to-end delay ∆ becomes double the sum of all the runnable periods as in Equation (14). By combining Equations (13) and (14), the control cost function in Equation (10) is transformed into as follows:

Finding the Optimal Runnable Periods
For visual understanding of the optimization process, let us pick an example system with only two runnables {r 1 , r 2 }. Then, the transformation of the control cost function is illustrated in Figure 4. In the left-hand side, the original control cost function is depicted, which is transformed into a function of p 1 and p 2 as in the right-hand side by Equation (15). Then, Figure 5 illustrates the optimization process where the schedulability constraint and the transformed control cost function are shown upon the two-dimensional problem space of p 1 and p 2 . In the figure, our optimization objective is to find the lowest point in the control cost plane that is inside the green schedulable area. This concept can be generally extended to n-runnable systems in n-dimensional problem spaces. In general, our original optimization problem in Equation (12) can be transformed into the following using the transformed control cost function: minimize p 1 ,p 2 ,··· ,p n J(p 1 , p 2 , · · · , p n ) = 2αp n + 2β Control cost Control cost To analytically solve the transformed optimization problem, the Lagranage multiplier method is applied. For the first step, a Lagrange function is formulated as follows: Then, we take the partial derivatives of L with respect to p 1 , p 2 , · · · , p n , and λ, respectively and set them to zeros as follows: which in turn is expanded to the followings: Then, by isolation λ in the left-hand side of the first in Equation (19), we have which can be applied to the remaining of Equation (19) except the last one. As a result, p 2 , p 3 , · · · , and p n are given in terms of p 1 as in the second to the last of the followings: · · · , p n−1 = p 1 e n−1 e 1 , Additionally, p 1 is given as the first of the above by replacing p 2 , p 3 , · · · , and p n in the last of Equation (19) with the second to the last of the above. Then, by Equation (21), we can find the real optimal runnable periods for arbitrary LPG-based applications.

Analytical Solution for Linear Multipath Graphs
Based on the method for the LPG model explained in Section 4, this section goes one step further to a more complex application model having multiple independent data flows from sensors to actuators.

LMG Model
When designing automobile control applications, there are cases where a simpler data flow model is preferred instead of using the complex DAG model. The most common such case is when there are several independent parallel data flows from sensors to actuators. In Figure 6, r 1 is the sensor runnable and r n is the actuator runnable. Between them, there are m paths where each runnable in the middle part {r 2 , r 3 , · · · , r n−1 } belongs to only one specific path among them. To distinguish such a particular application architecture from general DAGs, we specifically call them the linear multipath graph (LMG) model. Although the LMG model can be applied to a limited range of applications, it is meaningful since there is an increasing need for integrating independent control algorithms to develop integrated control systems or multi-functional ECUs [36][37][38]. In such new systems, sensor data propagate through multiple independent paths of runnables to the actuators.

Transformation of Control Cost Function
For the optimization, the objective function J(T, ∆) in Equation (10) should be transformed into a function of runnable periods (p 1 , p 2 , · · · , p n ). For that, in the same way in Section 4.2, the period T is transformed into as follows: For the end-to-end delay ∆, however, we cannot simply reuse the method in Section 4.2 since we have multiple paths with possibly different lengths. Thus, ∆ should be defined as the length of the longest path among them to represent the worst-case end-to-end delay. More specifically, let us remind that P i denotes the i-th path of m independent paths {P 1 , P 2 , · · · , P m }. Then, ∆ is defined as follows: Thus, our original optimization problem is transformed into as follows: minimize p 1 ,p 2 ,··· ,p n J(p 1 , p 2 , · · · , p n ) = 2αp n + β max where unlike the LPG model, the max operator introduces nonlinearity making it difficult to develop an analytical solution. Fortunately, however, due to the LMG model's workload characteristics, we can simplify the problem by defining an equilibrium state, which is to be obtained to find the optimal runnable periods in the LMG model. The equilibrium state of an LMG can be defined as follows:

Definition 6. (Equilibrium state)
For a set of m paths of a given LMG G, which is denoted by P(G) = {P 1 , P 2 , · · · , P m }, G is in its equilibrium state if and only if ∑ i∈P 1

Theorem 1. (Equilibrium state theorem)
If G is an LMG with its optimal runnable periods, G is always in its equilibrium state.
Proof of Theorem 1. If G is with its optimal runnable periods while not in the equilibrium state, we can increase runnable periods that do not belong to the critical path, without affecting the end-to-end delay. Then, the increased runnable periods will make a lower system utilization, which can be used to further decrease the end-to-end delay by shortening runnable periods in the critical path. Thus, we can conclude that G is not with the optimal runnable periods, which is a contradiction.
By the equilibrium state theorem, we can narrow down the problem space without sacrificing the optimality by excluding non-equilibrium states from the problem space. To express the equilibrium state more efficiently, ∆ is re-expressed by breaking it into three parts as with a helper notationP i = P i − {1, n}. Then, to explicitly express the equilibrium state, we define a new notation p * as in the following: which is an aggregate variable representing the path length of the middle part in the equilibrium state. Then, by using p * , ∆ can be re-expressed from Equations (26) and (27) as follows: Finally, the control cost function J(T, ∆) from Equation (10) is rewritten as a function of (p 1 , p * , p n ) by Equations (22) and (28) as in the following: With this transformed control cost function J(p 1 , p * , p n ), our original problem of n runnable periods is transformed into a problem of three free variables (p 1 , p * , p n ). Then, once they are decided, p * is distributed to runnables along each path. For that, we use a heuristic that runnables with larger e i s are assigned with longer p i s. More specifically, we assign p i s strictly proportional to e i s. Following this assignment rule, runnable periods p j s for eachP i are decided as follows:

Transformation of Schedulability Constraint Function
This subsection transforms the schedulability constraint function in Equation (11) to a function of (p 1 , p * , p n ). First, the original function U(p 1 , p 2 , · · · , p n ) is re-expressed by breaking it into three parts, and the middle part is arranged by grouping the runnables by the paths they belong to. The new expression can be simply comprehended as the sum of m per-path sums of utilizations as in the following: U(p 1 , p 2 , · · · , p n ) = e 1 p 1 + e 2 p 2 + · · · + e n−1 p n−1 + e n p n Then, to transform each i-th per-path utilization sum into a function of p * , Equation (30) is applied to eliminate p j as in the following: where P i denotes the number of elements in the ordered setP i . Finally, our utilization constraint is transformed into as follows:

Finding the Optimal Runnable Periods
After the transformation of the control cost function and the schedulability constraint function, our runnable periods optimization problem for the LMG model can be formulated with the three free variables (p 1 , p * , p n ) as follows: To solve the optimization problem, a Lagrange function is formulated as follows: Then, we take the partial derivatives of L with respect to p 1 , p * , p n , and λ, respectively and set them to zeros as follows: which in turn is expanded to the followings: Then, the first, second, and third of Equation (37) are rearranged by isolating λ in each left-hand side as follows: Then, by combining the first and second of Equation (38), we have the following: By combining the first and third of Equation (38), we have the following: By replacing 1 p * and 1 p n in the last of Equation (37) with the findings in Equations (39) and (40), we have the following: Finally, from Equations (39)-(41), we have the following solution: We have one remaining step of deciding (p 2 , p 3 , · · · , p n−1 ). For that, we distribute p * to runnables in each path in proportion to their e i s as in Equation (30). It is also worth noting that even with the equilibrium state theorem, we cannot find the real optimal solutions since we lose the optimality while distributing p * with a heuristic. Nevertheless, we can find high-quality solutions close to the real optimal runnable periods. Interested readers are referred to our previous work [27].

Generalized Analytical Method for Directed Acyclic Graphs
This section generalizes the previously explained methods for the LPG model and the LMG model to the general DAG model. Both methods are not usable for a general DAG-based application for their limited applicability. In particular, since our method for the LMG model assumes that there is no such runnable that belongs to different paths at the same time, it is not applicable to DAGs with at least one such runnable. If we forcibly try it, Equation (30) may yield two different, hence, conflicting results for such runnables. Thus, we need a separate method for the DAG model.

DAG Model and Its Challenge
The DAG model is already explained in Section 3.1. Hence this subsection just highlights how it is different from the LPG model and the LMG model and presents a challenge that does not exist in the previous models. As noted earlier, there is only one path in the LPG model, making it easy to define the system's end-to-end delay. In the LMG model, even though there are multiple paths, we can use the equilibrium state theorem to simply represent them together by their identical path length in the middle part, denoted by p * . Figure 7a shows a simple DAG that is not an LPG nor an LMG. In the figure, note that r 4 belongs to the following two different paths: < r 1 , r 2 , r 4 , r 7 > and < r 1 , r 4 , r 7 >. As a runnable period cannot be zero, the former is always longer than the latter. Thus, unlike the LMG model where we can always make an equilibrium state, we cannot always make an equilibrium state in the DAG model.

Transformation of Control Cost Function
With the above challenge, let us transform the control cost function to a function of runnable periods. For the period T, we can use the same method as for the LPG model and the LMG model since it is only concerned with the actuator runnable r n . Thus, T is transformed into as follows: Unfortunately, however, when transforming the end-to-end delay ∆, we cannot simply reuse the method for the LMG model in Section 5.2 since we cannot be sure that an equilibrium state can be made. To handle this challenge, let us begin with the general definition of ∆ as in the following, assuming m paths {P 1 , P 2 , · · · , P m }: For example, in Figure 7a, there are four paths, P 1 =< 1, 2, 3, 7 >, P 2 =< 1, 2, 4, 7 >, P 3 =< 1, 4, 7 >, and P 4 =< 1, 5, 6, 7 >. Among them, it is apparent that P 3 cannot be the critical path since it is always shorter than P 2 . However, among P 1 , P 2 , and P 4 , we cannot be sure which is the longest since all of them can be the critical path according to how we decide p i s.
To overcome this challenge, we propose to employ a heuristic with a clear rule regarding which path should be the critical path. For that, with given e i s, we employ a heuristic described by the following: Certainly, the most important benefit from making p i s simply proportional to e i s is that we can simply decide the critical path based on the path weights (See Definition 3) such that we can choose the heaviest path (See Definition 5) as the critical path. For example, in Figure 7a, the weights of paths, P 1 to P 4 , are calculated as 15, 17, 13, and 10, respectively. Then, P 2 , specified by the red color, turns out to be the heaviest path. By the heuristic, it is used as the critical path. The intuition behind this heuristic is that we give longer periods to runnables with longer execution times to evenly distribute the system utilization across runnables, eliminating possible bottlenecks. Note that p 1 and p n are excluded in Equation (45) as they have no effect on deciding the critical path. For further explanations, we introduce a new notation r c , which is defined as the set of runnables in the critical path excluding r 1 and r n . Figure 7b shows r c = {r 2 , r 4 }. Then, let us think as if r c is a virtual composite runnable combining its member runnables just like the ellipse covering r 2 and r 4 in the figure. Then, the critical path can be thought of as a three-runnable ordered set < r 1 , r c , r n >. For r c , let us also define e c and p c as in the followings: and Based on the above notations, ∆ can be defined as follows: which makes the control cost function as follows with Equation (43): Then, regarding how to derive p 2 , p 3 , · · · , and p n−1 from p c , we use the following assignment rule following Equation (45): Under the above assignment rule, the followings are ensured: • p i s are always proportional to e i s; • The length of the critical path excluding r 1 and r n is equal to p c ; • The length of any other path is always shorter than p c .
As an example, in Figure 7b, we can find that e c = e 2 + e 4 = 12 and p c = p 2 + p 4 . Once p c is decided, each p i can be derived as in the followings according to Equation (50):

Transformation of Schedulability Constraint Function
The schedulability constraint in Equation (11) uses a function of n runnable periods. Thus, it is transformed into a function of the three free variables (p 1 , p c , p n ), following the rule in Equation (50) as follows: Now, the utilization function U(p 1 , p 2 , · · · , p n ) can be replaced by a function of (p 1 , p c , p n ) as in the following: U(p 1 , p c , p n ) = e 1 p 1 + (n − 2) e c p c + e n p n . (53)

Finding the Optimal Runnable Periods
Based on the control cost function in Equation (49) and the utilization function in Equation (53), our runnable periods optimization problem for the DAG model can be formulated with the three free variables (p 1 , p c , p n ) as follows: To solve the optimization problem, a Lagrange function is formulated as follows: Then, we take the partial derivatives of L with respect to p 1 , p c , p n , and λ, respectively and set them to zeros as follows: which in turn is expanded to the followings: Then, the first, second, and third of Equation (57) are rearranged by isolating λ in each left-hand side as follows: Then, by combining the first and second of Equation (58), we have the following: By combining the first and third of Equation (58), we have the following: By replacing 1 p c and 1 p n in the last of Equation (57) with the findings in Equations (59) and (60), we have the following: Finally, from Equations (59)-(61), we have the following solution: After finding the optimal (p 1 , p c , p n ), the remaining runnable periods (p 2 , p 3 , · · · , p n−1 ) should be decided, too. For that, the assignment rule in Equation (50) is used.

Applying Our Method to Other Scheduling Algorithms
Thus far, we assumed the EDF scheduling algorithm for the underlying RTOS scheduling. However, other scheduling algorithms such as RM are also widely used in the automotive industry.
With this motivation, this subsection explains how we can apply our method to different scheduling algorithms. Fortunately, most real-time scheduling algorithms provide a schedulability analysis method based on the L&L utilization bound, where if the system utilization is less than or equal to a specific threshold value called a utilization bound, denoted by U B , the system is guaranteed to be schedulable. As noted earlier, U B for EDF is 100%, whereas U B for RM is 69.3%. Then, the schedulability condition is formally expressed as follows: Then, our optimization problem is slightly changed from Equation (54) to the following using U B in the schedulability constraint: Then, its Lagrange function is also modified as follows: Solving the above Lagrange function yields the following solution: From the above, (p 2 , p 3 , · · · , p n−1 ) are decided by the assignment rule in Equation (50). Note that we can apply our method to any scheduling algorithm whose schedulability analysis can be conducted by the L&L utilization bound method.

Algorithm
Algorithm 1 shows a complete procedure for finding optimal runnable periods for a given DAG by our analytical method. As inputs, the algorithm accepts (i) a list of worst-case execution times for n runnables, (ii) a list of m paths in the DAG, (iii) α and β of a given control cost function, and (iv) a utilization bound U B . The algorithm just needs a list of paths instead of the entire structure of the DAG. Thus, the algorithm itself does not consider generating paths from a DAG. As an output, the algorithm returns a list of optimal runnable periods. Note that the algorithm's computational complexity is just O(n × m), which is caused when finding the heaviest path in line 3. This polynomial time complexity makes our analytical method practical for use with large systems.

Evaluation
This section specifically evaluates our optimization method for the general DAG model. Readers interested in the evaluation results for the LPG and LMG models are referred to [27]. More specifically, we evaluate our optimization method by answering the following questions: • Q1: Is our analytical method able to find near-optimal runnable periods? • Q2: Is it practical to find real optimal solutions by the exhaustive search method? • Q3: Is our method practically competitive when optimizing large systems?

Evaluation Method
For the evaluation, we have to consider the following: (i) workload synthesis, (ii) control cost functions, (iii) optimization algorithms, and (iv) performance metrics. In the remainder of this subsection, the above topics are discussed to explain our evaluation method.
Workload synthesis. As representative AUTOSAR workloads, a total of nine DAGs are artificially synthesized. Among them, the first six DAGs in Figure 8 are relatively small ones with four to six runnables, whereas the remaining three DAGs in Figure 9 are with a relatively large number of runnables ranging from 12 to 25. Note that the DAGs are manually generated, however, understand that the resulting DAGs are purely random without any unfair bias. The small DAGs are used to test the optimality of our method since we can find the real optimal solutions for those small DAGs in Figure 8. On the other hand, we cannot find the real optimal solutions for the large DAGs in Figure 9 due to the vast problem space. However, although we cannot evaluate the optimality of our method with the large DAGs, they are still useful when evaluating our method in comparison to other heuristic optimization methods. Each DAG in the figures is labeled by a notation (nR, mL) representing its size and complexity, where nR denotes n runnables and mL denotes m links (or edges) between them. Basically, with larger n and m, DAGs become more and more complex. For example, the DAG in Figure 8a is labeled by (4R, 5L), which has four runnables and five links, and the DAG in Figure 9c, labeled by (25R, 34L), has 25 runnables and 34 links. For each DAG, we generate 100 sets of random runnable execution times uniformly distributed in the range of [20 ms, 150 ms].
Control cost functions. As our optimization objective, we use a linear control cost function as in Equation (10), which is a function of the control period (T) and the end-to-end delay (∆). As a representative control cost function, we use the following as our default control cost function, unless otherwise stated: Note the above control cost function has two coefficients α = 0.01 and β = 0.01. Here, however, the relative ratio of α and β is more important than their absolute values since the ratio represents the control cost function's relative sensitivity to the control period and the end-to-end delay. By using the same values for α and β in our default control cost function, the control cost is equally sensitive to the control period and the end-to-end delay. To represent other scenarios with varying relative sensitivities, we also use varying αs and βs in the range of [0.01, 0.05].
Optimization algorithms. To evaluate the optimization performance of our method, for the comparison purpose, we specifically consider the following three optimization methods: • OUR: Near-optimal solutions found by our analytical optimization method; • EXH: Real optimal solutions found by the exhaustive combinatorial search method; • PSO: Solutions optimized by the particle swarm optimization (PSO) method [39].
More specifically, the EXH method searches through the discrete integer problem space within [1 ms, 1000 ms] for each runnable period. We compare our method with the EXH method to evaluate the optimality of our optimization method with small DAGs to answer the question Q1. To evaluate the optimization performance with large DAGs as an answer to the question Q3, we compare our method with the PSO method.
Performance metrics. We mainly use two optimization performance metrics: (i) absolute control costs and (ii) normalized control costs. Absolute control costs are the raw control cost values resulting from an optimization process, whereas normalized control costs are used to compare our method with another algorithm, i.e., the EXH method and the PSO method. A normalized control cost is defined as the relative ratio of our resulting control cost by letting another method's result as 100%. Besides, to evaluate the practicality of each optimization method, the optimization times are measured with respect to varying application complexities. For the optimization, we use a workstation with an Intel i7-9700k CPU with 64 GB RAM (Dell, Round Rock, TX, USA) r 21 r 23 r 24 r 7 r 6 r 5 (c) (25R, 34L) Figure 9. Large DAGs used for evaluating the practicality of our method.

Evaluation Results and Discussion
Q1: Is our analytical method able to find near-optimal runnable periods? For the six DAGs from Figure 8a-f, their normalized average control costs by the EXH method and our method are compared in Figure 10. In the figure, our method shows near-optimal control costs with marginal performance losses compared with the EXH method. The minimum control cost increase is just 1.1% and the maximum is 12.3%. One interesting point is that DAG (a) shows a significantly better performance than the other DAGs. That is because our heuristic for selecting the critical path is always valid in this particular DAG shape. Note that, in DAG (a), < r 1 , r 2 , r 3 , r 4 > will be correctly chosen as the critical path by our heuristic regardless of their execution times since every other path is a subset of it. On the other hand, in other DAGs, there are multiple choices for the critical path. Nonetheless, our method must bet on a certain path based on the given execution times. However, as shown in the figure, the performance losses from the real optimal solutions are marginal.
Thus far, we have assumed the EDF scheduling algorithm. However, in the automotive industry, the RM scheduling algorithm is also widely used for scheduling real-time tasks. In this regard, Figure 11 compares the EDF case where the utilization bound is 100% and the RM case where the utilization bound is 69.3%. More specifically, Figure 11a compares their normalized average control costs across the six DAGs, each of which represents the relative optimization performance compared with the EXH method. The figure shows that our method provides not much different optimization results across the two scheduling algorithms. Figure 11b compares their absolute average control costs where EDF shows a significantly lower average control cost since it can efficiently schedule workloads with its higher utilization bound.
To investigate how varying control cost functions affect the optimization performance, Figures 12a,b show normalized average control costs with varying αs and βs, respectively. As shown in the figures, our method provides a consistent optimization performance with varying control cost functions that represent various sensitivities to the control period and the end-to-end delay.       Q2: Is it practical to find real optimal solutions by the exhaustive search method? By looking at Q1's results, one can argue that if we can use the EXH method to find real optimal runnable periods, why not just use the EXH method instead of our method? However, this argument does not hold since the EXH method is not usable for large DAGs due to the vast search space when n > 6. To answer the question, we evaluate our optimization method in terms of the required time for the optimization process. Table 1 shows the required optimization times for our method and the EXH method with varying number of runnables. The numbers inside parentheses are projected numbers. As our method finds the runnable periods by an analytical method, it shows negligible computational complexities as predicted in Algorithm 1. With the EXH method, we can find optimal runnable periods in about one month when the numbers of runnables is seven. However, after seven runnables, it is not feasible to use the EXH method since it takes more than a year even for small and medium-size systems. Thus, due to the scalability problem, the EXH method cannot be used for practical industrial applications, whereas our analytical method can be used for large industry applications. Q3: Is our method practically competitive when optimizing large systems? From Q1 and Q2, we showed that (i) our analytical method works well with small systems and (ii) real optimal solutions cannot be found for large systems. One remaining question is whether we can apply our analytical method to large systems with sufficient optimization performance. To answer this question, we use the three large DAGs with n = 12, 16, and 25, as in Figure 9. For the comparison, we additionally use an evolutionary metaheuristic algorithm known as particle swarm optimization (denoted by PSO) that searches an unknown vast problem space efficiently with swarm intelligence. To implement the PSO method, we use the PySwarms library [40]. Figure 13 shows the normalized average control costs of our method compared with the PSO method, letting the resulting control costs by the PSO method as 100%. As shown in the figure, our method shows significantly better results than the PSO method, especially for the largest DAG case. We notice the decreasing trend of normalized average control costs with the increasing complexity of DAGs. With the above results, we can claim that our analytical method performs better than the traditional evolutionary optimization method.

Conclusions
This paper formulates a runnable periods optimization problem for AUTOSAR control applications and provides an analytical solution based on the Lagrange multiplier method. Our method can find near-optimal solutions that maximize a given system's control performance regardless of the size and complexity of the application. Since the complexity of automobile control applications is rapidly growing due to the recent development of various advanced driver assistance systems and autonomous driving applications, it is no longer feasible to use traditional ad-hoc methods or time-consuming search-based optimization algorithms. Due to the analytical nature of our proposed runnable periods optimization method, we consider that our solution can be readily used in the automotive industry when designing their complex industry-scale AUTOSAR control applications.
Although our method provides a promising solution for optimizing complex applications, our method is only usable when the control cost is given or approximated as a linear function. As the approximation can induce overestimated control costs, we plan to extend our optimization method to nonlinear control cost functions in our future work.

Conflicts of Interest:
The authors declare no conflicts of interest.

Abbreviations
The following abbreviations are used in this manuscript: