tight timing estimation with the newton-gregory formulaeengelen/cpctalk.pdf · tight timing...
TRANSCRIPT
Tight Timing Estimation With theNewton-Gregory Formulae
Robert van Engelen
Kyle Gallivan
Burt Walsh
Florida State University
CPC 2003 – p.1/30
Introduction• Worst-case execution time (WCET) estimation
has important applications in scheduling andreal-time embedded systems.
0
5
10
15
20
25
30
0 20 40 60 80 100
(ms)
TaskWCET
The WCET bound is obtained by static (compiler)analysis of a task and is used to determine if thetask will finish within a given time frame.
CPC 2003 – p.2/30
Parameterized WCET• Parametric timing analysis produces formulae,
where the unknown values affecting theexecution are parameterized.
0
5
10
15
20
0 20 40 60 80 100
(ms)
Input Size
TaskWCET
WCET = 5.0 + 0.1 N
where N is the task input size.
CPC 2003 – p.3/30
Related Work• Presburger formulas [Pugh, 1994]• Summations over τ functions [Haghighat, 1995]• Ehrhart polynomials [Clauss, 1996]• Guarded sums [Sakellariou, 1997]• Parametric timing analysis [Vivancos et al., 2001]
CPC 2003 – p.4/30
Experiences• We incorporated Sakellariou’s guarded sums into
a WCET estimation framework which requiredlinking a small computer algebra system with theVPO compiler [Healy, 2000]
• The timing estimation can be very loose for loopswith slightly more complicated control flow
for i = 0 to 9 do
if a[i] > 0 then
for j = 1 to i do
b[j] = b[i] + a[i]
else
b[i] = a[i]
CPC 2003 – p.5/30
Motivation• WCET analysis focus on loops, because most of
the execution time of a task is typically spent inloops.
• Loops may have symbolic bounds and exhibitcomplicated control flow.
for i = 0 to N do
if . . . then
for j = 0 to i do
. . .
else
for j = 0 to i do
for k = 0 to j do
. . .CPC 2003 – p.6/30
Motivation (cont’d)Existing methods. . .
• are computationally expensive and requireextensive (symbolic) manipulation.
• can lead to an over estimation of the WCET ofloops with complicated control flow due to thedecoupling of the WCET of the loop body andthe iteration count
WCET = WCET (loopHeader)
+ WCET (loopBody) ∗ iterCount
CPC 2003 – p.7/30
Loop Execution Time• Loops are assumed to have been normalized
for i = a to b step s do
S⇒
for i = 0 to b b−a
sc do
S′
• The unknown loop execution time functions are
ω(H(i)) = Loop header execution time
ω(S ′(i)) = Loop body execution time
• The (unknown) real loop execution time ω is
ω = ω(H(0)) +
b b−a
sc
∑
i=0
ω(S ′(i)) + ω(H(i + 1))
CPC 2003 – p.8/30
Loop Execution Time Bound• First we recursively determine (parameterized)
WCET bounds on the unknowns
ω(H(0)) ≤ c0
ω(S ′(i)) + ω(H(i + 1)) ≤ p(i)
• Then, the WCET bound on ω is
ω ≤ WCET = c0 +n−1∑
i=0
p(i)
provided that the number of loop iterationsn = bb−a
sc+ 1 > 0.
CPC 2003 – p.9/30
Newton-Gregory• Let p(i) = p0 + p1 i + · · ·+ pk ik be a polynomial.
There exist Newton series coefficients
Φ(i) = 〈φ0, φ1, . . . , φk〉i
such that
p(i) =k
∑
j=0
φj
(
i
j
)
CPC 2003 – p.10/30
Newton-Gregory WCETLemma.
• To determine the WCET of a loop, we canreplace the WCET iteration summation with aconstant summation
WCET = c0 +n−1∑
i=0
p(i) =k
∑
j=0
φj
(
n
j + 1
)
for all (symbolic) n > 0.
CPC 2003 – p.11/30
Newton Series Conversions• Given coefficients [p0, p1, . . . , pk]i of polynomial
p(i) = p0 + p1 i + · · · + pk ik, then the Newtonseries is
Φ(i) = Nkp(i)
where Nk is the constant integer(k + 1) × (k + 1) “Newton triangle matrix”.
• Given Newton series coefficientsΦ(i) = 〈φ0, φ1, . . . , φk〉i, then
p(i) = N−1k Φ(i)
where N−1k is the constant rational
(k + 1) × (k + 1) “inverse Newton trianglematrix”. CPC 2003 – p.12/30
WCET of a Loop• Let Φ(i) = 〈φ0, . . . , φk〉i denote the Newton
series of a polynomial in i over i = 0, . . . , n− 1,n ≥ 0. We define
σ(Φ(i), n)def=
k∑
j=0
φj
(
n
j + 1
)
• The WCET of a (possibly zero trip) loopi = a, . . . , b, stride s, and iteration WCETpolynomial p(i) with Newton series Φ(i) is
WCET = c0 + σ(Φ(i), max(0, b−as
+ 1))
CPC 2003 – p.13/30
A Useful PropertyLemma.
• The coefficients s0, . . . , sk+1 of the polynomials(n) = σ(Φ(i), n) are given by the matrix-vectorproduct
s(n) = [s0, . . . , sk+1]n = N−1k+1〈0, φ0, . . . , φk〉i
where Φ(i) = 〈φ0, φ1, . . . , φk〉i.
CPC 2003 – p.14/30
Application• Hence, the WCET of a loop is
WCET = c0 + σ(Φ(i), max(0, b−as
+ 1)))
= c0 + s(max(0, b−as
+ 1)))
where s(n) = N−1k+1〈0, φ0, . . . , φk〉i.
CPC 2003 – p.15/30
An Example
for I = 1 to N do /* header H1 */
for J = I to I ∗ I − 2 step 2 do /* header H2 */
S
The normalized iteration space is
i = 0, . . . , N − 1
j = 0, . . . , b i+i2
2 c − 1
The (recursively determined) execution time bounds
ω(H1(0)) ≤ c0
ω(H ′2(i, 0)) ≤ c1
ω(S ′(i, j)) + ω(H ′2(i, j + 1)) ≤ c2
CPC 2003 – p.16/30
An Example (cont’d)
WCET 1
= c0 + σ(N1(c1 + σ(N0c2, max(0, i+i2
2 ))), max(0, N))
(i + i2 ≥ 0, so replace max(0, i+i2
2 ) by i+i2
2 )= c0 + σ(N1(c1 + σ(N0c2,
i+i2
2 )), max(0, N))
= c0 + σ(N1(c1 + σ(c2,i+i2
2 )), max(0, N))
= c0 + σ(N1(c1 + 12c2(i + i2)), max(0, N))
= c0 + σ(〈c1, c2, c2〉i, max(0, N))
= c0 + (c1 −16c2) max(0, N) + 1
6c2 max(0, N)3
CPC 2003 – p.17/30
An Example (cont’d)For c0 = 1, c1 = 1, and c2 = 2 we have
0100200300400500600700800900
1000
0 2 4 6 8 10
WCET 2WCET 1
where the conventional WCET estimation of theexample fragment gives the over estimation
WCET 2 = c0 + c1 N + c2 NbN2−N2 c
CPC 2003 – p.18/30
Loop Bounds Analysis• If the loop iteration space size is non-negative
(n = bb−asc+ 1 ≥ 0), the max operation can be
eliminated from the WCET expressionWCET = c0 + σ(Φ(i), max(0, b−a
s+ 1)).
• Otherwise, splitting with guards is used.• Use symbolic range propagation [Blume, 1995].• Or we can use Newton series representations
directly.
CPC 2003 – p.19/30
Monotonicity• If the values of a (symbolic) expression are
monotonic in a loop, its extreme values can beeasily determined (symbolically).
• Most array index and loop bound expressions aremonotonic (in one loop dimension).
• But how can we determine monotonicity withouttoo much effort?
CPC 2003 – p.20/30
Monotonic Polynomials• Let Φ(i) = 〈φ0, φ1, . . . , φk〉i denote the Newton
series of a polynomial p(i) in i.
• If h(i) = N−1k−1〈φ1, . . . , φk〉i ≥ 0 for all
i = 0, . . . , n− 2, n ≥ 0, then p(i) ismonotonically increasing on the interval[0, n − 1].
• Similarly, if h(i) ≤ 0 for all i = 0, . . . , n− 2,then p(i) is monotonically decreasing on theinterval [0, n − 1].
CPC 2003 – p.21/30
Monotonicity Example• p(i) = i2−i
2 with coefficients [0,−12 ,
12 ]i has
Newton series Φ(i) = N2[0,−12 ,
12 ]i = 〈0, 0, 1〉i.
• Because h(i) = N−11 〈0, 1〉i = i ≥ 0 for all i ≥ 0,
p(i) is monotonically increasing with i.• The value range of p(i) on i = 0, . . . , N is
[p(0), p(N)] = [0, N2−N2 ].
• While conventional value range analysis gives12[0, N ]2 − 1
2 [0, N ] = [−12N, 1
2N2].
CPC 2003 – p.22/30
Value Range Analysis
Value range of expression E = [L(E),U(E)]
Rewrite rules:L(E1 + E2) = L(E1) + L(E2)
L(Φ(i)) =
L(φ0) if L(〈φ1, . . . , φk〉i) ≥ 0
L(N−1
kΦ(n− 1)) if U(〈φ1, . . . , φk〉i) ≤ 0
L(N−1
kΦ(i)) otherwise
U(Φ(i)) =
U(φ0) if U(〈φ1, . . . , φk〉i) ≤ 0
U(N−1
kΦ(n− 1)) if L(〈φ1, . . . , φk〉i) ≥ 0
U(N−1
kΦ(i)) otherwise
CPC 2003 – p.23/30
Finding Critical PathsThe objective is to find the critical path
for i = 0 to n do
if C then
S1 /* path with parametric WCET cost p(i) */
else
S2 /* path with parametric WCET cost q(i) */
CPC 2003 – p.24/30
Comparing WCET Polynomials• Let Φ(i) and Ψ(i) be Newton series of
polynomials p(i) and q(i).• If L(Φ(i) −Ψ(i)) ≥ 0 then p(i) ≥ q(i).• If U(Φ(i) −Ψ(i)) ≤ 0 then p(i) ≤ q(i).
020406080
100120140160
0 2 4 6 8 10
(ms)
i
p(i)q(i)
CPC 2003 – p.25/30
Example
for i = 0 to N do
if a[i] > 0 then
for j = 0 to i do
S4
else
for j = 0 to i do
for k = 0 to j do
S8
ω(H1(0))≤ 1
ω(C2(i))≤ 1
ω(H3(i, 0))≤ 1
ω(S4(i, j)) + ω(H3(i, j + 1))≤ 2
ω(H6(i, 0))≤ 1
ω(H7(i, 0))≤ 1
ω(S8(i, j)) + ω(H7(i, j + 1))≤ 2
CPC 2003 – p.26/30
Example (cont’d)
WCET 1 = 7 + 61
6N + 21
2N 2 + 1
3N 3
WCET 2 = 1 + (N + 1) max(5 + 2N, 6 + 4N + N 2)
WCET 3 = 1 + (N + 1) max(5 + 2N, 6 + 5N + 2N 2)
0
500
1000
1500
2000
2500
3000
0 2 4 6 8 10
WCET 3WCET 2WCET 1
CPC 2003 – p.27/30
Bounding WCET Polynomials• When one of the WCET polynomials does not
dominate, we need to split the iteration space(root finding!) or derive an overall boundingpolynomial.
020406080
100120140160
0 2 4 6 8 10
p(i)q(i)
bound
CPC 2003 – p.28/30
Iteration ReversalWhen one of the WCET polynomials does notdominate and the paths are loop invariant, the iterationdirection can be reversed.
020406080
100120140160
0 2 4 6 8 10
(ms)
i
p(i)q(i)
020406080
100120140160
0 2 4 6 8 10
(ms)
i
p(i)q(i)
CPC 2003 – p.29/30
Conclusions• Parametric WCET has important applications.• Timing of loops with complicated control flow is
difficult.• Relatively simple numeric/symbolic method.• Approach also contributes to value range
analysis.• Implementation is work in progress.
CPC 2003 – p.30/30