Skip to content

feat(runtime): run slots of designs with derived clocks in the compiled scheduler - #1967

Merged
mergify[bot] merged 2 commits into
masterfrom
feature/derived-edge-sir-d
Oct 25, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feature/derived-edge-sir-d

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-2: #1786 PR D (derived clock domains in the compiled scheduler), after #1844 and #1888; C (batched clk.next(n) on derived events) follows.

The compiled scheduler rejected every design with gated, inverted or divided clocks ("the design has derived clocks", "RTL logic drives an event signal"), so those designs ran every slot in the reference loop. They now run in compiled slots: a divided clock costs ~110 Ir per cycle over the plain design instead of ~12,000.

What changes

  • Tracked events. Besides the events its kernels and host clocks change, the scheduler tracks the clocks derived from them, transitively (EventTopology::derived_events and combinational_derived). SchedulerSlots::levels holds the level of every tracked event at the slot's start, so SchedulerSchema::events now lists the derived clocks too; a run that returns in the middle of a slot leaves their levels as the reference does.
  • Waves. A slot of a design with derived clocks runs its domains as the reference loop's waves (continue_round / batch_round), in a new Plan::batch:
    • after the process phase, combinational logic settles (a settle perf(runtime): defer settles in compiled slots until their results are read #1923 deferred runs now);
    • with an active edge of a kernel's or clock's event, those domains evaluate together with the domains of the clocks gated by a changed source whose levels moved to their active edge, judged then; their judged levels become their baselines (judge_derived_edges);
    • without one, every tracked event whose level moved to its active edge since the slot started (replace_triggers_with_stable_edges);
    • after each wave commits and logic settles, the domains not run yet whose clocks moved to their active edge run in another wave, until none does; one domain evaluates and commits at once, several evaluate, then commit, in event order. The domains run in the slot collect in exit_arg.
  • Qualification. RTL logic may drive exactly the tracked derived clocks. A design with derived clocks keeps the reference loop when a waiting kernel stages nonblocking assignments, a tracked domain commits its blocking results in the active region, or a tracked domain may end the run ($finish, an error).
  • Observers. A derived clock changes in the slots of its sources, which the runtime does not tell apart: when the host observes one (set_observed_signals), no slot runs compiled.
  • Designs without derived clocks run exactly the code they ran before.

Not covered yet: a gated clock whose gate folds to a constant (logic en = 1; assign gclk = clk & en; — the topology does not list it as derived, so the old rule rejects it), four-state designs, and kernels that wait on a derived clock.

Validation

  • New differential tests (lib, every scheduler mode, native and Cranelift, state files equal to the reference's after each run): derived_clocks_run_in_compiled_slots (a kernel's clock gated by a kernel's enable, gated by an enable its domain raises, inverted, clk ^ tog moved back by the commit, divided, a divided clock gated by an enable changing with the edge, divided twice) and derived_host_clocks_run_in_compiled_slots (a host clock gated by a kernel's enable, divided, gated by a host input; with and without kernels).
  • Mutation-checked: dropping the judged gated edges, the waves after a commit, the re-baselining of judged clocks, or the first wave's active-edge rule fails them.
  • cargo test -p celox --features systemverilog --test systemverilog --test sv_update_events --test derived_register_clock --test cascade_race --test ff_comb_clock in the compiled, differential and differential-runs scheduler modes: 4,808 + 36 passed each after rebasing on master (4,711 + 36 + 24 + 2 + 1 with derived_register_clock, cascade_race and ff_comb_clock before); --lib 222; the timed-runtime integration tests (tick_semantics, clock_alias_edges, checkpoint, state_file, vcd, sv_vcd, simulation_step/stop/limits, processes, tiered, …): all passed. Compiled-scheduler coverage of the SV suite: 152/363 kernels.
  • clippy -D warnings (celox, celox-runtime, celox-napi; tests, examples), the default-feature lib test build without warnings, cargo fmt --check: clean. wasm32 NAPI build: builds.

Perf

examples/sched_bench, callgrind, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 3, release, native backend; the derived variants are local, not committed (64 registers on the derived clock):

bench master this PR change
b1 (plain) 724.0 724.0 same code
ac (plain, host clock) 527.0 527.0 same code
b1d: b1, registers on div (always_ff @(posedge clk) div <= ~div) 12,871.0 833.0 −93.5%
acd: ac, registers on div 8,129.0 636.7 −92.2%
b1g: b1, registers on clk & en (en raised by the clock's domain) 13,172.0 1,484.2 −88.7%
  • On master the derived variants run every slot in the reference loop.
  • The divided clock costs ~110 Ir per cycle over the plain design: the levels of the tracked events and the waves.
  • The gated clock is a combinational output of the clock, so each slot settles before judging edges and again after the commit (3 settles per cycle instead of 1). Judging gated clocks from their gate programs (as perf(runtime)!: run the derived clock edges of ticks in generated units #1888's tick units do) would save the first; a follow-up.
  • Build cost: total Ir at 20,000 cycles is lower than master's on every variant (e.g. b1g 715M vs 767M).

Review fixes

  • A host clock input with no clock armed (set once by the host) now has its slot-start level recorded; before, a gate on it fired its source's domain every slot (derived_clocks_of_an_unclocked_host_input_keep_its_level).
  • A design with gated clocks whose waiting kernels write what combinational logic reads keeps the reference loop: such a kernel runs in a pass after the settle that judges the gated clocks, and the reference sees its change only in the waves after the commit (gates_written_by_waiting_kernels_keep_the_reference_loop). Judging gated clocks per pass would lift this; v1 rejects structurally (any comb input, a superset of the gates' cones).

…ed scheduler

The compiled scheduler rejected every design with gated, inverted or
divided clocks ("the design has derived clocks", "RTL logic drives an
event signal"), so those designs ran every slot in the reference loop.

It now tracks the clocks derived, transitively, from the events its
slots change, and runs a slot's domains in the reference loop's waves:
after the process phase, combinational logic settles; the domains of the
events with an active edge evaluate together with those of the clocks
gated by a changed source whose levels moved to their active edge,
judged then, whose levels become their baselines; a slot without an
active edge runs every tracked event whose level moved to its active
edge. After each wave commits and logic settles, the domains not run yet
whose clocks moved to their active edge run in another, until none
does. Baselines are the levels of the tracked events at the slot's
start, in the levels slot, which now covers the derived clocks too, so
a run that returns in the middle of a slot leaves their levels as the
reference does.

RTL logic may drive exactly those derived clocks. A design with derived
clocks keeps the reference loop when a waiting kernel stages
nonblocking assignments, a tracked domain commits in the active region,
or a tracked domain may end the run; and when the host observes a
derived clock, which changes in the slots of its sources.

Change-Id: Ibb48c1e36a21599607c012f0e6748de35e2616ae
@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-25T05:30:18.367904Z
We couldn’t complete this review. Comment @codex review to try again.
3344533 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.

Two cases where the waves of a slot with derived clocks differed from
the reference loop's:

- A host clock input with no clock armed kept its slot-start level out
  of the levels slot, which only the clock-apply block filled. The waves
  compared against zero, so a gate on a clock input the host had set high
  fired its source's domain at every slot. The levels of every tracked
  event are now recorded at the slot's start.
- A waiting kernel woken by a clock's change runs in a pass after the
  settle that judges the clocks gated by it; what it writes moves those
  clocks only for the waves after the commit. The waves judge once, after
  every pass, so a design with gated clocks whose waiting kernels write
  what combinational logic reads keeps the reference loop.

Change-Id: I42793209eeebcfeffaf0fbc08b91fc586edc58f0
@mergify

mergify Bot commented Oct 25, 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 25, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 39 minutes 44 seconds in the queue, including 39 minutes 10 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 d65469c into master Oct 25, 2026
24 checks passed
@mergify
mergify Bot deleted the feature/derived-edge-sir-d branch October 25, 2026 07:11
@mergify mergify Bot removed the queued Mergify queue entry label Oct 25, 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