The asking thread runs at the highest priority #93

Closed
github-bot wants to merge 0 commits from github-bot/gh-93 into main AGit
Owner

@⁠mgrein on GitHub · 2026-11-30 11:17 UTC · original
mgrein:ask-priority → main · +49 −0 · 1 files · 47 commits · closed without merging

With VICTORY_ASK_FIRST=1 the submitting thread hands each submission's write-watch asking to a kept thread (victory-ask), then waits for it after planning. In the world of a new retail game I added temporary counters around that hand-off. They showed that the job sat in the queue ~150 µs before the thread ran it: 2.5–3.0 ms a frame over ~18 askings, next to ~5.2 ms of the asking itself. With our helpers and the title's threads on every core, the woken thread didn't get one right away. The submitting thread waited 5.9 ms a frame in total.

This sets that thread to the highest priority (THREAD_PRIORITY_HIGHEST) at its first asking. Its work is short (~0.3 ms an asking) and the frame's critical thread is blocked on it, so it shouldn't starve anything.

  • VICTORY_ASK_PRIORITY=<n> (-2 to 2) picks another priority.
  • VICTORY_ASK_PRIORITY=ab switches between the highest and the old priority every 20 seconds and logs each switch (ask-priority switch <unix ms> on|off), for an A/B inside one run.
  • Only the victory-ask thread is touched. A submitting thread that makes the asking itself (no thread available) keeps its priority.

Measured

RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, VICTORY_SUBMIT_SPLIT=1, VICTORY_ASK_FIRST=1, VICTORY_OFF_LINE=1, VICTORY_HELPER_PRIORITY=1. One 10-minute idle run in the world with VICTORY_ASK_PRIORITY=ab. Neighbouring 20 s windows are paired:

per frame old priority highest
asking queued before it ran 2.49 ms 0.27 ms
the asking itself 5.24 ms 4.18 ms
submitting thread waiting for it 5.93 ms 3.11 ms

Frame median about 1.3 ms less (21 of 25 pairs), submitting thread about 1.5 ms less (20 of 25 pairs).

cargo test -p victory-gpu --lib passes. In 6 runs one test failed once, which looks like an existing intermittent test; this change doesn't touch anything tests exercise beyond the asking thread's priority.

🤖 Generated with Claude Code

**@⁠mgrein** on GitHub · 2026-11-30 11:17 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/93) `mgrein:ask-priority` → `main` · +49 −0 · 1 files · 47 commits · closed without merging With `VICTORY_ASK_FIRST=1` the submitting thread hands each submission's write-watch asking to a kept thread (`victory-ask`), then waits for it after planning. In the world of a new retail game I added temporary counters around that hand-off. They showed that the job sat in the queue ~150 µs before the thread ran it: **2.5–3.0 ms a frame** over ~18 askings, next to ~5.2 ms of the asking itself. With our helpers and the title's threads on every core, the woken thread didn't get one right away. The submitting thread waited 5.9 ms a frame in total. This sets that thread to the highest priority (`THREAD_PRIORITY_HIGHEST`) at its first asking. Its work is short (~0.3 ms an asking) and the frame's critical thread is blocked on it, so it shouldn't starve anything. - `VICTORY_ASK_PRIORITY=<n>` (-2 to 2) picks another priority. - `VICTORY_ASK_PRIORITY=ab` switches between the highest and the old priority every 20 seconds and logs each switch (`ask-priority switch <unix ms> on|off`), for an A/B inside one run. - Only the `victory-ask` thread is touched. A submitting thread that makes the asking itself (no thread available) keeps its priority. ## Measured RTX 4070, Ryzen 5 5600X, Series S profile, DLSS quality + frame generation, `VICTORY_SUBMIT_SPLIT=1`, `VICTORY_ASK_FIRST=1`, `VICTORY_OFF_LINE=1`, `VICTORY_HELPER_PRIORITY=1`. One 10-minute idle run in the world with `VICTORY_ASK_PRIORITY=ab`. Neighbouring 20 s windows are paired: | per frame | old priority | highest | |---|---|---| | asking queued before it ran | 2.49 ms | 0.27 ms | | the asking itself | 5.24 ms | 4.18 ms | | submitting thread waiting for it | 5.93 ms | 3.11 ms | Frame median about 1.3 ms less (21 of 25 pairs), submitting thread about 1.5 ms less (20 of 25 pairs). `cargo test -p victory-gpu --lib` passes. In 6 runs one test failed once, which looks like an existing intermittent test; this change doesn't touch anything tests exercise beyond the asking thread's priority. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
With VICTORY_ASK_FIRST the submitting thread waits for the submission's
write-watch asking, made on a thread kept for it. That thread was
woken some 150 us after its job was sent, 2.5-3.0 ms a frame over ~18
askings, with our other helpers and the title's threads on the cores.
It now runs at the highest priority (its work is short: ~0.3 ms an
asking). VICTORY_ASK_PRIORITY=<n> sets another (-2 to 2); =ab switches
every 20 seconds and says so in the log.

