Question F5: Caching [10 pts]

Similar documents
Do not turn the page until 12:30.

Question F5: Caching [10 pts]

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

Using 7 bits, the MSB has to be 1 for negative numbers. So there are 6 negative numbers in total.

University of Washington Computer Science & Engineering Winter 2018 Instructor: Mark Wyse March 14, CSE 351 Final Exam. Last Name: First Name:

Do not turn the page until 12:30.

Question 1: Number Representation

CSE 351 Midterm Exam

Do not turn the page until 12:30.

Do not turn the page until 12:30.

1 Number Representation(10 points)

Do not turn the page until 12:30.

3. Address Translation (25 pts)

Problem 9. VM address translation. (9 points): The following problem concerns the way virtual addresses are translated into physical addresses.

The cache is 4-way set associative, with 4-byte blocks, and 16 total lines

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

CSE 351 Spring 2017 Midterm Exam (8 May 2017)

Virtual Memory III. CSE 351 Autumn Instructor: Justin Hsia

Virtual Memory: Systems

CSE 351 Spring 2017 Final Exam (7 June 2017)

CS , Spring 2002 Exam 2

CSE 351 Midterm - Winter 2015 Solutions

CSE 351 Midterm - Winter 2015

Do not turn the page until 5:10.

CS , Fall 2001 Exam 2

15-213, Fall 2007 Midterm Exam

15-213/18-213, Fall 2011 Final Exam

CSE 351. Virtual Memory

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Virtual Memory Overview

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

CS , Fall 2001 Exam 2

Do not turn the page until 5:10.

14 May 2012 Virtual Memory. Definition: A process is an instance of a running program

Do not turn the page until 5:10.

CS , Fall 2007 Exam 1

CSE 153 Design of Operating Systems

Virtual Memory Nov 9, 2009"

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

Virtual Memory II CSE 351 Spring

Do not turn the page until 5:10.

This lecture. Virtual Memory. Virtual memory (VM) CS Instructor: Sanjeev Se(a

Systems Programming and Computer Architecture ( ) Timothy Roscoe

CSE 351 Midterm - Winter 2017

Virtual Memory. Alan L. Cox Some slides adapted from CMU slides

Computer Systems. Virtual Memory. Han, Hwansoo

Question 6: Cache in While You Can (17 points, 26 Minutes)

Foundations of Computer Systems

CSE351 Autumn 2013 Final Exam (11 Dec 2013)

Final Exam Introduction to Computer Systems. May 10, Name: Andrew User ID: Recitation Section: Model Solution fp

CSE351 Autumn 2010 Final Exam (December 13, 2010)

Name: Login: cs61c- Decimal Ternary 5 12 three three

P6/Linux Memory System Nov 11, 2009"

Virtual Memory: Systems

CS , Fall 2003 Exam 2

Systems programming and Operating systems, 2005 Tentamen

Systems programming and Operating systems, 2005 Test Exam

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

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

CSE 351 Midterm Exam Spring 2016 May 2, 2015

F2) V(I/O)rtual Potpourri (23 pts)

Virtual Memory Oct. 29, 2002

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

CSE351 Autumn 2012 Midterm Exam (5 Nov 2012)

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Introduction to Computer Systems. Exam 2. April 11, Notes and calculators are permitted, but not computers.

CS-220 Spring 2018 Final Exam Version Practice May 10, Name:

Virtual Memory. Samira Khan Apr 27, 2017

Virtual Memory I. CSE 351 Spring Instructor: Ruth Anderson

CS 153 Design of Operating Systems

CSE351 Spring 2010 Final Exam (9 June 2010)

CISC 360. Virtual Memory Dec. 4, 2008

Virtual Memory I. CSE 351 Winter Instructor: Mark Wyse

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Binghamton University. CS-220 Spring X86 Debug. Computer Systems Section 3.11

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

University*of*Washington*

L14: Structs and Alignment. Structs and Alignment. CSE 351 Spring Instructor: Ruth Anderson

Do not turn the page until 11:30.

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

University of Washington Virtual memory (VM)

Carnegie Mellon. 16 th Lecture, Mar. 20, Instructors: Todd C. Mowry & Anthony Rowe

