CENG 3420 Computer Organization and Design. Lecture 08: Memory - I. Bei Yu

Similar documents
CSE 431 Computer Architecture Fall Chapter 5A: Exploiting the Memory Hierarchy, Part 1

CENG 3420 Computer Organization and Design. Lecture 08: Cache Review. Bei Yu

EE 4683/5683: COMPUTER ARCHITECTURE

Page 1. Memory Hierarchies (Part 2)

CSF Improving Cache Performance. [Adapted from Computer Organization and Design, Patterson & Hennessy, 2005]

Course Administration

CS3350B Computer Architecture

ECE7995 (4) Basics of Memory Hierarchy. [Adapted from Mary Jane Irwin s slides (PSU)]

ECE7995 (6) Improving Cache Performance. [Adapted from Mary Jane Irwin s slides (PSU)]

14:332:331. Week 13 Basics of Cache

CSF Cache Introduction. [Adapted from Computer Organization and Design, Patterson & Hennessy, 2005]

EEC 170 Computer Architecture Fall Improving Cache Performance. Administrative. Review: The Memory Hierarchy. Review: Principle of Locality

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

EEC 170 Computer Architecture Fall Cache Introduction Review. Review: The Memory Hierarchy. The Memory Hierarchy: Why Does it Work?

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 6: Memory Organization Part I

Improving Cache Performance

CS 61C: Great Ideas in Computer Architecture (Machine Structures)

Instructors: Randy H. Katz David A. PaGerson hgp://inst.eecs.berkeley.edu/~cs61c/fa10. 10/4/10 Fall Lecture #16. Agenda

14:332:331. Week 13 Basics of Cache

CS 61C: Great Ideas in Computer Architecture. Direct Mapped Caches

Memory Hierarchy. ENG3380 Computer Organization and Architecture Cache Memory Part II. Topics. References. Memory Hierarchy

Review: Performance Latency vs. Throughput. Time (seconds/program) is performance measure Instructions Clock cycles Seconds.

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Improving Cache Performance

ELEC 5200/6200 Computer Architecture and Design Spring 2017 Lecture 7: Memory Organization Part II

Adapted from instructor s supplementary material from Computer. Patterson & Hennessy, 2008, MK]

Caches Part 1. Instructor: Sören Schwertfeger. School of Information Science and Technology SIST

CS3350B Computer Architecture

Textbook: Burdea and Coiffet, Virtual Reality Technology, 2 nd Edition, Wiley, Textbook web site:

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2

CS 61C: Great Ideas in Computer Architecture. The Memory Hierarchy, Fully Associative Caches

CMPT 300 Introduction to Operating Systems

CENG3420 Lecture 08: Memory Organization

CS 61C: Great Ideas in Computer Architecture (Machine Structures)

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

Memory Hierarchy Design (Appendix B and Chapter 2)

Agenda. Recap: Components of a Computer. Agenda. Recap: Cache Performance and Average Memory Access Time (AMAT) Recap: Typical Memory Hierarchy

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 1

EECS151/251A Spring 2018 Digital Design and Integrated Circuits. Instructors: John Wawrzynek and Nick Weaver. Lecture 19: Caches EE141

The Memory Hierarchy & Cache Review of Memory Hierarchy & Cache Basics (from 350):

Memory Hierarchy Technology. The Big Picture: Where are We Now? The Five Classic Components of a Computer

Agenda. Cache-Memory Consistency? (1/2) 7/14/2011. New-School Machine Structures (It s a bit more complicated!)

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

Recap: Machine Organization

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 3

10/19/17. You Are Here! Review: Direct-Mapped Cache. Typical Memory Hierarchy

CpE 442. Memory System

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

ECE468 Computer Organization and Architecture. Memory Hierarchy

Transistor: Digital Building Blocks

CS161 Design and Architecture of Computer Systems. Cache $$$$$

Memory Technologies. Technology Trends

EN1640: Design of Computing Systems Topic 06: Memory System

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

ECE232: Hardware Organization and Design

Memory Hierarchy Y. K. Malaiya

CPS101 Computer Organization and Programming Lecture 13: The Memory System. Outline of Today s Lecture. The Big Picture: Where are We Now?

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 3

CS 61C: Great Ideas in Computer Architecture Caches Part 2

The Memory Hierarchy. Cache, Main Memory, and Virtual Memory (Part 2)

Memory. Lecture 22 CS301

Modern Computer Architecture

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2

CS152 Computer Architecture and Engineering Lecture 17: Cache System

Chapter 7 Large and Fast: Exploiting Memory Hierarchy. Memory Hierarchy. Locality. Memories: Review

CS152 Computer Architecture and Engineering Lecture 16: Memory System

Memory Hierarchy: Caches, Virtual Memory

Computer Architecture Computer Science & Engineering. Chapter 5. Memory Hierachy BK TP.HCM

Chapter Seven. Large & Fast: Exploring Memory Hierarchy

The Memory Hierarchy & Cache