Measured that way (25 neighbouring 20 s windows in the world, with
SUBMIT_SPLIT, ASK_FIRST, OFF_LINE; RTX 4070, Ryzen 5 5600X): queued
2.49 -> 0.27 ms a frame, the asking itself 5.2 -> 4.2 ms, the
submitting thread's wait for it 5.9 -> 3.1 ms; frame median about
1.3 ms less (21 of 25 pairs).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 11:20:21 +00:00
Author
Owner

@⁠kodifan on GitHub · 2026-11-30 12:57 UTC · original

Context: RTX 5060 Ti 16 GB, Ryzen 7 7700 (32 MB L3), 32 GB DDR5-6000, Windows 11 26200, driver 621.24. foxhound v0.8.2, Series S, DLSS Quality, Frame Generation on, 30 fps target. Measured from the layer's own per-frame lines.

Rendered frame 44.0 ms at 5,990 draws (21 fps), 57.7-60.7 ms at 8,744 draws (16 fps). The submitting thread is the whole frame: 39.3 / 40.4 / 43.0 / 48.2 ms in the samples - about 5.5-6.7 us per draw. The card is 84-89 % busy and idle 5.1-9.8 ms a frame behind that thread, drawing 46-58 W.

The asking shows up in our breakdown exactly where this PR measures it: 5.3-5.7 ms per frame "asking the write watch", with only 1.0-1.2 of the asks finding something to ask:

preparing per frame, the submitting thread: 48.2 ms ... 5.7 asking the write watch
(1.2 of them finding what to ask), ... 4.9 waiting for flights

That is on a 7700 with 32 MB L3, i.e. less cache than the 5600X in the PR's numbers, so the hand-off waiting may be worse here rather than better. 2-3 ms off the submitting thread would be 5-7 % of a frame here, which matters at 44 ms.

One negative result that may save someone time: we A/B'd Memory Integrity (HVCI) on this machine - the submitting thread cost 6.7 us per draw with it on and 5.5 us with it off, inside scene-to-scene scatter. So the cost is not kernel hardening on the ask path; it is the queueing this PR addresses. We reverted HVCI.

Happy to build and test this branch on the same save and spot and report the same numbers before and after.

**@⁠kodifan** on GitHub · 2026-11-30 12:57 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/93#issuecomment-7279149531) Context: RTX 5060 Ti 16 GB, Ryzen 7 7700 (32 MB L3), 32 GB DDR5-6000, Windows 11 26200, driver 621.24. foxhound v0.8.2, Series S, DLSS Quality, Frame Generation on, 30 fps target. Measured from the layer's own per-frame lines. Rendered frame 44.0 ms at 5,990 draws (21 fps), 57.7-60.7 ms at 8,744 draws (16 fps). The submitting thread is the whole frame: 39.3 / 40.4 / 43.0 / 48.2 ms in the samples - about 5.5-6.7 us per draw. The card is 84-89 % busy and idle 5.1-9.8 ms a frame behind that thread, drawing 46-58 W. The asking shows up in our breakdown exactly where this PR measures it: **5.3-5.7 ms per frame** "asking the write watch", with only 1.0-1.2 of the asks finding something to ask: ``` preparing per frame, the submitting thread: 48.2 ms ... 5.7 asking the write watch (1.2 of them finding what to ask), ... 4.9 waiting for flights ``` That is on a 7700 with 32 MB L3, i.e. less cache than the 5600X in the PR's numbers, so the hand-off waiting may be worse here rather than better. 2-3 ms off the submitting thread would be 5-7 % of a frame here, which matters at 44 ms. One negative result that may save someone time: we A/B'd Memory Integrity (HVCI) on this machine - the submitting thread cost 6.7 us per draw with it on and 5.5 us with it off, inside scene-to-scene scatter. So the cost is not kernel hardening on the ask path; it is the queueing this PR addresses. We reverted HVCI. Happy to build and test this branch on the same save and spot and report the same numbers before and after.
Author
Owner

