






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Counting Semaphore, Notes Examination, Major Components, Modern Operating, Deadlock, External Fragmentation, Pure Segmentation, External Fragmentation, Processor Scheduling, Numerical Order
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!







University of California, Berkeley College of Engineering Computer Science Division – EECS
Spring 2003 Anthony D. Joseph
March 13, 2003 CS162 Operating Systems
Your Name:
SID AND 162 Login:
TA:
Discussion Section:
General Information: This is a closed book and notes examination. You have two hours 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 100 points in all. 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!
Problem Possible Score 1 28
Total 100
Solutions
i) 3 points for each, 1 points for name and 2 points for role. Memory management, process management, file management, I/O system management, networking, scheduling, etc. No credit was given for OS functions (e.g., government).
ii)
iii)
b. (9 points) Give a definition of a counting semaphore, and list and describe the valid operations. 3 points for definition, 2 points for each operation. A counting semaphore is a synchronization data structure that can be used to control or limit the number of processes that can access to a critical region. There are three operations that are allowed on a semaphore:
Solutions
a. (9 points) Show the scheduling order for these processes under First-In-First-Out (FIFO), Shortest-Job First (SJF), and Round-Robin (RR) scheduling with a timeslice quantum = 1 time unit. Time FIFO SJF RR
Solutions
b. (12 points) For each process in each schedule above, indicate the queue wait time and turnaround time (TRT). Scheduler Process 1 Process 2 Process 3 Process 4 Process 5
The queue wait time is the total time a thread spends in the wait queue. Part a) 3 points per column, part b) 2 points per row.
3 points for each. 1 point for basic concept, -1 for minor errors, -1 for answers that are too long. For top-level paging schemes, -1 point for no mention of Page Table Base Register.
b. Virtual address format:
Paging Level 1 Paging Level 2 Offset
Paging Level 1 Segment Level 2 Offset
Page Table (^) Page Table^ Mem
Error!
Mem Seg table
Page Table
Solutions
a. (6 points) Show the complete format of a virtual address.
Each address is broken up into three parts: Page Level 1 – 10 bits Page Level 2 – 10 bits Offset – 12 bits
1 point for each field, 1 point for correct bit length of each field.
This is a multi-level scheme using two sets of page tables for each process: an “outer” one and an “inner” one. PL 1 is an index into the outer page table, containing PTE’s that contain pointers to the inner page table (which can be paged). In other words, the inner page table is broken up into pages that do not have to be stored contiguously.
The PTE at outer [PL 1] contains a pointer to the PL 1th^ page in the inner page table. PL 2 is an index into the PL 1th^ page in the inner page table. PTE's are 4 bytes, so there are 1,024 PTE's per page. Thus, PL 2 must be exactly 10 bits. The index at PL 2 points to the page that holds virtual addresses starting with PL 1 PL 2. The particular byte is the dth^ byte in that page. Since pages are 4K bytes, d must be exactly 12 bits. Since d is 12 bits and PL 2 is 10 bits, PL 1 must be 10 bits.
b. (6 points) Explain the steps the hardware takes in translating a virtual address to a physical address for this scheme (do not worry about supporting paging to disk).
See Problem 3a for the picture of the steps that are taken. The PTBR is used to locate the outer page table in physical memory. PL 1 is used to index into the outer page table. As above, the PTE at this index points to a page in the inner page table. PL 2 is used to index in this inner page table, and the PTE in the inner page table points to the physical page. Offset is a location on the physical page. If you didn’t mention the PTBR, we subtracted one point.
Note that each PTE should have a valid bit and several protection bits – e.g., read, write, execute, valid. The memory operation (load, store, load for execution) must agree with these bits in both sets of PTE's (inner and outer). Otherwise the hardware will generate an interrupt. If you didn’t mention the role of the valid bit or the protection bits, we subtracted one point for each missing role.
If you missed a level, we subtracted one point for each level missed. If you included an incorrect step, we subtracted one point.
Solutions
c. (3 points) How many memory operations are required to read or write a single 32- bit word?
Without extra hardware, performing a memory operation takes 3 actual memory operations: two page table lookups in addition to the desired memory operation. We did not award partial credit for this problem.
d. (4 points) List the fields of a Page Table Entry (PTE).
Each PTE will have a pointer to the proper page (two points) plus several bits – read, write, execute, (1 point for protection bits), and valid (one point). This information can all fit into 4 bytes, since if physical memory is 2^32 bytes, then 20 bits will be needed to point to the proper page, leaving ample space (12 bits) for the information bits.
If you didn't mention the valid and protection bits, then you lost 2 points. If you added incorrect fields, we subtracted one point for each incorrect field.
e. (6 points) How much physical memory is needed for a process with one page of virtual memory?
Three pages are needed: one for the outer page table, one for one page of the inner page table, and one for the process’ single page.
Note that the inner page table does not need 4M (2^10 * 4K), because the outer page table enables you to only have inner page table pages for those pages that are part of the process's virtual address space.
For partially correct answers, we subtracted three points for the wrong total and one point for each incorrect page level. Answers that stated that only enough memory was needed for a PTE at the outer and inner levels (instead of an entire page), were penalized at least three points.
f. (2 points) What happens in the virtual memory subsystem on a context switch? On a context switch, the PTBR of the new process must be loaded. Note that it is not necessary to save the PTBR of the outgoing process as that does not change on a context switch, as it is already stored in the process’ control block. We did not give partial credit for answers that only saved the PTBR.
Solutions
There are three complications to barriers. First, there is no master thread that controls the threads, waits for each of them to reach the barrier, and then tells them to re-start. Instead, the threads must monitor themselves and determine when they should wait or proceed. Second, for many dynamic programs, the number of threads that will be created during the lifetime of the parallel program is unknown in advance, since a thread can spawn another thread, which will start in the same program stage as the thread that created it. Third, a thread may end before the barrier. In all cases, all threads must synchronize at the barrier before the processing is allowed to proceed to the next phase.
a. (10 points) Provide the pseudo-code for a monitor class called Barrier that enables this style of barrier synchronization. Your solution must support creation of a new thread (an additional thread that needs to synchronize), termination of a thread (one less thread that needs to synchronize), waiting when a thread reaches the barrier early, and releasing waiting threads when the last thread reaches the barrier. Implement your solution using monitors (e.g., wait(), signal(), and signalAll()).
Your class must implement the following three methods: threadCreated(), threadEnd(), barrierReached(). Hint: this concept is very similar to Java synchronized objects.
Solutions
Class Barrier () { ConditionVar barrier; Lock lock = FREE; Int numThreads = 0; Int numThreadsAtBarrier = 0;
threadCreated() { lock.acquire(); numThreads ++ lock.release(); }
threadEnd() { lock.acquire(); numThreads--; if (numThreadsAtBarrier == numThreads) { numThreadsAtBarrier = 0; barrier.signalAll(); } lock.release(); }
barrierReached() { lock.acquire(); numThreadsAtBarrier++; if (numThreadsAtBarrier < numThreads) { barrier.wait(); } else { numThreadsAtBarrier = 0; barrier.signalAll(); } lock.release(); } } We subtracted points as follow: