liveBook · Manning

Polling

As explained in Latency

Polling is the repeated checking of a device or status condition by software instead of waiting for an interrupt.

Polling checks a device for events instead of waiting for the device to signal an interrupt. In a latency-sensitive application, that can make the timing of event checks more controllable: an interrupt may stop application code at an unpredictable moment and introduce a latency spike. section 7.5.2 section 2.3.4

A network driver can poll a network interface card (NIC) for newly arrived packets. Linux uses a hybrid approach: it polls while traffic is present and returns to interrupt-driven operation when traffic stops. Its polling path still uses software interrupts to process packets, so polling does not remove every source of interrupt-related work. section 3.3.1

The choice is a latency trade-off, not a universal optimization:

  • Polling gives more control over when checks occur, but repeated checks can do more work than interrupts when no events arrive. section 7.5.2
  • Interrupt affinity offers another way to limit interference: assign NIC interrupts to dedicated CPUs and keep application threads on other CPUs. section 3.3.1

Checking a network path

Packets first enter NIC receive queues, then undergo protocol processing that may run on a different CPU from the application thread. When evaluating polling, account for that processing as well as packet arrival, and test the intended production hardware for latency spikes. section 3.3.1 section 2.3.4

Figure 3.3 Packets traversing the network stack
Figure 3.4: Packets traversing the network stack.

Locates NIC receive queues and protocol processing in the packet path where polling and interrupt work matter. section 3.3.1

How Latency covers it

How deep it goes
Defines active checking, explains idle-work costs and Linux’s hybrid network behavior, but does not provide a polling implementation.
Examples
Illustrates polling with a Linux network driver checking a NIC for packets and switching modes when traffic stops.
What it assumes
Explains interrupt notification and NIC packet arrival while assuming basic familiarity with application threads and network packets.
What you can do after
Evaluate/understand polling versus interrupts by weighing controllable latency against unnecessary checks during idle periods.
How it connects
Connects polling to interrupts, software interrupts, network drivers, CPU affinity, and latency spikes.

Also explained in

Compare how 9 books explain polling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Latency. The section links point to the parts of the book it draws on.