# 锁步（计算）

锁步是一种同步方法，处理器或仿真组件以协调一致的步调共同推进，而非各自独立运行。该术语涵盖两种不同的实践。在硬件中，锁步系统是指两个处理器基于同一时钟同时执行相同的指令，其中一个更新内存和I/O，另一个则检查是否存在不一致。<sup>[1](https://docs.amd.com/api/khub/documents/2ltSPVPc3fSsubW6xw9ecA/content)</sup> 在并行离散事件仿真中，锁步意味着仿真组件通过全局时间步或屏障推进：每一轮计算哪些事件可以安全处理，处理这些事件，交换消息，并在下一轮之前进行同步。<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup> 因此，被同步的对象各不相同：硬件中是指令和时钟周期，仿真中则是仿真时间步。

| 关键事实 | 值 |
|---|---|
| 硬件锁步定义 | 两个处理器基于同一时钟同时执行相同指令<sup>[1](https://docs.amd.com/api/khub/documents/2ltSPVPc3fSsubW6xw9ecA/content)</sup> |
| DCLS资源开销 | 处理器资源翻倍，以换取近乎即时的错误检测<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> |
| 仿真锁步下界 | \( \mathrm{LBTS} = \min(N_{i} + \mathrm{LA}_{i}) \)，即每个进程的下一个事件时间加上其前瞻量；时间戳 \( \le \mathrm{LBTS} \) 的事件是安全的<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup> |
| GPU线程束大小 | 子组（CUDA中的线程束）通常包含16–128个线程，具体取决于架构<sup>[4](https://arbersephirotheca.github.io/files/PLDI-simt-step.pdf)</sup> |
| VDCLS性能开销 | Dhrystone 1.24 对比 1.38 DMIPS/Hz；约4%的额外FPGA资源占用<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> |
| FMI协同仿真步 | 时间通过fmi3DoStep以currentCommunicationPoint和communicationStepSize协商的步长推进<sup>[5](https://fmi-standard.org/docs/3.0.2/)</sup> |

## 工作原理

在并行离散事件仿真中，每个逻辑进程（LP）持有一个本地时钟和一个带时间戳的事件队列。同步的目标是确保每个LP按时间戳顺序处理事件；如果每个LP都这样做，就不会发生因果错误，这一条件称为局部因果约束。<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup><sup> • </sup><sup>[6](https://api.drum.lib.umd.edu/server/api/core/bitstreams/29292ec1-2127-4185-b310-3da953b26a67/content)</sup> 保守式锁步方案通过等待来满足该约束：任何保守式协议的主要任务是确定何时“安全”地处理事件，即不会再有更小时间戳的事件到达。<sup>[7](https://www.cs.auckland.ac.nz/courses/compsci703s1c/archive/2008/resources/mano/Fujimoto-Simulation.pdf)</sup>

安全性通过未来到达事件的下界来确立。每一轮计算时间戳下界（LBTS），\( \mathrm{LBTS} = \min(N_{i} + \mathrm{LA}_{i}) \)，其中 \( N_{i} \) 是进程i的下一个事件时间，\( \mathrm{LA}_{i} \) 是其前瞻量，即进程可以预测其未来消息时间的量。<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup> 时间戳等于或低于LBTS的事件是安全的。乐观式方案则允许违规并恢复：时间扭曲（Time Warp）由大卫·R·杰斐逊（David R. Jefferson）于1985年提出，它检测乱序执行，并利用保存的状态和反消息（anti-messages）进行回滚，反消息会消灭其匹配的正消息。<sup>[8](https://doi.org/10.1145/3916.3988)</sup><sup> • </sup><sup>[7](https://www.cs.auckland.ac.nz/courses/compsci703s1c/archive/2008/resources/mano/Fujimoto-Simulation.pdf)</sup> 保守式和乐观式同步仍然是并行离散事件仿真算法的两大类别。<sup>[9](https://www.cs.cmu.edu/~bryant/pubdir/wsc17.pdf)</sup>

在硬件中，其机制是复制而非屏障。两个相同的核心以时间错位执行相同的指令流，因此它们在任意时刻的内部电气状态是不同的。<sup>[10](https://export.arxiv.org/pdf/2307.15436v1.pdf)</sup>

## 实现方式

保守式仿真循环依次执行以下步骤<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup>：

1. 计算每个LP之后可能收到的LBTS。
2. 处理时间戳 \( \le \mathrm{LBTS} \) 的事件，这些事件是安全的。
3. 交换消息（或空消息，空消息承诺之后不会发送更小时间戳的消息；只要时间戳增量非零，空消息算法就能避免死锁）。<sup>[11](https://cs.rpi.edu/~chrisc/rc-web/node4.html)</sup>
4. 屏障同步并重复。

保守式时间窗口的变体通过在两个屏障同步阶段——窗口识别和事件处理——上锁步迭代。<sup>[6](https://api.drum.lib.umd.edu/server/api/core/bitstreams/29292ec1-2127-4185-b310-3da953b26a67/content)</sup>

硬件锁步在同一时钟下运行两个相同的处理器，二者之间存在时间延迟。微芯（Microchip）的RT PolarFire使用0.5到2个时钟周期的延迟，厂商称这适合检测大多数常见错误，比较器逐周期标记差异。<sup>[12](https://ww1.microchip.com/downloads/aemDocuments/documents/FPGA/ApplicationNotes/ApplicationNotes/Microchip_RT_PolarFire_FPGA_Lockstep_Processor_AN4228.pdf)</sup> 延迟不必恒定：在VDCLS的示例执行轨迹中，从核保持在主核之后三到七个时钟周期。<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> 在功能样机接口（FMI）下的协同仿真中，导入器的算法以currentCommunicationPoint和communicationStepSize调用fmi3DoStep，因此所有仿真单元通过协商的通信点以锁步方式推进。<sup>[5](https://fmi-standard.org/docs/3.0.2/)</sup><sup> • </sup><sup>[13](https://clagms.github.io/assets/pdfs/Hansen2022.pdf)</sup>

## 起源

保守式同步涉及同步问题及其最早的算法。<sup>[9](https://www.cs.cmu.edu/~bryant/pubdir/wsc17.pdf)</sup><sup> • </sup><sup>[7](https://www.cs.auckland.ac.nz/courses/compsci703s1c/archive/2008/resources/mano/Fujimoto-Simulation.pdf)</sup> 钱迪（Chandy）和米斯拉（Misra）在1981年《ACM通讯》的论文中报告了一种方案：允许多处理器网络死锁，使用对迪杰斯特拉-斯科尔滕（Dijkstra-Scholten）终止检测方案的修改以分布式方式检测死锁，然后打破死锁；该方案需要有限内存，不超过顺序仿真所需，且不需要全局时钟，因为每个进程维护自己的本地时钟。<sup>[14](https://doi.org/10.1145/358598.358613)</sup> 时间扭曲开创了乐观式同步<sup>[9](https://www.cs.cmu.edu/~bryant/pubdir/wsc17.pdf)</sup>，杰斐逊的"虚拟时间"于1985年发表在《ACM编程语言与系统汇刊》上。<sup>[8](https://doi.org/10.1145/3916.3988)</sup> 后来的窗口化工作包括大卫·M·尼科尔（David M. Nicol）的YAWNS全局窗口方法<sup>[15](https://doi.org/10.1145/151261.151266)</sup>、杰夫·S·斯坦曼（Jeff S. Steinman）的呼吸时间扭曲（Breathing Time Warp）<sup>[16](https://doi.org/10.1145/174134.158473)</sup>，以及尼科尔和刘（Liu）的复合同步。<sup>[17](https://doi.org/10.1109/tpds.2002.1003854)</sup>

## 变体

**双核锁步（DCLS）** 将两个核心耦合，使得在用户层面只有一个可见，而两者以时间错位执行相同的指令流；它一般在硬件层面实现。<sup>[10](https://export.arxiv.org/pdf/2307.15436v1.pdf)</sup> **三核锁步（TCLS）** 增加第三个核心并进行多数表决，能够立即恢复状态，但资源开销很大。<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> **可变延迟双核锁步（VDCLS）** 允许核心间延迟变化，在约4%额外FPGA资源占用下，将[Dhrystone](https://www.edgepedia.org/zh/dhrystone)性能从1.38降至1.24 DMIPS/Hz，CoreMark从2.10降至2.04 CoreMark/MHz。<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> **基于软件的锁步** 在双核ARM上配合硬件观察器，在质子辐照和故障注入下，即使最坏情况下也将基准测试截面提高了一个数量级。<sup>[18](https://ieeexplore.ieee.org/document/9706422)</sup> **FlexStep** 通过可配置互连在任何核心上复制用户线程，支持一对一（类DCLS）或一对二（类TCLS）验证，而非静态绑定相同的核心。<sup>[19](http://www.arxiv.org/pdf/2503.13848)</sup>

在GPU上，早期规范以锁步方式描述子组执行，所有汇聚的线程逐条指令共同推进；锁步仍然是开发者常见的心智模型，但规范已不再采用这一模型。<sup>[4](https://arbersephirotheca.github.io/files/PLDI-simt-step.pdf)</sup> 在FMI协同仿真中，编排器寻找使协同仿真误差最小化的通信点，同时确保所有仿真单元以锁步方式推进。<sup>[13](https://clagms.github.io/assets/pdfs/Hansen2022.pdf)</sup>

## 应用

硬件锁步用于安全关键和安全相关的硬件。<sup>[20](https://www.chipsalliance.org/news/implementing-dual-core-lockstep-in-the-veer-el2-risc-v-core/)</sup> 赛灵思（Xilinx）Zynq-7000中的锁步双核[ARM Cortex-A9](https://www.edgepedia.org/zh/arm-cortex-a9)在实验中缓解了约91%的软错误<sup>[21](https://link.springer.com/chapter/10.1007/978-3-319-56258-2_17)</sup>，CHIPS联盟将DCLS应用于开源VeeR EL2 RISC-V核心，在那里它还保护Caliptra等信任根宏，防止攻击者在获得芯片物理访问权限时进行侧信道攻击和错误注入。<sup>[20](https://www.chipsalliance.org/news/implementing-dual-core-lockstep-in-the-veer-el2-risc-v-core/)</sup> 由200多种工具支持的FMI协同仿真使用协商的通信点作为其锁步机制。<sup>[5](https://fmi-standard.org/docs/3.0.2/)</sup>

## 局限与替代方案

**硬件成本。** DCLS使处理器资源翻倍。<sup>[3](https://www.mdpi.com/2079-9292/12/2/464)</sup> 灵活方案的量化开销较小：FlexStep在AMD Alveo U280 FPGA上报告了1.07%的减速、2.21%的面积开销和2.89%的功耗，检测延迟为微秒级。<sup>[19](http://www.arxiv.org/pdf/2503.13848)</sup>

**仿真成本。** 保守式协议受前瞻量的极大限制，一个经典结果表明保守式仿真的速度受事件关键链长度的限制。<sup>[22](https://www.eurosis.org/conf/isc/isc2003/tutorial.pdf)</sup> 不允许零前瞻量循环，保守式系统无法充分利用可用并行性，因为它们必须防范最坏情况；乐观式系统则需支付状态保存开销，可能严重降低性能，且可能发生回滚抖动。<sup>[2](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)</sup> 从理论上的性能比较来看，利普顿（Lipton）和米泽尔（Mizell）表明时间扭曲可以以任意倍数优于钱迪/米斯拉算法，而空消息算法只能以常数倍数优于时间扭曲。<sup>[11](https://cs.rpi.edu/~chrisc/rc-web/node4.html)</sup>

**故障模式。** 死锁是经典的保守式故障：钱迪-米斯拉1981年方案故意允许死锁，检测并打破它。<sup>[14](https://doi.org/10.1145/358598.358613)</sup> 在FMI协同仿真中，仿真单元的语义违规会导致UPPAAL验证模型中的死锁<sup>[13](https://clagms.github.io/assets/pdfs/Hansen2022.pdf)</sup>，确定性锁步协同仿真要求FMU无记忆或实现回滚（fmiGetFMUstate/fmiSetFMUstate）或步长预测，最多允许一个缺乏这些能力的"遗留"FMU。<sup>[23](https://apps.dtic.mil/sti/pdfs/ADA587399.pdf)</sup> 非确定性是另一个隐患：由于FMI函数可能不是线程安全的，必须正确处理互斥，因为竞态条件会破坏协同仿真的可重复性。<sup>[24](https://ogst.ifpenergiesnouvelles.fr/articles/ogst/full_html/2019/01/ogst180065/ogst180065.html)</sup>

**弥合两种范式。** 保守式仿真器需要前瞻量但不需要回滚；乐观式仿真器需要回滚但不需要前瞻量，二者常被视为不兼容。统一虚拟时间（UVT）在前瞻量可用时（\( \mathrm{GVT} \le \mathrm{LVT} < \mathrm{CVT} \)）以保守方式执行事件，否则（\( \mathrm{CVT} \le \mathrm{LVT} \)）以乐观方式执行，将保守式执行视为本质上采用乐观式机制的引擎之上的加速器。<sup>[25](https://www.informs-sim.org/wsc17papers/includes/files/058.pdf)</sup>

## References

1. [AMD/Xilinx documentation on processor lockstep](https://docs.amd.com/api/khub/documents/2ltSPVPc3fSsubW6xw9ecA/content)
2. [Parallele Simulation (lecture notes, Chapter 6: Parallel Simulation, TU München)](https://www.net.in.tum.de/pub/simulationstechnik/ws20112012/skript/ST_WS20112012_Ch6_ParallelSim.pdf)
3. [Variable Delayed Dual-Core Lockstep (VDCLS) Processor for Safety and Security Applications](https://www.mdpi.com/2079-9292/12/2/464)
4. [SIMT-Step Execution: A Flexible Operational Semantics for GPU Subgroup Behavior (PLDI)](https://arbersephirotheca.github.io/files/PLDI-simt-step.pdf)
5. [Functional Mock-up Interface Specification 3.0.2](https://fmi-standard.org/docs/3.0.2/)
6. [Parallel and distributed simulation of discrete event systems (survey, University of Maryland repository)](https://api.drum.lib.umd.edu/server/api/core/bitstreams/29292ec1-2127-4185-b310-3da953b26a67/content)
7. [Parallel and Distributed Simulation Systems (Fujimoto, tutorial/Winter Simulation Conference paper)](https://www.cs.auckland.ac.nz/courses/compsci703s1c/archive/2008/resources/mano/Fujimoto-Simulation.pdf)
8. [David R. Jefferson (1985). Virtual time. ACM Transactions on Programming Languages and Systems.](https://doi.org/10.1145/3916.3988)
9. [Perspectives on the Origin and Evolution of Parallel Discrete Event Simulation (Winter Simulation Conference 2017)](https://www.cs.cmu.edu/~bryant/pubdir/wsc17.pdf)
10. [SafEDE (arXiv 2307.15436, 2023; also circulated as a university-repository copy)](https://export.arxiv.org/pdf/2307.15436v1.pdf)
11. [Parallel Simulation Technologies (Carothers, RPI course notes)](https://cs.rpi.edu/~chrisc/rc-web/node4.html)
12. [RT PolarFire Lockstep Processor Application Note (AN4228, Microchip)](https://ww1.microchip.com/downloads/aemDocuments/documents/FPGA/ApplicationNotes/ApplicationNotes/Microchip_RT_PolarFire_FPGA_Lockstep_Processor_AN4228.pdf)
13. [Verification and synthesis of co-simulation algorithms subject to algebraic loops and adaptive steps (Hansen 2022, author-hosted copy)](https://clagms.github.io/assets/pdfs/Hansen2022.pdf)
14. [K. M. Chandy, J. Misra (1981). Asynchronous distributed simulation via a sequence of parallel computations. Communications of the ACM.](https://doi.org/10.1145/358598.358613)
15. [David M. Nicol (1993). The cost of conservative synchronization in parallel discrete event simulations. Journal of the ACM.](https://doi.org/10.1145/151261.151266)
16. [Jeff S. Steinman (1993). Breathing Time Warp. ACM SIGSIM Simulation Digest.](https://doi.org/10.1145/174134.158473)
17. [D.M. Nicol, J. Liu (2002). Composite synchronization in parallel discrete-event simulation. IEEE Transactions on Parallel and Distributed Systems.](https://doi.org/10.1109/tpds.2002.1003854)
18. [Dual-core lockstep hybrid approach with software-based lockstep and hardware observer on ARM](https://ieeexplore.ieee.org/document/9706422)
19. [FlexStep (arXiv preprint, 2025)](http://www.arxiv.org/pdf/2503.13848)
20. [Dual-core Lockstep in the VeeR EL2 RISC-V core for safety-critical applications and side-channel access mitigation in Caliptra RoT | CHIPS Alliance](https://www.chipsalliance.org/news/implementing-dual-core-lockstep-in-the-veer-el2-risc-v-core/)
21. [Exploring Performance Overhead Versus Soft Error Detection in Lockstep Dual-Core ARM Cortex-A9 Processor Embedded into Xilinx Zynq APSoC](https://link.springer.com/chapter/10.1007/978-3-319-56258-2_17)
22. [Tutorial: Lookahead, Rollback and Lookback, Quest for Parallelism in Discrete Event Simulation (Szymanski & Chen, ISC 2003)](https://www.eurosis.org/conf/isc/isc2003/tutorial.pdf)
23. [Determinate composition of FMUs for co-simulation (Broman et al., EMSOFT 2013; DTIC copy)](https://apps.dtic.mil/sti/pdfs/ADA587399.pdf)
24. [A method for parallel scheduling of multi-rate co-simulation on multi-core platforms (Oil & Gas Science and Technology, 2019)](https://ogst.ifpenergiesnouvelles.fr/articles/ogst/full_html/2019/01/ogst180065/ogst180065.html)
25. [Virtual Time III: Unification of Conservative and Optimistic Synchronization in Parallel Discrete Event Simulation (Winter Simulation Conference 2017)](https://www.informs-sim.org/wsc17papers/includes/files/058.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Algorithms and computational methods

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/lockstep-computing

English original: https://www.edgepedia.org/lockstep-computing
