graphics: run the GPU thread at highest priority on Windows (cp2077) #2106

Open
github-bot wants to merge 1 commit from github-bot/gh-2106 into main AGit
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 13:27 UTC · original
ArtyomZabroda:pr/gpu-thread-priority → main · +17 −0 · 3 files · 1 commits · open

If Cyberpunk 2077 starts more job threads than the host has cores, they
spin while they wait for work. Windows shares the cores evenly between
them, so the GPU thread, which bounds the frame, keeps losing its core to
threads that only spin.

Raise the GPU thread to THREAD_PRIORITY_HIGHEST when it starts. Other
platforms are unchanged: Linux needs CAP_SYS_NICE to raise a thread's
priority, and neither has been measured.

Cyberpunk 2077 on a Ryzen 5 7500F (6 cores, 12 threads)
Before (2 FPS):
Снимок экрана 2026-11-04 161902
After (8 FPS):
Снимок экрана 2026-11-04 160943

**@⁠ArtyomZabroda** on GitHub · 2026-11-04 13:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106) `ArtyomZabroda:pr/gpu-thread-priority` → `main` · +17 −0 · 3 files · 1 commits · open If Cyberpunk 2077 starts more job threads than the host has cores, they spin while they wait for work. Windows shares the cores evenly between them, so the GPU thread, which bounds the frame, keeps losing its core to threads that only spin. Raise the GPU thread to THREAD_PRIORITY_HIGHEST when it starts. Other platforms are unchanged: Linux needs CAP_SYS_NICE to raise a thread's priority, and neither has been measured. Cyberpunk 2077 on a Ryzen 5 7500F (6 cores, 12 threads) Before (2 FPS): <img width="1276" height="749" alt="Снимок экрана 2026-11-04 161902" src="https://github.com/user-attachments/assets/b19c3777-fa7d-4b40-ac19-e9a52551ba59" /> After (8 FPS): <img width="1279" height="747" alt="Снимок экрана 2026-11-04 160943" src="https://github.com/user-attachments/assets/42ca76d5-c417-4c0a-8ea5-dfbc683aa5c2" />
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:29 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-04 13:33 UTC · original

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

On Windows, Common::Thread adds a method that requests THREAD_PRIORITY_HIGHEST for the calling thread and returns whether the request succeeded. GuestGpu::ThreadRun calls this method before its work loop and logs if the request fails. Other platforms do not run this priority-setting code.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Minimal · up to 5fd2e

The change is limited to Windows and preserves normal GPU operation if priority elevation fails.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: running the GPU thread at highest priority on Windows.
Description check Passed The description explains the Windows priority change, its performance rationale, platform scope, and reported Cyberpunk 2077 results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b2f40c6c03 and 5fd2efcbf1.

Files selected for processing: 3
  • src/common/threads.cpp
  • src/common/threads.h
  • src/graphics/guest_gpu/graphicsRun.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-04 13:33 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6631997500) <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2106?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> On Windows, `Common::Thread` adds a method that requests `THREAD_PRIORITY_HIGHEST` for the calling thread and returns whether the request succeeded. `GuestGpu::ThreadRun` calls this method before its work loop and logs if the request fails. Other platforms do not run this priority-setting code. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"5fd2efcbf1c503569988fc0ca276fe2710b2572e" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>5fd2e</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `5fd2e` --> <!-- final_review_risk_coverage:{"sourceCommitId":"5fd2efcbf1c503569988fc0ca276fe2710b2572e","coveredCommitId":"5fd2efcbf1c503569988fc0ca276fe2710b2572e","kind":"reviewed"} --> The change is limited to Windows and preserves normal GPU operation if priority elevation fails. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 warning</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: running the GPU thread at highest priority on Windows. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description explains the Windows priority change, its performance rationale, platform scope, and reported Cyberpunk 2077 results. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 3 files. **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2106)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/b2f40c6c03849e01535caf1d408025fe5ad25b26/.coderabbit.yaml>) - **Commit**: [b2f40c6](<https://github.com/KytyPS5/KytyPS5/commit/b2f40c6c03849e01535caf1d408025fe5ad25b26>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `bd5b9cee-fbc1-4207-bf72-7c62d2f4737a` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between b2f40c6c03849e01535caf1d408025fe5ad25b26 and 5fd2efcbf1c503569988fc0ca276fe2710b2572e. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 3</strong></summary> <dl> <dd> * `src/common/threads.cpp` * `src/common/threads.h` * `src/graphics/guest_gpu/graphicsRun.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠Nmzik on GitHub · 2026-11-04 19:13 UTC · original

@⁠ArtyomZabroda I think it’s related to AMD multi die CPU

**@⁠Nmzik** on GitHub · 2026-11-04 19:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6639693142) @⁠ArtyomZabroda I think it’s related to AMD multi die CPU
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 19:26 UTC · original · edited 2026-11-04 19:55 UTC

