HLE: the title's idle and lowest threads run below normal #2903

Open
github-bot wants to merge 2 commits from github-bot/gh-2903 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:32 UTC · original
0xkn0wh3r3:hle/title-idle-threads-below-normal → main · +71 −0 · 1 files · 2 commits · open

What

SetThreadPriority is now handled by the kernel module. When the title asks for idle (-15) or lowest (-2) priority, the thread gets below normal (-1) instead. Every other priority goes to the host unchanged. VICTORY_TITLE_PRIORITIES=0 passes every priority through as before.

Why

Some of the title's threads set themselves to idle priority, the streaming pager among them. On the console an idle thread still gets whatever the rest of the title leaves of its core. On a PC the cores are also busy with other programs and with our own workers (pipeline workers already run below normal). With all of those busy, an idle-priority thread ran about once every four seconds, whenever the Windows scheduler boosted it, and any loading waiting on it stalled too. The fork measured loads finishing 1.1 s late on average and 4.8 s at worst.

Nothing here depends on the GPU vendor.

Where it comes from

From the avatarmanz/VIctory-7900XTX fork, commit 0d065d3. The cherry-pick keeps its author. One change: the host call now goes through kernel's host module (a stub on non-Windows), as TerminateProcess does, so the module still builds off Windows. The comment no longer names the fork's runs.

Tested (Windows 11, RTX 5070 Ti)

  • cargo test -p victory-hle: 154 passed. New tests: no_title_thread_waits_for_idle_processors (the priority mapping) and an_idle_title_thread_is_set_below_normal_on_the_host (a real thread asks for -15 and the host reports -1).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.

Not tested

  • Not run with the title on this machine, so the loading-time numbers above are the fork's (measured on its RX 7900 XTX machine), not mine.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903) `0xkn0wh3r3:hle/title-idle-threads-below-normal` → `main` · +71 −0 · 1 files · 2 commits · open ## What `SetThreadPriority` is now handled by the kernel module. When the title asks for idle (-15) or lowest (-2) priority, the thread gets below normal (-1) instead. Every other priority goes to the host unchanged. `VICTORY_TITLE_PRIORITIES=0` passes every priority through as before. ## Why Some of the title's threads set themselves to idle priority, the streaming pager among them. On the console an idle thread still gets whatever the rest of the title leaves of its core. On a PC the cores are also busy with other programs and with our own workers (pipeline workers already run below normal). With all of those busy, an idle-priority thread ran about once every four seconds, whenever the Windows scheduler boosted it, and any loading waiting on it stalled too. The fork measured loads finishing 1.1 s late on average and 4.8 s at worst. Nothing here depends on the GPU vendor. ## Where it comes from From the avatarmanz/VIctory-7900XTX fork, commit [`0d065d3`](https://github.com/avatarmanz/VIctory-7900XTX/commit/0d065d35210e8751f5382a2254d6cc1fbc822049). The cherry-pick keeps its author. One change: the host call now goes through kernel's `host` module (a stub on non-Windows), as `TerminateProcess` does, so the module still builds off Windows. The comment no longer names the fork's runs. ## Tested (Windows 11, RTX 5070 Ti) - `cargo test -p victory-hle`: 154 passed. New tests: `no_title_thread_waits_for_idle_processors` (the priority mapping) and `an_idle_title_thread_is_set_below_normal_on_the_host` (a real thread asks for -15 and the host reports -1). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. ## Not tested - Not run with the title on this machine, so the loading-time numbers above are the fork's (measured on its RX 7900 XTX machine), not mine.
Some of the title's threads set themselves to idle priority, its
streaming pager's among them. On the console they get what the rest of
the title leaves of its cores; on a PC the processors are also wanted by
other programs and by our own workers (pipeline workers run below
normal), and with all of them busy such a thread ran once in four
seconds or so, when the host's scheduler boosted it, and the loading
that waits for it with it: loads were seen done 1.1 s late on average,
4.8 s at worst.

SetThreadPriority is now ours: idle and lowest become below normal, and
every other priority goes to the host as the title asked.
VICTORY_TITLE_PRIORITIES=0 passes them all through as before.

From avatarmanz/VIctory-7900XTX 0d065d3, with the host call moved into
kernel's host module so the module still builds off Windows.
The values between them (-14 to -3) are not priorities: they go to the
host unchanged, which refuses them with ERROR_INVALID_PARAMETER, as it
did before. (Review on #2903.)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:07 +00:00
Author
Owner

@⁠matheusfrta on GitHub · 2026-11-26 02:13 UTC · original

Tested c6fa949 on Windows 11 (NVIDIA GeForce GTX 1080 Ti, driver 32.0.15.8266), Rust 1.99.0 MSVC:

  • cargo test -p victory-hle --locked: 157 passed / 0 failed.
  • cargo clippy -p victory-hle --lib --tests --locked -- -D warnings: clean.
  • cargo xtask policy: ok.
**@⁠matheusfrta** on GitHub · 2026-11-26 02:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903#issuecomment-7180586605) Tested `c6fa949` on Windows 11 (NVIDIA GeForce GTX 1080 Ti, driver 32.0.15.8266), Rust 1.99.0 MSVC: - `cargo test -p victory-hle --locked`: 157 passed / 0 failed. - `cargo clippy -p victory-hle --lib --tests --locked -- -D warnings`: clean. - `cargo xtask policy`: ok.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:18 UTC · original

Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). This adds a SetThreadPriority export to the HLE kernel module (modules/kernel.rs, which covers kernel32/kernelbase). title_priority maps only IDLE (-15) and LOWEST (-2) to BELOW_NORMAL (-1) and passes every other value through unchanged; VICTORY_TITLE_PRIORITIES=0 turns the mapping off. The Win32 constants are right. This is host scheduling, not console semantics, and the PR states the reason (late loads from idle-priority threads competing with the pipeline workers, which run below normal). CI check passes.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903#issuecomment-7180668467) <!-- victory-triage v1 head=c6fa9496ce6f0e1aaa1f1332e9cd92f36cd94648 verdict=merge-candidate at=2026-11-26T02:18:05Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). This adds a `SetThreadPriority` export to the HLE `kernel` module (`modules/kernel.rs`, which covers kernel32/kernelbase). `title_priority` maps only IDLE (-15) and LOWEST (-2) to BELOW_NORMAL (-1) and passes every other value through unchanged; `VICTORY_TITLE_PRIORITIES=0` turns the mapping off. The Win32 constants are right. This is host scheduling, not console semantics, and the PR states the reason (late loads from idle-priority threads competing with the pipeline workers, which run below normal). CI `check` passes. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 23:35 UTC · original · reviewed

