PretVM: Predictable, Efficient Virtual Machine for Real-Time Concurrency

Shaokai Lin, Erling Rennemo Jellum, Mirco Theile, Tassilo Tanneberger, Binqi Sun, Chadlia Jerad, Ruomu Xu, Guangyu Feng, Christian Menard, Marten Lohstroh, Jerónimo Castrillón, Sanjit A. Seshia, Edward A. LeearXiv 2024 · DOI

In the domain of Cyber-Physical Systems (CPS)—such as autonomous vehicles and industrial robotics—timing is a fundamental correctness requirement rather than a mere performance metric. Traditionally, developers have relied on "bottom-up" approaches: implementing code, measuring execution timing, and iteratively adjusting schedulers. This process often results in brittle, platform-specific software that is difficult to verify.

PretVM (Precision-Timed Virtual Machine) offers a "top-down" alternative. By introducing a virtual machine layer specifically designed for real-time concurrency, PretVM enables the execution of programs with mathematically provable timing bounds without sacrificing the high-level coordination benefits of languages like Lingua Franca (LF).

The Challenge: Entangled Timing and Logic

A primary obstacle in real-time software is the "entanglement" of concerns. Reactivity (how a system responds to its environment) is frequently buried within the same code as functionality (the control laws). While the Lingua Franca coordination language helps separate these concerns, its default runtime is dynamic. Dynamic schedulers make on-the-fly decisions that introduce non-deterministic overhead and jitter. On multi-core systems, this makes it nearly impossible to guarantee that a system will consistently meet its deadlines. PretVM bridges the gap between high-level "logical time" and the "physical time" of the hardware by utilizing static analysis to pre-plan execution.

Methodology: The PretVM Toolchain

The researchers developed a toolchain that transforms LF programs into a predictable execution format.

The Lingua Franca Compiler toolchain for PretVM.

The compilation process involves several critical stages:

  1. State Space Exploration: The LF program's logic is unrolled into State Space Diagrams (SSDs). These diagrams capture the distinct phases of execution, including initialization, the periodic steady-state, and shutdown.
  2. DAG Generation: These SSDs are converted into Directed Acyclic Graphs (DAGs), where nodes represent individual "reactions" (tasks) and edges represent dependencies or timing constraints.
  3. Quasi-Static Scheduling: Instead of scheduling at runtime, offline algorithms (such as Load Balancing or Edge Generation) partition these DAGs across multiple CPU cores.
  4. PretVM Bytecode: The final schedule is compiled into a custom, RISC-V-inspired bytecode. This instruction set treats time as a first-class citizen with commands like DU (Delay Until) to pause execution until a specific physical time and ADV to advance a reactor's logical clock.
  5. The Runtime: A lightweight interpreter executes this bytecode, maintaining a clean separation between coordination logic and application-specific C code.
State Space Diagram (SSD) illustrating phased execution.

Key Insights and Results

A central insight of the PretVM approach is that most real-time systems operate in distinct phases. By treating initialization and shutdown as separate phases with their own static schedules, PretVM handles complex lifecycles while maintaining predictability. Furthermore, by eliminating the "global barrier" found in dynamic schedulers—where all tasks must wait for a global synchronization point—PretVM allows reactors to advance their logical time independently as long as dependencies are met.

The authors evaluated PretVM using eight real-time benchmarks on a Raspberry Pi 4. The experiments measured "Lag"—the difference between a task's logical scheduled start and its actual physical start.

  • Massive Jitter Reduction: In the LongShort benchmark, the dynamic scheduler suffered from an average lag of 1.49 milliseconds. PretVM reduced this to just 3.11 microseconds—a nearly 500x improvement.
  • Deterministic Execution: PretVM delivered "time-accurate" execution, where physical execution closely tracked the logical timeline defined in the code, even on a standard Linux OS.

Limitations and Future Work

While promising, the current version of PretVM does not support dynamic LF features like physical actions or nested reactors, which are more difficult to schedule statically. Additionally, the system relies on accurate Worst-Case Execution Time (WCET) estimates for the C code within reactions. Future work will focus on automating these manual steps and integrating sophisticated WCET analysis tools directly into the compiler.

Summary updated

BibTeX
@misc{lin2024pretvm,
  author = {Shaokai Lin and Erling Rennemo Jellum and Mirco Theile and Tassilo Tanneberger and Binqi Sun and Chadlia Jerad and Ruomu Xu and Guangyu Feng and Christian Menard and Marten Lohstroh and Jerónimo Castrillón and Sanjit A. Seshia and Edward A. Lee},
  title = {{PretVM: Predictable, Efficient Virtual Machine for Real-Time Concurrency}},
  year = {2024},
  eprint = {2406.06253},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.06253},
}
Figure