fix(libkernel): give each APR submit priority its own queue #15649
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15649"
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 hugodearaujo on 2026-11-03T23:18:53Z.
What
sceKernelAprSubmitCommandBufferandsceKernelAprSubmitCommandBufferAndGetIdignored theirpriorityargument. All generic APR command buffers ran on one queue: once a buffer stopped on an unsatisfiedWaitOnAddressorWaitOnCounter, every generic buffer submitted after it waited behind it, at any priority.Generic buffers now run on one queue per submit priority, in submission order within a priority. AMM buffers keep their single queue. Ids are still issued per kind (generic, AMM), across all of that kind's queues. So
sceKernelAprSubmitCommandBufferAndGetIdkeeps counting up, andsceKernelAprWaitCommandBuffer/AmmSubmittedfind a buffer at any priority.Marvel's Spider-Man 2 (PPSA03016 01.004.003) submits generic buffers at priorities 5, 3 and 1. A priority-5 buffer waits on a 64-bit word at
0xae83f98(compare 4, value >= reference), and none of the buffers queued behind it writes that word. With one queue, the wait never ends: presents stop, every guest thread parks on a semaphore, condition or event flag, the GPU queue workers sit idle, and only the APR thread runs. From a local diagnostic that is not part of this PR, without the change:and with it, in the one run where a wait passed 5 s:
That the console's queues are independent across priorities is inferred from this title, not measured. The debt entry says so, and it also records that any priority value is accepted and that each distinct value gets its own host thread.
Tested
Arch Linux (kernel 7.2.11), GCC, Release. Branch on
main1c8c0efc8c.guest_apr_read_priorities:sceKernelAprWaitCommandBufferwaits for all three by id.Apr.cppfrommain, the new test fails after 5 s withan APR buffer at another priority stayed behind a waiting buffer. With the change it passes.ctest -R "guest_ampr|guest_apr|guest_amm": 13 of 13 pass, includingguest_ampr_markers(#3588's wait cases) andguest_amm_placement.main4f41f4c375+ #9969 + #8939 + #13646 + #15399 + #15555. Cross every 30 s from 60 s.Not verified: the console's scheduling between priorities, its valid priority range and any preemption; Windows.
Checklist
main; no other open PR implements the same functions (#3588, merged, added the single queue; #13990 only tests command sizes)NotImplemented_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 XairRrR on 2026-11-03T23:31:30Z.
Review: APPROVED
Reviewed — approved
Generic APR command buffers now run on one queue for each submit priority, and each kind (generic, AMM) shares one id and completion tracker. The new test passes, it fails when
Apr.cppis reverted tomain, and the existing APR/AMPR/AMM tests still pass.What I ran
Head
f06738e1c82df441b06afaff08928b1f6b0125d7merged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10(merged tree11714c42a990c1265d66d0648874b808e10fd1db). Debian 13 VM (Xeon Gold 6136), GCC 14.2.0, Release, Ninja.Results
git diff --checkcheck_conventions.pyagc_driver_*denormal/division,guest_interfaces,guest_socket_options_multicast, …) also fail onmainand are unrelated to the PRguest_ampr|guest_apr|guest_amm, 3 repeatsguest_apr_read_prioritiestakes about 0.05 sguest_apr_read_prioritiesfails after 5.4 s, as expectedgit status --porcelainprinted nothing)Negative control output
Negative control
I restored only
core/libs/prx/libkernel/Apr/src/Apr.cppfrommainand rebuiltguest_apr_read_tests.guest_apr_read_prioritiesthen failed with the message the description gives (an APR buffer at another priority stayed behind a waiting buffer, after about 5 s). With the merged file restored and rebuilt, it passes again.Findings
Blocking
None.
Non-blocking
sceKernelAprWaitCommandBuffer(id)no longer waits for buffers with lower ids at other priorities, atApr.cpp#L825-L829.completed >= idalso meant every earlier id had finished. Now the wait checks only whether that one id is still outstanding.GuestAprRead.cpp(TestPriorities).behindDone/waiterDonechecks run after the release and are deterministic.Other code checks
submitlock is held, so ids within one priority increase in queue order. The completed-id set is pruned on every completion, so it does not grow without bound.g_counterWrites, AMM operations take the AMM state lock, file lookups takeg_filesLock, and the read cursor is local to each buffer. I found no state that becomes racy when several generic buffers run concurrently.Not verified
fault/stackcases.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-04T00:05:07Z.
Review: APPROVED
Re-checked — approved
The only change since my last review is commit
3a781a01fa. It adds the clause I asked for to the "APR submit priorities" debt entry, so both previous findings are now closed.What changed since my last review
3a781a01fa: it changes one line ofdocs/dev/debt/libkernel.md. Commits 1–3 are the same as before (git range-diffshows=), so the code and the test have not changed.What I ran
Head
3a781a01fa07c19f21be20cc8c5514ddb6841f03, merged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10(merged tree797db1f9d563f44e89781d6fec03ce386b8d0f8d). Debian 13 VM (Xeon Gold 6136), GCC 14.2.0, Release, Ninja.git diff --checkf06738e1c8docs/dev/debt/libkernel.md, 1 line changedcheck_conventions.pymainand are unrelated to this change.guest_ampr|guest_apr|guest_ammI did not repeat the negative control. The test and production code are unchanged since the last run, which failed as expected with
Apr.cpprestored frommain.Previous findings
TestPrioritiescan miss a regression: No longer applies as an action item. The author agreed with the analysis: the check cannot fail a correct build, and the checks after the release are deterministic. It stays a known limit of the test, not a CI risk.New findings
None.
Not verified