Skip to content

feat(sim)!: show the regions of a time slot to a slot observer - #1934

Merged
mergify[bot] merged 2 commits into
masterfrom
feat/runtime-host-observation
Oct 24, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feat/runtime-host-observation

Conversation

@tignear

@tignear tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Part of #1730, PR 2 of 3. The VPI host (PR 3) needs to see, inside a time slot of a timed Simulation:

  • an edge before the flip-flop domains commit, so that a cocotb RisingEdge(clk) reads the values from before the nonblocking updates;
  • every settled slot.

This PR adds that observation point and keeps every compiled kernel it can.

Change

  • Simulation::observe_slots(observer, signals) / stop_observing_slots() install a SlotObserver<B>:
    • before_domains(io, time) runs in every round, once its processes and scheduled values have run and before its domains evaluate. The round's edges are in state and nothing has committed. Writes through SlotIo are blocking host writes at time. The round logs them for the waits, settles comb and only then evaluates the domains.
    • end_of_slot(io, time) runs when the slot has settled. Writes there are updates of time, which the simulation settles at that time before it advances.
  • Runtime: HostBoundary gains before_domains and take_slot_writes. Both default to doing nothing, so other executors are unchanged.
  • Per-kernel scheduling (option A from the plan):
    • SchedulerSchema::kernel_events records, per process kernel, the bits of events it writes, computed from Plan's Kernel::writes.
    • With an observed event signal e, compiled_limit treats the wakeups of kernels that write e, and the edges of host clocks that drive e, as reference-loop work. A waiting kernel that writes e keeps compiled runs from starting while it waits, because the slot it resumes in is not known in advance.
    • All other kernels stay compiled.
  • Observed non-event signals: while an observer is installed, compiled runs take one slot at a time (the existing CompiledSlots::One path that VCD and the heap use), so end_of_slot sees each slot.
    • The observer finds their changes after the slot's nonblocking updates and the settle that follows. That is an implementation choice: the callback and the settle's updates are active events of one region, which a simulator may process in any order (IEEE 1800-2023 4.7). The rustdoc of end_of_slot says so.
    • PR 3 adds the cocotb fixture showing this order once the VPI host runs on Simulation; here a_settled_slot_shows_every_change_and_its_writes_stay_in_the_slot shows it.
  • Differential mode: installing an observer drops the shadow and records an unchecked reason, because the shadow doesn't see the observer's writes.
  • sched_bench gets an optional fifth argument, observe=<signal>: an observer that counts the signal's changes at the end of every slot, as a value-change callback does.

BREAKING CHANGE

  • Native image container format: version 35 (was 34), because SchedulerSchema is serialized in images and gains kernel_events. Images written by earlier versions are rejected on load and must be rebuilt.
  • celox_design::SchedulerSchema: new public field kernel_events: Vec<Vec<usize>>. Struct literals of it must add the field.

Perf

callgrind, sched_bench. Per cycle = (Ir at 200,000 − Ir at 20,000) / 180,000, medians of five runs each, taskset -c 3. Base is c430061 (master).

design base, no observer branch, no observer branch, one value-change callback on out branch, callback on clk
(b1) always #5 clock + stimulus kernel 898 898 6,843 11,725
(ac) add_clock 690 689 6,818 7,696
  • No observer: equal to base, so the hooks cost nothing when unused.
  • Callback on out (a data signal): about 7.6× in b1 and 9.9× in ac, from one compiled run per slot instead of one run for the whole run_until. Per slot in ac: the compiled slot code is about 540 Ir; the hand-off is about 1,050 Ir in run_compiled itself, 500 Ir in 7 slot writes and 230 Ir in compiled_limit; try_finish_timed_step is about 500 Ir, including about 340 Ir in the observer. This is the same hand-off cost VCD recording already pays. A cheaper hand-off for one-slot runs would help both and is a possible follow-up.
  • Callback on clk (an event signal): every slot of these designs has an edge of the observed clock, so every slot runs in the reference loop, as it must for the callback to see the edge before the domains commit. Under cocotb, each such slot also costs a Python callback, which is much more expensive.

Tests

New crates/celox/tests/slot_observer.rs:

  • the rises of an always #5 clock are seen before their always_ff update (q = 0, 1, 2, 3 at 5, 15, 25, 35);
  • with the clock observed, the slots of an unrelated always #7 kernel stay compiled (0 < compiled_slots < unobserved), with identical results;
  • a write before the domains is what the edge samples;
  • end_of_slot sees every change of a compiled clock's register, and a flag written there wakes a wait at the same time;
  • a differential simulation with an observer reports unchecked.

Validation

  • cargo nextest run -p celox -p celox-runtime -p celox-vpi --features celox/systemverilog,celox-test-suite/runtime-cases --lib --tests (excluding the SV vtest binary): 9758 passed.
  • node scripts/run-vtest.mjs --test systemverilog: 4542 passed.
  • CELOX_SCHEDULER=differential on timing::: 661 passed.
  • cargo clippy -p celox-runtime -p celox -p celox-vpi -p celox-napi -p celox-design -p celox-frontend-core --all-targets -- -D warnings and cargo fmt --check: clean.

A host such as a VPI driver needs to see an edge before the flip-flop
domains commit, and every settled slot. Simulation::observe_slots
installs a SlotObserver: before_domains runs in every round once its
processes and scheduled values have run and before its domains
evaluate, end_of_slot once the slot has settled. Writes there are
blocking host writes at the slot's time; the round settles them before
the domains read them, and those at the end of a slot are settled at
that time before the simulation advances.

The compiled scheduler keeps every kernel it can. SchedulerSchema
records, per kernel, the event signals it writes: the slots of the
kernels and host clocks that may change an observed event signal run
in the reference loop, the others stay compiled, one slot per run while
an observer is installed. A differential simulation stops checking, as
its shadow does not see the observer's writes.

BREAKING CHANGE: native image containers are version 35; images of
earlier versions no longer load. SchedulerSchema has a new public field,
kernel_events.

Part of #1730

Change-Id: I4ffaef0e5b3b716ec5185ff0250aeb33114fb496
Change-Id: I5737eb89d7389cb84585ee295af57fac35d9ccc4
@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 🔄 Running since 2026-10-24T21:07:30.020052Z 92a858e 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.

@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 43 minutes 26 seconds in the queue, including 33 minutes 9 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

@mergify
mergify Bot merged commit a833604 into master Oct 24, 2026
23 checks passed
@mergify
mergify Bot deleted the feat/runtime-host-observation branch October 24, 2026 23:40
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 2026
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