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

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

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

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

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

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

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

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

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

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 2

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

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

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

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

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

10/11/17. New-School Machine Structures. Review: Single Cycle Instruction Timing. Review: Single-Cycle RISC-V RV32I Datapath. Components of a Computer

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

EE 4683/5683: COMPUTER ARCHITECTURE

Course Administration

Page 1. Memory Hierarchies (Part 2)

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

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

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 Direct- Mapped Caches. Increasing distance from processor, decreasing speed.

CS3350B Computer Architecture

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

14:332:331. Week 13 Basics of Cache

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

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

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

Components of a Computer

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

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

14:332:331. Week 13 Basics of Cache

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

CMPT 300 Introduction to Operating Systems

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

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

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

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

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

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

ECE331: Hardware Organization and Design

Mo Money, No Problems: Caches #2...

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

Advanced Memory Organizations

Memory. Lecture 22 CS301

Levels in memory hierarchy

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

CS61C : Machine Structures

CS152 Computer Architecture and Engineering Lecture 17: Cache System

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

ECE331: Hardware Organization and Design

Cache memories are small, fast SRAM-based memories managed automatically in hardware. Hold frequently accessed blocks of main memory

Memory Hierarchy. Caching Chapter 7. Locality. Program Characteristics. What does that mean?!? Exploiting Spatial & Temporal Locality

Chapter Seven. Large & Fast: Exploring Memory Hierarchy

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

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

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

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

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

LECTURE 11. Memory Hierarchy

Basic Memory Hierarchy Principles. Appendix C (Not all will be covered by the lecture; studying the textbook is recommended!)

Advanced Computer Architecture

COSC3330 Computer Architecture Lecture 19. Cache

ECEC 355: Cache Design

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

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

Lecture 11 Cache. Peng Liu.

Show Me the $... Performance And Caches

Caches. Hiding Memory Access Times

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

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

ECE ECE4680

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

Let!s go back to a course goal... Let!s go back to a course goal... Question? Lecture 22 Introduction to Memory Hierarchies

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

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

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

Review. You Are Here! Agenda. Recap: Typical Memory Hierarchy. Recap: Components of a Computer 11/6/12

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

Memory Hierarchy: Caches, Virtual Memory

COSC 6385 Computer Architecture - Memory Hierarchies (I)

CS 61C: Great Ideas in Computer Architecture

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

V. Primary & Secondary Memory!

Question?! Processor comparison!

Modern Computer Architecture

CPE 631 Lecture 04: CPU Caches

CS61C : Machine Structures

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Computer Architecture Spring 2016

Memory Hierarchy. 2/18/2016 CS 152 Sec6on 5 Colin Schmidt

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

Transcription:

CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2 Instructors: Bernhard Boser & Randy H Katz http://insteecsberkeleyedu/~cs61c/ 10/18/16 Fall 2016 - Lecture #15 1

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 2

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 3

Typical Memory Hierarchy Datapath On-Chip Components Control RegFile Instr Cache Data Cache Second- Level Cache (SRAM) Third- Level Cache (SRAM) Main Memory (DRAM) Secondary Memory (Disk Or Flash) Speed (cycles): ½ s 1 s 10 s 100 s-1000 1,000,000 s Size (bytes): 100 s 10K s M s G s T s Cost/bit: highest lowest Principle of locality + memory hierarchy presents programmer with as much memory as is available in the cheapest technology at the speed offered by the fastesttechnology 10/18/16 Fall 2016 - Lecture #15 4

Adding Cache to Computer Processor Control Enable? Read/Write Memory Input Datapath PC Registers Address Write Data Cache Program Bytes Memory (including cache) organized around blocks, which are typically multiple words Arithmetic & Logic Unit (ALU) Read Data Processor organized around words and bytes Processor-Memory Interface Data Output I/O-Memory Interfaces 10/18/16 Fall 2016 - Lecture #15 5

Key Cache Concepts Principle of Locality Temporal Locality and Spatial Locality Hierarchy of Memories (speed/size/cost per bit) to exploit locality Cache copy of data in lower level of memory hierarchy Direct Mapped to find block in cache using Tag field and Valid bit for Hit Cache Design Organization Choices: Fully Associative, Set-Associative, Direct-Mapped 10/18/16 Fall 2016 - Lecture #15 6

Cache Organizations Fully Associative : Block placed anywhere in cache First design last lecture Note: No Index field, but one comparator/block Direct Mapped : Block goes only one place in cache Note: Only one comparator Number of sets = number blocks N-way Set Associative : N places for block in cache Number of sets = Number of Blocks / N N comparators Fully Associative: N = number of blocks Direct Mapped: N = 1 10/18/16 Fall 2016 - Lecture #15 7

