watch: waits for the guards' lock are charged to the place holding it #3604

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

@⁠ACSchafer on GitHub · 2026-11-30 01:36 UTC · original
ACSchafer:pr/guards-lock-holders → main · +64 −1 · 2 files · 1 commits · open

What it changes

In a diagnostics build, guards() records its caller (track_caller) while it holds the lock. A thread that has to wait reads that before it blocks, and charges its wait, once it has the lock, to the holder and to its own call site. The frame statistics get a line:

waits for the guards' lock per frame, by the place holding it: watch.rs:NNNN 1.23 ms in 45, ...; by holder <- waiter: ...

Other builds are unchanged: everything is behind cfg(feature = "diagnostics").

How it was tested

  • GPU and profile: not applicable (diagnostics counters)
  • Before: waits for the write trackers' locks per frame says how long threads wait, not for whom
  • After: not read in a game session on this branch. The diagnostics build compiles and the watch:: tests pass with --features diagnostics.
  • For shader changes, the wave sizes tested: not applicable
  • cargo test passed for the crates it touches: yes. cargo clippy -p victory-gpu --all-targets, with and without --all-features, adds no warnings.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #2372 (hang probe, memory by holder) is about slot eviction, not this lock.
**@⁠ACSchafer** on GitHub · 2026-11-30 01:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604) `ACSchafer:pr/guards-lock-holders` → `main` · +64 −1 · 2 files · 1 commits · open ## What it changes In a diagnostics build, `guards()` records its caller (`track_caller`) while it holds the lock. A thread that has to wait reads that before it blocks, and charges its wait, once it has the lock, to the holder and to its own call site. The frame statistics get a line: `waits for the guards' lock per frame, by the place holding it: watch.rs:NNNN 1.23 ms in 45, ...; by holder <- waiter: ...` Other builds are unchanged: everything is behind `cfg(feature = "diagnostics")`. ## How it was tested - GPU and profile: not applicable (diagnostics counters) - Before: `waits for the write trackers' locks per frame` says how long threads wait, not for whom - After: not read in a game session on this branch. The diagnostics build compiles and the `watch::` tests pass with `--features diagnostics`. - For shader changes, the wave sizes tested: not applicable - `cargo test` passed for the crates it touches: yes. `cargo clippy -p victory-gpu --all-targets`, with and without `--all-features`, adds no warnings. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #2372 (hang probe, memory by holder) is about slot eviction, not this lock.
A diagnostics build now says, once a frame-stats line, which call site held
the guards' lock when a thread had to wait for it, and which call site
waited: "waits for the guards' lock per frame, by the place holding it: ...;
by holder <- waiter: ...". `guards()` records its caller (track_caller) in a
static while it holds the lock; a waiter reads that before it blocks and
charges its wait there when it gets the lock.

Diagnostics builds only: without the feature nothing changes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:37:28 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-30 01:36 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-30 01:36 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604#pullrequestreview-6105953294) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠mstrmoos on GitHub · 2026-11-30 03:28 UTC · original

Ported this onto main 41adb551 and read it in a game session. It found a real one.

  • Setup: RTX 5080, Series X profile, 1440p, DLSS Balanced, frame generation off, VICTORY_COPY_BESIDE=1, 150 s in an outdoor save.
  • The line, per frame:
    • By holder: guard()'s retake of the lock after the unsure loop held it for 31.5 ms of other threads' waits. Then came guard()'s per-run retake (10.2 ms) and opened_for_writing (7.1 ms).
    • By holder <- waiter: much of it was opened_for_writing <- opened_for_writing (5.9 ms in 53) and guard <- opened_for_writing (11 ms). These are the title's copies (titlewrite) opening a block that has had its share of copies beside the guard. Unlike faults, they still take the lock.
  • Timeline spans confirmed it. Over three frames, opened_for_writing was called 764 times and waited 346 ms in all, up to 17 ms at a time, while its VirtualProtect took 0.2 ms in all.
  • Locally, opened_for_writing now uses open_unlocked as a fault does, and leaves the write to fault into the handler when that declines.
    • Waits for the guards' lock: 56 -> 22 ms a frame over all threads.
    • Frame: 40.0 ms against 41.3-42.6 for the same build before.
  • I'll open that as its own PR once I can push. Thanks for the diagnostic.
**@⁠mstrmoos** on GitHub · 2026-11-30 03:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604#issuecomment-7267930394) Ported this onto main 41adb551 and read it in a game session. It found a real one. - Setup: RTX 5080, Series X profile, 1440p, DLSS Balanced, frame generation off, `VICTORY_COPY_BESIDE=1`, 150 s in an outdoor save. - The line, per frame: - **By holder:** `guard()`'s retake of the lock after the unsure loop held it for 31.5 ms of other threads' waits. Then came `guard()`'s per-run retake (10.2 ms) and `opened_for_writing` (7.1 ms). - **By holder <- waiter:** much of it was `opened_for_writing <- opened_for_writing` (5.9 ms in 53) and `guard <- opened_for_writing` (11 ms). These are the title's copies (`titlewrite`) opening a block that has had its share of copies beside the guard. Unlike faults, they still take the lock. - Timeline spans confirmed it. Over three frames, `opened_for_writing` was called 764 times and waited 346 ms in all, up to 17 ms at a time, while its `VirtualProtect` took 0.2 ms in all. - Locally, `opened_for_writing` now uses `open_unlocked` as a fault does, and leaves the write to fault into the handler when that declines. - Waits for the guards' lock: **56 -> 22 ms a frame** over all threads. - Frame: **40.0 ms** against 41.3-42.6 for the same build before. - I'll open that as its own PR once I can push. Thanks for the diagnostic.
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/3604/head:github-bot/gh-3604'
git switch 'github-bot/gh-3604'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3604'
git switch 'github-bot/gh-3604'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3604'
git switch 'github-bot/gh-3604'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3604'
git switch 'main'
git merge --squash 'github-bot/gh-3604'
git switch 'main'
git merge --ff-only 'github-bot/gh-3604'
git switch 'main'
git merge 'github-bot/gh-3604'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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