D3D12.X: batch used-pipelines.txt writes off the bind lock #2625

Closed
Decodere wants to merge 1 commit from upstream-pr/2635 into main
Decodere commented 2026-11-26 03:37:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T03:37:42Z.


What is in it

Part of #2508
Part of #1833

pso_async::used::note() (crates/xcl/src/hle/d3d12x/pso_async.rs) previously ran synchronous create_dir_all, OpenOptions::open, and unbuffered writeln!(f, "{key:016x}") syscalls while holding the global used::now mutex on the title's command-recording / bind thread (Pending::note_use, called from resolve and resolve_wait_for). During world-load pipeline bursts, every newly used pipeline serialized bind threads behind disk I/O.

Changes (3 files: crates/xcl/src/hle/d3d12x/pso_async.rs, crates/xcl/src/host.rs, crates/xcl/src/eh.rs):

  • Extracted used::Journal backed by a single lightweight writer thread (xcl-pso-used), Mutex<JournalState>, wake_cv, and flushed_cv.
    • Journal::note(key) performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts into seen, appends to pending (continuing to queue keys while fallback_path is set even if writer spawn failed), and notifies wake_cv only on empty-to-nonempty (1) and burst-threshold (64) transitions. used::note(0) returns early before used::get(), avoiding OnceLock initialization and startup I/O on zero keys.
    • writer_loop coalesces bursts up to 25 ms (draining immediately at 64 unique keys), moves pending into in_flight (in_flight, in_flight_seq, in_flight_fallback_written) under the state lock before dropping it for I/O, lazily creates parent directories (only when absent) and opens used-pipelines.txt, performs a single batched write_all + flush, then clears in_flight and advances completed_seq = completed_seq.max(batch_seq). I/O failures clear the cached handle and never panic or break in-memory deduplication.
    • Kept if cfg!(test) isolated from the user's cache file (Journal::in_memory, with a test-only XCL_TEST_USED_STATIC_PATH env hook for subprocess exit verification) and left counts() un-flushed (present.rs calls it on PresentX).
  • Bounded initial lock and I/O paths, plus lossless accounting for batches already owned by the writer (addressing @Prime1997's #2572 review, @luckyteagirl's exit-flush review, and @KDenKC's follow-up review):
    • Added MAX_USED_FILE_BYTES = 16 MiB and read_used_bounded(path, max_bytes) in used::init_from_path and earlier_used_keys(), trimming any truncated tail back to the last newline so an oversized or truncated file cannot stall startup or parse a partial hex key.
    • Added lock_until(mutex, deadline) (try_lock loop with poison recovery, sleeping up to 1 ms slices until deadline) and poison recovery across all journal locks so Journal::flush_bounded(timeout) bounds both initial and post-fallback state-mutex acquisition and never deadlocks if another thread is suspended or wedged holding state during termination.
    • Journal::flush_bounded(timeout) accounts for writer-owned in_flight batches as well as pending: when timed out (e.g., xcl-pso-used blocked on the Windows loader lock during ExitProcess) or stopped, it drains both unwritten in_flight keys and pending keys to fallback_path and advances completed_seq only when append_to_path succeeds (restoring in_flight_fallback_written and pending on transient fallback failure, and leaving both untouched without advancing completed_seq when fallback_path is None).
    • Journal::shutdown(&self) flushes pending keys and joins xcl-pso-used through a shared &'static reference (Drop delegates to shutdown()), then drains any remaining unwritten in_flight (e.g., mid-batch writer panic where StopGuard marks writer_stopped) and pending keys to fallback_path.
    • Registered CRT atexit(on_process_exit) -> used::shutdown() when used::init_from_path initializes the file-backed static journal, wired pso_async::shutdown_used() on normal loader::run_main return in crates/xcl/src/host.rs, wired bounded pso_async::flush_used_bounded(500 ms) on the XCL_RUN_SECONDS watchdog thread (relocated below backend_before_guest() by #2844) before real::end_title(0) so a wedged writer cannot hang the watchdog, and wired pso_async::flush_used_bounded(100 ms) into crates/xcl/src/eh.rs::hk_nt_terminate_process alongside crate::log::flush().
  • Pure-CPU unit & subprocess tests in pso_async::used_tests:
    • used_note_does_not_block_on_slow_writer
    • used_burst_coalesces_writes_and_deduplicates_keys
    • used_flush_drop_lazy_file_and_io_error_are_graceful
    • used_static_once_lock_flushes_on_process_exit (normal / exit / explicit / bounded subprocess exit paths)
    • used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound
    • used_flush_bounded_respects_timeout_when_state_lock_is_held
    • used_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending (file-backed in-flight-only timeout, in-flight + pending timeout with monotonic completed_seq, non-fallback preservation, and mid-batch writer panic shutdown() recovery)
    • used_bounded_read_caps_oversized_file_on_line_boundary

(Rebased onto main 83b00818 to keep #2844's relocated XCL_RUN_SECONDS block below backend_before_guest() in crates/xcl/src/host.rs and #2976's XCL_PREPARE=0; patch diff is otherwise identical to 3dca5a09.)

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce RTX 4060 (8 GB, driver 621.14, 32-lane waves), Intel Core i5-11400F (6C/12T, 32 GB RAM), Windows 11, DXC 1.9.2609.5, rustc 1.100.0, debug + release
  • cargo clippy --all-targets -- -A clippy::approx_constant on rebased head aa2618e7: exit 0, 0 new warnings or errors across all 3 modified files (pso_async.rs, host.rs, eh.rs; only pre-existing upstream warnings in eh.rs and pso_async.rs's existing test module placement)
  • Post-rebase Debug WARP (XCL_ADAPTER=warp, XCL_WARP=1, --test-threads=1 --nocapture):
    • hle::d3d12x::pso_async:: -> 22 passed, 0 failed, 0 ignored (3/3 consecutive runs, 1.50–1.51 s, 0 runtime skips)
    • hle::d3d12x::bind:: -> 8 passed, 0 failed, 0 ignored (3/3 consecutive runs, 0.24–0.25 s, 0 runtime skips)
    • eh:: -> 6 passed, 0 failed, 0 ignored (3/3 consecutive runs, 0.02 s, 0 runtime skips)
  • Post-rebase Release RTX 4060 (--test-threads=1 --nocapture):
    • hle::d3d12x::pso_async:: -> 22 passed, 0 failed, 0 ignored (3/3 consecutive runs, 1.50 s, 0 runtime skips)
    • hle::d3d12x::bind:: -> 8 passed, 0 failed, 0 ignored (3/3 consecutive runs, 0.44–0.45 s, 0 runtime skips)
    • eh:: -> 6 passed, 0 failed, 0 ignored (3/3 consecutive runs, 0.02 s, 0 runtime skips)

Regression run

Paired quiet 60 s --release runs on desktop NVIDIA GeForce RTX 4060 with XCL_PREPARE=0 and XCL_NETWORK=0 (via scripts/smoke.ps1 -Seconds 60):

Baseline (main 83b008188efbf954b846667f48d75e3fa9310a01, XCL_PREPARE=0 XCL_NETWORK=0):

xcl-smoke v1
commit: 83b008188efbf954b846667f48d75e3fa9310a01
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1609 (PresentX 1609)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14027 MB

PR head (aa2618e7b5f305741c6b01d36776e265779a54af, XCL_PREPARE=0 XCL_NETWORK=0):

xcl-smoke v1
commit: aa2618e7b5f305741c6b01d36776e265779a54af
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1628 (PresentX 1628)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14050 MB

Not tested

  • Retail title mid-world-load PSO burst micro-benchmarks (the 60 s smoke run covers startup/intro/menus) and abrupt external TerminateProcess from outside the process (which bypasses user-mode hooks and atexit).
  • Startup shader precompilation (prepare_for_launch) was skipped in the paired 60 s smoke runs via XCL_PREPARE=0 (introduced by #2976); shaders compiled on demand during the run.
  • Did not re-run the full workspace suite after this 1-line rebase onto 83b00818 (only clippy --all-targets, targeted 3x Debug WARP + 3x Release RTX 4060 pso_async::/bind::/eh:: suites, and paired 60 s smokes ran on aa2618e7; full workspace 1443/0/47 ran on identical patch 3dca5a09).
  • Native wave64 GPUs, D3D12 debug layer SDK, non-Windows / Wine hosts, and #[ignore] tests.

AI use

  • Google Antigravity (Gemini 4 Neon) — authored the batched used::Journal writer, bounded initial lock/I/O paths (read_used_bounded, lock_until, XCL_RUN_SECONDS bounded flush), writer in-flight batch tracking and panic/timeout fallback recovery, process-exit flush/shutdown wiring (atexit, host::host_main, eh::hk_nt_terminate_process), unit and subprocess regression tests, rebase onto 83b00818, and verification runs.
<!-- greyfinch-sync:ivall/xcl:issue:5503537765 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T03:37:42Z. --- **What is in it** Part of #2508 Part of #1833 `pso_async::used::note()` (`crates/xcl/src/hle/d3d12x/pso_async.rs`) previously ran synchronous `create_dir_all`, `OpenOptions::open`, and unbuffered `writeln!(f, "{key:016x}")` syscalls while holding the global `used::now` mutex on the title's command-recording / bind thread (`Pending::note_use`, called from `resolve` and `resolve_wait_for`). During world-load pipeline bursts, every newly used pipeline serialized bind threads behind disk I/O. Changes (3 files: `crates/xcl/src/hle/d3d12x/pso_async.rs`, `crates/xcl/src/host.rs`, `crates/xcl/src/eh.rs`): - Extracted `used::Journal` backed by a single lightweight writer thread (`xcl-pso-used`), `Mutex<JournalState>`, `wake_cv`, and `flushed_cv`. - `Journal::note(key)` performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts into `seen`, appends to `pending` (continuing to queue keys while `fallback_path` is set even if writer spawn failed), and notifies `wake_cv` only on empty-to-nonempty (`1`) and burst-threshold (`64`) transitions. `used::note(0)` returns early before `used::get()`, avoiding `OnceLock` initialization and startup I/O on zero keys. - `writer_loop` coalesces bursts up to `25 ms` (draining immediately at `64` unique keys), moves `pending` into `in_flight` (`in_flight`, `in_flight_seq`, `in_flight_fallback_written`) under the state lock before dropping it for I/O, lazily creates parent directories (only when absent) and opens `used-pipelines.txt`, performs a single batched `write_all` + `flush`, then clears `in_flight` and advances `completed_seq = completed_seq.max(batch_seq)`. I/O failures clear the cached handle and never panic or break in-memory deduplication. - Kept `if cfg!(test)` isolated from the user's cache file (`Journal::in_memory`, with a test-only `XCL_TEST_USED_STATIC_PATH` env hook for subprocess exit verification) and left `counts()` un-flushed (`present.rs` calls it on `PresentX`). - Bounded initial lock and I/O paths, plus lossless accounting for batches already owned by the writer (addressing `@Prime1997`'s `#2572` review, `@luckyteagirl`'s exit-flush review, and `@KDenKC`'s follow-up review): - Added `MAX_USED_FILE_BYTES = 16 MiB` and `read_used_bounded(path, max_bytes)` in `used::init_from_path` and `earlier_used_keys()`, trimming any truncated tail back to the last newline so an oversized or truncated file cannot stall startup or parse a partial hex key. - Added `lock_until(mutex, deadline)` (`try_lock` loop with poison recovery, sleeping up to `1 ms` slices until `deadline`) and poison recovery across all journal locks so `Journal::flush_bounded(timeout)` bounds both initial and post-fallback state-mutex acquisition and never deadlocks if another thread is suspended or wedged holding `state` during termination. - `Journal::flush_bounded(timeout)` accounts for writer-owned `in_flight` batches as well as `pending`: when timed out (e.g., `xcl-pso-used` blocked on the Windows loader lock during `ExitProcess`) or stopped, it drains both unwritten `in_flight` keys and `pending` keys to `fallback_path` and advances `completed_seq` only when `append_to_path` succeeds (restoring `in_flight_fallback_written` and `pending` on transient fallback failure, and leaving both untouched without advancing `completed_seq` when `fallback_path` is `None`). - `Journal::shutdown(&self)` flushes pending keys and joins `xcl-pso-used` through a shared `&'static` reference (`Drop` delegates to `shutdown()`), then drains any remaining unwritten `in_flight` (e.g., mid-batch writer panic where `StopGuard` marks `writer_stopped`) and `pending` keys to `fallback_path`. - Registered CRT `atexit(on_process_exit)` -> `used::shutdown()` when `used::init_from_path` initializes the file-backed static journal, wired `pso_async::shutdown_used()` on normal `loader::run_main` return in `crates/xcl/src/host.rs`, wired bounded `pso_async::flush_used_bounded(500 ms)` on the `XCL_RUN_SECONDS` watchdog thread (relocated below `backend_before_guest()` by #2844) before `real::end_title(0)` so a wedged writer cannot hang the watchdog, and wired `pso_async::flush_used_bounded(100 ms)` into `crates/xcl/src/eh.rs::hk_nt_terminate_process` alongside `crate::log::flush()`. - Pure-CPU unit & subprocess tests in `pso_async::used_tests`: - `used_note_does_not_block_on_slow_writer` - `used_burst_coalesces_writes_and_deduplicates_keys` - `used_flush_drop_lazy_file_and_io_error_are_graceful` - `used_static_once_lock_flushes_on_process_exit` (`normal` / `exit` / `explicit` / `bounded` subprocess exit paths) - `used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound` - `used_flush_bounded_respects_timeout_when_state_lock_is_held` - `used_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending` (file-backed in-flight-only timeout, in-flight + pending timeout with monotonic `completed_seq`, non-fallback preservation, and mid-batch writer panic `shutdown()` recovery) - `used_bounded_read_caps_oversized_file_on_line_boundary` *(Rebased onto `main` `83b00818` to keep #2844's relocated `XCL_RUN_SECONDS` block below `backend_before_guest()` in `crates/xcl/src/host.rs` and #2976's `XCL_PREPARE=0`; patch diff is otherwise identical to `3dca5a09`.)* **Tested** - hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA GeForce RTX 4060 (8 GB, driver 621.14, 32-lane waves), Intel Core i5-11400F (6C/12T, 32 GB RAM), Windows 11, DXC `1.9.2609.5`, `rustc 1.100.0`, debug + release - `cargo clippy --all-targets -- -A clippy::approx_constant` on rebased head `aa2618e7`: exit `0`, `0` new warnings or errors across all 3 modified files (`pso_async.rs`, `host.rs`, `eh.rs`; only pre-existing upstream warnings in `eh.rs` and `pso_async.rs`'s existing test module placement) - Post-rebase Debug WARP (`XCL_ADAPTER=warp`, `XCL_WARP=1`, `--test-threads=1 --nocapture`): - `hle::d3d12x::pso_async::` -> `22 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `1.50–1.51 s`, `0` runtime skips) - `hle::d3d12x::bind::` -> `8 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `0.24–0.25 s`, `0` runtime skips) - `eh::` -> `6 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `0.02 s`, `0` runtime skips) - Post-rebase Release RTX 4060 (`--test-threads=1 --nocapture`): - `hle::d3d12x::pso_async::` -> `22 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `1.50 s`, `0` runtime skips) - `hle::d3d12x::bind::` -> `8 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `0.44–0.45 s`, `0` runtime skips) - `eh::` -> `6 passed, 0 failed, 0 ignored` (3/3 consecutive runs, `0.02 s`, `0` runtime skips) **Regression run** Paired quiet 60 s `--release` runs on desktop NVIDIA GeForce RTX 4060 with `XCL_PREPARE=0` and `XCL_NETWORK=0` (via `scripts/smoke.ps1 -Seconds 60`): Baseline (`main` `83b008188efbf954b846667f48d75e3fa9310a01`, `XCL_PREPARE=0 XCL_NETWORK=0`): ``` xcl-smoke v1 commit: 83b008188efbf954b846667f48d75e3fa9310a01 gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1609 (PresentX 1609) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14027 MB ``` PR head (`aa2618e7b5f305741c6b01d36776e265779a54af`, `XCL_PREPARE=0 XCL_NETWORK=0`): ``` xcl-smoke v1 commit: aa2618e7b5f305741c6b01d36776e265779a54af gpu: NVIDIA GeForce RTX 4060 title: 29640639 seconds: 60 exit: 0x0 frames shown: 1628 (PresentX 1628) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14050 MB ``` **Not tested** - Retail title mid-world-load PSO burst micro-benchmarks (the 60 s smoke run covers startup/intro/menus) and abrupt external `TerminateProcess` from outside the process (which bypasses user-mode hooks and `atexit`). - Startup shader precompilation (`prepare_for_launch`) was skipped in the paired 60 s smoke runs via `XCL_PREPARE=0` (introduced by #2976); shaders compiled on demand during the run. - Did not re-run the full workspace suite after this 1-line rebase onto `83b00818` (only `clippy --all-targets`, targeted 3x Debug WARP + 3x Release RTX 4060 `pso_async::`/`bind::`/`eh::` suites, and paired 60 s smokes ran on `aa2618e7`; full workspace `1443/0/47` ran on identical patch `3dca5a09`). - Native wave64 GPUs, D3D12 debug layer SDK, non-Windows / Wine hosts, and `#[ignore]` tests. **AI use** - Google Antigravity (Gemini 4 Neon) — authored the batched `used::Journal` writer, bounded initial lock/I/O paths (`read_used_bounded`, `lock_until`, `XCL_RUN_SECONDS` bounded flush), writer in-flight batch tracking and panic/timeout fallback recovery, process-exit flush/shutdown wiring (`atexit`, `host::host_main`, `eh::hk_nt_terminate_process`), unit and subprocess regression tests, rebase onto `83b00818`, and verification runs.
luckyteagirl commented 2026-11-26 04:14:55 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T04:14:55Z.

Review: COMMENTED


Used is held in a static OnceLock, so its Journal::Drop (which joins and drains the worker) does not run on ordinary process exit. After note() returns, the writer can wait up to COALESCE_WINDOW (25 ms) before opening/writing used-pipelines.txt; if the title exits during that window, those last-used keys are lost. The old synchronous path appended them before returning. Could the normal shutdown path explicitly flush/join this journal, and could a subprocess test record a key then exit without dropping a local Journal? The current drop test only covers a stack-owned journal.

<!-- greyfinch-sync:ivall/xcl:review:6068465427 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#pullrequestreview-6068465427). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T04:14:55Z. **Review:** COMMENTED --- `Used` is held in a `static OnceLock`, so its `Journal::Drop` (which joins and drains the worker) does not run on ordinary process exit. After `note()` returns, the writer can wait up to `COALESCE_WINDOW` (25 ms) before opening/writing `used-pipelines.txt`; if the title exits during that window, those last-used keys are lost. The old synchronous path appended them before returning. Could the normal shutdown path explicitly flush/join this journal, and could a subprocess test record a key then exit without dropping a local `Journal`? The current drop test only covers a stack-owned journal.
sage-sage commented 2026-11-26 06:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by sage-sage on 2026-11-26T05:18:03Z.


Test report: passes on NVIDIA. Exact head bd9b4008 (its base is current main b49be18, so head = merged).

Tested

  • RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build
  • cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three new used_tests pass
  • SKIPPED (29 lines, the same as on main on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dll not installed), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off)

Not tested

  • No game, so not the timing on a real first-bind burst.

Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:ivall/xcl:comment:7183362532 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183362532). Originally posted by [sage-sage](https://github.com/sage-sage) on 2026-11-26T05:18:03Z. --- **Test report: passes on NVIDIA.** Exact head `bd9b4008` (its base is current `main` `b49be18`, so head = merged). **Tested** - RTX 4080 SUPER (driver 621.40), Ryzen 5 7600X, Windows 11 26H2 build 26300.10075, rustc 1.100.0 MSVC, DXC 1.9.2602.17 (Windows SDK 10.0.26100), debug build - `cargo test --workspace -- --test-threads=4`: 1438 passed, 0 failed, 47 ignored; the three new `used_tests` pass - SKIPPED (29 lines, the same as on `main` on this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (`d3d12SDKLayers.dll` not installed), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off) **Not tested** - No game, so not the timing on a real first-bind burst. Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Decodere commented 2026-11-26 06:06:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T05:18:39Z.


@luckyteagirl Great catch — pushed ad798f3b addressing static OnceLock<Used> exit persistence across all Windows exit paths:

  • Wrapped Journal::writer in Mutex<Option<JoinHandle<()>>> so Journal::shutdown(&self) flushes pending keys and joins xcl-pso-used through the static reference (Drop delegates to shutdown()), and registered CRT atexit(on_process_exit) when used::init_from_path initializes the file-backed journal.
  • Wired pso_async::shutdown_used() into host::host_main on normal return and XCL_RUN_SECONDS (right before real::end_title(0) suspends threads / terminates), and wired pso_async::flush_used_bounded(100 ms) into eh::hk_nt_terminate_process alongside log::flush() with a direct-append fallback to used-pipelines.txt if xcl-pso-used is blocked on the Windows loader lock during a fast ExitProcess.
  • Added used_static_once_lock_flushes_on_process_exit (subprocess test with a 60 s coalesce window, no local Journal drop) covering normal process return (atexit), Win32 ExitProcess (eh::install_crash_handler + std::process::exit(0)), explicit shutdown_used(), and flush_used_bounded() (reproduced failing-first on bd9b4008, now 18/18 passing on WARP and RTX 4060). Thanks for the review!
<!-- greyfinch-sync:ivall/xcl:comment:7183371533 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183371533). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T05:18:39Z. --- @luckyteagirl Great catch — pushed `ad798f3b` addressing static `OnceLock<Used>` exit persistence across all Windows exit paths: - Wrapped `Journal::writer` in `Mutex<Option<JoinHandle<()>>>` so `Journal::shutdown(&self)` flushes pending keys and joins `xcl-pso-used` through the static reference (`Drop` delegates to `shutdown()`), and registered CRT `atexit(on_process_exit)` when `used::init_from_path` initializes the file-backed journal. - Wired `pso_async::shutdown_used()` into `host::host_main` on normal return and `XCL_RUN_SECONDS` (right before `real::end_title(0)` suspends threads / terminates), and wired `pso_async::flush_used_bounded(100 ms)` into `eh::hk_nt_terminate_process` alongside `log::flush()` with a direct-append fallback to `used-pipelines.txt` if `xcl-pso-used` is blocked on the Windows loader lock during a fast `ExitProcess`. - Added `used_static_once_lock_flushes_on_process_exit` (subprocess test with a 60 s coalesce window, no local `Journal` drop) covering normal process return (`atexit`), Win32 `ExitProcess` (`eh::install_crash_handler` + `std::process::exit(0)`), explicit `shutdown_used()`, and `flush_used_bounded()` (reproduced failing-first on `bd9b4008`, now 18/18 passing on WARP and RTX 4060). Thanks for the review!
KDenKC commented 2026-11-26 06:06:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T05:53:47Z.


Source review of head ad798f3b, no run. Two small things in the journal, both low impact today:

  1. completed_seq can go backwards (pso_async.rs, writer_loop: completed_seq = batch_seq). The writer takes batch 1 (batch_seq = 1) and is slow in write_batch. Meanwhile a new key arrives (enqueued_seq = 2), and flush_bounded times out, appends it itself and sets completed_seq = 2. The writer then finishes and stores 1. With pending empty and completed_seq < enqueued_seq, a later flush() waits forever. Today flush() is only called from tests, and the exit path is flush_bounded (with a timeout) followed by shutdown, which still joins. So this is a latent hang, not a live one. g.completed_seq = g.completed_seq.max(batch_seq); closes it.
  2. The spawn-failure fallback never has keys to write. with_sink sets writer_stopped = true when the thread fails to spawn, and note() returns early on writer_stopped. Nothing reaches pending, so the "or failed to spawn" branch in flush_bounded writes nothing and the run's keys are silently not recorded. If keys should survive that case, note() could still push while fallback_path is set.

Not tested: no build or run of this head on our side.

AI use: Gemini (Antigravity) did a first-pass review; Claude Code (Claude Opus 5.5) checked both points against the source at ad798f3b and wrote this.

<!-- greyfinch-sync:ivall/xcl:comment:7183902779 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7183902779). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-26T05:53:47Z. --- Source review of head `ad798f3b`, no run. Two small things in the journal, both low impact today: 1. **`completed_seq` can go backwards** (`pso_async.rs`, `writer_loop`: `completed_seq = batch_seq`). The writer takes batch 1 (`batch_seq = 1`) and is slow in `write_batch`. Meanwhile a new key arrives (`enqueued_seq = 2`), and `flush_bounded` times out, appends it itself and sets `completed_seq = 2`. The writer then finishes and stores `1`. With `pending` empty and `completed_seq < enqueued_seq`, a later `flush()` waits forever. Today `flush()` is only called from tests, and the exit path is `flush_bounded` (with a timeout) followed by `shutdown`, which still joins. So this is a latent hang, not a live one. `g.completed_seq = g.completed_seq.max(batch_seq);` closes it. 2. **The spawn-failure fallback never has keys to write.** `with_sink` sets `writer_stopped = true` when the thread fails to spawn, and `note()` returns early on `writer_stopped`. Nothing reaches `pending`, so the "or failed to spawn" branch in `flush_bounded` writes nothing and the run's keys are silently not recorded. If keys should survive that case, `note()` could still push while `fallback_path` is set. Not tested: no build or run of this head on our side. AI use: Gemini (Antigravity) did a first-pass review; Claude Code (Claude Opus 5.5) checked both points against the source at `ad798f3b` and wrote this.
Decodere commented 2026-11-26 07:03:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T06:56:57Z.


@KDenKC Good catches on both points — pushed 24e584ca addressing both:

  1. Monotonic completed_seq: writer_loop now stores g.completed_seq = g.completed_seq.max(batch_seq), so a slow batch completing after a timed-out flush_bounded() fallback drain can never regress completed_seq below enqueued_seq.
  2. Spawn-failure fallback: Journal::note() now continues queuing keys while fallback_path.is_some() even if writer_stopped is set, and Journal::shutdown() also drains any remaining pending keys to fallback_path so both flush_bounded() and shutdown() persist keys if xcl-pso-used fails to spawn.
  3. Added used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound covering both cases; re-verified release WARP & RTX 4060 pso_async:: (19/0/0), full release workspace (1440/0/47), and paired 60 s RTX 4060 smoke (1582 frames, 60 60 60, 0 removals/crashes).
<!-- greyfinch-sync:ivall/xcl:comment:7184941455 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7184941455). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T06:56:57Z. --- @KDenKC Good catches on both points — pushed `24e584ca` addressing both: 1. **Monotonic `completed_seq`:** `writer_loop` now stores `g.completed_seq = g.completed_seq.max(batch_seq)`, so a slow batch completing after a timed-out `flush_bounded()` fallback drain can never regress `completed_seq` below `enqueued_seq`. 2. **Spawn-failure fallback:** `Journal::note()` now continues queuing keys while `fallback_path.is_some()` even if `writer_stopped` is set, and `Journal::shutdown()` also drains any remaining `pending` keys to `fallback_path` so both `flush_bounded()` and `shutdown()` persist keys if `xcl-pso-used` fails to spawn. 3. Added `used_flush_bounded_timeout_and_spawn_failure_fallback_are_sound` covering both cases; re-verified release WARP & RTX 4060 `pso_async::` (`19/0/0`), full release workspace (`1440/0/47`), and paired 60 s RTX 4060 smoke (`1582` frames, `60 60 60`, `0` removals/crashes).
KDenKC commented 2026-11-26 08:04:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T07:14:26Z.


Checked at 24e584ca: writer_loop stores completed_seq.max(batch_seq), and note() keeps queuing while a fallback_path exists. Both points are addressed, thanks @Decodere.

AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.

<!-- greyfinch-sync:ivall/xcl:comment:7185244767 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7185244767). Originally posted by [KDenKC](https://github.com/KDenKC) on 2026-11-26T07:14:26Z. --- Checked at `24e584ca`: `writer_loop` stores `completed_seq.max(batch_seq)`, and `note()` keeps queuing while a `fallback_path` exists. Both points are addressed, thanks @Decodere. AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.
Decodere commented 2026-11-26 16:06:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T15:04:29Z.


Addressed @Prime1997's #2572 review item ("Bound initial lock/I/O paths and account for batches already owned by writer") in 3dca5a09:

  1. Bounded initial lock & I/O paths: Added MAX_USED_FILE_BYTES = 16 MiB and line-boundary read_used_bounded in used::init_from_path / earlier_used_keys(), restored if key == 0 { return; } before used::get() in used::note(), bounded Journal::flush_bounded initial and post-fallback state mutex acquisition via lock_until with poison recovery across journal locks, and switched the XCL_RUN_SECONDS watchdog in host.rs to flush_used_bounded(500 ms).
  2. Writer-owned in-flight batch accounting: Tracked active in_flight / in_flight_seq / in_flight_fallback_written in JournalState so timed-out flush_bounded calls and mid-batch writer-panic shutdown() persist both in-flight and pending keys to fallback_path, advancing completed_seq only on successful write (and preserving both untouched when fallback_path is None).
  3. Regression coverage: Added used_flush_bounded_respects_timeout_when_state_lock_is_held, used_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending, and used_bounded_read_caps_oversized_file_on_line_boundary; re-verified with 3x debug WARP & 3x release RTX 4060 pso_async:: (22/0/0), 0 new clippy warnings, full release workspace (1443/0/47), and refreshed 60 s RTX 4060 smoke against b49be183 (1554 frames, 60 60 60, 14003 MB, 0 rem/crash).
<!-- greyfinch-sync:ivall/xcl:comment:7195743331 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7195743331). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-26T15:04:29Z. --- Addressed `@Prime1997`'s `#2572` review item (*"Bound initial lock/I/O paths and account for batches already owned by writer"*) in [`3dca5a09`](https://github.com/xcl-dev/xcl/pull/2635/commits/3dca5a093dabd45f7933132694ef8be4e00df71f): 1. **Bounded initial lock & I/O paths:** Added `MAX_USED_FILE_BYTES = 16 MiB` and line-boundary `read_used_bounded` in `used::init_from_path` / `earlier_used_keys()`, restored `if key == 0 { return; }` before `used::get()` in `used::note()`, bounded `Journal::flush_bounded` initial and post-fallback `state` mutex acquisition via `lock_until` with poison recovery across journal locks, and switched the `XCL_RUN_SECONDS` watchdog in `host.rs` to `flush_used_bounded(500 ms)`. 2. **Writer-owned in-flight batch accounting:** Tracked active `in_flight` / `in_flight_seq` / `in_flight_fallback_written` in `JournalState` so timed-out `flush_bounded` calls and mid-batch writer-panic `shutdown()` persist both in-flight and pending keys to `fallback_path`, advancing `completed_seq` only on successful write (and preserving both untouched when `fallback_path` is `None`). 3. **Regression coverage:** Added `used_flush_bounded_respects_timeout_when_state_lock_is_held`, `used_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending`, and `used_bounded_read_caps_oversized_file_on_line_boundary`; re-verified with 3x debug WARP & 3x release RTX 4060 `pso_async::` (`22/0/0`), `0` new clippy warnings, full release workspace (`1443/0/47`), and refreshed 60 s RTX 4060 smoke against `b49be183` (`1554` frames, `60 60 60`, `14003 MB`, `0` rem/crash).
Decodere commented 2026-11-27 07:19:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T07:19:09Z.