Memory Block vs Word Addressing address 8 address 8 address 8 00000 Byte 00000 0 0 00000 00001 00001 1 00001 Word 00010 00010 2 00010 00011 00100 00101 00110 00111 00011 00100 00101 00110 00111 3 4 5 6 7 00011 00100 00101 00110 00111 8-Byte Block 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111 1 2 3 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111 2 LSBs are 0 3 LSBs are 0 Block # Byte offset in block 10/18/16 Fall 2016 - Lecture #15 8

Memory Block Number Aliasing 12-bit memory addresses, 16 Byte blocks Block # Block # mod 8 Block # mod 2 82 010100100000 2 010100100000 0 010100100000 83 010100110000 3 010100110000 1 010100110000 84 010101000000 4 010101000000 0 010101000000 85 010101010000 5 010101010000 1 010101010000 86 010101100000 6 010101100000 0 010101100000 87 010101110000 7 010101110000 1 010101110000 88 010110000000 0 010110000000 0 010110000000 89 010110010000 1 010110010000 1 010110010000 90 010110100000 2 010110100000 0 010110100000 91 010110110000 3 010110110000 1 010110110000 10/18/16 Fall 2016 - Lecture #15 9

Processor Address Fields used by Cache Controller Block Offset: Byte address within block Set Index: Selects which set Tag: Remaining portion of processor address Processor Address (32-bits total) Tag Set Index Block offset Size of Index = log 2 (number of sets) Size of Tag = Address size Size of Index log 2 (number of bytes/block) 10/18/16 Fall 2016 - Lecture #15 10

Direct-Mapped Cache Revisted One word blocks, cache size = 1K words (or 4KB) Valid bit ensures something useful in cache for this index Hit Compare Tag with upper part of Address to see if a Hit Tag 20 10 Index Index 0 1 2 1021 1022 1023 31 30 13 12 11 2 1 0 Valid Tag 20 Data Comparator Byte offset 32 Data Read data from cache instead of memory if a Hit 10/18/16 Fall 2016 - Lecture #15 11

Four-Way Set-Associative Cache 2 8 = 256 sets each with four ways (each with one block) 31 30 13 12 11 2 1 0 Byte offset Set Index Tag 22 Index 8 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 Way 0 Way 1 Way 2 Way 3 0 1 2 253 254 255 V Tag Data 32 Hit 4x1 select 10/18/16 Fall 2016 - Lecture #15 12 Data

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 13

Handling Stores with Write-Through Store instructions write to memory, changing values Need to make sure cache and memory have same values on writes: two policies 1) Write-Through Policy: write cache and write through the cache to memory Every write eventually gets to memory Too slow, so include Write Buffer to allow processor to continue once data in Buffer Buffer updates memory in parallel to processor 10/18/16 Fall 2016 - Lecture #15 14

Write-Through Cache Write both values in cache and in memory Write buffer stops CPU from stalling if memory cannot keep up Write buffer may have multiple entries to absorb bursts of writes What if store misses in cache? 32-bit Address 32-bit Address 252 Processor Cache 32-bit Data 32-bit Data 12 1022 99 Write 131 7 Buffer 2041 20 Addr Data Memory 10/18/16 Fall 2016 - Lecture #15 15

Handling Stores with Write-Back 2) Write-Back Policy: write only to cache and then write cache block back to memory when evict block from cache Writes collected in cache, only single write to memory per block Include bit to see if wrote to block or not, and then only write back if bit is set Called Dirty bit (writing makes it dirty ) 10/18/16 Fall 2016 - Lecture #15 16

Write-Back Cache Processor Store/cache hit, write data in cache only and set dirty bit Memory has stale value Store/cache miss, read data from memory, then update and set dirty bit Write-allocate policy Load/cache hit, use value from cache On any miss, write back evicted block, only if dirty Update cache with new block and clear dirty bit 32-bit Address 32-bit Address Cache 32-bit Data 252 D 12 1022 Dirty D 99 131 2041 Bits D D 7 20 32-bit Data Memory 10/18/16 Fall 2016 - Lecture #15 17

Write-Through vs Write-Back Write-Through: Simpler control logic More predictable timing simplifies processor control logic Easier to make reliable, since memory always has copy of data (big idea: Redundancy!) Write-Back More complex control logic More variable timing (0,1,2 memory accesses per cache access) Usually reduces write traffic Harder to make reliable, sometimes cache has only copy of data 10/18/16 Fall 2016 - Lecture #15 18

Administrivia Midterm #2 2 weeks away! November 1! In class! 3:40-5 PM Synchronous digital design and Project 3 (processor design) included Pipelines and Caches ONE Double sided Crib sheet Review Session, Sunday, 10/30, 1-3 PM, 10 Evans 10/18/16 Fall 2016 - Lecture #15 19

