Midterm Exam March 13, 2013 CS162 Operating Systems

Similar documents
Spring 2001 Midterm Exam, Anthony D. Joseph

Midterm Exam March 7, 2001 CS162 Operating Systems

Midterm Exam Solutions March 7, 2001 CS162 Operating Systems

Midterm Exam March 3, 1999 CS162 Operating Systems

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

Midterm Exam October 15, 2012 CS162 Operating Systems

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

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

Second Midterm Exam March 21, 2017 CS162 Operating Systems

Midterm Exam #2 April 20, 2016 CS162 Operating Systems

Midterm #2 Exam April 26, 2006 CS162 Operating Systems

Midterm I October 12 th, 2005 CS162: Operating Systems and Systems Programming

Final Exam Solutions May 11, 2012 CS162 Operating Systems

Midterm Exam #1 September 28, 2016 CS162 Operating Systems

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

First Midterm Exam September 28, 2017 CS162 Operating Systems

University of California College of Engineering Computer Science Division- EECS. Midterm Exam March 13, 2003 CS162 Operating Systems

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

Midterm I February 28 th, 2019 CS162: Operating Systems and Systems Programming

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

Midterm I October 19 th, 2009 CS162: Operating Systems and Systems Programming

Third Midterm Exam April 24, 2017 CS162 Operating Systems

Midterm Exam #1 Solutions February 28, 2018 CS162 Operating Systems

Midterm I October 15 th, 2008 CS162: Operating Systems and Systems Programming

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

Midterm Exam #2 December 4, 2013 CS162 Operating Systems

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

Midterm I October 18 th, 2010 CS162: Operating Systems and Systems Programming

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

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

Last Class: Deadlocks. Today

Problem Max Points Score Total 100

CPSC/ECE 3220 Summer 2018 Exam 2 No Electronics.

Lecture 9: Midterm Review

Lecture #7: Implementing Mutual Exclusion

Third Midterm Exam April 24, 2017 CS162 Operating Systems

CS 318 Principles of Operating Systems

Operating Systems (1DT020 & 1TT802)

Final Exam Solutions May 17, 2013 CS162 Operating Systems

Midterm Exam #1 September 29, 1999 CS162 Operating Systems

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

CPSC/ECE 3220 Summer 2017 Exam 2

Last Class: CPU Scheduling! Adjusting Priorities in MLFQ!

Midterm Exam #2 April 29, 2003 CS162 Operating Systems

Today: Synchronization. Recap: Synchronization

First Midterm Exam September 28, 2017 CS162 Operating Systems

Midterm Exam Answers

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

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

Midterm I March 11 th, 2015 CS162: Operating Systems and Systems Programming

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 8: Semaphores, Monitors, & Condition Variables

CSE 153 Design of Operating Systems

Implementing Mutual Exclusion. Sarah Diesburg Operating Systems CS 3430

Lecture 9: Multiprocessor OSs & Synchronization. CSC 469H1F Fall 2006 Angela Demke Brown

Suggested Solutions (Midterm Exam October 27, 2005)

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

CS450 OPERATING SYSTEMS FINAL EXAM ANSWER KEY

CS 450 Exam 2 Mon. 4/11/2016

Advanced Topic: Efficient Synchronization

Last Class: Synchronization

Comp 310 Computer Systems and Organization

CSE 451 Midterm Exam May 13 th, 2009

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

CS5460: Operating Systems

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

Sample Questions. Amir H. Payberah. Amirkabir University of Technology (Tehran Polytechnic)

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

CS161 Midterm Exam Spring 2006

Lecture 10: Multi-Object Synchronization

Midterm Exam #3 Solutions November 30, 2016 CS162 Operating Systems

Locks. Dongkun Shin, SKKU

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Steve Gribble. Synchronization. Threads cooperate in multithreaded programs

Midterm Exam Amy Murphy 19 March 2003

CS162 Operating Systems and Systems Programming Midterm Review"

Midterm Exam Amy Murphy 6 March 2002

CS162, Spring 2004 Discussion #6 Amir Kamil UC Berkeley 2/26/04

Page 1. Challenges" Concurrency" CS162 Operating Systems and Systems Programming Lecture 4. Synchronization, Atomic operations, Locks"

Midterm II December 4 th, 2006 CS162: Operating Systems and Systems Programming

EECS 482 Midterm (Fall 1998)

