Docsity

Improving Cache Performance Design | CMSC 411, Study notes of Computer Science

Toggle sidebar
bg1
1
Page1
MemoryHierarchyand
CacheDesign(2)
ImprovingCachePerformance
•Averagememory-accesstime
=Hittime+Missrate xMisspenalty
•Improveperformanceby:
1.Reducethemissrate,
2.Reducethemisspenalty,or
3.Reducethetimetohitinthecache.
ReducingMissRate
•SourcesofCachemisses
–Compulsorymisses
»Missesresultingfromfirstaccesstoablock
»Alsocalledcoldstartmissesorfirstreference
misses
–Capacitymisses
»Missesresultingfromfiniteorlimitedcachesize
–Conflictmisses
»Missesresultingfromfiniteorlimitedset
associativity
»Alsocalledcollisionmissesorinterferencemisses
Missratepertype
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Improving Cache Performance Design | CMSC 411 and more Study notes Computer Science in PDF only on Docsity!

Page 1

Memory Hierarchy and

Cache Design (2)

Improving Cache Performance

  • Average memory-access time

= Hit time + Miss rate x Miss penalty

  • Improve performance by:

1. Reduce the miss rate,

2. Reduce the miss penalty, or

3. Reduce the time to hit in the cache.

Reducing Miss Rate

  • Sources of Cache misses
    • Compulsory misses Ā» Misses resulting from first access to a block Ā» Also called cold start misses or first reference misses
    • Capacity misses Ā» Misses resulting from finite or limited cache size
    • Conflict misses Ā» Misses resulting from finite or limited set associativity Ā» Also called collision misses or interference misses

Miss rate per type

Page 2

Miss rate per type Back to Reducing Miss Rate

1. Larger block size

2. Higher set associativity

3. Victim cache

4. Pseudo-associative cache

5. Hardware prefetching of instruction and data

6. Compiler-controlled prefetching

7. Compiler optimization

First Approach

Large Block Size

  • reduces compulsory misses - principle of

locality

  • reduces number of blocks in cache
    • increasing conflict misses

Larger Block Size

Page 4

Victim Cache

Small, fully- associative cache

Fourth Approach

Pseudo-Associative Caches

  • Pseudo-Associative or Column Associative
    • get miss rate of set associative and the hit speed of direct mapped
  • Cache access proceeds just as in the direct

mapped cache for a hit

  • On a miss, before going to the memory,

another cache entry is checked to see if it

matches

  • E.g., invert the MSB of the index field to find the other block in the ā€œPseudo Setā€
  • Have one fast and one slow hit time

Pseudo-associative Cache

Two types of hits: regular (first access) and pseudo (second access) hits

Questions: 1. Methods for second access

  1. Replacement policy

Fifth Approach

Hardware Prefetching

  • Prefetch instructions and/or data before it is

requested by the processor

  • Prefetched into the cache or an external buffer
  • E.g. AXP 21064 fetches two (instruction)

blocks on a miss

  • requested block, Ā» Placed in the instruction cache
  • next consecutive block Ā» Placed into the instruction stream buffer
  • If requested block is in stream buffer Ā» Get it from there and issue next prefetch request

Page 5

Hardware Prefetching

Stream Buffer

  • Instruction or data
  • single or multiple streams

Hardware Prefetching

  • Relies on utilizing unused memory bandwidth
  • Could interfere with demand misses
    • Memory bus
    • Memory unit

Sixth Approach

Compiler-Controlled Prefetching

  • Compiler inserts prefetch instructions
  • Several flavors of prefetch
    • Register Prefetch Ā» load the value in a register
    • Cache Prefetch Ā» load data only into the cache and not the register
    • Either can be faulting or non-faulting (nonbinding) Ā» Address does or does not cause virtual address fault and protection violation
  • Normal load instruction
    • Faulting register prefetch instruction
  • Non faulting instructions turn into no-op if they were to cause a fault

Prefetching

  • Prefetch is made semantically invisible to a

program

  • Lockup-free (nonblocking) Cache
    • Processor can proceed while the prefetched data are being fetched
    • Cache continues to supply instructions and data while waiting for the prefetched data to return

Page 7

Loop Fusion

/ Before / for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) a[i][j] = 1/b[i][j] * c[i][j]; for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) d[i][j] = a[i][j] + c[i][j];

/ After / for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) { a[i][j] = 1/b[i][j] * c[i][j]; d[i][j] = a[i][j] + c[i][j];}

Blocking

