Repository navigation
feat(cli)!: checkpoint SystemVerilog runs on SIGUSR1 - #2134
Conversation
|
This pull request is part of a Mergify stack:
|
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: ba4eeda0ae
ℹ️ 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".
| let mut simulation = builder | ||
| .$build() | ||
| .map_err(|error| format!("compilation failed:\n{error}"))?; | ||
| report_warnings(simulation.warnings())?; | ||
| let saves = StateSaves::new(&simulation, &arguments.design.top, &arguments.save_state)?; | ||
| if let Some(path) = &arguments.save_state.restore_checkpoint { |
There was a problem hiding this comment.
Suppress declaration effects before restoring a checkpoint
When a design has a declaration initializer such as int fd = $fopen("output.log", "w");, resuming a checkpoint truncates the existing output before restoring anything. The builder calls Simulation::try_new, which executes static declaration initializers through initialize_declarations (crates/celox/src/simulation.rs:462), so calling system_checkpoint::restore afterward is too late to prevent those external effects. Restoring the saved file handler does not repair the host file unless another write occurs, contradicting the documented guarantee that restore leaves already delivered output intact. Build the restore target without executing declaration effects, or defer those effects until the checkpoint has been installed.
Useful? React with 👍 / 👎.
| if !mode.truncate { | ||
| match File::open(&path) { | ||
| Ok(mut source) => { | ||
| io::copy(&mut source, &mut file)?; | ||
| } | ||
| Err(error) if mode.create && error.kind() == io::ErrorKind::NotFound => {} | ||
| Err(error) => return Err(error), |
There was a problem hiding this comment.
Preserve append access to write-only files
For an existing file that the simulation user can write but cannot read, $fopen(path, "a") now fails: the initial host open succeeds, but this unconditional File::open requires read permission to populate the working copy. The previous HostFileSystem only requested the permissions specified by the HDL mode, so this breaks otherwise valid testbenches on Unix even when no checkpoint is requested, because the new handler is enabled by default. Preserve write-only append behavior rather than introducing an implicit read-permission requirement.
Useful? React with 👍 / 👎.
| time: u64, | ||
| core: Vec<u8>, | ||
| file_effects: celox_runtime::file_io::FileIoSnapshot, |
There was a problem hiding this comment.
Include the accumulated failure status in CLI checkpoints
If a testbench reports $error or a nonfatal assertion failure before a signal checkpoint and then finishes normally after restoration, the resumed command incorrectly exits successfully. drain_sv_output consumes the error event and records it only in the local failed flag in simulate_sv; this container captures neither that flag nor any equivalent CLI outcome state, and the resumed invocation initializes failed to false. Consequently, checkpointing and resuming can turn a failing experiment into a passing one. Serialize the accumulated failure status alongside the core and file effects, and restore it into the CLI execution loop.
Useful? React with 👍 / 👎.
| if !self.files.contains_key(&path) { | ||
| let mut file = tempfile::tempfile()?; |
There was a problem hiding this comment.
Share working contents between hard-linked file paths
When a testbench opens two hard-linked paths to the same regular file, each path gets a separate temporary working copy because canonicalize does not merge hard links and files is keyed by pathname. Opening both paths, writing through one descriptor, and reading through the other therefore returns stale bytes, even though the host file has been updated and the previous HostFileSystem would expose the write through both descriptors. This changes simulation results in ordinary runs without any checkpoint request. Track shared file identity separately from pathname and preserve that relationship in snapshots so aliases use the same working contents.
Useful? React with 👍 / 👎.
|
Queued — the merge queue status continues in this comment ↓. |
ba4eeda to
7960e41
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7960e41ec5
ℹ️ 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".
| fn close(&mut self, id: u64) -> io::Result<()> { | ||
| self.live_files.remove(&id); | ||
| self.streams | ||
| .remove(&id) | ||
| .ok_or_else(|| io::Error::other("closed file effect handle"))?; |
There was a problem hiding this comment.
Release working-file descriptors when HDL files are closed
On Unix, a testbench that sequentially opens and closes many distinct files eventually exhausts the process's file-descriptor limit even though it keeps only one HDL file open at a time. This method removes the stream but leaves every regular file's temporary File open in self.files, so descriptor usage grows with all paths ever encountered rather than currently open files. Because CheckpointFs is enabled by default, this also breaks ordinary runs that never request a checkpoint; the previous HostFileSystem::close released its file. Retain closed working contents in storage that can be reopened lazily, or otherwise bound the number of retained OS descriptors.
Useful? React with 👍 / 👎.
| core: Vec<u8>, | ||
| file_effects: celox_runtime::file_io::FileIoSnapshot, |
There was a problem hiding this comment.
Preserve source-driven waveform state in CLI checkpoints
When a testbench executes $dumpfile and $dumpvars before the signal checkpoint, resuming in a fresh process silently stops producing waveform output. Those tasks configure Simulator::sv_vcd and vcd_writer directly (simulation/vcd_tasks.rs), outside FileIo, and neither the core checkpoint nor this container saves them. The restored initial process has already passed the dump setup, while the fresh simulator retains its default empty VCD configuration, so subsequent steps and even $dumpon cannot continue the trace. Include the source-driven waveform configuration and a safe output-reconnection policy, or reject capture for this unsupported state instead of reporting a successfully resumable system checkpoint.
Useful? React with 👍 / 👎.
7960e41 to
c626196
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c626196b94
ℹ️ 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".
| if initialize { | ||
| state.initialize_declarations(&mut simulator)?; | ||
| // Before the first slot, sample declared or default values. | ||
| state.sample_values(&mut simulator.backend); |
There was a problem hiding this comment.
Sample initialized values when deferred startup actually runs
When a Rust host builds with .defer_initialization(true) and then steps without loading a checkpoint, declaration initializers run in SimulationState::step_time, but the initial sample_values call skipped here is never performed. Sampling on later time advances does not cover the time-zero slot. Consequently, an initializer such as int a = $test$plusargs("on"); followed by initial observed = $sampled(a); can observe the default sampled value instead of the initialized value, unlike an eagerly initialized simulation. Perform the initial sampling after pending declaration initialization completes, while preserving saved samples when restoring a checkpoint.
Useful? React with 👍 / 👎.
| let mut output = OpenOptions::new() | ||
| .write(true) | ||
| .append(stream.append) | ||
| .open(&stream.path)?; |
There was a problem hiding this comment.
Preserve open-file identity when publishing ordinary writes
On Unix, if an output file is renamed or unlinked after $fopen, each subsequent write now reopens its pathname instead of writing to the originally opened file. Unlinking therefore makes writes fail, while rotating the file and creating a replacement causes simulation output to overwrite the replacement rather than continue into the original file. The previous HostFileSystem retained the opened File, so neither regression occurred. Because this handler is enabled by default, ordinary runs are affected even without checkpoint capture or restore. Preserve the host handle's identity for active ordinary streams rather than resolving the pathname again for each write.
Useful? React with 👍 / 👎.
| let mut saves = StateSaves::new( | ||
| &simulation, | ||
| &arguments.design.top, | ||
| &arguments.save_state, | ||
| signal, |
There was a problem hiding this comment.
Restore scheduled-save bookkeeping with the simulation
When resuming with the same scheduled-save options, constructing a fresh StateSaves resets the cycle count and repopulates already-consumed save requests. For example, restoring a checkpoint at time 10 with --save-state-at-time 5 makes StateSaves::before save the restored time-10 state as time-5.state; StateSaves::save uses std::fs::write, so this silently overwrites the correct artifact from the original run. Cycle-based saves likewise restart their numbering, producing states at the wrong cycles or reporting that a previously reached cycle was never reached. Persist and restore the consumed requests and cycle-counting state rather than restoring only the accumulated failure flag.
Useful? React with 👍 / 👎.
On Unix, celox run accepts SIGUSR1 by default and saves a resumable CLI system checkpoint at the next complete simulation boundary while continuing execution. Use --no-checkpoint-on-signal to opt out, --save-state-dir for the destination, and --restore-checkpoint to resume a trusted artifact with the same design and options. The CLI composes core execution bytes with its file-effect handler, source waveform controls and accumulated assertion/error outcome. Handler state remains outside the core checkpoint. Restore targets defer initialization so declaration effects do not truncate previously delivered files. If stepped without restore, pending startup initializes sampled copies and history defaults after declarations (IEEE 1800-2023 16.5.1); restoring completed startup preserves saved samples, and a previously reported failure stays failed after resume. Pending scheduled saves, cycle counts and edge baselines are restored as CLI state, so consumed saves are not replayed. The restored schedule is authoritative; output directory and signal registration are local invocation options. The file handler keeps a disk-backed working view keyed by normalized path. Temporary contents reopen only during operations, bounding OS descriptor use even after many files have been closed or restored. Different paths, including hard links to the same host file, have independent views; callers coordinate aliases. Active output streams retain their original host handle until close, preserving writes across rename/unlink without inferring aliases. Restored streams reconnect to their recorded paths lazily; subsequent writes publish the restored branch without retracting previously delivered output during restore. Write-only append retains its unreadable prefix externally without requiring read permission. Standard streams, pipes and devices remain live external channels. Source-driven waveform recording resumes into a unique <original-name>.resume-<id>.vcd segment beside the original trace. Each segment preserves selected signals and dump controls, begins at the restored time, and has a fresh per-file byte-limit budget. Rust hosts can separately capture SourceWaveformState and choose their new output destination. Original traces are not overwritten. The signal handler only sets an atomic flag. Saves use checksummed containers and no-clobber publication; repeated pending signals coalesce. Save failures report to stderr without terminating the run. Validation: 284 Rust regressions passed (CLI, core checkpoint, declaration startup, sampled values, history and VCD), plus 24 NAPI/JS checkpoint/timing tests with a rebuilt addon. Coverage includes separate-process resume on interpreter, native, tiered, Cranelift and WASM; delayed-startup sampling and saved-sample preservation; scheduled saves across high/low clock phases; rename/unlink output behavior; 128 closed files with descriptor limit 64; waveform controls. Formatting and affected-crate clippy passed. BREAKING CHANGE: SimulatorOptions gains defer_initialization. Explicit options literals must initialize it or use ..Default::default(). The default preserves eager timed initialization. Change-Id: I262b57df801bf7309e6858f55dc52f84440851f8
c626196 to
a2237aa
Compare
Merge Queue Status
This pull request spent 34 minutes 51 seconds in the queue, including 32 minutes 58 seconds running CI. Required conditions to merge
|
Give each dynamic process execution its own deferred assertion report queue. Event/wait resumption flushes only that process; disable fork cancels live children's reports, while natural completion preserves reports across slot reuse. Keep owner context around kernel and host-request execution, including error and stop paths, without changing the backend event ring ABI. Host-owned monotonic identities stay outside core checkpoints. Core restore starts fresh ownership without withdrawing host reports; mirror copies queues and identities together. Resolve deferred string arguments consumed by the raw drain before heap replacement or collection. Failed portable loads restore the previous ownership context. Preserve conservative lost-fatal handling for ordinary multi-queue contexts while a dynamic process flush clears its loss. Mature Observed reports before Reactive program work, so a later wakeup cannot flush them; keep Final reports flushable until Postponed. Actions remain single display/severity calls. Distinguish assert/assume/cover final from actual final procedures in the shared timed-case validator. Validation: 1,112 timing tests, all 104 deferred-assertion API tests, six host ownership/raw-drain/restore units, 20 state-file API regressions, 32 suite units, four retained-report tests and nine Node report tests passed. The nine new shared cases pass 55 registered backend tests (native, native-image, native-parallel, Cranelift, Cranelift-parallel, WASM, plus an actual interpreter loop). Runtime units passed all 78 tests. Affected all-target clippy and formatting passed. Debug NAPI built and all nine tests in the timing, cascaded clock and runtime-event JS consumer files passed. Direct SystemVerilog fork semantics are verified through Rust Simulation; the JS bridge has no SV-input API. External observations remain failures, with exact reviewed records: xezim 0.11.3 has 2 passes and 7 mismatches; Verilator 5.052 has 2 passes, 3 mismatches, 3 compiler faults and 1 unsupported four-state case; Icarus 13.0 rejects all 9 with unsupported-deferred-assertion diagnostics. A standalone xezim #0 probe reproduces missing reports against IEEE 1800-2023 16.4.1/16.4.2. No exclusions or passing expectations replace these failures. Rebased onto master 9261b31 after #2146, #2149 and #2134. Preserve both function-fork and deferred-fork registrations and retained evidence. Post-sync validation passed 1,149 timing tests, 104 deferred API tests, six host units, 20 final-procedure tests, 20 state-file tests, four retained report tests and nine Node report tests, plus affected all-target clippy and formatting. Runtime ownership and Observed/Reactive logic are unchanged by conflict resolution; external fixtures and adapters are unchanged. Completes deferred assertion composition portion of #2111. Change-Id: I919ac183ed4c78ec100696954402308a01cb64ee
Give each dynamic process execution its own deferred assertion report queue. Event/wait resumption flushes only that process; disable fork cancels live children's reports, while natural completion preserves reports across slot reuse. Keep owner context around kernel and host-request execution, including error and stop paths, without changing the backend event ring ABI. Host-owned monotonic identities stay outside core checkpoints. Core restore starts fresh ownership without withdrawing host reports; mirror copies queues and identities together. Resolve deferred string arguments consumed by the raw drain before heap replacement or collection. Failed portable loads restore the previous ownership context. Preserve conservative lost-fatal handling for ordinary multi-queue contexts while a dynamic process flush clears its loss. Mature Observed reports before Reactive program work, so a later wakeup cannot flush them; keep Final reports flushable until Postponed. Actions remain single display/severity calls. Distinguish assert/assume/cover final from actual final procedures in the shared timed-case validator. Validation: 1,112 timing tests, all 104 deferred-assertion API tests, six host ownership/raw-drain/restore units, 20 state-file API regressions, 32 suite units, four retained-report tests and nine Node report tests passed. The nine new shared cases pass 55 registered backend tests (native, native-image, native-parallel, Cranelift, Cranelift-parallel, WASM, plus an actual interpreter loop). Runtime units passed all 78 tests. Affected all-target clippy and formatting passed. Debug NAPI built and all nine tests in the timing, cascaded clock and runtime-event JS consumer files passed. Direct SystemVerilog fork semantics are verified through Rust Simulation; the JS bridge has no SV-input API. External observations remain failures, with exact reviewed records: xezim 0.11.3 has 2 passes and 7 mismatches; Verilator 5.052 has 2 passes, 3 mismatches, 3 compiler faults and 1 unsupported four-state case; Icarus 13.0 rejects all 9 with unsupported-deferred-assertion diagnostics. A standalone xezim #0 probe reproduces missing reports against IEEE 1800-2023 16.4.1/16.4.2. No exclusions or passing expectations replace these failures. Rebased onto master 9261b31 after #2146, #2149 and #2134. Preserve both function-fork and deferred-fork registrations and retained evidence. Post-sync validation passed 1,149 timing tests, 104 deferred API tests, six host units, 20 final-procedure tests, 20 state-file tests, four retained report tests and nine Node report tests, plus affected all-target clippy and formatting. Runtime ownership and Observed/Reactive logic are unchanged by conflict resolution; external fixtures and adapters are unchanged. Completes deferred assertion composition portion of #2111. Latest master synchronization preserves compound-event tests and retained report entries. Revalidated 83 fork/deferred integration tests, all 104 deferred assertion API tests, 49 focused deferred tests including host units, four retained-report tests and seven report script tests. Affected-crate Clippy and formatting pass. Change-Id: I919ac183ed4c78ec100696954402308a01cb64ee
On Unix, celox run accepts SIGUSR1 by default and saves a resumable CLI system checkpoint at the next complete simulation boundary while continuing execution. Use --no-checkpoint-on-signal to opt out, --save-state-dir for the destination, and --restore-checkpoint to resume a trusted artifact with the same design and options.
The CLI composes core execution bytes with its file-effect handler, source waveform controls and accumulated assertion/error outcome. Handler state remains outside the core checkpoint. Restore targets defer initialization so declaration effects do not truncate previously delivered files. If stepped without restore, pending startup initializes sampled copies and history defaults after declarations (IEEE 1800-2023 16.5.1); restoring completed startup preserves saved samples, and a previously reported failure stays failed after resume. Pending scheduled saves, cycle counts and edge baselines are restored as CLI state, so consumed saves are not replayed. The restored schedule is authoritative; output directory and signal registration are local invocation options.
The file handler keeps a disk-backed working view keyed by normalized path. Temporary contents reopen only during operations, bounding OS descriptor use even after many files have been closed or restored. Different paths, including hard links to the same host file, have independent views; callers coordinate aliases. Active output streams retain their original host handle until close, preserving writes across rename/unlink without inferring aliases. Restored streams reconnect to their recorded paths lazily; subsequent writes publish the restored branch without retracting previously delivered output during restore. Write-only append retains its unreadable prefix externally without requiring read permission. Standard streams, pipes and devices remain live external channels.
Source-driven waveform recording resumes into a unique .resume-.vcd segment beside the original trace. Each segment preserves selected signals and dump controls, begins at the restored time, and has a fresh per-file byte-limit budget. Rust hosts can separately capture SourceWaveformState and choose their new output destination. Original traces are not overwritten.
The signal handler only sets an atomic flag. Saves use checksummed containers and no-clobber publication; repeated pending signals coalesce. Save failures report to stderr without terminating the run.
Validation: 284 Rust regressions passed (CLI, core checkpoint, declaration startup, sampled values, history and VCD), plus 24 NAPI/JS checkpoint/timing tests with a rebuilt addon. Coverage includes separate-process resume on interpreter, native, tiered, Cranelift and WASM; delayed-startup sampling and saved-sample preservation; scheduled saves across high/low clock phases; rename/unlink output behavior; 128 closed files with descriptor limit 64; waveform controls. Formatting and affected-crate clippy passed.
BREAKING CHANGE: SimulatorOptions gains defer_initialization. Explicit options literals must initialize it or use ..Default::default(). The default preserves eager timed initialization.