Skip to content

feat(runtime)!: fuse clock-waiting kernels into compiled slots - #1801

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

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

Conversation

@tignear

@tignear tignear commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-1 (compiled scheduler), PR 4 of 7. Builds on #1777 (merged); rebased onto master with #1764.

The compiled scheduler now also runs kernels that wait for one clock edge, such as initial forever @(posedge clk) stim = stim + 3; or stim <= stim + 3;, together with the delay-only kernels that drive the clock. The testbench shape of the scheduler bench, (b1) and (b5), drops from about 10,200 to about 1,260 Ir per cycle.

A slot that touches a kernel the scheduler does not run still runs entirely in the Rust reference loop, as in #1777; the fallback is per kernel and per slot.

BREAKING CHANGE

  • celox_design::SchedulerSlots (public) has new fields, ready and baseline.
  • Native images use container format 30; images written by earlier versions must be rebuilt.

Stacked on #1777: review the last commit (feat(runtime)!: fuse clock-waiting kernels into compiled slots).

Which kernels

A kernel that waits compiles when:

  • every wait site is the same single term: one edge (rising, falling or any change) of a one-bit signal that exactly one compiled delay-only kernel writes, and no RTL unit or other kernel. That writer runs once a slot (its delays are at least one), so the kernel wakes at most once a slot, and a staged site is never staged again before the NBA region: the kernel never returns Nba in a compiled slot (an Nba status there is an internal exit). A loop that does not suspend yields every 2^16 iterations, and Yield keeps the kernel in the reference loop;
  • every status it stores is a constant Wait, Nba, Done or Finish (no delay, no host request, no $stop, no yield, no Pending);
  • it writes no event signal and no signal any wait watches;
  • each nonblocking site stages its value with a pending flag (the staged path of select_nba_paths), with a static target range that nothing else writes, no other site targets, and nothing watches; the target also lies outside every occurrence probe (fix(sim)!: wake processes on value changes that are undone in the same time slot #1764): the reference publishes nonblocking updates through the runtime, which bumps the probes' counters, and the scheduler's publication does not;
  • neither it nor a delay-only kernel drives or waits for a clock whose domain commits blocking results in the active region (fix(sv): run waiters of blocking edge writes before the NBA region #1783: the reference evaluates such a domain before the NBA region).

What a compiled slot does now

The reference's process phase (process_phase / run_ready / settle_pass) with waiting kernels:

  1. the kernels due now are ready; each pass runs the lowest ready kernel (BTreeSet::pop_first), and after a run, while kernels remain ready or the kernel resumes at once (an Nba return), the waits are tested (observe_driven); a kernel woken in the middle of a pass joins it;
  2. a pass ends with a settle and a test of the waits; woken kernels run in another pass;
  3. a wait wakes on its edge since its baseline, and the baseline follows every change it is tested against (check_waits / advance); a kernel that waits again takes the current level (register_waiter);
  4. the domains, then the staged values (publish_nba) right after eval_apply, or after the applies with several domains, then the settle; without a domain, staged values publish and combinational logic settles once more.

The ready set is a mask over the compiled kernels, one bit per compiled kernel in kernel order (so a design may have any number of other processes), and every kernel copy, comb and the domain units are inlined once, as before. Waiting kernels move between the runtime's Waiter entries and the scheduler's waiting/baseline slots at every run; a run that ends in the middle of a slot hands back the ready mask (ready kernels stay ready) and the baselines as the reference leaves them.

Coverage and fallback stats

compiled_scheduler_coverage (test output): 129 of 296 kernels of the timed SV suite cases compile, against 126 with #1777. The kernels that wait still mostly fall back, for reasons the next steps address:

Reason Kernels
the process waits for a signal kernels that only delay do not drive (host inputs, comb outputs: PR 5 / 3b-2) 44
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 / 3
a declaration initializer 4
edge procedure, derived clocks, queued nonblocking sites, nonblocking assignments in delay-only kernels, level waits 2 each
combinational observers 1

In the differential SV suite 190 case-backend runs execute compiled slots. The bench's (b1) and (b5), the testbench shape this PR targets, now run every slot compiled (compiled slots 4000, kernels [Compiled, Compiled] at 2,000 cycles).

Perf

Callgrind, whole program, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 5. Base: #1777's head (3885415, on master 3766461); both built with the same sched_bench.rs.

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 10,213.6 1,259.0 −87.7%
(b5) the same with stim <= stim + 3 11,061.0 1,281.7 −88.4%
(d) always #5 clk = ~clk + RTL 931.1 966.2 +35.1
  • (b1)/(b5) reach the design note's target for this step (about the JIT work plus loop overhead, 1,000–1,100); the rest goes with settle elision (PR 6). In reference mode on the branch binary they are 10,211 and 11,058.
  • (d) pays about 17 Ir per slot for the ready-mask pick loop that the waiting kernels need (each pass picks the lowest ready kernel instead of running the due kernels in a fixed order); it stays 7.6× below the reference loop.
  • Compile-dominated totals at 20,000 cycles, base → branch: (a) 316.27M → 316.27M, (ac) 418.75M → 418.76M, (b1) 642.44M → 489.86M, (b5) 661.94M → 505.12M (the unit compiled in feat(runtime)!: compiled time-slot loop for delay-only kernels #1777 now runs), (d) 450.59M → 456.53M.

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: 194 passed, with new tests: clock kernels feeding the domain of their edge, blocking and nonblocking; kernels woken in the middle of a pass, declared before and after the clock kernels; falling and any-change waits; a clock kernel's $finish; compiled kernels declared after 66 other processes. Each runs in the compiled, differential and differential-runs modes and compares the state file with the reference's. Tests check that a waiting kernel whose loop yields falls back, and that a nonblocking site in a loop (kept, i < n, or unrolled, i < 2, with and without a $finish after it) keeps the kernel in the reference loop with the reference's state file in every mode.
  • 34 integration test files, celox-runtime, celox-design, celox-frontend-core, celox-sir, celox-heap, shared_jit_cache (image format 30): 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:54:30.290924Z a73c8f3 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 523350117c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/scheduler.rs Resolved
Comment thread crates/celox/src/scheduler.rs Resolved
@tignear
tignear force-pushed the feature/compiled-scheduler-3b4 branch 2 times, most recently from c867378 to 97108e9 Compare October 23, 2026 05:10
@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-3b4 branch from 97108e9 to fe58ec1 Compare October 23, 2026 08:04
@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 29 minutes 18 seconds in the queue, with no time running CI.

Reason

Pull request #1801 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/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 ↓.

@tignear

tignear commented Oct 23, 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 23, 2026
@tignear
tignear force-pushed the feature/compiled-scheduler-3b4 branch from fe58ec1 to 5a60bf3 Compare October 23, 2026 10:31
@tignear tignear 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-3b4 branch from 5a60bf3 to 8931be8 Compare October 23, 2026 12:32
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
@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

  • ✅ Entered queue — 2026-10-23 15:06 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1801 on master (d59616e) #1831
  • ✅ Merged — 2026-10-23 15:56 UTC · at 5eaab24756a7ac11d160ef307095095b1ab2eeaa · merge

This pull request spent 50 minutes 15 seconds in the queue, including 47 minutes 53 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 mentioned this pull request Oct 23, 2026
40 of 71 tasks
@mergify
mergify Bot merged commit 5eaab24 into master Oct 23, 2026
30 checks passed
@mergify
mergify Bot deleted the feature/compiled-scheduler-3b4 branch October 23, 2026 15:56
@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