Skip to content

fix(sim): judge derived clocks after several nonblocking updates - #1901

Merged
mergify[bot] merged 3 commits into
masterfrom
feature/fix/sim-gated-clock-nba
Oct 24, 2026
Merged

mergify[bot] merged 3 commits into
masterfrom
feature/fix/sim-gated-clock-nba

Conversation

@tignear

@tignear tignear commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #1860. Part of #1123.

Problem

The timed Simulation lost the edge of a combinationally gated clock when the NBA region publishing its source clock held another update too:

assign rclk = clk & ren;
always_ff @(posedge clk) ren <= ~ren;
always_ff @(posedge rclk) e <= e + 8'd1;
initial begin
  #9 clk <= 1; #1; clk <= 0;
  #3 clk <= 1; clk2 <= 1; #1; clk <= 0; clk2 <= 0;
  #3 clk <= 1; #1; clk <= 0;
end

e at t=12/16/20 was 1 1 2. Icarus 13.0 and Simulator give 1 2 3.

Cause

I confirmed it with a diagnostic run before changing code. At t=13 the settle after the NBA region saw rclk and clk triggered, but only clk in scheduled_trigger_ids and no gating source.

With several updates, publish_nba records the transitions of each update and marks their edges with mark_occurrences, which fills scheduled_trigger_ids. Unlike mark_scheduled_edges (the path for the processes' writes), mark_occurrences never pushed the source onto round.gating_sources. So the following settle_marked re-marked only the scheduled ids, and judge_derived_edges never judged rclk.

With a single update, mark_occurrences is not called, scheduled_trigger_ids stays empty, and the stable-edge scan finds rclk. That's why dropping the clk2 writes hides the bug.

Fix

mark_occurrences now registers a changed event signal with combinationally derived clocks as a gating source, as mark_scheduled_edges does. The settle that follows judges the derived clocks from the settled state.

Tests

One timing.vtest case per caller of mark_occurrences, each checked with verify-sv-icarus / verify-sv-verilator:

Case Caller Expected Icarus 13.0 Verilator 5.052
derived_clocks_follow_several_nonblocking_updates NBA publication (the issue's repro) e = 1 2 3 passes passes
derived_clocks_follow_active_region_commits active-region commit (evaluate_before_inactive) cnt=2 w=4 passes passes
derived_clocks_follow_superseded_publications finish_publications cnt=0 n=1 q=0 passes excluded: n=0
  • Before the fix: the first case gave e = 1 1 2. The other two already matched Icarus, and the fix keeps them.
  • The third case: Icarus evaluates the continuous assignment gq = q & en only after both NBA updates, so the pulse of q gives no edge of gq (4.7). Verilator 5.052 doesn't wake the @(q) waiter for the NBA pulse at all, so the case joins sv_verilator_intermediate_writes, with the LIMITATIONS.md row and shard rows.
  • Compiled mode: a slot whose NBA queue holds updates, or that runs these kernels, falls back to the reference loop. The new cases run on the full differential suite (CELOX_SCHEDULER=differential over --test systemverilog, 4488 passed) and under CELOX_SCHEDULER=compiled (15 passed).
  • The 3b child's ignored tick_semantics case isn't on master yet; it gets re-enabled when that PR lands or in this one if it lands first.

Performance

Runtime Ir measured with callgrind (200k-cycle minus 20k-cycle runs, taskset), base 48f908e:

Gate base branch Δ
(a) 151,560,076 151,560,063 0.00%
(b5) 184,500,016 184,355,705 −0.08%
(c) 2,302,920,034 2,313,539,856 +0.46%

(c) never takes the changed path. Its profile shows only layout shifts of unchanged code: run_time inlined into step_until, BinaryHeap::push out of line in rearm_clocks, and check_waits +2.2M at 50k cycles with an identical body. Two builds of the same commit vary by about 0.25% on (c) (measured on #1829).

Validation

Under the shared lock:

  • cargo test -p celox-runtime: 78 passed.
  • -p celox --features systemverilog,sv-dpi --lib plus --test systemverilog and the timed integration files (processes, state_file, checkpoint, comb_observer, runtime_api, simulation_step, time_state_and_delays, derived_register_clock, ff_comb_clock, tick_semantics, clock_gen_semantics): 5699 passed.
  • Differential --test systemverilog: 4488 passed. Compiled timing::derived: 15 passed.
  • retained_reports: 3 passed. clippy -D warnings and fmt are clean.
  • sv-tests matches expected.tsv.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

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 ✅ Completed 2026-10-24T17:48:29.459187Z badea1a New commits
ℹ️ 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

  • ✅ Entered queue — 2026-10-24 16:16 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • 🚫 Left the queue — 2026-10-24 16:20 UTC · at 94284e40f1cded822af11a303ae7b3a681b59b8a

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

Reason

The pull request conflicts with the base branch

The pull request was held in the queue, conflicting with at least one of 2 pull requests ahead of it. The conflict became a base branch one after #1847 merged.

Hint

You should update or rebase your pull request.

If you want to requeue this pull request, you can post a @mergifyio queue comment.

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

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 24, 2026
When several updates publish in one NBA region, or a domain commits its
blocking results in the active region, or publishes several evaluations,
the runtime marks the edges among the updates as occurrences. It did
not register their signals as sources of combinationally derived clocks,
so the settle that followed kept only the marked occurrences and dropped
the edge of a clock such as clk & ren. The derived clocks of a source
that changed are now judged at that settle, as for the processes' writes.
Fixes #1860.

Change-Id: I5d30a1832ead72125172cfa3425a809cfafdb147
…commits

Change-Id: Idb4448de658b44a14d031190bbd61bc5a5a2e596
Change-Id: I0d371af10f284bee80cf83580dccb19c6ce29825
@tignear
tignear force-pushed the feature/fix/sim-gated-clock-nba branch from 94284e4 to badea1a Compare October 24, 2026 17:47
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 24, 2026
@tignear tignear added merge-ready Request merging through Mergify after required checks and removed merge-ready Request merging through Mergify after required checks labels 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 57 minutes 44 seconds in the queue, including 1 hour 55 minutes 57 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 8b3372b into master Oct 24, 2026
30 checks passed
@mergify
mergify Bot deleted the feature/fix/sim-gated-clock-nba branch October 24, 2026 20:24
@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.

Simulation misses a gated-clock edge when the NBA batch has several updates

1 participant