UW CSE 351, Winter 2013 Midterm Exam

Processes and Virtual Memory Concepts

CSE351 Autumn 2014 Midterm Exam (29 October 2014)

Virtual Memory: Concepts

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

15-213: Final Exam Review

Virtual Memory: Concepts

CSE351 Spring 2010 Final Exam (9 June 2010)

CS , Spring 2004 Exam 1

15-213/18-243, Fall 2010 Exam 1 - Version A

Problem Page Possible Score Total 80

UW CSE 351, Winter 2013 Final Exam

CS 3330 Exam 3 Fall 2017 Computing ID:

Memory System Case Studies Oct. 13, 2008

Pentium/Linux Memory System March 17, 2005

Introduction to Computer Systems. Exam 2. April 10, Notes and calculators are permitted, but not computers.

Transcription:

Question F5: Caching [ pts] SID: We have 6 KiB of RAM and two options for our cache. Both are two-way set associative with 256 B blocks, LRU replacement, and write-back policies. Cache A is size KiB and Cache B is size 2 KiB. (A) Calculate the TIO address breakdown for Cache B: [.5 pt] Tag bits Index bits Offset bits (B) The code snippet below accesses an integer array. Calculate the Miss Rate for Cache A if it starts cold. [3 pt] #define LEAP 4 #define ARRAY_SIZE 52 int nums[array_size]; // &nums = x (physical addr) for (i = ; i < ARRAY_SIZE; i+=leap) nums[i] = i*i; (C) For each of the proposed (independent) changes, write MM for higher miss rate, NC for no change, or MH for higher hit rate to indicate the effect on Cache A for the code above:[3.5 pt] Direct-mapped Double LEAP Increase block size Write-through policy (D) Assume it takes 2 ns to get a block of data from main memory. Assume Cache A has a hit time of 4 ns and a miss rate of 4% while Cache B, being larger, has a hit time of 6 ns. What is the worst miss rate Cache B can have in order to perform as well as Cache A? [2 pt] 7

Question F7: Processes [9 pts] (A) The following function prints out four numbers. In the following blanks, list three possible outcomes: [3 pt] void concurrent(void) { int x = 3, status; if (fork()) { if (fork() == ) { x += 2; printf("%d",x); } else { wait(&status); wait(&status); x -= 2; } } printf("%d",x); exit(); } () (2) (3) (B) For the following examples of exception causes, write N for intentional or U for unintentional from the perspective of the user process. [2 pt] System call Segmentation fault Hardware failure Mouse clicked (C) Briefly define a zombie process. Name a process that can reap a zombie process. [2 pt] Zombie process: Reaping process: (D) In the following blanks, write Y for yes or N for no if the following need to be updated when execv is run on a process. [2 pt] Page table PTBR Stack Code 8

Question M: Number Representation [8 pts] (A) Take the 32-bit numeral xc8. Circle the number representation below that has the most negative value for this numeral. [2 pt] Floating Point Sign & Magnitude Two s Complement Unsigned (B) Let float f hold the value 2 2. What is the largest power of 2 that gets rounded off when added to f? Answer in exponential form, not just the exponent. [2 pt] Traffic lights display three basic colors: red (R), yellow (Y), and green (G), so we can use them to encode base 3! We decide to use the encoding R, Y, 2 G. For example, 5 = 3 +2 3 would be encoded as YG. Assume each traffic light can only display one color at a time. (C) What is the unsigned decimal value of the traffic lights displaying RGYY? [2 pt] (D) If we have 9 bits of binary data that we want to store, how many traffic lights would it take to store that same data? [2 pt] Question M2: Design Question [2 pts] (A) The machine code for x86-64 instructions are variable length. Name one advantage and one disadvantage of this design decision. [2 pt] Advantage: Disadvantage: 2

