25.07.2013 Views

Caches in WCET Analysis

Caches in WCET Analysis

Caches in WCET Analysis

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong><br />

Jan Re<strong>in</strong>eke<br />

Department of Computer Science<br />

Saarland University<br />

Saarbrücken, Germany<br />

ARTIST Summer School <strong>in</strong> Europe 2009<br />

Autrans, France<br />

September 7-11, 2009<br />

saarland<br />

university<br />

computer science<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 1 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 2 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 3 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

“hit”<br />

[ab]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

a1<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

“hit”<br />

[ab]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

a1!<br />

“hit”<br />

[ab]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

c3?<br />

“miss”<br />

[ab]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

“miss”<br />

[ab]<br />

c3? c?<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

“miss”<br />

[ac]<br />

c3? c = 〈c1c2c3c4〉!<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

c3!<br />

“miss”<br />

[ac]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

c4?<br />

“hit”<br />

[ac]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


<strong>Caches</strong><br />

How they work:<br />

◮ dynamically<br />

◮ managed by replacement policy<br />

CPU Cache Ma<strong>in</strong> Memory<br />

Capacity:<br />

Latency:<br />

c4!<br />

“hit”<br />

[ac]<br />

32 KB<br />

3 cycles<br />

Why they work: pr<strong>in</strong>ciple of locality<br />

◮ spatial<br />

◮ temporal<br />

2 MB<br />

100 cycles<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 4 / 51


Fully-Associative <strong>Caches</strong><br />

Address: log2(s) log2(8 ∗ b)<br />

•<br />

•<br />

•<br />

Tag<br />

Block<br />

offset<br />

Tag Data Block<br />

Tag Data Block<br />

Tag Data Block<br />

=?<br />

No:<br />

Miss!<br />

...<br />

Yes:<br />

Hit!<br />

k<br />

= associativity<br />

MUX<br />

Data<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 5 / 51<br />

B


Set-Associative <strong>Caches</strong><br />

Special cases:<br />

log2(s) log2(s) log2(8 ∗ b) log2(8 ∗ b)<br />

Address:<br />

•<br />

•<br />

•<br />

k s<br />

•<br />

Tag Index<br />

•<br />

•<br />

Cache Set:<br />

Tag Data Block<br />

Tag Data Block<br />

...<br />

Tag Data Block<br />

Block<br />

offset<br />

...<br />

log2(s) log2(8 ∗ b) s<br />

s<br />

Cache Set:<br />

Tag Data Block<br />

Tag Data Block<br />

...<br />

Tag Data Block<br />

=?<br />

No:<br />

Miss!<br />

Yes:<br />

Hit!<br />

direct-mapped cache: only one l<strong>in</strong>e per cache set<br />

fully-associative cache: only one cache set<br />

k<br />

MUX<br />

Data<br />

•<br />

•<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 6 / 51


Cache Replacement Policies<br />

Least-Recently-Used (LRU) used <strong>in</strong><br />

INTEL PENTIUM I and MIPS 24K/34K<br />

saarland<br />

university<br />

computer science<br />

First-In First-Out (FIFO or Round-Rob<strong>in</strong>) used <strong>in</strong><br />

MOTOROLA POWERPC 56X, INTEL XSCALE, ARM9, ARM11<br />

Pseudo-LRU (PLRU) used <strong>in</strong><br />

INTEL PENTIUM II-IV and POWERPC 75X<br />

Most Recently Used (MRU) as described <strong>in</strong> literature<br />

Each cache set is treated <strong>in</strong>dependently:<br />

−→ Set-associative caches are compositions of fully-associative caches.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 7 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 8 / 51


Cache <strong>Analysis</strong><br />

Two types of cache analyses:<br />

1 Local guarantees: classification of <strong>in</strong>dividual accesses<br />

◮ May-<strong>Analysis</strong> −→ Overapproximates cache contents<br />

◮ Must-<strong>Analysis</strong> −→ Underapproximates cache contents<br />

2 Global guarantees: bounds on cache hits/misses<br />

Cache analyses almost exclusively for LRU<br />

In practice: FIFO, PLRU, . . .<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 9 / 51


Challenges for Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

Always a cache hit/always a miss?<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 10 / 51


Challenges for Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

Always a cache hit/always a miss?<br />

1. Initial cache contents unknown.<br />

saarland<br />

university<br />

computer science<br />

2. Different paths lead to these po<strong>in</strong>ts.<br />

3. Cannot resolve address of z.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 10 / 51


Deriv<strong>in</strong>g Invariants about Cache States<br />

us<strong>in</strong>g Abstract Interpretation<br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Collect<strong>in</strong>g Semantics =<br />

set of states at each program po<strong>in</strong>t that<br />

any execution may encounter there<br />

Two approximations:<br />

Collect<strong>in</strong>g Semantics uncomputable<br />

⊆ Cache Semantics computable<br />

⊆ γ(Abstract Cache Sem.) efficiently<br />

computable<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 11 / 51


Deriv<strong>in</strong>g Invariants about Cache States<br />

us<strong>in</strong>g Abstract Interpretation<br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Collect<strong>in</strong>g Semantics =<br />

set of states at each program po<strong>in</strong>t that<br />

any execution may encounter there<br />

Two approximations:<br />

Collect<strong>in</strong>g Semantics uncomputable<br />

⊆ Cache Semantics computable<br />

⊆ γ(Abstract Cache Sem.) efficiently<br />

computable<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 11 / 51


Deriv<strong>in</strong>g Invariants about Cache States<br />

us<strong>in</strong>g Abstract Interpretation<br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Collect<strong>in</strong>g Semantics =<br />

set of states at each program po<strong>in</strong>t that<br />

any execution may encounter there<br />

Two approximations:<br />

