fix(videoout): end shutdown when a host thread cannot unwind #16791
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16791"
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 wanderingbug on 2026-11-07T16:43:26Z.
What
Open #16801 (
fix/macos-test-compile,38bddbff44) edits onlyResourceRequest.cpp,RtcpTransportFeedback.cpp, andGuestCesGbSetters.cpp:<initializer_list>andResourceRequestBasevalue initialization. None of those symbols are in this pull request.If a host thread cannot unwind out of the guest, shutdown still finishes instead of leaving that thread to hold the process. The abandoned path is
guest_shutdown_abandoned. Queue submission, the driver lifecycle, and the video-out driver take part in that ending.This replaces closed #12113. That patch also changed
DisplayBuffer.hpp,VulkanDevice.cpp, andVideoOutBuffer.cpp. This branch does not. Test-only #7804 and #4630 were in the Mac tree and are not code dependencies of this branch.Tested
guest_shutdown_abandonedexited 0 in the same cache-reuse run: Apple M2 Max, macOS 27.2, x86_64 under Rosetta, snapshot7a6e44ece4plus the six overlays listed on #16790. This head was not rebuilt alone. The square smoke also reached process exit on that machine, which is not the Vulkan validation comparisonCONTRIBUTING.mdasks for. Not tested on a second machine; no game tested.Checklist
main; no other open PR implements the same functions. Unchecked: parent is30a863d12d, and upstreammainis nowdaad891ea6. #16801 does not implement these functions. Other open pull requests were not fully scanned.//comments. The debt note is indocs/dev/debt/libSceVideoOut.md..mdfiles or images added to the repository. Existing development documentation is edited; maintainer confirmation of this rule is still needed3rdparty/change.mainwas not run.Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T17:45:26Z.
Review: COMMENTED
Code review of head
9c37fd53ac. I read the diff and the code it calls; I didn't build or run it (this is a Windows machine and the new test isfork-based, underif(UNIX)).1.
guest_shutdown_abandonedcan't pass as registered. Nothing definesSHUTDOWN_JOIN_TEST_STUB(notlibc/CMakeLists.txt, not the test), so the test links the reallibc. In the forked child,LateJoinCasepassesLibcExitCode_nid_no_patch()whileexitCodeis still its initial0, and when the worker notes the abandonment,JoinWhenReturnedOrEndIfAbandonedcallsLibcTerminate_nid_no_patch(0), which takes the newhostShutdownAbandonedbranch and doesstd::_Exit(0). The parent then requiresWEXITSTATUS(status) == 42and aborts. The42only exists in the stub branch. Also,add_testpasses no argument, so thelockandjoinmodes never run on their own. Thelinuxjob is skipped on this PR, so CI won't show it either.Either set a known exit code in the child before
LateJoinCase(for example throughLibcRequestExit_nid_postfix(42)or whatever path really records it) or drop the stub block and expect0; and registeradd_test(... lock)ifLockCaseshould be covered.2.
Driver::stop()can now wait forever on a worker that never enteredrun().worker.exitedis only set by theExitedguard insideDriver::run(). The thread lambda inDriver::enqueue(Submission.cpp, unchanged) returns beforerun(queue)whenRaiseWorkerThreadPrioritythrows, which it does whenAPS5_THREAD_PRIORITYis invalid or a requested priority is refused. That thread is joinable withexited == false, soJoinWhenReturnedOrEndIfAbandonedloops on its 20 ms sleep while!returned, and on Linux and WindowshostShutdownAbandonedis never set, so it never ends. Before this changethread.join()returned at once. Setting the flag in the lambda covers every exit and removes theworkers.at(id)lookup undermutexinrun():(
workersis astd::map, so the address stays valid.)3. Minor: a second
exit()overwrites the recorded code.LibcRequestExit_nid_postfixstoresexitCodebeforeexitRequested.exchange(true), so if thread A callsexit(1)and thread Bexit(2)after it,stop()andVideoOutDriver::Shutdownread 2, and the abandoned path ends with_Exit(2)while the exit that actually runs is 1. Storing after theexchangecheck keeps the first one.4. Minor:
JoinOrEndIfHostAbandonedis only used by the test; production code usesJoinWhenReturnedOrEndIfAbandoned.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-11T10:21:28Z.
Review: CHANGES_REQUESTED
Checked the diff against
Submission.cppand the PR thread (including the reviews of @gabichuuuuu and @adam25136).core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/QueueWorker.cpp:157:exitedis only set by the guard insideDriver::run(). The thread lambda inSubmission.cpp:808-817returns beforerun(queue)whenRaiseWorkerThreadPrioritythrows, so that worker is joinable withexited == false.Driver::stop()then loops inJoinWhenReturnedOrEndIfAbandonedforever (the abandoned flag is never set outside macOS), wheremainjoined at once. @adam25136 reproduced it:agc_driver_wait_shutdownwithAPS5_THREAD_PRIORITY=bogustimes out 3 of 3 with this PR and passes onmain. Fix: put theExitedguard in the thread lambda (beforeRaiseWorkerThreadPriority), passing&worker.exited, which also removes theworkers.at(id)lookup undermutexinrun().workersis astd::map, so the address is stable.run()must not blockstop()); the current tests only exercise the normal path.conventionscheck fails. Tick every checklist box and fillFixes/Unblocks/GPUs testedas the template asks.ShutdownJoin.hpp:19-25:JoinOrEndIfHostAbandonedis only used by the test; drop it or use it.Process.cpp:76:LibcRequestExit_nid_postfixstoresexitCodebefore theexchange, so a secondexit()overwrites the code of the exit that actually runs. Store it only whenexchangereturns false.The first point of the earlier review (exit status 42 in the abandoned-join test) is already fixed by
ed16d0fb.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:02:12Z.
Review: APPROVED
Reviewed — looks good
Nothing in the inspected changes establishes a blocking defect; shutdown coordination is handled by tracking worker return and ending the process when an abandoned host thread prevents progress.
What I ran
07b9df164e406fdb88157d38cf052657d14333e9using the pinnedrepo_read.pyreader.guest_shutdown_abandonedand a square smoke on Apple M2 Max, macOS 27.2, x86_64 under Rosetta, using a combined snapshot and overlays.Results
Findings
Blocking
None.
Non-blocking
LateJoinCasenever setsreturned, so it exercises the abandoned-flag exit path rather than a worker-return race. A focused case that makes the worker return and sets the flag would strengthen coverage ofJoinWhenReturnedOrEndIfAbandoned.mainwas not run. Consider adding that comparison before relying on the reported smoke for video-out behavior.Not verified
To get this to a good state
Nothing is required. The two points above are optional follow-up feedback.
Pull request closed