Cache and Virtual Memory Simulations

Similar documents
Computer Systems Principles Cache Simulator

Carnegie Mellon. Cache Lab. Recitation 7: Oct 11 th, 2016

Cache Lab Implementation and Blocking

CS 433 Homework 5. Assigned on 11/7/2017 Due in class on 11/30/2017

Review: Computer Organization

Recitation 7 Caches and Blocking. 9 October 2017

13-1 Memory and Caches

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

exercise 4 byte blocks, 4 sets index valid tag value 00

See also cache study guide. Contents Memory and Caches. Supplement to material in section 5.2. Includes notation presented in class.

Caches in Real-Time Systems. Instruction Cache vs. Data Cache

associativity terminology

See also cache study guide. Contents Memory and Caches. Supplement to material in section 5.2. Includes notation presented in class.

Caches III. CSE 351 Autumn Instructor: Justin Hsia

CSE351 Spring 2018, Final Exam June 6, 2018

Cache Memory: Instruction Cache, HW/SW Interaction. Admin

ECE331 Homework 4. Due Monday, August 13, 2018 (via Moodle)

Caches Design of Parallel and High-Performance Computing Recitation Session

Caches (Writing) Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.2 3, 5.5

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

Q3: Block Replacement. Replacement Algorithms. ECE473 Computer Architecture and Organization. Memory Hierarchy: Set Associative Cache

Cache Memory and Performance

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

ECE 2300 Digital Logic & Computer Organization. More Caches

6.004 Tutorial Problems L14 Cache Implementation

Chapter 09: Caches. Lesson 04: Replacement policy

ECE 30 Introduction to Computer Engineering

3) Cache, money. Dollar bills, y all. (24 min, 15 pts)

Question 13 1: (Solution, p 4) Describe the inputs and outputs of a (1-way) demultiplexer, and how they relate.

CSE351 Winter 2016, Final Examination March 16, 2016

Com S 321 Problem Set 3

Memory Hierarchy: Caches, Virtual Memory

Memory and Addresses. Pointers in C. Memory is just a sequence of byte-sized storage devices.

Improving our Simple Cache

VIRTUAL MEMORY II. Jo, Heeseung

Writing Functions in C

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

CS 136: Advanced Architecture. Review of Caches

Caches in Real-Time Systems. Instruction Cache vs. Data Cache

CISC 360. Cache Memories Exercises Dec 3, 2009

Computer Systems. Virtual Memory. Han, Hwansoo

UW CSE 351, Winter 2013 Final Exam

Caches III. CSE 351 Autumn Instructor: Justin Hsia

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Show Me the $... Performance And Caches

CS356: Discussion #9 Memory Hierarchy and Caches. Marco Paolieri Illustrations from CS:APP3e textbook

211: Computer Architecture Summer 2016

General Cache Mechanics. Memory Hierarchy: Cache. Cache Hit. Cache Miss CPU. Cache. Memory CPU CPU. Cache. Cache. Memory. Memory

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

Administrivia. Caches III. Making memory accesses fast! Associativity. Cache Organization (3) Example Placement

Lecture 20: Multi-Cache Designs. Spring 2018 Jason Tang

CS 240 Stage 3 Abstractions for Practical Systems

Key Point. What are Cache lines

Caches and Memory. Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , 5.8, 5.10, 5.13, 5.15, 5.17

CSE-160 (Winter 2017, Kesden) Practice Midterm Exam. volatile int count = 0; // volatile just keeps count in mem vs register

Virtual Memory II CSE 351 Spring

Caches III CSE 351 Spring

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

a) Do exercise (5th Edition Patterson & Hennessy). Note: Branches are calculated in the execution stage.

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

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

CS 31: Intro to Systems Caching. Kevin Webb Swarthmore College March 24, 2015

EE 4683/5683: COMPUTER ARCHITECTURE

CS 31: Intro to Systems Caching. Martin Gagne Swarthmore College March 23, 2017

Memory System Implementation

data block 0, word 0 block 0, word 1 block 1, word 0 block 1, word 1 block 2, word 0 block 2, word 1 block 3, word 0 block 3, word 1 Word index cache

