Lecture 2: devices

The I/O bus

Last time, we started designing a primitive keyboard. It consisted primarily of a collection of switches (one for each key). These are connected to an encoder; when a key is pressed, a collection of wires encoding the key code is activated.

In fact, the keyboard probably needs a bit more logic, for example to store the key that was pressed so that it can be accessed in the future. Terminology: the hardware in a device that operates the device (and communicates with the main CPU) is the device controller. It can be as simple as a few gates and a latch (as with the keyboard) or as complex as the CPU itself (in the case of a modern GPU)

The interesting question is what happens next. What do we do with those signals? How do they make their way to the processor and ultimately the program?

One design question is HOW the program interacts with the device:

Another question is WHEN the program interacts with the device:

Multiprogramming

The obvious remaining question when doing I/O is what to do while waiting. I/O can take millions of cycles, and sitting around waiting is a large waste of resources.

A natural choice is to have several tasks available, and to switch to a different task while waiting for input.

Some terminology:

When a process wants to wait for I/O, it calls a scheduler, which looks at the list of available processes and selects the next one to run. When the input becomes available, the interrupt handler can then schedule the process that was waiting to be run in the future.

Next lecture, we will talk about context switching from one process to another, and how to make scheduling decisions.