Getting the kernel to control the I/O

When a new TCP/IP connection gets established, or when a new key is pressed on the keyboard, the kernel must know about it so that it can act accordingly. There are two ways of doing this—the kernel could be looking to those ports or memory addresses once and again to look for changes, which would make the CPU work for nothing most of the time, or the kernel could be notified by a CPU interrupt.

As you can imagine, most kernels decide to go for the second option. They are idle, letting other processes use the CPU until there's a change in some I/O port or address. This makes the CPU interrupt at a hardware level, and gives control to the kernel. The kernel will check what happened and decide accordingly. ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.