Skip to content

Feature: Add Support for Real-Time Scheduling (SCHED_FIFO) #76

@dustinblack

Description

@dustinblack

To produce stable and reliable benchmark results, it is crucial to minimize environmental interference,
particularly from the operating system scheduler. Standard Linux schedulers (like CFS) are designed for
fairness, not for minimizing the latency of a specific application. This can introduce jitter and variability
into our measurements.

Our design should use the SCHED_FIFO real-time scheduling policy to grant the
benchmark processes priority over most other tasks on the system. To ensure we
can run tests in a similarly controlled environment, rusty-comms must support this capability.

Proposed Solution

A new command-line argument should be introduced to enable and configure real-time scheduling for the benchmark
processes.

  1. New Command-Line Argument:

    • Add an optional flag, for example: --sched-fifo <priority>.
    • The <priority> value should be an integer between 1 (lowest) and 99 (highest) for SCHED_FIFO.
  2. Implementation:

    • When this flag is provided, the application will use the sched_setscheduler function from the nix crate to
      change the scheduling policy for both the parent (sender) and child (receiver) processes.
    • This call should be made in both processes immediately after the fork().
  3. Error Handling:

    • Setting a real-time scheduling policy often requires elevated privileges (e.g., CAP_SYS_NICE or running as
      root).
    • If the sched_setscheduler call fails (e.g., due to a permissions error), the application should not
      terminate. Instead, it should log a clear and informative WARN message to the user, explaining that the
      policy could not be set and that the benchmark will continue with the default scheduler.

Acceptance Criteria

  • A new optional command-line argument, --sched-fifo <priority>, is added.
  • If the flag is used, sched_setscheduler is called for both the parent and child processes with the
    specified priority.
  • If setting the scheduler policy fails, a descriptive warning is logged, and the benchmark continues
    execution.
  • The benchmark runs correctly both with and without the new flag enabled.
  • The help text for the new argument clearly explains its purpose and the typical need for elevated
    privileges.

Context

This is a high-priority task (P1) for ensuring the environmental comparability of our benchmark results.

This task is dependent on the completion of the multi-process refactoring (Issue #74). The
logic must be applied to the separate parent and child processes created by that task.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Priority 1 (important or urgent)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions