Timeline test: a contended lock's waits are counted together (failed 1 run in 10 under load) #598

Merged
kibagami-nc merged 1 commit from upstream-pr/598 into main 2026-11-29 08:16:59 +00:00
kibagami-nc commented 2026-11-28 01:43:54 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T01:43:54Z.


The problem

timeline::report::tests::real_waits_are_recorded_with_who_ended_them sometimes fails under load. It is only built with the diagnostics feature (cargo test -p victory-gpu --all-features), so CI never runs it. The failing check is its last one:

assertion `left == right` failed
  left: None
 right: Some(13064)

No wait of the second thread lasting 10 ms or more had a waker. With eight test processes at once (each running this test 15 times) it failed in 13 of 120 runs. I found two causes.

  1. The 20 ms hold was counted from the spawn. The test holds the lock for 20 ms counted from the spawn of the second thread. On a busy processor that thread began late and found the lock nearly free.

  2. One lock wait came out as several. WaitOnAddress returns now and then with no wake, and std's lock waits again. A failing run, printed with a temporary log:

    • the 20 ms the second thread waited were 16 waits of 1 to 4 ms on the lock's object;
    • the only wake recorded for that object was the main thread's unlock, inside the last wait;
    • none of the 16 waits was 10 ms on its own.

    It happened when the test ran beside watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock in one process, as it does in cargo test.

The change

Only the test changes, in crates/victory-gpu/src/timeline/report.rs:

  • The hold starts once the second thread runs. The second thread sends on a channel just before it takes the lock, and the main thread waits for that before it holds the lock 20 ms.
  • The check sums the waits. It adds up the second thread's waits on the lock's object (the object of its longest wait) and expects 10 ms or more in all. The waker of the last of those waits must be the main thread.

The recorder and the report are unchanged. A follow-up could join a thread's back-to-back waits on one object in the report itself, so the chains show one wait.

Tests

  • Under the same load: 0 failures in 320 runs of eight processes at once, each running this test beside the watch test above.
    • Before: 13 in 120 (this test alone per process).
    • With the first change only: 5 in 200.
  • Whole suite: cargo test -p victory-gpu --all-features --locked --lib: 487 passed. The 2 failures were the indirect tests that then failed on main; main has fixed them since (9b712a6).
  • Clippy: cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings finds nothing in this file. It still stops on the lints main has.

No game files, dumps or extracted data are included.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5535480874 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/598). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T01:43:54Z. --- ## The problem `timeline::report::tests::real_waits_are_recorded_with_who_ended_them` sometimes fails under load. It is only built with the `diagnostics` feature (`cargo test -p victory-gpu --all-features`), so CI never runs it. The failing check is its last one: ``` assertion `left == right` failed left: None right: Some(13064) ``` No wait of the second thread lasting 10 ms or more had a waker. With eight test processes at once (each running this test 15 times) it failed in 13 of 120 runs. I found two causes. 1. **The 20 ms hold was counted from the spawn.** The test holds the lock for 20 ms counted from the spawn of the second thread. On a busy processor that thread began late and found the lock nearly free. 2. **One lock wait came out as several.** `WaitOnAddress` returns now and then with no wake, and std's lock waits again. A failing run, printed with a temporary log: - the 20 ms the second thread waited were **16 waits of 1 to 4 ms** on the lock's object; - the only wake recorded for that object was the main thread's unlock, inside the last wait; - none of the 16 waits was 10 ms on its own. It happened when the test ran beside `watch::many_askers_tests::no_write_is_lost_when_faults_take_no_lock` in one process, as it does in `cargo test`. ## The change Only the test changes, in `crates/victory-gpu/src/timeline/report.rs`: - **The hold starts once the second thread runs.** The second thread sends on a channel just before it takes the lock, and the main thread waits for that before it holds the lock 20 ms. - **The check sums the waits.** It adds up the second thread's waits on the lock's object (the object of its longest wait) and expects 10 ms or more in all. The waker of the last of those waits must be the main thread. The recorder and the report are unchanged. A follow-up could join a thread's back-to-back waits on one object in the report itself, so the chains show one wait. ## Tests - **Under the same load:** 0 failures in 320 runs of eight processes at once, each running this test beside the `watch` test above. - Before: 13 in 120 (this test alone per process). - With the first change only: 5 in 200. - **Whole suite:** `cargo test -p victory-gpu --all-features --locked --lib`: 487 passed. The 2 failures were the indirect tests that then failed on `main`; `main` has fixed them since (9b712a6). - **Clippy:** `cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings` finds nothing in this file. It still stops on the lints `main` has. No game files, dumps or extracted data are included.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA!598
No description provided.