230 likes | 355 Views
Con straint Systems used in Worst-Case Execution Time Analysis. Andreas Ermedahl andreas.ermedahl @ it .uu.se Dept. of Information Tech nology Uppsala University. Definition of WCET. actual BCET. actual WCET. possible execution times. safe BCET estimates. safe WCET estimates. 0.
E N D
Constraint Systems used in Worst-Case Execution Time Analysis Andreas Ermedahl andreas.ermedahl@it.uu.se Dept. of Information Technology Uppsala University
Definition of WCET actual BCET actual WCET possible execution times safe BCET estimates safe WCET estimates 0 tighter tighter • WCET = Worst possible execution time for a program running on target hardware • One program in isolation • No interrupts or context switches • Other estimates: • Best Case ET = Best case, Inverse of WCET, hard • Average Case ET = Soft real-time, not hard ASTEC/WCET
? Uses of WCET Estimates • Hard real-time systems • Scheduling • Schedulability analysis • System dimensioning • Formal verification • Program performancetuning void foo(int j, int a[]) { int i; for(i=100, i>0; i--) { if(j>50) a[i] = 2 * i; else a[i] = i; } } ASTEC/WCET
Static WCET Analysis • Don’t run the program - analyze it! • Guaranteed safe WCET • Trying to be as tight as possible • Provided all input is correct actual BCET actual WCET possible execution times safe BCET estimates safe WCET estimates 0 tighter tighter Measurement will give results in the unsafe area Static analysis will give results in the safe area ASTEC/WCET
Flow analysis Low level analysis Calculation ActualWCET WCETEstimate WCETEstimate Analysis Static WCET Analysis program • Flow analysis • Determine the dynamic behavior of program • Low level analysis • Determine execution time for program parts on the hardware • Calculation • Combine flow and low-level times to give a WCET estimate. Compiler ObjectCode Target Hardware ActualWCET Reality ASTEC/WCET
WCET Analysis Architecture • Modularization of WCET analysis • Several separate analysis steps • Make the analysis more retargetable • All analysis results are converted to constraints Program WCET Compiler ObjectCode Simulator Cache Analysis Cache Info IntermediateCode Pipeline Analysis Flow Analysis FlowInfo Constraint Problem Flow FactConversion Calculation ASTEC/WCET
max = 10max = 20 Structurally possible flows (infinite) A // A Basic finiteness samepath(D,G) B // B Statically allowed // C C D Actual feasible paths // D I E // E // F F G // G // H H // I // J J Relation between possible executions and flow info Basic block graph Flow Info Characteristics do { if(...) do { if(...) ... else ... if(...) ... else ... } while(...) else ... } while(...) ... WCET found here = overestimation WCET found here = desired result Exampleprogram ASTEC/WCET
Foo() XfooA XGA A XA XAB XB B XBC XBD C XC D XD XDE XCE XE E XEF XEG F XF • xnode for nodes XFG • xedge for edges G XG end Count Variables • Program model: • Basic block graph: nodes and edges • Execution count variable (xentity)holds number of times entity gets executed ASTEC/WCET
Foo() XfooA XGA • Start and end condition Xfoo=1 Xend =1 A XA XA=XfooA+XGA XAB XAB=XA XB B XBC • Program structure XBD XBC+XBD=XB XE=XCE+XDE C XC D XD XDE XCE XE E XEF XEG • Loop bounds F XF XA<=100 XFG • Other flow information G XG XC+XF<=XA end Constraints Generated • Constraints: ASTEC/WCET
IF IF IF EX EX EX EX EX EX M M M 1 2 3 4 5 1 2 3 4 5 6 7 A F F F B Pipeline Analysis • Time for a basic block: • Time from first instruction enters pipeline to last instruction leaves pipeline 1 2 3 4 5 6 7 tA = 7 A tB = 5 B ASTEC/WCET
IF IF IF IF EX EX EX EX EX EX EX EX M M M M 1 2 3 4 5 1 2 3 4 5 6 7 A F F F F B 1 2 3 4 5 6 7 8 9 10 Pipeline Analysis • Pipeline overlap between basic blocks • Timing effect of going from A to B is negative to indicate pipeline overlap • We use a general purpose simulator to extract times for nodes and edges 1 2 3 4 5 6 7 tA = 7 A AB= -2 tB = 5 B tAB = 10 AB = tAB- tA- tB= 10 - 7 - 5 = -2 ASTEC/WCET
Foo() tfooA=-4 tA=7 tGA=-1 A tAB=-2 tB=5 • Each basic block annotated with its execution time B tBC=-3 tBD=-5 tD=2 tC=12 C D tDE=-2 tCE=-1 tE=4 E • Each edge annotated with pipeline timing effect tEF=-3 tF=8 tEG=-2 F tFG=-3 tG=20 G end Pipeline Analysis Result Result: ASTEC/WCET
Foo() XfooA XGA tA=7 A XA XA=XfooA+XGA XAB tB=5 XAB=XA XB B XBC XBD XBC+XBD=XB tD=2 tC=12 XE=XCE+XDE C XC D XD XDE XCE tE=4 XE E XEF tF=8 XEG F XF XFG tG=20 G XG end IPET Calculation • WCET=max (xentity * tentity) • Where each xentitysatisfies all constraints Xfoo=1 XC+XF=100 XA<=100 ASTEC/WCET
Xfoo=1 Foo() XA=100 A XB=100 B XD=0 XC=100 C D WCET=4800 XE=100 E XF=0 F XG=100 G Xend=1 end Calculation methods • Solution methods: • Integer linear programming • Constraint satisfaction • Solution: • Counts for each individual node and edge • The value of the WCET ASTEC/WCET
A B C D E F G H I J K L Complicating Flow Information • Some flow information complicates the picture • Examples: • Local semantics:“For each entry of inner loop...” • Partially valid flow info: “During iterations 5 to 10 of inner loop it holds that...” • Loop dependencies:”Number of iterations of inner loop depends on current iteration of outer” • Non-linear constraints: ”If D was taken then K will be taken once” ASTEC/WCET
scope loop scope foo Local semantics • Create entry count variable: xentry(scope) holds number of times loop is entered • Local flow info are raised to the global level • For example: loop:[ ]:XH 10 gets converted to: XH 10 * Xentry(loop) A xentry(loop) B C “For each entry of the loop block Hwill beexecuted at most 10times” D E F G H I J “Block H can not be executed more than 10 * the number of times the loop is entered” Scope graph ASTEC/WCET
Facts can (partially) overlap Virtual scopes: scope:rangelet facts be valid for complete range of iterations scope loop 1..2 3..5 XC = XC + XC + XC + XC 6..10 11..20 1..2 3..5 XC + XC =5 (f1) loop:3..5 {f1,f2} loop:6..10 {f2} loop:11..20 { } loop:1..2{f1} Partial Flow Information A B C Loop bound: 20 loop : 1..5 : XC=5 (f1) loop : 3..10 : XC + XF 8 (f2) D E F G ASTEC/WCET
Graph is unrolled according to overlapping flow info Can generate large graphs Flow information often local (but can stretch over loop borders) Dependent flow info can be used to consider subpart of graph in isolation scope loop loop:3..5 {f1,f2} loop:6..10 {f2} loop:1..2{f1} Partial Flow Information A B C D E F Fact f1 and f2 only overlaps iterations 1..10 G ASTEC/WCET
A B C D E F G H I J K L Non-linear Constrains • Some flow info generates non-linear constraints • ”Number of iterations of inner loop depends on current iteration of outer” outer:XB 55or outer:XA * XA XB • ”If D was taken then K will be taken once” ifXD >0 then XK >0 and ifXD = 0 then XK = 0 • More powerful solver needed? ASTEC/WCET
WCET Tool Prototype • Prototype tool implemented • Works over whole program or use flow info to work bottom up over smaller program parts • Fast solution times when testing with CPLEX or similar solver (a network flow problem?) • We use integer linear programming (ILP) and lp_solve() • Not all flow information can be handled • Rather fast calculation times • Flow information sometimes generates large graphs and solution times • Other WCET research: Expressing hardware effects using constraints generates huge constraint systems and large solution times ASTEC/WCET
Experimental Results • Small programs: fast calculation (even with complex structure and flow) • Larger programs: Flow information slows down but increase precision • Example program: Nsichneu • Automatically generated program with massive amount of if-statements (> 250) ASTEC/WCET
Questions • What constraint solver should we use? • Are the generated constraints of a certain type? • More comments.... ASTEC/WCET