<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Denver, CO, USA, October</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Improving Timing Analysis for Matlab Simulink/Stateflow</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Lili Tan</string-name>
          <email>lili@cs.uni-sb.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Bj¨orn Wachter</string-name>
          <email>bwachter@cs.uni-sb.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Philipp Lucas</string-name>
          <email>phlucas@cs.uni-sb.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Reinhard Wilhelm⋆</string-name>
          <email>wilhelm@cs.uni-sb.de</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Universit ̈at des Saarlandes</institution>
          ,
          <addr-line>Saarbru ̈cken</addr-line>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2009</year>
      </pub-date>
      <volume>6</volume>
      <issue>2009</issue>
      <fpage>59</fpage>
      <lpage>63</lpage>
      <abstract>
        <p>Control software in embedded hard real-time systems is subject to stringent timing constraints. To compute the required safe upper bounds on its worst-case execution-time (WCET), static timing analysis is used in industry [1]. Today control software is predominantly developed with model-based design tools such as Matlab Simulink/Stateflow. However, current timing tools lose precision as they consider infeasible executions, e.g., changes between operating modes not admissible in the model. These tools analyze compiled executables where information about the feasibility of executions is hard to derive. We propose systematic methods that make model information available to timing analysis and present promising results with Simulink/Stateflow models. Static Timing Analysis. Static timing analysis [2] uses abstract interpretation [3] to derive program properties that hold for all executions. A classical static analysis is interval analysis, which determines, for each variable, a range of values for each program point which contains all the values of the variable in any program execution. The ranges are guaranteed to be safe, i.e., they can be used to exclude division by zero and array-out-of-bounds accesses at compile time. More generally, static analysis computes provably safe approximations of program states. Static timing analysis determines execution time bounds for programs. These bounds must be safe, i.e., they must not underestimate the execution time. They should also be tight to avoid unnecessary safety margins. The established methodology splits the problem into different phases. The input to the analysis is a compiled executable of the program. The first phase reconstructs from the executable a control-flow graph (CFG) over basic blocks. In the next phase, a variation of interval analysis, called value analysis, determines the contents of registers and memory locations. Then a micro-architectural analysis computes execution-time bounds for basic blocks. It accounts for the tremendous hardware-induced execution-time variability: depending on whether a memory access causes a cache hit or a cache miss, the execution time of an instruction may differ by two orders of magnitude. Therefore complex, processorspecific architectural features like cache and pipeline effects are considered [4]. In the final phase, path analysis determines a safe estimate of the WCET. First an ⋆ Supported by ITEA 2 project 06042, EU-FP7 Grant 216008 and SFB/TR 14.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>ILP generator models the control flow the program as an integer linear program.
Each ILP variable corresponds to the traversal count of a basic block. The value
of the objective function in the solution is the predicted execution time bound.</p>
      <p>The CFG also describes infeasible program executions if conditions are not
interpreted. Consider the C code if(a&gt;0) x=1; else x=2; if(a==0) a=x;.
Conditions a&gt;0 and a==0 are clearly correlated, more specifically, they
mutually exclude each other. Although the control-flow graph contains the path from
x=1 to a=x, this is not a feasible program execution. In general, we call a
controlflow path an infeasible path if it does not correspond to any program execution
(this notion is distinct from dead code).</p>
      <p>To make path analysis more precise, so-called flow constraints can be added
to the ILP that eliminate infeasible paths. A salient point of our work is that
such constraints can be systematically derived from model information.
Matlab Models and Generated Code. Matlab Simulink/Stateflow is a hierarchical
modeling language for control software with a sequential, imperative semantics.
The underlying methodology is to design control computation within Simulink
and control logic within Stateflow. Simulink offers building blocks for
proportional, integral and differential (PID) control computations and estimations,
e.g., filters, look-up tables, and arithmetic operators. Stateflow is an automata
specification language that can be used to express transitions between different
operating modes of the system. Blocks communicate with each other via signals
and receive external inputs from the environment.</p>
      <p>For deployment, code generators synthesize production C code, in which the
