CS61C : Machine Structures

Similar documents
CS61C : Machine Structures

UC Berkeley CS61C : Machine Structures

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

UCB CS61C : Machine Structures

Review : Pipelining. Memory Hierarchy

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

UC Berkeley CS61C : Machine Structures

UCB CS61C : Machine Structures

CS61C : Machine Structures

CS61C : Machine Structures

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

CS61C : Machine Structures

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

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

CS61C : Machine Structures

CS61C : Machine Structures

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

Memory Hierarchy. Mehran Rezaei

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

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

CS61C : Machine Structures

CS61C : Machine Structures

UCB CS61C : Machine Structures

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

Question?! Processor comparison!

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

Levels in memory hierarchy

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

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

CS61C : Machine Structures

ECE468 Computer Organization and Architecture. Memory Hierarchy

Memory Hierarchy, Fully Associative Caches. Instructor: Nick Riasanovsky

UCB CS61C : Machine Structures

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

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

CS61C : Machine Structures

UCB CS61C : Machine Structures

14:332:331. Week 13 Basics of Cache

LECTURE 11. Memory Hierarchy

CS61C : Machine Structures

CS61C : Machine Structures

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

UC Berkeley 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

CSC Memory System. A. A Hierarchy and Driving Forces

UCB CS61C : Machine Structures

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Recap: Machine Organization

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

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

Donn Morrison Department of Computer Science. TDT4255 Memory hierarchies

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

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

COMP 3221: Microprocessors and Embedded Systems

Memory Hierarchy: Motivation

Modern Computer Architecture

Course Administration

EE 4683/5683: COMPUTER ARCHITECTURE

Lecture-14 (Memory Hierarchy) CS422-Spring

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

ECE232: Hardware Organization and Design

Locality. Cache. Direct Mapped Cache. Direct Mapped Cache

CMPT 300 Introduction to Operating Systems

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

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

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

CS152 Computer Architecture and Engineering Lecture 17: Cache System

COSC 6385 Computer Architecture. - Memory Hierarchies (I)

12 Cache-Organization 1

Cache Memory COE 403. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

CS61C : Machine Structures

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

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

MEMORY. Objectives. L10 Memory

CPE 631 Lecture 04: CPU Caches

Announcement. Computer Architecture (CSC-3501) Lecture 20 (08 April 2008) Chapter 6 Objectives. 6.1 Introduction. 6.

Memory Hierarchy: The motivation


Chapter Seven. Large & Fast: Exploring Memory Hierarchy

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

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

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

Memory Hierarchy: Caches, Virtual Memory

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

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

Cycle Time for Non-pipelined & Pipelined processors

Welcome to Part 3: Memory Systems and I/O

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

Sarah L. Harris and David Money Harris. Digital Design and Computer Architecture: ARM Edition Chapter 8 <1>

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

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

Cache Memory and Performance

EEC 483 Computer Organization

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

CS 61C: Great Ideas in Computer Architecture Direct- Mapped Caches. Increasing distance from processor, decreasing speed.

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

14:332:331. Week 13 Basics of Cache

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

Algorithm Performance Factors. Memory Performance of Algorithms. Processor-Memory Performance Gap. Moore s Law. Program Model of Memory I

V. Primary & Secondary Memory!

Transcription:

