COMP 3221: Microprocessors and Embedded Systems

Similar documents
CS61C : Machine Structures

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

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

UCB CS61C : Machine Structures

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)

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

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

Review : Pipelining. Memory Hierarchy

CS61C : Machine Structures

CS61C : Machine Structures

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

CS61C : Machine Structures

Lctures 33: Cache Memory - I. Some of the slides are adopted from David Patterson (UCB)

12 Cache-Organization 1

Advanced Computer Architecture

Page 1. Memory Hierarchies (Part 2)

COSC 6385 Computer Architecture - Memory Hierarchies (I)

EE 4683/5683: COMPUTER ARCHITECTURE

CS3350B Computer Architecture

Course Administration

CS61C : Machine Structures

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

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

Memory Hierarchy. Mehran Rezaei

ECE331: Hardware Organization and Design

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

Spring 2018 :: CSE 502. Cache Design Basics. Nima Honarmand

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

1/19/2009. Data Locality. Exploiting Locality: Caches

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

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

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

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

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

Handout 4 Memory Hierarchy

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

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

LECTURE 11. Memory Hierarchy

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

CSE502: Computer Architecture CSE 502: Computer Architecture

LECTURE 10: Improving Memory Access: Direct and Spatial caches

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

ECE331: Hardware Organization and Design

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

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

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

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

CPE 631 Lecture 04: CPU Caches

The University of Adelaide, School of Computer Science 13 September 2018

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

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

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

Lecture 12: Memory hierarchy & caches

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Chapter 2: Memory Hierarchy Design, part 1 - Introducation. Advanced Computer Architecture Mehran Rezaei

EN1640: Design of Computing Systems Topic 06: Memory System

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

Review: Computer Organization

Memory. Lecture 22 CS301

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

EITF20: Computer Architecture Part4.1.1: Cache - 2

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

Caching Basics. Memory Hierarchies

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Memory Hierarchy and Caches

CS152 Computer Architecture and Engineering Lecture 17: Cache System

14:332:331. Week 13 Basics of Cache

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

ADDRESS TRANSLATION AND TLB

CS61C : Machine Structures

Chapter 5A. Large and Fast: Exploiting Memory Hierarchy

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

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

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

CMPSC 311- Introduction to Systems Programming Module: Caching

ADDRESS TRANSLATION AND TLB

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

ECE 2300 Digital Logic & Computer Organization. Caches

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

Why memory hierarchy

Lecture 14: Cache Innovations and DRAM. Today: cache access basics and innovations, DRAM (Sections )

LECTURE 12. Virtual Memory

Locality and Data Accesses video is wrong one notes when video is correct

Chapter Seven. Large & Fast: Exploring Memory Hierarchy

EEC 483 Computer Organization

Slide Set 5. for ENCM 501 in Winter Term, Steve Norman, PhD, PEng

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

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

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

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

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

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

Computer and Digital System Architecture

Agenda. EE 260: Introduction to Digital Design Memory. Naive Register File. Agenda. Memory Arrays: SRAM. Memory Arrays: Register File

COSC4201. Chapter 5. Memory Hierarchy Design. Prof. Mokhtar Aboelaze York University

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

Transcription:

COMP 3: Microprocessors and Embedded Systems Lectures 7: Cache Memory - III http://www.cse.unsw.edu.au/~cs3 Lecturer: Hui Wu Session, 5 Outline Fully Associative Cache N-Way Associative Cache Block Replacement Policy Multilevel Caches (if time) Cache write policy (if time) Modified from notes by Saeid Nooshabadi Review We would like to have the capacity of disk at the speed of the processor: unfortunately this is not feasible. So we create a memory hierarchy: each successively higher level contains most used data from next lower level exploits temporal locality Locality of reference is a Big Idea 3... Big Idea Review Mechanism for transparent movement of data among levels of a storage hierarchy set of address/value bindings address => index to set of candidates compare desired address with tag service hit or miss - load new block and binding on miss address: tag index offset Valid Tag x-3 x4-7 x8-b xc-f a b c d

