D3D12.X: a worker waiting for a big compile turn leaves the queue to a helper #2618
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2628"
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 KOLESNiii on 2026-11-26T03:10:35Z.
A huge driver compile on an
xcl-psoworker waits inbig_compile_turnfor one of the few slots (one at a time by default, 3 GB of free commit each), and it keeps its worker thread while it waits. When the retail title of #505 starts its world, every worker takes one of the title's huge compute programs and waits there, with only one or two of them compiling, so the rest of the queue has no worker. With this change, a pool thread that has to wait gets a helper thread in its place (a helper that parks too gets one of its own, up to 4 helpers per worker), so as many threads as the pool has keep serving the queue. A helper leaves once a parked thread is back. The slots and the commit check are unchanged, so no more driver compiles run at once than before. This is not "more workers" in the sense #2088 warns against.On the retail title of #505, this does not measurably speed up pipeline builds on my machine (see Tested): the PR fixes the stall that the test reproduces, not the title's long wait for frames.
Part of #1269, #2088 (scheduling).
What is in it
crates/xcl/src/hle/d3d12x/pso_async.rs:Mutex+Condvarholding the work and the counts of parked workers and helpers, instead of anmpscchannel. Nobody holds the lock while waiting for work.parked()returns a guard. On a pool worker it counts the worker as parked and starts a helper (xcl-pso-h{n}, numbered in start order) while there are fewer helpers than parked threads (workers and helpers), up toMOST_HELPERS_PER_WORKER(4) × the pool size. Off the pool, it does nothing.workers_parked_for_big_compiles_leave_the_queue_to_helpers: parks every worker and as many helpers, checks that a job queued behind them still runs, and that the counts return to 0 with no new work; twice. Without the change, that job never runs; with the helpers capped at the pool size, it fails too.parked_outside_the_pool_starts_no_helper.crates/xcl/src/hle/d3d12x/real.rs:big_compile_turntakes the guard before its first wait (outside the slots' lock) and holds it until it gets its slot.Tested
cargo test --workspace -- --test-threads=4on8cdbc6c(the same tree as the head16bf648, which only changes the commit message): 1431 passed, 0 failed, 47 ignored; 25SKIPPEDchecks: 21 "no wave64", 3 f16 per-lane forms refused (#1426), 1 "no heap windows"cargo test -p xcl --lib parked, 30 runs withXCL_DXC_THREADS1, 2 and 3: 0 failures.main08db802and8cdbc6c:Setup:
XCL_DXIL_CACHEShaderCacheControlcall, the same in both trees, not in this PR)XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_TRACE=1Results, one run each, from
xcl.log. The world load started at 314 s in themainrun and at 184 s in this PR's, so themainlog covers only 464 s after it, and the table stops at 420 s:mainHelpers start, but the build rate is the same within run-to-run noise. Frames do not come back after the world load in either run. Most of the title's own waiting is graphics pipelines built at a draw's first bind, which #1798 addresses. An earlier A/B of the first version of this PR (helpers capped at the pool size) showed +7 % builds over 600 s; that window does not fit both runs here, and with one run each it may have been noise.
Regression run
main:This PR:
Not tested
mainhas moved by 17 commits since08db802. The PR merges into it without conflicts, but it was not rebased or rerun on it.AI use
🤖 Generated with Claude Code
https://claude.ai/code/session_015csBcd63KUE2T1kW2P15nC
Imported from ivall/xcl. Originally posted by GodlyBDS on 2026-11-26T03:25:56Z.
Independent Ampere trace relevant to the worker-gate change. RTX 3090 Ti, driver 621.40, Windows 10, 32 GiB RAM. This was
e877812efrom #2624 with the local Windows startup compatibility fixes, four named PSO workers,XCL_HUGE_PSO_CONCURRENCY=1, and on-demand compilation. I have not applied #2628 to this run.For 31 gated compute compiles completing from 225 to 380 s, the median recorded gate wait was 10.441 s and the median time in the driver was 4.941 s. The longest recorded gate wait was 47.588 s, followed by 5.006 s of native compilation. Correlating the driver starts with their measured gate durations shows three of the four PSO workers waiting at the gate concurrently. The 435.403 s summed across workers is overlapping time, not wall time.
The title stopped presenting for this interval while compiles continued to finish. The trace establishes substantial worker occupancy at the gate on Ampere under the conservative compile limit. It does not establish how much of the Present gap a helper would remove. The experiment was left running while the queue progressed.
AI use: OpenAI Codex (GPT-6) correlated the log events and drafted this report.
Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-26T03:26:38Z.
Wine 11.0,
XCL_DXC_THREADS=2, exact head3693d9efe41c7f69b4f4d9a04b98c66ab6a94b7d, Windows-targetcargo test --locked --target x86_64-pc-windows-msvc -p xcl --lib parked -- --nocapture --test-threads=1: 3 pass, 1 fail.workers_parked_for_big_compiles_leave_the_queue_to_helpersstarts two helpers and executes the queued job, butpso_async.rs:1175observesPARKED=2immediately after releasing the workers, before they finish, and assertsPARKED==0. The test waits only whileHELPERS > PARKED(:1172), which is false when both equal 2. This is a test synchronization race, not evidence that the queue helper failed.Test-only diagnostic: replace the wait condition with
(PARKED.load(Acquire) != 0 || HELPERS.load(Acquire) != 0)under the existing 10 s deadline, then assert both zero. The focused test passed 1/1 in 0.26 s after this change; the temporary edit was restored. Please make that bounded wait in the PR test so a slower scheduler is not a false negative. Local logs:.compat-xcl/logs/verify-pr2628-wine-two-worker-helper{,-wait-fix}.log(not attached). No actual large driver compile or retail title was exercised; your reported ~1.1 GB higher smoke peak commit makes this unsuitable as a 16 GiB RAM reduction without a guarded A/B.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:52:04Z.
Review: COMMENTED
Could helper retirement and park admission use one synchronized state? A retiring helper can read
HELPERS=1andPARKED=0, then pause before its CAS. The worker can park again, incrementPARKEDto 1, seeHELPERS=1, and start no replacement. The helper's CAS from 1 to 0 then succeeds and it exits. WithXCL_DXC_THREADS=1, the final state is one parked worker and no helper, so a queued small build is unserved until the big-compile wait ends. This is a sequentially consistent interleaving; stronger atomic ordering alone would not close it. A controlled retirement/new-park overlap should assert a helper remains available for a later job. Exact-head source review at3693d9efe41c7f69b4f4d9a04b98c66ab6a94b7d; no live stall reproduction. AI-assisted review with Codex.Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T06:06:49Z.
Source review of head
3693d9ef, no run. One small thing about helper retirement inserve(pso_async.rs):A base worker waits with
rx.lock().unwrap().recv(), so an idle one keeps theINBOXmutex for as long as the queue is empty. A helper that wants to time out and reachretire_helper()first needs that mutex for itsrecv_timeout(250 ms). While a worker that came back from its turn is idle inrecv(), the helpers block onlock()instead, and they only retire once new work wakes that worker. Building is unaffected; the helpers' threads (64 MiB stack reservations) just linger through idle periods. Taking work withtry_recv/recv_timeouton the base workers too, or aCondvarqueue instead ofMutex<Receiver>, would let them leave on time.Not tested: no build or run of this head on our side.
AI use: Gemini (Antigravity) flagged it in a first-pass review; Claude Code (Claude Opus 5.5) checked it against the source at
3693d9efand wrote this.Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T12:09:42Z.
@GodlyBDS Thanks for the Ampere trace. Three of four workers waiting at the gate at the same time, with a median gate wait of 10.4 s against 4.9 s in the driver, is the case this PR is for. As you say, it doesn't show how much of the Present gap a helper would close; on Turing most of what is left is the graphics pipelines built at first bind (#1798).
AI use: Claude Code (Claude Opus 5.5) drafted this reply.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T12:09:44Z.
@pickles976 Thanks, confirmed and fixed in
8b15bae. The test now waits until both counts are 0 (same 10 s limit) and then checks both. I also rancargo test -p xcl --lib parked30 times withXCL_DXC_THREADS1, 2 and 3: 0 failures (RTX 2070 SUPER, Windows 11 26300). About peak commit: the smoke run on the new head peaked at 17338 MB, against 17249 MB onmain(one run each). The smoke title doesn't reach a big compile, though, so this says nothing about commit while helpers are running.AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T12:09:45Z.
@KDenKC Right, an idle base worker in
recv()kept the lock, so the helpers couldn't get to their timeout. Fixed in8b15bae: the queue is now oneMutex+Condvarinstead ofMutex<Receiver>, so nobody holds the lock while waiting, and a worker that comes back from its turn wakes the idle helpers, which then leave. The test now also checks that the helpers leave with no new work queued.AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T12:09:47Z.
@luckyteagirl Agreed, that interleaving was real. Fixed in
8b15bae: the work, the parked count and the helper count are now under the queue's one lock, so a helper deciding to leave and a worker parking can't overlap. The interleaving can't be forced in a test now that both steps are under the same lock. Instead, the test parks every worker twice, and the second time checks that helpers are started again and that a job queued behind the parked workers still runs.AI use: Claude Code (Claude Opus 5.5) wrote the fix and this reply.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-26T13:55:55Z.
Independent Windows/NVIDIA check of PR head
8b15baeagainstmainb49be18. Windows 11 build 26300, RTX 3080 Ti (621.35), Ryzen 7 9800X3D, rustc 1.99.1 MSVC.cargo build --offline --locked --workspace: passed.cargo test --offline --locked -p xcl --lib parked -- --test-threads=1: 4 passed, 0 failed, 0 ignored withXCL_DXC_THREADS=1. I then repeated that command in 30 fresh processes, 10 each withXCL_DXC_THREADS=1,2, and3: all 30 passed. The filter includes the two PSO helper tests and two sparse tests.cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,431 passed, 0 failed, 47 ignored across 37 test targets. The passed count includes 25 explicit GPU skip notices: 21 no wave64, 3 refused per-lane cases, 1 no heap windows.The focused test exercised queue handoff and helper retirement under synthetic waits. I did not measure a cold title run, NVIDIA driver compilation time, peak commit with helpers active, or AMD/wave64 behavior. The PR's title A/B predates this queue revision, and its smoke title did not start a helper, so the runtime benefit still needs an exact-head run that reaches the big-compile wait.
AI use: Codex (GPT-6.2 Sol) checked the changed queue and gate paths, ran the tests, and drafted this report.
Imported from ivall/xcl. Originally posted by KDenKC on 2026-11-26T16:31:50Z.
Checked at
16bf648b:servenow waits on aCondvarover the shared queue, and a helper retires as soon as it holds the lock with more helpers than parked workers (pso_async.rs:~330-346). An idle base worker no longer blocks it. Thanks @KOLESNiii.AI use: Claude Code (Claude Opus 5.5) checked the source at that head and wrote this.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-26T16:45:03Z.
Updated to
16bf648, after a review of the previous head (8b15bae):helpers < min(parked, pool size). With 2n huge programs ahead of the graphics pipelines, the queue had no free thread left, just n jobs later than before. Helpers now start while there are fewer helpers than parked threads (workers and helpers), up to 4 × the pool size. The test now parks every worker and as many helpers; with the old cap, its job is never built.big_compile_turnstarts the helper with the slots' lock released, not while holding it.Retail A/B, the new head against
main08db802(RTX 2070 SUPER, cold, one run each, details in the description): helpers start (32 or more), but the pipelines built after the world load matchmain's, 336 against 342 in the first 420 s. Frames do not come back in either run. I removed the +7 % claim of the first version: that window does not fit both runs here, and with one run each it may have been noise. What this PR fixes is the stall the test reproduces; the title's long wait is mostly graphics pipelines built at first bind (#1798).Tests on
8cdbc6c(same tree as16bf648):cargo test --workspace -- --test-threads=41431 passed, 0 failed, 47 ignored, 25SKIPPED;cargo test -p xcl --lib parked30 runs withXCL_DXC_THREADS1–3, 0 failures. The smoke runs (mainand16bf648) are in the description.AI use: Claude Code (Claude Opus 5.5) did the review, wrote the fixes and this comment, and ran the tests, smoke runs and A/B; I started the game in each A/B run.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-26T17:10:52Z.
Independent RTX 4060 (8 GB) / Windows 11 release verification of PR #2628 updated head
16bf648b61df518d8559f2d887f1e74e6e8d37db(exact parent & merge-base08db8020d323bf478964fcc586152cce54959cfc). Measurements and targeted test results only; not a full source review.Setup
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200rustc 1.100.0 (0ef1bc386 2026-11-09), DXC1.9.2609.5, release builds, warm DXIL/pipeline caches, quiet machine (zero concurrent builds/tests during timed runs)title: 29640639viascripts/smoke.ps1 -Seconds 60(XCL_NETWORK=0, default flags, no input)Targeted RTX 4060 release unit & GPU tests (
16bf648b)cargo test --release -p xcl --lib parked -- --nocaptureacrossXCL_DXC_THREADS=1,2, and3(3 consecutive runs per setting = 9/9 passes, coveringparked_outside_the_pool_starts_no_helper,workers_parked_for_big_compiles_leave_the_queue_to_helpers, and bothsparse::tests::flush_parked_*tests):XCL_DXC_THREADS=1: 4 passed, 0 failed, 0 ignored × 3 (0.28 s/0.28 s/0.28 s,0SKIPPED).XCL_DXC_THREADS=2: 4 passed, 0 failed, 0 ignored × 3 (0.27 s/0.27 s/0.28 s,0SKIPPED).XCL_DXC_THREADS=3: 4 passed, 0 failed, 0 ignored × 3 (0.27 s/0.27 s/0.27 s,0SKIPPED).cargo test --release -p xcl --lib hle::d3d12x::pso_async::(3 consecutive parallel passes): 16 passed, 0 failed, 0 ignored on all 3 passes (1.01 s/0.71 s/0.71 s,0SKIPPED).cargo test --release -p xcl --lib hle::d3d12x::real::big_compile_tests::: 11 passed, 0 failed, 0 ignored (0.27 s,0SKIPPED).Paired 60 s RTX 4060 smoke (exact parent
08db8020vs16bf648b)Both runs completed cleanly at steady 60/2 s pacing with
0device removals and0crashes (16bf648bvs08db8020xcl.log:6,116 MBpeak/end local VRAM on both,4,651 MBvs4,683 MBend non-local VRAM,19,387vs19,507translated draws /1,024dispatches with0skipped,128pipelines built ahead on warm cache).Exact parent (
08db8020):PR #2628 head (
16bf648b):Limits of coverage
16bf648b(only the 9parkedpasses acrossXCL_DXC_THREADS=1,2,3, 3 parallel passes ofhle::d3d12x::pso_async::,big_compile_tests::, release build, and exact-parent paired 60 s smokes).pso_asyncunit tests acrossXCL_DXC_THREADS=1,2,3.RTX 4060) on native Windows 11; no AMD, Intel, or Wine/Linux run on this host.AI use
Ran the targeted release tests across
XCL_DXC_THREADS=1,2,3, release build, and exact-parent paired quiet 60 s smoke runs with assistance from Google Antigravity (Gemini 4 Neon); all test counts, timings, memory figures, and smoke blocks were extracted directly fromcargo test,xcl.log, andscripts/smoke.ps1outputs.Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T13:09:37Z.
Already PR'd into main (with no attribution... :( )
Pull request closed