CSE 451 Midterm Exam May 13 th, 2009

Similar documents
Midterm 1, CSE 451, Winter 2001 (Prof. Steve Gribble)

Operating Systems Comprehensive Exam. Spring Student ID # 2/17/2011

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Midterm Exam #2 Solutions October 25, 2016 CS162 Operating Systems

Midterm Exam Solutions and Grading Guidelines March 3, 1999 CS162 Operating Systems

(b) External fragmentation can happen in a virtual memory paging system.

CROWDMARK. Examination Midterm. Spring 2017 CS 350. Closed Book. Page 1 of 30. University of Waterloo CS350 Midterm Examination.

Lecture 9: Midterm Review

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

CS-537: Midterm Exam (Fall 2013) Professor McFlub

ECE469 - Operating Systems Engineering Exam # March 25

CSE 153 Design of Operating Systems

CS 162 Midterm Exam. October 18, This is a closed book examination. You have 60 minutes to answer as many questions

CS4411 Intro. to Operating Systems Final Fall points 12 pages

Second Midterm Exam March 21, 2017 CS162 Operating Systems

412-S12 (shankar) Exam 2 SOLUTION Page 1 of 5. 5 problems. 50 points total. Closed book, closed notes, no electronic devices. Write your name above.

Midterm Exam March 13, 2013 CS162 Operating Systems

CS4411 Intro. to Operating Systems Exam 1 Fall points 10 pages

Midterm Exam March 3, 1999 CS162 Operating Systems

CS4411 Intro. to Operating Systems Exam 1 Fall points 9 pages

CMPSCI 377: Operating Systems Exam 1: Processes, Threads, CPU Scheduling and Synchronization. October 9, 2002

CPSC/ECE 3220 Summer 2017 Exam 2

University of Waterloo Midterm Examination Term: Winter Year: Solution. begin solution

University of Waterloo Midterm Examination Term: Winter Year: 2013

Midterm Exam October 15, 2012 CS162 Operating Systems

Operating Systems (1DT020 & 1TT802)

Midterm Exam. October 20th, Thursday NSC

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

Problem Max Points Score Total 100

Operating Systems Comprehensive Exam. Fall Student ID # 10/31/2013

University of California at Berkeley College of Engineering Department of Electrical Engineering and Computer Science

Fundamentals of Operating Systems (COMP355/L) A Student's Manual for Practice Exercises

COMP 3361: Operating Systems 1 Midterm Winter 2009

CS 4410 Operating Systems. Review 1. Summer 2016 Cornell University

CS-537: Midterm Exam (Fall 2013) Professor McFlub: The Solutions Edition

CPSC/ECE 3220 Summer 2018 Exam 2 No Electronics.

CS 318 Principles of Operating Systems

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

CSE 410 Final Exam 6/09/09. Suppose we have a memory and a direct-mapped cache with the following characteristics.

CS399 New Beginnings. Jonathan Walpole

CPS 110 Midterm. Spring 2011

Design of Operating System

CS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #1

Midterm I October 11 th, 2006 CS162: Operating Systems and Systems Programming

CS4411 Intro. to Operating Systems Exam 2 Fall 2009

CPS 310 midterm exam #1, 2/19/2018

CMPS 111 Spring 2013 Prof. Scott A. Brandt Midterm Examination May 6, Name: ID:

CSE 120 Principles of Operating Systems Spring 2017

Translation Buffers (TLB s)

Last Class: Deadlocks. Today

CS 537: Introduction to Operating Systems Fall 2015: Midterm Exam #1

Midterm Exam #2 Solutions April 20, 2016 CS162 Operating Systems

Question: Total Points: Score: CSE421 Midterm Exam. 09 Mar 2012

( B ) 4. Which is not able to solve the race condition? (A) Test and Set Lock (B) Shared memory (C) Semaphore (D) Monitor

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT I

Midterm Exam Solutions Amy Murphy 28 February 2001

CS153: Midterm (Winter 19)

What is the Race Condition? And what is its solution? What is a critical section? And what is the critical section problem?

Midterm #2 Exam April 26, 2006 CS162 Operating Systems

Stanford University Computer Science Department CS 140 Midterm Exam Dawson Engler Winter 1999

CS140 Operating Systems and Systems Programming

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

MCS-378 Intraterm Exam 1 Serial #:

Quiz Answers. CS 537 Lecture 9 Deadlock. What can go wrong? Readers and Writers Monitor Example

Indian Institute of Technology, Kharagpur

Midterm Exam Amy Murphy 19 March 2003

CMPS 111 Spring 2003 Midterm Exam May 8, Name: ID:

CS140 Operating Systems and Systems Programming Midterm Exam

