Peripheral Communication
A CPU on its own is deaf and mute; input/output (I/O) is how it communicates with keyboards, disks, networks, and displays. Because these devices operate on their own slower schedules, the system needs disciplined ways to coordinate.
The simplest method is polling (programmed I/O), where the CPU repeatedly asks a device in a loop if it is ready yet. While simple, polling wastes valuable CPU cycles through busy-waiting, doing no useful work while waiting.
| I/O Method | CPU Involvement | Best Used For |
|---|---|---|
| Polling | 100% busy-wait | Trivial or timing-critical tasks |
| Interrupts | Pauses only to handle events | General asynchronous devices |
| DMA | Interrupted only at the end | Large blocks of bulk data |
Interrupts and DMA
To avoid wasting cycles, we use interrupts. The CPU issues a request and continues other work until the device sends an interrupt signal, prompting the CPU to run an interrupt handler.
For bulk data transfers, direct memory access (DMA) is used. A dedicated DMA controller moves data between devices and main memory without the CPU handling every single byte.
Common pitfall: Assuming polling is better because it is simpler. Polling wastes CPU cycles; use interrupts or DMA for efficiency.