iclicker Saga 10/18/16 Fall 2016 -- Lecture #15 20

iclicker and EPA No longer taking attendance in lecture but we hope you will continue to come anyway Continue to use Clicker questions in lecture to help you test your understanding EPA will be based on a holistic assessment of lecture, piazza, guerrilla and tutoring sessions, office hours, discussion, and lab participation EPA will be calculated so as to only help your course grade, never hurt it 10/18/16 Fall 2016 -- Lecture #15 21

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 22

Cache (Performance) Terms Hit rate: fraction of accesses that hit in the cache Miss rate: 1 Hit rate Miss penalty: time to replace a block from lower level in memory hierarchy to cache Hit time: time to access cache memory (including tag comparison) Abbreviation: $ = cache (a Berkeley innovation!) 10/18/16 Fall 2016 - Lecture #15 23

Average Memory Access Time (AMAT) Average Memory Access Time (AMAT) is the average time to access memory considering both hits and misses in the cache AMAT = Time for a hit + Miss rate Miss penalty 10/18/16 Fall 2016 - Lecture #15 24

Clickers/Peer Instruction AMAT = Time for a hit + Miss rate x Miss penalty Given a 200 psec clock, a miss penalty of 50 clock cycles, a miss rate of 002 misses per instruction and a cache hit time of 1 clock cycle, what is AMAT? A: 200 psec B: 400 psec C: 600 psec D: 800 psec 10/18/16 Fall 2016 - Lecture #15 25

Clickers/Peer Instruction AMAT = Time for a hit + Miss rate x Miss penalty Given a 200 psec clock, a miss penalty of 50 clock cycles, a miss rate of 002 misses per instruction and a cache hit time of 1 clock cycle, what is AMAT? A: 200 psec B: 400 psec 1 clock cycle + 02 * 50 clock cycles = 2 clock cycles C: 600 psec D: 800 psec 10/18/16 Fall 2016 - Lecture #15 26

Ping Pong Cache Example: Direct-Mapped Cache w/4 Single-Word Blocks, Worst-Case Reference String Consider the main memory address reference string of word numbers: 0 4 0 4 0 4 0 4 Start with an empty cache - all blocks initially marked as not valid 0 4 0 4 0 4 0 4 10/18/16 Fall 2016 - Lecture #15 27

Ping Pong Cache Example: Direct-Mapped Cache w/4 Single-Word Blocks, Worst-Case Reference String Consider the main memory address reference string of word numbers: 0 4 0 4 0 4 0 4 Start with an empty cache - all blocks initially marked as not valid 0 miss 4 miss 0 miss 4 miss 01 4 00 0 01 4 00 Mem(0) 00 Mem(0) 01 Mem(4) 00 Mem(0) 00 0 miss 0 01 4 miss 4 00 0 miss 0 01 4 miss 4 01 Mem(4) 00 Mem(0) 01 Mem(4) 00 Mem(0) 8 requests, 8 misses Ping-pong effect due to conflict misses - two memory locations that map into the same cache block 10/18/16 Fall 2016 - Lecture #15 28

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 29

Alternative Block Placement Schemes DM placement: mem block 12 in 8 block cache: only one cache block where mem block 12 can be found (12 modulo 8) = 4 SA placement: four sets x 2-ways (8 cache blocks), memory block 12 in set (12 mod 4) = 0; either element of the set FA placement: mem block 12 can appear in any cache blocks 10/18/16 Fall 2016 - Lecture #15 30

Way Example: 2-Way Set Associative $ Cache 0 1 Set 0 1 0 1 V (4 words = 2 sets x 2 ways per set) Tag Q: 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) Q: How do we find it? Use next 1 low order memory address bit to determine which cache set (ie, modulo the number of sets in the cache) 10/18/16 Fall 2016 - Lecture #15 31

Ping Pong Cache Example: 4 Word 2- Way SA $, Same Reference String 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 10/18/16 Fall 2016 - Lecture #15 32

Ping Pong Cache Example: 4-Word 2- Way SA $, Same Reference String Consider the main memory address 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 Solves the ping-pongeffect in a direct-mapped cache due to conflict misses since now two memory locations that map into the same cache set can co-exist! 10/18/16 Fall 2016 - Lecture #15 33

Four-Way Set-Associative Cache 2 8 = 256 sets each with four ways (each with one block) 31 30 13 12 11 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 Way 0 Way 1 Way 2 Way 3 0 1 2 253 254 255 V Tag Data 32 Hit 4x1 select 10/18/16 Fall 2016 - Lecture #15 34 Data

Alternative Organizations of an Eight-Block Cache Total size of $ in blocks is equal to number of sets associativity For fixed $ size and fixed block size, increasing associativity decreases number of sets while increasing number of elements per set With eight blocks, an 8-way setassociative $ is same as a fully associative $ 10/18/16 Fall 2016 - Lecture #15 35

