Repository navigation
d3d12: the contended-lock test waits for the holder, not for a thread to start (GPU-TIMELINE-REPORT-WAIT-HANDSHAKE) - #3050
Conversation
|
CPU-only review at I checked the schedule in a small CPU-only model of the mutex and condvar handoff. Six ordinary attempts waited about 31 ms. Six with the waiter held until the release acquired in at most 0.001 ms. This models the synchronization sequence. The Rust trace test itself was not executed. A contrived delay immediately before the wait timer would exercise the remaining window in the Rust test. The trace lookup also runs after AI-assisted review. No GPU or game files used. |
… to start (GPU-TIMELINE-REPORT-WAIT-HANDSHAKE) `real_waits_are_recorded_with_who_ended_them` (timeline/report.rs, tests) holds a mutex, spawns a thread that is to block on it, sleeps a fixed 20 ms so that the thread has reached `lock.lock()` by then, lets go, and asserts that the trace recorded a wait of 10 ms or more naming this thread as the waker. The 20 ms is a bet on the scheduler. On a loaded machine the new thread has not been started inside it, so it acquires the lock at once, no wait of 10 ms or more exists, and the assert fails with `left: None` against `right: Some(this thread)`. Measured on main 60f7dcd: 3 failures in 40 whole-suite runs of `cargo test -p leonida-gpu --lib --features diagnostics`, and the failing line is the assert, not the recorder. The length of the wait is now the holder's own doing: the worker takes the lock first, says so through a mutex and a condvar, and keeps it for 30 ms; this thread waits for that word and then blocks on the lock for as long as the worker keeps it. The wait is as long as the holder's sleep and not as long as the machine takes to start a thread, so there is no window left to lose, and the test asserts that duration directly as well as the waker. The wait for the word is bounded by two seconds, so a holder that never takes the lock fails the test instead of hanging it. The waits are now read from this thread, because this is the thread that waits: the wait for the lock is the last of its waits of 10 ms or more before the join. The gate it waited on in the first half names the first worker, so the first match was that one. The join below is a wait of its own, so the ticks are taken before it and the waits are bounded by them: a slow worker exit makes the join the later wait, and the assert would pick a wait that names no waker. The chain and the rest of the test are untouched, and `last` is still taken before the contention, so none of this enters it. Red and green on this machine, no game files and no GPU: - Stock test, with 30 ms of start-up delay in the spawned thread (what the 20 ms sleep assumes away): FAILED, `left: None`, `right: Some(27892)`. - This test, with the same 30 ms of start-up delay: ok. - This test with 30 ms between the holder's release and its exit, so that the join is a wait of 10 ms or more: ok. Without the bound on the ticks it FAILS, `left: None` - the bound is what keeps that wait out. - This test without either perturbation: 20 of 20 runs ok. - Whole diagnostics suite (`cargo test -p leonida-gpu --lib --locked --features diagnostics`): 2 runs, 749 passed, 0 failed, 59 ignored, each. - Default suite (`cargo test -p leonida-gpu --lib --locked`): 668 passed, 0 failed, 59 ignored. - Teeth: with `Trace::waker` made to return `None`, this test fails at the assert, so the wait is still checked for who ended it. Only the test changes, and only under the diagnostics feature; no product code. AI-assisted: yes - DeepSeek V4.1 Flash Free (OpenCode), with a separate read-only review agent.
82e4a68 to
3f6545b
Compare
|
One review round found a second way for this test to fail, and it is fixed in this head ( The join below is a wait of its own: the wrappers record it like any other wait of this thread. If the worker is slow to exit, that wait is later than the wait for the lock and is at least 10 ms long, so the assertion could pick it - and a join names no waker, so it failed with Measured here: with 30 ms between the holder's release and its exit, this head passes, and the head without the bound fails with The wait for the holder's word is bounded as well (two seconds), so a holder that never takes the lock fails the test instead of hanging it. On this head: whole diagnostics suite 2 runs, 749 passed and 0 failed each; the test itself 20 of 20 runs; default suite 668 passed, 0 failed. |
Claimed in the coordination issue as: GPU-TIMELINE-REPORT-WAIT-HANDSHAKE
What and why
real_waits_are_recorded_with_who_ended_them(d3d12/crates/leonida-gpu/src/timeline/report.rs, tests) holds a mutex, spawns a thread that is to block on it, sleeps a fixed 20 ms so that the thread has reachedlock.lock()by then, lets go, and asserts that the trace recorded a wait of 10 ms or more naming this thread as the waker.The 20 ms is a bet on the scheduler. On a loaded machine the new thread has not been started inside it, so it acquires the lock at once, no wait of 10 ms or more exists, and the assert fails with
left: Noneagainstright: Some(this thread). Measured onmain60f7dcd: 3 failures in 40 whole-suite runs ofcargo test -p leonida-gpu --lib --features diagnostics. The failing line is the assert, not the recorder: the recorder had nothing to name because there was no wait.The test is under the diagnostics feature, so the default
--librun does not compile it; it is the run the layer's own diagnostics build uses.What changed
lastis still taken before the contention, so none of this enters the chain.Verification (CPU-only, no game files, no GPU)
On this head, based on
main0ae5a2664:left: None,right: Some(27892)- the flake, every time.left: None- the bound is what keeps that wait out.cargo test -p leonida-gpu --lib --locked --features diagnostics): 2 runs, 749 passed, 0 failed, 59 ignored, each. The stock test failed in this suite 3 times in 40 runs onmain60f7dcd.Trace::wakermade to returnNone, this test fails at the assert, so the wait is still checked for who ended it.cargo test -p leonida-gpu --lib --locked): 668 passed, 0 failed, 59 ignored.What this does not do
It does not serialise the suite and does not touch the other parallel races in this crate (
watch.rs,descriptor.rs,texture.rs,pool.rs), which are claimed elsewhere. It changes only this test, so it would also stand if the suite were serialised later: this test's wait is no longer a thing to hide.Notes
Checklist
main(0ae5a2664).python -I scripts/check_no_game_data.pyclean.AI-assisted: yes - DeepSeek V4.1 Flash Free (OpenCode); review: a separate read-only OpenCode agent.