/ Before / for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) {r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][k]z[k][j];}; x[i][j] = r; };*

  • Two Inner Loops:
    • Read all NxN elements of z[]
    • Read N elements of 1 row of y[] repeatedly
    • Write N elements of 1 row of x[]

Blocking

x[ ] y[ ] z[ ]

Before blocking

Blocking

/ After / for (jj = 0; jj < N; jj = jj+B) for (kk = 0; kk < N; kk = kk+B) for (i = 0; i < N; i = i+1) for (j = jj; j < min(jj+B-1,N); j = j+1) {r = 0; for (k = kk; k < min(kk+B-1,N); k = k+1) { r = r + y[i][k]z[k][j];}; x[i][j] = x[i][j] + r; };*

Page 8

Blocking

x[ ] y[ ] z[ ]

After blocking

Blocking factor

From Hennessey, J.L. and D.A. Patterson, Computer Architecture: A Quantitative Approach, Second Edition,Copyright 1996, Morgan Kaufman Publishers, San Francisco, CA, All rights reserved

Summary

  • Reducing Miss Rate 1. Larger Block Size 2. Higher Set Associativity 3. Victim Cache 4. Pseudo-Associative Cache 5. Hardware Prefetching 6. Compiler-controlled Prefetching 7. Compiler Optimizations

CPUtime = IC Ɨ CPI (^) Execution + Memory^ accesses Instruction Ɨ Miss rate Ɨ Miss penalty

Ɨ Clock cycle time

Improving Cache Performance

  • Average memory-access time

= Hit time + Miss rate x Miss penalty

  • Improve performance by:

1. Reduce the miss rate,

2. Reduce the miss penalty, or

3. Reduce the time to hit in the cache.

Page 10

Fourth Technique:

Nonblocking caches to reduce stalls on

cache misses

  • Nonblocking cache - does not block on a

miss

  • Possibility
    • Hit under miss (requires at least out-of-order completion capability)
    • Hit under multiple misses (requires in addition a memory system that can service multiple misses simultaneously) Significantly increases complexity of cache controller

Nonblocking caches to reduce stalls on

cache misses

  • 8-KB direct-mapped
  • 32-bytes blocks
  • 16-clock-cycle miss penalty

Fifth Technique:

Second-level caches

Instruction cache

Second-level cache

Data cache

DRAM memory

Processor

L1 cache

L2 cache

  • L1 (first-level) cache: Optimized for fast hit time
  • L2 (second-level) cache: Optimized for high hit rate
  • Important concern: Inclusion property

Second-level caches

With 32-KB L1 cache

Average memory access time = Hit time (L1) + Miss rate (L1) x (Hit time (L2) + Miss rate (L2) x Miss penalty (L2)) Local Miss Rate : # of misses in cache divided by total # of accesses to this cache Global Miss Rate : # of misses divided by the total # of accesses generated by CPU

Page 11

How to Design Second-level Caches

  • Size
  • Associativity
  • Block size
  • Inclusion property

Summary

  • Techniques for reducing cache miss penalty
    • Giving priority to read misses over writes
    • Sub-block placement for reduced miss penalty
    • Early restart and critical work first
    • Nonblocking caches to reduce stalls on cache misses
    • Second-level caches

Improving Cache Performance

  • Average memory-access time

= Hit time + Miss rate x Miss penalty

  • Improve performance by:

1. Reduce the miss rate,

2. Reduce the miss penalty, or

3. Reduce the time to hit in the cache.

Reducing Hit Time

1. Small and Simple Caches

2. Avoiding Address Translation During

Indexing of the Cache

  • Using virtual caches
  • Accessing physical caches without address translation

3. Pipelining Writes for Write Hits

Page 13

Homonym problem

Solutions to homonym problem

1. Cache purging at each context switch

2. Using PID (process id) as an additional tag

Homonym problem

Synonym problem

process 1 reads from virtual page 100 process 1 reads from virtual page 200 process 1 writes 10 to virtual page 100 process 1 reads from virtual page 200

process 1 translation information

tag data

Synonym problem

Solutions to synonym problem

1. Hardware anti-aliasing

2. Alignment of synonyms (require all the

synonyms to be identical in the lower bits

of their virtual addresses assuming a

direct-mapped cache)

Page 14

Third Technique:

Pipelining Writes for Fast Write Hits

tag comparison

actual writing

tag comparison

tag comparison

actual writing

actual writing

Time

Write request i Write request i + 1

Write request i Write request i + 1

Write request i - 1

Write request i - 1

Pipelining Writes for Fast Write Hits

Summary of Cache Optimizations Summary of Cache Optimizations