internal states of Stateflow and Simulink blocks are encoded by state variables.
Signals and internal inputs also map to C variables. The implementation of
blocks can be traced in the source code. However this mapping depends on
characteristics of different code generators.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Model-aware Timing Analysis</title>
      <p>In real-time systems, the different tasks run periodically and are triggered by a
scheduler. These tasks are commonly implemented with model-based tools like
Matlab. A periodic run corresponds to one execution of the Matlab model where
inputs are received, the internal state is updated, and outputs are produced.
Timing analysis has to determine an execution time bound that is safe for each
run. It is impossible in practice to know the worst-case inputs or the worst-case
internal state, hence the analysis has to cover all possibilities for each run.</p>
      <p>To ensure safety, the analysis must not assume that the value of an external
input variable remains constant between definition and use, i.e., the variable is
‘volatile’ in C terminology. For the internal state, timing analysis has to assume
all possibilities at task entry, i.e., for a state variable, assume all potential states.
Thus, both input and state must be treated specially to obtain a safe execution
time bound. In Matlab-generated code, input and state variables can be identified
syntactically. This enables an automatic solution that guarantees safe bounds.</p>
      <p>In the remainder of the section, our goal is to make these bounds tighter.</p>
      <p>We investigate where precision is lost due to infeasible paths. To this end,
we focus on typical patterns at the level of the model that lead to infeasible
paths. As a running example, we consider the fuel-rate controller which is a
Matlab demo model that contains typical features of embedded controllers. The
controller estimates airflow rate, and calculates the fuel injection rate based on
PID control principle.</p>
      <p>
        We analyzed the controller with aiT WCET Analyzer, the static timing
analysis tool [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ] of AbsInt [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]. aiT produces a worst-case path to explain the execution
time bound it has computed. Without providing flow constraints, the execution
time is over-approximated and the computed worst-case path is infeasible, since
static timing analysis is not aware of certain dependencies in the model.
      </p>
      <p>For example, like any control software, the fuel-rate controller has
operating modes and signals that conditionally exclude each other. Depending on the
current mode, signals, and their logical combinations, different look-up tables
or computations are triggered. As discussed in the introduction, the timing
analyzer generally does not interpret conditions. Hence it has to take the longer
branch of a conditional, even if execution history of the path does not admit so.
As a result, the worst-case path spuriously ‘switches’ between operating modes.</p>
      <p>For illustration, we consider such spurious resolutions of conditions on the
worst-case path. Some resemble the infeasible-path example in the introduction,
e.g., they involve conditions like mode==LOW and mode==RICH. Other conditions
are more involved. For example, condition O2_fail==0 &amp;&amp; mode==LOW checks
if the oxygen sensor is valid and the system is in operating mode LOW, while
condition pressure_fail==1 checks if the pressure sensor has failed. These
conditions do not have shared variables, and, simply by looking at the expressions,
they seem not to be related. Yet there is a relation entailed by the model: the
conditions are, in fact, mutually exclusive. The conditions are used in a Simulink
block, while the variables mode, O2_fail, pressure_fail are set by a Stateflow
automaton. However, the Stateflow automaton would not set mode to LOW if any
sensor had sent a failure signal. Such entailed relations need to be derived by
analyzing the model semantics. In the source code or executable, dependencies
are more implicit and even harder to track than in the model. In the following,
we show how to construct flow constraints from the model to achieve a more
precise timing analysis.</p>
      <p>Trigger Conditions. We aim at conditions that determine whether a piece of the