Fall 2015 COMP Operating Systems. Lab 06

Third Midterm Exam November 29, 2017 CS162 Operating Systems

Midterm I SOLUTIONS October 19 th, 2009 CS162: Operating Systems and Systems Programming

CS 140 Midterm Examination Winter Quarter, 2012

CS 450 Exam 2 Mon. 11/7/2016

FCM 710: Architecture of Secure Operating Systems

COMP 3430 Robert Guderian

CSE 451: Operating Systems Winter Lecture 7 Synchronization. Hank Levy 412 Sieg Hall

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657

Process & Thread Management II CIS 657

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

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

Page 1. Goals for Today" Atomic Read-Modify-Write instructions" Examples of Read-Modify-Write "

10/17/ Gribble, Lazowska, Levy, Zahorjan 2. 10/17/ Gribble, Lazowska, Levy, Zahorjan 4

CMPSCI 377 Midterm (Sample) Name:

Remaining Contemplation Questions

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

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

Synchronising Threads

CS 134: Operating Systems

COMP 3361: Operating Systems 1 Midterm Winter 2009

Transcription:

University of California, Berkeley College of Engineering Computer Science Division EECS Spring 2013 Anthony D. Joseph Midterm Exam March 13, 2013 CS162 Operating Systems Your Name: SID AND 162 Login: TA Name: Discussion Section Time: General Information: This is a closed book and one 2-sided handwritten note examination. You have 80 minutes to answer as many questions as possible. The number in parentheses at the beginning of each question indicates the number of points for that question. You should read all of the questions before starting the exam, as some of the questions are substantially more time consuming. Write all of your answers directly on this paper. Make your answers as concise as possible. If there is something in a question that you believe is open to interpretation, then please ask us about it! Good Luck!! QUESTION POINTS ASSIGNED POINTS OBTAINED 1 28 2 25 3 17 4 15 5 15 TOTAL 100 Page 1/10

1. (28 points total) True/False and short answer questions: a. (12 points) True/False and Why? CIRCLE YOUR ANSWER. i) The four conditions that must hold in order for deadlock to occur are: Holdand-wait, circular waiting, starvation and mutual exclusion. TRUE Why? (One sentence) FALSE ii) The main advantage of multilevel page tables is that they use page table memory efficiently. TRUE Why? (One sentence) FALSE iii) In the Nachos priority scheduler, if a HIGH priority thread is waiting for a LOW priority thread to release a lock, but there are NO OTHER THREADS in the system, the LOW priority thread's effective priority should be LOW. TRUE Why? (One sentence) FALSE iv) In Nachos, a thread's effective priority can only change when it is waiting on a thread queue. TRUE Why? (One sentence) FALSE Page 2/10

b. (16 points) Short Answer Questions: i) (4 points) Give a two to three sentence brief description of the difference between starvation and deadlock. ii) (4 points) When using the Banker s algorithm for resource allocation, if the system is in an unsafe state, will it always eventually deadlock? Briefly (1-2 sentences) state why or why not. iii) (4 points) In two to three sentences briefly discuss why caching is increasingly important in modern computer systems, and why it is of particular concern to the operating system. iv) (4 points) In two to three sentences briefly explain why the space shuttle failed to launch on April 10, 1981. Page 3/10

