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

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

Name: uteid: 1. CS439: Fall 2011 Midterm 2

Name: uteid: 1. CS439H: Fall 2011 Final Exam

Name: uteid: 1. CS439: Fall 2011 Midterm 2

Name: 1. CS372H: Spring 2009 Final Exam

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

Question 2 has four parts. Answer any three of the four parts of question 2.

My malloc: mylloc and mhysa. Johan Montelius HT2016

CPS 310 second midterm exam, 11/6/2013

New York University CSCI-UA.202: Operating Systems (Undergrad): Spring 2015 Midterm Exam I

6.097 Operating System Engineering: Fall Quiz II THIS IS AN OPEN BOOK, OPEN NOTES QUIZ.

The University of Texas at Austin CS 372H Introduction to Operating Systems: Honors: Spring 2012 Midterm Exam

! Why is synchronization needed? ! Synchronization Language/Definitions: ! How are locks implemented? Maria Hybinette, UGA

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

Parallel Programming: Background Information

Parallel Programming: Background Information

CSE 451 Midterm Exam May 13 th, 2009

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

First Midterm Exam Solutions October 1, 2018 CS162 Operating Systems

CSE351 Winter 2016, Final Examination March 16, 2016

Chapter 6: Process [& Thread] Synchronization. CSCI [4 6] 730 Operating Systems. Why does cooperation require synchronization?

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

Midterm Exam #1 February 28, 2018 CS162 Operating Systems

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

CPS 310 midterm exam #1, 2/17/2017

Common Misunderstandings from Exam 1 Material

This is an open book, open notes exam. But no online or in-class chatting.

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

CSE 303 Midterm Exam

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Processes. Johan Montelius KTH

CS 322 Operating Systems Practice Midterm Questions

A process. the stack

Heap Arrays and Linked Lists. Steven R. Bagley

CS 31: Introduction to Computer Systems : Threads & Synchronization April 16-18, 2019

Precept 2: Non-preemptive Scheduler. COS 318: Fall 2018

Questions: ECE551 PRACTICE Final

COMP 3361: Operating Systems 1 Final Exam Winter 2009

CS61C Midterm Review on C & Memory Management

New York University CSCI-UA : Advanced Computer Systems: Spring 2016 Midterm Exam

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

CA341 - Comparative Programming Languages

Midterm Review. CS 211 Fall 2018

Highlights. - Making threads. - Waiting for threads. - Review (classes, pointers, inheritance)

CPS 310 first midterm exam, 10/6/2014

The University of Texas at Austin CS 439 Principles of Computer Systems: Spring 2013 Midterm Exam I

Understanding Pointers

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

QUIZ. What is wrong with this code that uses default arguments?

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Kurt Schmidt. October 30, 2018

Computer Science 162, Fall 2014 David Culler University of California, Berkeley Midterm 2 November 14, 2014

The University of Texas at Austin CS 439 Principles of Computer Systems: Spring 2013 Midterm Exam II

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

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

CSCI [4 6] 730 Operating Systems. Example Execution. Process [& Thread] Synchronization. Why does cooperation require synchronization?

University of Waterloo Midterm Examination Model Solution CS350 Operating Systems

The deadlock problem