model is executed. These conditions on external inputs, internal signals (e.g.,
mode variables), and states guard signal transformation and control
computation. Simulink/Stateflow express this by conditional blocks, similar to
conditionals in C, e.g., triggered and enabled subsystems, guarded transitions in Stateflow
and switch-blocks. We uniformly refer to the conditions as trigger conditions.
Flow Constraints from Definition-Use Dependencies. We formulate flow
constraints that relate a definition, e.g., a mode variable, and uses of that variable.
Certain definitions always make a trigger condition false. Trivially, a program
execution cannot pass through such a condition and the branch guarded by the
trigger condition. This can be expressed by flow constraints. One example for
such constraints in the fuel-rate controller are signals that indicate a failure of
a sensor. These signals are set in a Stateflow block and are used in a Simulink
block to trigger the evaluation of a lookup table.</p>
      <p>Flow Constraints from Correlations between Trigger Conditions. Relations
between trigger conditions can be formulated as flow constraints, e.g., independent,
equivalence, implication, antivalence, and exhaustion can be expressed. To be
effective, entailed relations need to be considered. The analysis of entailed relations
requires information about deep semantic properties of Stateflow and Simulink
blocks. To this end, we anticipate that relational abstract domains from static
analysis may be helpful.</p>
      <p>Other relations could be derived purely from Simulink. This includes the
common case of a choice between two implementations of an algorithm with
directly inverse trigger conditions.</p>
      <p>Significant Branches. Eliminating infeasible paths does not per se improve
precision. For example, if branches of conditionals have approximately the same
execution time, there can be little gain in precision. Therefore, we focus on
significant unbalanced branches when giving flow constraints. In our running
examples, the invocations of look-up tables and mode-dependent discrete filters
give rise to such branches.</p>
      <p>Relative to Stateflow, the Simulink blocks typically dominate the execution
time, while Stateflow blocks themselves contribute little to the overall execution
time. This is because control logic computations consist of conditionals and
assignments, while the expensive computations are often in the Simulink part,
e.g., lookup tables and discrete filters for estimation and PID control. Thus
determination of infeasible paths pays off more in the Simulink part than in
Stateflow.</p>
      <p>Experimental Results. We used aiT for our experiments. For the fuel-rate
controller, we have manually applied the described derivation method for flow
constraints. Flow constraints from definition-use dependencies alone reduced the
execution time bound by 4%. Adding both kinds of flow constraints yields an overall
reduction by 19% and a feasible worst-case path. If we compute an
executiontime bound for each operating mode, we achieve a reduction from 20% to 48%
per operating mode.
3</p>
    </sec>
    <sec id="sec-3">
      <title>Related Work</title>
      <p>
        Previous work on flow constraints focused on the executable [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], or C level. In [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ],
the authors consider timing analysis of code synthesized from Esterel. They
identify flow constraints to eliminate feasible paths. The principal ideas concerning
the two kinds of flow constraints are related, however Esterel is significantly
different from Matlab Simulink, e.g., Esterel does not have automata as a language
feature. Hence rules to derive flow constraints differ significantly.
[
        <xref ref-type="bibr" rid="ref8">8</xref>
        ] describes early work on timing analysis for Simulink models without
Stateflow. Model information like loop bounds is passed to the underlying timing
analysis tool. They modified the code generator and used their own (uncertified)
compiler. Their timing analysis tool lacks value analysis [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ] and thus does not
discover loop bounds which aiT derives from the executable alone. Integrations
of aiT with ASCET and SCADE are described in [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ] and [
        <xref ref-type="bibr" rid="ref11">11</xref>
        ]. They pass model
information to aiT, e.g., variable ranges and loop bounds. Unlike this paper, [
        <xref ref-type="bibr" rid="ref10 ref11 ref8">8,
10, 11</xref>
        ] mainly focus on other aspects than precision.
4
      </p>
    </sec>
    <sec id="sec-4">
      <title>Conclusion</title>
      <p>Initial results the benefit of model information in terms of automation and