Sound: mapping the title's idle/lowest range (-15..=-2) to below-normal keeps those threads ahead of our own below-normal workers while staying under the title's normal threads — the measured starvation (boost-only runs, seconds-late loads) is exactly what the clamp fixes. Range is correct since Windows priorities can't go below -15. The =0 opt-out preserves title semantics. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 23:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6066484139) · **reviewed** Sound: mapping the title's idle/lowest range (-15..=-2) to below-normal keeps those threads ahead of our own below-normal workers while staying under the title's normal threads — the measured starvation (boost-only runs, seconds-late loads) is exactly what the clamp fixes. Range is correct since Windows priorities can't go below -15. The =0 opt-out preserves title semantics. LGTM.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:43 UTC · original · reviewed

Verified head 51a71e98 cleanly on origin/main (63bcca43) on Windows 11 x64.

Code Review

  • Clamping idle/lowest priorities to THREAD_PRIORITY_BELOW_NORMAL (-1) with the VICTORY_TITLE_PRIORITIES=0 escape hatch is clean and keeps non-Windows builds intact.
  • Minor nits (non-blocking):
    • IDLE..=LOWEST (-15..=-2) also maps invalid Win32 priority values in -14..=-3 to -1 (succeeding instead of failing with ERROR_INVALID_PARAMETER as SetThreadPriority normally does); matching IDLE | LOWEST directly avoids accepting invalid values.
    • GetThreadPriority passes through to the host, so a title querying back its own priority sees -1 (covered by the new test).

Local Verification

  • cargo test --locked -p victory-hle: 154/154 unit tests passed (including no_title_thread_waits_for_idle_processors and an_idle_title_thread_is_set_below_normal_on_the_host), plus fidelityfx (1/1) and no_dll_planting (1/1).
  • cargo clippy --locked -p victory-hle --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6066557488) · **reviewed** Verified head `51a71e98` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64. ### Code Review - Clamping idle/lowest priorities to `THREAD_PRIORITY_BELOW_NORMAL` (`-1`) with the `VICTORY_TITLE_PRIORITIES=0` escape hatch is clean and keeps non-Windows builds intact. - **Minor nits (non-blocking)**: - `IDLE..=LOWEST` (`-15..=-2`) also maps invalid Win32 priority values in `-14..=-3` to `-1` (succeeding instead of failing with `ERROR_INVALID_PARAMETER` as `SetThreadPriority` normally does); matching `IDLE | LOWEST` directly avoids accepting invalid values. - `GetThreadPriority` passes through to the host, so a title querying back its own priority sees `-1` (covered by the new test). ### Local Verification - `cargo test --locked -p victory-hle`: **154/154** unit tests passed (including `no_title_thread_waits_for_idle_processors` and `an_idle_title_thread_is_set_below_normal_on_the_host`), plus `fidelityfx` (1/1) and `no_dll_planting` (1/1). - `cargo clippy --locked -p victory-hle --tests -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 13:11 UTC · original · approved these changes

Verified against origin/main (63bcca4):

  • cargo test -p victory-hle --lib modules::kernel:: -- --test-threads=1: 7/7 passed (including an_idle_title_thread_is_set_below_normal_on_the_host and no_title_thread_waits_for_idle_processors).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly maps idle and lowest title thread priorities to THREAD_PRIORITY_BELOW_NORMAL on the host.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 13:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6074707888) · **approved these changes** Verified against `origin/main` (`63bcca4`): - `cargo test -p victory-hle --lib modules::kernel:: -- --test-threads=1`: 7/7 passed (including `an_idle_title_thread_is_set_below_normal_on_the_host` and `no_title_thread_waits_for_idle_processors`). - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly maps idle and lowest title thread priorities to `THREAD_PRIORITY_BELOW_NORMAL` on the host. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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/2903/head:github-bot/gh-2903'
git switch 'github-bot/gh-2903'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2903'
git switch 'github-bot/gh-2903'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2903'
git switch 'github-bot/gh-2903'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2903'
git switch 'main'
git merge --squash 'github-bot/gh-2903'
git switch 'main'
git merge --ff-only 'github-bot/gh-2903'
git switch 'main'
git merge 'github-bot/gh-2903'
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/Marvisak--VIctory!2903
No description provided.