Collect<strong>in</strong>g Semantics uncomputable<br />

⊆ Cache Semantics computable<br />

⊆ γ(Abstract Cache Sem.) efficiently<br />

computable<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 11 / 51


Deriv<strong>in</strong>g Invariants about Cache States<br />

us<strong>in</strong>g Abstract Interpretation<br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Collect<strong>in</strong>g Semantics =<br />

set of states at each program po<strong>in</strong>t that<br />

any execution may encounter there<br />

Two approximations:<br />

Collect<strong>in</strong>g Semantics uncomputable<br />

⊆ Cache Semantics computable<br />

⊆ γ(Abstract Cache Sem.) efficiently<br />

computable<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 11 / 51


Deriv<strong>in</strong>g Invariants about Cache States<br />

us<strong>in</strong>g Abstract Interpretation<br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Collect<strong>in</strong>g Semantics =<br />

set of states at each program po<strong>in</strong>t that<br />

any execution may encounter there<br />

Two approximations:<br />

Collect<strong>in</strong>g Semantics uncomputable<br />

⊆ Cache Semantics computable<br />

⊆ γ(Abstract Cache Sem.) efficiently<br />

computable<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 11 / 51


Least-Recently-Used (LRU): Concrete Behavior<br />

“Cache Miss”:<br />

“Cache Hit”:<br />

z<br />

y<br />

x<br />

t<br />

z<br />

y<br />

s<br />

t<br />

s<br />

s<br />

s<br />

z<br />

y<br />

x<br />

s<br />

z<br />

y<br />

t<br />

LRU has<br />

notion of age<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 12 / 51


LRU: Must-<strong>Analysis</strong>: Abstract Doma<strong>in</strong><br />

Used to predict cache hits.<br />

Ma<strong>in</strong>ta<strong>in</strong>s upper bounds on ages of memory blocks.<br />

saarland<br />

university<br />

computer science<br />

Upper bound ≤ associativity −→ memory block def<strong>in</strong>itely cached.<br />

Example<br />

Abstract state:<br />

{x}<br />

{}<br />

{s,t}<br />

{}<br />

age 0<br />

age 3<br />

. . . and its <strong>in</strong>terpretation:<br />

Describes the set of all concrete cache<br />

states <strong>in</strong> which x, s, and t occur,<br />

x with an age of 0,<br />

s and t with an age not older than 2.<br />

γ([{x}, {}, {s, t}, {}]) =<br />

{[x, s, t, a], [x, t, s, a], [x, s, t, b], . . .}<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 13 / 51


Sound Update – Local Consistency<br />

(must) (must ′ Abstract Update<br />

)<br />

γ γ<br />

Lifted<br />

Concrete<br />

Update<br />

concrete cache states concrete cache states<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 14 / 51


LRU: Must-<strong>Analysis</strong>: Update<br />

“Potential Cache Miss”:<br />

“Def<strong>in</strong>ite Cache Hit”:<br />

{x}<br />

{}<br />

{s,t}<br />

{x}<br />

{}<br />

{s,t}<br />

Why does t not age <strong>in</strong> the second case?<br />

{}<br />

{}<br />

z<br />

s<br />

{z}<br />

{x}<br />

{}<br />

{s,t}<br />

{s}<br />

{x}<br />

{t}<br />

{}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 15 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


LRU: Must-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

“Intersection + Maximal Age”<br />

{}<br />

{}<br />

{a,c}<br />

How many memory blocks can be <strong>in</strong> the must-cache?<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 16 / 51


Example: Must-<strong>Analysis</strong><br />

⊥<br />

B<br />

entry [{}, {}, {}, {}]<br />

A ⊥<br />

D ⊥<br />

exit ⊥<br />

C<br />

⊥<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 17 / 51


Example: Must-<strong>Analysis</strong><br />

⊥<br />

B<br />

entry [{}, {}, {}, {}]<br />

A<br />

D ⊥<br />

exit ⊥<br />

⊥ ⊔ [{}, {}, {}, {}] = [{}, {}, {}, {}]<br />

C<br />

⊥<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 17 / 51


Example: Must-<strong>Analysis</strong><br />

[{A}, {}, {}, {}]<br />

B<br />

entry [{}, {}, {}, {}]<br />

A<br />

D ⊥<br />

exit ⊥<br />

⊥ ⊔ [{}, {}, {}, {}] = [{}, {}, {}, {}]<br />

C<br />

[{A}, {}, {}, {}]<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 17 / 51


Example: Must-<strong>Analysis</strong><br />

[{A}, {}, {}, {}]<br />

B<br />

entry [{}, {}, {}, {}]<br />

A<br />

D<br />

exit ⊥<br />

⊥ ⊔ [{}, {}, {}, {}] = [{}, {}, {}, {}]<br />

C<br />

[{A}, {}, {}, {}]<br />

saarland<br />

university<br />

computer science<br />

[{B}, {A}, {}, {}] ⊔ [{C}, {A}, {}, {}] =<br />

[{}, {A}, {}, {}]<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 17 / 51


Example: Must-<strong>Analysis</strong><br />

[{A}, {}, {}, {}]<br />

B<br />

entry [{}, {}, {}, {}]<br />

A<br />

D<br />

[{D}, {}, {A}, {}] ⊔ [{}, {}, {}, {}] =<br />

[{}, {}, {}, {}]<br />

C<br />

[{A}, {}, {}, {}]<br />

saarland<br />

university<br />

computer science<br />

[{B}, {A}, {}, {}] ⊔ [{C}, {A}, {}, {}] =<br />

[{}, {A}, {}, {}]<br />

exit [{D}, {}, {A}, {}]<br />

