perf(cpu): pin GPU and host threads to P-cores and optional disk I/O to E-cores #15

Open
github-bot wants to merge 1 commit from github-bot/gh-15 into beta AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 16:32 UTC · original
Vladimir-Human:perf/hybrid-cpu-affinity → beta · +480 −0 · 4 files · 1 commits · open

Pin performance-critical GPU frame threads to performance cores (EfficiencyClass max) on hybrid CPUs and optionally move DirectStorage worker threads onto efficiency cores (VICTORY_DISK_CORES=slow).

What is in it

  • crates/victory-gpu/src/affinity.rs + crates/victory-gpu/src/lib.rs:
    • OnceLock-cached GetSystemCpuSetInformation topology probe (partition_cpu_sets), logging fast/slow logical processor counts once and remaining a complete no-op on uniform (non-hybrid) CPUs or non-Windows platforms.
    • Safe SetThreadSelectedCpuSets soft scheduler preference helpers: keep_on_fast_cores (default on when hybrid cores exist; opt-out VICTORY_FAST_CORES=0) and keep_on_slow_cores (opt-in VICTORY_DISK_CORES=slow).
    • Zero new external crates (Cargo.toml and Cargo.lock untouched for --locked builds).
  • crates/victory-gpu/src/host.rs: pins victory-late-wait, victory-relay, and the synchronous caller of Host::submit (one-shot thread_local!) to fast cores.
  • crates/victory-hle/src/modules/dstorage.rs: calls keep_on_slow_cores("dstorage") on DirectStorage worker threads (VICTORY_DISK_CORES=slow).

Verification (305e0ef, Windows 11 Build 26300, Intel Core i5-13400F 12 fast LPs / 4 slow LPs, Rust 1.98.1)

  • cargo test -p victory-gpu --locked affinity::tests:: -- --nocapture (repeated 5x): 5/5 runs passed (verifies live GetCurrentProcessorNumberEx placement on fast vs slow cores across parent + VICTORY_DISK_CORES=slow + VICTORY_FAST_CORES=0 child processes).
  • Non-Windows #[cfg(not(windows))] build & unit tests: verified clean (0 warnings, 3/3 pure unit tests pass).
  • cargo test --workspace --locked --no-fail-fast: 584 passed, 1 pre-existing failed, 12 ignored (the sole failure is pre-existing origin/klbf-amd / beta xtask repository_passes_policy on lower.rs > 512 KiB and docs/klbf/logo.svg; cargo clippy reports 0 warnings in all 4 modified/added files, with pre-existing lints untouched in unrelated files).
  • Latency under 16-thread CPU contention (Intel Core i5-13400F, 3 trials x 400 iters): unpinned mean 69.1–92.5 us / p99 294.2–543.2 us / max 2,021–10,659 us vs pcore+bg_slow mean 51.9–54.4 us / p99 64.4–103.1 us / max 105.5–162.2 us (4–5x lower p99, >15x lower max spikes).

Not tested

  • Retail title E2E runtime run (clean-room development environment without game files).
  • Non-hybrid / AMD CPUs tested only via unit tests and OnceLock uniform-CPU fallback logic.