Types of Cache Misses (#/) Compulsory Misses occur when a program is first started cache does not contain any of that program s data yet, so misses are bound to occur can t be avoided easily, so won t focus on these in this course 3 4 5 6 7 8 9 A B C D E F Types of Cache Misses (#/) 3 Conflict Misses miss that occurs because two distinct memory addresses map to the same cache location two blocks (which happen to map to the same location) can keep overwriting each other big problem in direct-mapped caches how do we lessen the effect of these? Dealing with Conflict Misses Solution : Make the cache size bigger fails at some point Solution : Multiple distinct blocks can fit in the same Cache Index? 3 4 5 6 7 8 9 A B Fully Associative Cache (#/4) Memory address fields: Tag: same as before Offset: same as before Index: non-existent 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

Fully Associative Cache (#/4) Fully Associative Cache (e.g., 3 B block) compare tags in parallel 3 4 Cache Tag (7 bits long) Byte Offset Fully Associative Cache (#3/4) address tag CAM data RAM = = = : = = Cache Tag : Valid Cache Data B 3 B B : : : hit mux data CAM (Content Addressable memory): A RAM Cell with in-built comparator Fully Associative Cache (#4/4) Benefit of Fully Assoc Cache no Conflict Misses (since data can go anywhere) Drawbacks of Fully Assoc Cache need hardware comparator for every single entry: if we have a 64KB of data in cache with 4B entries, we need 6K comparators: infeasible Third Type of Cache Miss Capacity Misses miss that occurs because the cache has a limited size miss that would not occur if we increase the size of the cache sketchy definition, so just get the general idea This is the primary type of miss for Fully Associate caches.

N-Way Set Associative Cache (#/5) Memory address fields: Tag: same as before Offset: same as before Index: points 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 N-Way Set Associative Cache (#/5) -Way Set Associative address index Cache Organisation 3 4 5 6 7 8 9 A B C D E F decoder decoder tag RAM compare compare tag RAM hit data RAM mux mux data RAM data N-Way Set Associative Cache (#3/5) Summary: cache is direct-mapped with respect to sets each set is fully associative basically N direct-mapped caches working in parallel: each has its own valid bit and data N-Way Set Associative Cache (#4/5) Given memory address: Find correct set using Index value. Compare Tag with all Tag values in the determined set. If a match occurs, it s a hit, otherwise a miss. Finally, use the offset field as usual to find the desired data within the desired block.

N-Way Set Associative Cache (#5/5) Cache Organisation Comparison What s so great about this? relative performance even a -way set assoc cache avoids a lot of conflict misses.5 hardware cost isn t that bad: only need N comparators In fact, for a cache with M blocks,.5 it s Direct-Mapped if it s -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.5 6 4 cache size (Kbytes) /4 -way direct-mapped associative Degree of Associativity on 4KB Cache ARM3 Cache Organisation.5 3 virtual address 6 5 4 3.5 tag CAM user/supervisor tag CAM enable tag CAM decode tag CAM [9:] [:] [3:] data RAM byte addresses.5 4 8 associativity (ways) 6 3 64 8 56 performance bandwidth 64 entry 64 entry hit 64 entry 64 entry [9:4] 4 x 3-bit word data

Block Replacement Policy (#/) Direct-Mapped Cache: index completely specifies which position a block can go in on a miss N-Way Set Assoc (N > ): 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 Block Replacement Policy (#/) Solution: 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. Question: if we have the choice, where should we write an incoming block? 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 -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 Block Replacement Example We have a -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):,,,, 4,,, 3, 5, 4 How many hits and how many misses will there for the LRU block replacement policy?

Block Replacement Example: LRU Addresses,,,, 4,,... : miss, bring into set (loc ) : miss, bring into set (loc ) : hit : miss, bring into set (loc ) 4: miss, bring into set (loc, replace ) : hit loc loc set lru set set lru set set set set lru lru set lru set lru set lru set lru set 4 4 lru Ways to Reduce Miss Rate Larger cache limited by cost and technology hit time of first level cache < cycle time More places in the cache to put each block of memory - associativity fully-associative - any block any line k-way set associated - k places for each block - direct map: k= Big Idea How chose between options of associativity, block size, replacement policy? Design against a performance model Minimize: Average Access Time = Hit Time x Hit Rate + Miss Penalty x Miss Rate influenced by technology and program behavior Create the illusion of a memory that is large, cheap, and fast - on average Assume Hit Time = cycle Miss rate = 5% Example Miss penalty = cycles Avg mem access time = +.5 x = cycle

Improving Miss Penalty When caches first became popular, Miss Penalty ~ processor clock cycles Today MHz Processor ( ns per clock cycle) and ns to go to DRAM processor clock cycles! MEM L Proc L Solution: another cache between memory and the processor cache: Second Level (L) Cache DRAM Analyzing Multi-level Cache Hierarchy Proc L hit time L L hit time L Miss Penalty L Miss Rate L Miss Penalty Avg Mem Access Time = L Hit Time + L Miss Rate * L Miss Penalty L Miss Penalty = L Hit Time + L Miss Rate * L Miss Penalty Avg Mem Access Time = L Hit Time + L Miss Rate * (L Hit Time + L Miss Rate * L Miss Penalty) L DRAM L Miss Rate L: size: tens of KB Typical Scale hit time: complete in one clock cycle miss rates: -5% L: size: hundreds of KB hit time: few clock cycles miss rates: -% L miss rate is fraction of L misses that also miss in L why so high? Assume Example L Hit Time = cycle L Miss rate = 5% L Hit Time = 5 cycles L Miss rate = 5% (% L misses that miss) L Miss Penalty = cycles L miss penalty = 5 +.5 * = Avg mem access time = +.5 x = cycle

Assume Example: Without L Cache L Hit Time = cycle L Miss rate = 5% L Miss Penalty = cycles Avg mem access time = +.5 x = 6 cycles 3x faster with L cache 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 line indicating that memory needs to be updated when block is replaced => OS flushes cache before I/O!!! So that cache values become the same as memory values changed by I/O Performance trade-offs? Things to Remember (#/) Caches are NOT mandatory: Processor performs arithmetic Memory stores data Caches simply make data transfers go faster Each level of memory hierarchy is just a subset of next higher level Caches speed up due to temporal locality: store data used recently Block size > word speeds up due to spatial locality: store words adjacent to the ones used recently Things to Remember (#/) Cache design choices: size of cache: speed v. capacity direct-mapped v. associative for N-way set assoc: choice of N block replacement policy nd level cache? Write through v. write back? Use performance model to pick between choices, depending on programs, technology, budget,...

Reading Material Steve Furber: ARM System On-Chip; nd Ed, Addison-Wesley,, ISBN: -- 6759-6. Chapter.