CPE 631 Lecture 04: CPU Caches

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface. 5 th. Edition. Chapter 5. Large and Fast: Exploiting Memory Hierarchy

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

COEN-4730 Computer Architecture Lecture 3 Review of Caches and Virtual Memory

CS 61C: Great Ideas in Computer Architecture. Cache Performance, Set Associative Caches

Chapter 5 Large and Fast: Exploiting Memory Hierarchy (Part 1)

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Memory Technology. Caches 1. Static RAM (SRAM) Dynamic RAM (DRAM) Magnetic disk. Ideal memory. 0.5ns 2.5ns, $2000 $5000 per GB

10/16/17. Outline. Outline. Typical Memory Hierarchy. Adding Cache to Computer. Key Cache Concepts

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2

LECTURE 11. Memory Hierarchy

Memory Technology. Chapter 5. Principle of Locality. Chapter 5 Large and Fast: Exploiting Memory Hierarchy 1

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Lecture 12. Memory Design & Caches, part 2. Christos Kozyrakis Stanford University

Memory Hierarchies. Instructor: Dmitri A. Gusev. Fall Lecture 10, October 8, CS 502: Computers and Communications Technology

COMPUTER ORGANIZATION AND DESIGN The Hardware/Software Interface

CPU issues address (and data for write) Memory returns data (or acknowledgment for write)

Memory Hierarchy. Reading. Sections 5.1, 5.2, 5.3, 5.4, 5.8 (some elements), 5.9 (2) Lecture notes from MKP, H. H. Lee and S.

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

COSC3330 Computer Architecture Lecture 19. Cache

EN1640: Design of Computing Systems Topic 06: Memory System

The Memory Hierarchy & Cache The impact of real memory on CPU Performance. Main memory basic properties: Memory Types: DRAM vs.

Page 1. Multilevel Memories (Improving performance using a little cash )

Advanced Memory Organizations

Transcription:

CENG 3420 Computer Organization and Design Lecture 08: Memory - I Bei Yu CEG3420 L08.1 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.2 Spring 2016

Review: Major Components of a Computer Processor Devices Control Memory Input Datapath Output Secondary Memory (Disk) Main Memory Cache CEG3420 L08.3 Spring 2016

Processor-Memory Performance Gap Moore s Law µproc 55%/year (2X/1.5yr) Processor-Memory Performance Gap (grows 50%/year) DRAM 7%/year (2X/10yrs) CEG3420 L08.4 Spring 2016

Memory Performance Impact on Performance q Suppose a processor executes at ideal CPI = 1.1 50% arith/logic, 30% ld/st, 20% control and that 10% of data memory operations miss with a 50 cycle miss penalty q EX: calculate practical CPI: q CPI = ideal CPI + average stalls per instruction = 1.1(cycle) + ( 0.30 (datamemops/instr) x 0.10 (miss/datamemop) x 50 (cycle/miss) ) = 1.1 cycle + 1.5 cycle = 2.6 so 58% of the time the processor is stalled waiting for memory! CEG3420 L08.5 Spring 2016

Memory Hierarchy q Fact: Large memories are slow and fast memories are small q How do we create a memory that gives the illusion of being large, cheap and fast (most of the time)? With hierarchy With parallelism CEG3420 L08.6 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.7 Spring 2016

A Typical Memory Hierarchy q Take advantage of the principle of locality to present the user with as much memory as is available in the cheapest technology at the speed offered by the fastest technology On-Chip Components Control Datapath RegFile ITLB DTLB Instr Data Cache Cache Second Level Cache (SRAM) Main Memory (DRAM) Secondary Memory (Disk) Speed (%cycles): ½ s 1 s 10 s 100 s 10,000 s Size (bytes): 100 s 10K s M s G s T s Cost: highest lowest CEG3420 L08.8 Spring 2016

The Memory Hierarchy: Why Does it Work? q Temporal Locality (locality in time) If a memory location is referenced then it will tend to be referenced again soon Keep most recently accessed data items closer to the processor q Spatial Locality (locality in space) If a memory location is referenced, the locations with nearby addresses will tend to be referenced soon Move blocks consisting of contiguous words closer to the processor CEG3420 L08.9 Spring 2016

Characteristics of the Memory Hierarchy Increasing distance from the processor in access time Processor L1$ L2$ Main Memory 4-8 bytes (word) 8-32 bytes (block) 1 to 4 blocks 1,024+ bytes (disk sector = page) Inclusive what is in L1$ is a subset of what is in L2$ is a subset of what is in MM that is a subset of is in SM Secondary Memory (Relative) size of the memory at each level CEG3420 L08.10 Spring 2016

The Memory Hierarchy: Terminology q Block (or line): the minimum unit of information that is present (or not) in a cache q Hit Rate: the fraction of memory accesses found in a level of the memory hierarchy Hit Time: Time to access that level which consists of Time to access the block + Time to determine hit/miss q Miss Rate: the fraction of memory accesses not found in a level of the memory hierarchy 1 - (Hit Rate) Miss Penalty: Time to replace a block in that level with the corresponding block from a lower level which consists of Time to access the block in the lower level + Time to transmit that block to the level that experienced the miss + Time to insert the block in that level + Time to pass the block to the requestor Hit Time << Miss Penalty CEG3420 L08.11 Spring 2016