CPSC/ECE 3220 Fall 2017 Exam Give the definition (note: not the roles) for an operating system as stated in the textbook. (2 pts.

Introduction to C. Sean Ogden. Cornell CS 4411, August 30, Geared toward programmers

Deadlock and Monitors. CS439: Principles of Computer Systems February 7, 2018

AST: scalable synchronization Supervisors guide 2002

CPS 310 second midterm exam, 11/14/2014

Introduction to C. Ayush Dubey. Cornell CS 4411, August 31, Geared toward programmers

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

STUDENT NAME: STUDENT ID: Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total

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

COMP 3361: Operating Systems 1 Midterm Winter 2009

Lecture 04 Introduction to pointers

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

CSC369 Lecture 2. Larry Zhang

Synchronization 1. Synchronization

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

CSC369 Lecture 2. Larry Zhang, September 21, 2015

Final Examination CS 111, Fall 2016 UCLA. Name:

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

6.824 Distributed System Engineering: Spring Quiz I Solutions

CS 241 Honors Concurrent Data Structures

CPS 310 midterm exam #1, 2/17/2017

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

Midterm Exam March 13, 2013 CS162 Operating Systems

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Suggested Solutions (Midterm Exam October 27, 2005)

1 /10 2 /15 3 /20 4 /15 total /60. CSE 120 Fall 2007 Midterm Examination. Name. Student ID

Midterm Exam #1 September 28, 2016 CS162 Operating Systems

CS 537: Introduction to Operating Systems (Summer 2017) University of Wisconsin-Madison Department of Computer Sciences.

Heap Arrays. Steven R. Bagley

Homework 3 CS161 Computer Security, Fall 2008 Assigned 10/07/08 Due 10/13/08

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

CSCI-1200 Data Structures Fall 2009 Lecture 25 Concurrency & Asynchronous Computing

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

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

Pointers in C/C++ 1 Memory Addresses 2

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CSE373 Fall 2013, Midterm Examination October 18, 2013

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

Midterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017

UNIVERSITY REGULATIONS

Transcription:

Name: uteid: 1 Instructions CS439H: Fall 2011 Midterm 1 Stop writing when time is announced at the end of the exam. I will leave the room as soon as I ve given people a fair chance to bring me the exams. I will not accept exams once my foot crosses the threshold. This midterm is closed book and notes. If a question is unclear, write down the point you find ambiguous, make a reasonable interpretation, write down that interpretation, and proceed. For full credit, show your work and explain your reasoning and any important assumptions. Write brief, precise, and legible answers. Rambling brain-dumps are unlikely to be effective. Think before you start writing so that you can crisply describe a simple approach rather than muddle your way through a complex description that works around each issue as you come to it. Perhaps jot down an outline to organize your thoughts. And remember, a picture can be worth 1000 words. Write your name and uteid on every page of this exam.

Name: uteid: 2 1. (8) Suppose you had a choice between two file systems. System 1 s vendor guarantees it will be 99% reliable and 100% available. System 2 s vendor guarantees it will be 100% reliable and 99% available. Which would you pick? System 2. An unreliable file system can permanently lose data. 2. (16) Virtualization uses a hypervisor running in privileged mode to create a virtual machine that runs in unprivileged mode. Then, unmodified guest operating systems can run in the virtual machine. The hypervisor can provide the illusion that each guest operating system is running on its own machine in privileged mode. Early versions of the x86 architecture (pre-2006) were not completely virtualizable these system could not guarantee to run unmodified guest operating systems properly. One problem was the popf pop flags instruction. When popf was run in privileged mode, it could change both the ALU flags (e.g., ZF) and the systems flags (e.g., IF, which controls interrupt delivery), and when popf was run in unprivileged mode, it could change just the ALU flags. Why do instructions like popf prevent transparent virtualization of the (old) x86 architecture? Since this instruction behaves differently for user and kernel mode and since it does not cause a trap in user mode, the guest kernel will expect it to do one thing (privileged mode version) but it will actually do something else. How would you change the x86 hardware to fix this problem? A simple thing to do is to add a privileged flag that, when set, causes popf in user mode to trap. Then the hypervisor ensures that whenever the guest is running in virtual privileged mode, the popf-trap flag is set; it can be cleared when the guest is running in virtual unprivileged mode. 3. (4) List the four necessary conditions for deadlock. limited resources, wait while holding, circular waiting, no preemption

Name: uteid: 3 4. (16) For each of the data structures listed in the table below, indicate (by checking the box in the appropriate column) whether the memory identified is stored in per-thread areas of memory (i.e., it refers to per-thread state) or if it is stored in areas of memory that can be shared by many threads (i.e., it refers to potentially shared state). int max = 42; char message [] = " Hello world "; int main ( int argc, char ** argv ) char * msg = message ; sthread_t *t = ( sthread_t *) malloc ( sizeof ( sthread_t )); sthread_init (t, go, msg ); t = ( sthread_t *) malloc ( sizeof ( sthread_t )); sthread_init (t, foo, NULL ); void go( char * toprint ) int OK = 1; static int done = 0; if( strlen ( toprint ) > max ) OK = 0; done = 1; void foo ( void * notused ) // Code omitted... Private, per-thread state Shared/sharable state heap stack message msg toprint argc OK max t go done shared: heap, message, max, go, done; others are private

Name: uteid: 4 5. (8) Consider a virtual memory system with 42-bit physical addresses and 6 control bits per page. How large does the page size have to be to allow each page table entry to fit in a 4-byte word? 42 + 6-32 = 16. So each page needs to be 2 16 bytes (64KB). 6. (8) Consider a virtual memory system with 48-bit virtual addresses, 44-bit physical addresses, 16KB pages, and 7 control bits per word. Assuming a multi-level page table arrangement, how many levels of page tables should this system use? entry size = 44 + 7-14 = 37 round up to 8 bytes entries per page = 2K bits per level = 11 number vpage bits = 48-14 = 34 number of levels needed = 4 (the top level has just 2 entries, though) 7. (8) The Bryant and O Halloran book says that it is safe to do conservative mark and sweep garbage collection in a C program. This is not quite true. Write a short C program (detailed pseudocode is fine) that can dereference a pointer that could point to garbage collected memory after a mark and sweep pass. The key thing here is to do some pointer arithmatic such that allocated memory has no pointer pointing into it, but you can construct such a pointer. char * hidden = malloc ( 100 * sizeof ( char )); sprintf ( hidden, " Hidden."); hidden = hidden /2;... // mark and sweep happens... hidden = hidden * 2; printf ( hidden );

Name: uteid: 5 8. (32) Implement a priority condition variable. A priority condition variable (PCV) has 3 public methods: void PCV :: wait ( Lock * lock, int priority ); void PCV :: signal ( Lock * lock ); void PCV :: broadcast ( Lock * lock, int priority ); These methods are similar to those of a standard condition variable. The one difference is that a PCV enforces both priority and ordering. In particular, signal(lock *lock) causes the currently waiting thread with the highest priority to return from wait(); if multiple threads with the same priority are waiting, then the one that is waiting the longest should return before any that have been waiting a shorter amount of time. Similarly, broadcast(lock *lock, int priority) causes all currently waiting threads whose priority equals or exceeds priority to return from wait(). For full credit, you must follow the thread coding standards discussed in class. This problem ended up being tougher than intended. The intention was for this to be a standard implement a shared object problem a PCV is just another type of shared object and the standard techniques apply. A large number of people interpreted this as a implement from atomic operations problem or did a hybrid atomic operations/locking-based solution. I can see why that might appear to be a reasonable interpretation, so I graded those accordingly. Also, in retrospect, I should have given the Lock *lock parameter a more descriptive name to make it more clear what was going on. (Some people used that lock for mutex in this object; that does give the ownership pattern, so I gave credit. class PCV Member variables type name initial value (if any) type name initial value (if any) Lock mylock NA CV cv NA SortedList waiting empty

Name: uteid: 6 PCV::wait(Lock *lock, int priority) // Wait should atomically release the callerlock // and start waiting until signalled. And it should // reacquire the lock before returning. // // NOTE : Since we ( a) want to follow the Standards and // ( b) don t want to risk deadlock, we break wait () // into two pieces dowait ( callerlock, priority ); lock -> acquire (); void PCV :: dowait ( Lock * lock, int priority )\ mylock. acquire (); lock -> release (); WaitRecord * wr = new WaitRecord ( priority ); waiting. insertsortedbypriorityandinsertorder (wr ); while (! wr. oktogo ) cv. wait (& mylock ); free (wr ); mylock. release (); PCV::signal(Lock *lock) mylock. acquire (); waiting. markfirstoktogo (); cv. broadcast (& mylock ); mylock. release (); PCV::broadcast(Lock *lock, int priority) mylock. acquire (); waiting. markpriorityoktogo ( priority ); cv. broadcast (& mylock ); mylock. release (); Note: WaitRecord has 4 fields: priority (initialized) and oktogo (initially false), and next/prev Here are the helper functions (it was OK to include much less detail than this.) SortedList :: insertsortedbypriorityandinsertorder ( WaitRecord WaitRecord * cur = head ; while ( cur && cur -> next && cur -> next >= e-> priority ) cur = cur -> next ; e-> next = cur -> next ; e-> prev = cur ; if(cur -> next ) *e)

Name: uteid: 7 e->next -> prev = e; if(cur!= head ) e->prev -> next = e; else head = e; // Note : also need to remove first from // list to avoid remarking it SortedList :: markfirstoktogo () WaitRecord * cur = head ; if(cur ) cur -> OKToGo = true ; head = cur -> next ; if( head ) head -> prev = NULL ; return ; SortedList :: markfirstoktogo ( int pri ) while ( head && head - > priority >= pri ) markfirstoktogo (); return ;

Name: uteid: 8 This page intentionally left almost blank This page intentionally left almost blank