fix(host): isolate unlocked relay_wait telemetry and fix settle_unlocked races under submit-split #3103

Open
qlfu wants to merge 1 commit from upstream-pr/3103 into main
qlfu commented 2026-11-29 20:02:10 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T20:02:10Z.


Summary

Fixes the remaining thread-safety and pacing races in VICTORY_SETTLE_UNLOCKED=1 (particularly when paired with VICTORY_SUBMIT_SPLIT=1):

  • relay_wait_unlocked: unlocked settle() / settle_now() calls wait on the relay without mutating submit-thread-owned telemetry globals (WORKING, CARD_CLOCK_US[2], SUBMISSION_US[1], READ_KIND, BLAMED).
  • WHY_SYNC locking & trailing wait_sent(): synchronizes WHY_SYNC updates and ensures unlocked settles call send::wait_sent() before snapshotting line(), preventing Present / fence waits from observing stale pre-send flight lines when VICTORY_SUBMIT_SPLIT=1 is active.
  • settle_for_sync_fence(): dedicated mid-submit() path for callers that already hold the submit path so fence settles do not deadlock or race.
  • Locked fallback on host.dynamic(...) retries: falls back safely when an unlocked dynamic buffer check retries.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --no-deps --locked: 0 new warnings.
  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- settle_unlocked --test-threads=1: 2/2 passed (settle_unlocked + relay_wait_unlocked).
  • Live 90s A/B on Series X title (1440p DLSS Balanced, VICTORY_SUBMIT_SPLIT=1, 0 WARNs / 0 ERRORs):
    • Native (SU=0 vs SU=1): Submit: all 33.60 -> 29.35 ms (-4.25 ms), FPS 20.85/21.95 -> 21.30/22.82 (max 42.2), GPU busy 96.0% -> 97.0%, GPU idle 1.9 -> 1.5 ms.
    • FG 2x (SU=0 vs SU=1): ahead_lock 0.90 -> 0.50 ms, present_wait 4.7 -> 3.4 ms, FPS 21.20/22.77 -> 21.90/23.56 (p10 16.2 -> 19.0), 0 WARNs / 0 ERRORs.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554562353 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3103). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T20:02:10Z. --- ## Summary Fixes the remaining thread-safety and pacing races in `VICTORY_SETTLE_UNLOCKED=1` (particularly when paired with `VICTORY_SUBMIT_SPLIT=1`): - **`relay_wait_unlocked`**: unlocked `settle()` / `settle_now()` calls wait on the relay without mutating submit-thread-owned telemetry globals (`WORKING`, `CARD_CLOCK_US[2]`, `SUBMISSION_US[1]`, `READ_KIND`, `BLAMED`). - **`WHY_SYNC` locking & trailing `wait_sent()`**: synchronizes `WHY_SYNC` updates and ensures unlocked settles call `send::wait_sent()` before snapshotting `line()`, preventing `Present` / fence waits from observing stale pre-send flight lines when `VICTORY_SUBMIT_SPLIT=1` is active. - **`settle_for_sync_fence()`**: dedicated mid-`submit()` path for callers that already hold the submit path so fence settles do not deadlock or race. - **Locked fallback on `host.dynamic(...)` retries**: falls back safely when an unlocked dynamic buffer check retries. ## Verification - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --no-deps --locked`: 0 new warnings. - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- settle_unlocked --test-threads=1`: `2/2` passed (`settle_unlocked` + `relay_wait_unlocked`). - Live 90s A/B on Series X title (1440p DLSS Balanced, `VICTORY_SUBMIT_SPLIT=1`, `0 WARNs / 0 ERRORs`): - Native (`SU=0` vs `SU=1`): `Submit: all` `33.60 -> 29.35 ms` (`-4.25 ms`), FPS `20.85/21.95 -> 21.30/22.82` (max `42.2`), `GPU busy 96.0% -> 97.0%`, `GPU idle 1.9 -> 1.5 ms`. - FG 2x (`SU=0` vs `SU=1`): `ahead_lock 0.90 -> 0.50 ms`, `present_wait 4.7 -> 3.4 ms`, FPS `21.20/22.77 -> 21.90/23.56` (`p10 16.2 -> 19.0`), `0 WARNs / 0 ERRORs`.
ghptc commented 2026-11-30 03:58:00 +00:00 (Migrated from github.com)

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


Thanks, @qlfu. The unlocked wait path in this PR already covers a case we reproduced through land_before_remap. It can run concurrently with submission even when VICTORY_SETTLE_UNLOCKED is off. If submitter A is working when remap thread B enters relay_wait, B can clear the shared work marker and then restore its saved true after A has finished. This undercounts A's work during the wait and attributes work after A has stopped. With the phase observer in #3649, the restore can also make B the recorded owner.

The synthetic regression starts an observed empty interval and A's work at tick 10, enters B's wait at 20, ends A's work at 35 and returns from B's wait at 40. At the tick-50 report there are 25 ticks of submit work and 15 outside submit work, with the work clock idle. The paired relay test covers pause and restore when the caller does hold the submission lock.

The focused follow-up cross-compiled in MSVC release mode. Both relay tests and the submit sub-bin test passed under Proton without a GPU. The follow-up changes work-clock ownership and gap attribution. The existing stood accounting, other wait counters, landing predicate, ordering and fences remain as they were. The tests cover attribution and provide no FPS estimate.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7268351813 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3103#issuecomment-7268351813). Originally posted by [ghptc](https://github.com/ghptc) on 2026-11-30T03:58:00Z. --- Thanks, @qlfu. The unlocked wait path in this PR already covers a case we reproduced through `land_before_remap`. It can run concurrently with submission even when `VICTORY_SETTLE_UNLOCKED` is off. If submitter A is working when remap thread B enters `relay_wait`, B can clear the shared work marker and then restore its saved `true` after A has finished. This undercounts A's work during the wait and attributes work after A has stopped. With the phase observer in #3649, the restore can also make B the recorded owner. The synthetic regression starts an observed empty interval and A's work at tick 10, enters B's wait at 20, ends A's work at 35 and returns from B's wait at 40. At the tick-50 report there are 25 ticks of submit work and 15 outside submit work, with the work clock idle. The paired relay test covers pause and restore when the caller does hold the submission lock. The [focused follow-up](https://github.com/ghptc/VIctory-NVIDIA/commit/a67df5c9f7f4dace8acd3d2b24722db62b77b869) cross-compiled in MSVC release mode. Both relay tests and the submit sub-bin test passed under Proton without a GPU. The follow-up changes work-clock ownership and gap attribution. The existing `stood` accounting, other wait counters, landing predicate, ordering and fences remain as they were. The tests cover attribution and provide no FPS estimate.
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/3103:upstream-pr/3103'
git switch 'upstream-pr/3103'

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