Rebased cleanly onto main (83b008188efbf954b846667f48d75e3fa9310a01) at aa2618e7b5f305741c6b01d36776e265779a54af, keeping #2844's relocated XCL_RUN_SECONDS block below backend_before_guest() in crates/xcl/src/host.rs with bounded flush_used_bounded(500 ms) before real::end_title(0) alongside #2976's XCL_PREPARE=0 (git range-diff = = vs prior patch 3dca5a09).

Re-verified on the rebased head (rustc 1.100.0, DXC 1.9.2609.5, Windows 11, desktop NVIDIA RTX 4060):

  • cargo clippy --all-targets -- -A clippy::approx_constant: clean (0 new warnings across pso_async.rs, host.rs, eh.rs)
  • Debug WARP & Release RTX 4060 (3x each): pso_async:: 22/22, bind:: 8/8, eh:: 6/6 (0 failed, 0 ignored, 0 runtime skips)
  • Paired 60 s --release smoke runs with XCL_PREPARE=0 XCL_NETWORK=0 (83b00818 1609 frames / 14027 MB vs aa2618e7 1628 frames / 14050 MB, 0 device removals, 0 crashes)
  • CI checks (PR description, Build and test (Windows, no GPU)): passing (MERGEABLE / CLEAN)
<!-- greyfinch-sync:ivall/xcl:comment:7212355773 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7212355773). Originally posted by [Decodere](https://github.com/Decodere) on 2026-11-27T07:19:09Z. --- Rebased cleanly onto `main` (`83b008188efbf954b846667f48d75e3fa9310a01`) at `aa2618e7b5f305741c6b01d36776e265779a54af`, keeping #2844's relocated `XCL_RUN_SECONDS` block below `backend_before_guest()` in `crates/xcl/src/host.rs` with bounded `flush_used_bounded(500 ms)` before `real::end_title(0)` alongside #2976's `XCL_PREPARE=0` (`git range-diff` = `=` vs prior patch `3dca5a09`). Re-verified on the rebased head (`rustc 1.100.0`, DXC `1.9.2609.5`, Windows 11, desktop NVIDIA RTX 4060): - `cargo clippy --all-targets -- -A clippy::approx_constant`: clean (`0` new warnings across `pso_async.rs`, `host.rs`, `eh.rs`) - Debug WARP & Release RTX 4060 (`3x` each): `pso_async::` `22/22`, `bind::` `8/8`, `eh::` `6/6` (`0` failed, `0` ignored, `0` runtime skips) - Paired 60 s `--release` smoke runs with `XCL_PREPARE=0 XCL_NETWORK=0` (`83b00818` `1609` frames / `14027 MB` vs `aa2618e7` `1628` frames / `14050 MB`, `0` device removals, `0` crashes) - CI checks (`PR description`, `Build and test (Windows, no GPU)`): passing (`MERGEABLE` / `CLEAN`)
Foniass commented 2026-12-01 08:31:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:31:25Z.


Triage (#1607) – head aa2618e

main already moves the used-pipelines.txt writes off the bind lock. Commit 8f0bffe ("D3D12.X: journal used pipeline keys off bind threads") added hle/d3d12x/used_journal.rs: an xcl-pso-used writer thread with a 25 ms coalesce window and a 64-key batch. pso_async::flush_used_bounded is called from eh.rs:hk_nt_terminate_process and pso_async::shutdown_used from host.rs, the same hooks this PR adds. 8e3755a then kept pending keys when the writer stops. The PR's Journal in pso_async.rs duplicates that and conflicts with main.
Recommendation: close (superseded by main commits 8f0bffe and 8e3755a).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7305431014 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7305431014). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:31:25Z. --- **Triage (#1607)** – head aa2618e main already moves the `used-pipelines.txt` writes off the bind lock. Commit 8f0bffe ("D3D12.X: journal used pipeline keys off bind threads") added `hle/d3d12x/used_journal.rs`: an `xcl-pso-used` writer thread with a 25 ms coalesce window and a 64-key batch. `pso_async::flush_used_bounded` is called from `eh.rs:hk_nt_terminate_process` and `pso_async::shutdown_used` from `host.rs`, the same hooks this PR adds. 8e3755a then kept pending keys when the writer stops. The PR's `Journal` in `pso_async.rs` duplicates that and conflicts with main. Recommendation: close (superseded by main commits 8f0bffe and 8e3755a). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Decodere commented 2026-12-02 07:48:58 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T07:48:58Z.


Closing as superseded by main commits 8f0bffe5 (crates/xcl/src/hle/d3d12x/used_journal.rs) and 8e3755a1, which move used-pipelines.txt writes onto a dedicated background journal with bounded exit/termination flushes in eh.rs and host.rs. Thanks @Foniass, @Prime1997, and @luckyteagirl for the reviews and feedback. (AI note: verified with Antigravity, Gemini 4 Neon.)

<!-- greyfinch-sync:ivall/xcl:comment:7338644053 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2635#issuecomment-7338644053). Originally posted by [Decodere](https://github.com/Decodere) on 2026-12-02T07:48:58Z. --- Closing as superseded by `main` commits `8f0bffe5` (`crates/xcl/src/hle/d3d12x/used_journal.rs`) and `8e3755a1`, which move `used-pipelines.txt` writes onto a dedicated background journal with bounded exit/termination flushes in `eh.rs` and `host.rs`. Thanks @Foniass, @Prime1997, and @luckyteagirl for the reviews and feedback. (AI note: verified with Antigravity, Gemini 4 Neon.)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!2625
No description provided.