feat(agc): keep the last submissions per queue and dump them on a stall or crash #4855
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4855"
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 fdfawef324 on 2026-10-13T00:10:51Z.
What
Each GPU queue keeps a ring of its last submissions, and the rings are printed when the Windows crash report runs or when a waiter stalls. Before this, a GPU hang or a crash left no record of what the queues were last given:
APS5_TRACE_GPUprints every submission (too much to leave on), and theWAIT_REG_MEMtimeout message shows only the packet before the wait on the waiting queue.APS5_PM4_RING=<n>(default 16, 0 to 4096, 0 disables): per queue, the TraceMs time in tenths of a millisecond, serial, size, guest address and the first 512 dwords after indirect buffers are inlined, REWIND tails included. Recorded under the driver lock next to the serial. The ring and the failure report registration are set up at the top ofSubmit, so recording does not allocate. Disabled,Submitonly tests a static flag. Enabled, it costs one bounded copy per submission.Pm4::PacketWordsand the newPm4::KnownName.KnownNamereturns the decoder's names as views of static strings, or nothing for an unknown opcode, which is printed asUNKNOWN_0x%02x.Pm4::Namenow builds itsstd::stringfrom it. Each line is formatted with integer and string conversions only, into a 512-byte stack buffer, and written with oneWriteFile/write(2)on the stderr handle. So the dump does not allocate from the C runtime heap, it does not take the CRT stream lock (#3871), and lines from different threads do not interleave.LibcRegisterFailureReport_nid_no_patch,Unregister,Run).Runruns the registered reports the first time it is called and returns at once after that. The Windows crash report calls it in three places: after the thread dump of an unhandled exception, after SIGABRT (this covers theAPS5_HANG_DUMP_SECStimed dump, which aborts) and after an invalid CRT parameter.APS5_STALL_WATCHDOG_SECS=<n>(0 to 86400, default 0) makes a waiter that has not progressed for n seconds dump the rings once per wait. The waiters are aWAIT_REG_MEM, aREWINDwaiting for the title, and a compute submission held behind queue 0. The last one prints under the driver lock, so submissions and the other queues wait for it; USAGE.md says so. An invalid value of either variable throws at the first submission. The order hold behind queue 0 is released on scope exit.docs/dev/debt/libSceAgcDriver.md) says what the crash-path dump can and cannot do:Sleep(INFINITE)and hangs instead of ending.No packet semantics change. Packet sizes and names are those of the existing decoder (PM4 type-3 header layout as in Mesa
src/amd/common/sid.h). This PR makes no speed claim.Tested
Head
871fe7627, rebased onto main8856f180c. The CMake conflict resolution keeps main's 30-second timeout onagc_driver_pm4_failureand all ten ring/watchdog test registrations. The ring and stall-watch hooks sit next to main's submission-capture hooks, both records under the driver lock. The original author, author date and commit message are kept. Conventions and diff checks pass. The head also merges with main34454bd83without conflicts; that merge was not built.Every result below is from head
871fe7627: Windows Server 2025, RTX 3060 12 GB (driver 591.86), GCC 15.2 (winlibs) Release,build-devbuilt withninja alland the three replay tools.New ctests (agc_driver_pm4_tests modes):
agc_driver_pm4_ring,_ring_empty,_ring_disabled,_ring_invalid,_ring_report,_ring_report_heap,_stall_watchdog,_stall_watchdog_invalid,_stall_watchdog_rewind,_stall_watchdog_order. Alsowindows_backtrace_failure_reportandwindows_backtrace_failure_report_once. The PM4 catalog test (agc_driver_pm4) checksKnownNameagainst every opcode and custom name. All 18^agc_driver_pm4|^windows_backtracetests pass. The ring tests take 0.02 to 0.5 s and the stall tests about 2.6 to 2.8 s.agc_driver_pm4_ring_report_heap(Windows) swaps theHeapAlloc/HeapReAllocimports ofucrtbase.dllfor counters, so it counts every C runtime allocation made on the reporting thread. It submits a buffer holdingINDEX_BUFFER_SIZE(17 characters, longer than the std::string inline buffer) and runs the failure reports. The report must name the packet and make no allocation. As a check on the trap itself,Pm4::Nameof the same header must be seen allocating. On Linux the mode returns 77 (skipped).Red with the fixes reverted, green with them:
SubmissionRing.cppdecoding names throughPm4::Nameand the time through%.1f:agc_driver_pm4_ring_report_heapfails with "the failure report allocated from the C runtime heap".FailureReport.cppresetting its flag after a run:windows_backtrace_failure_report_oncefails, because the FAIL regex finds the report printed twice.Behavioural red: the new files were kept and only the hook sites (
QueueWorker.cpp,Submission.cpp,WaitMemory.cpp,CrashReport.cpp) were reverted to the base8856f180c. These failed:agc_driver_pm4_ring: "the ring dump header is wrong"_ring_report: "the failure report does not dump the rings"_ring_report_heap: "the failure report does not name INDEX_BUFFER_SIZE"_ring_invalidand_stall_watchdog_invalid: "expected PM4 rejection"_stall_watchdog,_rewindand_order: "... did not dump the rings" (about 15.7 s each)windows_backtrace_failure_report: required regex not found_ring_empty,_ring_disabledandwindows_backtrace_failure_report_oncepass without the hooks, as expected.Suite:
ctest -R "^agc_|libc|^windows_backtrace" -j 4: 597/600 passed, 3 skipped, 0 failed. The skips areagc_host_import_sparseandagc_driver_sparse_dma_buf_import(udmabuf imports are Linux only) andagc_driver_stencil_ref_export(the device lacksVK_EXT_shader_stencil_export). The 9 failures reported on the earlier base1c5e62878(agc_driver_flat_loads,agc_driver_global_loads,agc_driver_flat_apertures_2,_5,agc_driver_pixel_interlockand their variants) pass here.python -I tools/check_test_registration.py build-dev: 879 test executables, none built and not run, none new.Not run: the Linux build and tests (the shared code keeps Windows calls behind
#ifdef _WIN32, and the heap test is skipped there); no title or homebrew; no test outside the agc, libc and backtrace sets.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)🤖 Generated with Claude Code
Co-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:49:38Z.
Rebased onto current
main(one include conflict inCrashReport.cpp, kept both includes). Checked: scoped build and ctest for agc driver, libc and libkernel pass, including the ten newagc_driver_pm4_*ring/stall tests. The only failure,agc_driver_tessellation, is a segfault insidelibvulkan_radeonand also happens withAPS5_PM4_RING=0. Read the dump path (no allocation, bounded line buffer, queue and capacity limits, invalid env throws). The Windows-only parts are covered by the Windows build run before merging.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:08:18Z.
Rebased onto current
main(the only conflict was two adjacent new sections indocs/user/USAGE.md, both kept). Checked: the scoped build and tests for the AGC driver and libc, including the newagc_driver_pm4_ring*/_stall_watchdog*tests (pass on Linux; the heap-trap test is Windows-only and skips here), the order-hold loop rewrite (pollreturns the predicate, same exit condition as before), invalid env values throwing at the first submission, and the technical debt and USAGE entries. Windows behaviour is covered by the full Build before merging; merging once it is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T12:43:50Z.
Re-checked the new head after the rebase onto
mainwith the merged submission-capture hooks. The only change against our previous rebase is thatcapture->TakeandRecordSubmissionnow sit side by side under the driver lock inSubmitandexecuteRewindTail. The scoped build and tests for the AGC driver and libc pass, including theagc_driver_pm4_ring*and_stall_watchdog*tests (the heap-trap test is Windows-only and skips here).agc_driver_tessellationsegfaults inlibvulkan_radeonand also fails onmain. Windows behaviour is covered by the full Build before merging; merging once it is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:03:42Z.
Re-checked the new head after the rebase onto
main8856f180c. The PR's own changes are identical to the head we approved. The scoped build and tests for the AGC driver and libc pass, including theagc_driver_pm4_ring*and_stall_watchdog*tests (the heap-trap test is Windows-only and skips here).agc_driver_tessellationsegfaults inlibvulkan_radeonand also fails onmain. Windows behaviour is covered by the full Build before merging; merging once it is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T11:13:26Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceAgcDriver.mdL81docs/dev/debt/libSceAgcDriver.mdL81-82core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppL316core/libs/prx/libSceAgcDriver/tests/Pm4.cppL5Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/QueueWorker.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cppcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libc/CMakeLists.txtdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/QueueWorker.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mddocs/user/USAGE.mdcore/libs/prx/libc/src/specifics/windows/CrashReport.cppdocs/user/USAGE.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libc/CMakeLists.txtcore/libs/tests/WindowsBacktraceReport.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/Pm4.hppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/QueueWorker.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cppcore/libs/prx/libSceAgcDriver/Execution/src/Pm4.cppcore/libs/prx/libc/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T11:50:42Z.
Checked the failed Build run:
windowsis green; the only failure reported isagc_pending_key_stores, a recorder test this PR does not touch, which passes here with the PR merged ontomain. Treating it as unrelated to this change. Merging once the full Build is acceptable.Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T12:10:44Z.
Windows results for the current head
871fe7627(unchanged since your last check). Windows Server 2025, RTX 3060, GCC 15.2 Release, fullninja allbuild:ctest -R "^agc_|libc|^windows_backtrace" -j 4: 597/600 passed, 3 skipped (two Linux-only udmabuf imports, plusagc_driver_stencil_ref_export, which needsVK_EXT_shader_stencil_export), 0 failed. The Windows-onlyagc_driver_pm4_ring_report_heapand bothwindows_backtrace_failure_report*tests pass.Pm4::Namedecoding (heap test fails), flag reset (_oncetest fails).34454bd83without conflicts. I did not build that merge.The body's Tested section now shows these results.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T09:26:11Z.
The full Build failed
check_skipson linux:agc_driver_pm4_ring_report_heapexits 77 on Linux with "the C runtime heap trap needs ucrtbase.dll", which is not one of the accepted device limitations, so the job would lose that coverage silently. I changed the CMake registration soring-report-heapis only added on Windows (own commit on your branch, rebased onto currentmain). Scoped build and ctest otherwise pass;agc_driver_tessellationsegfaults in radeon and also fails onmain. Merging once the full Build is green.