@⁠Nmzik I don't think so. The 7500F has the same layout as the 7700X: one CCD
plus an I/O die. In #182 the 7700X (8 cores) gets 7-10 FPS in gameplay without this change, while my 7500f gets ~1 FPS on the same code and ~8 FPS with it. So the die layout is the same and the difference is core count: with fewer cores, the spinning job threads take the GPU thread's time unless it runs at a higher priority.

**@⁠ArtyomZabroda** on GitHub · 2026-11-04 19:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6639999565) · edited 2026-11-04 19:55 UTC @⁠Nmzik I don't think so. The 7500F has the same layout as the 7700X: one CCD plus an I/O die. In #182 the 7700X (8 cores) gets 7-10 FPS in gameplay without this change, while my 7500f gets ~1 FPS on the same code and ~8 FPS with it. So the die layout is the same and the difference is core count: with fewer cores, the spinning job threads take the GPU thread's time unless it runs at a higher priority.
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 19:37 UTC · original · edited 2026-11-04 19:55 UTC

I can run a test: I'll try #2110, which fixes the 100% CPU usage across all threads, without this patch, and see whether the FPS goes up once the GPU thread no longer has to compete for CPU time. I'll post the results here when I'm done.

**@⁠ArtyomZabroda** on GitHub · 2026-11-04 19:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6640225601) · edited 2026-11-04 19:55 UTC I can run a test: I'll try #2110, which fixes the 100% CPU usage across all threads, without this patch, and see whether the FPS goes up once the GPU thread no longer has to compete for CPU time. I'll post the results here when I'm done.
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 19:53 UTC · original · edited 2026-11-04 19:55 UTC

#2110 fixes the FPS issue on its own. But I don't think this PR is redundant: the two tackle the same problem from different sides. #2110 removes one source of CPU contention (Wwise polling an event flag), while this PR keeps the GPU thread from losing its core to any guest thread that spins, not just that one.

Снимок экрана 2026-11-04 224942
**@⁠ArtyomZabroda** on GitHub · 2026-11-04 19:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6640581949) · edited 2026-11-04 19:55 UTC #2110 fixes the FPS issue on its own. But I don't think this PR is redundant: the two tackle the same problem from different sides. #2110 removes one source of CPU contention (Wwise polling an event flag), while this PR keeps the GPU thread from losing its core to any guest thread that spins, not just that one. <img width="1278" height="744" alt="Снимок экрана 2026-11-04 224942" src="https://github.com/user-attachments/assets/1fbb8b85-3813-433f-9a75-2e96e5fec589" />
Author
Owner

@⁠Nmzik on GitHub · 2026-11-04 21:36 UTC · original · edited 2026-11-04 21:37 UTC

while this PR keeps the GPU thread from losing its core to any guest thread that spins

@⁠ArtyomZabroda Thanks for investigating!

I've seen multiple PRs doing the following solutions to get "better FPS":
1)give the GPU thread the highest priority.
2)give GPU thread a dedicated CPU core.
3)GPU thread runs on a performance core (on newer Intel CPUs).
4)Something related to multi-die AMD CPUs?
For me, options 1–3 don't seem to provide ANY benefits on Linux (Intel 275HX) as they all depend on the OS scheduler

I haven't tested any of these solutions on Windows, though :)

**@⁠Nmzik** on GitHub · 2026-11-04 21:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6642723680) · edited 2026-11-04 21:37 UTC > while this PR keeps the GPU thread from losing its core to any guest thread that spins @⁠ArtyomZabroda Thanks for investigating! I've seen multiple PRs doing the following solutions to get "better FPS": 1)give the GPU thread the highest priority. 2)give GPU thread a dedicated CPU core. 3)GPU thread runs on a performance core (on newer Intel CPUs). 4)Something related to multi-die AMD CPUs? For me, options 1–3 don't seem to provide ANY benefits on Linux (Intel 275HX) as they all depend on the OS scheduler I haven't tested any of these solutions on Windows, though :)
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 21:40 UTC · original

@⁠Nmzik Let’s postpone this issue until the weekend. I'll download linux and investigate it more thoroughly. #2110 fixes the FPS, so it's probably worth taking a look at now.

**@⁠ArtyomZabroda** on GitHub · 2026-11-04 21:40 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6642809834) @⁠Nmzik Let’s postpone this issue until the weekend. I'll download linux and investigate it more thoroughly. #2110 fixes the FPS, so it's probably worth taking a look at now.
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-04 22:06 UTC · original · edited 2026-11-04 22:11 UTC