How is the Hierarchy Managed? q registers memory by compiler (programmer?) q cache main memory by the cache controller hardware q main memory disks by the operating system (virtual memory) virtual to physical address mapping assisted by the hardware (TLB) by the programmer (files) CEG3420 L08.12 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.13 Spring 2016

Memory Hierarchy Technologies q Caches use SRAM for speed and technology compatibility Fast (typical access times of 0.5 to 2.5 nsec) Low density (6 transistor cells), higher power, expensive ($2000 to $5000 per GB in 2008) Static: content will last forever (as long as power is left on) q Main memory uses DRAM for size (density) High density (1 transistor cells), lower power, cheaper ($20 to $75 per GB in 2008) Dynamic: needs to be refreshed regularly (~ every 8 ms) - consumes1% to 2% of the active cycles of the DRAM Addresses divided into 2 halves (row and column) - RAS or Row Access Strobe triggering the row decoder - CAS or Column Access Strobe triggering the column selector CEG3420 L08.14 Spring 2016

Classical SRAM Organization bit (data) lines R o w D e c o d e r RAM Cell Array Each intersection represents a 6-T SRAM cell word (row) line row address Column Selector & I/O Circuits column address data bit or word One memory row holds a block of data, so the column address selects the requested bit or word from that block CEG3420 L08.15 Spring 2016

Classical SRAM Organization q Latch based memory Memory$Data$In WE Write$bitlines D D.$.$. D m SR-Latch Memory$WriteAddress n Write$Address$Decoder.$.$..$.$. D D D.$.$. D D.$.$. D Read$bitlines Read$word$line Write$word$line.$.$. Read$Address$Decoder n Memory$Read$Address D Q Gated D8latch WE m Memory$Data$Out CEG3420 L08.16 Spring 2016

Classical DRAM Organization bit (data) lines R o w D e c o d e r row address RAM Cell Array Column Selector & I/O Circuits data bit data bit data bit Each intersection represents a 1-T DRAM cell word (row) line column address The column address selects the requested bit from the row in each plane CEG3420 L08.17 Spring 2016

Classical DRAM Operation q DRAM Organization: N rows x N column x M-bit Column Address N cols Read or Write M-bit at a time Each M-bit access requires a RAS / CAS cycle N rows DRAM Row Address Cycle Time M-bit Output M bit planes 1 st M-bit Access 2 nd M-bit Access RAS CAS Row Address Col Address Row Address Col Address CEG3420 L08.18 Spring 2016

Page Mode DRAM Operation q Page Mode DRAM N x M SRAM to save a row Column Address N cols q After a row is read into the SRAM register Only CAS is needed to access other M-bit words on that row RAS remains asserted while CAS is toggled Cycle Time N rows DRAM N x M SRAM M-bit Output Row Address M bit planes 1 st M-bit Access 2 nd M-bit 3 rd M-bit 4 th M-bit RAS CAS Row Address Col Address Col Address Col Address Col Address CEG3420 L08.19 Spring 2016

DRAM Latency & Bandwidth Milestones (optional) DRAM Page DRAM FastPage DRAM FastPage DRAM Synch DRAM DDR SDRAM Module Width 16b 16b 32b 64b 64b 64b Year 1980 1983 1986 1993 1997 2000 Mb/chip 0.06 0.25 1 16 64 256 Die size (mm 2 ) 35 45 70 130 170 204 Pins/chip 16 16 18 20 54 66 BWidth (MB/s) 13 40 160 267 640 1600 Latency (nsec) 225 170 125 75 62 52 Patterson, CACM Vol 47, #10, 2004 q In the time that the memory to processor bandwidth doubles the memory latency improves by a factor of only 1.2 to 1.4 q To deliver such high bandwidth, the internal DRAM has to be organized as interleaved memory banks CEG3420 L08.20 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.21 Spring 2016

Memory Systems that Support Caches q The off-chip interconnect and memory architecture can affect overall system performance in dramatic ways on-chip CPU One word wide organization (one word wide bus and one word wide memory) q Assume 32-bit data & 32-bit addr per cycle Cache bus DRAM Memory q 1. 1 clock cycle to send the addr 2. 15 clock cycles to get the 1 st word in the block from DRAM, 5 clock cycles for 2 nd, 3 rd, 4 th words (column access time) 3. 1 clock cycle to return a word of data Memory-Bus to Cache bandwidth l number of bytes accessed from memory and transferred to cache/cpu per clock cycle CEG3420 L08.22 Spring 2016

One Word Wide Bus, One Word Blocks on-chip CPU Cache bus DRAM Memory q If the block size is one word, then for a memory access due to a cache miss, the pipeline will have to stall for the number of cycles required to return one data word from memory cycle to send address cycles to read DRAM cycle to return data total clock cycles miss penalty q Number of bytes transferred per clock cycle (bandwidth) for a single miss is bytes per memory bus clock cycle CEG3420 L08.23 Spring 2016

