D3D12.X: the GPU wait watchdog does not miss the wake of an armed wait #2499

Open
github-bot wants to merge 1 commit from github-bot/gh-2499 into main AGit
Owner

@⁠tiagonleal on GitHub · 2026-11-25 20:42 UTC · original
tiagonleal:watchdog-lost-wakeup → main · +66 −6 · 1 files · 1 commits · open

The GPU wait watchdog takes its pair's lock, reads ARMED_GPU_WAITS and sleeps on the condvar when it is 0. The arm in try_gpu_wait called notify_one() without that lock, so a notify that fell between the watchdog's read of 0 and its cv.wait was lost: the watchdog slept with the wait armed, its timeout never ran, and a wait with no producer was never released on the CPU (no "did not complete … released on CPU" line). Only a later arm woke it. The notify now takes the pair's lock.

Part of #1452

Lock order (all callers):

  • the watchdog holds the pair's lock only from its check to cv.wait / wait_timeout and takes no other lock while it holds it (SYNC_GRAPH comes after the guard is dropped);
  • the one notifier, try_gpu_wait → wake_sync_watchdog, has dropped SYNC_GRAPH by then and takes the pair's lock last;
  • so the pair's lock is a leaf and cannot invert with SYNC_GRAPH or a queue lock.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: notify_sync_watchdog takes the lock around notify_one(); the check-and-sleep moves unchanged into sync_watchdog_sleep_if_idle, which has an after_check hook (a no-op in the runtime, as frame::publish_origin's after_release); new test a_wait_armed_during_the_watchdogs_check_wakes_it.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug tests, release smoke builds.
  • The test pauses the watchdog in after_check (it has read 0 and holds the lock), arms and notifies from the test thread, and requires the watchdog to wake within 2 s. Without the fix (the lock removed from notify_sync_watchdog, local commit): FAILED … assertion failed: the watchdog slept through the arm's notify, left: Err(Timeout) (1 failed, 2.02 s). With the fix: passed 10 of 10 runs alone (0.20 s each).
  • cargo test -p xcl --lib hle::d3d12x -- --test-threads=4, 3 runs: 254 passed, 0 failed, 2 ignored each.
  • cargo build --workspace ok; cargo test --workspace --no-fail-fast -- --test-threads=4, 2 runs: 1420 passed, 4 failed, 46 ignored each; 25 SKIPPED lines. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3, which fail the same way on the base commit 6d12f58a on this machine (cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu: 0 passed, 4 failed).
  • Smoke on the title below (60 s, release): no device removal, no crash, frames 1629 vs 1529 on main, peak commit 14807 vs 14875 MB.

Regression run

main (6d12f58a):

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1529 (PresentX 1529)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14875 MB

this PR (62f37212):

xcl-smoke v1
commit: 62f372122cb7c5efa8c2e78e4979e310b87dcb61
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1629 (PresentX 1629)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14807 MB

Not tested

  • How often the race happens in a real title: not measured. This PR does not claim to fix the stalled load in #1452; it closes one way a wait can stay armed with no release.
  • The test covers the wake (check, arm, notify, wait), not the 5 s release that follows it on the real watchdog thread.
  • AMD and Intel GPUs.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5) helped developing.

🤖 Generated with Claude Code