Range of Set-Associative Caches For a fixed-size cache and fixed block size, each increase by a factor of two in associativity doubles the number of blocks per set (ie, 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 Word offset Byte offset 10/18/16 Fall 2016 - Lecture #15 36

Range of Set-Associative Caches For a fixed-size cache and fixed block size, each increase by a factor of two in associativity doubles the number of blocks per set (ie, 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 Word offset Byte offset Decreasing associativity, lower way, more sets Direct mapped (only one way) Smaller tags, only a single comparator Increasing associativity, higher way, less sets Fully associative (only one set) Tag is all the bits except block and byte offset 10/18/16 Fall 2016 - Lecture #15 37

Total Cache Capacity = Associativity # of sets block_size Bytes = blocks/set sets Bytes/block C = N S B Tag Index Byte Offset address_size = tag_size + index_size + offset_size = tag_size + log 2 (S) + log 2 (B) 10/18/16 Fall 2016 - Lecture #15 38

Total Cache Capacity = Associativity * # of sets * block_size Bytes = blocks/set * sets * Bytes/block C = N * S * B Tag Index Byte Offset address_size = tag_size + index_size + offset_size = tag_size + log 2 (S) + log 2 (B) Double the Associativity: Number of sets? tag_size? index_size? # comparators? Double the Sets: Associativity? tag_size? index_size? # comparators? 10/18/16 Fall 2016 - Lecture #15 39

Total Cache Capacity = Associativity * # of sets * block_size Bytes = blocks/set * sets * Bytes/block C = N * S * B Tag Index Byte Offset address_size = tag_size + index_size + offset_size = tag_size + log 2 (S) + log 2 (B) Double the Associativity: Halve the number of sets tag_size + 1 while index_size 1, 2 x comparators Double the Sets: Halve the associativity tag_size - 1 while index_size + 1, ½ x comparators 10/18/16 Fall 2016 - Lecture #15 40

Your Turn For a cache of 64 blocks, each block four bytes in size: 1 The capacity of the cache is: 256 bytes 2 Given a 2-way Set Associative organization, there are 32 sets, each of 2 blocks, and 2 places a block from memory could be placed 3 Given a 4-way Set Associative organization, there are 16 sets each of 4 blocks and 4 places a block from memory could be placed 4 Given an 8-way Set Associative organization, there are 8 sets each of 8 blocks and 8 places a block from memory could be placed 10/18/16 Fall 2016 - Lecture #15 41

Clicker/Peer Instruction For S sets, N ways, B blocks, which statements hold? (i) The cache has B tags (ii) The cache needs N comparators (iii) B = N x S (iv) Size of Index = Log 2 (S) A: (i) only B: (i) and (ii) only C: (i), (ii), (iii) only D: All four statements are true E: None are true 10/18/16 Fall 2016 - Lecture #15 42

Costs of Set-Associative Caches 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) DM $: block is available before the Hit/Miss decision In Set-Associative, not possible to just assume a hit and continue and recover later if it was a miss When miss occurs, which way s block selected for replacement? Least Recently Used (LRU): one that has been unused the longest (principle of temporal locality) Must track when each way s block was used relative to other blocks in the set For 2-way SA $, one bit per set set to 1 when a block is referenced; reset the other way s bit (ie, last used ) 10/18/16 Fall 2016 - Lecture #15 43

Cache Replacement Policies Random Replacement Hardware randomly selects a cache evict Least-Recently Used Hardware keeps track of access history Replace the entry that has not been used for the longest time For 2-way set-associative cache, need one bit for LRU replacement Example of a Simple Pseudo LRU Implementation Assume 64 Fully Associative entries Hardware replacement pointer points to one cache entry Whenever access is made to the entry the pointer points to: Move the pointer to the next entry Otherwise: do not move the pointer (example of not-most-recently used replacement policy) 10/18/16 Fall 2016 - Lecture #15 Replacement Pointer Entry 0 Entry 1 : Entry 63 44

Benefits of Set-Associative Caches Choice of DM $ versus SA $ depends on the cost of a miss versus the cost of implementation Largest gains are in going from direct mapped to 2-way (20%+ reduction in miss rate) 10/18/16 Fall 2016 - Lecture #15 45

Outline Cache Organization and Principles Write Back vs Write Through Cache Performance Cache Design Tradeoffs And in Conclusion 10/18/16 Fall 2016 Lecture #15 46

And in Conclusion Name of the Game: Reduce AMAT Reduce Hit Time Reduce Miss Rate Reduce Miss Penalty Balance cache parameters (Capacity, associativity, block size) 10/18/16 Fall 2016 - Lecture #15 47