Input-Output, typically referred to as I/O is the way the outside world communicates with hardware, and the hardware sends data

A port is a connection point for a hardware device A bus is a set of shared wires with a protocol A controller is an electronic device to operate a port/bus and interact with attached devices

Typical Raspberry Pi I/O

Typical Laptop/Desktop I/O

Core I/O Concepts

Some devices are primarily for output:

  • e.g. HDMI

Some primarily for input:

  • e.g. Keyboard

Some are bidirectional for both:

  • e.g. ethernet

Generally I/O is digital though sometimes it can be digital I/O Bandwidth is typically described in bits per second (bps)

Blocking vs Non-Blocking I/O

From user space, when you issue an IO command, it may return immediately (non-blocking), or it may wait (blocking) until the operation completes when all the data is transferred.

The key problem with blocking is that IO can be slow, so waiting for IO to complete may take a long time. The thread that initiated the blocking IO is unable to do any other useful work while it is waiting.

On the other hand, a non-blocking IO call returns immediately, performing as much data transfer as is currently possible with the specified device. If no data transfer can be performed, an error status code is returned.

In terms of Unix file descriptor flags, the O_NONBLOCK flag indicates that an open file should support non-blocking IO calls

Why is I/O slow?

I/O requires a constant need for context switches, as well as copying data from kernel memory to user memory. Buffering can improve performance. The objective is to batch small units of data into a larger unit and process in bulk, the act of buffering quantizes data processing. A buffer in this example is just a temporar storage location for data being transferred from one place to another