@⁠Nmzik
Could you try running Cyberpunk on a build without #2110, limited to fewer cores to simulate a low-core CPU:
taskset -c 0-7 ./kyty_emulator
taskset -c 0-11 ./kyty_emulator
I expect much worse performance with the first command, which is exactly what my patch is trying to fix.
If it does get worse, could you then raise the GPU thread's priority with
sudo renice -n -10 -p tid
(tid = the GPU thread's id from top -H -p <emulator pid>)? That's roughly the linux equivalent of what my patch does on windows.

**@⁠ArtyomZabroda** on GitHub · 2026-11-04 22:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6643332085) · edited 2026-11-04 22:11 UTC @⁠Nmzik Could you try running Cyberpunk on a build without #2110, limited to fewer cores to simulate a low-core CPU: taskset -c 0-7 ./kyty_emulator <args> taskset -c 0-11 ./kyty_emulator <args> I expect much worse performance with the first command, which is exactly what my patch is trying to fix. If it does get worse, could you then raise the GPU thread's priority with sudo renice -n -10 -p tid (tid = the GPU thread's id from `top -H -p <emulator pid>`)? That's roughly the linux equivalent of what my patch does on windows.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-11-10 18:29 UTC · original

I tested this PR with a second game, Demon's Souls (PPSA01341), and sampled the emulator's threads with and without it. The CPU is a Ryzen 5 7600X (one CCD, 6 cores / 12 threads), so no multi-die layout here either. Windows 11, RX 9070 XT, emulator limited to 10 logical CPUs.

Game result. main 782a85c62 against the same commit plus this PR's commit (5fd2efcbf). Both builds of a pair also carry the same local test-only commits (a scripted pad input player and logging); they differ only in this PR's commit. Same input script and same run length for every run, each build warmed up with one run first. Overlay values from the last screenshot of each run:

build run last screenshot FPS "CPU waiting on GPU"
main 1 black screen 1.9 767 ms/s (31 waits/s)
main 2 language select 1.0 860 ms/s (15 waits/s)
main 3 language select 1.8 931 ms/s (31 waits/s)
main 4 language select 4.7 879 ms/s (72 waits/s)
this PR 1 3D scene after the menus 13.3 66 ms/s (171 waits/s)
this PR 2 3D scene after the menus 23.6 97 ms/s (310 waits/s)
this PR 3 3D scene after the menus 17.7 91 ms/s (230 waits/s)
this PR 4 3D scene after the menus 22.2 107 ms/s (310 waits/s)

The FPS values come from different scenes, so they are not like for like. The result is how far each build got with the same input: with the PR all four runs reached the 3D scene, main never left the first screens.

Thread CPU use, sampled in the middle of a run (percent of one logical CPU):

build whole process the 13 game threads named BPE JobWorkerThread GPU thread
main 959 % 43.4 to 83.4 % each 0.3 %, priority 0
this PR 967 % 27.2 to 84.1 % each 70.9 %, priority +2
this PR, second run 966 % 25.0 to 83.1 % each 75.9 %, priority +2

What the GPU thread does on main. 60 stack samples of it in that window: 42 % are blocked in a wait inside the Vulkan driver below MasterSemaphore::Wait <- CommandScheduler::Wait <- BufferCache::DownloadBufferMemory (a buffer readback waiting for the GPU), and 55 % have the instruction pointer in user-mode code (the remaining 3 % are in rows my sampler did not print), although the thread received only 0.3 % of a CPU in the same window. A thread that sits in user-mode code and gets no CPU time is ready to run and is not being scheduled. So on main the GPU thread waits in the ready queue behind the workers; with the PR it runs.

Why the workers never free a CPU. The workers' idle loop is pause + rdtsc (eboot 0x83b6ba to 0x83b82c). A worker only goes to sleep when its last job is older than 2 * sceKernelGetTscFrequency() ticks, so while the game is running all 13 spin between jobs and keep the CPUs busy (959 % of the 1000 % available in the table above).

The Windows side, measured outside the emulator. A small standalone program on the same PC: 10 CPUs, 13 threads spinning on pause + rdtsc at normal priority, plus one thread that wakes from SleepConditionVariableCS(..., 1) by timeout (1 ms timer period):

waking thread spinners time between wake-ups (median / p90)
normal priority 0 1.0 ms / 2.0 ms
normal priority 13 17.8 ms / 33.5 ms
highest priority 13 1.0 ms / 2.0 ms

So at equal priority a thread that becomes ready on Windows can wait 17 to 33 ms for a CPU behind spinning threads, and at a higher priority it does not wait. This is a standalone test, not a measurement inside the game, and I have not measured Linux.