COMP 3361: Operating Systems 1 Final Exam Winter 2009

University of Waterloo Midterm Examination Model Solution

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

CSE 120 Principles of Operating Systems

CS 153 Design of Operating Systems Winter 2016

CS 318 Principles of Operating Systems

CSE 120 Principles of Computer Operating Systems Fall Quarter, 2002 Halloween Midterm Exam. Instructor: Geoffrey M. Voelker

FCM 710: Architecture of Secure Operating Systems

Midterm #2 Exam Solutions April 26, 2006 CS162 Operating Systems

CPS 310 first midterm exam, 2/26/2014

CSE473/Spring st Midterm Exam Tuesday, February 19, 2007 Professor Trent Jaeger

CSE 451 Midterm 1. Name:

CPS 310 second midterm exam, 11/14/2014

COS 318: Midterm Exam (October 23, 2012) (80 Minutes)

Course Description: This course includes the basic concepts of operating system

Sections 01 (11:30), 02 (16:00), 03 (8:30) Ashraf Aboulnaga & Borzoo Bonakdarpour

CS4411 Intro. to Operating Systems Final Fall points 10 pages

Name: uteid: 1. CS439H: Fall 2011 Midterm 1

CS161 Midterm Exam Spring 2006

CMU Introduction to Computer Architecture, Spring 2014 HW 5: Virtual Memory, Caching and Main Memory

Operating Systems: Quiz2 December 15, Class: No. Name:

a. A binary semaphore takes on numerical values 0 and 1 only. b. An atomic operation is a machine instruction or a sequence of instructions

Operating Systems EDA092, DIT 400 Exam

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

CSE 120 Principles of Operating Systems

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

CPS 310 first midterm exam, 10/6/2014

Computer Structure. X86 Virtual Memory and TLB

Computer Science 161

COMP 300E Operating Systems Fall Semester 2011 Midterm Examination SAMPLE. Name: Student ID:

Transcription:

CSE 451 Midterm Exam May 13 th, 2009 Your Name: Student ID: General Information: This is a closed book examination. You have 50 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points given to the question. There are 8 pages on this exam (check to make sure you have all of them), and there is a total of 100 points in all. Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in the question that you believe is open to interpretation, then please go ahead and interpret, but state your assumptions in your answer. 1

Problem 1: (25 points) Which of the following require assistance from hardware to implement correctly and/or safely? For those that do, circle them, and name the necessary hardware support. For those that don t briefly explain why (one or two sentences at most). System call: requires hardware support, in particular to set the CPU s protection bit to run in protected kernel model. Process creation: requires HW support. must do a system call, so need a protection bit. Also, need to manipulate address spaces (i.e., create new page tables for the new process). Thread creation: [ok if you argued that kernel threads require system calls, and hence need a protection bit, but user-level threads do not need assistance from HW] Process context switch: requires HW support. need a timer interrupt to prevent starvation, and also need to manipulate address spaces (usually by changing a register to point to the page directory for the new process, e.g., cr3 on x86) Thread context switch: [ok if you argued that kernel threads require system calls, but user-level threads do not need hw assistance] Lock acquisition : requires hw support. need support for atomic instructions (e.g., test and set), or support for disabling/enabling interrupts. [ note: there are software-only solutions to the critical section problem see problems 6.9 and 6.10 in the textbook -- and therefore it is possible to use those to implement a (very slow) lock. If you claimed you don t need HW for lock acquisition, and justified this by arguing for a software-only solution to CS, we gave you full credit.] Lock release: [even if you require HW support to grab a lock, in many cases you don t need it to release the lock. See, for example, how test-and-set based locks works you don t use the test-and-set to release the lock.] 2

