29
CS 152 Computer Architecture and Engineering Lecture 6 - Memory Krste Asanovic Electrical Engineering and Computer Sciences University of California at Berkeley http://www.eecs.berkeley.edu/~krste http://inst.eecs.berkeley.edu/~cs 152

L06 Memory

Embed Size (px)

Citation preview

Page 1: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 1/29

CS 152 Computer Architecture andEngineering

Lecture 6 - Memory

Krste Asanovic

Electrical Engineering and Computer SciencesUniversity of California at Berkeley

http://www.eecs.berkeley.edu/~krste

http://inst.eecs.berkeley.edu/~cs152

Page 2: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 2/29

2/10/2009 CS152-Spring’09 2

Last time in Lecture 5

• Control hazards (branches, interrupts) are mostdifficult to handle as they change which instructionshould be executed next

• Speculation commonly used to reduce effect of control hazards (predict sequential fetch, predict no

exceptions)• Branch delay slots make control hazard visible to

software

• Precise exceptions: stop cleanly on one instruction,

all previous instructions completed, no followinginstructions have changed architectural state

• To implement precise exceptions in pipeline, shiftfaulting instructions down pipeline to “commit” point,where exceptions are handled in program order 

Page 3: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 3/29

2/10/2009 CS152-Spring’09 3

CPU-Memory Bottleneck

MemoryCPU

Performance of high-speed computers is usually

limited by memory bandwidth & latency 

• Latency (time for a single access)Memory access time >> Processor cycle time

• Bandwidth (number of accesses per unit time)if fraction m of instructions access memory,

⇒1+m memory references / instruction

⇒CPI = 1 requires 1+m memory refs / cycle

(assuming MIPS RISC ISA)

Page 4: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 4/29

2/10/2009 CS152-Spring’09 4

Core Memory• Core memory was first large scale reliable main memory

 – invented by Forrester in late 40s/early 50s at MIT for Whirlwind project

• Bits stored as magnetization polarity on small ferrite coresthreaded onto 2 dimensional grid of wires

• Coincident current pulses on X and Y wires would write cell

and also sense original state (destructive reads)

DEC PDP-8/E Board,

4K words x 12 bits, (1968)

• Robust, non-volatile storage

• Used on space shuttle computersuntil recently

• Cores threaded onto wires by

hand (25 billion a year at peakproduction)

• Core access time ~ 1µ s

Page 5: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 5/29

2/10/2009 CS152-Spring’09 5

Semiconductor Memory, DRAM

• Semiconductor memory began to be competitive in early1970s

 – Intel formed to exploit market for semiconductor memory

•First commercial DRAM was Intel 1103 – 1Kbit of storage on single chip

 – charge on a capacitor used to hold value

• Semiconductor memory quickly replaced core in ‘70s

Page 6: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 6/29

2/10/2009 CS152-Spring’09 6

One Transistor Dynamic RAM

TiN top electrode (VREF )

Ta2O

5dielectric

W bottomelectrode

polywordline

access

transistor

1-T DRAM Cell

word

bit

access transistor

Storagecapacitor (FET gate,trench, stack)

VREF

Page 7: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 7/292/10/2009 CS152-Spring’09 7

DRAM Architecture

Ro

w

Ad

dress

De

coder

Col.

1

Col.

2M

Row 1

Row 2N

Column Decoder & Sense Amplifiers

M

N

N+M

bit linesword lines

Memory cell(one bit)

DData

• Bits stored in 2-dimensional arrays on chip

• Modern chips have around 4 logical banks on each chip

– each logical bank physically implemented as many smaller arrays

Page 8: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 8/292/10/2009 CS152-Spring’09 8

DRAM Packaging

• DIMM (Dual Inline Memory Module) containsmultiple chips with clock/control/address signalsconnected in parallel (sometimes need buffers

to drive signals to all chips)• Data pins work together to return wide word

(e.g., 64-bit data bus using 16x4-bit parts)

Address lines multiplexedrow/column address

Clock and control signals

Data bus(4b,8b,16b,32b)

DRAMchip~12

~7

Page 9: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 9/292/10/2009 CS152-Spring’09 9

DRAM OperationThree steps in read/write access to a given bank•