CS C L.. Cache I () Design Principles for Hardware CSC : Machine Structures Lecture.. Cache I -- Kurt Meinz inst.eecs.berkeley.edu/~csc. Simplicity favors regularity Every instruction has operands, opcode same place for EVERY instr. Smaller is faster registers, no more. Good design demands good compromise MIPS Immediate format vs. R format. Make the common case fast Support of constants via immediates K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB The Big Picture Memory Hierarchy (/) Computer Processor Memory (active) (passive) Control (where ( brain ) programs, Datapath data live ( brawn ) when running) CS C L.. Cache I () Devices Input Output Keyboard, Mouse Disk, Network Display, Printer K. Meinz, Summer UCB Processor executes instructions on order of nanoseconds to picoseconds holds a small amount of code and data in registers Memory More capacity than registers, still limited Access time ~- ns Disk HUGE capacity (virtually limitless) VERY slow: runs ~milliseconds CS C L.. Cache I () K. Meinz, Summer UCB Memory Hierarchy (/) Processor Higher Levels in memory hierarchy Lower Size of memory at each level As we move to deeper levels the latency goes up and price per bit goes down. CS C L.. Cache I () Level Level Level... Level n Increasing Distance from Proc., Decreasing speed K. Meinz, Summer UCB Memory Hierarchy (/) If level closer to Processor, it must be: smaller faster subset of lower levels (contains most recently used data) Lowest Level (usually disk) contains all available data Other levels? CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I () Trend Comparison Processor Performance Cycle time Exponential Growth # Transistors Exponential Growth Memory Performance RAM size Exponential Disk Size Exponential RAM/Disk Access Time Roughly Linear/Slow exponential Trend Comparison Performance 98 98 98 98 98 98 98 98 988 989 99 99 99 99 99 99 99 99 998 999 CPU DRAM µproc %/yr. Processor-Memory Performance Gap: (grows % / year) DRAM %/yr. 989 first Intel CPU with cache on chip 998 Pentium III has two levels of cache on chip K. Meinz, Summer UCB CS C L.. Cache I (8) K. Meinz, Summer UCB Memory Caching We ve discussed three levels in the hierarchy: processor, memory, disk Mismatch between processor and memory speeds leads us to add a new level: a memory cache Implemented with SRAM technology: faster but more expensive than DRAM memory. Memory Hierarchy Analogy: Library (/) You re writing a term paper (Processor) at a table in Doe Doe Library is equivalent to disk essentially limitless capacity very slow to retrieve a book Table is memory smaller capacity: means you must return book when table fills up easier and faster to find a book there once you ve already retrieved it CS C L.. Cache I (9) K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Memory Hierarchy Analogy: Library (/) Open books on table are cache smaller capacity: can have very few open books fit on table; again, when table fills up, you must close a book much, much faster to retrieve data Illusion created: whole library open on the tabletop Keep as many recently used books open on table as possible since likely to use again Also keep as many books on table as possible, since faster than going to library Memory Hierarchy Analogy: Library (/) At any time, you have a working set of books you access most often Your working set shifts over time (maybe study Schopenhauer then Nietzsche). But it s always a small subset of the books in the library. As long as you can keep your working set close to you, your book effective access time is very fast Programs work just the same way CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I () Memory Hierarchy Basics Programs exhibit temporal locality If we just accessed it, chances are we ll access it again soon. Or, more formally, The probability of accessing a particular piece of data varies inversely with the time since we last accessed it. FYI: Working set is theoretical. Temporal locality is a way of finding the working set of a program. Memory Hierarchy Basics Disk contains everything. Memory contains copies of data on disk that are being used. Cache contains copies of data in memory that are being used. When Processor needs something, bring it into to all higher levels of memory. K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Cache Design Cache Design: Four Questions Big Four Questions of Cache Design Where does each memory address map to? (Remember that cache is subset of memory, so multiple memory addresses map to the same cache location.) How do we know which elements are in cache? How do we quickly locate them? How/when do we replace things Q: Where can a block be placed in the upper level? (Block placement) Q: How is a block found if it is in the upper level? (Block identification) Q: Which block should be replaced on a miss? (Block replacement) Q: What happens on a write? (Write strategy) CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Direct-Mapped Cache (/) In a direct-mapped cache, each memory address is associated with one possible block within the cache Therefore, we only need to look in a single location in the cache for the data if it exists in the cache Block is the unit of transfer between cache and memory CS C L.. Cache I () K. Meinz, Summer UCB Direct-Mapped Cache (/) Cache Memory Index Memory Address 8 9 A B C D E F CS C L.. Cache I (8) Byte Direct Mapped Cache Cache Location can be occupied by data from: Memory location,, 8, blocks => any memory location that is multiple of K. Meinz, Summer UCB

