Repository navigation
perf(runtime): defer settles in compiled slots until their results are read - #1923
Conversation
…e read The compiled scheduler settled combinational logic after every pass of the process phase and after the NBA region, as the reference loop does. Since #1811 it skips a settle whose inputs did not change, but the settle after a domain's commit ran in every slot that fired one, though usually only the host reads its results, at the end of the run. Such a settle now stays pending (the dirty flag stays set) until something observes it, and runs at the point the reference ran it last, so every observer sees the reference's values: - the host: before the run returns at its limit or after a clock overflow, which ends a complete slot; - a kernel that loads storage combinational logic writes, or may end the run in the middle of a slot ($finish, an error): before the slot it is due in, or, for a waiting kernel, which may wake in any pass, before every slot and pass; every kernel once a constant delay may overflow, as the run then returns in the middle of the slot; - a domain that may end the run, or reads combinational outputs without fused units: before it evaluates; slots that fire several domains whose units observe it: before their units; - a domain that reads combinational outputs and has fused units (Veryl): the fused units compute what it reads, then evaluate and apply. Combinational logic with effects of its own or that may fail keeps every settle where the reference has it. The waits the scheduler checks never watch combinational outputs, which a debug assertion now states. Change-Id: I5aa9c77efe9277bde745a55de530c352804f875e
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72f732adf5
ℹ️ 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".
…e does A deferred settle merges the settles it replaces into one, which is only equivalent when a settle is a function of its inputs. Combinational logic that keeps state between settles is not: a latch keeps what it captured while open, and the guarded units of `always @*` and similar processes run on a change of their inputs since their last activation, so a latch opened and closed between two observers, or inputs that changed and changed back, gave other results than the reference's. Combinational logic now settles lazily only when no settle reads what an earlier one left: every load of storage it writes is covered, on every path, by stores earlier in the same settle. Guarded units load their snapshots first, and feedback reads the previous value, so designs with either keep every settle where the reference has it, skipping only those whose inputs did not change. Change-Id: I568c6d92c6fa2c2b1a1fb64ffccfe1a3151aab5b
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 51 minutes 13 seconds in the queue, including 33 minutes 28 seconds running CI. Required conditions to merge
|
Part of #1123, step 3b-2: the lazy settle from the compiled-slot frequency analysis (before #1786 D).
In the time slots the compiled scheduler runs, the settle after a domain's commit ran in every slot that fired a domain, though usually nothing in the run reads its results: only the host does, after the run. Such a settle now stays pending until something observes it, and runs where the reference loop ran it last, so every observer sees the reference's values. On the scheduler overhead benches a cycle drops by 19–24% in Ir (ac 690 → 525, b1 900 → 724, d 728 → 564), and by 32% on a variant whose registers read
always_combnext-state logic.What changes
The settle stays pending (the scheduler's dirty flag stays set) and runs:
$finish, which is its status, or an error): before the slot it is due in. A waiting kernel that observes it may wake in any pass, so it runs before every slot and every further pass. Once a constant delay of a kernel may overflow, before every slot, as the run then returns in the middle of it;Combinational logic with effects of its own (records, captures, external calls, trigger marks), that may fail, or that keeps state between settles keeps every settle where the reference has it, as before. Keeping state is structural: a load of storage combinational logic writes that stores earlier in the same settle do not cover on every path (a forward must-store analysis over the comb units in settle order). That covers latches, the guarded units of
always @*and other processeslower_comb_processlowers (they compare against snapshots of their inputs), and feedback. It is per design, since an eager latch may read the outputs of the rest. The waits the scheduler checks never watch combinational outputs (they already fall back), which a debug assertion now states.All settles of the unit share one copy of combinational logic, entered with a continuation per call site, as the two settles did before.
Limitation: the SystemVerilog frontend builds no fused units, so an SV domain whose flip-flops read
always_comboutputs settles before it evaluates: the same number of settles as before. Fused units for SV would let it skip them.Validation
differentialtests (lib): newdeferred_settles_reach_their_readers(a domain whose next state isalways_comb, a delay kernel sampling a combinational output, a waiting kernel sampling it in the pass after the clock kernel changed it, host writes between runs; native and Cranelift),fused_domains_compute_what_they_read(Veryl, fused units),compiled_slots_fail_in_a_domain_as_the_reference($fatal),stateful_combinational_logic_settles_every_activation(analways_latchopened and closed between observers, a latch on a register-toggled gate, itsalways @*variant and a purealways @*); combinational outputs added to the kernel-$finish, delay-overflow and clock-overflow tests, whose state files must equal the reference's.$finish, state-keeping combinational logic) fails at least one of these tests.cargo test -p celox --features systemverilog --test systemverilog --test sv_update_eventsin the compiled, differential and differential-runs scheduler modes: 4,537 + 36 passed each;--lib218 passed; the timed-runtime integration tests (checkpoint, state_file, vcd, sv_vcd, simulation_step/stop/limits, time_state_and_delays, processes, tiered, tick_semantics, edge_api, …): all passed.node scripts/run-vtest.mjs --test systemverilog -E 'test(timing::)'withCELOX_SCHEDULER=differentialandcompiled: 656 passed each (a bogusCELOX_SCHEDULERvalue fails every case, so the mode reaches the executor).-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, same session:ac(64 registers, host clock, no kernels)b1(clock kernel, waiting stimulus kernel)b5(as b1, nonblocking stimulus)bh(host clock, waiting stimulus kernel)d(clock kernel only)bn(as b1, registers readalways_combnext state; local variant, not committed)out, which only the host reads: it now settles once per run instead of once per cycle.bn's domain reads combinational outputs and the SV frontend has no fused units, so it settles before the domain: once per cycle instead of twice (its comb also reads the stimulus, so master settled both before and after the domain).