Formal Simulation and Analysis of the CASH Scheduling Algorithm in Real-Time Maude

Peter Csaba Ölveczky, Marco Caccamo

Abstract

The CASH (Capacity SHaring) algorithm is a sophisticated real-time scheduling mechanism designed to maximize CPU utilization by reclaiming unused execution time. However, its implementation involves an unbounded queue of spare capacities, making it difficult to verify using traditional finite-state formal methods. This study utilizes Real-Time Maude, a tool based on rewriting logic, to formally model and analyze the CASH algorithm. Our analysis demonstrates that a seemingly intuitive optimization to the algorithm actually introduces subtle deadline misses. Notably, while extensive Monte Carlo simulations failed to identify these failures, Real-Time Maude’s exhaustive reachability analysis successfully uncovered them, highlighting the critical role of formal methods in safety-critical system design.

Introduction

In the domain of real-time computing, tasks are often scheduled based on their Worst-Case Execution Time (WCET) to guarantee that deadlines are met under all circumstances. In practice, however, tasks frequently complete their execution much earlier than the WCET predicts. This discrepancy leads to "slack time"—idle CPU cycles that could be used to improve the performance of other tasks, particularly those with "soft" real-time requirements.

The CASH algorithm addresses this by maintaining a queue of "spare capacities" or "budgets" reclaimed from tasks that finish early. These budgets can then be assigned to other tasks. A significant hurdle in verifying the correctness of CASH is that the number of entries in this spare capacity queue is theoretically unbounded. Traditional verification tools like Uppaal or Kronos, which rely on finite-state automata, struggle with such "infinite-control" systems.

Modeling with Real-Time Maude

To overcome the limitations of finite-state tools, the researchers employed Real-Time Maude. Maude is a high-performance language and toolset based on rewriting logic, which allows for the specification of systems using algebraic data types and rewrite rules. This flexibility makes it uniquely suited for modeling unbounded structures like the CASH queue.

The system was modeled using an object-oriented approach:

  • Objects: Servers and the CASH queue were represented as objects with specific attributes, such as maxBudget, timeToDeadline, and usedBudget.
  • Rewrite Rules: These rules defined the transitions between states, such as job arrivals, execution steps, and the reclamation of unused time.
  • Timed Fair Rewriting: This allowed for the simulation of "fair" execution paths to prototype and observe the system's basic behavior.

Verification Methodology

The study utilized several analytical techniques provided by the Maude environment:

  1. Monte Carlo Simulation: A pseudo-random function was used to generate realistic job arrival patterns and execution times. This served as a baseline for traditional randomized testing.
  2. Reachability Analysis (Search): The tool exhaustively searched all possible states within a defined time bound to identify if a DEADLINE-MISS state was reachable.
  3. LTL Model Checking: Linear Temporal Logic (LTL) was used to verify if specific properties—such as the perpetual absence of deadline misses—held true across all possible execution paths.

The "Optimization" and the Discovery of Flaws

A key contribution of this research was the analysis of a proposed modification to the CASH algorithm. The modification suggested that when the CPU is idle, it should consume the spare budget with the latest deadline first, preserving budgets with earlier deadlines for future use. While this optimization appeared intuitive and efficient, formal analysis proved otherwise.

The researchers tested two main configurations: init2 (a two-server system) and init5 (a three-server system). The results were striking:

  • Monte Carlo Failure: Traditional randomized simulations were run for millions of time units. Despite the intensity of this testing, no deadline misses were detected.
  • Maude Success: Using exhaustive search, Real-Time Maude identified a deadline miss in the two-server system within a time bound of 12. The bug was found in just 50 seconds after exploring 151,000 distinct states. In the three-server system, the bug was found within a time bound of 9.

This discrepancy underscores a fundamental truth in system verification: randomized testing is often insufficient for finding "corner case" bugs in complex, concurrent systems.

Validation of the Original Algorithm

To ensure the validity of the modeling approach, the researchers also analyzed the original, unmodified CASH algorithm. After several hours of exhaustive searching, no deadline misses were found. This provides strong empirical evidence for the correctness of the original algorithm, which had previously been established through mathematical proofs.

Conclusion and Future Work

The application of Real-Time Maude to the CASH algorithm demonstrates the power of rewriting logic in handling complex, unbounded real-time systems. The discovery of a flaw in a proposed optimization—one that escaped millions of cycles of conventional testing—highlights the necessity of formal reachability analysis in safety-critical contexts.

While this study successfully identified specific bugs, it was limited to specific initial configurations. Future work could involve the use of interactive theorem provers to provide a universal proof of correctness for all possible starting states. Additionally, there is a burgeoning need to develop formal methods that can evaluate not just the safety of scheduling algorithms, but also their performance and efficiency.

Summary updated

Abstract

This paper describes the application of the Real-Time Maude tool to the formal specification and analysis of the CASH scheduling algorithm and its suggested modifications. The CASH algorithm is a sophisticated state-of-the-art scheduling algorithm with advanced capacity sharing features for reusing unused execution budgets. Because the number of elements in the queue of unused resources can grow beyond any bound, the CASH algorithm poses challenges to its formal specification and analysis. Real-Time Maude extends the rewriting logic tool Maude to support formal specification and analysis of object-based real-time systems. It emphasizes generality of specification and supports a spectrum of analysis methods, including symbolic simulation and (unbounded and time-bounded) reachability analysis and LTL model checking. We show how we have used Real-Time Maude to experiment with different design modifications of the CASH algorithm using both Monte Carlo simulation and reachability analysis. We could quickly and easily specify and analyze these modifications using Real-Time Maude, and discovered subtle behaviors in the modifications that lead to missed deadlines.
BibTeX
@inproceedings{olveczky2006formal,
  author = {Peter Csaba Ölveczky and Marco Caccamo},
  title = {{Formal Simulation and Analysis of the CASH Scheduling Algorithm in Real-Time Maude}},
  booktitle = {FASE},
  year = {2006},
  doi = {10.1007/11693017\_26},
}
Figure