Worst-Case C Execution Time Analysis Jan Gustafsson, Docent Mälardalen Real-Time Research Center (MRTC) Västerås, Sweden jan.gustafsson@mdh.se 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 Period Response Time Execution Time ! What is the program ! What is the execution doing? time of the program? R i = C i + ∑ " R i / T j # C j ! Will it always do the ! Will it always take the same thing? same time to execute? j ∈ hp(i) ! How important is ! How important is the result? execution time? Where do these C values come from? 3 4 WCET - definition Program timing ! Worst-Case Execution Time = WCET ! Most computer programs have varying " The longest calculation time possible execution time " For one program/task when run in isolation " Due to input values " Other interesting measures: BCET, ACET " Due to software characteristics ! The goal of a WCET analysis is to derive " Due to hardware characteristics a safe upper bound on a program’s WCET ! Example: some timed program runs BCET WCET #program runs Most runs have Is this the longest similar execution time execution time... safe safe possible lower upper Some take much execution times ... or can we get timing timing longer time (why?) even longer ones? bounds bounds 0 time 0 execution time 5
Presentation outline ! Embedded system fundamentals Embedded ! WCET analysis systems " Measurements " Static analysis fundamentals " Flow analysis, low-level analysis, and calculation " Hybrid approaches ! WCET analysis tools ! The SWEET approach to WCET analysis ! (Multi-core + WCET analysis?) ! WCET analysis demo (SWEET) Embedded computers Embedded systems everywhere ! Today, all advanced ! An integrated part of a larger system products contain " Example 1: A microwave oven contains at least one embedded processor embedded computers! " Example 2: A modern car can contain more " Our society depends on than 100 embedded processors that they function correctly ! Interacts with the user, the environment, and with other computers " Often limited or no user interface " Often with timing constraints result input Embedded system hardware Embedded systems software ! Huge variety of embedded ! Amount of software can vary from 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, … ) ! The hardware is often tailored " Often limited resources (memory / speed) " 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
Real-time systems Some interesting figures ! Computer systems where the timely ! 4 billion embedded processors sold in 2008 behavior is a central part of the function " Global market worth € 60 billion " Predicted annual growth rate of 14% " Containing one or more embedded computers " Forecasts predict more than 40 billion embedded devices in 2020 " Both soft- and hard real-time, or a mixture … ! Embedded processors clearly dominate yearly production Timing of radio Timing of music communication, motor playing from MP3 file control, rudder and flaps control, … Timing of network communication, motor Timing of radio "Desktop" control, ABS brakes, "Embedded" communication, anti-slip control, … 2% speech 98% recognition, … Source: http://www.artemis-ju.eu/embedded_systems Timely Software - a Challenge 13 Uses of reliable WCET bounds ! Hard real-time systems " WCET needed to guarantee behavior WCET ! Real-time scheduling " Creating and verifying schedules analysis " Large part of RT research assume the existence of reliable WCET bounds ! Soft real-time systems " WCET useful for system understanding ! Program tuning " Critical loops and paths ! Interrupt latency checking Measuring for the WCET Obtaining WCET bounds ! Measurement ! Methodology: " Industrial practice " Determine ”worst-case input” or run as many inputs as possible " Execute and measure ! Static analysis the time " Add a safety margin " Research front 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 " Option 2: HW + SW methods combinations typically is huge. ! Add instrumentation code " For example: 10 variables of size 32 bits => number of necessary measurement runs = 4 294 967 295 10 ! Use oscilloscopes, logic analyzers, emulators 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 Using an oscilloscope SW measurement methods ! Operating system clocks ! Common equipment for HW debugging " Commands such as time time , date date and clock 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 time that the I/O pin is high observed for task 4. This is the time spent in the routine " Keep in shipping systems, read at service intervals 21 22 HW measurement tools Using a logic analyzer Target ! In-circuit emulators (ICE) ! Equipment designed for board troubleshooting digital " Special CPU version revealing internals hardware ! High visibility & bandwidth ! High cost + supportive HW required ! Have dozens or even HW Debugger ! Processors with debug support hundreds of inputs " Each one keeping track on " Designed into processor whether the electrical signal ! Use a few dedicated processor pins it is attached to is currently " Using standardized interfaces at logic level 1 or 0 " 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 " Common on modern chip input patterns 23 24
Fundamental problems when using measurements ! Measured time never exceeds WCET Static BCET WCET WCET safe safe possible lower upper execution times analysis timing timing bounds bounds time 0 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 ! Execution characteristics ! Do not run the program – analyze it! foo(x,i): while(i < 100) " Using models based on the static properties of the of the software software and the hardware if (x > 5) then " A program can often execute x = x * 2; ! Guaranteed safe WCET bounds in many different ways else " Provided all models, input data and analysis " Input data dependencies x = x+2; methods are correct end ! Trying to be as tight as possible " Application characteristics if (x < 0) then ! Timing characteristics b[i] = a[i]; BCET WCET end of the hardware All derived i = i+1; safe safe bounds will possible " Clock frequency end lower upper be ≥ WCET execution times timing timing " CPU characteristics bounds bounds " Memories used 0 time " … WCET analysis phases 1. Flow analysis program " Bound the number of times Flow different program parts may Flow be executed (mostly SW analysis) analysis Compiler analysis 2. Low-level analysis Low level Object " Bound the execution time analysis Code of different program parts (combined SW & HW analysis) Target Calculation 3. Calculation Hardware " Combine flow- and low-level analysis results to derive an Actual WCET WCET bound upper WCET bound Reality Analysis 30
Recommend
More recommend