D3D12.X: batch used-pipelines.txt writes off the bind lock #2635
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2635
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Decodere on GitHub · 2026-11-26 03:37 UTC · original
Decodere:fix-pso-async-batch-used-writes→main· +783 −26 · 3 files · 1 commits · openWhat 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 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_boundaryTested
1.9.2609.5,rustc 1.100.0, debug + releasecargo clippy --all-targets -- -A clippy::approx_constant: 0 new warnings or errors across all 3 modified files (pso_async.rs,host.rs,eh.rs)XCL_ADAPTER=warp,XCL_WARP=1):cargo test -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture->22 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.79 seach,0skipped)cargo test --release -p xcl --lib -- hle::d3d12x::pso_async:: --test-threads=4 --nocapture->22 passed, 0 failed, 0 ignored(3/3 consecutive runs,0.78–0.79 s,0skipped)cargo test --release -p xcl --lib -- hle::d3d12x::bind:: --test-threads=4 --nocapture->8 passed, 0 failed, 0 ignoredcargo test --release -p xcl --lib -- eh:: --test-threads=4 --nocapture->6 passed, 0 failed, 0 ignoredcargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture: 1443 passed, 0 failed, 47 ignored across 37 workspace test targets (SKIPPED GPU tests/subcases: wave64-only GPU tests on 32-lane RTX 4060, 3 per-lane wave32 driver-refused subcases,heap_window_out_of_memory_falls_back_to_the_switch_formwithoutXCL_HEAP_WINDOWS=1,pso_measurement_compiles_an_exact_synthetic_recordwithout Windows Developer Mode, and 3 debug-layer tests withoutd3d12SDKLayers.dll)Regression run
main:
PR:
Not tested
TerminateProcessfrom outside the process (which bypasses user-mode hooks andatexit).XCL_HEAP_WINDOWS=1, driver-cache-disabled PSO measurement), non-Windows / Wine hosts, and the 47#[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, and verification runs.bd9b400884toad798f3b5c@sage-sage on GitHub · 2026-11-26 05:18 UTC · original
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.
@Decodere on GitHub · 2026-11-26 05:18 UTC · original
@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!@KDenKC on GitHub · 2026-11-26 05:53 UTC · original
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.@luckyteagirl on GitHub · 2026-11-26 04:14 UTC · original · reviewed
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.ad798f3b5cto24e584cab1@Decodere on GitHub · 2026-11-26 06:56 UTC · original
@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).@KDenKC on GitHub · 2026-11-26 07:14 UTC · original
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.
24e584cab1to3dca5a093d@Decodere on GitHub · 2026-11-26 15:04 UTC · original
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).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.