Devices and controllers
A controller shows the CPU status, command and data registers; a driver is kernel code that knows them.
Port-mapped I/O (x86 in/out): a separate address space. Memory-mapped I/O (RISC-V, Arm, RARS at 0xffff0000): ordinary loads/stores to reserved physical addresses. MMIO must be uncached and ordered (fence w,o before a “go” write on RISC-V).
Worked example. In the model above, add 2000 cycles to set up each DMA transfer, plus the 1000-cycle interrupt at its end. A 4 KiB block costs 3000 cycles instead of 1024×100=102,4001024 × 100 = 102{,}4001024×100=102,400 for polling and 1024×1000=1,024,0001024 × 1000 = 1{,}024{,}0001024×1000=1,024,000 for interrupts. The 200 MB/s disk needs 200⋅106/4096=48,828200 · 10^6 / 4096 = 48{,}828200⋅106/4096=48,828 blocks a second, 1.46⋅1081.46 · 10^81.46⋅108 cycles: 7.3 % of the processor. With 64 KiB transfers it drops to 0.46 %. In this model DMA with 4 KiB blocks would use the whole processor only at 2.73 GB/s, which is why fast devices use larger transfers, descriptor rings and fewer interrupts.
Worked example. A keyboard: 10 key presses a second, one 4-byte transfer each. Polling costs 100×1000/(2⋅109)=5⋅10−5100 × 1000 / (2 · 10^9) = 5 · 10^{-5}100×1000/(2⋅109)=5⋅10−5 of the processor, 0.005 %; interrupts cost 1000×10/(2⋅109)=5⋅10−61000 × 10 / (2 · 10^9) = 5 · 10^{-6}1000×10/(2⋅109)=5⋅10−6, ten times less. Both are negligible, but polling would also add up to a millisecond of delay, and on a laptop the wake-ups of a polling loop keep the processor out of its low-power states. A disk delivering 200 MB/s: that is 5⋅1075 · 10^75⋅107 transfers a second. Polling once per transfer needs 5⋅1095 · 10^95⋅109 cycles a second, 2.5 processors; one interrupt per transfer needs 25. Neither works. The two costs are equal where 100×1000=1000×r/4100 × 1000 = 1000 × r/4100×1000=1000×r/4, at r=400 B/s: below that interrupts are cheaper, above it polling is, and both need a whole processor long before disk speeds, polling at 80 MB/s and interrupts at 8 MB/s.