One Word Wide Bus, One Word Blocks on-chip CPU Cache bus DRAM Memory q If the block size is one word, then for a memory access due to a cache miss, the pipeline will have to stall for the number of cycles required to return one data word from memory 1 15 1 17 cycle to send address cycles to read DRAM cycle to return data total clock cycles miss penalty q Number of bytes transferred per clock cycle (bandwidth) for a single miss is 4/17 = 0.235 bytes per memory bus clock cycle CEG3420 L08.24 Spring 2016

One Word Wide Bus, Four Word Blocks on-chip CPU Cache bus q What if the block size is four words and each word is in a different DRAM row? cycle to send 1 st address cycles to read DRAM cycles to return last data word total clock cycles miss penalty DRAM Memory q Number of bytes transferred per clock cycle (bandwidth) for a single miss is bytes per clock CEG3420 L08.25 Spring 2016

One Word Wide Bus, Four Word Blocks on-chip CPU Cache q What if the block size is four words and each word is in a different DRAM row? 1 4 x 15 = 60 1 62 cycle to send 1 st address cycles to read DRAM cycles to return last data word total clock cycles miss penalty bus DRAM Memory 15 cycles 15 cycles 15 cycles 15 cycles q Number of bytes transferred per clock cycle (bandwidth) for a single miss is (4 x 4)/62 = 0.258 bytes per clock CEG3420 L08.26 Spring 2016

One Word Wide Bus, Four Word Blocks on-chip CPU Cache bus q What if the block size is four words and all words are in the same DRAM row? cycle to send 1 st address cycles to read DRAM cycles to return last data word total clock cycles miss penalty DRAM Memory q Number of bytes transferred per clock cycle (bandwidth) for a single miss is bytes per clock CEG3420 L08.27 Spring 2016

One Word Wide Bus, Four Word Blocks on-chip CPU Cache q What if the block size is four words and all words are in the same DRAM row? 1 15 + 3*5 = 30 1 32 cycle to send 1 st address cycles to read DRAM cycles to return last data word total clock cycles miss penalty bus DRAM Memory 15 cycles 5 cycles 5 cycles 5 cycles q Number of bytes transferred per clock cycle (bandwidth) for a single miss is (4 x 4)/32 = 0.5 bytes per clock CEG3420 L08.28 Spring 2016

Interleaved Memory, One Word Wide Bus on-chip CPU Cache q For a block size of four words cycle to send 1 st address cycles to read DRAM banks cycles to return last data word total clock cycles miss penalty bus DRAM DRAM DRAM DRAM Memory Memory Memory Memory bank 0 bank 1 bank 2 bank 3 q Number of bytes transferred per clock cycle (bandwidth) for a single miss is bytes per clock CEG3420 L08.29 Spring 2016

Interleaved Memory, One Word Wide Bus on-chip CPU Cache q For a block size of four words 1 15 + 3 = 18 1 20 cycle to send 1 st address cycles to read DRAM banks cycles to return last data word total clock cycles miss penalty bus DRAM DRAM DRAM DRAM Memory Memory Memory Memory bank 0 bank 1 bank 2 bank 3 15 cycles 15 cycles 15 cycles 15 cycles q Number of bytes transferred per clock cycle (bandwidth) for a single miss is (4 x 4)/20 = 0.8 bytes per clock CEG3420 L08.30 Spring 2016

Memory System Summary q Its important to match the cache characteristics caches access one block at a time (usually more than one word) q with the DRAM characteristics use DRAMs that support fast multiple word accesses, preferably ones that match the block size of the cache q with the memory-bus characteristics make sure the memory-bus can support the DRAM access rates and patterns with the goal of increasing the Memory-Bus to Cache bandwidth CEG3420 L08.31 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.32 Spring 2016

Cache Basics q Two questions to answer (in hardware): Q1: How do we know if a data item is in the cache? Q2: If it is, how do we find it? q Direct mapped Each memory block is mapped to exactly one block in the cache - lots of lower level blocks must share blocks in the cache Address mapping (to answer Q2): Have a tag associated with each cache block that contains the address information (the upper portion of the address) required to identify the block (to answer Q1) CEG3420 L08.33 Spring 2016

