OS Notes
Understanding I/O hardware components — device types, device controllers, I/O ports, memory-mapped I/O, and how the CPU communicates with peripheral devices.
Introduction
Your computer communicates with the outside world through Input/Output (I/O) devices — keyboards for input, monitors for output, disks for both, and network cards for communication. But how does the CPU, which only understands binary numbers and memory addresses, communicate with such diverse devices as printers, USB drives, webcams, and touchscreens?
The answer lies in I/O hardware architecture — a layered system of buses, controllers, ports, and protocols that standardizes communication between the CPU and hundreds of different device types. Understanding I/O hardware is essential because I/O is often the biggest performance bottleneck in computer systems.
Device Classification
By Direction
- Input devices: Keyboard, mouse, scanner, microphone, webcam
- Output devices: Monitor, printer, speakers
- Both (I/O): Disk drives, network cards, touchscreens
By Data Transfer Mode
- Character devices: Transfer data one character/byte at a time (keyboard, serial port, mouse). Accessed sequentially, no seeking.
- Block devices: Transfer data in fixed-size blocks (hard drives, SSDs, USB drives). Support random access and seeking.
By Access Method
- Sequential: Data accessed in order (tape drives, keyboard)
- Random: Any position accessible directly (disks, RAM)
Device Controllers
Devices do not connect directly to the CPU. Each device (or group of similar devices) has a controller — a small specialized processor that handles the detailed communication with the device hardware.
| CPU | ←──── System Bus ──→ | Controller | ←── Cable ──→ | Device |
|---|---|---|---|---|
| (chip on board) | (physical) |
Examples:
- SATA controller manages hard drives
- USB controller manages USB devices
- Network Interface Card (NIC) manages network communication
- GPU manages display output
I/O Port Space vs Memory-Mapped I/O
The CPU communicates with controllers through registers. Two approaches for accessing these registers:
Port-Mapped I/O (Isolated I/O)
Device registers are in a separate address space from memory. Special instructions (IN/OUT on x86) are used.
Memory-Mapped I/O
Device registers are mapped into the regular memory address space. The CPU accesses them using normal load/store instructions.
| 0x00000000 - 0x7FFFFFFF | Regular RAM |
| 0x80000000 - 0x80000FFF | Network card registers (memory-mapped) |
| 0x80001000 - 0x80001FFF | GPU control registers |
| 0x80002000 - 0x80002FFF | Sound card registers |
Advantages of memory-mapped I/O: No special instructions needed, can use all memory-referencing instructions, C/C++ pointers work directly. Disadvantages: Cannot cache these addresses (they are live hardware!), reduces available memory address space.
Bus Architecture
Devices connect through a hierarchy of buses:
| CPU ← | [Memory Bus] ←→ RAM |
| └── | [PCI Express Bus] |
| ├── [USB Controller] | USB devices |
| ├── [SATA Controller] | Hard drives |
| ├── [Audio Controller] | Speakers |
| └── [Network Controller] | Ethernet/WiFi |
Modern PCs use PCIe (PCI Express) as the primary expansion bus. Each device gets dedicated lanes (bandwidth), unlike older shared buses where devices competed for bandwidth.
Polling vs Interrupts vs DMA
Three methods for the CPU to interact with I/O devices:
Polling (Busy Waiting): CPU repeatedly checks device status register. Simple but wastes CPU cycles.
Interrupts: Device signals the CPU when it is ready. CPU does other work while waiting. Efficient but has interrupt handling overhead.
DMA (Direct Memory Access): A special controller transfers data directly between device and memory without CPU involvement. The CPU only sets up the transfer and gets interrupted when it is complete. Best for large data transfers (disk I/O, network packets).
Real-World Analogy
I/O hardware is like a postal system. The CPU is the central office. Device controllers are local post offices that handle the specifics of each delivery method (air mail = network, ground shipping = disk). Buses are the roads connecting them. Memory-mapped I/O is like having post office boxes in the same building as regular offices. DMA is like a delivery truck that goes directly from warehouse to destination without passing through the central office.
Key Takeaways
- I/O devices are classified as character (byte-at-a-time) or block (chunk-at-a-time)
- Device controllers mediate between the CPU and physical devices through register interfaces
- Port-mapped I/O uses special instructions; memory-mapped I/O uses regular memory addresses
- Modern systems use PCIe buses with dedicated bandwidth lanes per device
- Three CPU-device interaction methods: polling (simple, wasteful), interrupts (efficient), DMA (best for bulk)
- I/O hardware design critically affects system performance since I/O is typically the bottleneck
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for I/O Hardware.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, input, output, hardware, i/o hardware
Related Operating Systems Topics