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

Open
ACSchafer wants to merge 1 commit from upstream-pr/3604 into main
ACSchafer commented 2026-11-30 01:36:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ACSchafer on 2026-11-30T01:36:39Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5557427079 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604). Originally posted by [ACSchafer](https://github.com/ACSchafer) on 2026-11-30T01:36:39Z. --- ## 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.
copilot-pull-request-reviewer[bot] commented 2026-11-30 01:36:49 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-30T01:36:49Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6105953294 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604#pullrequestreview-6105953294). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-30T01:36:49Z. **Review:** COMMENTED --- 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.
mstrmoos commented 2026-11-30 03:28:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-11-30T03:28:58Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7267930394 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3604#issuecomment-7267930394). Originally posted by [mstrmoos](https://github.com/mstrmoos) on 2026-11-30T03:28:58Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3604:upstream-pr/3604'
git switch 'upstream-pr/3604'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3604'
git switch 'upstream-pr/3604'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3604'
git switch 'upstream-pr/3604'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3604'
git switch 'main'
git merge --squash 'upstream-pr/3604'
git switch 'main'
git merge --ff-only 'upstream-pr/3604'
git switch 'main'
git merge 'upstream-pr/3604'
git push origin 'main'
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!3604
No description provided.