Caching: A Simple First Example Cache Index Valid 00 01 10 11 Tag Q1: Is it there? Data Compare the cache tag to the high order 2 memory address bits to tell if the memory block is in the cache 0000xx 0001xx 0010xx 0011xx 0100xx 0101xx 0110xx 0111xx 1000xx 1001xx 1010xx 1011xx 1100xx 1101xx 1110xx 1111xx Main Memory One word blocks Two low order bits define the byte in the word (32b words) Q2: How do we find it? Use next 2 low order memory address bits the index to determine which cache block (i.e., modulo the number of blocks in the cache) (block address) modulo (# of blocks in the cache) CEG3420 L08.34 Spring 2016

Caching: A Simple First Example Cache Index Valid 00 01 10 11 Tag Q1: Is it there? Data Compare the cache tag to the high order 2 memory address bits to tell if the memory block is in the cache 0000xx 0001xx 0010xx 0011xx 0100xx 0101xx 0110xx 0111xx 1000xx 1001xx 1010xx 1011xx 1100xx 1101xx 1110xx 1111xx Main Memory One word blocks Two low order bits define the byte in the word (32b words) Q2: How do we find it? Use next 2 low order memory address bits the index to determine which cache block (i.e., modulo the number of blocks in the cache) (block address) modulo (# of blocks in the cache) CEG3420 L08.35 Spring 2016

Direct Mapped Cache q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 1 2 3 4 3 4 15 0 1 2 3 4 3 4 15 CEG3420 L08.36 Spring 2016

Direct Mapped Cache q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 1 2 3 4 3 4 15 0 miss 1 miss 2 miss 3 miss 00 Mem(0) 00 Mem(0) 00 Mem(0) 00 Mem(0) 00 Mem(1) 00 Mem(1) 00 Mem(1) 00 Mem(2) 00 Mem(2) 00 Mem(3) 01 4 miss 3 hit 4 hit 15 miss 4 00 Mem(0) 01 Mem(4) 01 Mem(4) 01 Mem(4) 00 Mem(1) 00 Mem(1) 00 Mem(1) 00 Mem(1) 00 Mem(2) 00 Mem(2) 00 Mem(2) 00 Mem(2) 00 Mem(3) 00 Mem(3) 00 Mem(3) 11 00 Mem(3) 15 8 requests, 6 misses CEG3420 L08.37 Spring 2016

MIPS Direct Mapped Cache Example q One word blocks, cache size = 1K words (or 4KB) 31 30... 13 12 11... 2 1 0 Byte offset Hit Tag 20 Index 10 Data Index 0 1 2... 1021 1022 1023 Valid Tag 20 Data 32 What kind of locality are we taking advantage of? CEG3420 L08.38 Spring 2016

Multiword Block Direct Mapped Cache q Four words/block, cache size = 1K words Hit 31 30... 13 12 11... 4 3 2 1 0 Byte offset Data Tag 20 Index 8 Block offset IndexValid 0 1 2... 253 254 255 Tag 20 Data What kind of locality are we taking advantage of? CEG3420 L08.39 Spring 2016 32

Taking Advantage of Spatial Locality q Let cache block hold more than one word Start with an empty cache - all blocks initially marked as not valid 0 1 2 3 4 3 4 15 0 1 2 3 4 3 4 15 CEG3420 L08.40 Spring 2016

Taking Advantage of Spatial Locality q Let cache block hold more than one word Start with an empty cache - all blocks initially marked as not valid 0 1 2 3 4 3 4 15 0 miss 00 Mem(1) Mem(0) 1 hit 2 00 Mem(1) Mem(0) miss 00 Mem(1) Mem(0) 00 Mem(3) Mem(2) 3 hit 4 miss 3hit 01 5 4 00 Mem(1) Mem(0) 00 Mem(3) Mem(2) 00 Mem(1) Mem(0) 00 Mem(3) Mem(2) 01 Mem(5) Mem(4) 00 Mem(3) Mem(2) 4 hit 15 miss 01 Mem(5) Mem(4) 00 Mem(3) Mem(2) 8 requests, 4 misses 1101 Mem(5) Mem(4) 15 14 00 Mem(3) Mem(2) CEG3420 L08.41 Spring 2016

Miss Rate vs Block Size vs Cache Size q Miss rate goes up if the block size becomes a significant fraction of the cache size because the number of blocks that can be held in the same size cache is smaller (increasing capacity misses) CEG3420 L08.42 Spring 2016

Cache Field Sizes q The number of bits in a cache includes both the storage for data and for the tags 32-bit byte address For a direct mapped cache with 2 n blocks, n bits are used for the index For a block size of 2 m words (2 m+2 bytes), m bits are used to address the word within the block and 2 bits are used to address the byte within the word q What is the size of the tag field? 32 (n + m +2) q The total number of bits in a direct-mapped cache is then 2 n x (block size + tag field size + valid field size) CEG3420 L08.43 Spring 2016

EX: Bits in a Cache q How many total bits are required for a direct mapped cache with 16KB of data and 4-word blocks assuming a 32-bit address? CEG3420 L08.44 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.45 Spring 2016

Handling Cache Hits q Read hits (I$ and D$) this is what we want! q Write hits (D$ only) require the cache and memory to be consistent - always write the data into both the cache block and the next level in the memory hierarchy (write-through) - writes run at the speed of the next level in the memory hierarchy so slow! or can use a write buffer and stall only if the write buffer is full allow cache and memory to be inconsistent - write the data only into the cache block (write-back the cache block to the next level in the memory hierarchy when that cache block is evicted ) - need a dirty bit for each data cache block to tell if it needs to be written back to memory when it is evicted can use a write buffer to help buffer write-backs of dirty blocks CEG3420 L08.46 Spring 2016

Sources of Cache Misses q Compulsory (cold start or process migration, first reference): First access to a block, cold fact of life, not a whole lot you can do about it. If you are going to run millions of instruction, compulsory misses are insignificant Solution: increase block size (increases miss penalty; very large blocks could increase miss rate) q Capacity: Cache cannot contain all blocks accessed by the program Solution: increase cache size (may increase access time) q Conflict (collision): Multiple memory locations mapped to the same cache location Solution 1: increase cache size Solution 2: increase associativity (stay tuned) (may increase access time) CEG3420 L08.47 Spring 2016

q q Handling Cache Misses (Single Word Blocks) Read misses (I$ and D$) stall the pipeline, fetch the block from the next level in the memory hierarchy, install it in the cache and send the requested word to the processor, then let the pipeline resume Write misses (D$ only) 1. stall the pipeline, fetch the block from next level in the memory hierarchy, install it in the cache (which may involve having to evict a dirty block if using a write-back cache), write the word from the processor to the cache, then let the pipeline resume Or (normally used in write-back caches) 2. Write allocate just write the word into the cache updating both the tag and data, no need to check for cache hit, no need to stall Or (normally used in write-through caches with a write buffer) 3. No-write allocate skip the cache write (but must invalidate that cache block since it will now hold stale data) and just write the word to the write buffer (and eventually to the next memory level), no need to stall if the write buffer isn t full CEG3420 L08.48 Spring 2016

Write-Through Cache with No-Write Allocation CEG3420 L08.49 Spring 2016

Write-Back Cache with Write Allocation CEG3420 L08.50 Spring 2016

Multiword Block Considerations q Read misses (I$ and D$) Processed the same as for single word blocks a miss returns the entire block from memory Miss penalty grows as block size grows - Early restart processor resumes execution as soon as the requested word of the block is returned - Requested word first requested word is transferred from the memory to the cache (and processor) first Nonblocking cache allows the processor to continue to access the cache while the cache is handling an earlier miss q Write misses (D$) If using write allocate must first fetch the block from memory and then write the word to the block (or could end up with a garbled block in the cache (e.g., for 4 word blocks, a new tag, one word of data from the new block, and three words of data from the old block) CEG3420 L08.51 Spring 2016

Measuring Cache Performance q Assuming cache hit costs are included as part of the normal CPU execution cycle, then CPU time = IC CPI CC = IC (CPI ideal + Memory-stall cycles) CC CPI stall q Memory-stall cycles come from cache misses (a sum of read-stalls and write-stalls) Read-stall cycles = reads/program read miss rate read miss penalty Write-stall cycles = (writes/program write miss rate write miss penalty) + write buffer stalls q For write-through caches, we can simplify this to Memory-stall cycles = accesses/program miss rate miss penalty CEG3420 L08.52 Spring 2016

Impacts of Cache Performance q Relative cache penalty increases as processor performance improves (faster clock rate and/or lower CPI) The memory speed is unlikely to improve as fast as processor cycle time. When calculating CPI stall, the cache miss penalty is measured in processor clock cycles needed to handle a miss The lower the CPI ideal, the more pronounced the impact of stalls q A processor with a CPI ideal of 2, a 100 cycle miss penalty, 36% load/store instr s, and 2% I$ and 4% D$ miss rates Memory-stall cycles = 2% 100 + 36% 4% 100 = 3.44 more than twice the CPI ideal! So CPI stalls = 2 + 3.44 = 5.44 q What if the CPI ideal is reduced to 1? q What if the D$ miss rate went up 1%? 2%? q What if the processor clock rate is doubled (doubling the miss penalty)? CEG3420 L08.53 Spring 2016

Average Memory Access Time (AMAT) q A larger cache will have a longer access time. An increase in hit time will likely add another stage to the pipeline. At some point the increase in hit time for a larger cache will overcome the improvement in hit rate leading to a decrease in performance. q Average Memory Access Time (AMAT) is the average to access memory considering both hits and misses AMAT = Time for a hit + Miss rate x Miss penalty q What is the AMAT for a processor with a 20 psec clock, a miss penalty of 50 clock cycles, a miss rate of 0.02 misses per instruction and a cache access time of 1 clock cycle? CEG3420 L08.54 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.55 Spring 2016

Reducing Cache Miss Rates #1 1. Allow more flexible block placement q q In a direct mapped cache a memory block maps to exactly one cache block At the other extreme, could allow a memory block to be mapped to any cache block fully associative cache q A compromise is to divide the cache into sets each of which consists of n ways (n-way set associative). A memory block maps to a unique set (specified by the index field) and can be placed in any way of that set (so there are n choices) (block address) modulo (# sets in the cache) CEG3420 L08.56 Spring 2016

Another Reference String Mapping q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 4 0 4 0 4 0 4 0 4 0 4 0 4 0 4 CEG3420 L08.57 Spring 2016

Another Reference String Mapping q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 4 0 4 0 4 0 4 0 miss 4 miss 0 miss 4 miss 01 4 00 00 Mem(0) 00 Mem(0) 0 01 01 Mem(4) 00 Mem(0) 4 0 miss 4 miss 0 miss 4 miss 00 0 01 4 01 4 01 Mem(4) 00 Mem(0) 0001 Mem(4) 0 00 Mem(0) 8 requests, 8 misses q Ping pong effect due to conflict misses - two memory locations that map into the same cache block CEG3420 L08.58 Spring 2016

Way Set Associative Cache Example Cache 0 1 Set 0 1 0 1 V Tag Q1: Is it there? Data Compare all the cache tags in the set to the high order 3 memory address bits to tell if the memory block is in the cache 0000xx 0001xx 0010xx 0011xx 0100xx 0101xx 0110xx 0111xx 1000xx 1001xx 1010xx 1011xx 1100xx 1101xx 1110xx 1111xx Main Memory One word blocks Two low order bits define the byte in the word (32b words) Q2: How do we find it? Use next 1 low order memory address bit to determine which cache set (i.e., modulo the number of sets in the cache) CEG3420 L08.59 Spring 2016

Another Reference String Mapping q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 4 0 4 0 4 0 4 0 4 0 4 CEG3420 L08.60 Spring 2016

Another Reference String Mapping q Consider the main memory word reference string Start with an empty cache - all blocks initially marked as not valid 0 4 0 4 0 4 0 4 0 miss 4 miss 0 hit 4 hit 000 Mem(0) 000 Mem(0) 000 Mem(0) 000 Mem(0) 010 Mem(4) 010 Mem(4) 010 Mem(4) 8 requests, 2 misses q Solves the ping pong effect in a direct mapped cache due to conflict misses since now two memory locations that map into the same cache set can co-exist! CEG3420 L08.61 Spring 2016

Four-Way Set Associative Cache q 2 8 = 256 sets each with four ways (each with one block) 31 30... 11 10 9... 2 1 0 Byte offset Tag 22 Index 8 Index 0 1 2... 253 254 255 V Tag Data 0 1 2... 253 254 255 V Tag Data 0 1 2... 253 254 255 V Tag Data 0 1 2... 253 254 255 Way 0 Way 1 Way 2 Way 3 V Tag Data 32 Hit 4x1 select Data CEG3420 L08.62 Spring 2016

Range of Set Associative Caches q For a fixed size cache, each increase by a factor of two in associativity doubles the number of blocks per set (i.e., the number or ways) and halves the number of sets decreases the size of the index by 1 bit and increases the size of the tag by 1 bit Tag Index Block offset Byte offset CEG3420 L08.63 Spring 2016

Range of Set Associative Caches q For a fixed size cache, each increase by a factor of two in associativity doubles the number of blocks per set (i.e., the number or ways) and halves the number of sets decreases the size of the index by 1 bit and increases the size of the tag by 1 bit Used for tag compare Selects the set Selects the word in the block Tag Index Block offset Byte offset Decreasing associativity Direct mapped (only one way) Smaller tags, only a single comparator Increasing associativity Fully associative (only one set) Tag is all the bits except block and byte offset CEG3420 L08.64 Spring 2016

Costs of Set Associative Caches q When a miss occurs, which way s block do we pick for replacement? Least Recently Used (LRU): the block replaced is the one that has been unused for the longest time - Must have hardware to keep track of when each way s block was used relative to the other blocks in the set - For 2-way set associative, takes one bit per set set the bit when a block is referenced (and reset the other way s bit) q N-way set associative cache costs N comparators (delay and area) MUX delay (set selection) before data is available Data available after set selection (and Hit/Miss decision). In a direct mapped cache, the cache block is available before the Hit/Miss decision - So its not possible to just assume a hit and continue and recover later if it was a miss CEG3420 L08.65 Spring 2016

Benefits of Set Associative Caches q The choice of direct mapped or set associative depends on the cost of a miss versus the cost of implementation Miss Rate 12 10 8 6 4 2 0 1-way 2-way 4-way 8-way Associativity 4KB 8KB 16KB 32KB 64KB 128KB 256KB 512KB Data from Hennessy & Patterson, Computer Architecture, 2003 q Largest gains are in going from direct mapped to 2-way (20%+ reduction in miss rate) CEG3420 L08.66 Spring 2016

Reducing Cache Miss Rates #2 2. Use multiple levels of caches q q With advancing technology have more than enough room on the die for bigger L1 caches or for a second level of caches normally a unified L2 cache (i.e., it holds both instructions and data) and in some cases even a unified L3 cache For our example, CPI ideal of 2, 100 cycle miss penalty (to main memory) and a 25 cycle miss penalty (to UL2$), 36% load/stores, a 2% (4%) L1 I$ (D$) miss rate, add a 0.5% UL2$ miss rate CPI stalls = 2 + (.02 25 +.005 100) + (.36.04 25 +.36.005 100) = 3.54 (as compared to 5.44 with no L2$) CEG3420 L08.67 Spring 2016

Multilevel Cache Design Considerations q Design considerations for L1 and L2 caches are very different Primary cache should focus on minimizing hit time in support of a shorter clock cycle - Smaller with smaller block sizes Secondary cache(s) should focus on reducing miss rate to reduce the penalty of long main memory access times - Larger with larger block sizes - Higher levels of associativity q The miss penalty of the L1 cache is significantly reduced by the presence of an L2 cache so it can be smaller (i.e., faster) but have a higher miss rate q For the L2 cache, hit time is less important than miss rate The L2$ hit time determines L1$ s miss penalty L2$ local miss rate >> than the global miss rate CEG3420 L08.68 Spring 2016

Two Machines Cache Parameters L1 cache organization & size L1 associativity Intel Nehalem Split I$ and D$; 32KB for each per core; 64B blocks 4-way (I), 8-way (D) set assoc.; ~LRU replacement AMD Barcelona Split I$ and D$; 64KB for each per core; 64B blocks 2-way set assoc.; LRU replacement L1 write policy write-back, write-allocate write-back, write-allocate L2 cache organization & size Unified; 256kB (0.25MB) per core; 64B blocks Unified; 512KB (0.5MB) per core; 64B blocks L2 associativity 8-way set assoc.; ~LRU 16-way set assoc.; ~LRU L2 write policy write-back, write-allocate write-back, write-allocate L3 cache organization & size Unified; 8192KB (8MB) shared by cores; 64B blocks Unified; 2048KB (2MB) shared by cores; 64B blocks L3 associativity 16-way set assoc. 32-way set assoc.; evict block shared by fewest cores L3 write policy write-back, write-allocate write-back; write-allocate CEG3420 L08.69 Spring 2016

Two Machines Cache Parameters Intel P4 AMD Opteron L1 organization Split I$ and D$ Split I$ and D$ L1 cache size 8KB for D$, 96KB for trace cache (~I$) L1 block size 64 bytes 64 bytes 64KB for each of I$ and D$ L1 associativity 4-way set assoc. 2-way set assoc. L1 replacement ~ LRU LRU L1 write policy write-through write-back L2 organization Unified Unified L2 cache size 512KB 1024KB (1MB) L2 block size 128 bytes 64 bytes L2 associativity 8-way set assoc. 16-way set assoc. L2 replacement ~LRU ~LRU L2 write policy write-back write-back CEG3420 L08.70 Spring 2016

FSM Cache Controller q Key characteristics for a simple L1 cache Direct mapped Write-back using write-allocate Block size of 4 32-bit words (so 16B); Cache size of 16KB (so 1024 blocks) 18-bit tags, 10-bit index, 2-bit block offset, 2-bit byte offset, dirty bit, valid bit, LRU bits (if set associative) Processor 1-bit Read/Write 1-bit Valid 32-bit address 32-bit data 32-bit data 1-bit Ready Cache & Cache Controller 1-bit Read/Write 1-bit Valid 32-bit address 128-bit data 128-bit data 1-bit Ready DDR SDRAM CEG3420 L08.71 Spring 2016

Four State Cache Controller Idle Cache Hit Mark Cache Ready Valid CPU request Compare Tag If Valid && Hit Set Valid, Set Tag, If Write set Dirty Allocate Read new block from memory Memory Ready Cache Miss Old block is clean Cache Miss Old block is Dirty Write Back Write old block to memory Memory Not Ready Memory Not Ready CEG3420 L08.72 Spring 2016

Outline q Why Memory Hierarchy q How Memory Hierarchy? SRAM (Cache) & DRAM (main memory) Memory System q Cache Basics q Cache Performance q Reduce Cache Miss Rates q Summary CEG3420 L08.73 Spring 2016

Summary: Improving Cache Performance 0. Reduce the time to hit in the cache smaller cache direct mapped cache smaller blocks for writes - no write allocate no hit on cache, just write to write buffer - write allocate to avoid two cycles (first check for hit, then write) pipeline writes via a delayed write buffer to cache 1. Reduce the miss rate bigger cache more flexible placement (increase associativity) larger blocks (16 to 64 bytes typical) victim cache small buffer holding most recently discarded blocks CEG3420 L08.74 Spring 2016

Summary: Improving Cache Performance 2. Reduce the miss penalty smaller blocks use a write buffer to hold dirty blocks being replaced so don t have to wait for the write to complete before reading check write buffer (and/or victim cache) on read miss may get lucky for large blocks fetch critical word first use multiple cache levels L2 cache not tied to CPU clock rate faster backing store/improved memory bandwidth - wider buses - memory interleaving, DDR SDRAMs CEG3420 L08.75 Spring 2016

Summary: The Cache Design Space q Several interacting dimensions cache size block size associativity replacement policy write-through vs write-back write allocation q The optimal choice is a compromise depends on access characteristics - workload - use (I-cache, D-cache, TLB) depends on technology / cost q Simplicity often wins Cache Size Associativity Block Size Bad Good Factor A Factor B Less More CEG3420 L08.76 Spring 2016