kernel: lower Windows priority for ASTRO BOT's Havok workers #2022
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2022
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2022"
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?
@Nawid3333 on GitHub · 2026-10-31 13:14 UTC · original
Nawid3333:fix/astro-havok-priority→main· +177 −18 · 4 files · 4 commits · openGame: ASTRO BOT (PPSA21564). On Windows the game often gets stuck before the first level (a few FPS, long frame stalls) or loads it slowly, then runs at 9-11 FPS with audio dropouts.
Cause. 18
Havok Workerthreads are created at guest priority 478, which the Windows mapping turns into host priority +2 (<= 478 -> +2). They spin on a test-and-set lock without yielding.DrawThread(680) andPhysics_ATQT(699) run at host 0 and get almost no CPU while the workers spin, so the frame and the level loading wait for them.Change (Windows only). The host +2 band ends at 460 instead of 478, at thread creation and in
PthreadSetprio, so guest 461..478 runs at host 0 like the rest of the 479..732 band. The game's audio threads (guest 256/257) keep +2.PthreadGetPriorityForKernelnow takes the class from the guest priority with the existing thresholds (478/733), so the order of priority-ordered semaphores (its only user,semaphore.cpp:221) is the same as before. Linux and macOS are unchanged.Results on
4919fdb(Windows 11, Ryzen 5 7600X, RX 9070 XT; builds of main and of this branch plus only a lab input-script player that presses the same buttons in every run; runs from boot, each starting with the same copied Vulkan pipeline cache and translating the shaders during the run; read from the performance overlay: "gameplay" = the first reading above 600 draws per frame, the desert level then shows ~730-750):ODX Definition is not foundWith 10 or 12 CPUs the two builds are close; the difference shows when the emulator gets 4.
Earlier runs on lab builds of
5e837a9bwith profiling counters (4 CPUs, 3 runs each) showed the same: with this change gameplay was reached in less than half the time of main, at 31 vs 9-11 FPS, with 0 vs 872-1244 audio underruns per run. A variant that moved every guest priority<= 732to host 0 reached gameplay as fast but caused 4052-4716 audio underruns per run, which is why the band starts at 460 (fpPS4 uses the same boundary for its above-normal band).Tests.
pthread_priority_testschecks host priority, kernel class and guest priority for 460, 461, 478, 479, 732 and 733 and forPthreadSetprio; it fails on main at the 461 row and passes with this change. The CI change adds it to the Windows job.Needs #2010 for the Windows job. Since
026189166main's Windows build fails intests/ShaderRecompilerComputeTests.cpp: the test added by #2003 names a lambdanear, which the Windows headers define as a macro. #2010 renames it; until it is merged, the Windows job of this PR stops at that file beforepthread_priorityruns. Locally (on4919fdb) the branch buildspthread_priority_tests, the test passes, and it fails with thepthread.cppchange reverted.Related: #1050 changes the same mapping differently (guest 478 -> 0 and 680-700 -> -1, GPU thread highest); in the same ASTRO BOT setup on 4 CPUs it did not reach gameplay in 3 runs. The two PRs overlap; this one keeps the GPU thread as it is.
AI use: the investigation, the code and the tests were done with an AI coding assistant (Claude) and reviewed with other models; I reviewed the change and the measurements and ran the game tests on my PC.
@coderabbitai[bot] on GitHub · 2026-10-31 13:19 UTC · original · edited 2026-11-01 18:18 UTC
No actionable comments were generated in the recent review.
d36694f8-86bd-4af7-ab01-f4e67f7afc61Reviewing files that changed from the base of the PR and between
1656d89cf2and3f5743a99c.CMakeLists.txttests/PthreadPriorityTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Walkthrough
The Windows pthread priority mapping now uses a lower threshold for mapping guest priorities to host priority
+2. Windows kernel priority lookup now returns specific values for missing attributes and specified guest-priority ranges. A new Windows test checks priority values for six workers and changes one worker’s priority. CMake and the Windows build workflow now build and select the test.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
3f574The priority changes and Windows test integration are ready to merge with no identified actionable risk.
Pre-merge checks:
4 ·
1
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 7 functions across 2 files. (1 skipped: 1 unsupported.)
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
@ -3194,0 +3195,4 @@if (thread->attr == nullptr) {return 700;}if (thread->attr->guest_priority >= 733) {@coderabbitai[bot] on GitHub · 2026-10-31 13:19 UTC · original · edited 2026-10-31 13:37 UTC
Synchronize the guest-priority read.
If one thread calls
PthreadSetpriofor a running thread while that thread enters a priority-ordered semaphore wait, this read can overlap the write tothread->attr->guest_priorityat Line 3559. The new Windows path has a C++ data race and can assign the waiter the wrong priority class. Makeguest_priorityatomic across its reads and writes, or protect those accesses with a shared lock. The semaphore records this result when it adds the waiter. (raw.githubusercontent.com)✅ Addressed in commit
38d444e@coderabbitai[bot] on GitHub · 2026-10-31 13:19 UTC · original · reviewed
Actionable comments posted: 1
32f8e892-a305-4163-ac6f-723ca5e79cb8Reviewing files that changed from the base of the PR and between
026189166fandf06a764a0a..github/workflows/build.ymlCMakeLists.txtsrc/kernel/pthread.cpptests/PthreadPriorityTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -3194,0 +3195,4 @@if (thread->attr == nullptr) {return 700;}if (thread->attr->guest_priority >= 733) {@Nawid3333 on GitHub · 2026-10-31 13:29 UTC · original
Fixed in
38d444e0:guest_priorityis nowstd::atomic<int>, soPthreadSetprio,PthreadGetprio,PthreadAttrGetschedparamandPthreadGetPriorityForKernelno longer race on it.PthreadGetprioon main already read it from other threads without synchronization; the semaphore path added a second reader.@ -3194,0 +3195,4 @@if (thread->attr == nullptr) {return 700;}if (thread->attr->guest_priority >= 733) {@coderabbitai[bot] on GitHub · 2026-10-31 13:38 UTC · original
@Nawid3333 The supplied code confirms that
guest_priorityis nowstd::atomic<int>. The listed readers and writers use atomic operations, which addresses this data-race finding. The change also covers the existingPthreadGetprioread path.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-11-01 16:47 UTC · original · edited 2026-11-01 18:18 UTC
On
CMakeLists.txtline 600 (outdated):Restrict this target to Windows.
On Linux and macOS, the test returns without running assertions, but
kyty_testsstill builds a full-emulator executable for it. Guard the target, test registration, and aggregate dependency withWIN32to avoid that build cost. (raw.githubusercontent.com)✅ Addressed in commit
3f5743a@coderabbitai[bot] on GitHub · 2026-11-01 16:47 UTC · original · reviewed
Actionable comments posted: 1
b2de7bd9-5373-4f1a-8ee1-df3466d752d0Reviewing files that changed from the base of the PR and between
38d444e0ceand1656d89cf2..github/workflows/build.ymlCMakeLists.txtsrc/kernel/pthread.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nawid3333 on GitHub · 2026-11-01 18:11 UTC · original
On
CMakeLists.txtline 600 (outdated):Done in
3f5743a99:pthread_priority_testsis now created, registered with ctest and added tokyty_testsonly insideif(WIN32), the same waymacos_sse4a_testsis limited to macOS. The Windows-only guards inside the test went away with it.@coderabbitai[bot] on GitHub · 2026-11-01 18:19 UTC · original
On
CMakeLists.txtline 600 (outdated):@Nawid3333 Thanks. The supplied
CMakeLists.txtconfirms that all three operations are insideif(WIN32). This addresses the unnecessary Linux and macOS build cost.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Review thread resolved.
You are interacting with an AI system.
@Nawid3333 on GitHub · 2026-11-05 15:03 UTC · original
New runs on a newer main (
91c5820c0) with 8 CPUs for the emulator: main shows a periodic frame stall in ASTRO BOT that this PR removes.Setup. Windows 11, Ryzen 5 7600X, RX 9070 XT, 8 CPUs for the emulator. Two builds of main
91c5820c0(built from my fork's main, which adds only.githubworkflow files): main, and main plus this PR's diff (head3f5743a99, applied unchanged). Both builds also carry three lab-only additions that are not part of the PR:Every run starts from boot with the shader store of a warm-up run of its own build. The main runs also loaded the Vulkan pipeline cache file of their warm-up; the PR runs started with an empty one, which favors main. The first 12 readings of each run are skipped.
91c5820c0So on main, frames come at the normal 16.7 ms pace, but the longest frame of every reading is 5355-5707 ms (median per run). These long frames alone take 43-46% of the measured time. With this PR they are gone, and the same scene runs at about 50 FPS.
Caveat: 2 further runs of the PR build stopped early (not in the table). Both hit the game's own assert
Room.cpp:787 ODX Definition is not found(opening_next_shooting_star_singleandskybox_blank_desert_intro), followed by a guest access violation. In both, the log first showsRead 0 bytesfor that.odxbfile, which exists and is not empty.The zero-byte reads are not caused by this PR:
The read lands in a guest page that the GPU cache has write-protected, so Windows
ReadFilefails (ERROR_NOACCESS or ERROR_INVALID_USER_BUFFER) and the guest gets 0 bytes. The crash needs that lost read to be an.odxbdefinition. #838 addressed this (closed unmerged), and #1165 addresses it for Linux.@ZrDaniel07 on GitHub · 2026-11-14 22:16 UTC · original
A/B on 12 cores / 24 threads, for your table. Setup: Windows 11, Ryzen 9 5900X (no CPU affinity limit), RTX 5090 (driver 621.24), 2560x1440, ASTRO BOT PPSA21564, same save.
Builds:
main3e226bff+ #2172 + a port of #838.Both builds also log one line per second from the performance overlay's refresh (a local lab patch). Each run was the first on its build, with an empty shader cache, so both compiled shaders in the same way. The game was played by hand through the Garden level (
aerial_garden).There is no measurable difference here. The run is GPU-side bound: the CPU waits on the GPU for about 920 ms of every second, and the emulator uses under 20% of 24 threads. That matches your 10 and 12 CPU rows, where main and this PR are close. I did not test with fewer CPUs.
AI use: Claude Code built both variants, added the log line and summarized the logs with me; I played both runs.
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.