Eroxl's Notes
Polling (Computer Science)

Polling is a technique where the CPU repeatedly checks an I/O controller to determine if data is available or if the device is ready. The CPU uses PIO to read status registers from the controller in a loop until the desired condition is met.

Example

int pollDeviceForValue() {
    volatile int *ready = 0x80000100;
    volatile int *value = 0x80000104;
    while (!*ready) {}  // Busy-wait until ready
    return *value;
}

When Polling is Acceptable

Polling is acceptable when:

  • The poll operation has low overhead
  • There is a high probability that data will be available on each poll
  • The device responds quickly

Problems with Polling

  • CPU waste: Reading I/O-mapped memory is slow, and the CPU wastes cycles waiting
  • Inefficient for rare events: If data is rarely available, most polls are wasted
  • Better alternatives exist: Interrupts allow the controller to signal the CPU only when needed, eliminating busy-waiting