CS61C : Machine Structures

Similar documents
UCB CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

Lecture 33 Caches III What to do on a write hit? Block Size Tradeoff (1/3) Benefits of Larger Block Size

CS61C : Machine Structures

www-inst.eecs.berkeley.edu/~cs61c/

UCB CS61C : Machine Structures

Block Size Tradeoff (1/3) Benefits of Larger Block Size. Lecture #22 Caches II Block Size Tradeoff (3/3) Block Size Tradeoff (2/3)

UCB CS61C : Machine Structures

1" 0" d" c" b" a" ...! ! Benefits of Larger Block Size. " Very applicable with Stored-Program Concept " Works well for sequential array accesses

And in Review! ! Locality of reference is a Big Idea! 3. Load Word from 0x !

CS61C : Machine Structures

CS61C : Machine Structures

Review : Pipelining. Memory Hierarchy

CS61C : Machine Structures

COMP 3221: Microprocessors and Embedded Systems

Direct-Mapped Cache Terminology. Caching Terminology. TIO Dan s great cache mnemonic. Accessing data in a direct mapped cache

UC Berkeley CS61C : Machine Structures

Review: New-School Machine Structures. Review: Direct-Mapped Cache. TIO Dan s great cache mnemonic. Memory Access without Cache

UCB CS61C : Machine Structures

! CS61C : Machine Structures. Lecture 22 Caches I. !!Instructor Paul Pearce! ITʼS NOW LEGAL TO JAILBREAK YOUR PHONE!

CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

UCB CS61C : Machine Structures

CS61C : Machine Structures

CS61C : Machine Structures

CS61C : Machine Structures

CS61C : Machine Structures

CS61C : Machine Structures

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

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

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

EE 4683/5683: COMPUTER ARCHITECTURE

CS3350B Computer Architecture

CMPT 300 Introduction to Operating Systems

COSC 6385 Computer Architecture - Memory Hierarchies (I)

UC Berkeley CS61C : Machine Structures

Levels in memory hierarchy

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

Course Administration

Page 1. Memory Hierarchies (Part 2)

12 Cache-Organization 1

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

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

UCB CS61C : Machine Structures

Memory Hierarchy. Mehran Rezaei

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

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

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

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

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

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

CS61C - Machine Structures. Lecture 17 - Caches, Part I. October 25, 2000 David Patterson

CS61C : Machine Structures

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

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

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

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

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

Advanced Computer Architecture

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)

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

LECTURE 11. Memory Hierarchy

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1


Caching Basics. Memory Hierarchies

CS152 Computer Architecture and Engineering Lecture 17: Cache System

CS61C : Machine Structures

Memory Hierarchies 2009 DAT105

Direct-Mapped and Set Associative Caches. Instructor: Steven Ho

CPE 631 Lecture 04: CPU Caches

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

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

CS61C : Machine Structures

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

Handout 4 Memory Hierarchy

Memory. Lecture 22 CS301

ECE232: Hardware Organization and Design

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

Review. Manage memory to disk? Treat as cache. Lecture #26 Virtual Memory II & I/O Intro

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

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

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Memory Hierarchy: Caches, Virtual Memory

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Background. Memory Hierarchies. Register File. Background. Forecast Memory (B5) Motivation for memory hierarchy Cache ECC Virtual memory.

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

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

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

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Improving Cache Performance

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

Modern Computer Architecture

Introduction to OpenMP. Lecture 10: Caches

LECTURE 10: Improving Memory Access: Direct and Spatial caches

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

CPE300: Digital System Architecture and Design

Memory hierarchy review. ECE 154B Dmitri Strukov

3Introduction. Memory Hierarchy. Chapter 2. Memory Hierarchy Design. Computer Architecture A Quantitative Approach, Fifth Edition

Spring 2016 :: CSE 502 Computer Architecture. Caches. Nima Honarmand

Transcription:

inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #24 Cache II 27-8-6 Scott Beamer, Instructor New Flow Based Routers CS61C L24 Cache II (1) www.anagran.com

