Skip to content

refactor(runtime)!: run timed slots from SimulationState with a differential scheduler harness - #1756

Merged
mergify[bot] merged 2 commits into
masterfrom
feature/compiled-scheduler-3b2
Oct 22, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feature/compiled-scheduler-3b2

Conversation

@tignear

@tignear tignear commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-1 (compiled scheduler), PR 2 of 7. This prepares the runtime for a compiled time-slot loop. Behaviour is unchanged: every mode still runs the reference loop.

BREAKING CHANGE

  • SimulatorOptions (public, exhaustive) has a new field, scheduler (#[doc(hidden)]).
  • celox_design::ProcessSlots has a new field, const_delays.
  • celox_frontend_core::process::ProcessKernelBuilder::delay and inactive_delay take a second argument, the amount's value when the frontend knows it (Option<u64>).
  • Native images use container format 28; images written by earlier versions are rejected and must be rebuilt.

Run loop in SimulationState

SimulationState::run_until now holds the loop Simulation::run_until ran (step every time with work up to the target, stop at $stop or $finish, then advance to the target). Simulation::run_until delegates to it and keeps the VCD dump at the target. step_until stays the one-step API. Both have _observed variants that show every step to a StepObserver; the plain versions pass (), whose empty hooks cost nothing. In PR 3 the free-running loop is where a compiled scheduler takes over runs of slots, and Differential mode checks exactly that loop through the observer.

Scheduler mode and stats (hidden)

  • SchedulerMode::{Reference, Compiled, Differential}, selected with the #[doc(hidden)] builder option Simulation::builder(..).scheduler_mode(..). Library code reads no environment variable. The default is Reference; PR 3 makes Compiled the default with the compiled loop.
  • Simulation::scheduler_stats() (#[doc(hidden)]) reports the mode, the compiled slots (always 0 here), the steps checked against a shadow, and how each kernel is scheduled. Today every kernel reports "the design has no compiled scheduler".

Differential harness

SchedulerMode::Differential compiles the design a second time into a shadow Simulation that runs Reference. The primary runs the same SimulationState::run_until/step_until as every other mode, with the shadow check as its StepObserver; there is no separate checked loop.

  • Before every step, the shadow takes the primary's design state (the memory image after the state header, and the heap), scheduling state, undrained runtime events, and the host-side flags design code observes. Host calls between steps (writes, add_clock, schedule, load_state, raw memory writes) therefore need no mirroring. Pending events are remapped by id to the shadow's own handles, so the shadow runs its own compiled code (a native test checks the handles' function pointers).
  • After every step, the step result (time or error message), a canonical form of the scheduling state (SimulationState::schedule_key: events by id, wakeups and waiters in order, ready/inactive sets, NBA queue, counters, flags), the state bytes, the string heap (Heap::same_contents) and the pending runtime events must match. A mismatch fails the step with the step's start time and the first difference, e.g. state byte 1234 (top.count).
  • In a slot suspended at $stop the scheduling state cannot be copied: the shadow takes the design state, host flags and the pending host-write flag, and continues the slot in lockstep. A test runs $stop, a host write, then run_until in Differential mode.
  • No shadow is built for designs whose host state lives outside the memory image (SV file I/O, VCD control tasks, external components), the same designs that cannot be checkpointed. scheduler_stats().unchecked gives the reason, and the SV suite harness reports each such case (differential: unchecked: ...); every other timed case must have checked_steps > 0 or fails.

The SV suite harness maps CELOX_SCHEDULER=reference|compiled|differential to the builder option (the scoped clippy::disallowed_methods allow follows celox-vpi/tests/cocotb_e2e.rs). Unit tests show that the harness passes a run with a host write between run_until calls, and reports a shadow that diverges (one that sees other plusargs).

Constant delays as kernel metadata

ProcessKernelBuilder::delay/inactive_delay take the amount's value when the frontend knows it, and the builder records in ProcessSlots::const_delays whether every delay of the kernel is a constant of at least one time unit. The SV frontend records integral constants (literals, parameters, after time-unit scaling, without overflow); real and negative delays count as variable. The SDK lowering records two-state constant expressions. The emitted SIR is unchanged. ProcessSlots is part of the native image, so the image container version moves from 27 to 28 (one above master; #1720 also changed the image schema at 27).

Moved to PR 3: SchedulerSchema and the handoff functions. They land with their first user instead of as dead code here.

Perf

Callgrind, whole program, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 5. Base and branch built from the same base (8af0a41, #1720).

Case base Ir/cycle branch Ir/cycle change
(a) Simulator::tick 703.0 702.8 −0.2
(ac) Simulation + add_clock 6,176.9 6,151.2 −25.7
(b1) 10,281.4 10,290.0 +8.6 (0.08%)
(b5) 11,128.7 11,137.7 +9.0 (0.08%)

(a) and (ac) are equal (the run-to-run spread of one variant is ~0.5–1.2 Ir/cycle; (a) runs none of the changed code). No new work runs per step: with no observer the loop calls ()'s empty hooks, and scheduler_stats counts nothing in the reference loop (a first version counted every step and cost (ac) +7 Ir/cycle; it was removed). The (b1)/(b5) difference is about 4 Ir per step inside the unchanged step_until code, from code layout; the frontend commit alone measures (b1) 10,281.6.

Compile-dominated totals at 20,000 cycles, base → branch: (a) 310.21M → 310.21M, (ac) 419.71M → 419.14M, (b1) 566.05M → 566.11M, (b5) 585.22M → 585.45M Ir. Differential mode compiles the design twice; it is a test option.

Validation

  • SIR identity: the post-optimized SIR of all 590 SV suite designs (454 untimed, 136 timed) hashes identically on base and branch (measured on 4467534 before the rebase; the later changes touch no SIR emission).
  • CELOX_SCHEDULER=differential cargo test -p celox --features systemverilog --test systemverilog timing:: (native, cranelift, native/cranelift parallel, wasm): 504 passed, 0 failed, every step checked against the shadow. Unchecked runs reported by the harness: 10, all "the case took no scheduler step" (time_calls_in_child_port_actuals and time_calls_in_child_port_subroutines on the 5 backends: no processes, waits or scheduled events, so host writes settle on read and run_until only moves time). No timed case lacks a shadow.
  • All results below are from the pushed head, on 8af0a41 (fix(sim)!: reject designs with processes in untimed Simulator builds #1720). --test shared_jit_cache (image version tests): 34 passed; -p celox-heap: 10 passed.
  • cargo test -p celox --features systemverilog --lib simulation: 67 passed (runtime core tests on every backend including the interpreter and a native image round trip, the differential harness tests, the const-delay tests).
  • --test checkpoint 30, processes 17, simulation_limits 10, simulation_step 7, simulation_stop 9, state_file 20: all passed.
  • cargo fmt --check; clippy -D warnings with tests on celox, celox-runtime, celox-design, celox-frontend-core, celox-frontend-sv, celox-heap: clean.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-22T14:37:11.071624Z
We couldn’t complete this review. Comment @codex review to try again.
17af9f5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tignear
tignear force-pushed the feature/compiled-scheduler-3b2 branch from 17af9f5 to 2ba0d0a Compare October 22, 2026 15:52
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

… times

ProcessKernelBuilder takes the delay amount's value when the frontend
knows it and records in ProcessSlots::const_delays whether every delay
of the kernel is a constant of at least one time unit. The SV frontend
records integral constants; the SIR it emits is unchanged. The slots
are part of the native image, so its container version moves to 28.

BREAKING CHANGE: ProcessSlots has a new field, `const_delays`, and
ProcessKernelBuilder::delay and inactive_delay take the amount's known
value as a second argument. Native images use container format 28;
images written by earlier versions must be rebuilt.

Change-Id: I0cf80b28fd983be51686322c0562d9b664d919e1
…uler mode

SimulationState::run_until now holds the loop Simulation::run_until ran,
and run_until_observed/step_until_observed show every step to a
StepObserver; the plain versions pass (). A hidden builder option selects
the SchedulerMode, and a hidden Simulation::scheduler_stats reports the
mode, the steps checked against a shadow and how each kernel is
scheduled. Every mode runs the reference loop until a compiled scheduler
exists.

SchedulerMode::Differential compiles the design twice and runs the same
loop with a shadow check as its observer: before a step the shadow takes
the design state, scheduling state (remapped to its own event handles)
and undrained runtime events, or in a slot suspended at $stop the design
state and host changes; after it the step result, scheduling state, state
bytes, string heap and runtime events must match. Designs without a
shadow record why. The SV suite harness selects the mode from
CELOX_SCHEDULER and reports every case it could not check.

BREAKING CHANGE: SimulatorOptions has a new field, `scheduler`.

Change-Id: I34d2fda76a4ed59ab4a2d0efc84ca033774c9bac
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 22, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 47 minutes 24 seconds in the queue, with no time running CI.

Reason

Pull request #1756 has been dequeued

Queue conditions are not satisfied:

  • label = merge-ready

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for
  • check-success = Queue validation
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
All conditions
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
    • check-success = @github-actions/Rust Test & NAPI Build
  • check-success = Conventional Commit title
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

Requeued — the merge queue status continues in this comment ↓.

@tignear tignear removed the merge-ready Request merging through Mergify after required checks label Oct 22, 2026
@tignear

tignear commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio dequeue

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 22, 2026
@tignear
tignear force-pushed the feature/compiled-scheduler-3b2 branch from 2ba0d0a to c90b37d Compare October 22, 2026 18:05
@tignear tignear changed the title refactor(runtime): run timed slots from SimulationState with a differential scheduler harness refactor(runtime)!: run timed slots from SimulationState with a differential scheduler harness Oct 22, 2026
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 22, 2026
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 22, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 22, 2026
@mergify

mergify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-22 20:36 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1756 on master (59f9f80) #1771
  • ✅ Merged — 2026-10-22 21:37 UTC · at 22d68c3c1ca8db7b3541d7305eb31fddd806f765 · merge

This pull request spent 1 hour 1 minute 23 seconds in the queue, including 59 minutes 40 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant