Skip to content

feat(runtime)!: host periodic clocks in the compiled loop - #1805

Merged
mergify[bot] merged 3 commits into
masterfrom
feature/compiled-scheduler-3b5
Oct 23, 2026
Merged

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

Conversation

@tignear

@tignear tignear commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-1 (compiled scheduler), PR 5 of 7. Builds on #1801.

Periodic clocks from add_clock now run inside the compiled scheduler's loop, and kernels may wait for them: a testbench whose clock comes from the host, such as initial forever @(posedge clk) stim = stim + 3; with add_clock("clk", 10, 5), the new bench case (bh), drops from about 8,200 to about 1,090 Ir per cycle.

A slot that touches anything the scheduler does not run still runs entirely in the Rust reference loop, as before: one-shot schedule() events and clocks the scheduler does not take only bound its runs.

BREAKING CHANGE

  • celox_design::SchedulerSlots (public) has new fields: clock_next, clock_period, clock_value, clock_armed. SchedulerSchema has clocks, and SchedulerExit has ClockOverflow.
  • Native images use container format 31; images written by earlier versions must be rebuilt.

Stacked on #1801: review the last commit (feat(runtime)!: host periodic clocks in the compiled loop).

Which clocks and kernels

  • A host clock runs in compiled slots when its event is a one-bit clock edge (posedge or negedge domain, not an asynchronous reset) that no design code writes (no RTL unit, no kernel, no nonblocking site), whose domain does not commit blocking results in the active region (fix(sv): run waiters of blocking edge writes before the NBA region #1783), and the event queue holds exactly one periodic edge for it, of the event's own signal. Every other scheduled event stays in the Rust queue and ends a compiled run before its time. The design reserves clock slots for every such event at generation; which clocks run is decided at each run by what add_clock registered. A run that takes no clock skips all clock code of its slots behind one test of the armed mask (the next-edge scan, the batch, the re-arm). Asynchronous resets get no clock slots: each reserved event costs the unit its domains' code even when no clock runs, and the host drives resets by writes; kernels waiting for a host-written reset still compile (below).
  • A kernel that waits for one edge now also compiles when the signal it waits for is one bit wide and no design code writes it (a host clock, or an input the host writes between runs), in addition to signals one compiled delay-only kernel alone drives (feat(runtime)!: fuse clock-waiting kernels into compiled slots #1801). Such a signal changes in a compiled slot only at its start, at most once.

What a slot does with host clocks

The reference's round (run_time, step_round, rearm_clocks), unchanged:

  1. the slot's time is the earliest of the compiled kernels' wake times and the host clocks' next edges;
  2. the clocks due now write their levels, in event order, before any kernel runs, and the waits are tested once after them (observe after the batch); their edges are the first edges of the slot, judged against the levels the slot started from, and chain with the kernels' writes into the domains, as mark_scheduled_edges chains the batch's transitions with the first pass's;
  3. the process phase, domains and NBA region as in feat(runtime)!: fuse clock-waiting kernels into compiled slots #1801;
  4. at the end of the slot each clock whose edge applied waits for its opposite level half a period later (ceil(P/2) high, floor(P/2) low, P < 2 taken as 2), in event order; a next edge past the end of time fails the run with the reference's event N overflows simulation time, after the clocks before it re-armed. The reference re-arms at the end of the slot's first round; a compiled slot has a single round, since no kernel it runs resumes in the same slot.

Clock edges move between the Rust event queue and the scheduler's clock slots at every run. A run that ends in the middle of a slot (a $finish) leaves the clocks whose edge applied out of the queue, as the reference leaves them before rearm_clocks.

State files now list the queued events in the order they fire rather than in the queue's internal order, which depends on the order they were pushed: a run that hands its clocks back must leave the same state file as the reference's.

Coverage

compiled_scheduler_coverage (test output): 132 of 296 kernels of the timed SV suite cases compile, against 129 with #1801. The suite's timed cases drive their own clocks (none uses add_clock); the gain is kernels that wait for a one-bit signal no design code writes. Kernels that wait for a signal not driven this way fall from 44 to 39:

Reason Kernels
the process waits for a signal that neither one kernel that only delays nor the host alone drives (comb outputs, several writers: 3b-2) 39
the design counts event occurrences 29
a delay is not a constant of at least one time unit 20
the process waits for more than one edge (lists, @*: 3b-2) 12
RTL logic drives an event signal 11
the process makes host requests / the design is four-state 10 / 10
the process drives or waits for a clock whose domain commits blocking results in the active region 8
the process suspends other than for a delay / for one edge 5 / 5
a declaration initializer 4
edge procedure, derived clocks, queued nonblocking sites, nonblocking assignments in delay-only kernels, level waits 2 each
combinational observers 1

Perf

Callgrind, whole program, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 5. Base: #1801's head (97108e9). (bh) has no base binary; its base is the branch binary in reference mode, whose loop this PR does not change.

Case base branch change
(a) Simulator::tick 969.0 969.0 0
(ac) Simulation + add_clock 6,093.0 6,093.0 0
(b1) always #5 clk = ~clk + forever @(posedge clk) stim = stim + 3 + RTL 1,259.0 1,259.2 +0.2
(b5) the same with stim <= stim + 3 1,281.5 1,281.8 +0.3
(d) always #5 clk = ~clk + RTL 967.0 966.6 −0.4
(dr) (d) with an asynchronous reset input on every register, set once by the host 1,234.7 1,233.0 −1.7
(bh) (b1) with add_clock(10, 5) instead of the clock kernel (reference mode → default) 8,202.0 1,089.6 −86.7%
  • (bh) runs every slot compiled (compiled slots 4000, kernels [Compiled] at 2,000 cycles) and stays below (b1).
  • (dr) is the case of a host-driven reset beside a kernel clock: it runs every slot compiled with the same unit as on feat(runtime)!: fuse clock-waiting kernels into compiled slots #1801 (totals at 20,000 cycles 944.54M → 944.68M). It costs more than (d) because each of its registers has the reset; the base column is the same bench file on feat(runtime)!: fuse clock-waiting kernels into compiled slots #1801.
  • (a), (ac), (b1), (b5) and (d) have no event a host clock could take, so their units are the same; (ac) has no kernel and no scheduler (PR 7).
  • Totals at 20,000 cycles, base → branch: (a) 316.33M → 316.34M, (ac) 418.82M → 418.83M, (b1) 489.10M → 489.26M, (b5) 498.34M → 498.36M, (d) 456.55M → 456.49M; (bh) 517.97M in reference mode → 474.93M.

Validation

  • cargo test -p celox --features systemverilog --test systemverilog (all groups, native/cranelift/parallel/wasm): 4,222 passed, 20 ignored in each of CELOX_SCHEDULER=differential, differential-runs and the default (compiled).
  • --lib: 201 passed, with new tests, each in the compiled, differential and differential-runs modes, comparing the state file with the reference's after every run (on the native and Cranelift backends, except the restore and overflow cases, native only):
    • kernels waiting for a host clock, blocking and nonblocking;
    • three host clocks with coinciding edges and odd and short periods (7, 3, 1, 2, 5, 9), a kernel clock in the same slots, and rising, falling and any-change waits;
    • host writes between runs (of an input a kernel waits for, and of clocked signals), a clock added between runs, a one-shot event on a clocked signal, a clock added twice to one event;
    • a $finish in a slot with host clock edges, and a state file and a checkpoint taken in the middle, restored and run on;
    • a clock edge that overflows the time, with the same error and state file as the reference;
    • clocks on an event a kernel drives, or added twice, that stay in the Rust queue;
    • a host-written reset and an unclocked clock input with a $finish in the middle of a slot, in runs that take no clock.
  • 44 integration test files (state_file, checkpoint, clock_alias_edges, edge_api, vcd, shared_jit_cache with image format 31, ...), celox-runtime, celox-design, celox-frontend-core, celox-sir, celox-heap: all passed.
  • napi build --platform --target wasm32-wasip1-threads (WASI SDK 25): builds.
  • clippy -D warnings (tests, examples) and cargo fmt --check: clean.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T13:55:46.723712Z 3912589 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 23, 2026 •

Copy link
Copy Markdown
Contributor

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

@tignear
tignear force-pushed the feature/compiled-scheduler-3b5 branch from 17cd2f0 to 594c565 Compare October 23, 2026 06:45
@tignear
tignear force-pushed the feature/compiled-scheduler-3b5 branch from 594c565 to 4aff484 Compare October 23, 2026 08:19
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 23, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 9 minutes 29 seconds in the queue, including 3 minutes 14 seconds running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Lint & Format

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, 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/Lint & Format
    • check-skipped = @github-actions/Lint & Format
    • check-success = @github-actions/Lint & Format
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
    • check-success = @github-actions/NAPI Build (Windows)
  • 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
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
    • check-success = @github-actions/JS Test (Ubuntu)
  • any of: [🛡 GitHub repository ruleset rule master]
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
    • check-success = @github-actions/JS Test (Windows)
All conditions
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
    • check-success = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
    • check-success = @github-actions/NAPI Build (Windows)
  • 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
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
    • check-success = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
    • check-success = @github-actions/JS Test (Windows)
  • check-success = Conventional Commit title
  • 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 ↓.

@mergify mergify Bot added dequeued Mergify stopped this queue entry; investigate before retrying and removed queued Mergify queue entry labels Oct 23, 2026
@tignear tignear removed merge-ready Request merging through Mergify after required checks dequeued Mergify stopped this queue entry; investigate before retrying labels Oct 23, 2026
@mergify mergify Bot added the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 23, 2026
@tignear
tignear force-pushed the feature/compiled-scheduler-3b5 branch from 4aff484 to 6f2a0a1 Compare October 23, 2026 11:21
@mergify mergify Bot removed the dequeued Mergify stopped this queue entry; investigate before retrying label Oct 23, 2026
The compiled scheduler now also runs kernels whose every wait is the
same single edge of a one-bit signal that one compiled delay-only
kernel alone drives, whose statuses are Wait, Nba, Done or Finish, and
whose nonblocking sites stage their values into targets nothing else
writes. Such a kernel wakes at most once a slot, so a site is never
staged again before the NBA region.

A slot runs the ready kernels lowest first, tests the waits after each
run while kernels remain ready or the kernel resumes at once, and again
after each pass's settle, as the reference's process phase does; a wait
compares against a baseline that follows every tested change. The
ready set is a mask over the compiled kernels in kernel order. Staged
values publish after the domains, or with a settle of their own without
one. Waiting kernels move between Waiters and the scheduler's slots at
each run, and a run that ends in the middle of a slot hands back the
ready set and the baselines as the reference leaves them. Kernels that
drive or wait for a clock whose domain commits blocking results in the
active region keep the reference loop.

A staged site's target must also lie outside every occurrence probe: the
reference publishes nonblocking updates through the runtime, which bumps
the probes' counters, and the scheduler's publication does not.

BREAKING CHANGE: SchedulerSlots has new fields, `ready` and `baseline`.
Native images use container format 30; images written by earlier
versions must be rebuilt.

Change-Id: Ib033a13b9ad213155c0ffca86c4e891fe61876b2
@tignear
tignear force-pushed the feature/compiled-scheduler-3b5 branch from 6f2a0a1 to 344d7de Compare October 23, 2026 12:41
A delay-only kernel that pulses the signal another kernel waits on
within one activation, by two stores or in a loop, makes the frontend
count the signal's occurrences, and the compiled scheduler leaves a
design that counts occurrences to the reference loop. The test checks
that every mode wakes on each pulse as the reference does, the guard
for when counted designs become compilable.

Change-Id: I479dec1591e33514389937797b7283eb3baefba2
Periodic clocks from add_clock now run inside the compiled scheduler's
loop when their event is a one-bit clock edge (not an asynchronous
reset) that no design code writes, whose
domain does not commit blocking results in the active region, and the
queue holds exactly one periodic edge of the event's own signal. Every
other scheduled event stays in the Rust queue and ends a compiled run
before its time.

A slot applies the clocks due at its time, in event order, before any
kernel runs and tests the waits once after them; their edges start the
slot's edges and chain with the kernels' writes into the domains. At
the end of the slot each clock whose edge applied waits for its opposite
level half a period later, with the extra unit of an odd period in the
high phase; a next edge past the end of time fails the run as the
reference does, after the clocks before it re-armed. Clock edges move
between the event queue and the scheduler's clock slots at every run;
a run that ends in the middle of a slot leaves the clocks that fired in
it out of the queue, as the reference leaves them.
A run that takes no clock skips the clock code of its slots behind one
test of the armed mask.

A kernel that waits for one edge also compiles when no design code
writes its one-bit signal: a host clock, or an input the host writes
between runs, changes in a compiled slot only at its start.

State files list the queued events in the order they fire instead of
the queue's internal order, which depends on the order of the pushes.

BREAKING CHANGE: SchedulerSlots has new fields, `clock_next`,
`clock_period`, `clock_value` and `clock_armed`; SchedulerSchema has
`clocks` and SchedulerExit has `ClockOverflow`. Native images use
container format 31; images written by earlier versions must be
rebuilt.

Change-Id: I3b7e4561ecbf897a5bf1f4e6d83dc5f3e2697311
@tignear
tignear force-pushed the feature/compiled-scheduler-3b5 branch from 344d7de to 3912589 Compare October 23, 2026 13:51
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 23, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 23, 2026
@mergify

mergify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 1 hour 14 minutes 13 seconds in the queue, including 1 hour 13 minutes 29 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 adc2f52 into master Oct 23, 2026
30 checks passed
@mergify
mergify Bot deleted the feature/compiled-scheduler-3b5 branch October 23, 2026 16:26
@mergify mergify Bot removed the queued Mergify queue entry label Oct 23, 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