feat(libc,libkernel,agc): name host threads on Linux #19181
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19181"
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 Raghav314 on 2026-11-12T22:49:29Z.
What
On Linux every AnyPS5 thread showed up under the executable's name, so
top -H,perf report --sort tid, gdb'sinfo threadsand per-thread profiles listed bare thread IDs. Windows already names the queue workers and the presenter (#5862) and guest threads (#14402); this does the same on Linux.ThreadNamegains a Linux half:SetCurrentnames the calling thread withpthread_setname_np,SetTasknames another thread of the process through/proc/self/task/<tid>/comm. Linux keeps 15 bytes of a name, so a longer name first drops its spaces (queue worker 0x20becomesqueueworker0x20, keeping the worker id) and is then cut at a UTF-8 character boundary.PinWorkerThread) are now named throughNameDriverThread, which also names the draw committer, the draw finisher and the shader prepare threads, on Windows as well as Linux. The release thread, mirror refresh and GPU progress watcher helpers are named inPinHelperThread.scePthreadRename, whether the thread renames itself or another thread renames it (through its host thread id; an adopted thread, which has none, is renamed only by itself).On Windows the draw committer, draw finisher, shader prepare and the three helper threads are now named too (they had no description before). No behaviour changes besides the names.
Tested
Arch Linux (CachyOS, kernel 7.3.3), GCC, Release, RTX 4090 (NVIDIA 620.70.06).
thread_namenow also builds and runs on Linux: truncation rules, naming the calling thread, naming another thread. Newguest_thread_host_name: a guest thread named at creation, renamed by another thread, and renamed by itself. Both fail with the change reverted and pass with it.cpu_topology,guest_posix_thread_namepass.main(85c79e7221) and this PR withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1,ctest -V, Khronos validation 1.4.363:agc_driver_draw_pipeline_trace,agc_driver_draw_finisher_trace,agc_driver_draw_pipeline_retired_items,agc_driver_compute_pipeline_outside_gpu_mutex. Both logs show the loader inserting the layer, neither reports it missing, noVUID-lines in either; all pass on both.Checklist
main; no other open PR implements the same functionsNotImplemented_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)Summary by CodeRabbit
Improvements
Tests
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T01:08:51Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
Head
0ff525bfc0576c36c1f7bb896ed2361b6a8b1234, basemain. No merged-preview check and no build were run here. Repository files were read only through the reader, pinned to the head.Results
thread_name,guest_thread_host_nameFindings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/WorkerAffinity.cpp:38: the driver names print a[thread-name]line when naming fails, but the Linux path incore/libs/prx/libkernel/Pthread/src/Thread.cpp:1572discards theThreadName::SetTaskerror silently. A failed rename, such as one for a thread that has already gone, leaves the old name with no trace.core/libs/prx/libc/include/CpuTopology.hpp:4: the header now includesThreadName.hpp.WorkerAffinity.cppandThread.cppboth includeCpuTopology.hpp, so they now get the Windows headers (windows.h) or the POSIX headers fromThreadName.hpp. This works, but it is a compile-time cost on a shared header.Sources
PinHelperThread: Recorder.cpp, Recorder.cpp, GuestBufferMemory.cppNot verified
std::eraseonstd::stringinThreadName.hpp:53needs C++20; the Linux includes andssize_tare unchecked too.thread_name,guest_thread_host_name,cpu_topology,guest_posix_thread_name, the four AGC validation-layer tests) were not reproduced.core/libs/prx/libc/CMakeLists.txt:2352does not linklibc, unlike the Windows branch at line 2347. The test uses only inline header code, so this is probably fine, but it is not built.self->nameis set beforeStartNativeThreadruns (Thread.cpp:1150) is not verified. The guest-name test depends on it.ThreadName.hpp,WorkerAffinity.cpplines 1–30,Thread.cpplines 1140–1160,libc/CMakeLists.txtlines 2340–2356. The other changed files were read through their hunks indiff.patch, plus name searches:DrawPipeline.cpp,ShaderRegistry.cpp,WorkerAffinity.hpp,CpuTopology.hpp,libkernel/CMakeLists.txt,GuestThreadHostName.cppandThreadName.cpp.files.jsonexcluded nothing.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-13T22:34:24Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reported tests cover the new Linux naming paths, and the inspected code shows no verified defect.
What I ran
Read the prepared diff and changed-file source at head
81e5c011061cc954e04c6413f461f20b8df6782eusingrepo_read.py. No build or tests were run during this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No runtime/build verification was performed. The PR description reports Linux tests and focused AGC tests passing, and Windows was not built; these are author-reported results. Read all changed files and every added line listed in the manifest. No changed files were excluded by the prepared manifest. The repository reader serves only the prepared review documents;
files.jsonwas not available as a review document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T05:40:31Z.
Review: COMMENTED
Architecture findings (1)
Advisory architecture findings (1)
b6657406-002d-46d9-8134-72189e4eb05cReviewing files that changed from the base of the PR and between
63ee1c120aand79fad5dd54.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/WorkerAffinity.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libc/CMakeLists.txtcore/libs/prx/libc/include/CpuTopology.hppcore/libs/prx/libc/include/general/ThreadName.hppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Pthread/src/Thread.cppcore/libs/tests/GuestThreadHostName.cppcore/libs/tests/ThreadName.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T05:55:35Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: avoid reading
CurrentGuestState().currentfrom a thread renaming a different guest thread, which can race with that caller's thread-local state.What I ran
Reviewed head
79fad5dd542215860ecd53a76b0e83722a5f0811from the prepared diff and targeted source reads. No build or tests were run.Results
Findings
Blocking
core/libs/prx/libkernel/Pthread/src/Thread.cpp:1690:CurrentGuestState().currentis caller-thread-local state, so using it to determine whether the target thread is current does not establish that relationship. When a guest thread renames another, this branch can misclassify the target and callSetCurrenton the caller, leaving the target's OS name stale. Compare the target against a reliable current-thread identity (or unconditionally use its recorded host TID for Linux naming).Non-blocking
None.
Sources
core/libs/prx/libkernel/Pthread/src/Thread.cpp:1676-1692— rename updates the target's stored name and chooses the Linux naming path based on caller TLS.core/libs/prx/libc/include/general/ThreadName.hpp:67-76—SetTaskwrites the name to the task identified by host TID.Not verified
description.md,commits.md,manifest.json,diff.patch, and all nine changed files listed in the manifest (the complete included file texts were supplied for the changed files; targeted source ranges were also read). No files were excluded by the manifest.To get this to a good state
Use a reliable target-versus-caller identity check in
scePthreadRename, then run the Linux thread naming and guest-thread host-name tests on the updated head.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:17:10Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean. I compiled and ran this head’s exactThreadName.cppon Linux. It passed the UTF-8 truncation and self/remote naming controls.Please make the host rename best-effort on allocation failure, too.
SetTaskopens/proc/self/task/<tid>/commbefore constructingHostName; if that construction throws, the descriptor leaks and the exception escapesscePthreadRenameafter updating the guest name. A fixed-size host-name buffer or a scoped file descriptor with contained allocation failure would preserve the guest result. The full guest-thread and paired AGC controls are pending.AI-assisted: yes.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.