Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations...

32
Approximation of the Worst-Case Approximation of the Worst-Case Execution Time Using Structural Execution Time Using Structural Analysis Analysis Matteo Corti and Thomas Gross Zürich

Transcript of Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations...

Page 1: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

Approximation of the Worst-CaseApproximation of the Worst-Case

Execution Time Using StructuralExecution Time Using Structural

AnalysisAnalysis

Matteo Corti and Thomas Gross

Zürich

Page 2: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 2

GoalGoal

• Worst-case execution time estimation of soft-

real time Java applications.

• We focus on semantic analysis:

– compute a tight bound on the max and min

number of iterations for every block

– consider different path frequencies inside loops

– avoid path enumeration

Page 3: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 3

OutlineOutline

• Goal

• Loop bounds

• Block bounds

• Complexity and related work

• Testing environment

• Results

• Concluding remarks

Page 4: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 4

Semantic analysis

SystemSystem’’s overviews overview

bytecode

annotated

asm

partial

abstract

interpretation

loop

header

bounds

block

bounds

instruction

duration

analysis

WCET

Page 5: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 5

JavaJava

• Whole program analysis.

• Variable type based analysis to resolve

polymorphism.

• We consider only local integer variables for

the loop analysis.

• Our block iterations bounding technique

is language independent.

Page 6: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 6

Semantic analysis

SystemSystem’’s overviews overview

bytecode

annotated

asm

partial

abstract

interpretation

loop

header

bounds

block

bounds

instruction

duration

analysis

WCET

Page 7: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 7

Partial abstract interpretationPartial abstract interpretation

• We perform a limited abstract interpretation

pass over linear code.

• We discover some false paths (not

containing cycles).

• We gather information on possible variables’

values. void foo(int i) { if (i > 0) {

for(;i<10;i++) { bar(); } }}

