==== Start Lecture #11 ====

Chapter 5: Input/Output

5.1: Principles of I/O Hardware

5.1.1: I/O Devices

5.1.2: Device Controllers

These are the ``real devices'' as far as the OS is concerned. That is the OS code is written with the controller spec in hand not with the device spec.

The figure in the book is so oversimplfied as to be borderline false. The following picture is closer to the truth (but really there are several I/O buses of different speeds).

Homework: 2

5.1.3: Direct Memory Access (DMA)

Homework: 5

5.2: Principles of I/O Software

As with any large software system, good design and layering is important.

5.2.1: Goals of the I/O Software

Device independence

We want to have most of the OS, unaware of the characteristics of the specific devices attached to the system. Indeed we also want the OS to be largely unaware of the cpu type itself.

It is thanks to this device independence that programs can be written to write and read generic devices and then at run time specific devices are assigned. Writing to a disk has differences from writing to a terminal, but unix cp (dos copy) doesn't see these differences. Indeed, most of the OS, including the filesystem code, Is unaware of whether the device is a floppy or hard disk.

Uniform naming

Recall that we discussed the value of the name space implemented by filesystems. There is no dependence between the name of the file and the device on which it is stored.

Error handling

There are several aspects to error handling including: detection, correction (if possible) and reporting.
  1. Detection should be done as close to where the error occurred as possible before more damage is done (fault containment). This is not trivial.

  2. Correction is sometimes easy, for example ECC memory does this automatically (but the OS wants to know about it and schedule replacement of the faulty chips before unrecoverable double errors occur).

    Other easy cases include successful retries for failed ethernet transmissions. In this example, while logging is appropriate, it is quite reasonable for no action to be taken.

  3. Error reporting tends to be awful. The trouble is that the error occurs occurs at a low level but by the time it is reported the context is lost. Unix/linux in particular is horrible in this area.

Creating the illusion of synchronous I/O

Sharable vs dedicated devices

For devices like printers and tape drives, only one user at a time is permitted. These are called serially resuable devices and are studied next chapter.

Layering

Layers of abstraction as usual prove to be effective. Most systems are believed to use the following layers (but for many systems, the OS code is not available for inspection).

  1. User level I/O routines
  2. Device independent I/O software
  3. Device drivers
  4. Interrupt handlers

We give a bottom up explanation.

5.2.2: Interrupt Handlers

We discussed an interrupt handler before when studying page faults. Then it was called ``assembly language code''.

In the present case, we have a process (actually the device driver OS code running in behalf of a user process) blocked on I/O and the I/O event has just completed. So the goal is to make the process ready. Possible methods are.

5.2.3: Device Drivers

The portion of the OS that ``knows'' the characteristics of the controler.

The driver has two ``parts'' corresponding to its two access points. Recall the following figure from the beginning of the course.

  1. Access by the main line OS with an I/O request.
  2. Accessed by the interrupt handler when the I/O completes (this completion is signaled by an interrupt).

Tanenbaum describes the actions of the driver assuming it is implemented as a process (which he recommends). I give both that view point and the self-service paradigm in which the driver is invoked by the OS acting in behalf of a user process (more precisely the process shifts into kernel mode).

Driver as a process (tanenbaum)

Driver in a self-service paradigm

5.2.4: Device-Independent I/O Software

Most of the functionality. But not necessarily most of the code since there can be many drivers all doing essentially the same thing is slightely different way due to slightly different controllers.

5.2.5: User-Space Software

A good deal of I/O code is actually executed in user space. Some is in library routines linked into user programs and some is in daemon processes.

Homework:

Homework: 6, 7, 8.

5.3: Disks

The ideal storage device is

  1. Fast
  2. Big (in capacity)
  3. Cheap
  4. Impossible

Disks are big and cheap, but slow.

5.3.1: Disk Hardware

Show a real disk opened up and illustrate the components

Overlapping I/O operations is important. Many controllers can do overlapped seeks, i.e. issue a seek to one disk while another is already seeking.

Despite what Tannenbaum says, modern disks cheat and do not have the same number of sectors on outer cylinders as on inner one. Often the controller ``cover for them'' and protect the lie.

Again contrary to Tannenbaum, it is not true that when one head is reading from cylinder C, all the heads can read from cylinder C with no penalty.