CS C L.. Cache I (9) Issues with Direct-Mapped Since multiple memory addresses map to same cache index, how do we tell which one is in there? What if we have a block size > byte? Result: divide memory address into three fields ttttttttttttttttt iiiiiiiiii oooo tag index byte to check to offset if have select within correct block block block 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 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 K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Caching Terminology When we try to read memory, things can happen:. cache hit: cache block is valid and contains proper address, so read desired word. cache miss: nothing in cache in appropriate block, so fetch from memory. cache miss, block replacement: wrong data is in cache at appropriate block, so discard it and fetch desired data from memory (cache always copy) Direct-Mapped Cache Example (/) Suppose we have a KB of data in a direct-mapped cache with word blocks Determine the size of the tag, index and offset fields if we re using a -bit architecture Offset need to specify correct byte within a block block contains words = bytes = bytes need bits to specify correct byte CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Direct-Mapped Cache Example (/) Index: (~index into an array of blocks ) need to specify correct row in cache cache contains KB = bytes block contains bytes ( words) # blocks/cache = bytes/cache bytes/block = bytes/cache bytes/block = blocks/cache need bits to specify this many rows Direct-Mapped Cache Example (/) Tag: use remaining bits as tag tag length = addr length offset - index = - - bits = 8 bits so tag is leftmost 8 bits of memory address Why not full bit address as tag? All bytes within block need same address (b) Index must be same for every address within a block, so its redundant in tag check, thus can leave off to save memory ( bits in this example) CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I () Accessing data in a direct mapped cache Ex.: KB of data, Memory direct-mapped, word blocks Read addresses. x. xc. x. x8 Memory values on right: only cache/ memory level of hierarchy Address (hex)value of Word a b 8 c C d 8 C 8 8 88 8C e f g h i j k l K. Meinz, Summer UCB Accessing data in a direct mapped cache Addresses: x, xc, x, x8 Addresses divided (for convenience) into Tag, Index, Byte Offset fields Tag Index Offset CS C L.. Cache I () K. Meinz, Summer UCB KB Direct Mapped Cache, B blocks bit: determines whether anything is stored in that row (when computer initially turned on, all entries are invalid) Index Tag x- x- x8-b xc-f. Read x Index Tag x- x- x8-b xc-f CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I (8) K. Meinz, Summer UCB So we read block () Index Tag x- x- x8-b xc-f No valid data Index Tag x- x- x8-b xc-f CS C L.. Cache I (9) K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I () So load that data into cache, setting tag, valid Index Tag x- x- x8-b xc-f a b c d Read from cache at offset, return word b Index Tag x- x- x8-b xc-f a b c d K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB. Read xc =.. Index Tag x- x- x8-b xc-f a b c d Index is Index Tag x- x- x8-b xc-f a b c d CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Index valid, Tag Matches Index Tag x- x- x8-b xc-f a b c d Index, Tag Matches, return d Index Tag x- x- x8-b xc-f a b c d CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I (). Read x =.. Index Tag x- x- x8-b xc-f a b c d So read block Index Tag x- x- x8-b xc-f a b c d K. Meinz, Summer UCB CS C L.. Cache I (8) K. Meinz, Summer UCB No valid data Index Tag x- x- x8-b xc-f a b c d Load that cache block, return word f Index Tag x- x- x8-b xc-f a b c d e f g h CS C L.. Cache I (9) K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB. Read x8 =.. Index Tag x- x- x8-b xc-f a b c d e f g h So read Cache Block, Data is Index Tag x- x- x8-b xc-f a b c d e f g h CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB

CS C L.. Cache I () Cache Block Tag does not match (!= ) Index Tag x- x- x8-b xc-f a b c d e f g h Miss, so replace block with new data & tag Index Tag x- x- x8-b xc-f i j k l e f g h K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB And return word j Index Tag x- x- x8-b xc-f i j k l e f g h Do an example yourself. What happens? Chose from: Cache: Hit, Miss, Miss w. replace Values returned: a,b, c, d, e,, k, l Read address x? Read address xc? Cache Index Tag x- x- x8-b xc-f i j k l e f g h CS C L.. Cache I () K. Meinz, Summer UCB CS C L.. Cache I () K. Meinz, Summer UCB Answers x a hit Memory Index =, Tag matches, Offset =, value = e Address Value of Word a xc a miss b 8 c Index =, Tag mismatch, c d so replace from memory, Offset = xc, value = d Since reads, values must = memory values whether or not cached: x = e xc = d CS C L.. Cache I () 8 c 8 8 88 8c e f g h i j k l K. Meinz, Summer UCB And in Conclusion 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 Tag x- x- x8-b xc-f a b c d CS C L.. Cache I (8) K. Meinz, Summer UCB