Row access (RAS) – decode row address, enable addressed row (often multiple Kb in row) – bitlines share charge with storage cell – small change in voltage detected by sense amplifiers which latch whole

row of bits – sense amplifiers drive bitlines full rail to recharge storage cells

• Column access (CAS) – decode column address to select small number of sense amplifier 

latches (4, 8, 16, or 32 bits depending on DRAM package) – on read, send latched bits out to chip pins – on write, change sense amplifier latches which then charge storage

cells to required value – can perform multiple column accesses on same row without another 

row access (burst mode)• Precharge

 – charges bit lines to known value, required before next row access

Each step has a latency of around 15-20ns in modern DRAMsVarious DRAM standards (DDR, RDRAM) have different ways of encoding the

signals for transmission to the DRAM, but all share same core architecture

Page 10: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 10/292/10/2009 CS152-Spring’09 10

Double-Data Rate (DDR2) DRAM

[ Micron, 256Mb DDR2 SDRAM datasheet ] 

Row Column Precharge Row’

Data

200MHz

Clock

400Mb/s

Data Rate

Page 11: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 11/292/10/2009 CS152-Spring’09 11

Processor-DRAM Gap (latency)

Time

µProc 60%/year

DRAM7%/year

1

10

100

1000

1980

1981

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

DRAM

CPU

1982

Processor-MemoryPerformance Gap:(grows 50% / year)

Perfo

rm

ance  “Moore’s Law” 

Four-issue 2GHz superscalar accessing 100ns DRAM could

execute 800 instructions during time for one memory access!

Page 12: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 12/292/10/2009 CS152-Spring’09

Typical Memory Reference Patterns

Address

Time

Instruction

fetches

Stack

accesses

Data

accesses

n loop iterations

subroutine

callsubroutine

return

argument access

  v e c t o r

  a c c e

 s s

scalar accesses

Page 13: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 13/292/10/2009 CS152-Spring’09

Common Predictable Patterns

Two predictable properties of memory references:

 – Temporal Locality: If a location is referenced it is

likely to be referenced again in the near future.

 – Spatial Locality: If a location is referenced it is likelythat locations near it will be referenced in the near 

future.

Page 14: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 14/29

Memory Reference Patterns

Donald J. Hatfield, Jeanette Gerald: Program

Restructuring for Virtual Memory. IBM Systems Journal10(3): 168-192 (1971)

Time

M  e  m

  o  r  yAdd

  r  e  s  s(  o

  n  ed

  ot

  p  e  r  a  c  c  e  s  s)

SpatialLocality

Temporal

Locality

Page 15: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 15/292/10/2009 CS152-Spring’09

Multilevel Memory

Strategy: Reduce average latency using small, fastmemories called caches.

Caches are a mechanism to reduce memorylatency based on the empirical observation thatthe patterns of memory references made by a

processor are often highly predictable:  PC  

… 96 

loop: ADD r2, r1, r1 100 

SUBI r3, r3, #1 104BNEZ r3, loop 108 

…  112 

Page 16: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 16/292/10/2009 CS152-Spring’09 16

Memory Hierarchy

Small,Fast

Memory(RF, SRAM)

• capacity : Register << SRAM << DRAM why? • latency: Register << SRAM << DRAM why? • bandwidth: on-chip >> off-chip why? 

On a data access:hit (data ∈ fast memory) ⇒ low latency accessmiss (data ∉ fast memory) ⇒ long latency access (DRAM)

CPUBig, SlowMemory(DRAM)

A B

holds frequently used data

Page 17: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 17/292/10/2009 CS152-Spring’09 17

Relative Memory Cell Sizes

QuickTimeª and a TIFF (Uncompressed) decompressor

are needed to see this picture.

[ Foss, “Implementing 

 Application-Specific 

Memory”, ISSCC 1996 ] 

QuickTimeª and a TIFF (Uncompressed) decompressor

are needed to see this picture.

DRAM on

memory chip

On-Chip

SRAM inlogic chip

Page 18: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 18/292/10/2009 CS152-Spring’09 18

Management of Memory Hierarchy

•Small/fast storage, e.g., registers – Address usually specified in instruction

 – Generally implemented directly as a register file

» but hardware might do things behind software’s back, e.g.,stack management, register renaming

