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

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

Course Administration

EE 4683/5683: COMPUTER ARCHITECTURE

14:332:331. Week 13 Basics of Cache

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

CS3350B Computer Architecture

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

14:332:331. Week 13 Basics of Cache

Page 1. Memory Hierarchies (Part 2)

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

Memory Hierarchy Design (Appendix B and Chapter 2)

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

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

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

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

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

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

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

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Modern Computer Architecture

CS152 Computer Architecture and Engineering Lecture 17: Cache System

Handout 4 Memory Hierarchy

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

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

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

CPE 631 Lecture 04: CPU Caches

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

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

CSE 2021: Computer Organization

Memory Hierarchy Review

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

CSE 2021: Computer Organization

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

LECTURE 11. Memory Hierarchy

ECE ECE4680

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

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

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

COSC 6385 Computer Architecture - Memory Hierarchies (I)

Performance! (1/latency)! 1000! 100! 10! Capacity Access Time Cost. CPU Registers 100s Bytes <10s ns. Cache K Bytes ns 1-0.

Computer Systems Laboratory Sungkyunkwan University

Computer Architecture Spring 2016

CMPT 300 Introduction to Operating Systems

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

EECS150 - Digital Design Lecture 11 SRAM (II), Caches. Announcements

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

Memory Hierarchy: Caches, Virtual Memory

Memory Technologies. Technology Trends

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

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

ECE331: Hardware Organization and Design

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

ארכיטקטורת יחידת עיבוד מרכזי ת

Pick a time window size w. In time span w, are there, Multiple References, to nearby addresses: Spatial Locality

ECE232: Hardware Organization and Design

CS3350B Computer Architecture

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

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

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

Lecture 17 Introduction to Memory Hierarchies" Why it s important " Fundamental lesson(s)" Suggested reading:" (HP Chapter

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Speicherarchitektur. Who Cares About the Memory Hierarchy? Technologie-Trends. Speicher-Hierarchie. Referenz-Lokalität. Caches

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

Chapter 5. Memory Technology

EEC 483 Computer Organization

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

ECE331: Hardware Organization and Design

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

Lecture 11 Cache. Peng Liu.

Caches and Memory Hierarchy: Review. UCSB CS240A, Winter 2016

Caches and Memory Hierarchy: Review. UCSB CS240A, Fall 2017

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

LECTURE 10: Improving Memory Access: Direct and Spatial caches

Chapter Seven. Large & Fast: Exploring Memory Hierarchy

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

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

ECE260: Fundamentals of Computer Engineering

CS 152 Computer Architecture and Engineering. Lecture 7 - Memory Hierarchy-II

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

V. Primary & Secondary Memory!

CISC 662 Graduate Computer Architecture Lecture 16 - Cache and virtual memory review

registers data 1 registers MEMORY ADDRESS on-chip cache off-chip cache main memory: real address space part of virtual addr. sp.

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

Chapter 5 Memory Hierarchy Design. In-Cheol Park Dept. of EE, KAIST

Cache Memory - II. Some of the slides are adopted from David Patterson (UCB)

CS 152 Computer Architecture and Engineering. Lecture 7 - Memory Hierarchy-II

CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs"

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Advanced Computer Architecture

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

Paging! 2/22! Anthony D. Joseph and Ion Stoica CS162 UCB Fall 2012! " (0xE0)" " " " (0x70)" " (0x50)"

CSE 141 Computer Architecture Spring Lectures 17 Virtual Memory. Announcements Office Hour

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

Transcription:

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

Review: The Memory Hierarchy 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 Increasing distance from the processor in access time Processor 4-8 bytes (word) L1$ 8-32 bytes (block) L2$ 1 to 4 blocks Main Memory 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 1,024+ bytes (disk sector = page) (Relative) size of the memory at each level

The Memory Hierarchy: Why Does it Work? Temporal Locality (Locality in Time): apple Keep most recently accessed data items closer to the processor Spatial Locality (Locality in Space): apple Move blocks consisting of contiguous words to the upper levels To Processor From Processor Upper Level Memory Blk X Lower Level Memory Blk Y

The Memory Hierarchy: Terminology Hit: data is in some block in the upper level (Blk X) Hit Rate: the fraction of memory accesses found in the upper level Hit Time: Time to access the upper level which consists of RAM access time + Time to determine hit/miss To Processor Upper Level Memory Lower Level Memory From Processor Blk X Blk Y Miss: data is not in the upper level so needs to be retrieve from a block in the lower level (Blk Y) Miss Rate = 1 - (Hit Rate) Miss Penalty: Time to replace a block in the upper level + Time to deliver the block the processor Hit Time << Miss Penalty

How is the Hierarchy Managed? registers apple memory by compiler (programmer?) cache apple main memory by the cache controller hardware main memory apple disks by the operating system (virtual memory) virtual to physical address mapping assisted by the hardware (TLB) by the programmer (files)

Cache 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? Direct mapped For each item of data at the lower level, there is exactly one location in the cache where it might be - so lots of items at the lower level must share locations in the upper level Address mapping: (block address) modulo (# of blocks in the cache) First consider block sizes of one word

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 Two low order bits define the byte in the word (32-b 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)

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 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)

Direct Mapped Cache 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 14 0 1 2 3 4 3 4 15

Direct Mapped Cache 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) 4 miss 3 hit 4 hit 15 miss 01 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