**@⁠tiagonleal** on GitHub · 2026-11-25 20:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/2499) `tiagonleal:watchdog-lost-wakeup` → `main` · +66 −6 · 1 files · 1 commits · open The GPU wait watchdog takes its pair's lock, reads `ARMED_GPU_WAITS` and sleeps on the condvar when it is 0. The arm in `try_gpu_wait` called `notify_one()` without that lock, so a notify that fell between the watchdog's read of 0 and its `cv.wait` was lost: the watchdog slept with the wait armed, its timeout never ran, and a wait with no producer was never released on the CPU (no "did not complete … released on CPU" line). Only a later arm woke it. The notify now takes the pair's lock. Part of #1452 Lock order (all callers): - the watchdog holds the pair's lock only from its check to `cv.wait` / `wait_timeout` and takes no other lock while it holds it (`SYNC_GRAPH` comes after the guard is dropped); - the one notifier, `try_gpu_wait` → `wake_sync_watchdog`, has dropped `SYNC_GRAPH` by then and takes the pair's lock last; - so the pair's lock is a leaf and cannot invert with `SYNC_GRAPH` or a queue lock. **What is in it** - `crates/xcl/src/hle/d3d12x/list_x.rs`: `notify_sync_watchdog` takes the lock around `notify_one()`; the check-and-sleep moves unchanged into `sync_watchdog_sleep_if_idle`, which has an `after_check` hook (a no-op in the runtime, as `frame::publish_origin`'s `after_release`); new test `a_wait_armed_during_the_watchdogs_check_wakes_it`. **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug tests, release smoke builds. - The test pauses the watchdog in `after_check` (it has read 0 and holds the lock), arms and notifies from the test thread, and requires the watchdog to wake within 2 s. Without the fix (the lock removed from `notify_sync_watchdog`, local commit): `FAILED … assertion failed: the watchdog slept through the arm's notify, left: Err(Timeout)` (1 failed, 2.02 s). With the fix: passed 10 of 10 runs alone (0.20 s each). - `cargo test -p xcl --lib hle::d3d12x -- --test-threads=4`, 3 runs: 254 passed, 0 failed, 2 ignored each. - `cargo build --workspace` ok; `cargo test --workspace --no-fail-fast -- --test-threads=4`, 2 runs: 1420 passed, 4 failed, 46 ignored each; 25 `SKIPPED` lines. The 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3`, which fail the same way on the base commit 6d12f58a on this machine (`cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu`: 0 passed, 4 failed). - Smoke on the title below (60 s, release): no device removal, no crash, frames 1629 vs 1529 on main, peak commit 14807 vs 14875 MB. **Regression run** main (6d12f58a): ``` xcl-smoke v1 commit: 6d12f58a229bc73889878a448c64dc3af25eeba0 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1529 (PresentX 1529) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14875 MB ``` this PR (62f37212): ``` xcl-smoke v1 commit: 62f372122cb7c5efa8c2e78e4979e310b87dcb61 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1629 (PresentX 1629) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14807 MB ``` **Not tested** - How often the race happens in a real title: not measured. This PR does not claim to fix the stalled load in #1452; it closes one way a wait can stay armed with no release. - The test covers the wake (check, arm, notify, wait), not the 5 s release that follows it on the real watchdog thread. - AMD and Intel GPUs. **AI use** - Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5) helped developing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The watchdog thread takes its pair's lock, reads ARMED_GPU_WAITS and
sleeps on the condvar when it is 0. The arm in try_gpu_wait called
notify_one() without taking that lock, so a notify falling between the
watchdog's read of 0 and its cv.wait was lost: the watchdog slept with
the wait armed, its timeout never ran, and a wait with no producer was
never released on the CPU (no "did not complete" line). Only a later
arm woke it.

The notify now takes the pair's lock (notify_sync_watchdog). The lock
is a leaf: the watchdog takes no other lock while it holds it, so the
notifier's SYNC_GRAPH or queue locks cannot invert with it. The check
and sleep move to sync_watchdog_sleep_if_idle, with an after_check
hook the new test uses to arm and notify between the read and the
wait; it fails on main (the watchdog does not wake within 2 s) and
passes with the fix.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:32:12 +00:00
Author
Owner

@⁠emirduran707 on GitHub · 2026-11-25 21:00 UTC · original

Independent AMD RDNA4 (native wave64) test report on exact head 62f372122cb7c5efa8c2e78e4979e310b87dcb61 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1422 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • The PR's test passed: hle::d3d12x::list_x::tests::a_wait_armed_during_the_watchdogs_check_wakes_it.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 62f372122cb7c5efa8c2e78e4979e310b87dcb61
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14222 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
**@⁠emirduran707** on GitHub · 2026-11-25 21:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2499#issuecomment-7174487666) Independent AMD RDNA4 (native wave64) test report on exact head `62f372122cb7c5efa8c2e78e4979e310b87dcb61` (clean detached checkout, no local changes). **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2602.17; tests debug, smoke release. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: **1422 passed, 2 failed, 46 ignored; 8 SKIPPED** (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu` refused by per-lane form; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`). All native wave64 GPU tests ran and passed. - The PR's test passed: `hle::d3d12x::list_x::tests::a_wait_armed_during_the_watchdogs_check_wakes_it`. - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) are pre-existing on unmodified `main` on this GPU. **Regression run** (60 s retail-title smoke, `XCL_NETWORK=0`, release) ``` xcl-smoke v1 commit: 62f372122cb7c5efa8c2e78e4979e310b87dcb61 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1575 (PresentX 1575) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 14222 MB ``` (Matched `main` `68a284a` baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.) **Not tested** - D3D12 debug layer; Intel GPUs. **AI use** - Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 21:00 UTC · original

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of the new a_wait_armed_during_the_watchdogs_check_wakes_it: passed. Related context from this lane: on #2439 two d11_* tests sit red here because bridged Wait64 waits get released by the 5 s watchdog; this PR's armed-wake fix is the right machinery for that class.

**@⁠SlopTart** on GitHub · 2026-11-25 21:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2499#issuecomment-7174492077) `gpu_` suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Targeted run of the new `a_wait_armed_during_the_watchdogs_check_wakes_it`: passed. Related context from this lane: on #2439 two `d11_*` tests sit red here because bridged Wait64 waits get released by the 5 s watchdog; this PR's armed-wake fix is the right machinery for that class.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 21:03 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 21:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/2499#issuecomment-7174550194) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2499/head:github-bot/gh-2499'
git switch 'github-bot/gh-2499'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2499'
git switch 'github-bot/gh-2499'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2499'
git switch 'github-bot/gh-2499'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2499'
git switch 'main'
git merge --squash 'github-bot/gh-2499'
git switch 'main'
git merge --ff-only 'github-bot/gh-2499'
git switch 'main'
git merge 'github-bot/gh-2499'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.