No cache hits can be predicted :-(<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 17 / 51


Context-Sensitive <strong>Analysis</strong>/Virtual Loop-Unroll<strong>in</strong>g<br />

Problem:<br />

saarland<br />

university<br />

◮ The first iteration of a loop will always result <strong>in</strong> cache misses.<br />

◮ Similarly for the first execution of a function.<br />

Solution:<br />

◮ Virtually Unroll Loops: Dist<strong>in</strong>guish the first iteration from others<br />

◮ Dist<strong>in</strong>guish function calls by call<strong>in</strong>g context.<br />

Virtually unroll<strong>in</strong>g the loop once:<br />

Accesses to A and D are provably<br />

hits after the first iteration<br />

Accesses to B and C can still not be<br />

classified. With<strong>in</strong> each execution of<br />

the loop, they may only miss once.<br />

−→ Persistence <strong>Analysis</strong><br />

[{A}, {}, {}, {}]<br />

B<br />

[{A}, {D}, {}, {}]<br />

exit<br />

B<br />

entry<br />

A<br />

D<br />

A<br />

D<br />

computer science<br />

[{}, {}, {}, {}]<br />

C<br />

[{A}, {}, {}, {}]<br />

[{}, {A}, {}, {}]<br />

[{D}, {}, {A}, {}]<br />

C<br />

[{A}, {D}, {}, {}]<br />

[{}, {A}, {D}, {}]<br />

exit<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 18 / 51


LRU: May-<strong>Analysis</strong>: Abstract Doma<strong>in</strong><br />

saarland<br />

university<br />

computer science<br />

Used to predict cache misses.<br />

Ma<strong>in</strong>ta<strong>in</strong>s lower bounds on ages of memory blocks.<br />

Lower bound ≥ associativity<br />

−→ memory block def<strong>in</strong>itely not cached.<br />

Example<br />

Abstract state:<br />

{x,y}<br />

{}<br />

{s,t}<br />

{u}<br />

age 0<br />

age 3<br />

. . . and its <strong>in</strong>terpretation:<br />

Describes the set of all concrete cache states <strong>in</strong><br />

which no memory blocks except x, y, s, t, and<br />

u occur,<br />

x and y with an age of at least 0,<br />

s and t with an age of at least 2,<br />

u with an age of at least 3.<br />

γ([{x, y}, {}, {s, t}, {u}]) =<br />

{[x, y, s, t], [y, x, s, t], [x, y, s, u], . . .}<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 19 / 51


LRU: May-<strong>Analysis</strong>: Update<br />

“Def<strong>in</strong>ite Cache Miss”:<br />

“Potential Cache Hit”:<br />

{x}<br />

{}<br />

{s,t}<br />

{y}<br />

{x}<br />

{}<br />

{s,t}<br />

{y}<br />

Why does t age <strong>in</strong> the second case?<br />

z<br />

s<br />

{z}<br />

{x}<br />

{}<br />

{s,t}<br />

{s}<br />

{x}<br />

{}<br />

{y,t}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 20 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


LRU: May-<strong>Analysis</strong>: Jo<strong>in</strong><br />

Need to comb<strong>in</strong>e <strong>in</strong>formation where control-flow merges.<br />

Jo<strong>in</strong> should be conservative:<br />

γ(A) ⊆ γ(A ⊔ B)<br />

γ(B) ⊆ γ(A ⊔ B)<br />

{a}<br />

{}<br />

{c,f}<br />

{d}<br />

⊔<br />

{c}<br />

{e}<br />

{a}<br />

{d}<br />

=<br />

“Union + M<strong>in</strong>imal Age”<br />

{a,c}<br />

{e}<br />

{f}<br />

{d}<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 21 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 22 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 23 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong><br />

saarland<br />

university<br />

Amount of uncerta<strong>in</strong>ty determ<strong>in</strong>es precision of <strong>WCET</strong> analysis<br />

Uncerta<strong>in</strong>ty <strong>in</strong> cache analysis depends on replacement policy<br />

variation due to <strong>in</strong>puts<br />

and <strong>in</strong>itial hardware state<br />

uncerta<strong>in</strong>ty<br />

×<br />

penalty<br />

BCET ACET <strong>WCET</strong> upper<br />

bound<br />

execution<br />

time<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 24 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 25 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

1. Initial cache contents unknown.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 25 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

1. Initial cache contents unknown.<br />

2. Need to comb<strong>in</strong>e <strong>in</strong>formation.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 25 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

1. Initial cache contents unknown.<br />

2. Need to comb<strong>in</strong>e <strong>in</strong>formation.<br />

3. Cannot resolve address of z.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 25 / 51


Uncerta<strong>in</strong>ty <strong>in</strong> Cache <strong>Analysis</strong><br />

read<br />

y<br />

read<br />

z<br />

write<br />

z<br />

read<br />

x<br />

1. Initial cache contents unknown.<br />

2. Need to comb<strong>in</strong>e <strong>in</strong>formation.<br />

3. Cannot resolve address of z.<br />

=⇒ Amount of uncerta<strong>in</strong>ty determ<strong>in</strong>ed<br />

by ability to recover <strong>in</strong>formation<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 25 / 51


Predictability Metrics<br />

Evict<br />

[dex]<br />

[fed]<br />

[fec]<br />

[fde]<br />

Fill<br />

[gfe]<br />

[gfd]<br />

Sequence: 〈a, . . . , e, f, g, h〉<br />

[hgf ]<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 26 / 51


Mean<strong>in</strong>g of Metrics<br />

Evict<br />

Fill<br />

◮ Number of accesses to obta<strong>in</strong> any may-<strong>in</strong>formation.<br />

◮ I.e. when can an analysis predict any cache misses?<br />

◮ Number of accesses to complete may- and must-<strong>in</strong>formation.<br />

◮ I.e. when can an analysis predict each access?<br />

saarland<br />

university<br />

−→ Evict and Fill bound the precision of any static cache analysis.<br />

Can thus serve as a benchmark for analyses.<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 27 / 51


Evaluation of Least-Recently-Used<br />

LRU “forgets” about past quickly:<br />

◮ cares about most-recent access to each block only<br />

◮ order of previous accesses irrelevant<br />

?<br />

?<br />

?<br />

?<br />

a<br />

a<br />

?<br />

?<br />

?<br />

In the example: Evict = Fill = 4<br />

b<br />

b<br />

a<br />

?<br />

?<br />

c<br />

c<br />

b<br />

a<br />

?<br />

d<br />

saarland<br />

university<br />

computer science<br />

In general: Evict(k) = Fill(k) = k, where k is the associativity of<br />

the cache<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 28 / 51<br />

d<br />

c<br />

b<br />

a


Evaluation of First-In First-Out (sketch)<br />

Like LRU <strong>in</strong> the miss-case<br />

But: “Ignores” hits<br />

?<br />

a<br />

b<br />

c<br />

a<br />

?<br />

a<br />

b<br />

c<br />

b<br />

?<br />

a<br />

b<br />

c<br />

c<br />

?<br />

a<br />

b<br />

c<br />

d<br />

saarland<br />

university<br />

computer science<br />

In the worst-case k − 1 hits and k misses: (k = associativity)<br />

−→ Evict(k) = 2k − 1<br />

Another k accesses to obta<strong>in</strong> complete knowledge:<br />

−→ Fill(k) = 3k − 1<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 29 / 51<br />

d<br />

?<br />

a<br />

b


Evaluation of Pseudo-LRU (sketch)<br />

Tree-bits po<strong>in</strong>t to block to be replaced<br />

1<br />

1 1<br />

a b c d<br />

c<br />

0<br />

1 1<br />

a b c d<br />

Accesses “rejuvenate” neighborhood<br />

e<br />

1<br />

0 1<br />

a e c d<br />

◮ Active blocks keep their (<strong>in</strong>active) neighborhood <strong>in</strong> the cache<br />

<strong>Analysis</strong> yields:<br />

◮ Evict(k) = k<br />

2 log 2<br />

◮ Fill(k) = k<br />

2 log 2<br />

k + 1<br />

k + k − 1<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 30 / 51


Evaluation of Policies<br />

saarland<br />

university<br />

Policy Evict(k) Fill(k) Evict(8) Fill(8)<br />

LRU k k 8 8<br />

FIFO 2k − 1 3k − 1 15 23<br />

MRU 2k − 2 ∞/3k − 4 14 ∞/20<br />

k + k − 1 13 19<br />

PLRU k<br />

2 log 2<br />

k + 1 k<br />

2 log 2<br />

LRU is optimal w.r.t. metrics.<br />

Other policies are much less predictable.<br />

−→ Use LRU if predictability is a concern.<br />

computer science<br />

How to obta<strong>in</strong> may- and must-<strong>in</strong>formation with<strong>in</strong> the given limits for<br />

other policies?<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 31 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 32 / 51


Relative Competitiveness<br />

saarland<br />

university<br />

computer science<br />

Competitiveness (Sleator and Tarjan, 1985):<br />

worst-case performance of an onl<strong>in</strong>e policy relative to the optimal<br />

offl<strong>in</strong>e policy<br />

◮ used to evaluate onl<strong>in</strong>e policies<br />

Relative competitiveness (Re<strong>in</strong>eke and Grund, 2008):<br />

worst-case performance of an onl<strong>in</strong>e policy relative to another<br />

onl<strong>in</strong>e policy<br />

◮ used to derive local and global cache analyses<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 33 / 51


Def<strong>in</strong>ition – Relative Miss-Competitiveness<br />

Notation<br />

saarland<br />

university<br />

computer science<br />

mP(p, s) = number of misses that policy P <strong>in</strong>curs on<br />

access sequence s ∈ M ∗ start<strong>in</strong>g <strong>in</strong> state p ∈ C P<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 34 / 51


Def<strong>in</strong>ition – Relative Miss-Competitiveness<br />

Notation<br />

saarland<br />

university<br />

computer science<br />

mP(p, s) = number of misses that policy P <strong>in</strong>curs on<br />

access sequence s ∈ M ∗ start<strong>in</strong>g <strong>in</strong> state p ∈ C P<br />

Def<strong>in</strong>ition (Relative miss competitiveness)<br />

Policy P is (k, c)-miss-competitive relative to policy Q if<br />

mP(p, s) ≤ k · m Q(q, s) + c<br />

for all access sequences s ∈ M ∗ and cache-set states p ∈ C P , q ∈ C Q<br />

that are compatible p ∼ q.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 34 / 51


Def<strong>in</strong>ition – Relative Miss-Competitiveness<br />

Notation<br />

saarland<br />

university<br />

computer science<br />

mP(p, s) = number of misses that policy P <strong>in</strong>curs on<br />

access sequence s ∈ M ∗ start<strong>in</strong>g <strong>in</strong> state p ∈ C P<br />

Def<strong>in</strong>ition (Relative miss competitiveness)<br />

Policy P is (k, c)-miss-competitive relative to policy Q if<br />

mP(p, s) ≤ k · m Q(q, s) + c<br />

for all access sequences s ∈ M ∗ and cache-set states p ∈ C P , q ∈ C Q<br />

that are compatible p ∼ q.<br />

Def<strong>in</strong>ition (Competitive miss ratio of P relative to Q)<br />

The smallest k, s.t. P is (k, c)-miss-competitive rel. to Q for some c.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 34 / 51


Example – Relative Miss-Competitiveness<br />

P is (3, 4)-miss-competitive relative to Q.<br />

If Q <strong>in</strong>curs x misses, then P <strong>in</strong>curs at most 3 · x + 4 misses.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 35 / 51


Example – Relative Miss-Competitiveness<br />

P is (3, 4)-miss-competitive relative to Q.<br />

If Q <strong>in</strong>curs x misses, then P <strong>in</strong>curs at most 3 · x + 4 misses.<br />

Best: P is (1, 0)-miss-competitive relative to Q.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 35 / 51


Example – Relative Miss-Competitiveness<br />

P is (3, 4)-miss-competitive relative to Q.<br />

If Q <strong>in</strong>curs x misses, then P <strong>in</strong>curs at most 3 · x + 4 misses.<br />

Best: P is (1, 0)-miss-competitive relative to Q.<br />

saarland<br />

university<br />

computer science<br />

Worst: P is not-miss-competitive (or ∞-miss-competitive) relative to Q.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 35 / 51


Example – Relative Hit-Competitiveness<br />

P is ( 2<br />

3 , 3)-hit-competitive relative to Q.<br />

If Q has x hits, then P has at least 2<br />

3 · x − 3 hits.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 36 / 51


Example – Relative Hit-Competitiveness<br />

P is ( 2<br />

3 , 3)-hit-competitive relative to Q.<br />

If Q has x hits, then P has at least 2<br />

3 · x − 3 hits.<br />

Best: P is (1, 0)-hit-competitive relative to Q.<br />

Equivalent to (1, 0)-miss-competitiveness.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 36 / 51


Example – Relative Hit-Competitiveness<br />

P is ( 2<br />

3 , 3)-hit-competitive relative to Q.<br />

If Q has x hits, then P has at least 2<br />

3 · x − 3 hits.<br />

Best: P is (1, 0)-hit-competitive relative to Q.<br />

Equivalent to (1, 0)-miss-competitiveness.<br />

Worst: P is (0, 0)-hit-competitive relative to Q.<br />

Analogue to ∞-miss-competitiveness.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 36 / 51


Local Guarantees: (1, 0)-Competitiveness<br />

Let P be (1, 0)-competitive relative to Q:<br />

mP(p, s) ≤ 1 · m Q(q, s) + 0<br />

⇔ mP(p, s) ≤ m Q(q, s)<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 37 / 51


Local Guarantees: (1, 0)-Competitiveness<br />

Let P be (1, 0)-competitive relative to Q:<br />

1 If Q “hits”, so does P, and<br />

2 if P “misses”, so does Q.<br />

mP(p, s) ≤ 1 · m Q(q, s) + 0<br />

⇔ mP(p, s) ≤ m Q(q, s)<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 37 / 51


Local Guarantees: (1, 0)-Competitiveness<br />

Let P be (1, 0)-competitive relative to Q:<br />

1 If Q “hits”, so does P, and<br />

2 if P “misses”, so does Q.<br />

As a consequence,<br />

mP(p, s) ≤ 1 · m Q(q, s) + 0<br />

⇔ mP(p, s) ≤ m Q(q, s)<br />

1 a must-analysis for Q is also a must-analysis for P, and<br />

2 a may-analysis for P is also a may-analysis for Q.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 37 / 51


Global Guarantees: (k, c)-Competitiveness<br />

Given: Global guarantees for policy Q.<br />

Wanted: Global guarantees for policy P.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 38 / 51


Global Guarantees: (k, c)-Competitiveness<br />

Given: Global guarantees for policy Q.<br />

Wanted: Global guarantees for policy P.<br />

1 Determ<strong>in</strong>e competitiveness of policy P relative to policy Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 38 / 51


Global Guarantees: (k, c)-Competitiveness<br />

Given: Global guarantees for policy Q.<br />

Wanted: Global guarantees for policy P.<br />

1 Determ<strong>in</strong>e competitiveness of policy P relative to policy Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

2 Compute global guarantee for task T under policy Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 38 / 51


Global Guarantees: (k, c)-Competitiveness<br />

Given: Global guarantees for policy Q.<br />

Wanted: Global guarantees for policy P.<br />

1 Determ<strong>in</strong>e competitiveness of policy P relative to policy Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

2 Compute global guarantee for task T under policy Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

saarland<br />

university<br />

computer science<br />

3 Calculate global guarantee on the number of misses for P us<strong>in</strong>g<br />

the global guarantee for Q and the competitiveness results of P<br />

relative to Q.<br />

mP ≤ k · m Q + c m Q(T) = mP(T)<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 38 / 51


Relative Competitiveness:<br />

Automatic Computation<br />

P and Q (here: FIFO and LRU) <strong>in</strong>duce transition system:<br />

(h, h)<br />

e<br />

[eabc] FIFO , [eabc] LRU<br />

c (h, h)<br />

[eabc] FIFO , [ceab] LRU<br />

[eabc] FIFO , [ceda] LRU<br />

e<br />

(m, m)<br />

c<br />

(h, m)<br />

first-<strong>in</strong><br />

last-<strong>in</strong><br />

MRU<br />

LRU<br />

[abcd] FIFO , [abcd] LRU<br />

d (h, h)<br />

[abcd] FIFO , [dabc] LRU<br />

e (m, m)<br />

[eabc] FIFO , [edab] LRU<br />

(h, h)<br />

d<br />

a<br />

(m, h)<br />

Legend<br />

[abcd] FIFO<br />

[deab] FIFO , [deab] LRU<br />

saarland<br />

university<br />

computer science<br />

Cache-set state<br />

·<br />

d<br />

·<br />

(h, m), . . .<br />

Memory access<br />

Misses <strong>in</strong> pairs of<br />

cache-set states<br />

Competitive miss ratio = maximum ratio of misses <strong>in</strong> policy P to misses<br />

<strong>in</strong> policy Q <strong>in</strong> transition system<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 39 / 51


Transition System is ∞ Large<br />

Problem: The <strong>in</strong>duced transition system is ∞ large.<br />

Observation: Only the relative positions of elements matter:<br />

[abc] LRU , [bde] FIFO<br />

c<br />

(h, m)<br />

[cab] LRU , [cbd] FIFO<br />

≈<br />

[fgl] LRU , [ghm] FIFO<br />

(h, m)<br />

[lfg] LRU , [lgh] FIFO<br />

Solution: Construct f<strong>in</strong>ite quotient transition system.<br />

≈<br />

l<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 40 / 51


≈-Equivalent States <strong>in</strong> Runn<strong>in</strong>g Example<br />

(h, h)<br />

e<br />

[eabc] FIFO , [eabc] LRU<br />

c (h, h)<br />

[eabc] FIFO , [ceab] LRU<br />

[eabc] FIFO , [ceda] LRU<br />

e<br />

(m, m)<br />

c<br />

(h, m)<br />

[abcd] FIFO , [abcd] LRU<br />

d (h, h)<br />

[abcd] FIFO , [dabc] LRU<br />

e (m, m)<br />

[eabc] FIFO , [edab] LRU<br />

(h, h)<br />

d<br />

a<br />

(m, h)<br />

saarland<br />

university<br />

[deab] FIFO , [deab] LRU<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 41 / 51


F<strong>in</strong>ite Quotient Transition System<br />

saarland<br />

university<br />

computer science<br />

Merg<strong>in</strong>g ≈-equivalent states yields a f<strong>in</strong>ite quotient transition system:<br />

[eabc] FIFO , [ceda] LRU<br />

(m, m)<br />

(h, m)<br />

(h, h)<br />

[abcd] FIFO , [abcd] LRU<br />

(h, h)<br />

[abcd] FIFO , [dabc] LRU<br />

(m, m)<br />

[eabc] FIFO , [edab] LRU<br />

(m, h)<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 42 / 51


Competitive Ratio = Maximum Cycle Ratio<br />

saarland<br />

university<br />

computer science<br />

Competitive miss ratio =<br />

maximum ratio of misses <strong>in</strong> policy P to misses <strong>in</strong> policy Q<br />

(1, 1)<br />

(0, 0)<br />

(1, 1)<br />

(0, 1)<br />

(0, 0)<br />

(1, 0)<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 43 / 51


Competitive Ratio = Maximum Cycle Ratio<br />

saarland<br />

university<br />

computer science<br />

Competitive miss ratio =<br />

maximum ratio of misses <strong>in</strong> policy P to misses <strong>in</strong> policy Q<br />

(1, 1)<br />

(0, 0)<br />

(1, 1)<br />

(0, 1)<br />

Maximum cycle ratio = 0+1+1<br />

0+1+0 = 2<br />

(0, 0)<br />

(1, 0)<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 43 / 51


Tool Implementation<br />

Implemented <strong>in</strong> Java, called Relacs<br />

Interface for replacement policies<br />

Fully automatic<br />

saarland<br />

university<br />

computer science<br />

Provides example sequences for competitive ratio and constant<br />

<strong>Analysis</strong> usually practically feasible up to associativity 8<br />

◮ limited by memory consumption<br />

◮ depends on similarity of replacement policies<br />

Onl<strong>in</strong>e version:<br />

http://rw4.cs.uni-sb.de/~re<strong>in</strong>eke/relacs<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 44 / 51


Generalizations<br />

Identified patterns and proved generalizations by hand.<br />

Aided by example sequences generated by tool.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 45 / 51


Generalizations<br />

Identified patterns and proved generalizations by hand.<br />

Aided by example sequences generated by tool.<br />

Previously unknown facts:<br />

PLRU(k) is (1, 0) comp. rel. to LRU(1 + log2k),<br />

−→ LRU-must-analysis can be used for PLRU<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 45 / 51


Generalizations<br />

Identified patterns and proved generalizations by hand.<br />

Aided by example sequences generated by tool.<br />

Previously unknown facts:<br />

PLRU(k) is (1, 0) comp. rel. to LRU(1 + log2k),<br />

−→ LRU-must-analysis can be used for PLRU<br />

saarland<br />

university<br />

computer science<br />

FIFO(k) is ( 1 k−1<br />

2 , 2 ) hit-comp. rel. to LRU(k), whereas<br />

LRU(k) is (0, 0) hit-comp. rel. to FIFO(k), but<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 45 / 51


Generalizations<br />

Identified patterns and proved generalizations by hand.<br />

Aided by example sequences generated by tool.<br />

Previously unknown facts:<br />

PLRU(k) is (1, 0) comp. rel. to LRU(1 + log2k),<br />

−→ LRU-must-analysis can be used for PLRU<br />

saarland<br />

university<br />

computer science<br />

FIFO(k) is ( 1 k−1<br />

2 , 2 ) hit-comp. rel. to LRU(k), whereas<br />

LRU(k) is (0, 0) hit-comp. rel. to FIFO(k), but<br />

LRU(2k − 1) is (1, 0) comp. rel. to FIFO(k), and<br />

LRU(2k − 2) is (1, 0) comp. rel. to MRU(k).<br />

−→ LRU-may-analysis can be used for FIFO and MRU<br />

−→ optimal with respect to predictability metric Evict<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 45 / 51


Generalizations<br />

Identified patterns and proved generalizations by hand.<br />

Aided by example sequences generated by tool.<br />

Previously unknown facts:<br />

PLRU(k) is (1, 0) comp. rel. to LRU(1 + log2k),<br />

−→ LRU-must-analysis can be used for PLRU<br />

saarland<br />

university<br />

computer science<br />

FIFO(k) is ( 1 k−1<br />

2 , 2 ) hit-comp. rel. to LRU(k), whereas<br />

LRU(k) is (0, 0) hit-comp. rel. to FIFO(k), but<br />

LRU(2k − 1) is (1, 0) comp. rel. to FIFO(k), and<br />

LRU(2k − 2) is (1, 0) comp. rel. to MRU(k).<br />

−→ LRU-may-analysis can be used for FIFO and MRU<br />

−→ optimal with respect to predictability metric Evict<br />

FIFO-may-analysis used <strong>in</strong> the analysis of the branch target buffer of<br />

the MOTOROLA POWERPC 56X.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 45 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 46 / 51


Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

Run program on a number of <strong>in</strong>puts and<br />

<strong>in</strong>itial states.<br />

Comb<strong>in</strong>e measurements for basic blocks<br />

to obta<strong>in</strong> <strong>WCET</strong> estimation.<br />

Sensitivity <strong>Analysis</strong> demonstrates this<br />

approach may be dramatically wrong.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 47 / 51


Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

Run program on a number of <strong>in</strong>puts and<br />

<strong>in</strong>itial states.<br />

Comb<strong>in</strong>e measurements for basic blocks<br />

to obta<strong>in</strong> <strong>WCET</strong> estimation.<br />

Sensitivity <strong>Analysis</strong> demonstrates this<br />

approach may be dramatically wrong.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 47 / 51


Influence of Initial Cache State<br />

variation due to<br />

<strong>in</strong>itial cache state<br />

BCET <strong>WCET</strong> upper<br />

bound<br />

Def<strong>in</strong>ition (Miss sensitivity)<br />

Policy P is (k, c)-miss-sensitive if<br />

mP(p, s) ≤ k · mP(p ′ , s) + c<br />

execution<br />

time<br />

for all access sequences s ∈ M ∗ and cache-set states p, p ′ ∈ C P .<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 48 / 51


Sensitivity Results<br />

Policy 2 3 4 5 6 7 8<br />

LRU 1, 2 1, 3 1, 4 1, 5 1, 6 1, 7 1, 8<br />

FIFO 2, 2 3, 3 4, 4 5, 5 6, 6 7, 7 8, 8<br />

PLRU 1, 2 − ∞ − − − ∞<br />

MRU 1, 2 3, 4 5, 6 7, 8 MEM MEM MEM<br />

saarland<br />

university<br />

LRU is optimal. Performance varies <strong>in</strong> the least possible way.<br />

For FIFO, PLRU, and MRU the number of misses may vary<br />

strongly.<br />

computer science<br />

Case study based on simple model of execution time by<br />

Hennessy and Patterson (2003):<br />

<strong>WCET</strong> may be 3 times higher than a measured execution time<br />

for 4-way FIFO.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 49 / 51


Outl<strong>in</strong>e<br />

1 <strong>Caches</strong><br />

2 Cache <strong>Analysis</strong> for Least-Recently-Used<br />

3 Beyond Least-Recently-Used<br />

Predictability Metrics<br />

Relative Competitiveness<br />

Sensitivity – <strong>Caches</strong> and Measurement-Based Tim<strong>in</strong>g <strong>Analysis</strong><br />

4 Summary<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 50 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Predictability Metrics<br />

. . . quantify the predictability of replacement policies.<br />

−→ LRU is the most predictable policy.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Predictability Metrics<br />

. . . quantify the predictability of replacement policies.<br />

−→ LRU is the most predictable policy.<br />

Relative Competitiveness<br />

. . . allows to derive guarantees on cache performance,<br />

. . . yields first may-analyses for FIFO and MRU.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Predictability Metrics<br />

. . . quantify the predictability of replacement policies.<br />

−→ LRU is the most predictable policy.<br />

Relative Competitiveness<br />

. . . allows to derive guarantees on cache performance,<br />

. . . yields first may-analyses for FIFO and MRU.<br />

Sensitivity <strong>Analysis</strong><br />

. . . determ<strong>in</strong>es the <strong>in</strong>fluence of <strong>in</strong>itial state on cache performance.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Predictability Metrics<br />

. . . quantify the predictability of replacement policies.<br />

−→ LRU is the most predictable policy.<br />

Relative Competitiveness<br />

. . . allows to derive guarantees on cache performance,<br />

. . . yields first may-analyses for FIFO and MRU.<br />

Sensitivity <strong>Analysis</strong><br />

. . . determ<strong>in</strong>es the <strong>in</strong>fluence of <strong>in</strong>itial state on cache performance.<br />

Thank you for your attention!<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Summary<br />

Cache <strong>Analysis</strong> for Least-Recently-Used<br />

saarland<br />

university<br />

computer science<br />

. . . efficiently represents sets of cache states by bound<strong>in</strong>g the age<br />

of memory blocks from above and below.<br />

. . . requires context-sensitivity for precision.<br />

Predictability Metrics<br />

. . . quantify the predictability of replacement policies.<br />

−→ LRU is the most predictable policy.<br />

Relative Competitiveness<br />

. . . allows to derive guarantees on cache performance,<br />

. . . yields first may-analyses for FIFO and MRU.<br />

Sensitivity <strong>Analysis</strong><br />

. . . determ<strong>in</strong>es the <strong>in</strong>fluence of <strong>in</strong>itial state on cache performance.<br />

Thank you for your attention!<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Most-Recently-Used – MRU<br />

MRU-bits record whether l<strong>in</strong>e was recently used<br />

e<br />

c<br />

−→ Never converges<br />

[abcd] 0101<br />

[ebcd] 1101<br />

[ebcd] 0010<br />

b,d<br />

e,b,d<br />

c<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Pseudo-LRU – PLRU<br />

1<br />

1 0<br />

a b c d<br />

Initial cacheset<br />

state<br />

[a, b, c, d] 110 .<br />

0<br />

1 1<br />

a b e d<br />

After a miss<br />

on e. State:<br />

[a, b, e, d] 011 .<br />

1<br />

1 1<br />

a b e d<br />

After a hit<br />

on a. State:<br />

[a, b, e, d] 111 .<br />

0<br />

1 0<br />

saarland<br />

university<br />

a b e f<br />

computer science<br />

After a miss<br />

on f . State:<br />

[a, b, e, f ] 010 .<br />

Hit on a “rejuvenates” neighborhood; “saves” b from eviction.<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


May- and Must-Information<br />

may P (n) :=<br />

must P (n) :=<br />

May P (s) := <br />

p∈C P<br />

Must P (s) := <br />

p∈C P<br />

CCP(updateP(p, s))<br />

CCP(updateP(p, s))<br />

<br />

<br />

May P <br />

<br />

(s) , where s ∈ S = M ∗ , |s| = n<br />

<br />

<br />

Must P <br />

<br />

(s) , where s ∈ S = M ∗ , |s| = n<br />

saarland<br />

university<br />

computer science<br />

S = : set of f<strong>in</strong>ite access sequences with pairwise different accesses<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Def<strong>in</strong>itions of Metrics<br />

Evict P :=<br />

<br />

m<strong>in</strong> n | may P <br />

(n) ≤ n ,<br />

Fill P :=<br />

<br />

m<strong>in</strong> n | must P <br />

(n) = k ,<br />

where k is P’s associativity.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Relation: Pred. Metrics ↔ Rel. Competitiveness<br />

Let P(k) be (1, 0)-miss-competitive relative to policy Q(l), then<br />

(i) Evict P (k) ≥ Evict Q (l),<br />

(ii) mls P (k) ≥ mls Q (l).<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Alternative Pred. Metrics ↔ Rel. Competitiveness<br />

Let l be the smallest associativity, such that LRU(l) is<br />

(1, 0)-miss-competitive relative to P(k). Then<br />

Alt-Evict P (k) = l.<br />

Let l be the greatest associativity, such that P(k) is<br />

(1, 0)-miss-competitive relative to LRU(l). Then<br />

Alt-mls P (k) = l.<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Size of Transition System<br />

2 l+l′<br />

·<br />

status bits<br />

of P and Q<br />

m<strong>in</strong>{k,k ′ }<br />

<br />

j=0<br />

k<br />

<br />

k<br />

i<br />

i=0<br />

<br />

·<br />

k<br />

non-empty l<strong>in</strong>es <strong>in</strong> P<br />

′<br />

<br />

i ′ <br />

k ′<br />

i<br />

=0<br />

′<br />

<br />

<br />

m<strong>in</strong>{i,i<br />

·<br />

non-empty l<strong>in</strong>es <strong>in</strong> Q<br />

′ } <br />

<br />

i i ′<br />

j!<br />

j j<br />

j=0<br />

<br />

number of overlapp<strong>in</strong>gs<br />

<strong>in</strong> non-empty l<strong>in</strong>es<br />

k<br />

j<br />

k ′<br />

This can be bounded by<br />

2 l+l′ +k+k ′<br />

≤ |(C l k<br />

j<br />

<br />

j! ≤ k! · k ′ !<br />

≤ k! · k ′ !<br />

m<strong>in</strong>{k,k ′ }<br />

<br />

∞<br />

j=0<br />

j=0<br />

1<br />

(k − j)!j!(k ′ − j)!<br />

1<br />

j! = e · k! · k ′ !<br />

saarland<br />

university<br />

computer science<br />

× Cl′<br />

k ′)/ ≈ | ≤ 2l+l′ +k+k ′<br />

· e · k! · k ′ !<br />

<br />

bound on number of overlapp<strong>in</strong>gs<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Compatible States<br />

i P = [⊥⊥⊥⊥] P<br />

p<br />

≈<br />

updateP(i P , s)<br />

≈<br />

i Q = [⊥⊥⊥⊥] Q<br />

q<br />

update Q(i Q , s)<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


(1, 0)-Competitiveness and May/Must-Analyses<br />

Let P be (1, 0)-competitive relative to Q, then<br />

mP(p, 〈x〉) = 1<br />

p q<br />

≈<br />

p ′<br />

=⇒<br />

≈<br />

q ′<br />

m Q(q, 〈x〉) = 1<br />

saarland<br />

university<br />

computer science<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


(1, 0)-Competitiveness and May/Must-Analyses<br />

CP CQ ≈<br />

S<br />

∀p ∈ P : mP(p, 〈x〉) = 1<br />

P<br />

P ′<br />

≈<br />

=⇒<br />

≈<br />

Q<br />

Q ′<br />

S<br />

saarland<br />

university<br />

computer science<br />

∀q ∈ Q : m Q(q, 〈x〉) = 1<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51


Case Study: Impact of Sensitivity<br />

saarland<br />

university<br />

computer science<br />

Simple model of execution time from Hennessy & Patterson (2003)<br />

CPIhit = Cycles per <strong>in</strong>struction assum<strong>in</strong>g cache hits only<br />

Memory accesses<br />

Instruction<br />

Twc<br />

Tmeas<br />

<strong>in</strong>clud<strong>in</strong>g <strong>in</strong>struction and data fetches<br />

= CPI Memory accesses<br />

hit + ×Miss ratewc×Miss penalty<br />

Instruction<br />

Memory accesses<br />

CPIhit + ×Miss ratemeas×Miss penalty<br />

Instruction<br />

= 1.5+1.2×0.20×50 13.5<br />

1.5+1.2×0.05×50 = 4.5<br />

= 3<br />

Jan Re<strong>in</strong>eke <strong>Caches</strong> <strong>in</strong> <strong>WCET</strong> <strong>Analysis</strong> ARTIST Summer School 2009 51 / 51

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!