• Large/slower storage, e.g., memory

 – Address usually computed from values in register 

 – Generally implemented as a cache hierarchy» hardware decides what is kept in fast memory

» but software may provide “hints”, e.g., don’t cache or prefetch

Page 19: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 19/292/10/2009 CS152-Spring’09 19

CS152 Administrivia

• Quiz 1 Thursday in class (306 Soda) – Lectures 1-5, closed book, no calculators or computers

• Krste, special office hours, Wednesday 2/11, 2-3pm,579 Soda Hall (Par Lab)

• Scott special office hours, Wednesday 2/11, 4-5pm,711 Soda Hall

• Next week lecture 2/17 back in 320 Soda

Page 20: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 20/292/10/2009 CS152-Spring’09

Caches

Caches exploit both types of predictability:

 – Exploit temporal locality by remembering the

contents of recently accessed locations.

 – Exploit spatial locality by fetching blocks of dataaround recently accessed locations.

Page 21: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 21/292/10/2009 CS152-Spring’09

Inside a Cache

CACHEProcessor MainMemory

Address Address

DataData

AddressTag

Data Block

DataByte

DataByte

DataByte

Line100

304

6848

copy of main

memorylocation 100

copy of main

memorylocation 101

416

Page 22: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 22/292/10/2009 CS152-Spring’09

Cache Algorithm (Read)

Look at Processor Address, search cache tags to find match. Theneither 

Found in cachea.k.a. HIT

Return copyof data fromcache

Not in cachea.k.a. MISS

Read block of data fromMain Memory

Wait …

Return data to processorand update cache

Q: Which line do we replace?

Page 23: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 23/292/10/2009 CS152-Spring’09 23

Placement Policy

0 1 2 3 4 5 6 70 1 2 3Set Number

Cache

Fully (2-way) Set DirectAssociative Associative Mappedanywhere anywhere in only into

set 0 block 4  (12 mod 4) (12 mod 8)

0 1 2 3 4 5 6 7 8 9

1 1 1 1 1 1 1 1 1 1

0 1 2 3 4 5 6 7 8 9

2 2 2 2 2 2 2 2 2 2

0 1 2 3 4 5 6 7 8 9

3 3

0 1

Memory

Block Number

block 12can be placed

Page 24: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 24/29

2/10/2009 CS152-Spring’09

Direct-Mapped Cache

Tag Data BlockV

=

Block

OffsetTag Index

tk b

t

HIT Data Word or Byte

2k

lines

Page 25: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 25/29

2/10/2009 CS152-Spring’09

Direct Map Address Selectionhigher-order vs. lower-order address bits

Tag Data BlockV

=

Block

OffsetIndex

tkb

t

HIT Data Word or Byte

2k

lines

Tag

Page 26: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 26/29

2/10/2009 CS152-Spring’09

2-Way Set-Associative Cache

Tag Data BlockV

=

Block

OffsetTag Index

tk

b

HIT

 

Tag Data BlockV

DataWordor Byte

=

t

Page 27: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 27/29

2/10/2009 CS152-Spring’09

Fully Associative Cache

 

Tag Data BlockV

=

Block

Offset

Tag

t

b

HIT

DataWordor Byte

 =

 =

t

Page 28: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 28/29

2/10/2009 CS152-Spring’09 28

Replacement Policy

In an associative cache, which block from a set

should be evicted when the set becomes full?

• Random

• Least Recently Used (LRU)

• LRU cache state must be updated on every access• true implementation only feasible for small sets (2-way)• pseudo-LRU binary tree often used for 4-8 way

• First In, First Out (FIFO) a.k.a. Round-Robin• used in highly associative caches

• Not Least Recently Used (NLRU)• FIFO with exception for most recently used block or blocks

This is a second-order effect. Why? 

Replacement only happens on misses

Page 29: L06 Memory

8/4/2019 L06 Memory

http://slidepdf.com/reader/full/l06-memory 29/29

Acknowledgements

• These slides contain material developed and

copyright by: – Arvind (MIT)

 – Krste Asanovic (MIT/UCB)

 – Joel Emer (Intel/MIT)

 – James Hoe (CMU)

 – John Kubiatowicz (UCB)

 – David Patterson (UCB)

• MIT material derived from course 6.823

• UCB material derived from course CS252