Caching Terminology When we try to read memory, 3 things can happen: 1. cache hit: cache block is valid and contains proper address, so read desired word 2. cache miss: nothing in cache in appropriate block, so fetch from memory 3. cache miss, block replacement: wrong data is in cache at appropriate block, so discard it and fetch desired data from memory (cache always copy) CS61C L24 Cache II (2)

Direct-Mapped Cache Terminology All fields are read as unsigned integers. Index: specifies the cache index (which row of the cache we should look in) Offset: once we ve found correct block, specifies which byte within the block we want -- I.e., which column Tag: the remaining bits after offset and index are determined; these are used to distinguish between all the memory addresses that map to the same location CS61C L24 Cache II (3)

TIO Dan s great cache mnemonic AREA (cache size, B) 2 (H+W) = 2 H * 2 W = HEIGHT (# of blocks) * WIDTH (size of one block, B/block) Tag Index Offset WIDTH (size of one block, B/block) HEIGHT (# of blocks) AREA (cache size, B) CS61C L24 Cache II (4)

16 KB Direct Mapped Cache, 16B blocks Valid bit: determines whether anything is stored in that row (when computer initially turned on, all entries invalid) Valid Index Tag x-3 x4-7 x8-b xc-f 1 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (5)

1. Read x14 1 1 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (6)

So we read block 1 (1) 1 1 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (7)

No valid data 1 1 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (8)

So load that data into cache, setting tag, valid 1 1 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (9)

Read from cache at offset, return word b 1 1 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (1)

2. Read x1c =..1 11 1 11 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (11)

Index is Valid 1 11 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (12)

Index valid, Tag Matches 1 11 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (13)

Index Valid, Tag Matches, return d 1 11 Tag field Index field Offset Valid Index Tag x-3 x4-7 x8-b xc-f 1 1 a b c d 2 3 4 5 6 7... 122 123... CS61C L24 Cache II (14)

Types of Cache Misses Compulsory Misses When program starts, nothing is loaded Conflict Misses Two (or more) needed blocks map to the same cache location Fixed by Fully Associative Cache Capacity Misses Not enough room to hold it all Can be fixed by bigger cache CS61C L24 Cache II (15)

Fully Associative Cache Memory address fields: Tag: same as before Offset: same as before Index: non-existant What does this mean? no rows : any block can go anywhere in the cache must compare with all tags in entire cache to see if data is there CS61C L24 Cache II (16)

What to do on a write hit? Write-through update the word in cache block and corresponding word in memory Write-back update word in cache block allow memory word to be stale add dirty bit to each block indicating that memory needs to be updated when block is replaced OS flushes cache before I/O Performance trade-offs? CS61C L24 Cache II (17)

N-Way Set Associative Cache (1/3) Memory address fields: Tag: same as before Offset: same as before Index: points us to the correct row (called a set in this case) So what s the difference? each set contains multiple blocks once we ve found correct set, must compare with all tags in that set to find our data CS61C L24 Cache II (18)

Memory Address 12 Associative Cache Example 3 4 5 6 7 8 9 A B C D E F Memory CS61C L24 Cache II (19) Cache Index 1 1 Here s a simple 2 way set associative cache.

N-Way Set Associative Cache (2/3) Basic Idea cache is direct-mapped w/respect to sets each set is fully associative basically N direct-mapped caches working in parallel: each has its own valid bit and data Given memory address: Find correct set using Index value. Compare Tag with all Tag values in the determined set. If a match occurs, hit!, otherwise a miss. Finally, use the offset field as usual to find the desired data within the block. CS61C L24 Cache II (2)

N-Way Set Associative Cache (3/3) What s so great about this? even a 2-way set assoc cache avoids a lot of conflict misses hardware cost isn t that bad: only need N comparators In fact, for a cache with M blocks, it s Direct-Mapped if it s 1-way set assoc it s Fully Assoc if it s M-way set assoc so these two are just special cases of the more general set associative design CS61C L24 Cache II (21)

4-Way Set Associative Cache Circuit tag index CS61C L24 Cache II (22)

Peer Instructions 1. In the last 1 years, the gap between the access time of DRAMs & the cycle time of processors has decreased. (I.e., is closing) 2. A 2-way set-associative cache can be outperformed by a direct-mapped cache. 3. Larger block size lower miss rate CS61C L24 Cache II (23) ABC : FFF 1: FFT 2: FTF 3: FTT 4: TFF 5: TFT 6: TTF 7: TTT

Peer Instructions Answer 1. That was was one of the motivation for caches in the first place -- that the memory gap is big and widening. 2. Sure, consider the caches from the previous slides with the following workload:, 2,, 4, 2 2-way: m, 2m, h, 4m, 2m; DM: m, 2m, h, 4m, 2h 3. Larger block size lower miss rate, true until a certain point, and then the ping-pong effect takes over 1. In the last 1 years, the gap between the access time of DRAMs & the cycle time of processors has decreased. (I.e., is closing) 2. A 2-way set-associative cache can be outperformed by a direct-mapped cache. 3. Larger block size lower miss rate ABC : FFF 1: FFT 2: FTF 3: FTT 4: TFF 5: TFT 6: TTF 7: TTT CS61C L24 Cache II (24)

Administrivia Proj4 due Sunday (will be posted tonight) Proj3 Face-to-Face grading starts today Make an appointment (and show up) Final Review Session in works Course Survey during last lecture 2 points extra added for taking survey (still anonymous) I don t see results until long after grades due CS61C L24 Cache II (25)

Block Replacement Policy Direct-Mapped Cache: index completely specifies position which position a block can go in on a miss N-Way Set Assoc: index specifies a set, but block can occupy any position within the set on a miss Fully Associative: block can be written into any position Question: if we have the choice, where should we write an incoming block? If there are any locations with valid bit off (empty), then usually write the new block into the first one. If all possible locations already have a valid block, we must pick a replacement policy: rule by which we determine which block gets cached out on a miss. CS61C L24 Cache II (26)

Block Replacement Policy: LRU LRU (Least Recently Used) Idea: cache out block which has been accessed (read or write) least recently Pro: temporal locality recent past use implies likely future use: in fact, this is a very effective policy Con: with 2-way set assoc, easy to keep track (one LRU bit); with 4-way or greater, requires complicated hardware and much time to keep track of this CS61C L24 Cache II (27)

Block Replacement Example We have a 2-way set associative cache with a four word total capacity and one word blocks. We perform the following word accesses (ignore bytes for this problem):, 2,, 1, 4,, 2, 3, 5, 4 How many hits and how many misses will there be for the LRU block replacement policy? CS61C L24 Cache II (28)

Block Replacement Example: LRU Addresses, 2,, 1, 4,,... : miss, bring into set (loc ) 2: miss, bring into set (loc 1) CS61C L24 Cache II (29) : hit 1: miss, bring into set 1 (loc ) 4: miss, bring into set (loc 1, replace 2) : hit loc loc 1 set lru set 1 set lru set 1 set lru set 1 set lru lru 2 2 lru 2 set 1 1 lru set lru lru 24 set 1 1 lru set lru lru set 1 4 1 lru

Big Idea How to choose between associativity, block size, replacement & write policy? Design against a performance model Minimize: Average Memory Access Time = Hit Time + Miss Penalty x Miss Rate influenced by technology & program behavior Create the illusion of a memory that is large, cheap, and fast - on average How can we improve miss penalty? CS61C L24 Cache II (3)

Improving Miss Penalty When caches first became popular, Miss Penalty ~ 1 processor clock cycles Today 24 MHz Processor (.4 ns per clock cycle) and 8 ns to go to DRAM 2 processor clock cycles! MEM Proc $ $ 2 DRAM Solution: another cache between memory and the processor cache: Second Level (L2) Cache CS61C L24 Cache II (31)

Analyzing Multi-level cache hierarchy Proc CS61C L24 Cache II (32) L1 hit time $ L2 hit time L1 Miss Rate L1 Miss Penalty Avg Mem Access Time = L1 Hit Time + L1 Miss Rate * L1 Miss Penalty L1 Miss Penalty = L2 Hit Time + L2 Miss Rate * L2 Miss Penalty Avg Mem Access Time = L1 Hit Time + L1 Miss Rate * (L2 Hit Time + L2 Miss Rate * L2 Miss Penalty) $ 2 DRAM L2 Miss Rate L2 Miss Penalty

Example Assume Hit Time = 1 cycle Miss rate = 5% Miss penalty = 2 cycles Calculate AMAT Avg mem access time = 1 +.5 x 2 = 1 + 1 cycles = 2 cycles CS61C L24 Cache II (33)

Ways to reduce miss rate Larger cache limited by cost and technology hit time of first level cache < cycle time (bigger caches are slower) More places in the cache to put each block of memory associativity fully-associative any block any line N-way set associated N places for each block direct map: N=1 CS61C L24 Cache II (34)

Typical Scale L1 size: tens of KB hit time: complete in one clock cycle miss rates: 1-5% L2: size: hundreds of KB hit time: few clock cycles miss rates: 1-2% L2 miss rate is fraction of L1 misses that also miss in L2 why so high? CS61C L24 Cache II (35)

Example: with L2 cache Assume L1 Hit Time = 1 cycle L1 Miss rate = 5% L2 Hit Time = 5 cycles L2 Miss rate = 15% (% L1 misses that miss) L2 Miss Penalty = 2 cycles L1 miss penalty = 5 +.15 * 2 = 35 Avg mem access time = 1 +.5 x 35 = 2.75 cycles CS61C L24 Cache II (36)

Example: without L2 cache Assume L1 Hit Time = 1 cycle L1 Miss rate = 5% L1 Miss Penalty = 2 cycles Avg mem access time = 1 +.5 x 2 = 11 cycles 4x faster with L2 cache! (2.75 vs. 11) CS61C L24 Cache II (37)

An actual CPU Early PowerPC Cache 32 KByte Instructions and 32 KByte Data L1 caches External L2 Cache interface with integrated controller and cache tags, supports up to 1 MByte external L2 cache Dual Memory Management Units (MMU) with Translation Lookaside Buffers (TLB) Pipelining Superscalar (3 inst/cycle) 6 execution units (2 integer and 1 double precision IEEE floating point) CS61C L24 Cache II (38)

An Actual CPU Pentium M 32KB I$ 32KB D$ CS61C L24 Cache II (39)

Peer Instructions 1. All caches take advantage of spatial locality. 2. All caches take advantage of temporal locality. 3. On a read, the return value will depend on what is in the cache. CS61C L24 Cache II (4) ABC : FFF 1: FFT 2: FTF 3: FTT 4: TFF 5: TFT 6: TTF 7: TTT

Peer Instruction Answer F A L S E T R U E 1. All caches take advantage of spatial locality. 2. All caches take advantage of temporal locality. F A L S E ABC 3. On a read, the return value will depend on what is in the cache. 1. Block size = 1, no spatial! 2. That s the idea of caches; We ll need it again soon. 3. It better not! If it s there, use it. Oth, get from mem : FFF 1: FFT 2: FTF 3: FTT 4: TFF 5: TFT 6: TTF 7: TTT CS61C L24 Cache II (41)

And in Conclusion We ve discussed memory caching in detail. Caching in general shows up over and over in computer systems Filesystem cache Web page cache Game databases / tablebases Software memoization Others? Big idea: if something is expensive but we want to do it repeatedly, do it once and cache the result. Cache design choices: Write through v. write back size of cache: speed v. capacity direct-mapped v. associative for N-way set assoc: choice of N block replacement policy 2 nd level cache? 3 rd level cache? Use performance model to pick between choices, depending on programs, technology, budget,... CS61C L24 Cache II (42)

Block Size Tradeoff Conclusions Miss Penalty Block Size Miss Rate Exploits Spatial Locality Block Size Fewer blocks: compromises temporal locality Average Access Time Increased Miss Penalty & Miss Rate Block Size CS61C L24 Cache II (43)