Skip to content
Part IA Lent Term

I/O Hardware and Methods

The device hierarchy

I/O devices span a vast range of performance:

DeviceData rateTypical use
Keyboard10 B/sCharacter input
Mouse100 B/sPointer updates
Gigabit Ethernet125 MB/sNetwork I/O
NVMe SSD3–7 GB/sStorage
GPU16–64 GB/s (PCIe)Graphics/compute

The OS must manage devices whose speeds differ by nine orders of magnitude — from slow character devices to high-throughput DMA engines.

Three I/O methods: programmed I/O, interrupt-driven I/O, and direct memory access (DMA), with interrupt handling flow diagram

Programmed I/O (PIO)

The CPU directly controls every byte of data transfer. The device has a status register (busy/ready) and a data register. The CPU polls the status register in a loop:

while (status & DEVICE_BUSY);    // wait until ready
*data_reg = byte_to_send;        // write data

Advantages: Simple hardware (no interrupt controller needed). Predictable latency.

Disadvantages: The CPU wastes cycles polling (CPU-bound waiting). Terrible for slow devices — the CPU could do millions of instructions while waiting for a disk or network operation.

Interrupt-driven I/O

The CPU issues an I/O command to the device, then continues executing other processes. When the device completes the operation, it raises an interrupt. The CPU invokes the device’s Interrupt Service Routine (ISR), which copies the data and wakes any waiting process.

Advantages: No busy-waiting. The CPU is free for other work during I/O.

Disadvantages: Interrupt overhead (context switch, ISR execution) for every small transfer. For a high-speed device (e.g., 10 Gbps Ethernet), interrupt overhead can dominate CPU time.

Direct Memory Access (DMA)

For bulk transfers, the CPU offloads the entire operation to a DMA controller. The CPU tells the DMA controller: source address, destination address, byte count. The DMA controller transfers the data directly between the device and memory, without CPU involvement per byte. When the transfer completes, the DMA controller raises a single interrupt.

Advantages: CPU is free during the entire transfer, not just between bytes. One interrupt per transfer, not per byte.

Disadvantages: Requires DMA-capable hardware. DMA transfers compete with the CPU for memory-bus bandwidth (though modern memory controllers are sophisticated enough to arbitrate fairly). DMA controllers are a limited resource (one per chipset, or per PCIe device).

Comparison

MethodCPU involvementLatency per byteBest for
PIOCPU moves every byteHigh (CPU-bound)Very slow devices, early boot, debugging
Interrupt-drivenCPU handles one interrupt per transferMedium (interrupt overhead)Medium-speed devices (keyboard, mouse)
DMACPU sets up transfer; device touches memory directlyLow (one interrupt per bulk transfer)High-speed bulk devices (disk, NIC, GPU)

The modern reality

Real systems use hybrids. A network card might use interrupt-driven I/O for low traffic, then switch to DMA (and interrupt coalescing — batching multiple completions into one interrupt) under high load to reduce CPU overhead.

Summary

  • PIO: CPU polls/writes every byte — simple but CPU-inefficient.
  • Interrupt-driven: CPU free during I/O; overhead per interrupt.
  • DMA: bulk transfers without per-byte CPU involvement; one interrupt per bulk transfer.
  • Modern systems dynamically switch between polling, interrupt-driven, and DMA based on load.