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

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

@⁠kibagami-nc on GitHub · 2026-11-28 01:43 UTC · original
kibagami-nc:fix/timeline-test-second-thread-waits → main · +20 −6 · 1 files · 1 commits · open

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 are the indirect tests that fail on main, fixed in #578.
  • 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.

**@⁠kibagami-nc** on GitHub · 2026-11-28 01:43 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/598) `kibagami-nc:fix/timeline-test-second-thread-waits` → `main` · +20 −6 · 1 files · 1 commits · open ## 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 are the indirect tests that fail on `main`, fixed in #578. - **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.
real_waits_are_recorded_with_who_ended_them (diagnostics feature) failed
now and then under load, at its last check: no wait of the second thread
of 10 ms or more had a waker (left: None, right: Some(<this thread>)).
With eight test processes at once it failed in 13 of 120 runs. Two
causes:

- The 20 ms the lock is held were counted from the spawn of the second
  thread, which on a busy processor began late and found the lock nearly
  free. The main thread now waits until the second one runs and is about
  to take the lock.

- The second thread's wait comes out as several: WaitOnAddress returns
  now and then with no wake, and std's lock waits again. In one failing
  run the 20 ms were 16 waits of 1 to 4 ms on the lock, with the one wake
  (this thread's unlock) in the last; none was 10 ms on its own. The test
  now sums the second thread's waits on the lock's object (that of its
  longest wait) and takes the waker of the last of them.

After the change: 0 failures in 320 runs, eight processes at once, each
running this test beside watch::many_askers_tests' busiest one (5 in 200
with the first change alone). Only the test changes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 01:46:39 +00:00
This pull request can be merged automatically.
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/598/head:github-bot/gh-598'
git switch 'github-bot/gh-598'

Merge

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