Assignment 5, due Feb. 24
Part of
the homework for 22C:112, Spring 2012
|
On every assignment, write your name legibly as it appears on your University ID and on the class list! Assignments are due at the start of class on the day indicated (usually Friday). Exceptions will be by advance arrangement unless there is what insurance companies call "an act of God" (something outside your control). Homework must be turned in on paper, either in class or in the instructor's mailbox. Never push late work under someone's door!
The routine to enqueue a disk request used reserved linkage fields in the disk request record also enables the disk interrupt, just in case it was disabled because the disk queue had been empty. The identity of the device register and the mask for setting the device-specific interrupt enable bit are stored in the queue control block. Here is a version of enqueue appropriate for simple FIFO disk request queues:
enqueue( request * b; diskqueue * q ) { request->next = NULL; if (q->tail == NULL) { /* empty queue detected */ q->head = request; } else { /* non-empty queue */ q->tail->next = request; } q->tail = request; out(q->controlreg, in(q->controlreg) | q->iebit ) }
Note: The above code is modified. The original version of the assignment contained a serious programming error.
a) Write the corresponding dequeue that can be called from within the disk interrupt service routine. Assume it is called with interrupts disabled globally. In the event that dequeue is applied to an empty queue, it should: i - return NULL and ii - disable the device specific interrupt. Otherwise, it leaves interrupts alone and returns a pointer to the dequeued disk request block. (0.8 points)
b) Given that the disk interrupt service routine does the dequeue operations from the disk request queue, there are critical sections in the enqueue code that must be protected by turning off the CPU's main interrupt enable bit. Add them in properly using ei() and di() as primitives to enable and disable interrupts. Note that the sequence ei();di() makes sense when there are two consecutive critical sections involving unrelated subjects. (0.7 points)
c) To support a simple FIFO queue, there is a pair of pointers in each queue control block, q->head and q->tail. What change would you make to the queue control block data structure if you wanted to use the elevator algorithm for disk scheduling? (0.8 points)