Assignment 5, due Sept 27

Part of the homework for 22C:116, fall 2002
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

  1. Background: There is a user-level thread package written in C and callable from C or C++ programs on-line at:
    http://homepage.cs.uiowa.edu/~dwjones/opsys/threads/

    The usual way for a C program to read a character from standard input is to call ch=getchar(); for many purposes, this is equivalent to the Unix kernel call read(0,&ch,1). (Under Unix, file descriptor zero is standard input.)

    The Problem: Write, thread_getchar(), a routine to read a character from standard input under the thread manager. This would have to allow other threads to run until a character was available on standard input.

    Suggestion: You could use the select() Unix kernel call to implement this, or you could you use the O_NONBLOCK option for the open() kernel call (opening /dev/tty, the current interactive terminal) to implement this, or you could use fcntl to set the O_NONBLOCK attribute of file descriptor zero, which is already open. (See the unix man pages for documentation of these services!)

  2. Background: Your code for thread_getchar() probably makes one or two kernel calls each time you call it. Kernel calls are typically more expensive than procedure or function calls because of the cost of crossing the user/kernel protection boundary.

    A Problem: Under certain circumstances, some of the kernel calls suggested above allow thread-getchar() to make fewer than 1 kernel call per character being read. What implementation would allow this, and under what circumstances will this be true?

    A Hint: Consider the difference between getchar() as defined in <stdio.h> and the Unix kernel call read(0,&ch,1). You can read the source for the former in /usr/include/stdio.h.

  3. Background: You know that the page-fault handler in a virtual memory system must do disk I/O in order to handle a fault. Suppose we have a hard drive with one partition reserved as the "swap space" used for the virtual memory of the entire system, with many different processes running on the system.

    Further, suppose our disk I/O driver uses the elevator algorithm for disk I/O scheduling, and that it uses the trick suggested in the course notes to use the pending requests in the disk queue as a cache.

    A Question: Explain the relationship between the process manager, the disk interrupt service routine and the page-fault handler. Focus on the time when the disk I/O transfer required to service a page fault is completed.

  4. A Problem: Do problem 11 on page 374 of the text. The numbers requested in the text give the peak data rate to or from the device. Also compute the average data rate you'd expect for a sequence of input or output requests to randomly selected sectors on disk.