Home › Theme A › A1 › A1.3 › A1.3.4

A1.3.4 Polling vs interrupts: which is better when?

SL + HLCommand term: Evaluate

1. Polling vs interrupts: race simulator

A device produces events (), such as key presses or arriving network data. Polling: the CPU keeps asking the device "anything new?" every few ticks. Interrupts: the device tells the CPU the moment something happens. Pick a scenario or set the sliders, then step through 60 ticks.

⚡ Device events
🔁 CPU with polling
🔔 CPU with interrupts
useful workpoll: nothing new (wasted)poll: event found and handledinterrupt handler (ISR)asleep (saving power)awake but idle (using battery)

2. What happens during an interrupt?

Click Next to follow the CPU as it handles a key-press interrupt.

3. Evaluate: polling or interrupts?

For each real-world scenario, choose the better approach. The explanation names the factors from the syllabus. Score: 0 /

Learning objectives

By the end of this page you should be able to:

  1. Describe how polling works.
  2. Describe how interrupts and interrupt handling work.
  3. Compare polling and interrupts by event frequency, CPU overhead, power source, predictability, latency and security.
  4. Evaluate the use of polling or interrupts in real-world scenarios such as keyboard and mouse input, network communications and disk I/O.
  5. Justify the choice of polling or interrupts for embedded and real-time systems.

Polling

The CPU repeatedly checks the status of a device at regular intervals ("Are you ready? Anything new?"). It is simple and predictable, but the CPU wastes time checking when nothing has happened, and an event may wait until the next check.

Interrupts

The device sends an interrupt signal to the CPU when it needs attention. The CPU finishes its current instruction, saves its state (PC and registers) on the stack, runs an interrupt service routine (ISR), then restores its state and carries on. Interrupts can have priorities, so urgent ones are handled first.

Evaluation by factor

FactorPolling is better when…Interrupts are better when…
Event frequencyevents are very frequent: there is almost always something new, so checks are rarely wasted and repeated interrupt overheads are avoidedevents are rare: no CPU time is wasted checking an idle device
CPU processing overheadseach check is cheap and there's no context switchingavoiding constant checks matters more than the small cost of saving and restoring state for each interrupt
Power sourcethe device is on mains power and the CPU is busy anywayit runs on battery: the CPU can sleep until an interrupt wakes it
Event predictabilityevents are regular / predictable, so polls can be timed to match themevents are unpredictable, e.g. a user pressing a key
Controlled latencya fixed, guaranteed response time is needed (deterministic timing in some safety-critical loops)the fastest possible response to unpredictable events is needed
Security concernsa simpler, predictable design is easier to verify; a flood of interrupts can't overwhelm the CPUhandlers must be protected: malicious devices or software could cause interrupt storms (a form of denial of service), or exploit ISR code that runs with high privilege

Typical real-world choices

  • Keyboard and mouse: interrupts (unpredictable, relatively rare events; the user expects an instant response).
  • Network communications: interrupts for normal traffic; under very heavy traffic, network cards often switch to polling to avoid an interrupt for every packet.
  • Disk input/output: interrupts signal that a slow read/write has finished, so the CPU can do other work meanwhile.
  • Embedded systems: simple, regular sensors are often polled; battery devices use interrupts so they can sleep.
  • Real-time systems: prioritised interrupts for urgent events (e.g. an airbag crash sensor); polling where a fixed, predictable cycle is required.
Exam tip: "Evaluate" needs both sides and a conclusion for the specific scenario. Name at least two factors, for example: "As key presses are unpredictable and the laptop runs on battery, interrupts are more suitable…"

Use the 中文 button at the top to show or hide the Chinese terms.

Term中文Meaning

Choose an answer. You get instant feedback.

Score: 0 /

Write your answer first, then reveal the markscheme. These are exam-style practice questions written for this site.

1. Distinguish between polling and interrupt handling. [2]

Polling: the CPU repeatedly checks the status of a device at regular intervals [1]; interrupt: the device sends a signal to the CPU when it needs attention, so the CPU does not need to check [1].

2. Describe the steps the CPU takes when it receives an interrupt. [4]

Award [1] for each, up to [4]: the CPU completes the current instruction; it saves the contents of the PC and registers (onto the stack); it identifies the source / type of interrupt (interrupt vector); it runs the interrupt service routine; it restores the saved registers / PC; it resumes the interrupted program.

3. Explain why interrupts are more suitable than polling for the keyboard of a battery-powered laptop. [3]

Award [1] for each, up to [3]: key presses are unpredictable / relatively infrequent; with polling, the CPU would waste processing time checking when no key has been pressed; with interrupts, the CPU only responds when a key is pressed; the CPU can enter a low-power state between interrupts, saving battery; the response is immediate (low latency).

4. A network card in a busy data centre receives millions of packets per second. Evaluate the use of polling instead of interrupts in this scenario. [4]

Award [1] for each, up to [4]: events (packets) are extremely frequent; with interrupts, every packet would cause a context switch, and the overhead would overwhelm the CPU (an interrupt storm / livelock); with polling, almost every check finds data, so little time is wasted; packets can be processed in batches, improving throughput; the server is on mains power, so power use is less of a concern; but polling wastes time when traffic drops, so many systems switch between the two depending on load; conclusion: polling is more suitable under heavy load.

5. Outline one security concern related to interrupt handling. [2]

A malicious device or program could generate a flood of interrupts (interrupt storm) [1]; which keeps the CPU busy handling them, causing a denial of service [1]. OR: ISRs run with high privilege [1], so a vulnerability in a handler or driver could let an attacker take control of the system [1].