36
CS136, Advanced Architecture Cache and Memory Performance

CS136, Advanced Architecture

  • Upload
    fritz

  • View
    48

  • Download
    2

Embed Size (px)

DESCRIPTION

CS136, Advanced Architecture. Cache and Memory Performance. Outline. 11 Advanced Cache Optimizations Memory Technology and DRAM optimizations Virtual Machines Xen VM: Design and Performance Conclusion. Why More on Memory Hierarchy?. Processor-Memory Performance Gap Growing. - PowerPoint PPT Presentation

Citation preview

Page 1: CS136, Advanced Architecture

CS136, Advanced Architecture

Cache and Memory Performance

Page 2: CS136, Advanced Architecture

CS136 2

Outline

• 11 Advanced Cache Optimizations• Memory Technology and DRAM optimizations• Virtual Machines• Xen VM: Design and Performance• Conclusion

Page 3: CS136, Advanced Architecture

CS136 3

Why More on Memory Hierarchy?

1

10

100

1,000

10,000

100,000

1980 1985 1990 1995 2000 2005 2010

Year

Performance

Memory

ProcessorProcessor-MemoryPerformance GapGrowing

Page 4: CS136, Advanced Architecture

CS136 4

Review: 6 Basic Cache Optimizations

• Reducing hit time1. Giving reads priority over writes

• E.g., read completes before earlier writes in write buffer2. Avoiding address translation during cache

indexing

• Reducing miss penalty3. Multilevel caches

• Reducing miss rate4. Larger block size (compulsory misses)5. Larger cache size (capacity misses)6. Higher associativity (conflict misses)

Page 5: CS136, Advanced Architecture

CS136 5

11 Advanced Cache Optimizations

• Reducing hit time1.Small and simple

caches2.Way prediction3.Trace caches

• Increasing cache bandwidth

4.Pipelined caches5.Multibanked caches6.Nonblocking caches

• Reducing Miss Penalty7. Critical word first8. Merging write buffers

• Reducing Miss Rate9. Compiler optimizations

• Reducing miss penalty or miss rate via parallelism

10.Hardware prefetching11.Compiler prefetching

Page 6: CS136, Advanced Architecture

CS136 6

1. Fast Hit times via Small and Simple Caches• Index tag memory and then compare ⇒takes time Small cache can help hit time since smaller memory

takes less time to index– E.g., L1 caches same size for 3 generations of AMD microprocessors:

K6, Athlon, and Opteron– Also L2 cache small enough to fit on chip with processor ⇒ avoids

time penalty of going off chip• Simple direct mapping

– Can overlap tag check with data transmission since no choice• Access time estimate for 90 nm using CACTI model 4.0

– Median ratios of access time relative to direct-mapped caches are 1.32, 1.39, and 1.43 for 2-way, 4-way, and 8-way caches

-

0.50

1.00

1.50

2.00

2.50

16 KB 32 KB 64 KB 128 KB 256 KB 512 KB 1 MB

Cache size

Acc

ess

time

(ns) 1-way 2-way 4-way 8-way

Page 7: CS136, Advanced Architecture

CS136 7

2. Fast Hit Times Via Way Prediction

• How to combine fast hit time of direct-mapped with lower conflict misses of 2-way SA cache?

• Way prediction: keep extra bits in cache to predict “way” (block within set) of next access

– Multiplexer set early to select desired block; only 1 tag comparison done that cycle (in parallel with reading data)

– Miss check other blocks for matches in next cycle

• Accuracy 85%• Drawback: CPU pipeline harder if hit variable

length

Hit Time

Way-Miss Hit Time Miss Penalty

Page 8: CS136, Advanced Architecture

CS136 8

3. Fast Hit Times Via Trace Cache (Pentium 4 Only; and Last Time?)• Find more instruction level parallelism?

How avoid translation from x86 to micro-ops? • Trace cache in Pentium 4

– Dynamic traces of executed instructions vs. static sequences from memory layout

» Built-in branch predictor– Cache micro-ops instead of x86 instructions

» Decode/translate from x86 to micro-ops on trace miss

• Utilizes long instruction blocks better (don’t enter or exit in middle)

• Complicated address mapping (addresses no longer aligned to nice multiples of word size)

• Instructions can appear many times in multiple dynamic traces due to different branch outcomes

Page 9: CS136, Advanced Architecture

CS136 9

4: Increasing Cache Bandwidth by Pipelining• Pipeline cache access to maintain bandwidth (but

higher latency)• Instruction cache pipeline stages:

1: Pentium2: Pentium Pro through Pentium III 4: Pentium 4

⇒Greater penalty on mispredicted branches ⇒More clock cycles between issue of load and use

of data

Page 10: CS136, Advanced Architecture

