perf(libkernel): pin guest threads to the efficiency cores on request #12544
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12544"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-28T19:02:33Z.
What
On a hybrid CPU the queue workers and the presenter run on the performance cores by default on Linux (#626). Guest threads have no host affinity: the affinity a title sets is kept for its getters but never applied to the host thread. A title whose job workers spin at full load on every core they own therefore puts those spinners on the same performance cores, often on the second hardware thread of a core a queue worker runs on.
APS5_GUEST_AFFINITY=1now pins every guest thread to the efficiency cores of a hybrid CPU when it starts, on Linux and Windows.APS5_GUEST_AFFINITY_MASK=<hex>picks the cores instead. Both are off by default, likeAPS5_JOB_AFFINITY. That variable selects threads by one title's job worker name and is Windows only; the new one does not look at thread names.Tested
Arch Linux 7.2.11-zen, GCC 16.2.1, Ninja, Release, on
main3a2b919816, Intel Core i9-14900KF (8 performance cores with 2 threads each, 16 efficiency cores):New
guest_thread_host_affinity(Linux): setsAPS5_GUEST_AFFINITY_MASKto one core of the process and checks that two guest threads run on exactly that core, and that the creating thread keeps its mask. WithThread.cppfrommainit fails:a guest thread does not run on the cores APS5_GUEST_AFFINITY_MASK names.Full
ctest -j8on the first base (main3b362ba2e0): all 2741 tests pass (60 skipped). Rebased on3a2b919816:guest_thread_host_affinityand theguest_pthread*tests pass (56/56).tools/check_conventions.py --base origin/mainpasses.PPSA05684 (Uncharted: Legacy of Thieves Collection): its 13 job workers (
NdJobWorkerThread 0..12) spin withpauseat 100 % each. WithAPS5_GUEST_AFFINITY=1they run on the efficiency cores.The captures below follow the Performance report form. They come from clean builds of
main3a2b919816and of this branch, fda3f6ca6c ("dirty": falsein both), captured on the same machine in the same session, with warm caches. Both capture the Uncharted 4 prison yard fight, reached through the developer menu by the same scripted inputs, withAPS5_TRACE_SECONDS=195:8and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch. The environments differ only inAPS5_GUEST_AFFINITY. TheAPS5_LOCAL_*names come from my launch script and do not exist onmain.The 8 s window keeps queue 0 inside its default event buffer, so neither trace drops events. The launch script writes the log to a file in both runs; the logger reports 0.2 to 4.4 KiB per 10 s there.
main3a2b919816APS5_GUEST_AFFINITY=1queue worker 0x0busyClean
maindoes not reach this scene every time. Over 7 attempts in this session on the two builds, 5 ended early:std::bad_alloc.vkWaitForFencesreturnedVK_ERROR_DEVICE_LOST.The oversized views and the device loss do not happen on the local stack.
The captures are from the runs that reached the fight.
Traces:
main, this branchSummary line,
main:Summary line, this branch:
tools/trace_digest.py,mainseconds 195:8 from present 2410: 28 presents, frame p50 282.4 / p90 308.3 / p99 359.7 / max 359.7 ms, GPU busy 104.7 ms per present
NVIDIA GeForce RTX 4070 Ti SUPER, NVIDIA 615.78.08, Linux 7.2.11-zen1-1-zen, 2560x1440, commit
3a2b919816, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1880.2, Driver.WorkerWait.dequeue_order 1848.5, Driver.Packet 1154.7, Driver.Packet.memory_wait 758.2, Driver.Packet.dispatch 274.9, Driver.Dispatch 237.3, batch 104.5, Driver.Packet.draw 102.6, Driver.Draw 102.3, Graphics.Draw 84.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
batch 662: 6.4 ms at 1521 ms, present 2415: GPU no ranges; recorded by Driver.WorkerWait (queue worker 0x0) 29.6, Driver.WorkerWait.dequeue_order (queue worker 0x0) 29.6, Driver.Packet (queue worker 0x0) 2.6, Driver.Packet.pipeline_drain (queue worker 0x0) 1.3
batch 358: 6.1 ms at 863 ms, present 2412: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 7.4, Driver.Packet.draw (queue worker 0x0) 6.4, Driver.Draw (queue worker 0x0) 6.4, Driver.Draw.shader_compile_and_link (queue worker 0x0) 3.4
batch 2184: 6.1 ms at 4894 ms, present 2427: GPU no ranges; recorded by Recorder.Submit (draw committer) 2.0, Recorder.Reap (draw committer) 0.1, Graphics.Draw (draw committer) 0.0, Graphics.Draw.draw_and_resource_release (draw committer) 0.0
batch 3183: 6.0 ms at 7212 ms, present 2435: GPU no ranges; recorded by Driver.WorkerWait (queue worker 0x0) 44.8, Driver.WorkerWait.dequeue_order (queue worker 0x0) 44.8, Driver.Packet (queue worker 0x0) 2.9, Driver.Packet.draw (queue worker 0x0) 1.2
batch 2435: 6.0 ms at 5445 ms, present 2429: GPU no ranges; recorded by Driver.WorkerWait (queue worker 0x0) 46.0, Driver.WorkerWait.dequeue_order (queue worker 0x0) 46.0, Driver.Packet (queue worker 0x0) 1.9, Driver.Packet.pipeline_drain (queue worker 0x0) 0.8
tools/trace_digest.py, this branchseconds 195:8 from present 2503: 32 presents, frame p50 250.1 / p90 278.1 / p99 302.5 / max 302.5 ms, GPU busy 93.9 ms per present
NVIDIA GeForce RTX 4070 Ti SUPER, NVIDIA 615.78.08, Linux 7.2.11-zen1-1-zen, 2560x1440, commit fda3f6ca6c0c, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.WorkerWait 1718.2, Driver.WorkerWait.dequeue_order 1684.3, Driver.Packet 963.9, Driver.Packet.memory_wait 620.6, Driver.Packet.dispatch 233.7, Driver.Dispatch 198.5, batch 93.9, Driver.Packet.draw 92.8, Driver.Draw 92.6, Graphics.Draw 74.4
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
batch 218: 5.5 ms at 482 ms, present 2504: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 5.7, Driver.Packet.draw (queue worker 0x0) 5.1, Driver.Draw (queue worker 0x0) 5.0, Driver.Draw.shader_compile_and_link (queue worker 0x0) 2.4
batch 515: 5.4 ms at 1091 ms, present 2507: GPU no ranges; recorded by no CPU slices
batch 1408: 5.2 ms at 2940 ms, present 2514: GPU no ranges; recorded by Driver.Packet (queue worker 0x0) 5.7, Driver.Packet.draw (queue worker 0x0) 5.1, Driver.Draw (queue worker 0x0) 5.1, Driver.Draw.shader_compile_and_link (queue worker 0x0) 2.6
batch 266: 5.1 ms at 569 ms, present 2505: GPU no ranges; recorded by no CPU slices
batch 1904: 5.1 ms at 3990 ms, present 2519: GPU no ranges; recorded by Driver.Packet (queue worker 0x39) 9.5, Driver.Packet.dispatch (queue worker 0x39) 9.5, Driver.Dispatch (queue worker 0x39) 9.0, GpuMutex.wait.dispatch (queue worker 0x39) 7.2
Toggling the variable on one build of a local stack of open PRs gave the same direction: 36.2 vs 40.4 presents per 10 s in the prison, and 13.3 vs 14.8 in The Lost Legacy's Sri Lanka.
The variable stays opt-in because
APS5_JOB_AFFINITYmeasured 0 to -9 % at a video stage in the title it was written for.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T19:12:44Z.
Review: CHANGES_REQUESTED
The code and the test look right (
guest_thread_host_affinityfails without theThread.cppchange), and keeping it opt-in is reasonable. One thing is missing before merging:perflabel needs the evidence the Performance report form asks for (see the bot comment above): theaps5-summary.jsonlline of a capture onmainand one with the change, from the same title, scene and machine, both traces attached, and the output oftools/trace_digest.pyfor each. The table in### Testedhas the numbers but not the captures behind them. Please paste those and the PR can go on.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T19:21:05Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The affinity change and its focused test build successfully, but this
perfPR is missing the paired trace evidence required by the repository's performance-report rules.What I ran
Reviewed exact head
d74683cb2b088c1d2c596e47b92a437cd4dd994eagainst currentmain319621ba2e578bd053b0baba2877fe70520e0737; the merge tree is clean. Environment: Debian 12 x86_64, GCC 12.2.0, CMake, Ninja.Results
mainguest_thread_host_affinity_testsbuildguest_thread_host_affinityRaw output
Negative control
Findings
Blocking: The PR is labeled
perf, but it does not include the twoaps5-summary.jsonllines formainand the change, the matching trace attachments, ortools/trace_digest.pyoutput. The report form requires those captures from the same machine, title, scene, and settings; the current presents-per-10-second table does not provide the requested capture data. Please attach both traces, paste both summary lines, and include each digest output.Non-blocking: This host cannot run the focused test because it fails the project's CPU-feature guard before reaching test assertions. The hosted Windows job linked changed host-only test targets but skipped CTest; the Linux and specialized jobs were skipped. The PR description reports separate Linux test runs and title measurements, which I did not independently reproduce.
Sources
Not verified
I could not run the test assertions on this CPU, independently verify the hybrid-core behavior on supported hardware, reproduce the title captures, or verify the reported performance delta. A QEMU rerun was unavailable because the temporary worktree and executable were no longer present after the first CTest attempt.
To get this to a good state
Attach the paired base/change traces, paste their
aps5-summary.jsonllines, and add the output ofpython3 tools/trace_digest.pyfor each trace. Please also runguest_thread_host_affinityon a CPU that passes the project's feature guard. I will rerun the same review commands against the updated head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T01:25:31Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested for the performance report
The code branch is now based on current
main, and the new captures match their summary lines, but both captures use extraAPS5_TRACE_*switches excluded by the required performance protocol.What I ran
fda3f6ca6c0cbf3370ecd5fb580312f707ecc082againstmain3a2b91981651569163768854a1fcdc7193b6667b.git diff --check upstream/main...refs/remotes/review/12544.git merge-tree --write-tree upstream/main refs/remotes/review/12544.python3 tools/check_conventions.py --base upstream/main --head refs/remotes/review/12544.python3 tools/trace_digest.py <trace> --frames 2 --top 3, matching each provided summary line to its trace.Results
f0e052678e77fe66adfbceccab77b3f6ba4ce16cguest_thread_host_affinityandguest_pthread*, author-reported; not rerun locallyRaw trace-digest output excerpts
Negative control
No independent negative control was run on this rebased head. My prior local run on the earlier head built the test executable but stopped at the project CPU-feature guard before its assertions.
Findings
Blocking
APS5_TRACE_SUMMARY_EVERY=10andAPS5_TRACE_DIR=<path>. The repository’s Performance report form requires no additionalAPS5_TRACE_*orAPS5_PROFILE_*switches. Please recapturemainand this head with only the required capture setting, then replace the summaries, traces, and digests. Both current digests also report dropped trace events; please check whether the prescribed recapture avoids that loss.Non-blocking
mainand preserves the single-topic diff. I independently checked the trace files and summary records, but did not rerun the affinity CTests on this host.Sources
Not verified
To get this to a good state
Recapture both builds with the documented capture settings and no extra trace/profile switches, include the refreshed summary lines, traces, and digests, and confirm the digests no longer report dropped events if possible. I will recheck the updated report and hosted build on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T03:18:09Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
I reviewed the performance report at exact head
fda3f6ca6c0cbf3370ecd5fb580312f707ecc082. The new main-versus-change pair fixes the commit-provenance problem from my prior review, and both published digest sections reproduce exactly. Two capture-form requirements remain unmet.What I ran
On Linux, I downloaded the two trace assets linked by the PR and ran the
trace_digest.pyversion from currentmain(3a2b91981651569163768854a1fcdc7193b6667b) with each matching summary line extracted from the PR description:I also checked the current performance-report form and hosted checks. I did not rebuild the project or rerun the game or unit tests.
Results
main3a2b91981651and clean PR commitfda3f6ca6c0cAPS5_GUEST_AFFINITYguest_thread_host_affinityandguest_pthread*tests on the rebased head; I did not rerun themNegative control
The main capture is the requested baseline: 28 presents and 282.4 ms frame-time p50. The candidate reports 32 presents and 250.1 ms p50. This review verifies the supplied trace and summary artifacts, not an independently repeated performance run.
Findings
Blocking
aps5-trace-<commit>-<pid>.json.gzto be attached in its Traces field. The description instead links the assets from a separate fork release. Please attach both files to this PR.Non-blocking
Sources
maintrace_digest.pyat the baseline commitNot verified
I did not build the PR, rerun its CTest targets, or reproduce the game captures. Linux and specialized hosted jobs were skipped.
To get this to a good state
Attach both traces directly to the PR and provide a fresh pair captured without log redirection, with matching summary lines and newly generated digests. Then I can recheck the report against the same requirements.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T06:42:34Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
d2058add1c490bdb78e75677f27e1719f34657e2. I read the prepared description, commits, manifest, diff, and all four changed files listed as reviewed. I also read the relevantCpuTopology.hppimplementation. No commands or tests were run in this session; the test and performance results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
core/libs/tests/GuestThreadHostAffinity.cpp:23limits the observed affinity to CPUs 0–63 and usescpu_set_t. On Linux hosts with CPU IDs beyond that range,CurrentMask()omits allowed CPUs, so the test can incorrectly report that the guest thread's affinity differs from the requested mask. Consider using a dynamically sized CPU set, or explicitly constrain the test to representable CPUs.Not verified
I did not run the build, tests, conventions check, or performance captures. The reported full-suite and focused test results, as well as the reported hardware performance measurements, are supplied by the author and were not independently checked. No files were excluded from review: all four changed files marked
reviewedin the manifest were read;files.jsonwas not available through the reader.To get this to a good state
Nothing is required. The test portability point above is optional.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:19:16Z.
Review: COMMENTED
I built and ran
guest_thread_host_affinitywithd2058add1cintegrated into a Linux release build. The fixture passed with a process mask of0xfffand an explicit guest mask of0x800. It verified that both created guest threads ran on the selected CPU and that the creating host thread kept its original affinity. The host reportedhybrid=0, so this run covers the explicit mask path.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.