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

Closed
Vladimir-Human wants to merge 60 commits from upstream-pr/15 into main
Vladimir-Human commented 2026-11-25 16:32:51 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T16:32:51Z.


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).
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5495180378 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T16:32:51Z. --- 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`).
HandshakeHackin commented 2026-11-25 16:51:42 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-25T16:51:42Z.


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

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7168642791 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7168642791). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-25T16:51:42Z. --- 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)
PastiiJay commented 2026-11-25 17:02:33 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T17:02:33Z.


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

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7168913539 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7168913539). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T17:02:33Z. --- 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 commented 2026-11-25 17:16:50 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T17:16:50Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7169270473 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7169270473). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T17:16:50Z. --- 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.
Vladimir-Human commented 2026-11-25 20:52:23 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T20:52:23Z.


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!

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174303165 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7174303165). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T20:52:23Z. --- 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!
PastiiJay commented 2026-11-25 20:53:26 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T20:53:26Z.


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.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174327230 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7174327230). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T20:53:26Z. --- 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.
Vladimir-Human commented 2026-11-28 18:42:22 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:42:22Z.


Closing obsolete PR: the changes are already present on origin/stable-amd (cores.rs).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243993485 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/15#issuecomment-7243993485). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:42:22Z. --- Closing obsolete PR: the changes are already present on `origin/stable-amd` (`cores.rs`).

Pull request closed

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
PastiiJay/klbf-lab!15
No description provided.