**@⁠Nawid3333** on GitHub · 2026-11-10 18:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-6775766744) I tested this PR with a second game, Demon's Souls (PPSA01341), and sampled the emulator's threads with and without it. The CPU is a Ryzen 5 7600X (one CCD, 6 cores / 12 threads), so no multi-die layout here either. Windows 11, RX 9070 XT, emulator limited to 10 logical CPUs. **Game result.** main 782a85c62 against the same commit plus this PR's commit (5fd2efcbf). Both builds of a pair also carry the same local test-only commits (a scripted pad input player and logging); they differ only in this PR's commit. Same input script and same run length for every run, each build warmed up with one run first. Overlay values from the last screenshot of each run: | build | run | last screenshot | FPS | "CPU waiting on GPU" | |---|---|---|---|---| | main | 1 | black screen | 1.9 | 767 ms/s (31 waits/s) | | main | 2 | language select | 1.0 | 860 ms/s (15 waits/s) | | main | 3 | language select | 1.8 | 931 ms/s (31 waits/s) | | main | 4 | language select | 4.7 | 879 ms/s (72 waits/s) | | this PR | 1 | 3D scene after the menus | 13.3 | 66 ms/s (171 waits/s) | | this PR | 2 | 3D scene after the menus | 23.6 | 97 ms/s (310 waits/s) | | this PR | 3 | 3D scene after the menus | 17.7 | 91 ms/s (230 waits/s) | | this PR | 4 | 3D scene after the menus | 22.2 | 107 ms/s (310 waits/s) | The FPS values come from different scenes, so they are not like for like. The result is how far each build got with the same input: with the PR all four runs reached the 3D scene, main never left the first screens. **Thread CPU use**, sampled in the middle of a run (percent of one logical CPU): | build | whole process | the 13 game threads named `BPE JobWorkerThread` | GPU thread | |---|---|---|---| | main | 959 % | 43.4 to 83.4 % each | 0.3 %, priority 0 | | this PR | 967 % | 27.2 to 84.1 % each | 70.9 %, priority +2 | | this PR, second run | 966 % | 25.0 to 83.1 % each | 75.9 %, priority +2 | **What the GPU thread does on main.** 60 stack samples of it in that window: 42 % are blocked in a wait inside the Vulkan driver below `MasterSemaphore::Wait <- CommandScheduler::Wait <- BufferCache::DownloadBufferMemory` (a buffer readback waiting for the GPU), and 55 % have the instruction pointer in user-mode code (the remaining 3 % are in rows my sampler did not print), although the thread received only 0.3 % of a CPU in the same window. A thread that sits in user-mode code and gets no CPU time is ready to run and is not being scheduled. So on main the GPU thread waits in the ready queue behind the workers; with the PR it runs. **Why the workers never free a CPU.** The workers' idle loop is `pause` + `rdtsc` (eboot 0x83b6ba to 0x83b82c). A worker only goes to sleep when its last job is older than `2 * sceKernelGetTscFrequency()` ticks, so while the game is running all 13 spin between jobs and keep the CPUs busy (959 % of the 1000 % available in the table above). **The Windows side, measured outside the emulator.** A small standalone program on the same PC: 10 CPUs, 13 threads spinning on `pause` + `rdtsc` at normal priority, plus one thread that wakes from `SleepConditionVariableCS(..., 1)` by timeout (1 ms timer period): | waking thread | spinners | time between wake-ups (median / p90) | |---|---|---| | normal priority | 0 | 1.0 ms / 2.0 ms | | normal priority | 13 | 17.8 ms / 33.5 ms | | highest priority | 13 | 1.0 ms / 2.0 ms | So at equal priority a thread that becomes ready on Windows can wait 17 to 33 ms for a CPU behind spinning threads, and at a higher priority it does not wait. This is a standalone test, not a measurement inside the game, and I have not measured Linux.
Author
Owner

@⁠ArtyomZabroda on GitHub · 2026-11-21 15:37 UTC · original

@⁠Nmzik Update: I've tested cyberpunk on linux without this patch (and without the patch that fixes 100% cpu load #2110) and I didn't notice the same fps drop that I saw on windows. So it seems that this issue only affects CPUs with <16 logical cores on windows.

**@⁠ArtyomZabroda** on GitHub · 2026-11-21 15:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2106#issuecomment-7065025538) @⁠Nmzik Update: I've tested cyberpunk on linux without this patch (and without the patch that fixes 100% cpu load #2110) and I didn't notice the same fps drop that I saw on windows. So it seems that this issue only affects CPUs with <16 logical cores on windows.
This pull request has changes conflicting with the target branch.
  • src/common/threads.cpp
  • src/common/threads.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2106/head:github-bot/gh-2106'
git switch 'github-bot/gh-2106'

Merge

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