Problem 2: (25 points) Three processes P1, P2, and P3 have priorities P1=1, P2=5, P3=10. ( 10 is higher priority than 1.) The processes execute the following code: P1: begin <code sequence A> lock(x); <critical section CS> unlock(x); <code sequence B> end P2: begin P3: begin <code sequence A> <code sequence A> lock(x); lock(y); lock(y); lock(x); <critical section CS> <critical section CS> unlock(y); unlock(x); unlock(x); unlock(y); <code sequence B> <code sequence B> end end The X and Y locks are initialized to unlocked, i.e., they are free. <code sequence A> takes 2 time units to execute, <code sequence B> takes 3 time units to execute, and <critical section CS> takes 4 time units to execute. Assume lock() and unlock() are instantaneous, and that context switching is also instantaneous. P1 begins executing at time 0, P2 at time 3, and P3 at time 10. There is only one CPU shared by all processes. a) (9 points) Assume that the scheduler uses a priority scheduling policy: at any time, the highest priority process that is ready (runnable and not waiting for a lock) will run. If a process with a higher priority than the currently running process becomes ready, preemption will occur and the higher priority process will start running. Diagram the execution of the three processes over time. Calculate the job throughput and the average turnaround time. On your diagram, use: A to signify that the process is executing <code sequence A> B to signify that the process is executing <code sequence B> X to signify that the process holds lock X and is in the critical section Y to signify that the process holds lock Y and is in the critical section 2 to signify that the process holds both locks and is in the critical section, and leave blank space if the process is not executing (for any reason). We ve started your diagram for you on the next page. 3

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 P1 A A X X X X B B B P2 A A 2 2 2 2 B B B P3 A A 2 2 2 2 B B B Job throughput: Average turnaround time: 3 jobs in 27 time units = 1/9 jobs/time-unit job 1: 27 time unit turnaround. job 2: 21 time unit turnaround. job 3: 11 time unit turnaround. Average: (27 + 21 + 11) / 3 = 59 / 3 = 19 2/3 b) (9 points) Deadlock is a phenomenon that occurs when a process waits for a resource that will never become available. Repeat a) with the same assumptions and priorities, but this time assume that: P1 begins executing at time 0, P2 begins executing at time 6, and P3 begins executing at time 3. P1 has priority 1, P2 has priority 10, and P3 has priority 5. 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 P1 A A X X X X B B B P2 P3 A A A A Job throughput: Average turnaround time: 0 infinity! c) (7 points) Propose and justify a solution to the problem you uncovered in b). Use no more than 3 sentences. Change P3 to grab/release locks in the same order as P2 4

Problem 3: (25 points) (a) (9 points) Find all of the logic bugs in the following piece of code. Modify the code (in place, or above the specific lines you d like to change) to fix the bugs. semaphore mutex = 0; // BUG #1 semaphore mutex = 1; // returns true if the item was added, false otherwise bool add_item_to_queue(queue_t queue, item_t item) { P(mutex); if (is_full(queue)) { V(mutex); // BUG #2 (this was missing) return false; append_to_queue(queue, item); V(mutex); return true; V(mutex); // BUG #3 this should be before the return 5

(b) (16 points) Find all of the logic bugs in the following piece of code. Modify the code (in place, or above the specific lines you d like to change) to fix the bugs. If it is helpful, assume the existence of a thread-safe queue class that has add() and remove() functions. semaphore thread_available = 0, work_available = 0; semaphore thread_available = NUM_THREADS, work_available = 0; functionptr_t dispatch_function; queue dispatch_function_q; thread_t thread_pool[num_threads]; void threadpool_start(int my_id); // PUBLIC FUNCTION; initialize the thread pool void threadpool_init() { for (int i=0; i<num_threads; i++) { thread_pool[i] = thread_create(threadpool_start, i); // PUBLIC FUNCTION; dispatch a worker to run function "f" void threadpool_dispatch(functionptr_t f) { P(thread_available); dispatch_function = f; enqueue(dispatch_function_q, f); V(work_available); // PRIVATE FUNCTION: workers wait here until dispatched void threadpool_start(int my_id) { printf("worker thread %d is alive!\n", my_id); while(1) { P(work_available); x = dequeue(dispatch_function_q); x(); V(thread_available); 6

Problem 4: (25 points) Consider an operating system that uses paging in order to provide virtual memory capabilities; the paging system employs a TLB and a two-level page table. Assume that page tables are wired (pinned) in physical memory, and assume that the TLB is hardware-loaded (i.e, the CPU walks page tables to load the TLB on a miss). Draw a flow chart that describes the logic of handling a memory reference. Your chart must include the possibility of TLB hits and misses, as well as page faults. Be sure to mark which activities are accomplished by hardware, and which are accomplished by the OS s page fault exception handler. Also be sure to clearly identify addresses as either virtual or physical. 7

virtual address == VDX:VPX:offset physical address = PFN:offset issue physical memory reference TLB lookup hit get PFN from PTE miss yes page directory lookup. &PDE = &PD + VDX (phys) PT valid? perms OK? yes page table lookup. &PTE = &PT + VPX (phys) page valid? perms OK? no no page fault (trap to OS) update PDE with phys addr of PT page fault (trap to OS) update PTE with phys addr of page select victim page allocate PT select victim page allocate page no no is victim dirty? yes write back victim page is victim dirty? yes write back victim page RED = HARDWARE BLACK = OS 8

VPN virtual address PDX PTX offset PDX page directory PD base (phys addr) page directory register (cr3 on x86) PTX page table page frame 3 page frame 2 page frame 1 page frame 0 offset 9