Upload
zalman
View
38
Download
0
Embed Size (px)
DESCRIPTION
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. - PowerPoint PPT Presentation
Citation preview
ConConstraint Systems used straint Systems used in Worst-Case Execution in Worst-Case Execution
Time AnalysisTime Analysis
Andreas ErmedahlAndreas Ermedahlandreas.ermedahlandreas.ermedahl@@itit.uu.se.uu.se
Dept. of Dept. of Information TechInformation Technologynology
Uppsala UniversityUppsala University
September 2000 ASTEC/WCET 2
Definition of WCETDefinition of WCET
WCETWCET = Worst = Worst possible execution time fpossible execution time for a or a program running on target hardwareprogram running on target hardware
One program in One program in isolationisolation No interrupts or context switchesNo interrupts or context switches
Other estimates: Other estimates: Best Case ETBest Case ET = Best case = Best case, Inverse of WCET, hard, Inverse of WCET, hard AveraAverage ge Case ETCase ET = = Soft reaSoft real-time, not hardl-time, not hard
0 tighter tighter
safe BCETestimates
safe WCETestimates
actual BCET
actual WCET
possible execution times
September 2000 ASTEC/WCET 3
Uses of WCET EstimatesUses of WCET Estimates
Hard real-time systemsHard real-time systems Scheduling Scheduling Schedulability analysisSchedulability analysis System dimensioningSystem dimensioning Formal verification Formal verification Program performanceProgram performance
tuningtuning
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; }}
?
September 2000 ASTEC/WCET 4
Static WCET AnalysisStatic WCET Analysis
Don’t run the program - analyze it!Don’t run the program - analyze it! Guaranteed safe WCETGuaranteed safe WCET Trying to be as tight as possibleTrying to be as tight as possible
Provided all input is correctProvided all input is correct
0 tighter tighter
safe BCETestimates
safe WCETestimates
actual BCET
actual WCET
possible execution times
Static analysisStatic analysis will will give give
results in tresults in the he safe areasafe area
Measurement wMeasurement will ill give resultgive resultss in th in the e
unsafe areaunsafe area
September 2000 ASTEC/WCET 5
Static WCET AnalysisStatic WCET Analysis
Flow analysisFlow analysis Determine the dynamic Determine the dynamic
behavior of programbehavior of program
Low level analysisLow level analysis Determine execution time for Determine execution time for
program parts on the program parts on the hardwarehardware
CalculationCalculation Combine flow and low-level Combine flow and low-level
times to give a WCET times to give a WCET estimateestimate. .
Compiler
ObjectCode
Target Hardware
Reality
program
ActualWCET
Low levelanalysis
Calculation
Flow analysis
Analysis
WCETEstimate
ActualWCET
WCETEstimate
September 2000 ASTEC/WCET 6
WCET Analysis ArchitectureWCET Analysis Architecture
Compiler
Program
Flow Analysis
IntermediateCode
Cache Analysis
Cache Info
Simulator
Pipeline Analysis
WCET
CalculationConstraint
ProblemFlowInfo
ObjectCode
Modularization of WCET analysisModularization of WCET analysis Several sepSeveral sepaarate analysis steps rate analysis steps Make the analysis more retargetableMake the analysis more retargetable
Flow FactConversion
All analysis results are All analysis results are converted to converted to constraints constraints
September 2000 ASTEC/WCET 7
Example program
Flow Info CharacteristicsFlow Info Characteristics
do{ if(...) do { if(...) ... else ... if(...) ... else ... } while(...) else ...} while(...)...
Basic finiteness
Statically allowed
Actual feasible
paths
// A// A
// B// B// C// C
// D // D // E// E
// F// F
// G// G// H // H
// I// I// J// J
Structurally possible
flows (infinite)
Relation between possible executions and flow info
max = 10max = 10
max = 20max = 20
samepath(D,G)samepath(D,G)
WCET found here = WCET found here =
desired resultdesired result
A
B
C D
F G
H
E
Basic block graph
J
I
WCET found here =WCET found here =
overestimationoverestimation
September 2000 ASTEC/WCET 8
Program model:Program model: Basic block graph: Basic block graph:
nnodes and edges odes and edges Execution count Execution count
variable (variable (xxentityentity)) holds holds number of times entity number of times entity gets executedgets executed
Foo()
C
A
B
D
E
F
G
end
Count Count VariablesVariables
XXAA
XXBB
XXCC XXDD
XXEE
XXFF
XXGG
xxnode node for nodesfor nodes
XXGAGA
XXABAB
XXBCBC XXBDBD
XXDEDE
XXEGEG
XXCECE
XXEFEF
XXFGFG
XXfooAfooA
xxedge edge for edgesfor edges
September 2000 ASTEC/WCET 9
Constraints:Constraints: Foo()
C
A
B
D
E
F
G
end
Constraints GeneratedConstraints Generated
XXAA
XXBB
XXCC XXDD
XXEE
XXFF
XXGG
XXGAGA
XXABAB
XXBCBC XXBDBD
XXDEDE
XXEGEG
XXCECE
XXEFEF
XXFGFG
XXfooAfooAXXfoofoo=1=1
XXend end =1=1Start and end Start and end conditioncondition
XXABAB=X=XAA
XXEE=X=XCECE+X+XDEDE
XXAA=X=XfooAfooA+X+XGAGA
XXBCBC+X+XBDBD=X=XBB
Program Program structurestructure
XXAA<=100 <=100 Loop boundsLoop bounds
XXCC+X+XFF<=X<=XAA
Other flow Other flow informationinformation
September 2000 ASTEC/WCET 10
A
B
Pipeline AnalysisPipeline Analysis Time for a basic block:Time for a basic block:
Time from first instruction enters pipeline Time from first instruction enters pipeline to last instruction leaves pipelineto last instruction leaves pipeline
ttA A = 7= 7
B
IF
EXEX
M
F
1 2 3 4 5
ttB B = 5= 5
IF
EXEX
M
F
1 2 3 4 5 6 7
A IF
EXEX
M
F
1 2 3 4 5 6 7
September 2000 ASTEC/WCET 11
A
B
Pipeline AnalysisPipeline Analysis Pipeline overlap between basic blocksPipeline overlap between basic blocks
Timing effect of going from A to B is Timing effect of going from A to B is negative to indicate pipeline overlapnegative to indicate pipeline overlap
We use a general purpose simulator to We use a general purpose simulator to extract times for nodes and edgesextract times for nodes and edges
ttA A = 7= 7
B
IF
EXEX
M
F
1 2 3 4 5
ttB B = 5= 5
ttAB AB = 10= 10
ABAB = = -2-2
AB AB = = ttABAB - - ttAA - - ttBB = 10 - 7 - 5 = = 10 - 7 - 5 = -2-2
1 2 3 4 5 6 7 8 9
IF
EXEX
M
F
10
IF
EXEX
M
F
1 2 3 4 5 6 7
A IF
EXEX
M
F
1 2 3 4 5 6 7
September 2000 ASTEC/WCET 12
Pipeline Analysis ResultPipeline Analysis Result
Result:Result: Foo()
C
A
B
D
E
F
G
end
Each edge Each edge annotated with annotated with pipeline timing pipeline timing effect effect
ttGAGA=-1=-1ttABAB=-2=-2
ttBCBC=-3=-3 ttBDBD=-5=-5
ttDEDE=-2=-2
ttEGEG=-2=-2
ttCECE=-1=-1
ttEFEF=-3=-3
ttFGFG=-3=-3
ttfooAfooA=-4=-4
Each basic block Each basic block annotated with its annotated with its execution timeexecution time
ttAA=7=7
ttDD=2=2
ttBB=5=5
ttCC=12=12
ttEE=4=4
ttFF=8=8
ttGG=20=20
September 2000 ASTEC/WCET 13
WCET=WCET=max max (x(xentityentity * t * tentityentity))
Where each Where each xxentityentity
satisfies all constraintssatisfies all constraints
Foo()
C
A
B
D
E
F
G
end
ttAA=7=7
ttDD=2=2
ttBB=5=5
ttCC=12=12
ttEE=4=4
ttFF=8=8
ttGG=20=20
IPET CalculationIPET Calculation
XXAA
XXBB
XXCC XXDD
XXEE
XXFF
XXGG
XXGAGA
XXABAB
XXBCBC XXBDBD
XXDEDE
XXEGEG
XXCECE
XXEFEF
XXFGFG
XXfooAfooA
XXfoofoo=1=1XXABAB=X=XAA
XXEE=X=XCECE+X+XDEDE
XXAA=X=XfooAfooA+X+XGAGA
XXBCBC+X+XBDBD=X=XBB
XXAA<=100<=100
XXCC+X+XFF=100=100
September 2000 ASTEC/WCET 14
Solution methods:Solution methods: Integer linear programmingInteger linear programming Constraint satisfactionConstraint satisfaction
Solution:Solution: Counts for each Counts for each
individual node and edgeindividual node and edge The value of the WCETThe value of the WCET
Foo()
C
A
B
D
E
F
G
end
Calculation methodsCalculation methods
XXAA=100=100
XXBB=100=100
XXCC=100=100 XXDD=0=0
XXEE=100=100
XXFF=0=0
XXGG=100=100
WCET=4800WCET=4800
XXfoofoo=1=1
XXendend=1=1
September 2000 ASTEC/WCET 15
Some flow information Some flow information complicates the picturecomplicates the picture
Examples: Examples: Local semantics:Local semantics:
“For each entry of “For each entry of inner loop...”inner loop...” Partially valid flow info: Partially valid flow info:
“During iterations 5 to 10 of “During iterations 5 to 10 of inner loop it holds that...”inner loop it holds that...”
Loop dependencies:Loop dependencies: ”Number of iterations of inner loop ”Number of iterations of inner loop depends on current iteration of outer”depends on current iteration of outer”
Non-linear constraints: Non-linear constraints: ”If D was taken then K will be taken ”If D was taken then K will be taken once” once”
B
C
D E
G H
I
F
J
A
LK
Complicating Flow InformationComplicating Flow Information
September 2000 ASTEC/WCET 16
scope foo
scope loop
Local semanticsLocal semantics
Create entry count variable: Create entry count variable: xxentry(scope) entry(scope) holds number of holds number of times loop is enteredtimes loop is entered
Local fLocal flow low info areinfo are raised raised to the global levelto the global level
For example: For example: loop:[ ]:Xloop:[ ]:XH H 1010
gets converted to:gets converted to: XXH H 10 * X10 * Xentry(loop)entry(loop)
B
C
D E
G H
I
F
J
A
Scope graph
““For each For each entry of the entry of the loop block Hloop block H
will bewill be executed at executed at
most 10most 10 times”times”
““Block H can not be executed Block H can not be executed
more than 10 * the number more than 10 * the number
of times the loop is entered”of times the loop is entered”
xxentry(loop)entry(loop)
September 2000 ASTEC/WCET 17
scopeloop
Partial Flow Information Partial Flow Information
B
A
C
D
F
Facts can (partially) overlapFacts can (partially) overlap Virtual scopes: Virtual scopes: scope:rangescope:range
let facts be valid for complete let facts be valid for complete range of iterationsrange of iterations
G
E
Loop bound: 20loop : 1..5 : XC=5 (f1)loop : 3..10 : XC + XF 8 (f2)
loop:1..2{f1}
loop:3..5{f1,f2}
loop:6..10{f2}
loop:11..20 { }
XC = XC + XC + XC + XC
1..2 3..5
6..10 11..20
XC + XC =5 (f1) 1..2 3..5
September 2000 ASTEC/WCET 18
scopeloop
Partial Flow Information Partial Flow Information
B
A
C
D
F
GGraph is unrolled according to raph is unrolled according to overlapping flow info overlapping flow info
Can generateCan generate l large graphsarge graphs Flow information often local (but Flow information often local (but
can stretch over loop borders) can stretch over loop borders) Dependent flow info can be used to Dependent flow info can be used to
consider subpart of graph in isolation consider subpart of graph in isolation
G
E
loop:1..2{f1}
loop:3..5{f1,f2}
loop:6..10{f2}
Fact f1 and f2 Fact f1 and f2 only overlaps only overlaps
iterations iterations 1..101..10
September 2000 ASTEC/WCET 19
Some flow info generates Some flow info generates non-linear constraints non-linear constraints ””Number of iterations of inner Number of iterations of inner
loop depends on current iteration loop depends on current iteration of outer” of outer” outer:outer: XXB B 55 55 or or outer:outer: XXA A * X* XA A X XBB
””If D was taken then K will be If D was taken then K will be taken once” taken once” ifif XXD D >> 0 then X0 then XK K >> 0 and 0 and
ifif XXD D = 0 then X= 0 then XK K = 0= 0
More powerful solver needed?More powerful solver needed?
B
C
D E
G H
I
F
J
A
LK
Non-linear ConstrainsNon-linear Constrains
September 2000 ASTEC/WCET 20
WCET Tool PrototypeWCET Tool Prototype Prototype tool implemented Prototype tool implemented
Works over whole program or use flow info to work bottom up over Works over whole program or use flow info to work bottom up over smaller program partssmaller program parts
Fast solution times when testing with CPLEX or similar Fast solution times when testing with CPLEX or similar solver solver (a network flow problem?)(a network flow problem?)
We use integer linear programming (ILP) and lp_solve()We use integer linear programming (ILP) and lp_solve() Not all flow information can be handledNot all flow information can be handled Rather fast calculation timesRather fast calculation times
Flow information sometimes generates large graphs Flow information sometimes generates large graphs and solution timesand solution times
Other WCET research: Expressing hardware effects Other WCET research: Expressing hardware effects using constraints generates huge constraint systems using constraints generates huge constraint systems and large solution timesand large solution times
September 2000 ASTEC/WCET 21
Experimental ResultsExperimental Results Small programs: fast calculation Small programs: fast calculation
(even with complex structure and flow)(even with complex structure and flow)
Larger programs: Flow information slows Larger programs: Flow information slows down but increase precision down but increase precision
Example program: NsichneuExample program: Nsichneu Automatically generated program with massive amount Automatically generated program with massive amount
of if-statements (> 250)of if-statements (> 250)Benchmark Flow WCET Graph gen Solving Variables ConstraintsProgram Facts estimate Time (s) Time (s)Nsichneu 0 97662 3.34 1.54 2143 1524Nsichneu (simple facts) 126 51133 3.48 1.44 2143 1650Nsichneu (range facts) 129 51101 233.64 90.16 10943 7945Nsichneu (more facts) 130 51085 279.80 202.37 15222 10971
September 2000 ASTEC/WCET 22
QuestionsQuestions
What constraint solver should What constraint solver should we use?we use?
Are the generated constraints of Are the generated constraints of a certain type?a certain type?
More comments....More comments....
The The End!End!