
Worst-Case Execution Time C Analysis Jan Gustafsson, Docent Mälardalen Real-Time Research Center (MRTC) Västerås, Sweden [email protected] 2 What C are we talking about? Program timing is not trivial! ! ”Computation time” - a key component int f(int x) { in the analysis of real-time systems return 2 * x; ! You have seen it in formulas such as: } Simpler questions Harder questions Worst-Case Worst-Case Response Time Period Execution Time ! What is the program ! What is the execution doing? time of the program? ! Will it always do the ! Will it always take the Ri = Ci + ∑ "Ri / Tj# Cj same thing? same time to execute? j∈hp(i) ! How important is ! How important is Where do these C values come from? the result? execution time? 3 4 Program timing WCET - definition ! Most computer programs have varying ! Worst-Case Execution Time = WCET execution time " The longest calculation time possible " For one program/task when run in isolation " Due to input values " Other interesting measures: BCET, ACET " Due to software characteristics " Due to hardware characteristics ! The goal of a WCET analysis is to derive ! Example: some timed program runs a safe upper bound on a program’s WCET BCET WCET Most runs have Is this the longest similar execution time execution time... safe safe possible lower upper Some take much ... or can we get execution times longer time (why?) timing timing #program runs #programruns even longer ones? bounds bounds 0 time 0 execution time 5 Presentation outline ! Embedded system fundamentals ! WCET analysis Embedded " Measurements " Static analysis systems " Flow analysis, low-level analysis, and calculation " Hybrid approaches fundamentals ! WCET analysis tools ! The SWEET approach to WCET analysis ! (Multi-core + WCET analysis?) ! WCET analysis demo (SWEET) Embedded computers Embedded systems everywhere ! An integrated part of a larger system ! Today, all advanced " Example 1: A microwave oven contains at products contain least one embedded processor embedded computers! " Example 2: A modern car can contain more than 100 embedded processors " Our society depends on that they function correctly ! Interacts with the user, the environment, and with other computers " Often limited or no user interface " Often with timing constraints input result Embedded systems software Embedded system hardware ! Amount of software can vary from ! Huge variety of embedded extremely small to very large system processors " Gives characteristics to the product " Not just one main processor type as for PCs ! Often developed with target " Additionally, same CPU can be used with various hardware in mind hardware configurations (memories, devices, …) " Often limited resources (memory / speed) ! The hardware is often tailored " Often direct accesses to different HW devices specifically to the application " Not always easily portable to other HW " E.g., using a DSP processor for signal ! Many different programming languages processing in a mobile telephone " C still dominates, but often special purpose languages ! Cross-platform development ! Many different software development tools " E.g., develop on PC and download " Not just GCC and/or Microsoft Visual Studio final application to target HW 11 Some interesting figures Real-time systems ! 4 billion embedded processors sold in 2008 ! Computer systems where the timely " Global market worth €60 billion behavior is a central part of the function " Predicted annual growth rate of 14% " Forecasts predict more than 40 billion embedded devices in 2020 " Containing one or more embedded computers ! Embedded processors clearly dominate yearly " Both soft- and hard real-time, or a mixture… Timing of radio Timing of music production communication, motor playing from MP3 file control, rudder and flaps control,… Timing of network communication, motor Timing of radio control, ABS brakes, "Desktop" communication, "Embedded" anti-slip control,… 2% speech 98% recognition,… Source: http://www.artemis-ju.eu/embedded_systemsTimely Software - a Challenge 13 Uses of reliable WCET bounds ! Hard real-time systems " WCET needed to guarantee behavior ! Real-time scheduling " Creating and verifying schedules WCET " Large part of RT research assume the existence of reliable WCET bounds analysis ! Soft real-time systems " WCET useful for system understanding ! Program tuning " Critical loops and paths ! Interrupt latency checking Obtaining WCET bounds Measuring for the WCET !Measurement !Methodology: " Industrial practice " Determine ”worst-case input” or run as many inputs as possible " Execute and measure !Static analysis the time " Research front " Add a safety margin 18 Measurement issues 1 Measurement issues 2 ! What is the worst-case input? ! How to measure the execution time? " In general, the problem of determining the worst case input " Option 1: SW methods value combination to an arbitrary program is very hard. ! Operating system clocks ! Alternative: run all inputs? ! Simulators ! High-water marking " Typically not possible, since the number of input combinations typically is huge. " Option 2: HW + SW methods " For example: 10 variables of size 32 bits => number of ! Add instrumentation code 10 ! Use oscilloscopes, logic analyzers, emulators necessary measurement runs = 4 294 967 295 Buzzer logic analyzers or debug support " Also keep in mind that the program state is a part of the input ! The instrumentation may affect the ! In practice: run as many inputs as possible timing ! Instrumentation code is often left in " There are some ideas how to test extreme cases and corners shipped code " Has the worst-case path really been taken? No guarantee! ! How much instrumention output can be handled? LEDs 19 20 SW measurement methods Using an oscilloscope ! Operating system clocks ! Common equipment for HW debugging " Commands such as time, date and clock " Used to examine electrical output " Note that all OS-based solutions require signals of HW precise HW timing facilities (and an OS) ! Observes the voltage or signal ! Cycle-level simulators waveform on a particular pin " Software simulating CPU " Usually only two to four inputs " Correctness vs. hardware? ! To measure time spent in a routine: ! High-water marking 1. Set I/O pin high when entering routine " Keep system running 2. Set the same I/O pin low before exiting " Record maximum time 3. Oscilloscope measures the amount of observed for task time that the I/O pin is high 4. This is the time spent in the routine " Keep in shipping systems, read at service intervals 21 22 Using a logic analyzer HW measurement tools Target ! Equipment designed for ! In-circuit emulators (ICE) board troubleshooting digital " Special CPU version revealing internals hardware ! High visibility & bandwidth ! High cost + supportive HW required ! Have dozens or even HW Debugger hundreds of inputs ! Processors with debug support " Each one keeping track on " Designed into processor whether the electrical signal ! Use a few dedicated processor pins it is attached to is currently at logic level 1 or 0 " Using standardized interfaces " Result can be displayed ! Nexus debug interfaces, JTAG, against a timeline Embedded Trace Macrocell, … " Can be programmed to start " Supportive SW & HW required capturing data at particular input patterns " Common on modern chip 23 24 Fundamental problems when using measurements ! Measured time never exceeds WCET BCET WCET Static safe safe possible lower upper execution times WCET timing timing bounds bounds 0 time analysis Measurement will result Only this measurement in a value ≤ WCET is safe (= WCET)! How do we know that we catched the WCET? " A safety margin must be added, but how much is enough? Again: Causes of Static WCET analysis Execution Time Variation ! Do not run the program – analyze it! ! Execution characteristics foo(x,i): " Using models based on the static properties of the of the software while(i < 100) software and the hardware if (x > 5) then " A program can often execute ! Guaranteed safe WCET bounds x = x*2; in many different ways else " Provided all models, input data and analysis methods are correct " Input data dependencies x = x+2; end " Application characteristics ! Trying to be as tight as possible if (x < 0) then BCET WCET ! Timing characteristics b[i] = a[i]; end All derived of the hardware safe i = i+1; possible safe bounds will lower " Clock frequency end execution times upper be ≥ WCET timing timing " CPU characteristics bounds bounds " Memories used 0 time " … WCET analysis phases program 1. Flow analysis " Bound the number of times Flow different program parts may analysis be executed (mostly SW analysis) Compiler Flow 2. Low-level analysis Object Low level Code analysis " Bound the execution time of different program parts analysis (combined SW & HW analysis) Target Calculation Hardware 3. Calculation " Combine flow- and low-level Actual WCET analysis results to derive an WCET bound upper WCET bound Reality Analysis 30 Flow Analysis The control-flow graph foo() Program ! Provides bounds on the number foo(x,i): A: while(i < 100) of times different program parts A B: if (x > 5) then Each block Flow may be executed will run as a analysis " Valid for all possible executions C: x = x*2; B unit else ! Examples of provided info: Low level D: x = x+2; C D " Bounds of loop iterations analysis end " Bounds on recursion depth E: if (x < 0) then E Flows as " Infeasible paths edges Calculation F: b[i] = a[i]; F ! Info provided by: end " Static program analysis G: i = i+1; WCET G Estimate " Manual annotations end end 31 Flow
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages19 Page
-
File Size-