CMPSC 311- Introduction to Systems Programming Module: Caching

CS 61C: Great Ideas in Computer Architecture. Multilevel Caches, Cache Questions

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

Levels in memory hierarchy

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

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

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

CS429: Computer Organization and Architecture

1. Creates the illusion of an address space much larger than the physical memory

CSE 153 Design of Operating Systems

CS3350B Computer Architecture

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

Page 1. Memory Hierarchies (Part 2)

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

6.004 Tutorial Problems L14 Cache Implementation

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

Caches & Memory. CS 3410 Computer System Organization & Programming

ECE 454 Computer Systems Programming

Your submitted proj3.c must compile and run on linprog as in the following example:

Caches (Writing) P & H Chapter 5.2 3, 5.5. Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

Memory Hierarchy Design (Appendix B and Chapter 2)

Announcements. ! Previous lecture. Caches. Inf3 Computer Architecture

VIRTUAL MEMORY READING: CHAPTER 9

Caches (Writing) P & H Chapter 5.2 3, 5.5. Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University

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

Caches. Samira Khan March 23, 2017

CS Computer Architecture

Structure of Computer Systems

Advanced Computer Architecture

Memory Hierarchy. Slides contents from:

CS 465 Final Review. Fall 2017 Prof. Daniel Menasce

William Stallings Copyright 2009

EEC 483 Computer Organization. Chapter 5.3 Measuring and Improving Cache Performance. Chansu Yu

Transcription:

Cache and Virtual Memory Simulations

Does it really matter if you pull a USB out before it safely ejects?

Data structure: Cache struct Cache { }; Set *sets; int set_count; int line_count; int block_size; int set_bits; int block_bits; Set 0: Set 1: Set S -1: 1 valid bit per line Valid Valid Valid Valid Valid Valid t tag bits per line Tag Tag Tag Tag Tag Tag 0 0 B bytes per cache line 0 0 0 0 1 1 1 1 1 1 B 1 B 1 B 1 B 1 B 1 B 1 E lines per set

Data structure: Cache struct Cache { Set *sets; Memory Address: m-1 t bits set_bits bits block_bits bits 0 int set_count; Tag Set index Block offset int line_count; int block_size; int set_bits; int block_bits; block size = 2 _ set count = 2 _ };

Data structure: Cache struct Cache { Set *sets; Memory Address: m-1 t bits set_bits bits block_bits bits 0 int set_count; Tag Set index Block offset int line_count; int block_size; int set_bits; int block_bits; block size = 2 _ set count = 2 _ };

Data structure: Cache struct Cache { Set *sets; Memory Address: m-1 t bits set_bits bits block_bits bits 0 int set_count; Tag Set index Block offset int line_count; int block_size; int set_bits; int block_bits; block size = 2 _ set count = 2 _ };

Data structure: Cache struct Cache { Set *sets; Memory Address: m-1 t bits set_bits bits block_bits bits 0 int set_count; Tag Set index Block offset int line_count; int block_size; int set_bits; int block_bits; block size = 2 _ set count = 2 _ };

Data structure: Set struct Set { Line *lines; int line_count; LRUNode *lru_queue; }; lines is an array lru_queue is a pointer to the head node of a queue

Data structure: Set struct Set { Line *lines; int line_count; LRUNode *lru_queue; }; lines is an array lru_queue is a pointer to the head node of a queue

Data structure: Line struct Line { char valid; int tag; char *accessed; int block_size; };

Data structure: Line struct Line { char valid; int tag; char *accessed; int block_size; };

i-clicker question If a cache has 4 blocks per line, how many block offset bits in the address do we need? A. 1 B. 2 C. 3 D. 4

i-clicker question If a cache has 256 sets, how many set index bits in the address do we need? A. 2 B. 4 C. 6 D. 8

Create and initialize cache Cache *cache = //allocate memory for a cache

Create and initialize cache Cache *cache = //allocate memory for a cache Set *sets = // allocate memory for a set

Create and initialize cache Cache *cache = //allocate memory for a cache Set *sets = // allocate memory for a set cache->sets = make_sets(..) // allocate memory for and initialize the set array sets[i].lines = make_lines(..) // allocate memory for and initialize the lines array

