Part 5 · 2 chapters · ~12 min

IO and Device Drivers

Device drivers, port and memory-mapped IO, polling, interrupts and DMA, interrupt handling and softirqs, block and character devices, the IO models (blocking, non-blocking, multiplexed, asynchronous), epoll, kqueue and io_uring, and batching to reduce boundary crossings.

11

Interrupts, DMA and drivers

Everything the Node course said about the event loop (epoll, kqueue, the threadpool for files) is this part seen from the application side.

HOW A DEVICE TALKS TO THE CPU
interrupts, DMA and drivers
CPUruns the drivermemorybuffersdeviceNIC, NVMeinterrupt"I am done"DMAdevice writes memory directlydriverkernel code for the device
swipe the figure sideways, or tap expand for full screen
1/4
drivers
A driver is kernel code that knows one device: how to configure it, submit work and handle completion. Most of the Linux source tree is drivers.
kernel code per device typemost of the kernel is drivers
12

IO models

modelhowused by
blockingread() sleeps until data arrivesthread-per-connection servers
non-blockingread() returns EAGAIN if nothing is readybuilding block for event loops
multiplexed readinessselect, poll, epoll (Linux), kqueue (BSD, macOS): wait on many fds at onceNginx, Node, Redis, Go's netpoller
completion-based asynchronoussubmit operations, collect completions (IOCP on Windows, io_uring on Linux)newer databases and runtimes; works for files too