Deterministic Real-time Thread Scheduling

Heechul Yun, Cheolgi Kim, Lui ShaarXiv 2011

Abstract

Non-deterministic thread interleaving in multithreaded real-time systems often leads to elusive "heisenbugs" like race conditions. This paper introduces a deterministic scheduling method that utilizes Worst Case Executable Instructions (WCEI) to ensure repeatable software behavior. By combining traditional timer interrupts with hardware instruction counters, the proposed scheduler eliminates timing variability without sacrificing real-time deadlines.

Introduction

In critical real-time domains such as aerospace and medical devices, software reliability is paramount. However, modern hardware features like caches and out-of-order execution introduce timing variability, making thread scheduling non-deterministic. A bug might manifest once in thousands of hours and disappear during debugging—a phenomenon known as "No Fault Found" (NFF). This research addresses the challenge of providing deterministic execution in real-time environments where timing guarantees are non-negotiable.

The WCEI Scheduling Approach

The core of the proposed solution is the Worst-Case Executable Instructions (WCEI) function. The scheduler uses two types of interrupts: timer interrupts to track absolute wall-clock time and instruction count interrupts to trigger scheduling events at specific code locations.

When a task is allocated a time slice $t$, the scheduler calculates $I$, the number of instructions guaranteed to complete within $t$ using the formula $WCEI = at - b$ (where $a$ is execution speed and $b$ is the cache cold-miss penalty). The task executes exactly $I$ instructions and then voluntarily idles until the next real-time tick. This mechanism ensures that context switches occur at identical instruction points across every execution run.

Figure 3: Timing diagram illustrating the deterministic scheduling mechanism, including WCEI calculation and task preemption.

Multi-Phase Modeling for Efficiency

A significant hurdle for deterministic scheduling is the potential for high CPU utilization loss due to pessimistic instruction estimates. To optimize performance, the researchers developed Multi-Phase WCEI. This approach recognizes that different program segments—such as initialization versus heavy computation—exhibit different instruction-per-cycle (IPC) rates.

Figure 6: Multi-phase WCEI modeling for SPEC2000GZIP, demonstrating how phase-specific slopes track instruction retirement more accurately than a single global function.

By partitioning programs into phases and applying tailored WCEI functions, the system drastically improves efficiency. In evaluations using the SPEC2000GZIP benchmark, the multi-phase approach reduced worst-case utilization loss from approximately 62% to less than 3%.

Experimental Results

The researchers evaluated their prototype on a Linux 2.6.36 kernel using Intel Core2Duo hardware performance counters. Key findings include:

  • Reproducibility: The deterministic scheduler successfully converted a non-deterministic race condition in the Paparazzi UAV (Unmanned Aerial Vehicle) software into a repeatable event, simplifying the debugging process.
  • Utilization: The multi-phase optimization proved vital for practical use, maintaining high performance while guaranteeing determinism.
  • Scalability: While currently focused on uniprocessor systems, the results provide a foundation for deterministic execution in more complex environments.

Conclusion

This paper demonstrates that determinism and real-time performance are not mutually exclusive. By anchoring scheduling to instruction counts via WCEI, developers can eliminate race conditions and ensure that critical systems behave predictably. Future work will explore extending these concepts to multi-core architectures and automating the identification of program phases.

Summary updated

BibTeX
@misc{yun2011deterministic,
  author = {Heechul Yun and Cheolgi Kim and Lui Sha},
  title = {{Deterministic Real-time Thread Scheduling}},
  year = {2011},
  eprint = {1104.2110},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1104.2110},
}
Figure