Part 1 of 7 · 1 min read
Why this page comes fourth
In this module you will
- Describe a device controller and its registers, and tell port-mapped I/O from memory-mapped I/O.
- Write the polling loop for a device in C-like code, and compute how much processor time it wastes.
- Compute the processor time of interrupt-driven I/O and say when polling is the better choice.
- Explain how direct memory access (DMA) moves data without the processor, and compute the saving.
- Measure the interrupts that a read causes on Linux, and read the I/O ports and memory ranges.
Pages 1 to 3 treated storage devices as boxes that accept requests. This page opens the box one level: how the processor starts a transfer, learns that it is finished, and moves the data. Level 0 introduced interrupts. Here they are used for real devices, next to polling and DMA. Page 5 builds the software layers of the kernel on top of this hardware.
About this example About this example
Real: The C program in section 5 was compiled with gcc -Wall -Wextra and run on a Linux test machine (2 processors, kernel 6.18). The listings of /proc/ioports, /proc/iomem and /proc/interrupts were read on the same machine, which is a virtual machine and shows virtual devices.
Scripted: The times of 50 ns per poll, 20 ns per word, 5 microseconds per interrupt and 10 microseconds for DMA set-up, and the device speeds, are made up to show the idea.
Not real: The register names and the polling loop in section 2 are a labelled sketch and not the registers of any real device. Real drivers add checks, locks and error paths.