@⁠missionarteemis-cloud on GitHub · 2026-11-30 18:35 UTC · original

A data point from an 8-thread CPU (no SMT), where I expected this to matter most: no measurable effect here.

Machine: i7-9700K (8 cores / 8 threads), RTX 4070 12 GB, 32 GB DDR4-3000, Windows 10 22H2 (Agility SDK runtime beside victory.exe), driver 621.40. Series S profile, DLSS Quality, DLSS-FG on, the launcher's v0.8.2 switch set (process above normal, VICTORY_HELPER_PRIORITY=1). A v0.8.2 timeline shows the CPU oversubscribed: the threads' running time adds up to ~1.2x what 8 threads can give, and ~10 ms a frame of "woken, not running yet" sits on the present's chain.

Method: v0.8.2 diagnostics build with this PR and #116 cherry-picked. Your ab mode and #116's flip on the same wall-clock 20 s windows, so I bound both to VICTORY_AB bits instead. In ask_thread_priority(), crate::ab::pick("VICTORY_ASK_PRIORITY") picks 2 when on and the helper priority when off. Phases of 15 s cycle through all four combinations, standing still after loading a save, and each round is compared against its own both-off phase. Rounds where draws a frame moved by more than 2 % are left out.

Frame time vs both off, per round (3 steady rounds, ~7,650 draws a frame):

round 1 round 2 round 3 median
ASK_PRIORITY on +0.4 % -0.6 % -0.4 % -0.4 % (within noise)
READBACK_POOL on (#116) -0.8 % -1.4 % -2.1 % -1.4 %

So on this machine the asking thread's priority does not show in the frame time. My guess is that what waits here is mostly the title's own threads (~24 ms a frame on the chain) rather than our helpers. I can run a timeline with it on and off if that would help.

**@⁠missionarteemis-cloud** on GitHub · 2026-11-30 18:35 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/93#issuecomment-7288078483) A data point from an 8-thread CPU (no SMT), where I expected this to matter most: **no measurable effect here.** **Machine:** i7-9700K (8 cores / 8 threads), RTX 4070 12 GB, 32 GB DDR4-3000, Windows 10 22H2 (Agility SDK runtime beside victory.exe), driver 621.40. Series S profile, DLSS Quality, DLSS-FG on, the launcher's v0.8.2 switch set (process above normal, VICTORY_HELPER_PRIORITY=1). A v0.8.2 timeline shows the CPU oversubscribed: the threads' running time adds up to ~1.2x what 8 threads can give, and ~10 ms a frame of "woken, not running yet" sits on the present's chain. **Method:** v0.8.2 diagnostics build with this PR and #116 cherry-picked. Your `ab` mode and #116's flip on the same wall-clock 20 s windows, so I bound both to `VICTORY_AB` bits instead. In `ask_thread_priority()`, `crate::ab::pick("VICTORY_ASK_PRIORITY")` picks 2 when on and the helper priority when off. Phases of 15 s cycle through all four combinations, standing still after loading a save, and each round is compared against its own both-off phase. Rounds where draws a frame moved by more than 2 % are left out. **Frame time vs both off, per round (3 steady rounds, ~7,650 draws a frame):** | | round 1 | round 2 | round 3 | median | |---|---|---|---|---| | ASK_PRIORITY on | +0.4 % | -0.6 % | -0.4 % | **-0.4 %** (within noise) | | READBACK_POOL on (#116) | -0.8 % | -1.4 % | -2.1 % | -1.4 % | So on this machine the asking thread's priority does not show in the frame time. My guess is that what waits here is mostly the title's own threads (~24 ms a frame on the chain) rather than our helpers. I can run a timeline with it on and off if that would help.
github-bot closed this pull request 2026-12-01 01:10:32 +00:00
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 01:36 UTC · original

A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection.

Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 01:36 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/93#issuecomment-7297693468) A note on why this shows as closed: GitHub closed every open pull request by itself when main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), and they cannot be reopened. This is not a rejection. Your change is in the batch being tested for the next release, carried over as one commit with you as its author. Nothing is needed from you now; the result will be posted here.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.