AI use

  • AI-assisted implementation, tests, and independent audit (gemini-4-hydrogen-high + gemini-4-neon-xhigh).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 16:32 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15) `Vladimir-Human:perf/hybrid-cpu-affinity` → `beta` · +480 −0 · 4 files · 1 commits · open Pin performance-critical GPU frame threads to performance cores (`EfficiencyClass` max) on hybrid CPUs and optionally move DirectStorage worker threads onto efficiency cores (`VICTORY_DISK_CORES=slow`). ### What is in it - `crates/victory-gpu/src/affinity.rs` + `crates/victory-gpu/src/lib.rs`: - `OnceLock`-cached `GetSystemCpuSetInformation` topology probe (`partition_cpu_sets`), logging fast/slow logical processor counts once and remaining a complete no-op on uniform (non-hybrid) CPUs or non-Windows platforms. - Safe `SetThreadSelectedCpuSets` soft scheduler preference helpers: `keep_on_fast_cores` (default on when hybrid cores exist; opt-out `VICTORY_FAST_CORES=0`) and `keep_on_slow_cores` (opt-in `VICTORY_DISK_CORES=slow`). - Zero new external crates (`Cargo.toml` and `Cargo.lock` untouched for `--locked` builds). - `crates/victory-gpu/src/host.rs`: pins `victory-late-wait`, `victory-relay`, and the synchronous caller of `Host::submit` (one-shot `thread_local!`) to fast cores. - `crates/victory-hle/src/modules/dstorage.rs`: calls `keep_on_slow_cores("dstorage")` on DirectStorage worker threads (`VICTORY_DISK_CORES=slow`). ### Verification (`305e0ef`, Windows 11 Build 26300, Intel Core i5-13400F 12 fast LPs / 4 slow LPs, Rust 1.98.1) - `cargo test -p victory-gpu --locked affinity::tests:: -- --nocapture` (repeated 5x): **5/5 runs passed** (verifies live `GetCurrentProcessorNumberEx` placement on fast vs slow cores across parent + `VICTORY_DISK_CORES=slow` + `VICTORY_FAST_CORES=0` child processes). - Non-Windows `#[cfg(not(windows))]` build & unit tests: verified clean (`0` warnings, `3/3` pure unit tests pass). - `cargo test --workspace --locked --no-fail-fast`: **584 passed, 1 pre-existing failed, 12 ignored** (the sole failure is pre-existing `origin/klbf-amd` / `beta` `xtask` `repository_passes_policy` on `lower.rs` > 512 KiB and `docs/klbf/logo.svg`; `cargo clippy` reports **0 warnings** in all 4 modified/added files, with pre-existing lints untouched in unrelated files). - Latency under 16-thread CPU contention (`Intel Core i5-13400F`, 3 trials x 400 iters): `unpinned` mean `69.1–92.5 us` / p99 `294.2–543.2 us` / max `2,021–10,659 us` vs `pcore+bg_slow` mean `51.9–54.4 us` / p99 `64.4–103.1 us` / max `105.5–162.2 us` (**4–5x lower p99, >15x lower max spikes**). ### Not tested - Retail title E2E runtime run (clean-room development environment without game files). - Non-hybrid / AMD CPUs tested only via unit tests and `OnceLock` uniform-CPU fallback logic. ### AI use - AI-assisted implementation, tests, and independent audit (`gemini-4-hydrogen-high` + `gemini-4-neon-xhigh`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:51:59 +00:00
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-25 16:51 UTC · original

I checked the uniform-CPU fallback on a Windows runner using an AMD EPYC 9V74 (4 logical processors exposed). With fast-core selection enabled and VICTORY_DISK_CORES=slow, the topology probe reported no hybrid tiers and both pin requests returned false. The four existing affinity tests and the additional uniform-CPU assertion passed. The live hybrid test printed its expected skip on this host.

Windows test output

**@⁠HandshakeHackin** on GitHub · 2026-11-25 16:51 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7168642791) I checked the uniform-CPU fallback on a Windows runner using an AMD EPYC 9V74 (4 logical processors exposed). With fast-core selection enabled and `VICTORY_DISK_CORES=slow`, the topology probe reported no hybrid tiers and both pin requests returned `false`. The four existing affinity tests and the additional uniform-CPU assertion passed. The live hybrid test printed its expected skip on this host. [Windows test output](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45657892942/job/139359417146)
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 17:02 UTC · original

Thanks a lot @⁠Vladimir-Human! Noted. I'll test it on the RX 9070 XT in the next test build and report back here.

**@⁠PastiiJay** on GitHub · 2026-11-25 17:02 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7168913539) Thanks a lot @⁠Vladimir-Human! Noted. I'll test it on the RX 9070 XT in the next test build and report back here.
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 17:16 UTC · original

Thanks again @⁠Vladimir-Human. While porting it onto the next test build I found that this build already pins the late-wait, relay and submit threads to the fast cores (VICTORY_FAST_CORES, on by default) and can keep the DirectStorage workers on the slow cores (VICTORY_DISK_CORES=slow). So this PR would pin the same threads twice. I'm leaving it open for now. If you see a thread the existing switch misses, tell me and I'll add it. #16 is ported and under test now.

