Programmed I-O and Interrupts
In questa pagina 4
The ways to move data between a peripheral and the CPU (Input-Output Devices and InterfacesPeripherals (keyboard, disk, display) differ from the CPU in speed, codes and operation, so interfaces synchronise and adapt the data. One bus connects several peripherals, each with an address decoder (memory-mapped I/O shares addresses with memory; isolated I/O has separate control lines). Asynchronous control uses strobing (no acknowledgement) or handshaking (acknowledged, more robust); transmission can be serial or parallel, simplex, half or full duplex; USB sends packets with NRZI coding.Input-Output Devices and Interfaces →) differ in who controls the transfer. The third way, DMA, is in Direct Memory Access (DMA)In DMA a controller takes over the buses and moves data between a fast device and memory without involving the CPU; it asks for the bus with Bus Request, receives it with Bus Granted, increments an address register after every word, and raises a single interrupt at the end. The CPU programs it as if it were a peripheral.Direct Memory Access (DMA) →.
Programmed I/O
Definition (programmed I/O). The transfer is started and controlled by a program instruction. The CPU constantly checks the device status in an instruction loop, the busy-wait, and can do nothing else; the device is usually far slower, so many machine cycles are wasted. Simple but inefficient.
Example. A device at byte/s: one byte every ms. If checking the status takes the CPU ns, between two transfers it checks times, nearly all useless.
Interrupts
Definition (interrupt). The transfer is no longer monitored by the CPU but by an interface that raises a signal, the interrupt, when data are available. Meanwhile the CPU does useful work; when the interrupt arrives it suspends the current operation, runs a service routine to process the data and returns to the original task. The interrupt is an output of the peripheral and an input of the CPU.
Example. For the same byte/s device the CPU is interrupted times per second, instead of performing status checks per byte.
The interrupt is recognised by the CPU as an external event, which diverts the flow to the service routine and then back to the interrupted program; the keyboard controller, for instance, talks to the CPU this way.
- Vectored interrupt: the device supplies the location (vector address) of the service routine; non-vectored: a fixed location.
- Several devices: how to identify the source? Simultaneous requests are possible, so a priority strategy is needed, in software (after an interrupt the CPU polls the devices) or in hardware (serial/daisy chain, or parallel).
Definition (priority).
- Daisy chain: priority is given by the order in the chain of connected devices; the first device that raised the interrupt sends its vector address and is served by the CPU. Devices pass the grant along the chain, so the CPU does not determine the highest-priority device (the chain does) and two interrupts cannot be handled in parallel.
- Parallel priority: a priority encoder determines the priority; devices can be masked (disabled) with a mask register.
Example. If are in a chain and request an interrupt together, , the closest to the CPU, is served first.
Comparison of transfer modes
| programmed I/O | interrupt | DMA | |
|---|---|---|---|
| who controls | CPU (polling) | interface (signal) | DMA controller |
| CPU while waiting | busy (busy-wait) | free | free |
| suited to | slow, simple devices | infrequent events | large blocks of data |
Common mistakes
- Saying the CPU sets the priority in a daisy chain: the order in the chain does.
- Saying the interrupt is an input of the peripheral: it is an output of the peripheral and an input of the CPU.
Versione ripasso
- Programmed I/O: the CPU checks the status in a busy-wait loop; simple but wasteful. A device at 100 byte/s with a 100 ns status check means checks per byte, nearly all useless.
- Interrupt: the interface raises a signal when data are ready; the CPU suspends its work, runs the service routine and returns. Output of the peripheral, input of the CPU. With the same device: 100 interrupts per second.
- Vectored: the device gives the vector address of the routine; non-vectored: fixed location.
- Priority: software (CPU polls the devices) or hardware. Daisy chain: priority is the position in the chain, the CPU does not choose, no parallel handling of two interrupts; closest to the CPU wins. Parallel: priority encoder plus mask register to disable devices.
- Comparison: programmed I/O (CPU busy, slow simple devices), interrupt (CPU free, infrequent events), DMA (CPU free, large blocks) (Direct Memory Access (DMA)In DMA a controller takes over the buses and moves data between a fast device and memory without involving the CPU; it asks for the bus with Bus Request, receives it with Bus Granted, increments an address register after every word, and raises a single interrupt at the end. The CPU programs it as if it were a peripheral.Direct Memory Access (DMA) →).
- Mistakes: priority attributed to the CPU in a daisy chain; interrupt seen as an input of the peripheral.