Create and initialize cache No freeing Cache *cache = //allocate memory for a cache Set *sets = // allocate memory for a set cache->sets = make_sets(..) // allocate memory for and initialize the set array sets[i].lines = make_lines(..) // allocate memory for and initialize the lines array

Create and initialize cache Cache *cache = //allocate memory for a cache Set *sets = // allocate memory for a set cache->sets = make_sets(..) // allocate memory for and initialize the set array sets[i].lines = make_lines(..) // allocate memory for and initialize the lines array line[i].valid = 0; line[i].tag = 0;

Create and initialize cache Cache *cache = //allocate memory for a cache Set *sets = // allocate memory for a set cache->sets = make_sets(..) // allocate memory for and initialize the set array sets[i].lines = make_lines(..) // allocate memory for and initialize the lines array line[i].valid = 0; line[i].tag = 0; cache->set_count = // 2 raised to the power of set_bits cache->block_size = // 2 raised to the power of block_bits

i-clicker question Consider a computer system where each memory address has m address bits. 2 of these bits are block offset bits. What is the correct way to allocate memory for blocks in a single line? Suppose each block has 1 byte. A. char *blocks = (char *)(malloc(2)); B. char *blocks = malloc(2); C. char *blocks = (char *)(malloc(4)); D. char *blocks = malloc(4);

Cache Miss Cold miss: The first reference to a block of memory, starting with an invalid cache line. Conflict miss: Two blocks are mapped to set and there is not enough room to hold both.

LRU algorithm Maintain a linked list Hit pull the used cache line to the front Cold miss fetch data from memory add a new cache line that contains the new data at the head Conflict miss fetch data from memory get the tail of the list and update it with new data, then move this cache line to the head of the list

LRU algorithm Maintain a linked list Hit pull the used cache line to the front Cold miss fetch data from memory add a new cache line that contains the new data at the head Conflict miss fetch data from memory get the tail of the list and update it with new data, then move this cache line to the head of the list What if the cache is a direct-mapped cache?

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5 cache hit

LRU algorithm in a set Reference tag sequence: 2 6 7 2 1 3 4 5 cache hit

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 1 2 3 4 5 cold miss

LRU algorithm in a set Reference tag sequence: 2 6 7 3 1 2 4 5 cold miss

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5 cold miss

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 5 conflict miss

LRU algorithm in a set Reference tag sequence: 2 6 7 6 1 2 4 7 conflict miss

LRU algorithm in a set Reference tag sequence: 2 6 7 7 6 1 2 4 conflict miss

LRU algorithm in a set Reference tag sequence: 2 6 7 7 6 1 2 4 conflict miss

LRU algorithm current = set->lru_queue; while current is not NULL: line = current->line if the line is valid and the tag matches: we have a hit, move the lru_node to the front and adjust the linked list return if the line is not valid: we have a cold miss set the line valid to 1, update its tag, move the lru_node to the front and adjust the linked list return go to the next element in the list and loop again if we iterated through all the lines in the set and did not find a cold line or matching tag we have a conflict miss we will resue the last line, update its tag, move this line to the front of the LRU stack/queue. return

LRU algorithm current = set->lru_queue; while current is not NULL: line = current->line if the line is valid and the tag matches: we have a hit, move the lru_node to the front and adjust the linked list return if the line is not valid: we have a cold miss set the line valid to 1, update its tag, move the lru_node to the front and adjust the linked list return go to the next element in the list and loop again if we iterated through all the lines in the set and did not find a cold line or matching tag we have a conflict miss we will resue the last line, update its tag, move this line to the front of the LRU stack/queue. return

i-clicker question Which of the following is not true for LRU caching algorithm? A. When you have a cold miss and you enter a new line (with the new tag and valid bits) you should make sure that you make that line to the top of the queue as it is the most recently accessed line. B. During a conflicting miss, LRU is taking the last element and make it the first with the new tag values. C. During the eviction, LRU discards the least recently used items first. D. During a hit, LRU is taking the last element and make it the first with the new tag values.