i 1..[ [

Page 8: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 8

Partial abstract interpretationPartial abstract interpretation

22_228_jack

19_222_mpegaudio

240_213_javac

2_209_db

7_205_raytrace

3_202_jess

2_201_compress

Infeasible pathsBenchmark

Page 9: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 9

Partial abstract interpretationPartial abstract interpretation

1whetstone

2linpack

2JavaLayer

Infeasible longest pathBenchmark

Page 10: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 10

Semantic analysis

SystemSystem’’s overviews overview

bytecode

annotated

asm

partial

abstract

interpretation

loop

header

bounds

block

bounds

instruction

duration

analysis

WCET

Page 11: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 11

Loop boundsLoop bounds

• Bounds on the loop header computed

similarly to C. Healy [RTAS’98].

• We introduce noncontiguous sets of integers

to easily handle equality operators.

• Iteration branch: a block where the

conditional jump could be responsible for a

loop exit.

• For each edge e and iteration branch ib we

compute the possible number of iterations.

Page 12: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 12

[101]

[101][101]

[101]

[50] [50]

[100]

Loop boundsLoop bounds

• The bounds on the iterations of the header

are safe for the whole loop.

• But: some parts of the loop could be

executed less frequently:

for(int i=0; i<100; i++) { if (i < 50) { A; } else { B; }}

A B

[101]

[1]

[100]

Page 13: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 13

Semantic analysis

SystemSystem’’s overviews overview

bytecode

annotated

asm

partial

abstract

interpretation

loop

header

bounds

block

bounds

instruction

duration

analysis

WCET

Page 14: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 14

Basic block iterationsBasic block iterations

• The number of iterations of a block is not a

local property (based on immediate

predecessors).

P0 P1

B

[10]

[10]

[0..10][0..10]

void foo(boolean b) { for(int i=0; i<10; i++) { if (b) { P0; } else { P1; } B; }}

Page 15: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 15

Basic block iterationsBasic block iterations

• The number of iterations of a block is not a

local property (based on immediate

predecessors).

void foo(boolean b) { for(int i=0; i<20; i++) { if (i<10) { P0; } else { P1; } B; }}

P0 P1

B

[20]

[20]

[10][10]

Page 16: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 16

Basic block iterationsBasic block iterations

• The number of iterations of a block is not a

local property (based on immediate

predecessors). void foo(boolean b) { int i = 0; if (b) { do { i++; P0; } while (i<10); } else { do { i++; P1; } while (i<10); } B;}

B

P1

[1]

[1]

[0] [10]

[0] [10]P0

[0] [10]

[0] [10]

Page 17: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 17

Basic block iterationsBasic block iterations

• The number of iterations of a block is not a

local property (based on immediate

predecessors).

[1]

[1]

[0] [10]

[0] [10]

[20]

[20]

[10][10]

[10]

[10]

[0..10][0..10]

[0] [10]

[0] [10]

Page 18: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 18

Structural analysisStructural analysis

• Powerful interval analysis.

• Recognizes semantic

constructs.

• Useful when the source

code is not available.

• Iteratively matches the

blocks with predefined

patterns.

Page 19: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 19

Structural analysisStructural analysis

• Powerful interval analysis.

• Recognizes semantic

constructs.

• Useful when the source

code is not available.

• Iteratively matches the

blocks with predefined

patterns.

Page 20: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 20

Structural analysisStructural analysis

if (A || (B && C)) { D;} else { E;}F;

A

D

B

E

C

F

Static patterns:

Dynamic patterns:

Page 21: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 21

Block iterationsBlock iterations

• Block iterations are computed

using the CFG root and the

iteration branches.

• The header and the type of the

biggest semantic region that

includes all the predecessors of

a node determine its number of

iterations.

• Complete algorithm in the paper.

P0

B

H

P1

Page 22: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 22

ExampleExample

P0 P1

B

H [20]

[20]

[10][10]

void foo(boolean b) { for(int i=0; i<20; i++) { if (i<10) { P0; } else { P1; } B; }}

Page 23: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 23

ExampleExample

B

H

P1

[1]

[1]

[0..10]

[0..10]P0

[0..10]

[0..10]

void foo(boolean b) { int i = 0; if (b) { do { i++; P0; } while (i<10); } else { do { i++; P1; } while (i<10); } B;}

Page 24: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 24

ExampleExample

B

PH

L

H

[1]

[1]

[11]

[10]

void foo(boolean b) { PH; for(int i=0; i<10; i++) { L; } B;}

Page 25: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 25

Related workRelated work

• Automatically detected value-dependent

constraints [Healy, RTAS’99]:

– per block bounds

– requires path enumeration (in the loop body)

• We propagate the header bounds to the

blocks in quadratic time:

– Structural analysis: O(B2)

– Loop bounds: O(B)

– Block bounds: O(B)

Page 26: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 26

Evaluation: hardware-level analysisEvaluation: hardware-level analysis

• The semantic analysis is platform independent.

• Evaluation: Pentium III on Linux.

• We approximate the effects of caches and

pipelines:

– we assume that the effects of an instruction fade over

time.

– caches and pipelines are analyzed locally.

• Possible sources of inaccuracies:

– cache misses and pipeline stalls

– but not the number of iterations of an instruction

(conservative)

Page 27: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 27

EvaluationEvaluation

• Base: the bounds on the iterations of the

loop header are used for the whole loop.

• Enhanced: structural analysis is used to

consider different path frequencies in loop

bodies.

Page 28: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 28

Results: synthetic benchmarksResults: synthetic benchmarks

for (i=0; i<10000; i++) { if (i<5000) { array[i] = -array[i]; } if (array[i] > max) { max = array[i]; }}

for(i=0; i<10; i++) { for (j=0; j<10; j++) { if(j<9) { m[i][j] *= m[i][j]; } else { for(k=0; k<9; k++) { m[i][j]+=m[i][k]; } } } }

10’000

10’000

B2

90

100

B3

5’000

10’000

B1

10Enhanced

100Base

B4

B1

B2

B3

B4

Example 1 Example 2

Page 29: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 29

ResultsResults

2%2.73·1092%2.73·1092.68·109MatMult

22%1.08·101022%1.08·10100.88·1010Jacobi

4.76·1012

2.12·1011

1.49·109

1.11·1010

1.42·1011

1.30·1010

50’370%117%9.45·109_201_compress

858%579%2.47·1010SciMark

558%487%2.67·109JavaLayer

Base

[cycles]

Enhanced

[cycles]

Max observed

[cycles]

Benchmark

Page 30: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 30

_201_compress_201_compress

for (data = 0; data < N; data++) {

// compress data

if (data == 10’000) {

// update structures

}

}

Page 31: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

EMSOFT 2004, © Matteo Corti 31

Concluding remarksConcluding remarks

• We tighten the bounds of basic blocks

iteration considering different paths inside

loop bodies.

• We do not perform path enumeration

• Tests with real applications validate the

semantic analysis.

Page 32: Approximation of the Worst-Case Execution Time Using ... · Block iterations • Block iterations are computed using the CFG root and the iteration branches. • The header and the

Questions?Questions?