Salta al contenuto
Note per Studenti Programmed I-O and Interrupts Report

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 100100 byte/s: one byte every 1010 ms. If checking the status takes the CPU 100100 ns, between two transfers it checks 10 ms/100 ns=100 00010\,\mathrm{ms}/100\,\mathrm{ns}=100\,000 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 100100 byte/s device the CPU is interrupted 100100 times per second, instead of performing 100 000100\,000 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 P1,P2,P3P_1,P_2,P_3 are in a chain and request an interrupt together, P1P_1, 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

Teoria collegata