Repository navigation
Conversation
There was a problem hiding this comment.
On 88c2045, the new settle_readbacks_skips_state_lock_when_no_job_finished fixture holds iso.state while calling worker.join(), then drops the guard afterward. The current Some(5000) path avoids blocking on that lock, but a future regression to a blocking STATE.lock()—the behavior this fixture is meant to catch—would make the worker and join wait on each other indefinitely. The existing took < 500 ms assertion would never execute, so CI would hang instead of reporting the regression.
Could the worker send its result over a channel, let the main thread use recv_timeout while it holds STATE, then always release the guard before joining and asserting the timed result? That preserves the timing check without detaching a worker that may still use the fixture. This is exact-head source review; I did not deliberately hang the test.
|
Source review of
Is that intended (e.g. Not tested: no build or run of this head on our side. AI use: Gemini (Antigravity) flagged it in a review. Claude Code (Claude Opus 5.5) read the paths in the diff and wrote this. |
|
Follow-up to KDenKC's publication-gap comment on head A schedule that distinguishes this head from its base is: one unrelated, GPU-unfinished readback is already pending; a second submission completes its title fence for an immediate CPU write, then pauses after Could an unpublished submission remain visible to settling callers until publication or cancellation, with those callers observing that transition within their existing wait budget? A deterministic regression can use barriers to pause publication after the second title fence completes, start the observer with a bounded test timeout, release publication, and assert the CPU value when the observer reports the fence complete. The current contention test starts settling after joining the submitter, so it does not cover this window. This is a source trace, not a live reproduction. No build or GPU test of #2749 was run for this finding. AI use: Codex (GPT-6.2 Astra) traced the ordering; Codex (GPT-6.2 Sol) checked the current diff and drafted this comment. |
|
Thanks @thehollowedone, that is the better framing. Counting the plan earlier only changes the zero fast path, which existed on the base too. Your schedule (an older unfinished job pending, an immediate write planned but not yet published, a fence observer settling in between) is the case that actually differs from the base. Keeping an unpublished submission visible to settling callers until it is published or cancelled is the right shape for a fix; my AI use: Claude Code (Claude Opus 5.5) wrote this. |
|
Test report:
The suite does not cover the publication window @thehollowedone describes above: as they note, the contention test starts settling after the submitter has joined. RTX 4060 8 GB (driver 621.01), Ryzen 7 5700X, 24 GB, Windows 11 26200, rustc 1.100.0, DXC 1.9.2609.5. Not tested: any title or smoke run, the sparse path under a real workload, timings, AMD. AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this; I read it before posting. |
|
Follow-up to my source review: I reproduced the planned-but-unpublished immediate window on head The test leaves an older readback unfinished, prepares a second immediate write under On Windows 11 build 26300, RTX 3080 Ti (driver 621.35), Ryzen 7 9800X3D, rustc 1.99.1 MSVC:
A fix needs the planned submission to remain visible until it is published or cancelled, and the settling caller to observe that transition within its wait budget. Merely incrementing Test-only regression diff@@ -7523,6 +7523,72 @@ mod tests {
}
}
+ /// A fence observer must not report settled while an immediate has been planned but has not
+ /// yet been published to the readback queue. An older unfinished job keeps RB_PENDING nonzero.
+ #[test]
+ fn a_planned_immediate_is_visible_to_a_concurrent_fence_observer() {
+ unsafe {
+ let iso = IsolatedAsyncState::new();
+ let title: ID3D12CommandQueue = iso.dev.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).expect("title queue");
+ let old_title: ID3D12Fence = iso.dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).expect("old title fence");
+ let old_done: ID3D12Fence = iso.dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).expect("old copy fence");
+ let mut old = iso.make_job(0xAB, 64, old_title.clone(), old_done.clone(), 1, 1);
+ {
+ let mut rq = iso.rb.lock().unwrap();
+ rq.job_seq += 1;
+ old.seq = rq.job_seq;
+ rq.rb_jobs.push_back(old);
+ }
+ RB_PENDING.fetch_add(1, Ordering::Release);
+
+ let dst = iso.base + 0x800;
+ let value = 0xCAFE_BABE_1234_5678u64;
+ let state = Arc::clone(&iso.state);
+ let q_send = SendQueue(title.clone());
+ let (ready_tx, ready_rx) = std::sync::mpsc::channel();
+ let (release_tx, release_rx) = std::sync::mpsc::channel();
+ let submitter = std::thread::spawn(move || {
+ let (plan, excess) = {
+ let mut g = state.lock().unwrap();
+ let s = g.as_mut().unwrap();
+ s.note_queue(&q_send.0);
+ s.prepare_after_execute(&q_send.0, &[], &[(dst, value, 8)])
+ };
+ drop(excess);
+ ready_tx.send(()).unwrap();
+ release_rx.recv().unwrap();
+ submit_async_readback(&q_send.0, plan.expect("planned immediate"));
+ });
+ ready_rx.recv_timeout(std::time::Duration::from_secs(5)).expect("plan prepared");
+ assert_eq!(std::ptr::read_volatile(dst as *const u64), 0);
+ // Model the title fence that the real fence observer has already seen.
+ let title_visible: ID3D12Fence = iso.dev.CreateFence(0, D3D12_FENCE_FLAG_NONE).expect("title-visible fence");
+ title.Signal(&title_visible, 1).expect("signal title-visible fence");
+ let t0 = std::time::Instant::now();
+ while super::super::real::fence_completed(&title_visible) < 1 {
+ assert!(t0.elapsed() < std::time::Duration::from_secs(5), "title fence did not complete");
+ std::thread::yield_now();
+ }
+
+ let early = settle_readbacks_with(&iso.state, &iso.rb, Drain::TitleDone, 300, Some(0));
+ release_tx.send(()).unwrap();
+ submitter.join().unwrap();
+
+ let t1 = std::time::Instant::now();
+ while std::ptr::read_volatile(dst as *const u64) != value {
+ assert!(settle_readbacks_with(&iso.state, &iso.rb, Drain::TitleDone, 2000, None));
+ assert!(t1.elapsed() < std::time::Duration::from_secs(5), "immediate did not land");
+ std::thread::yield_now();
+ }
+ old_title.Signal(1).unwrap();
+ old_done.Signal(1).unwrap();
+ assert!(settle_readbacks_with(&iso.state, &iso.rb, Drain::TitleDone, 2000, None));
+ assert_eq!(std::ptr::read_volatile(dst as *const u64), value);
+ assert_eq!(RB_PENDING.load(Ordering::Acquire), 0, "all test jobs were landed");
+ assert!(!early, "observer reported success before the planned immediate was published");
+ }
+ }
+
/// `readback_after_execute_with` releases `STATE` before acquiring `RB_SUBMIT` and recording
/// D3D12 copy commands, and `land_finished_readbacks` returns excess `RbJob`s beyond the 32-job
/// pool cap so callers drop them outside all locks.AI use: Codex (GPT-6.2 Sol) wrote and ran the regression and drafted this report; Codex (GPT-6.2 Astra) reviewed the publication/cancellation design. |
88c2045 to
9cfa753
Compare
|
Thanks
Re-verified all 6 lock-split/publication/contention tests on debug WARP ( |
|
Follow-up to my report, on the new head
Not tested: any title or smoke run, timings, AMD. AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this; I read it before posting. |
|
Independent RTX 3080 Ti recheck of #2749 head Both revisions passed
The six distinct failing test names are identical on base and head; On the head, Not tested: a retail title, paired clean-commit smoke, sustained in-world readback traffic, AMD/Intel, or a performance improvement under real contention. The tests establish Ampere coverage for the fix, not a merge-readiness or runtime-speed claim. AI use: Codex (GPT-6.2 Sol) ran the paired Windows tests and wrote this report; Codex (GPT-6.2 Astra) reviewed the low-level publication path. |
|
Test report: in the world on an RTX 4080 16 GB (the case under "Not tested"). Three back-to-back runs of the retail title of #505 into the world, two with this PR and one without, same warm caches. Tested
Not tested
AI use: Claude Code (Claude Fable 5.2) ran this on the owner's machine and wrote the report. |
Previously, `sparse::drain_readbacks_spin` held the global `STATE` mutex across up to 300-2000 us of GPU fence spinning per pending readback job and dropped excess recycled `RbJob`s above the 32-job pool cap while holding `STATE`, `settle_readbacks_within` and `start_readback_thread` contended on `STATE` even when no readback had finished, and `readback_after_execute` held `STATE` across D3D12 `CreateFence`/`CreateCommandAllocator`/`CreateCommandList`/`CreateCommittedResource`/`Map`/`Reset`/`CopyBufferRegion`/`Close`/`pc_execute`/`Signal`. - Split async readback queues and staging pool into a pure leaf `ReadbackQueue` wrapped in `SharedReadbacks` (`Mutex<ReadbackQueue>` + `Condvar`, reachable via `READBACKS`) and per-queue fence/recording state into `RbSubmit` (`Arc<Mutex<RbSubmit>>`), forming a strict 2-level DAG (`STATE -> ReadbackQueue` and `RbSubmit -> ReadbackQueue`) where `STATE` and `RbSubmit` never nest and `ReadbackQueue` is never held across GPU spins, `Condvar` waits, D3D12 COM calls, or `RbJob` drops. - Keep unpublished async readback plans visible to settling callers from `prepare_after_execute` (while `STATE` is still held) until `submit_async_readback` publishes or cancels via `ReadbackQueue::submitting` + RAII `SubmittingGuard` paired with `RB_PENDING` and `SharedReadbacks::published`: `wait_and_check_ready` waits within the caller's existing budget (`lock_ms` / unbounded) so concurrent fence observers never return early with stale CPU values when an unrelated unfinished readback is already pending, return `false` if their budget expires before publication, and wake cleanly on cancellation. - Move `Drain::TitleDone` fence spinning in `settle_readbacks` / `settle_readbacks_within` / `readback_now` completely outside all locks with a single total `spin_us` deadline; skip locking `STATE` entirely when no submission is publishing, no job has finished, and none is mid-landing (`landing == 0`), while preserving strict ascending `seq` order and visibility synchronization under `STATE` when landing finished `imm_jobs` and `rb_jobs`. - Return excess recycled `RbJob`s above cap 32 from `land_finished_readbacks`, `before_execute_on`, and `readback_ranges` so callers drop them outside all locks; decrement remaining pending jobs in `ReadbackQueue::drop` so `RB_PENDING` stays balanced across `init` re-initialization. - Gate `start_readback_thread` on `RB_PENDING != 0` and a leaf `READBACKS` check (`has_unpopped_finished_jobs`) before trying `STATE`. - Split `readback_after_execute` into a brief `STATE` snapshot (`prepare_after_execute`, leaving the rare `rbq.is_none()` sync fallback intact) followed by `submit_async_readback` under `RbSubmit` outside `STATE`, pushing jobs to `ReadbackQueue` only after both queue fences are signalled. - Add 6 deterministic concurrency/lock-split tests and a contention micro-bench in `sparse::tests` covering zero-lock GPU fence wait, non-deadlocking bounded `recv_timeout` skip-`STATE` regression guard when unfinished, concurrent strict-`seq` landing + `landing > 0` visibility, recording and dropping excess `RbJob`s outside `STATE`, `STATE` lock latency under spin contention, and paused-publication / bounded-timeout / plan-cancellation visibility. Part of xcl-dev#2688 Assisted-by: Google Antigravity (Gemini 4 Neon)
9cfa753 to
f644a23
Compare
|
Rebased cleanly onto
|
|
Independent Windows/NVIDIA check of the rebased #2749 head On Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35, 12 GiB), rustc 1.99.1:
The ten full-suite failures were the same on both revisions in this setup. The head's six additional tests passed. The CI-named Not tested: AMD/Intel, a retail smoke on this revision, or a repeat of the CI environment. AI use: Codex (GPT-6.2 Sol) selected the matched commands, ran them, compared the logs, and wrote this report. I checked each reported result against the output. |
|
Follow-up on the rebased head
Not tested: any title, so nothing on how AI use: Claude Code (Claude Opus 5.5) ran the tests and drafted this; I read it before posting. |
Targets
nvidia-dev(eae01502), independent of #2729 and #2768. Splits async sparse readback fence spinning and command recording out ofsparse::STATEso submitting threads and allocation/mapping callers no longer stall behinddrain_readbacks_spinGPU waits orreadback_after_executeD3D12 recording, while preservingeb784bc3lock-holder timing (XCL_LOOK_STATS=2),3c1a475a(XCL_SUBMIT_LOCK_FIRST=1), and4ac75585(XCL_MIRROR_FILL_MB=1024).Part of #2688
What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:rb_jobs,imm_jobs,rb_pool,rb_fence,rbq_done,job_seq,submitting,landing) intoArc<SharedReadbacks>(Mutex<ReadbackQueue>+Condvar, reachable withoutSTATEviastatic READBACKS) and per-queue fence/recording state (dev,rb_queue_fences) intoArc<Mutex<RbSubmit>>, establishing a strict 2-level DAG (STATE -> ReadbackQueueandRbSubmit -> ReadbackQueue) whereSTATEandRbSubmitnever nest andReadbackQueueis never held across GPU spins,Condvarwaits, D3D12 COM calls, orRbJobdrops.prepare_after_execute(whileSTATEis still held) untilsubmit_async_readbackpublishes or cancels viaReadbackQueue::submitting+ RAIISubmittingGuardpaired withRB_PENDINGandSharedReadbacks::published:wait_and_check_readywaits within the caller's existing budget (lock_ms/ unbounded) so concurrent fence observers never return early with stale CPU values when an unrelated unfinished readback is already queued, returnfalseif their budget expires before publication, and wake immediately if a plan is dropped/cancelled on error.Drain::TitleDonefence spinning (wait_and_check_ready) outside all locks with a single totalspin_usdeadline across pending title-done copies; skip lockingSTATEcompletely whensubmitting == 0, no job has finished, andlanding == 0. Tracklandingcount underSTATE -> ReadbackQueuewhile jobs are popped and landing so concurrentsettle_readbacks*callers synchronize onSTATEbefore reading CPU memory while preserving strict ascendingseqlanding order.origin/nvidia-dev(eae01502) lock-holder telemetry (holding(Holder::{Submit,After,Settle,ReadbackThread,CpuRead}),HELD,HELD_AFTER_WAIT,behind) andXCL_SUBMIT_LOCK_FIRST=1priority (lock_for_submit(),FLUSHERS_WAITING,try_lock_giving_wayinsettle_readbacks_with, andSUBMITS_WAITINGyield checks instart_readback_thread) alongside theSharedReadbackssplit.RbJobs above the 32-job pool cap fromland_finished_readbacks,before_execute_on, andreadback_rangesso callers drop them outside all locks; decrement remaining unlanded jobs inReadbackQueue::dropsoRB_PENDINGstays balanced acrossinitre-initialization (withSubmittingGuardholdingArc<SharedReadbacks>soDropcannot run while a plan is in flight).readback_after_executeinto a briefSTATEsnapshot (prepare_after_execute, leaving the rarerbq.is_none()sync fallback intact) followed bysubmit_async_readbackunderRbSubmitoutsideSTATE, pushingImmJob/RbJobentries toReadbackQueueonly after both queue fences are signalled.sparse::tests:settle_readbacks_waits_for_copy_fence_without_holding_state,settle_readbacks_skips_state_lock_when_no_job_finished(using anmpsc::channel+recv_timeout(500 ms)and always droppingSTATEbeforeworker.join()so a blocking regression fails cleanly instead of deadlocking),concurrent_settle_lands_jobs_in_strict_seq_order,readback_after_execute_records_outside_state_lock_and_drops_excess_outside_locks,state_lock_latency_stays_unblocked_under_readback_spin_contention, andsettle_waits_for_in_flight_plan_publication_and_handles_cancellation.Tested
rustc 1.100.0, DXC1.9.2609.5, debug (WARP) and release (RTX 4060), rebased cleanly ontoorigin/nvidia-dev(eae01502).cargo test -p xcl --lib -- --test-threads=1 --nocapture ...):XCL_ADAPTER=warp):6 passed, 0 failed, 0 ignored(0skipped,1.65 s); contention bench (40spin calls):STATElock waitp50=1 us, p99=21 us, max=21 us.6 passed, 0 failed, 0 ignored(0skipped,1.67 s); contention bench (36spin calls):STATElock waitp50=0 us, p99=0 us, max=0 us(vs holdingSTATEacross the2000 uscopy-fence spin before).cargo test --release -p xcl --lib hle::d3d12x::sparse::tests:: -- --test-threads=4 --nocapture(2× consecutive runs, including3c1a475a'stry_lock_giving_waytests):68 passed, 0 failed, 1 ignored(early_commit_timing,0skipped;3.51 s/3.55 s; contention benchp50=0 us, p99=0 us, max=0 uson both runs).cargo test --release -p xcl --test sparse_reinit -- --test-threads=1 --nocapture:1 passed, 0 failed, 0 ignored(0.49 s).cargo clippy --workspace --all-targets:0new warnings and0new errors across all added/changed lines incrates/xcl/src/hle/d3d12x/sparse.rs(pre-existingnvidia-devwarnings/errors remain on untouched lines including pre-existingmissing_safety_doconreadback_after_execute).XCL_LOOK_STATS=2 XCL_SUBMIT_LOCK_FIRST=1onf644a239(title: 29640639):518frames (PresentX 518),35 60 60presents/2 s,0device removals,0crashes,14726 MBpeak commit,exit: 0x0.Regression run
Quiet 60 s
scripts/smoke.ps1runs on RTX 4060 with default flags (XCL_LOOK_STATSandXCL_SUBMIT_LOCK_FIRSTunset). Includesmainmerge-base (b49be183, same-day run on this hardware) forpr_check.py,nvidia-devtarget base (eae01502), and rebased PRHEAD(f644a239):main(b49be183, merge-base):nvidia-dev(eae01502, target base):PR
HEAD(f644a239, default flags):Not tested
--workspacetest suite on the rebasedeae01502commit (all 6 targeted lock-split tests debug WARP + release RTX 4060, 2× fullsparse::tests::68/0/1,sparse_reinit, clippy, and smokes ran onf644a239).title: 29640639does not exercise heavy sparse readback contention (those lock-contention and publication-window paths are verified by the 6 unit/concurrency tests and contention micro-bench above).XCL_SAMPLE_RPF/XCL_SAMPLE_TTPF/XCL_SAMPLE_AWCunset) and D3D12 debug-layer tests (d3d12SDKLayers.dllnot installed).AI use
ReadbackQueue/RbSubmitlock split andSharedReadbacks/SubmittingGuardpublication visibility, wrote the 6 concurrency/contention tests, rebased ontoorigin/nvidia-dev(eae01502) preservingeb784bc3/3c1a475atelemetry and submit-lock priority, ran clippy, unit tests, and the RTX 4060 retail smoke runs on the hardware above, and updated this description.