3. Virtual Memory (9 points) Assume we have a virtual memory detailed as follows: 256 MiB Physical Address Space 4 GiB Virtual Address Space KiB page size A TLB with 4 sets that is 8-way associative with LRU replacement For the following questions it is fine to leave your answers as powers of 2. a) How many bits will be used for: Page offset? Virtual Page Number (VPN)? Physical Page Number ()? TLB index? TLB tag? b) How many entries in this page table? c) We run the following code with an empty TLB. Calculate the TLB miss rate for data (ignore instruction fetches). Assume i and sum are stored in registers and cool is page-aligned. #define LEAP 8 int cool[52];... // Some code that assigns values into the array cool... // Now flush the TLB. Start counting TLB miss rate from here. int sum; for (int i = ; i < 52; i += LEAP) { sum += cool[i]; } TLB Miss Rate: (fine to leave you answer as a fraction) 4 of 9

UW NetID: _ Question 4: Procedures & The Stack [24 pts.] Consider the following x86-64 assembly and C code for the recursive function rfun. // Recursive function rfun long rfun(char *s) { if (*s) { long temp = (long)*s; s++; return temp + rfun(s); } return ; } // Main Function - program entry int main(int argc, char **argv) { char *s = "CSE35"; long r = rfun(s); printf("r: %ld\n", r); } 45e6 <rfun>: 45e6: f b6 7 movzbl (%rdi),%eax 45e9: 84 c test %al,%al 45eb: 74 3 je 46 <rfun+xa> 45ed: 53 push %rbx 45ee: 48 f be d8 movsbq %al,%rbx 45f2: 48 83 c7 add $x,%rdi 45f6: e8 eb ff ff ff callq 45e6 <rfun> 45fb: 48 d8 add %rbx,%rax 45fe: eb 6 jmp 466 <rfun+x2> 46: b8 mov $x,%eax 465: c3 retq 466: 5b pop %rbx 467: c3 retq 5

UW NetID: _ (A) How much space (in bytes) does this function take up in our final executable? [2 pts.] (B) The compiler automatically creates labels it needs in assembly code. How many labels are used in rfun (including the procedure itself)? [2 pts.] (C) In terms of the C function, what value is being saved on the stack? [2 pts.] (D) What is the return address to rfun that gets stored on the stack during the recursive calls (in hex)? [2 pts.] (E) Assume main calls rfun with char *s = CSE35 and then prints the result using the printf function, as shown in the C code above. Assume printf does not call any other procedure. Starting with (and including) main, how many total stack frames are created, and what is the maximum depth of the stack? [2 pts.] Total Frames: Max Depth: 6

UW NetID: _ (F) Assume main calls rfun with char *s = CSE35, as shown in the C code. After main calls rfun, we find that the return address to main is stored on the stack at address x7fffffffdb38. On the first call to rfun, the register %rdi holds the address x46d, which is the address of the input string CSE35 (i.e. char *s == x46d). Assume we stop execution prior to executing the movsbq instruction (address x45ee) during the fourth call to rfun. [4 pts.] For each address in the stack diagram below, fill in both the value and a description of the entry. The value field should be a hex value, an expression involving the C code listed above (e.g., a variable name such as s or r, or an expression involving one of these), a literal value (integer constant, a string, a character, etc.), unknown if the value cannot be determined, or unused if the location is unused. The description field should be one of the following: Return address, Saved %reg (where reg is the name of a register), a short and descriptive comment, unused if the location is unused, or unknown if the value is unknown. Memory Address Value Description x7fffffffdb48 unknown %rsp when main is entered x7fffffffdb38 x466 Return address to main x7fffffffdb3 unknown original %rbx x7fffffffdb28 x7fffffffdb2 x7fffffffdb8 x7fffffffdb x7fffffffdb8 x7fffffffdb 7

/2/27 L2: Virtual Memory II CSE35, Winter 28 Summary of Address Translation Symbols Basic Parameters N = 2 n Number of addresses in virtual address space M = 2 m Number of addresses in physical address space P = 2 p Page size (bytes) Components of the virtual address (VA) VPO VPN TLBI TLBT Virtual page offset Virtual page number TLB index TLB tag Components of the physical address (PA) PPO Physical page offset (same as VPO) Physical page number 8 L2: Virtual Memory II CSE35, Winter 28 Simple Memory System Example (small) Addressing 4-bit virtual addresses 2-bit physical address Page size = 64 bytes 3 2 9 8 7 6 5 4 3 2 VPN Virtual Page Number VPO Virtual Page Offset 9 8 7 6 5 4 3 2 Physical Page Number PPO Physical Page Offset 9