precision of WCET analysis. We propose model-based generation of flow constraints
and have evaluated our method using the industrial tool aiT. Initial results with
the fuel-rate controller are promising. While definition-use flow constraints are
relatively easy to apply, relations between trigger conditions are more difficult
to automate due to entailed relations. In future work, we will automate the
generation of flow constraints and apply our approach to industrial examples.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Thesing</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Souyris</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Heckmann</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Randimbivololona</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Langenbach</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wilhelm</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ferdinand</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          :
          <article-title>An Abstract Interpretation-Based Timing Validation of Hard Real-Time Avionics Software Systems</article-title>
          .
          <source>In: Proceedings of DSN</source>
          . (
          <year>2003</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Ferdinand</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Heckmann</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Langenbach</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Martin</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schmidt</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Theiling</surname>
            ,
            <given-names>H.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Thesing</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wilhelm</surname>
          </string-name>
          , R.:
          <article-title>Reliable and precise WCET determination for a real-life processor</article-title>
          .
          <source>In: EMSOFT. Volume 2211 of LNCS</source>
          . (
          <year>2001</year>
          )
          <fpage>469</fpage>
          -
          <lpage>485</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Cousot</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Cousot</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          :
          <article-title>Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints</article-title>
          .
          <source>In: POPL77</source>
          , Los Angeles, California (
          <year>1977</year>
          )
          <fpage>238</fpage>
          -
          <lpage>252</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Heckmann</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Langenbach</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Thesing</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wilhelm</surname>
            ,
            <given-names>R.:</given-names>
          </string-name>
          <article-title>The influence of processor architecture on the design and the results of WCET tools</article-title>
          .
          <source>Proceedings of the IEEE</source>
          <volume>91</volume>
          (
          <year>2003</year>
          )
          <fpage>1038</fpage>
          -
          <lpage>1054</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>5. AbsInt Angewandte Informatik GmbH: http://www.absint.com/</mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <surname>Stein</surname>
            ,
            <given-names>I.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Martin</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Analysis of path exclusion at the machine code level</article-title>
          .
          <source>In: Proceedings of WCET</source>
          . (
          <year>2007</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Ju</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Huynh</surname>
            ,
            <given-names>B.K.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Roychoudhury</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Chakraborty</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          :
          <article-title>Performance debugging of Esterel specifications</article-title>
          .
          <source>In: CODES+ISSS</source>
          . (
          <year>2008</year>
          )
          <fpage>173</fpage>
          -
          <lpage>178</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Kirner</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lang</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Freiberger</surname>
            ,
            <given-names>G.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Puschner</surname>
            ,
            <given-names>P.</given-names>
          </string-name>
          :
          <article-title>Fully automatic worst-case execution time analysis for Matlab/Simulink models</article-title>
          .
          <source>In: ECRTS</source>
          . (
          <year>2002</year>
          )
          <fpage>31</fpage>
          -
          <lpage>40</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          9.
          <string-name>
            <surname>Tan</surname>
            ,
            <given-names>L.</given-names>
          </string-name>
          :
          <article-title>The worst-case execution time tool challenge 2006</article-title>
          .
          <source>International Journal on Software Tools for Technology Transfer (STTT) 11</source>
          (
          <year>2009</year>
          )
          <fpage>133</fpage>
          -
          <lpage>152</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          10.
          <string-name>
            <surname>Ferdinand</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Heckmann</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wolff</surname>
            ,
            <given-names>H.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Renz</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Parshin</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Wilhelm</surname>
          </string-name>
          , R.:
          <article-title>Towards model-driven development of hard real-time systems</article-title>
          .
          <source>In: Proceedings of ASWSD</source>
          . (
          <year>2006</year>
          )
          <fpage>145</fpage>
          -
          <lpage>160</lpage>
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          11.
          <string-name>
            <surname>Ferdinand</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Heckmann</surname>
            ,
            <given-names>R.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Sergent</surname>
            ,
            <given-names>T.L.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Lopes</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Martin</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Fornari</surname>
            ,
            <given-names>X.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Martin</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>Combining a high-level design tool for safety-critical systems with a tool for WCET analysis on executables</article-title>
          .
          <source>In: Proceedings of ERTS</source>
          . (
          <year>2008</year>
          )
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>