feat(agc): opt-in raised priority for the queue workers and the presenter #1873
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1873"
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 fisherjoey on 2026-10-08T22:29:27Z.
What
Adds an opt-in
APS5_THREAD_PRIORITYthat raises the AGC queue workers and the VideoOut presenter above the title's threads. Guest priorities don't reach host scheduling, so a title whose job system busy-waits on every hardware thread can keep the queue 0 worker off a core and make the driver the bottleneck (#1788).=high: niceAPS5_THREAD_NICE(default -10). On Linux through rtkit (MakeThreadHighPriorityWithPID) over a dlopen'd libdbus-1, the way SDL does it. On Windows,THREAD_PRIORITY_HIGHEST.=rt: real-time priorityAPS5_THREAD_RT(default 10) through rtkit'sMakeThreadRealtimeWithPID. On Windows,THREAD_PRIORITY_TIME_CRITICAL.SetThreadPriorityrefuses, a queue worker sends the refusal throughDriver::ReportFailure, so the next submit, wait or shutdown rethrows it, and the presenter passes it back to the VideoOut constructor.off,highandrtare accepted. Any other value (hgih,1,realtime) is rejected the same way as a refusal.[thread-priority]. Unset means no change.RLIMIT_RTTIMEhandling for=rt(second commit, after @MarcZX100's review in #1788): rtkit'sverify_process_rttimereads the hard limit from/proc/<pid>/limitsand refuses when it is aboveRTTimeUSecMax(source). Lowering only the soft limit is not enough. With soft 100000 us and hard unlimited,MakeThreadRealtimeWithPIDreturns "Access denied"; with hard 200000 it succeeds. So the code now:MaxRealtimePriorityandRTTimeUSecMaxfirst. If rtkit is unreachable or the priority is above its maximum, the limit is not touched.min(APS5_THREAD_RTTIME_US, RTTimeUSecMax), and otherwise lowers it to that value. The soft limit goes to at most half of the hard one.An unprivileged process cannot raise the hard limit again, so once lowered it stays lowered even if rtkit then refuses (burst limit, user or start-time checks). That is listed in TechnicalDebt and in BUILD.md. The log also reports the policy rtkit applied:
SCHED_RRby default, notSCHED_FIFOas the issue says.Why opt-in: it changes host scheduling for every title, rtkit is not on every system, and under
=rta queue worker that runs pastRLIMIT_RTTIMEwithout blocking gets the process a SIGXCPU. #626 (P-core pinning on hybrid CPUs) is complementary.Closes #1788.
Tested
Latest revision (
f01f95d), on the same basea29ef592: the NVIDIA GPU on this machine is down for now, so these runs are on RADV (Ryzen 5 7600X iGPU, Mesa 26.2.1).ctest -R agc_ -j1: 325 of 326. The one failure,agc_driver, segfaults onmainbf6e25a1on RADV as well.agc_driver_pm4_priority_refused(new) submits a write withAPS5_THREAD_PRIORITY=highand no rtkit, and expects the refusal fromWaitIdleand from shutdown, with the write not executed. Without theSubmission.cppchange the process aborts instd::terminate.agc_thread_priorityfails without the parser change onAPS5_THREAD_PRIORITY=hgih must be rejected.Earlier revisions:
Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti, driver 595.91.07, Ryzen 5 7600X. Rebased on
maina29ef592.ctest -R agc_ -j1ona29ef592with the variable unset: 324 of 325. The one failure,agc_driver_dcc_keys_first_write, also fails onmain. On the earlier based70b8998: 259 of 260 unset, and the same withAPS5_THREAD_PRIORITY=highand with=rt.agc_thread_priority_refused_rtand_highrun the raise with the system bus pointed at a missing socket and pass only if it throws.ctest -R agc_driver -j1202 of 202, unset and with=rt. In thertrun the queue workers logSCHED_RR 10 via rtkit, and the hard limit is lowered from unlimited to 200000 us once per process.RaiseWorkerThreadPriority(=rt): hard limit unlimited is lowered to 200000 (soft 100000); a preset soft 30000 / hard 150000 is left as is and rtkit grants;APS5_THREAD_RT=99(aboveMaxRealtimePriority20) and an unreachable system bus leave the limit untouched (that run predates the throw).python3 tools/check_conventions.py --base origin/main: passes.=highthe PS Studios movie went from 254-255 to 345 presents per 10 s, and the attract movie from 429-447 to 520-536 presents per 10 s. With the priority on, the boot-time capture race from #1787 became more likely; with that fix, 15 of 15 runs were clean.agc_thread_prioritypasses, and the threads loghighest/time-criticalin the two modes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T23:05:35Z.
Added a unit test,
agc_thread_priority(c46440b0). The env parsing and the RLIMIT_RTTIME decision are now plain functions (ParseThreadPriorityMode,PlanRealtime) thatPrepareRealtimecalls, so the test runs without rtkit or real limits. It checks that an unreachable rtkit, a priority above MaxRealtimePriority and an RTTimeUSecMax of 0 all refuse without touching the limit, that an unlimited hard limit drops to min(APS5_THREAD_RTTIME_US, RTTimeUSecMax) with the soft limit at half, and that a limit rtkit already accepts is left alone.mainhas no ThreadPriority.cpp, so there is no run onmain. WithPlanRealtimereplaced by the first commit's rule (always set the hard limit toAPS5_THREAD_RTTIME_US), it fails:On the branch it passes. Also rebased on
f1451396.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:40Z.
ThreadPriority.cppfalls back step by step when a request is refused: rtkit real-time, then an rtkit nice level, thensetpriority. Fallbacks aren't allowed here (#182); please decide the path from the mode before the call (rt→ rtkit real-time only,high→ one nice-level path) and throw with the refusal when it fails. It also conflicts with main inVideoOutDriver.cppsince #1367; please rebase.Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T09:38:33Z.
Windows run of the
SetThreadPrioritybranch, since the description lists Windows as not tested.Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), GCC 15.2.0 (WinLibs r7), Release. Head
abe8eb69merged ontomaind9484c71.The merge conflicts in
VideoOutDriver.cpp, because since #1367 the presenter thread gets astartedpromise. I resolved it by keeping both: the priority call first, thenpresentLoop(token, started).agc_thread_prioritypasses.APS5_THREAD_PRIORITY=high: every queue worker logs[thread-priority] queue 0x… worker: highestinagc_driver,agc_driver_pm4andagc_driver_flip, and the VideoOut presenter logspresenter: highest. Withrtthey logtime-critical. The tests pass in both modes.video_out_flip_tests:controlsanddecodepass in both modes. The defaultlifetimemode aborts withVideoOut: port is closedwith and without the variable; that's themainbug #1225 fixes.No title was run.
🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T15:19:56Z.
Done in 2af260f9. The mode now picks one path up front, and a refusal throws:
rtasks rtkit for real-time priority and nothing else.highasks rtkit for the nice level and nothing else. Thesetprioritystep is gone.SetThreadPrioritythrows too.Two new tests,
agc_thread_priority_refused_rtand_high, point the system bus at a missing socket and pass only if the raise throws.agc_thread_prioritystill checks theRLIMIT_RTTIMEplan, including a priority aboveMaxRealtimePriority. Rebased ontomaind70b8998. TheVideoOutDriver.cppconflict keeps both sides: the presenter raises its priority first, then runspresentLoop(token, started). If the raise throws, the exception goes back through thestartedpromise, so the VideoOut constructor fails instead of the thread terminating. In a queue worker there is nothing to hand it to, so a refusal there ends the process. That only happens whenAPS5_THREAD_PRIORITYis set.Linux, RTX 5070 Ti, 595.91.07:
ctest -R agc_259 of 260 unset, with=highand with=rt. The one failure,agc_driver_dcc_keys_first_write, also fails onmaind70b8998. Conventions pass.@popcoder565 thanks for the Windows run. I added it to the description.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:58:19Z.
Rechecked the new head
2af260f9on Windows, since the Windows path now throws on a refusal. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, merged ontomaind70b8998.APS5_THREAD_PRIORITYctest -R "agc_|video_out|guest_video_out"highrthigh, 15 queue workers and 2 presenters logged[thread-priority] ...: highest. Withrtthey loggedtime-critical. SoSetThreadPrioritysucceeded and nothing threw.agc_thread_prioritypasses. The tworefusedtests aren't registered on Windows, as intended.🤖 Addressed by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:58:24Z.
Review: CHANGES_REQUESTED
Checked on Linux (merged onto main): AGC/VideoOut ctest is green apart from display-dependent video_out tests, and
agc_thread_priority,_refused_rtand_refused_highpass. The fallback removal asked for earlier looks right. Three things to fix:Submission.cpp:317-322:RaiseWorkerThreadPriorityruns in the thread lambda, outside thetryinDriver::run. When rtkit refuses, the exception escapes thestd::threadand callsstd::terminate, while the presenter reports its refusal through the constructor. Catch it there and send it throughDriver::ReportFailurelike the other worker failures, so a refusal surfaces the same way for both threads.ThreadPriority.cpp:288: any unrecognisedAPS5_THREAD_PRIORITYvalue (a typo likehgih) silently becomeshigh. Accept the documented values and throw on anything else, with a test row for it.tests/ThreadPriority.cpp:50: remove the code comment.Not verified here: the real rtkit path and the Demon's Souls numbers (no title or rtkit on our side); the Windows path rests on @popcoder565's runs.
Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T18:15:50Z.
0fe61e41isaf321131rebased: the PR's own changes are identical in all ten files, so the three points from the review are still open on this head:Submission.cpp:320still callsRaiseWorkerThreadPriorityin the thread lambda, outside thetryinDriver::run. Reproduced here (Linux, D-Bus system bus present, no rtkit): withAPS5_THREAD_PRIORITY=highor=rt,agc_driverandagc_driver_pm4die withterminate called after throwing an instance of 'std::runtime_error',what(): APS5_THREAD_PRIORITY=high: queue 0x0 worker nice -10 refused: MakeThreadHighPriorityWithPID: The name org.freedesktop.RealtimeKit1 was not provided by any .service files(the=rtmessage namesMaxRealtimePriority). Unset, both pass.ThreadPriority.cpp:285-289still maps any other value toHigh: withAPS5_THREAD_PRIORITY=hgihthe same abort happens and its message says=high.tests/ThreadPriority.cpp:50is still there.Merged onto current
main(57f96fd2) it builds, andagc_thread_priority,_refused_rt,_refused_highand the agc driver set pass with the variable unset (PR CI does not build the libraries).AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-10T18:23:57Z.
@adriadam10 Thanks. All three points are in
f01f95d:Submission.cpp: the worker lambda now catches whatRaiseWorkerThreadPrioritythrows and sends it throughReportFailure, then returns without running the queue. New testagc_driver_pm4_priority_refused(Linux only, like the other refusal tests) submits a write withAPS5_THREAD_PRIORITY=highand the system bus pointed at a missing socket. It expects the refusal fromAgcDriverWaitIdle_nid_postfixand from shutdown, and checks that the write did not run. Without theSubmission.cppchange it aborts:terminate called after throwing an instance of 'std::runtime_error'.ThreadPriority.cpp:ParseThreadPriorityModeaccepts unset, empty,off,highandrt, and throwsstd::invalid_argumenton anything else. The rejected rows arehgih,HIGH,realtime,on,1,0andhigh.realtime,on,1and0were accepted before, but BUILD.md never listed them, so they go too. BUILD.md now says that onlyoff,highandrtare valid. A bad value fails the first raised thread the same way a refusal does. Without the parser change,agc_thread_priorityfails withAPS5_THREAD_PRIORITY=hgih must be rejected.tests/ThreadPriority.cpp: comment removed.Tested on RADV (Ryzen 5 7600X iGPU, Mesa 26.2.1), because the NVIDIA GPU on this machine is down for now. The branch is still on
a29ef592.ctest -R agc_ -j1passes 325 of 326. The one failure isagc_driver, which segfaults on RADV onmainbf6e25a1as well.check_conventions.pypasses. I updated the PR description.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-10T18:46:59Z.
Checked
f01f95d1merged onto currentmain(57f96fd2; clean merge), Linux, D-Bus system bus present, no rtkit:APS5_THREAD_PRIORITY=highor=rt,agc_driverandagc_driver_pm4now end in a reported failure instead ofstd::terminate:shutdown: APS5_THREAD_PRIORITY=high: queue 0x0 worker nice -10 refused: MakeThreadHighPriorityWithPID: The name org.freedesktop.RealtimeKit1 was not provided by any .service files(=rtnamesMaxRealtimePriority). With=hgih:APS5_THREAD_PRIORITY=hgih is not off, high or rt. Unset, the agc driver set passes.agc_driver_pm4_priority_refused,agc_thread_priority,_refused_rtand_refused_highpass. Each new check pins its change: withSubmission.cppback at0fe61e41,agc_driver_pm4_priority_refusedaborts withterminate called after throwing an instance of 'std::runtime_error'; withThreadPriority.cppback at0fe61e41,agc_thread_priorityfails withAPS5_THREAD_PRIORITY=hgih must be rejected.AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:27:23Z.
Review: APPROVED
Checked
f01f95dmerged onto main on Linux (no rtkit):agc_thread_priority,agc_thread_priority_refused_rt/_high,agc_driver_pm4andagc_driver_pm4_priority_refusedpass. Without theSubmission.cpptry/catch,agc_driver_pm4_priority_refusedaborts, so the test covers the fix. Build and conventions are green on the head; Windows run by @popcoder565 on the previous revision. Merging.