MIPS Direct Mapped Cache Example One word/block, cache size = 1K words 31 30... 13 12 11... 2 1 0 Byte offset Hit Tag 20 10 Index Data Index 0 1 2... 1021 1022 1023 Valid Tag 20 Data 32 What kind of locality are we taking advantage of?

Handling Cache Hits Read hits (I$ and D$) this is what we want! Write hits (D$ only) allow cache and memory to be inconsistent - write the data only into the cache block (write-back the cache contents 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 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) so don t need a dirty bit - writes run at the speed of the next level in the memory hierarchy so slow! or can use a write buffer, so only have to stall if the write buffer is full

Write Buffer for Write-Through Caching Processor Cache DRAM Write buffer between the cache and main memory Processor: writes data into the cache and the write buffer Memory controller: writes contents of the write buffer to memory The write buffer is just a FIFO Typical number of entries: 4 write buffer Works fine if store frequency (w.r.t. time) << 1 / DRAM write cycle Memory system designer s nightmare When the store frequency (w.r.t. time) 1 / DRAM write cycle leading to write buffer saturation - One solution is to use a write-back cache; another is to use an L2 cache (next lecture)

Review: Why Pipeline? For Throughput! To avoid a structural hazard need two caches on-chip: one for instructions (I$) and one for data (D$) Time (clock cycles) I n s t r. O r d e r Inst 0 Inst 1 Inst 2 Inst 3 Inst 4 ALU I$ Reg D$ Reg ALU I$ Reg D$ Reg ALU I$ Reg D$ Reg ALU I$ Reg D$ Reg ALU I$ Reg D$ Reg To keep the pipeline running at its maximum rate both I$ and D$ need to satisfy a request from the datapath every cycle. What happens when they can t do that?

Another Reference String Mapping 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

Another Reference String Mapping 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) 01 Mem(4) 0 01 00 Mem(0) 4 0 miss 4 miss 0 miss 4 miss 00 01 4 01 4 01 Mem(4) 0 00 00 Mem(0) 01 Mem(4) 0 00 Mem(0) 8 requests, 8 misses Ping pong effect due to conflict misses - two memory locations that map into the same cache block

Sources of Cache Misses 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 Conflict (collision): Multiple memory locations mapped to the same cache location Solution 1: increase cache size Solution 2: increase associativity (next lecture) Capacity: Cache cannot contain all blocks accessed by the program Solution: increase cache size

Handling Cache Misses Read misses (I$ and D$) stall the entire 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 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; must invalidate the cache block since it will be inconsistent (now holding stale data)

Multiword Block Direct Mapped Cache 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 Index Valid 0 1 2... 253 254 255 Tag 20 Data What kind of locality are we taking advantage of? 32

Taking Advantage of Spatial Locality 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

Taking Advantage of Spatial Locality 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 3 hit 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)

Miss Rate vs Block Size vs Cache Size 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)

Block Size Tradeoff Larger block sizes take advantage of spatial locality but If the block size is too big relative to the cache size, the miss rate will go up Larger block size means larger miss penalty - Latency to first word in block + transfer time for remaining words Miss Rate Exploits Spatial Locality Fewer blocks compromises Temporal Locality Miss Penalty Average Access Time Increased Miss Penalty & Miss Rate Block Size Block Size Block Size In general, Average Memory Access Time = Hit Time + Miss Penalty x Miss Rate

Multiword Block Considerations 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 datapath 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 datapath) first Nonblocking cache allows the datapath to continue to access the cache while the cache is handling an earlier miss Write misses (D$) Can t use write allocate or will 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), so must fetch the block from memory first and pay the stall time

Cache Summary The Principle of Locality: Program likely to access a relatively small portion of the address space at any instant of time - Temporal Locality: Locality in Time - Spatial Locality: Locality in Space Three major categories of cache misses: Compulsory misses: sad facts of life. Example: cold start misses Conflict misses: increase cache size and/or associativity Nightmare Scenario: ping pong effect! Capacity misses: increase cache size Cache design space total size, block size, associativity (replacement policy) write-hit policy (write-through, write-back) write-miss policy (write allocate, write buffers)