c
play

C Execution Time Analysis ! Jan Gustafsson, Docent Mlardalen - PDF document

Worst-Case C Execution Time Analysis ! Jan Gustafsson, Docent Mlardalen Real-Time Research Center (MRTC) Vsters, Sweden andreas.ermedahl@mdh.se 2 What C are we talking about? Program timing is not trivial! ! A key component in the


  1. Worst-Case C Execution Time Analysis ! Jan Gustafsson, Docent Mälardalen Real-Time Research Center (MRTC) Västerås, Sweden andreas.ermedahl@mdh.se 2 What C are we talking about? Program timing is not trivial! ! A key component in the analysis of int f(int x) { 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? 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 and WCET analysis Program timing basics ! 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 time 0 execution time 0 5

  2. 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 assignment Embedded computers Embedded systems everywhere ! Today, all advanced ! An integrated part of a larger system products contain " Example: A microwave oven contain at least one embedded processor embedded computers! " Example: A modern car can contain more " Our society is dependant 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 input result Embedded system hardware Embedded systems software ! 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, … ) ! 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

  3. 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 control, ABS brakes, "Desktop" "Embedded" communication, anti-slip control, … speech 2% 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 potential ”worst-case input” " Run and measure " Add a safety margin ! Static analysis " Research front 18

  4. Measurement issues SW measurement methods ! Operating system facilities ! Large number of potential worst-case inputs " Commands such as time time , date date and clock clock " Program state might be part of input " Note that all OS-based solutions require precise HW timing facilities (and an OS) ! Has the worst-case path really been taken? ! Cycle-level simulators " Often many possible paths through a program " Hardware features may interact in unexpected ways " Software simulating CPU " Correctness vs. hardware? ! How to monitor the execution? ! High-water marking Buzzer " The instrumentation " Keep system running may affect the timing " Record maximum time " How much instrumention observed for task output can be handled? " Keep in shipping systems, read at service intervals LEDs 19 20 Using an oscilloscope Using a logic analyzer ! Equipment designed for ! Common equipment for HW debugging troubleshooting digital " Used to examine electrical output signals of HW hardware ! Observes the voltage or signal ! Have dozens or even waveform on a particular pin hundreds of inputs " Usually only two to four inputs " Each one keeping track on whether the electrical signal ! To measure time spent in a routine: it is attached to is currently 1. Set I/O pin high when entering routine at logic level 1 or 0 2. Set the same I/O pin low before exiting " Result can be displayed 3. Oscilloscope measures the amount of against a timeline time that the I/O pin is high " Can be programmed to start 4. This is the time spent in the routine capturing data at particular input patterns 21 22 HW measurement tools Problem of using measurement Target ! In-circuit emulators (ICE) board ! Measured time never exceeds WCET " Special CPU version revealing internals BCET WCET ! High visibility & bandwidth ! High cost + supportive HW required safe safe HW Debugger possible ! Processors with debug support lower upper execution times timing timing " Designed into processor bounds bounds ! Use a few dedicated processor pins 0 time " Using standardized interfaces Measurement will result Only this measurement ! Nexus debug interfaces, JTAG, in a value ≤ WCET is safe (= WCET)! Embedded Trace Macrocell, … How do we know that we catched " Supportive SW & HW required the WCET? " Common on modern chip " A safety margin must be added, but how much is enough? 23

  5. Static WCET analysis ! Do not run the program – analyze it! Static " Using models based on the static properties of the software and the hardware WCET ! Guaranteed safe WCET bounds " Provided all models, input data and analysis methods are correct analysis ! Trying to be as tight as possible BCET WCET All derived safe safe bounds will possible lower upper be ≥ WCET execution times timing timing bounds bounds 0 time Again: Causes of WCET analysis phases Execution Time Variation 1. Flow analysis ! Execution characteristics foo(x,i): program " " Bound the number of times of the software while(i < 100) if (x > 5) then different program parts may " A program can often execute Flow " x = x * 2; be executed (mostly SW analysis) analysis " in many different ways else Compiler " 2. Low-level analysis " Input data dependencies x = x+2; end Low level " " Application characteristics Object 
 " Bound the execution time analysis " Code " if (x < 0) then of different program parts ! Timing characteristics b[i] = a[i]; (combined SW & HW analysis) end of the hardware Target " Calculation " 3. Calculation i = i+1; Hardware " " Clock frequency end " Combine flow- and low-level " CPU characteristics analysis results to derive an Actual 
 WCET 
 " Memories used WCET " bound " upper WCET bound Reality " Analysis " " … Flow Analysis ! Provides bounds on the number Program Flow of times different program parts may be executed Flow analysis analysis " Valid for all possible executions ! Examples of provided info: Low level " Bounds of loop iterations analysis " Bounds on recursion depth " Infeasible paths Calculation ! Info provided by: " Static program analysis WCET Estimate " Manual annotations 29 30

Recommend


More recommend