# 中断延迟

**中断延迟**是指从中断请求被发出，到对应的中断服务程序（ISR）的第一条指令开始执行之间的延迟。它是实时系统的一项核心性能指标，因为系统对外部事件的响应时间直接取决于它。在微控制器上，中断延迟通常以处理器时钟周期来度量；在运行于应用处理器的操作系统上，则以微秒度量，并包含关抢占、临界区等软件开销。<sup>[1](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)</sup><sup> • </sup><sup>[2](https://www.sciencedirect.com/topics/computer-science/interrupt-latency)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 从中断请求置位到 ISR 第一条指令执行的时间<sup>[1](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)</sup> |
| Cortex-M 硬件延迟 | 12 周期（Cortex-M3/M4/M33），15（M0+/M23），16（M0），M7 通常为 12、最坏 14，均以零等待态存储器为前提<sup>[1](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)</sup> |
| Armv7-M 各环节 | 异常进入 12 周期，尾链 6 周期，异常退出 10 周期<sup>[3](https://irqkit.com/tools/interrupt-latency-calculator)</sup> |
| RTOS 的影响 | 最坏情况延迟的下界为最长的 RTOS 临界区加上硬件固有延迟<sup>[4](https://past.date-conference.com/proceedings-archive/2021/pdf/1782.pdf)</sup> |
| RISC-V 对比 | CV32E40P 在常规 ABI 下非 RTOS ISR 最坏延迟为 33 周期，EABI 加 RV32E 下为 24 周期，而 Cortex-M3 为 12 周期<sup>[4](https://past.date-conference.com/proceedings-archive/2021/pdf/1782.pdf)</sup> |
| Linux PREEMPT_RT | 强制中断处理程序以 SCHED_FIFO 优先级 50 线程化运行，减少关中断或关抢占的代码段<sup>[5](https://cdn.kernel.org/doc/html/latest/core-api/real-time/theory.html)</sup> |
| Linux 最佳公开结果 | 一种在 ARM 多核平台上的中断隔离设计实现了稳定的亚 0.5 微秒响应时间，优于常规 PREEMPT_RT 配置<sup>[6](https://arxiv.org/abs/2509.03855)</sup> |

## 延迟由哪些部分构成

总延迟分为硬件部分和软件部分。硬件部分包括：中断信号经中断控制器传播、当前执行指令执行完毕，以及在第一条 ISR 指令得以运行之前自动保存处理器状态（寄存器与程序状态入栈）。在 Cortex-M3 上，寄存器 R0 至 R3 和 R12 在 12 周期的进入序列内被压入栈中，这使得中断处理程序可以写成普通的 C 子程序，立即开始实际工作。<sup>[7](https://community.arm.com/processors/b/blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors)</sup>

软件部分通常更大，也更不稳定。正在进行的低优先级中断服务会阻塞比它优先级更低的新中断；关中断的代码段会将其完整执行时长加到在此期间到来的任何中断的延迟上；而在带有内存管理单元的处理器上，冷翻译后备缓冲器（TLB）引发的页表遍历会显著增加中断延迟。<sup>[8](https://www.digikey.com/en/articles/real-time-some-notes-on-microcontroller-interrupt-latency)</sup> 在实时操作系统中，除非体系结构允许非 RTOS 中断在临界区内运行，否则最坏情况的下界为程序中最长的临界区加上硬件固有延迟。<sup>[4](https://past.date-conference.com/proceedings-archive/2021/pdf/1782.pdf)</sup>

## Arm Cortex-M 的公开数据

Arm 官方文档给出的 Cortex-M 系列中断延迟，是在零等待态存储器系统中，从中断请求置位到处理程序第一条指令就绪所在周期的精确周期数：<sup>[1](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)</sup>

| 处理器 | 周期数（零等待态存储器） |
|---|---|
| Cortex-M0 | 16 |
| Cortex-M0+ | 15 |
| Cortex-M23 | 15 |
| Cortex-M3 | 12 |
| Cortex-M4 | 12 |
| Cortex-M7 | 通常 12，最坏 14 |
| Cortex-M33 | 12 |

这些数字假定：零等待态存储器未被其他总线主设备占用、片上中断信号连接无延迟、未被当前运行的异常阻塞、Cortex-M4 配 FPU 时启用惰性压栈，且当前指令中无未对齐或位带传输。<sup>[7](https://community.arm.com/processors/b/blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors)</sup> 实践中，许多运行频率高于 100 MHz 的微控制器使用的是工作在 30 到 50 MHz 的闪存，尽管闪存加速硬件有所帮助，等待态仍可能抬高实际延迟。因此，一个零等待态存储器的 Cortex-M0/M0+ 系统，其实际中断延迟可能比 Cortex-M3/M4/M7 系统更短。<sup>[1](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)</sup>

Armv7-M 架构增加了缩短连续中断处理的机制：尾链（连续的中断进入只需 6 周期，而非完整退出再进入）和中断迟到，二者均在 Cortex-M3 中实现。<sup>[3](https://irqkit.com/tools/interrupt-latency-calculator)</sup><sup> • </sup><sup>[9](https://documentation-service.arm.com/static/5f2286f2f3ce30357bc28b2a?token=)</sup> Cortex-M0 和 Cortex-M0+ 还提供可选特性，可强制中断响应时间零抖动。<sup>[7](https://community.arm.com/processors/b/blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors)</sup>

## RISC-V 与中断控制器

中断控制器的设计与内核同样重要。标准的 RISC-V 平台级中断控制器（PLIC）需要软件介入：内核必须读写配置与控制寄存器来解复用并接受到来的中断，这一软件控制环路会带来延迟。因此，RISC-V 微控制器的中断延迟往往高于 Arm Cortex-M 器件，后者在嵌套向量中断控制器（NVIC）中采用硬件加速的向量化处理。增强型 PLIC（EPLIC）等增强控制器加入了硬件加速的向量化调度、上下文保存与恢复、中断嵌套和尾链，以缩小这一差距。<sup>[10](https://www.sciencedirect.com/science/article/pii/S1879239125000773)</sup>

一项使用 FreeRTOS、对开源 RISC-V 内核 [CV32E40P](https://www.edgepedia.org/zh/cv32e40p) 与 Cortex-M3 进行的周期精确对比量化了这一差异。非 RTOS ISR 的最坏延迟，在常规 ABI（16 个调用者保存寄存器）下为 33 周期，在 RV32E 下为 27 周期，在嵌入式 ABI（EABI）加 RV32E（7 个调用者保存寄存器）下为 24 周期；而 Cortex-M3 为 12 周期、6 个调用者保存寄存器。差距源于 Cortex-M3 在取 ISR 地址的同时由硬件保存全部调用者保存寄存器和机器状态，而 RISC-V 内核则用软件保存寄存器。RISC-V 侧的软件优化使 RTOS 中断延迟平均改善 33%，最坏情况改善 20%。<sup>[4](https://past.date-conference.com/proceedings-archive/2021/pdf/1782.pdf)</sup>

## 通用操作系统中的中断延迟

在运行 Linux 或其他通用内核的系统上，软件部分占主导。关抢占会阻止调度器切换到更高优先级的任务并增加延迟，因此关中断或关抢占运行的内核代码为最坏情况设定了下限。[PREEMPT_RT](https://www.edgepedia.org/zh/preempt-rt) 补丁集将 Linux 转变为实时内核：用可抢占、支持优先级继承的 rtmutex 取代 spinlock_t，并强制中断处理程序线程化，使中断处理在可调度的线程中运行。默认情况下，线程化处理程序以 SCHED_FIFO 策略、优先级 50（MAX_RT_PRIO / 2）运行，处于实时优先级最小值和最大值的中点。从唤醒中断线程到线程化处理完成，中断源在中断控制器中被屏蔽，使设备中断保持挂起状态而不会再次触发 CPU。<sup>[5](https://cdn.kernel.org/doc/html/latest/core-api/real-time/theory.html)</sup>

虚拟化又增加了一层。虚拟机监控器和非对称多处理框架会引入自身的中断延迟，必须加以测量以验证实时合规性；一项研究使用专用硬件测量电路在 Zynq UltraScale+ MPSoC 上测量了这些延迟，因为纯软件测量具有侵入性且精度较低。<sup>[11](https://www.mdpi.com/2079-9292/13/9/1626)</sup> 一种更新的方法——中断隔离，配合一套专用 API 来有选择地调用定时器例程并抑制非关键处理器间中断——在基于 ARM 的多核平台上实现了稳定的亚 0.5 微秒响应时间，优于常规 Linux PREEMPT_RT 配置。<sup>[6](https://arxiv.org/abs/2509.03855)</sup>

## 测量

延迟通常从一个硬件事件测量到一个可见响应，例如在 ISR 中翻转 GPIO 并用逻辑分析仪计时，或使用专用硬件电路独立于被测软件为中断置位和处理程序进入打时间戳。<sup>[11](https://www.mdpi.com/2079-9292/13/9/1626)</sup> 基准测试套件定义了在给定平台上激发最小和最大中断延迟以及最大中断吞吐量的测试用例；其中一种针对 ARMv8-A 平台的方法将七个压力测试用例组合成三个基准函数。<sup>[12](https://arxiv.org/abs/2009.00506)</sup> 由于公开的周期数假定零等待态存储器且无总线争用，对特定系统而言唯一可靠的真相是在真实负载下于真实硬件上测量。<sup>[7](https://community.arm.com/processors/b/blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors)</sup>

## References

1. [Cortex-M for Beginners, ARM white paper (Table 8: interrupt latency with zero wait state memory)](https://community.arm.com/cfs-file/__key/telligent-evolution-components-attachments/01-2057-00-00-00-01-28-35/Cortex_2D00_M-for-Beginners-_2D00_-2017_5F00_EN_5F00_v2.pdf)
2. [Interrupt Latency - an overview, ScienceDirect Topics](https://www.sciencedirect.com/topics/computer-science/interrupt-latency)
3. [Interrupt Latency Calculator (ARM Cortex-M), IRQKit](https://irqkit.com/tools/interrupt-latency-calculator)
4. [R. Balas, L. Benini (2021). RISC-V for Real-time MCUs - Software Optimization and Microarchitectural Gap Analysis, DATE 2021](https://past.date-conference.com/proceedings-archive/2021/pdf/1782.pdf)
5. [Theory of operation, The Linux Kernel documentation (PREEMPT_RT)](https://cdn.kernel.org/doc/html/latest/core-api/real-time/theory.html)
6. [Towards Deterministic Sub-0.5 us Response on Linux through Interrupt Isolation, arXiv:2509.03855](https://arxiv.org/abs/2509.03855)
7. [Beginner guide on interrupt latency and Arm Cortex-M processors, Arm Community](https://community.arm.com/processors/b/blog/posts/beginner-guide-on-interrupt-latency-and-interrupt-latency-of-the-arm-cortex-m-processors)
8. [Real Time: Some Notes on Microcontroller Interrupt Latency, DigiKey](https://www.digikey.com/en/articles/real-time-some-notes-on-microcontroller-interrupt-latency)
9. [ARM Cortex-M3 Processor Technical Reference Manual, Arm](https://documentation-service.arm.com/static/5f2286f2f3ce30357bc28b2a?token=)
10. [Enhanced platform-based interrupt controller for RISC-V MCUs, Microelectronics Journal, Volume 159, May 2025](https://www.sciencedirect.com/science/article/pii/S1879239125000773)
11. [Interrupt Latency Accurate Measurement in Multiprocessing Embedded Systems by Means of a Dedicated Circuit, Electronics 2024, 13(9), 1626](https://www.mdpi.com/2079-9292/13/9/1626)
12. [Quantifying the Latency and Possible Throughput of External Interrupts on Cyber-Physical Systems, arXiv:2009.00506](https://arxiv.org/abs/2009.00506)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Embedded & soft processors › Embedded systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/interrupt-latency

English original: https://www.edgepedia.org/interrupt-latency
