</>EmbeddedInterview

What is interrupt latency and how do you reduce it?

MediumEmbedded C

Short answer: Interrupt latency is the time from the interrupt signal being asserted until the first instruction of the ISR runs. On Cortex-M3/M4 the hardware minimum is 12 clock cycles with zero-wait-state memory (Cortex-M0 is 16, M0+ 15). In real systems it is dominated by software: periods with interrupts disabled, higher-priority interrupts running, and memory wait states.

What adds latency

Cause Effect
Interrupts disabled (critical sections, __disable_irq) the interrupt waits until they are re-enabled
A higher- or equal-priority ISR already running waits for it to finish (or tail-chains after it)
Flash wait states, cache misses on the vector fetch or stacking adds cycles
FPU context stacking (Cortex-M4F/M7) up to 17 extra words; lazy stacking defers it
RTOS kernel critical sections the kernel masks interrupts up to its syscall priority
Multi-cycle instructions (e.g. LDM on some cores) may be restarted or completed first
Wake-up from deep sleep clock and regulator start-up time (microseconds to milliseconds)

How to reduce it

  • Keep critical sections short; mask only what you must (BASEPRI to block lower priorities instead of PRIMASK, which blocks everything).
  • Give time-critical interrupts the highest priority and keep other ISRs short.
  • Put the vector table and hot ISRs in RAM or TCM (Cortex-M7: ITCM) to avoid flash wait states; enable flash prefetch/ART accelerators and caches.
  • Avoid the FPU in time-critical ISRs, or keep lazy stacking enabled.
  • On an RTOS, run the most time-critical interrupts above the RTOS's maximum syscall priority, so kernel critical sections never mask them (they then must not call RTOS APIs).
  • Choose a lighter sleep mode if wake-up time matters.

Jitter (variation in latency) often matters more than the average for control loops; measure both by toggling a GPIO at the start of the ISR and capturing the delay from the input edge on an oscilloscope or logic analyser.

Related Cortex-M features: tail-chaining (6 cycles between back-to-back ISRs instead of a full exit and entry) and late arrival (a higher-priority interrupt arriving during stacking gets serviced first without re-stacking) both reduce latency automatically.