D3D12.X: batch used-pipelines.txt writes off the bind lock #2625
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2635"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 synchronouscreate_dir_all,OpenOptions::open, and unbufferedwriteln!(f, "{key:016x}")syscalls while holding the globalused::nowmutex on the title's command-recording / bind thread (Pending::note_use, called fromresolveandresolve_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):used::Journalbacked by a single lightweight writer thread (xcl-pso-used),Mutex<JournalState>,wake_cv, andflushed_cv.Journal::note(key)performs zero filesystem syscalls on the caller thread or under the state mutex: it inserts intoseen, appends topending(continuing to queue keys whilefallback_pathis set even if writer spawn failed), and notifieswake_cvonly on empty-to-nonempty (1) and burst-threshold (64) transitions.used::note(0)returns early beforeused::get(), avoidingOnceLockinitialization and startup I/O on zero keys.writer_loopcoalesces bursts up to25 ms(draining immediately at64unique keys), movespendingintoin_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 opensused-pipelines.txt, performs a single batchedwrite_all+flush, then clearsin_flightand advancescompleted_seq = completed_seq.max(batch_seq). I/O failures clear the cached handle and never panic or break in-memory deduplication.if cfg!(test)isolated from the user's cache file (Journal::in_memory, with a test-onlyXCL_TEST_USED_STATIC_PATHenv hook for subprocess exit verification) and leftcounts()un-flushed (present.rscalls it onPresentX).@Prime1997's#2572review,@luckyteagirl's exit-flush review, and@KDenKC's follow-up review):MAX_USED_FILE_BYTES = 16 MiBandread_used_bounded(path, max_bytes)inused::init_from_pathandearlier_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.lock_until(mutex, deadline)(try_lockloop with poison recovery, sleeping up to1 msslices untildeadline) and poison recovery across all journal locks soJournal::flush_bounded(timeout)bounds both initial and post-fallback state-mutex acquisition and never deadlocks if another thread is suspended or wedged holdingstateduring termination.Journal::flush_bounded(timeout)accounts for writer-ownedin_flightbatches as well aspending: when timed out (e.g.,xcl-pso-usedblocked on the Windows loader lock duringExitProcess) or stopped, it drains both unwrittenin_flightkeys andpendingkeys tofallback_pathand advancescompleted_seqonly whenappend_to_pathsucceeds (restoringin_flight_fallback_writtenandpendingon transient fallback failure, and leaving both untouched without advancingcompleted_seqwhenfallback_pathisNone).Journal::shutdown(&self)flushes pending keys and joinsxcl-pso-usedthrough a shared&'staticreference (Dropdelegates toshutdown()), then drains any remaining unwrittenin_flight(e.g., mid-batch writer panic whereStopGuardmarkswriter_stopped) andpendingkeys tofallback_path.atexit(on_process_exit)->used::shutdown()whenused::init_from_pathinitializes the file-backed static journal, wiredpso_async::shutdown_used()on normalloader::run_mainreturn incrates/xcl/src/host.rs, wired boundedpso_async::flush_used_bounded(500 ms)on theXCL_RUN_SECONDSwatchdog thread (relocated belowbackend_before_guest()by #2844) beforereal::end_title(0)so a wedged writer cannot hang the watchdog, and wiredpso_async::flush_used_bounded(100 ms)intocrates/xcl/src/eh.rs::hk_nt_terminate_processalongsidecrate::log::flush().pso_async::used_tests:used_note_does_not_block_on_slow_writerused_burst_coalesces_writes_and_deduplicates_keysused_flush_drop_lazy_file_and_io_error_are_gracefulused_static_once_lock_flushes_on_process_exit(normal/exit/explicit/boundedsubprocess exit paths)used_flush_bounded_timeout_and_spawn_failure_fallback_are_soundused_flush_bounded_respects_timeout_when_state_lock_is_heldused_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending(file-backed in-flight-only timeout, in-flight + pending timeout with monotoniccompleted_seq, non-fallback preservation, and mid-batch writer panicshutdown()recovery)used_bounded_read_caps_oversized_file_on_line_boundary(Rebased onto
main83b00818to keep #2844's relocatedXCL_RUN_SECONDSblock belowbackend_before_guest()incrates/xcl/src/host.rsand #2976'sXCL_PREPARE=0; patch diff is otherwise identical to3dca5a09.)Tested
1.9.2609.5,rustc 1.100.0, debug + releasecargo clippy --all-targets -- -A clippy::approx_constanton rebased headaa2618e7: exit0,0new warnings or errors across all 3 modified files (pso_async.rs,host.rs,eh.rs; only pre-existing upstream warnings ineh.rsandpso_async.rs's existing test module placement)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,0runtime skips)hle::d3d12x::bind::->8 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.24–0.25 s,0runtime skips)eh::->6 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.02 s,0runtime skips)--test-threads=1 --nocapture):hle::d3d12x::pso_async::->22 passed, 0 failed, 0 ignored(3/3 consecutive runs,1.50 s,0runtime skips)hle::d3d12x::bind::->8 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.44–0.45 s,0runtime skips)eh::->6 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.02 s,0runtime skips)Regression run
Paired quiet 60 s
--releaseruns on desktop NVIDIA GeForce RTX 4060 withXCL_PREPARE=0andXCL_NETWORK=0(viascripts/smoke.ps1 -Seconds 60):Baseline (
main83b008188efbf954b846667f48d75e3fa9310a01,XCL_PREPARE=0 XCL_NETWORK=0):PR head (
aa2618e7b5f305741c6b01d36776e265779a54af,XCL_PREPARE=0 XCL_NETWORK=0):Not tested
TerminateProcessfrom outside the process (which bypasses user-mode hooks andatexit).prepare_for_launch) was skipped in the paired 60 s smoke runs viaXCL_PREPARE=0(introduced by #2976); shaders compiled on demand during the run.83b00818(onlyclippy --all-targets, targeted 3x Debug WARP + 3x Release RTX 4060pso_async::/bind::/eh::suites, and paired 60 s smokes ran onaa2618e7; full workspace1443/0/47ran on identical patch3dca5a09).#[ignore]tests.AI use
used::Journalwriter, bounded initial lock/I/O paths (read_used_bounded,lock_until,XCL_RUN_SECONDSbounded 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 onto83b00818, and verification runs.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T04:14:55Z.
Review: COMMENTED
Usedis held in astatic OnceLock, so itsJournal::Drop(which joins and drains the worker) does not run on ordinary process exit. Afternote()returns, the writer can wait up toCOALESCE_WINDOW(25 ms) before opening/writingused-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 localJournal? The current drop test only covers a stack-owned journal.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 currentmainb49be18, so head = merged).Tested
cargo test --workspace -- --test-threads=4: 1438 passed, 0 failed, 47 ignored; the three newused_testspassmainon this machine): 21 wave64 tests (NVIDIA is wave32 only), 3 per-lane wave32 f16/f32 forms (refused), 3 D3D12 debug layer (d3d12SDKLayers.dllnot installed), 1no heap windows, 1pso_measurement_compiles_an_exact_synthetic_record(Developer Mode off)Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T05:18:39Z.
@luckyteagirl Great catch — pushed
ad798f3baddressing staticOnceLock<Used>exit persistence across all Windows exit paths:Journal::writerinMutex<Option<JoinHandle<()>>>soJournal::shutdown(&self)flushes pending keys and joinsxcl-pso-usedthrough the static reference (Dropdelegates toshutdown()), and registered CRTatexit(on_process_exit)whenused::init_from_pathinitializes the file-backed journal.pso_async::shutdown_used()intohost::host_mainon normal return andXCL_RUN_SECONDS(right beforereal::end_title(0)suspends threads / terminates), and wiredpso_async::flush_used_bounded(100 ms)intoeh::hk_nt_terminate_processalongsidelog::flush()with a direct-append fallback toused-pipelines.txtifxcl-pso-usedis blocked on the Windows loader lock during a fastExitProcess.used_static_once_lock_flushes_on_process_exit(subprocess test with a 60 s coalesce window, no localJournaldrop) covering normal process return (atexit), Win32ExitProcess(eh::install_crash_handler+std::process::exit(0)), explicitshutdown_used(), andflush_used_bounded()(reproduced failing-first onbd9b4008, now 18/18 passing on WARP and RTX 4060). Thanks for the review!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:completed_seqcan go backwards (pso_async.rs,writer_loop:completed_seq = batch_seq). The writer takes batch 1 (batch_seq = 1) and is slow inwrite_batch. Meanwhile a new key arrives (enqueued_seq = 2), andflush_boundedtimes out, appends it itself and setscompleted_seq = 2. The writer then finishes and stores1. Withpendingempty andcompleted_seq < enqueued_seq, a laterflush()waits forever. Todayflush()is only called from tests, and the exit path isflush_bounded(with a timeout) followed byshutdown, which still joins. So this is a latent hang, not a live one.g.completed_seq = g.completed_seq.max(batch_seq);closes it.with_sinksetswriter_stopped = truewhen the thread fails to spawn, andnote()returns early onwriter_stopped. Nothing reachespending, so the "or failed to spawn" branch inflush_boundedwrites nothing and the run's keys are silently not recorded. If keys should survive that case,note()could still push whilefallback_pathis 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
ad798f3band wrote this.Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T06:56:57Z.
@KDenKC Good catches on both points — pushed
24e584caaddressing both:completed_seq:writer_loopnow storesg.completed_seq = g.completed_seq.max(batch_seq), so a slow batch completing after a timed-outflush_bounded()fallback drain can never regresscompleted_seqbelowenqueued_seq.Journal::note()now continues queuing keys whilefallback_path.is_some()even ifwriter_stoppedis set, andJournal::shutdown()also drains any remainingpendingkeys tofallback_pathso bothflush_bounded()andshutdown()persist keys ifxcl-pso-usedfails to spawn.used_flush_bounded_timeout_and_spawn_failure_fallback_are_soundcovering both cases; re-verified release WARP & RTX 4060pso_async::(19/0/0), full release workspace (1440/0/47), and paired 60 s RTX 4060 smoke (1582frames,60 60 60,0removals/crashes).Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T07:14:26Z.
Checked at
24e584ca:writer_loopstorescompleted_seq.max(batch_seq), andnote()keeps queuing while afallback_pathexists. Both points are addressed, thanks @Decodere.AI use: Claude Code (Claude Opus 5.5) checked the source and wrote this.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T15:04:29Z.
Addressed
@Prime1997's#2572review item ("Bound initial lock/I/O paths and account for batches already owned by writer") in3dca5a09:MAX_USED_FILE_BYTES = 16 MiBand line-boundaryread_used_boundedinused::init_from_path/earlier_used_keys(), restoredif key == 0 { return; }beforeused::get()inused::note(), boundedJournal::flush_boundedinitial and post-fallbackstatemutex acquisition vialock_untilwith poison recovery across journal locks, and switched theXCL_RUN_SECONDSwatchdog inhost.rstoflush_used_bounded(500 ms).in_flight/in_flight_seq/in_flight_fallback_writteninJournalStateso timed-outflush_boundedcalls and mid-batch writer-panicshutdown()persist both in-flight and pending keys tofallback_path, advancingcompleted_seqonly on successful write (and preserving both untouched whenfallback_pathisNone).used_flush_bounded_respects_timeout_when_state_lock_is_held,used_flush_bounded_persists_writer_in_flight_batch_and_preserves_non_fallback_pending, andused_bounded_read_caps_oversized_file_on_line_boundary; re-verified with 3x debug WARP & 3x release RTX 4060pso_async::(22/0/0),0new clippy warnings, full release workspace (1443/0/47), and refreshed 60 s RTX 4060 smoke againstb49be183(1554frames,60 60 60,14003 MB,0rem/crash).Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T07:19:09Z.
Rebased cleanly onto
main(83b008188efbf954b846667f48d75e3fa9310a01) ataa2618e7b5f305741c6b01d36776e265779a54af, keeping #2844's relocatedXCL_RUN_SECONDSblock belowbackend_before_guest()incrates/xcl/src/host.rswith boundedflush_used_bounded(500 ms)beforereal::end_title(0)alongside #2976'sXCL_PREPARE=0(git range-diff==vs prior patch3dca5a09).Re-verified on the rebased head (
rustc 1.100.0, DXC1.9.2609.5, Windows 11, desktop NVIDIA RTX 4060):cargo clippy --all-targets -- -A clippy::approx_constant: clean (0new warnings acrosspso_async.rs,host.rs,eh.rs)3xeach):pso_async::22/22,bind::8/8,eh::6/6(0failed,0ignored,0runtime skips)--releasesmoke runs withXCL_PREPARE=0 XCL_NETWORK=0(83b008181609frames /14027 MBvsaa2618e71628frames /14050 MB,0device removals,0crashes)PR description,Build and test (Windows, no GPU)): passing (MERGEABLE/CLEAN)Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:31:25Z.
Triage (#1607) – head
aa2618emain already moves the
used-pipelines.txtwrites off the bind lock. Commit8f0bffe("D3D12.X: journal used pipeline keys off bind threads") addedhle/d3d12x/used_journal.rs: anxcl-pso-usedwriter thread with a 25 ms coalesce window and a 64-key batch.pso_async::flush_used_boundedis called fromeh.rs:hk_nt_terminate_processandpso_async::shutdown_usedfromhost.rs, the same hooks this PR adds.8e3755athen kept pending keys when the writer stops. The PR'sJournalinpso_async.rsduplicates that and conflicts with main.Recommendation: close (superseded by main commits
8f0bffeand8e3755a).AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Decodere on 2026-12-02T07:48:58Z.
Closing as superseded by
maincommits8f0bffe5(crates/xcl/src/hle/d3d12x/used_journal.rs) and8e3755a1, which moveused-pipelines.txtwrites onto a dedicated background journal with bounded exit/termination flushes ineh.rsandhost.rs. Thanks @Foniass, @Prime1997, and @luckyteagirl for the reviews and feedback. (AI note: verified with Antigravity, Gemini 4 Neon.)Pull request closed