Operating Systems (CS422) : Name: Netid

Download as ps, pdf, or txt
Download as ps, pdf, or txt
You are on page 1of 5

Operating Systems (CS422)

Spring 2002
Yale University
March 1, 2002
Name:

Netid:

 Write your answers directly on the examination paper, including any work that you wish to be considered for
partial credit. Use the back side of each sheet if you require more space to answer a question.
 Each question is marked with the number of points assigned to that problem. The total number of points is 25.
 The duration of this exam is an hour.
 The examination is open-notes and open-book.

Problem
1
2
3
4

Topic

Points

TLB and Page Faults


Virtual Memory
Bridge Crossing
River Crossing

TOTAL

Problem 1

TLB and Page Faults [6 points]

Consider a system with 8KB pages and 256MB of physical memory. 64MB of the physical memory is reserved for
storing OS code and page tables. The processor has 32 TLB entries. Consider the following two fragments of C code.
Version 1:
int A[SIZE1][SIZE2];
for (i=0; i<SIZE1; i++)
for (j=0; j<SIZE2; j++)
A[i][j] = 0;
Version 2:
int A[SIZE1][SIZE2];
for (j=0; j<SIZE2; j++)
for (i=0; i<SIZE1; i++)
A[i][j] = 0;
How many page faults and TLB faults do these two code fragments incur when SIZE1 = SIZE2 = 2048. (Assume
that sizeof(int) = 4. Assume that TLB replacement is FIFO and page replacement is LRU. Also assume that the
program has just begun execution and none of the TLB entries and the page table entries are valid. State any other
assumptions that you might need to solve the problem.)

Problem 2

Virtual Memory [4 points]

Consider a virtual memory system with segmentation and paging. Also assume that the page tables themselves are
paged. Each process can address 4 segments. Let the page size be 4KB. If the contents of the segment table were:
Entry
Entry
Entry
Entry

0:
1:
2:
3:

0xC0000000
0xC0300000
0xC0400000
0x00A10000

Segment 3 is the system segment, and the 3rd entry in the segment table stores a physical address. Consider the virtual
address 0x4200488C (segment number: 0x1, page number: 0x02004, offset: 0x88C). To translate this virtual address,
the system needs to lookup two page table entries. The first lookup involves accessing an entry in the page table for
the system segment. Note that the system page table is located at physical address 0x00A10000. What is the exact
physical address of the system page table entry that is accessed by the first lookup? (Assume that page table entries
are 4 bytes long.)

Problem 3

Bridge Crossing [6 points]

Consider the following code that we examined for solving the Bridge Crossing problem.
Lock lock; Condition safe;
int currentNumber, currentDirec;
ArriveBridge(int direc) {
ExitBridge(int direc) {
lock.Acquire();
lock.Acquire();
while (!safe_to_cross(direc))
currentNumber--;
safe.wait(&lock);
safe.signal(&lock);
currentNumber++;
lock.Release();
currentDirec = direc;
}
lock.Release();
}
boolean safe_to_cross(int direc) {
if (currentNumber == 0) return TRUE;
else if (currentNumber < 3 && currentDirec == direc) return TRUE;
else return FALSE;
}
Is it correct to rewrite the ExitBridge function as follows? If incorrect, identify what sequences of events would break
the code.
ExitBridge(int direc) {
currentNumber--;
lock.Acquire();
safe.signal(&lock);
lock.Release();
}

And is it correct to rewrite the ExitBridge function as follows? If incorrect, identify what sequences of events would
break the code.
ExitBridge(int direc) {
lock.Acquire();
currentNumber--;
lock.Release();
safe.signal(&lock);
}

Problem 4

River Crossing [9 points]

A particular river crossing is shared by Linux Hackers, Microsoft employees, and Department of Justice officials.
A boat is used to cross the river, but it only seats three people, and must always carry a full load. In order to preserve
balance of power, each boat can have exactly one Microsoft employee, one Linux hacker, and one DoJ official.
You are to write three procedures: HackerArrives, EmployeeArrives, and DoJOfficialArrives called by a hacker,
employee, or official when he/she arrives at the river bank. The procedures arrange the arriving passengers into
safe boatloads; once the boat is full, one thread calls RowBoat and only after the call to RowBoat, the three threads
representing people in the boat can return.
You can use either semaphores or condition variables to implement the solution. Any order is acceptable and there
should be no busy-waiting and no undue waiting.

You might also like