/2/27 L2: Virtual Memory II CSE35, Winter 28 Simple Memory System: Page Table Only showing first 6 entries (out of ) Note: showing 2 hex digits for even though only 6 bits Note: other management bits not shown, but part of PTE VPN Valid 28 2 33 3 2 4 5 6 6 7 VPN Valid 8 3 9 7 A 9 B C D 2D E F D 2 L2: Virtual Memory II CSE35, Winter 28 Simple Memory System: TLB 6 entries total 4-way set associative Why does the TLB ignore the page offset? TLB tag TLB index 3 2 9 8 7 6 5 4 3 2 virtual page number virtual page offset Set Tag Valid Tag Valid Tag Valid Tag Valid 3 9 D 7 2 3 2D 2 4 A 2 2 8 6 3 3 7 3 D A 34 2 2 2

/2/27 L2: Virtual Memory II Simple Memory System: Cache Direct-mapped with K = 4 B, C/K = 6 Physically addressed CSE35, Winter 28 Note: It is just coincidence that the is the same width as the cache Tag cache tag cache index cache offset 9 8 7 6 5 4 3 2 physical page number Index Tag Valid B B B2 B3 9 99 23 5 2 B 2 4 8 3 36 4 32 43 6D 8F 9 5 D 36 72 F D 6 3 7 6 C2 DF 3 physical page offset Index Tag Valid B B B2 B3 8 24 3A 5 89 9 2D A 2D 93 5 DA 3B B B C 2 D 6 4 96 34 5 E 3 83 77 B D3 F 4 22 L2: Virtual Memory II CSE35, Winter 28 Current State of Memory System TLB: Set Tag V Tag V Tag V Tag V 3 9 D 7 2 3 2D 2 4 A 2 2 8 6 3 3 7 3 D A 34 2 Cache: Index Tag V B B B2 B3 9 99 23 5 2 B 2 4 8 3 36 4 32 43 6D 8F 9 5 D 36 72 F D 6 3 7 6 C2 DF 3 Page table (partial): VPN V VPN V 28 8 3 9 7 2 33 A 9 3 2 B 4 C 5 6 D 2D 6 E 7 F D Index Tag V B B B2 B3 8 24 3A 5 89 9 2D A 2D 93 5 DA 3B B B C 2 D 6 4 96 34 5 E 3 83 77 B D3 F 4 23 3

/2/27 L2: Virtual Memory II CSE35, Winter 28 Memory Request Example # Virtual Address: x3d4 TLBT TLBI 3 2 9 8 7 6 5 4 VPN 3 2 VPO Note: It is just coincidence that the is the same width as the cache Tag VPN TLBT TLBI TLB Hit? Page Fault? Physical Address: CT CI CO 9 8 7 6 5 4 3 2 PPO CT CI CO Cache Hit? Data (byte) 24 L2: Virtual Memory II Memory Request Example #2 Virtual Address: x38f TLBT TLBI 3 2 9 8 7 6 5 4 VPN 3 2 VPO CSE35, Winter 28 Note: It is just coincidence that the is the same width as the cache Tag VPN TLBT TLBI TLB Hit? Page Fault? Physical Address: CT CI CO 9 8 7 6 5 4 3 2 PPO CT CI CO Cache Hit? Data (byte) 25 4

/2/27 L2: Virtual Memory II CSE35, Winter 28 Memory Request Example #3 Virtual Address: x2 TLBT TLBI 3 2 9 8 7 6 5 4 VPN 3 2 VPO Note: It is just coincidence that the is the same width as the cache Tag VPN TLBT TLBI TLB Hit? Page Fault? Physical Address: CT CI CO 9 8 7 6 5 4 3 2 PPO CT CI CO Cache Hit? Data (byte) 26 L2: Virtual Memory II Memory Request Example #4 Virtual Address: x36b TLBT TLBI 3 2 9 8 7 6 5 4 VPN 3 2 VPO CSE35, Winter 28 Note: It is just coincidence that the is the same width as the cache Tag VPN TLBT TLBI TLB Hit? Page Fault? Physical Address: CT CI CO 9 8 7 6 5 4 3 2 PPO CT CI CO Cache Hit? Data (byte) 27 5