These problems should be done on your own. We're not going to be grading them strictly (we'll mainly look at whether you attempted them). But they will be reinforcing knowledge and skills, so you should totally work through them carefully.
Polling vs. interrupts
As discussed in class, two ways for an operating system to become aware of external events associated with a device are interrupts and polling. We observed that if a computer were receiving many interrupts, it might spend all of its time processing them and not get other work done; in that case, the operating system should switch to polling the device. Now consider the following:
A computer has an attached keyboard. The keyboard has a 1024-byte internal memory buffer to hold the codes of recently-pressed keys, each of which consumes 2 bytes of buffer space. (The buffer is a FIFO, which for our purposes means that the OS simply reads from it and doesn’t manage the memory; if this parenthetical confuses you, you can ignore it.)
This computer and its OS take 1 microsecond (10 − 6 seconds) to handle an interrupt from the keyboard. That duration includes everything: reading from the keyboard’s buffer, determining which key was pressed, and painting the appropriate letter to the screen.
Assume that polling requires a fixed cost of 1 microsecond per poll. Further assume that, per poll, the operating system can read an arbitrary amount of the keyboard’s internal memory buffer, up to the entire size of that buffer.
Assume that, if polling, the operating system checks the device in question every 200 milliseconds.
Assume that humans are sensitive to lags of 100 milliseconds or greater. Specifically, if a human types a letter, that letter must appear on the screen less than 100 milliseconds after the human types it, to avoid annoyance.
You type exceptionally quickly: 200 words per minute. Assume that the average word has 7 letters, including the space at the end of the word.
Each key code (each letter, in other words) generates a separate interrupt.
- How many interrupts per second would your typing generate on average? Show your work.
- Should the computer use polling or interrupts to handle your fast typing? Explain why your choice is acceptable and the other choice is not. Do not use more than three sentences.
Zero-copy I/O
In some operating systems, IO from/to disk is done directly to/from a buffer in the user process's memory. The user program does a system call specifying the address and length of the buffer (the length must be a multiple of the disk sector size).
The disk controller needs a physical memory address, not a virtual address. Your friend proposes that when the user does a write system call, the operating system should check that the user's virtual address is valid, translate it into a physical address, and pass that address and the length (also checked for validity) to the disk hardware.
This won't quite work. In no more than two sentences, what did your friend forget?
File systems
Consider a file system that has the following description:
- The disk is divided into 1024-byte blocks.
- The beginning of the disk contains an array of 216 inodes, each of which can represent a file or be unallocated.
- A file has an indexed structure: an inode contains (a) 8 data block pointers, each of which is 4 bytes and each of which points to a disk block and (b) a pointer to ONE indirect block, which is a disk block that itself contains data block pointers.
- The inode also contains a userid (2 bytes), three time stamps (4 bytes each), protection bits (2 bytes), a reference count (3 bytes), and the size (4 bytes).
- A directory contains a list of
(file_name, inode_number)
pairs, where thefile_name
portion is always exactly 14 bytes, including the null terminator (if thefile_name
would otherwise be fewer than 14 bytes, it is padded to 14 bytes).
- State the maximum file size, and explain briefly, for example by showing your work. You may express your answer as a sum of powers-of-two.
- State the maximum number of files in a directory, and explain briefly, for example by showing your work. Again, you may express your answer as a sum of powers-of-two.
Handing in the homework
Use Gradescope; you can enroll in our course with entry code JBGJKG. (And please feel free to send us feedback about Gradescope.)