CS136 10

5. Increasing Cache Bandwidth: Non-Blocking Caches• Non-blocking or lockup-free cache allows

continued cache hits during miss– Requires F/E bits on registers or out-of-order execution– Requires multi-bank memories

• Hit under miss reduces effective miss penalty by working during miss vs. ignoring CPU requests

• Hit under multiple miss or miss under miss further lowers effective miss penalty by overlapping multiple misses

– Significantly increases complexity of cache controller since can be many outstanding memory accesses

– Requires multiple memory banks– Penium Pro allows 4 outstanding memory misses

Page 11: CS136, Advanced Architecture

CS136 11

Value of Hit Under Miss for SPEC (Old Data)

• 8 KB Data Cache, Direct Mapped, 32B block, 16 cycle miss, SPEC 92• FP programs on average: AMAT= 0.68 -> 0.52 -> 0.34 -> 0.26• Int programs on average: AMAT= 0.24 -> 0.20 -> 0.19 -> 0.19

Hit Under i Misses

Avg.

Mem

. Acc

ess

Tim

e

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

1.8

2

eqnt

ott

espr

esso

xlisp

com

pres

s

mdl

jsp2 ear

fppp

pto

mca

tv

swm

256

dodu

csu

2cor

wave

5

mdl

jdp2

hydr

o2d

alvi

nn

nasa

7sp

ice2g

6or

a

0->1

1->2

2->64

Base

Integer Floating Point

“Hit under n Misses”

0->11->22->64Base

Page 12: CS136, Advanced Architecture

CS136 12

6: Increasing Cache Bandwidth Via Multiple Banks• Rather than treating cache as single monolithic

block, divide into independent banks to support simultaneous accesses

– E.g., T1 (“Niagara”) L2 has 4 banks

• Works best when accesses naturally spread across banks mapping of addresses to banks affects behavior of memory system

• Simple mapping that works well is sequential interleaving

– Spread block addresses sequentially across banks– E,g, bank i has all blocks with address i modulo n

Page 13: CS136, Advanced Architecture

CS136 13

7. Reduce Miss Penalty: Early Restart and Critical Word First• Don’t wait for full block before restarting CPU• Early restart—As soon as requested word of

block arrives, send to CPU and continue execution

– Spatial locality tend to want next sequential word, so may still pay to get that one

• Critical Word First—Request missed word from memory first, send it to CPU right away; let CPU continue while filling rest of block

– Long blocks more popular today Critical Word 1st widely used

block

Page 14: CS136, Advanced Architecture

CS136 14

8. Merging Write Bufferto Reduce Miss Penalty• Write buffer lets processor continue while

waiting for write to complete• If buffer contains modified blocks, addresses can

be checked to see if new data matches that of some write buffer entry

• If so, new data combined with that entry• For sequential writes in write-through caches,

increases block size of write (more efficient)• Sun T1 (Niagara) and many others use write

merging

Page 15: CS136, Advanced Architecture

CS136 15

9. Reducing Missesby Compiler Optimizations• McFarling [1989] reduced misses by 75% in

software on 8KB direct-mapped cache, 4 byte blocks

• Instructions– Reorder procedures in memory to reduce conflict misses– Profiling to look at conflicts (using tools they developed)

• Data– Merging arrays: Improve spatial locality by single array of

compound elements vs. 2 arrays– Loop interchange: Change nesting of loops to access data in

memory order– Loop fusion: Combine 2 independent loops that have same

looping and some variable overlap– Blocking: Improve temporal locality by accessing blocks of

data repeatedly vs. going down whole columns or rows

Page 16: CS136, Advanced Architecture

CS136 16

Merging Arrays Example

/* Before: 2 sequential arrays */int val[SIZE];int key[SIZE];

/* After: 1 array of structures */struct merge {

int val;int key;

};struct merge merged_array[SIZE];

Reduce conflicts between val & key; improve spatial locality

Page 17: CS136, Advanced Architecture

CS136 17

Loop Interchange Example

/* Before */for (k = 0; k < 100; k = k+1)

for (j = 0; j < 100; j = j+1)for (i = 0; i < 5000; i = i+1)x[i][j] = 2 * x[i][j];

/* After */for (k = 0; k < 100; k = k+1)

for (i = 0; i < 5000; i = i+1)for (j = 0; j < 100; j = j+1)x[i][j] = 2 * x[i][j];

Sequential accesses instead of striding through memory every 100 words; improved spatial locality

Page 18: CS136, Advanced Architecture

CS136 18

Loop Fusion Example

