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

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/2903 into main
0xkn0wh3r3 commented 2026-11-25 23:32:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:32:49Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615951527 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:32:49Z. --- ## 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.
kotekompotek commented 2026-11-26 00:03:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:35:39Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066484139 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6066484139). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:35:39Z. **Review:** COMMENTED --- 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.
fuzeofficlal commented 2026-11-26 00:03:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:43:20Z.

Review: COMMENTED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066557488 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6066557488). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:43:20Z. **Review:** COMMENTED --- 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.
matheusfrta commented 2026-11-26 03:05:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by matheusfrta on 2026-11-26T02:13:36Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7180586605 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903#issuecomment-7180586605). Originally posted by [matheusfrta](https://github.com/matheusfrta) on 2026-11-26T02:13:36Z. --- 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.
Marvisak commented 2026-11-26 03:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:18:12Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180668467 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903#issuecomment-7180668467). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:18:12Z. --- <!-- 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)_
Dukestar69 commented 2026-11-26 14:01:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T13:11:39Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6074707888 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2903#pullrequestreview-6074707888). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T13:11:39Z. **Review:** APPROVED --- 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 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/2903:upstream-pr/2903'
git switch 'upstream-pr/2903'

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