Interrupt latency

On this page 7

Interrupt latency is the time that elapses between the moment a hardware device asserts an interrupt signal and the moment the processor begins executing the corresponding interrupt service routine (ISR). In operating systems, it is a key measure of how quickly drivers & devices can get attention from the CPU, and it sets a lower bound on how fast the system can react to external events.

Engineers care about two numbers: the typical latency, which affects throughput and responsiveness, and the worst-case latency, which decides whether a real-time deadline can be guaranteed. A system with excellent average latency may still be unsuitable for control tasks if rare spikes exceed the allowed bound.

What happens between the interrupt signal and the handler

Interrupt latency is the sum of several sequential delays in hardware and software. A device raises an interrupt request line or sends a message signaled interrupt; the interrupt controller prioritizes it and forwards it to a CPU core; the core finishes or abandons the current instruction, saves state, consults the interrupt vector table and jumps to the entry code of the handler.

The table below breaks the path into its components. The ranges are indicative for modern hardware and vary with processor design, clock speed and system load.

StageWhat causes the delayIndicative range
Signal propagationBus transfer, MSI write, controller routingTens to hundreds of nanoseconds
Interrupt maskingCode running with interrupts disabledNanoseconds to milliseconds
Instruction completionFinishing long or multi-cycle instructionsA few to hundreds of cycles
Context save and dispatchPushing registers, vector lookup, mode switchTens to hundreds of cycles
Cache and TLB missesHandler code and data not in cacheHundreds of nanoseconds or more
Power state exitWaking a core from a deep idle stateMicroseconds to over 100 µs
Components of interrupt latency

In practice, the longest interrupt-disabled section in the kernel and the deepest allowed idle state dominate the worst case. Hardware dispatch on a microcontroller can take as little as 12 cycles, while a general-purpose desktop may show worst cases of tens or hundreds of microseconds.

Interrupt latency is often confused with neighboring measurements. Precise vocabulary matters because a vendor figure for one of them does not predict the others.

MeasureStarts atEnds at
Interrupt latencyDevice asserts the interruptFirst instruction of the ISR
Interrupt response timeDevice asserts the interruptISR performs useful work
Deferred processing latencyISR finishesBottom half, DPC or threaded handler runs
Scheduling latencyTask becomes runnableTask actually runs on a CPU
End-to-end I/O latencyApplication issues a requestApplication receives the result
Related latency measures in driver and kernel work

Modern kernels split interrupt handling into a short top half that acknowledges the device and a deferred part, such as Linux softirqs and threaded IRQs or Windows deferred procedure calls. This design keeps interrupt latency low for other devices, but it moves work into a later phase whose delay must be measured separately.

Factors that increase interrupt latency

Latency grows whenever something prevents the CPU from accepting the interrupt or slows the path to the handler. Many of these causes are invisible in normal benchmarks and appear only under specific load.

  • Long critical sections in drivers or the kernel that disable interrupts or hold spinlocks with interrupts off.
  • Poorly written ISRs of other devices that run for a long time at higher priority.
  • Deep CPU idle states (C-states) and frequency scaling, which add wake-up time.
  • System management interrupts (SMIs) on x86, which run firmware code invisible to the operating system.
  • Virtualization, where the hypervisor must intercept and inject interrupts into a guest.
  • Interrupt coalescing in network cards, which deliberately delays interrupts to batch work.

Measuring and reducing interrupt latency

Interrupt latency is measured by timestamping a known external event and the start of its handler. Common approaches include toggling a GPIO pin in the ISR and observing it with an oscilloscope, using tracing tools such as ftrace or Event Tracing for Windows, or running test programs like cyclictest that report maximum observed latency over long periods.

The next table pairs common goals with techniques that experienced engineers apply. Each technique has a cost, usually in power consumption or throughput, so the choice depends on the workload.

GoalTechniqueTrade-off
Bound the worst casePREEMPT_RT kernel or a real-time OSSlightly lower average throughput
Avoid wake-up delayLimit deep C-states on critical coresHigher idle power and heat
Reduce interferencePin the interrupt and task to an isolated coreFewer cores for general work
Shorten handlersMove work to threaded or deferred handlersMore complex driver design
Speed up deliveryUse MSI or MSI-X instead of shared linesRequires device and platform support
Remove batching delayDisable or tune interrupt coalescingMore interrupts and CPU load
Techniques for lowering interrupt latency

Where interrupts arrive too often, the opposite approach can win: polling or hybrid schemes such as Linux NAPI disable interrupts during bursts and process many events per pass. This trades a little latency at low load for far better throughput at high load.

Why worst-case latency matters more than the average

For real-time systems, a single late interrupt can be a failure. A motor controller sampling at 20 kHz has a period of 50 µs; if one interrupt arrives 80 µs late, a control cycle is lost no matter how good the average is. Certification of safety-related systems therefore relies on measured and analyzed worst-case bounds, not on mean values.

General-purpose desktops usually do not guarantee bounds at all. Audio dropouts, input stutter and missed frames on such systems often trace back to a single misbehaving driver that disables interrupts or runs a long deferred routine.

The short version

Interrupt latency is how long a device waits before the computer starts paying attention to it. When a key is pressed or a network packet arrives, the hardware taps the processor on the shoulder, and the latency is the pause before the processor turns around.

Most of the time the pause is tiny. What matters for machines and audio is the longest pause, because one slow response can cause a glitch even if all the others were quick.

Where it makes a difference

A small manufacturer builds an industrial robot arm controlled by a Linux computer. The motor encoder raises an interrupt every 100 µs, and the control loop must react within 30 µs. On a standard kernel, a week-long cyclictest run shows worst-case latency spikes near 400 µs, caused mainly by deep idle states and a storage driver that disables interrupts during long transfers.

The engineers switch to a PREEMPT_RT kernel, isolate one core for the encoder interrupt and the control task, and limit that core to shallow idle states. A new test over seven days shows a maximum latency of about 18 µs. The arm now meets its timing budget with margin, at the cost of slightly higher idle power.