/* 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];}

2 misses per access to a & c vs. one miss per access; improve spatial locality

Page 19: CS136, Advanced Architecture

CS136 19

Blocking Example/* 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[]

• Capacity misses a function of N & Cache Size:– 2N3 + N2 => (assuming no conflict; otherwise …)

• Idea: compute on BxB submatrix that fits

Page 20: CS136, Advanced Architecture

CS136 20

Blocking Example

/* 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;};

• B called Blocking Factor• Capacity misses from 2N3 + N2 to 2N3/B +N2

• Reduce conflict misses Too?

Page 21: CS136, Advanced Architecture

CS136 21

Reducing Conflict Misses by Blocking

• Conflict misses in caches not FA vs. Blocking size– Lam et al [1991]: Blocking factor of 24 had 1/5 the misses vs. 48

despite both fitting in cache

Blocking Factor

Mis

s Ra

te

0

0.05

0.1

0 50 100 150

Fully Associative Cache

Direct Mapped Cache

Page 22: CS136, Advanced Architecture

CS136 22

Performance Improvement 1 1.5 2 2.5 3

compress

cholesky(nasa7)

spicemxm (nasa7)btrix (nasa7)

tomcatvgmty (nasa7)

vpenta (nasa7)

mergedarrays

loopinterchange

loop fusion blocking

Summary of Compiler Optimizations to Reduce Cache Misses (by hand)

Page 23: CS136, Advanced Architecture

CS136 23

10. Reducing Misses by Hardware Prefetching of Instructions & Data

• Prefetching relies on having extra memory bandwidth that can be used without penalty

• Instruction prefetching– Typically, CPU fetches 2 blocks on miss: requested and next – Requested block goes in instruction cache, prefetched goes in instruction

stream buffer• Data prefetching

– Pentium 4 can prefetch data into L2 cache from up to 8 streams from 8 different 4 KB pages

– Prefetching invoked if 2 successive L2 cache misses to a page, if distance between those cache blocks is < 256 bytes

1.16

1.45

1.18 1.20 1.21 1.26 1.29 1.32 1.40 1.49

1.97

1.001.201.401.601.802.002.20

Per

form

ance

Impr

ovem

ent

SPECint2000 SPECfp2000

Page 24: CS136, Advanced Architecture

CS136 24

11. Reducing Misses by Software Prefetching Data• Data prefetch

– Load data into register (HP PA-RISC loads)– Cache prefetch: load into cache

(MIPS IV, PowerPC, SPARC v. 9)– Special prefetching instructions cannot cause faults; form of

speculative execution

• Prefetch instructions take time– Is cost of prefetch issues < savings in reduced misses?– Higher superscalar reduces problem of issue bandwidth

Page 25: CS136, Advanced Architecture

CS136 25

Compiler Optimization vs. Memory Hierarchy Search

• Compiler tries to figure out memory hierarchy optimizations

• New approach: “Auto-tuners”– Run variations of program to find best combinations of

optimizations (blocking, padding, …) and algorithms– Then produce C code for that computer

• “Auto-tuner” targeted to numerical method– E.g., PHiPAC (BLAS), Atlas (BLAS),

Sparsity (Sparse linear algebra), Spiral (DSP), FFT-W

Page 26: CS136, Advanced Architecture

CS136 26

Reference

Best: 4x2

Mflop/s

Mflop/s

Sparse Matrix – Search for Blockingfor finite element problem [Im, Yelick, Vuduc, 2005]

Page 27: CS136, Advanced Architecture

CS136 27

Best Sparse Blocking for 8 Computers

• All possible column block sizes selected across the 8; how could compiler know?

Intel Pentium M

Sun Ultra 2, Sun Ultra 3,

AMD Opteron

IBM Power 4, Intel/HP Itanium

Intel/HP Itanium 2

IBM Power 3

8

4

2

1

1 2 4 8

row

blo

ck s

ize

(r)

column block size (c)

Page 28: CS136, Advanced Architecture

CS136 28

Technique Hit Time

Band-width

Miss penalty

Miss rate

HW cost/ complexity Comment

Small and simple caches + – 0 Trivial; widely used

Way-predicting caches + 1 Used in Pentium 4

Trace caches + 3 Used in Pentium 4

Pipelined cache access – + 1 Widely used

Nonblocking caches + + 3 Widely used

Banked caches + 1Used in L2 of Opteron and Niagara

Critical word first and early restart + 2 Widely used

Merging write buffer + 1Widely used with write through

Compiler techniques to reduce cache misses + 0

Software is a challenge; some computers have compiler option

Hardware prefetching of instructions and data + +

2 instr., 3 data

Many prefetch instructions; AMD Opteron prefetches data

Compiler-controlled prefetching + + 3

Needs nonblocking cache; in many CPUs

Page 29: CS136, Advanced Architecture

CS136 29

Main-Memory Background

• Performance of Main Memory: – Latency: cache miss penalty

» Access time: time between request and when word arrives» Cycle time: time between requests

– Bandwidth: I/O & large block miss penalty (L2)

• Main Memory is DRAM: Dynamic Random Access Memory

– Dynamic since needs to be refreshed (8 ms, 1% time)– Addresses divided into 2 halves (memory as 2D matrix):

» RAS or Row Access Strobe» CAS or Column Access Strobe

• Cache uses SRAM: Static Random Access Memory– No refresh (6 transistors/bit vs. 1 transistor)

Size: DRAM/SRAM ~ 4-8, Cost/cycle time: SRAM/DRAM ~ 8-16

Page 30: CS136, Advanced Architecture

CS136 30

Main Memory Deep Background

• “Out-of-Core”, “In-Core,” “Core Dump”?• “Core memory”?• Non-volatile, magnetic• Lost to 4 Kbit DRAM (today using 512Mbit DRAM)• Access time 750 ns, cycle time 1500-3000 ns

Page 31: CS136, Advanced Architecture

CS136 31

DRAM logical organization (4 Mbit)

• Square root of bits per RAS/CAS

Column Decoder

Sense Amps & I/O

Memory Array(2,048 x 2,048)

A0…A10

…11 D

Q

Word LineStorage

Cell

Page 32: CS136, Advanced Architecture

CS136 32

Quest for DRAM Performance

1. Fast Page mode – Add timing signals to allow repeated accesses to row buffer

without another row access time– Easy, since array buffers 1024-2048 bits for each access

2. Synchronous DRAM (SDRAM)– Add clock signal to DRAM interface so repeated transfers

don’t pay overhead to synchronize with controller3. Double Data Rate (DDR SDRAM)

– Transfer data on rising and falling edges of clock, doubling peak data rate

– DDR2 lowers power by dropping voltage from 2.5 to 1.8 volts, and offers higher clock rates: up to 400 MHz

– DDR3 drops to 1.5 volts and raises clock rates to 800 MHz• Improved bandwidth, not latency

Page 33: CS136, Advanced Architecture

CS136 33

DRAM Named by Peak Chip Xfers / SecDIMM Named by Peak DIMM MBytes / Sec

Stan-dard

Clock Rate (MHz)

M transfers / second

DRAM Name

Mbytes/s/ DIMM

DIMM Name

DDR 133 266 DDR266 2128 PC2100

DDR 150 300 DDR300 2400 PC2400

DDR 200 400 DDR400 3200 PC3200

DDR2 266 533 DDR2-533 4264 PC4300

DDR2 333 667 DDR2-667 5336 PC5300

DDR2 400 800 DDR2-800 6400 PC6400

DDR3 533 1066 DDR3-1066 8528 PC8500

DDR3 666 1333 DDR3-1333 10664 PC10700

DDR3 800 1600 DDR3-1600 12800 PC12800x 2 x 8

Fast

est f

or s

ale

4/06

($12

5/G

B)

Page 34: CS136, Advanced Architecture

CS136 34

Need for Error Correction!

• Motivation:– Failures/time ` to number of bits!– As DRAM cells shrink, more vulnerable

• Went through period when failure rate was low enough to ignore error correction

– Servers always corrected memory systems– Even desktop DRAM banks too large now

• Basic idea: add redundancy through parity bits– Common configuration: Random error correction

» SEC-DED (single error correct, double error detect)» One example: 64 data bits + 8 parity bits (11% overhead)

– Really want to handle physical component failures as well» Organization is multiple DRAMs/DIMM, multiple DIMMs» Want to recover from failed DRAM and failed DIMM!» “Chip kill” to handle failures width of single DRAM chip

Page 35: CS136, Advanced Architecture

CS136 35

Basics of Error Correction

• Parity (XOR of all bits) can detect one flipped bit• Identifying which takes minimum of log2 word

size bits (why?)• Hamming’s insight: Now XOR top 16 only ⇒ can

tell whether flipped bit is in top or bottom half

• Now XOR top 8 of top 16, also top 8 of bottom 16 ⇒ can tell which byte it’s in

• End result: can identify individual bit, and if properly arranged, incorrect XORs give index of bit to invert!

Page 36: CS136, Advanced Architecture

CS136 36

Fancier Error Correction

• Based on serious math (groups and fields)• Basic idea: each valid word is coordinate in n-

space– E.g., 32-space for 32-bit word

• Append k correction bits to place word into (n+k)-space

– Ensure valid words are “far” from each other in larger space– Errors perturb position in space– Correction simply involves finding closest “legal” point

• State of the art has focused on burst errors, e.g., 17 consecutive bits incorrect

– Caused by noise bursts in communication or on disk– Not as relevant to memory

• Slight variations needed for modern memory