**@⁠PastiiJay** on GitHub · 2026-11-25 17:16 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7169270473) Thanks again @⁠Vladimir-Human. While porting it onto the next test build I found that this build already pins the late-wait, relay and submit threads to the fast cores (`VICTORY_FAST_CORES`, on by default) and can keep the DirectStorage workers on the slow cores (`VICTORY_DISK_CORES=slow`). So this PR would pin the same threads twice. I'm leaving it open for now. If you see a thread the existing switch misses, tell me and I'll add it. #16 is ported and under test now.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 20:52 UTC · original

Thanks @⁠PastiiJay for checking! Looking at the current beta tree (e328c88), the only other persistent/pool background workers aside from victory-late-wait, victory-relay, victory-submit, and dstorage are the victory-pipelines-{i} shader compile workers (which already set THREAD_PRIORITY_BELOW_NORMAL in pipeline/make.rs), card accounting diagnostics walks, and shadow::victory-wide-{i} workers. Keeping victory-pipelines-* on slow/efficiency cores when hybrid E-cores exist is about the only extra knob worth considering so shader compilation stays out of the render P-cores' cache.

Since your internal build already covers late-wait / relay / submit via VICTORY_FAST_CORES and dstorage via VICTORY_DISK_CORES=slow, I'm completely fine closing #15 once those changes land on beta (or keeping only the hybrid/uniform-CPU fallback helper if needed). Thanks for testing #16 and #29 as well!

**@⁠Vladimir-Human** on GitHub · 2026-11-25 20:52 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7174303165) Thanks @⁠PastiiJay for checking! Looking at the current `beta` tree (`e328c88`), the only other persistent/pool background workers aside from `victory-late-wait`, `victory-relay`, `victory-submit`, and `dstorage` are the `victory-pipelines-{i}` shader compile workers (which already set `THREAD_PRIORITY_BELOW_NORMAL` in `pipeline/make.rs`), `card accounting` diagnostics walks, and `shadow::victory-wide-{i}` workers. Keeping `victory-pipelines-*` on slow/efficiency cores when hybrid E-cores exist is about the only extra knob worth considering so shader compilation stays out of the render P-cores' cache. Since your internal build already covers `late-wait` / `relay` / `submit` via `VICTORY_FAST_CORES` and `dstorage` via `VICTORY_DISK_CORES=slow`, I'm completely fine closing #15 once those changes land on `beta` (or keeping only the hybrid/uniform-CPU fallback helper if needed). Thanks for testing #16 and #29 as well!
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 20:53 UTC · original

Thanks @⁠Vladimir-Human, that's a very useful map of the remaining threads. Agreed: we keep #15 open until those changes land on beta, then close it with credit to you.

The idea of keeping the victory-pipelines-* workers on efficiency cores makes sense. Our test CPU (Ryzen 7 9800X3D) has no E-cores, so we can't measure it ourselves. If an Intel hybrid owner wants to try it, a before/after with the frame-time lines would tell us whether it's worth adding.

**@⁠PastiiJay** on GitHub · 2026-11-25 20:53 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7174327230) Thanks @⁠Vladimir-Human, that's a very useful map of the remaining threads. Agreed: we keep #15 open until those changes land on `beta`, then close it with credit to you. The idea of keeping the `victory-pipelines-*` workers on efficiency cores makes sense. Our test CPU (Ryzen 7 9800X3D) has no E-cores, so we can't measure it ourselves. If an Intel hybrid owner wants to try it, a before/after with the frame-time lines would tell us whether it's worth adding.
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/15/head:github-bot/gh-15'
git switch 'github-bot/gh-15'

Merge

Merge the changes and update on Forgejo.
git switch 'beta'
git merge --no-ff 'github-bot/gh-15'
git switch 'github-bot/gh-15'
git rebase 'beta'
git switch 'beta'
git merge --ff-only 'github-bot/gh-15'
git switch 'github-bot/gh-15'
git rebase 'beta'
git switch 'beta'
git merge --no-ff 'github-bot/gh-15'
git switch 'beta'
git merge --squash 'github-bot/gh-15'
git switch 'beta'
git merge --ff-only 'github-bot/gh-15'
git switch 'beta'
git merge 'github-bot/gh-15'
git push origin 'beta'
This discussion has been locked. Commenting is limited to contributors.
No description provided.