2. (25 points) Synchronization primitives: Consider a machine with hardware support for a single thread synchronization primitive, called Compare-And-Swap (CAS). Compare-and-swap is an atomic operation, provided by the hardware, with the following pseudocode: int compare_and_swap(int *a, int old, int new) { if (*a == old) { *a = new; return 1; else { return 0; Your first task is to implement the code for a simple spinlock using compare-andswap. You are not allowed to assume any other hardware or kernel support exists (e.g., disabling interrupts). You may assume your spinlock will be used correctly (i.e., no double release or release by a thread not holding the lock) a. (3 points) Fill in the code for the spinlock data structure. struct spinlock { /* Fill in */ b. (4 points) Fill in the code for the acquire data function. void acquire(struct spinlock *lock) { /* Fill in */ Page 4/10

c. (4 points) Fill in the code for the release data function. void release(struct spinlock *lock) { /* Fill in */ After completing your implementation, you realize that using a spinlock is inefficient for applications that may hold the lock for a long time. You consider using the following two primitives to implement more efficient locks: atomic_sleep and wake. atomic_sleep is an atomic operation, provided by the hardware, with the following pseudocode: void atomic_sleep(struct *lock, int *val1, int val2){ *val1 = val2; /* set val1 to val2 */ enqueue(lock); /* put current thread on a lock s wait queue*/ sleep(); /* put current thread to sleep */ wake is non-atomic with the following pseudocode: void wake(struct lock *lock){ dequeue(); /* remove a thread (if any) from lock s wait queue and add it to the scheduler s ready queue */ Your second task is to reimplement your lock code more efficiently using atomic_sleep and wake. You may use Compare-And-Swap if you want. You are not allowed to assume any other hardware or kernel support exists (e.g., disabling interrupts). Page 5/10

d. (4 points) Fill in the code for the new lock data structure. struct lock { /* Fill in */ e. (5 points) Fill in the code for the new acquire data function. void acquire(struct lock *lock) { /* Fill in */ f. (5 points) Fill in the code for the new release data function. void release(struct lock *lock) { /* Fill in */ Page 6/10

3. (17 points total) Memory management: a. (7 points) Consider a memory system with a cache access time of 10ns and a memory access time of 200ns, including the time to check the cache. What hit rate H would we need in order to achieve an effective access time 10% greater than the cache access time? (Symbolic and/or fractional answers are OK) b. (10 points) Suppose you have a 47-bit virtual address space with a page size of 16 KB and that page table entry takes 8 bytes. How many levels of page tables would be required to map the virtual address space if every page table is required to fit into a single page? Be explicit in your explanation and show how a virtual address is structured. Page 7/10

4. (15 points total) Concurrency control: Building H 2 O 2. The goal of this exercise is for you to create a monitor with methods Hydrogen() and Oxygen(), which wait until a Hydrogen Peroxide molecule (H 2 O 2 ) can be formed and then return. Don t worry about actually creating the Hydrogen Peroxide molecule; instead only need to wait until two hydrogen threads and two oxygen threads can be grouped together. For example, if two threads call Hydrogen, another thread calls Oxygen, and then a fourth thread calls Oxygen, the fourth thread should wake up the first three threads and they should then all return. a. (3 points) Specify the correctness constraints. Be succinct and explicit in your answer. b. (12 points) Observe that there is only one condition any thread will wait for (i.e., a hydrogen peroxide molecule being formed). However, it will be necessary to signal hydrogen and oxygen threads independently, so we choose to use two condition variables, waitingh and waitingo. State variable description Variable name Initial value Number of waiting hydrogen threads wh 0 Number of waiting oxygen threads wo 0 Number of active hydrogen threads ah 0 Number of active oxygen threads ao 0 You start with the following code: Hydrogen() { wh++; lock.acquire(); while (ah == 0) { if (wh >= 2 && wo >= 2) { wh-=2; ah+=2; wo-=2; ao+=2; waitingh.broadcast(); waitingo.broadcast(); else { waitingh.wait(&lock); lock.acquire(); ah--; lock.release(); Page 8/10

Oxygen() { wo++; lock.acquire(); while (ao == 0) { if (wh >= 2 && wo >= 2) { wh-=2; ah+=2; wo-=2; ao+=2; waitingh.signal(); waitingh.signal(); waitingo.signal(); else { waitingo.wait(&lock); ao--; lock.release(); For each method, say whether the implementation either (i) works, (ii) doesn t work, or (iii) is dangerous that is, sometimes works and sometimes doesn t. If the implementation does not work or is dangerous, explain why (there maybe several errors) and briefly show how to fix it so it does work. Also, list and fix any inefficiencies. You do not have to reimplement the methods. i. Hydrogen() ii. Oxygen() Page 9/10

5. (15 points total) Scheduling. Consider the following processes, arrival times, and CPU processing requirements: Process Name Arrival Time Processing Time 1 0 4 2 2 3 3 5 3 4 6 2 For each scheduling algorithm, fill in the table with the process that is running on the CPU (for timeslice-based algorithms, assume a 1 unit timeslice). For RR and SRTF, assume that an arriving thread is run at the beginning of its arrival time, if the scheduling policy allows it. Also, assume that the currently running thread is not in the ready queue while it is running. The turnaround time is defined as the time a process takes to complete after it arrives. Time FIFO RR SRTF 0 1 1 1 1 2 3 4 5 6 7 8 9 10 11 Average Turnaround Time Page 10/10