mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 08:33:12 -05:00
A GPU hang or a crash in a title leaves no record of what the queues were last given: APS5_TRACE_GPU prints every submission (too much to leave on), and the WAIT_REG_MEM timeout message shows only the packet before the wait on the waiting queue. Each queue now keeps a ring of its last 16 submissions (APS5_PM4_RING=<n>, 0 to 4096, 0 disables): the TraceMs time in tenths of a millisecond, serial, size, guest address and a copy of the first 512 dwords after indirect buffers are inlined, recorded under the driver lock next to the serial, REWIND tails included. The ring of a queue and the failure report registration are set up at the top of Submit, before any output is reserved, so recording under the lock does not allocate. Disabled, Submit only tests a static flag; enabled, it costs one bounded copy per submission. DumpSubmissionRings decodes the kept dwords with Pm4::PacketWords and the new Pm4::KnownName, which returns the decoder's names as views of static strings (empty for an unknown opcode, printed as UNKNOWN_0x%02x); Pm4::Name now builds its std::string from it. Every line is formatted with integer and string conversions only into a 512-byte stack buffer and written with one WriteFile / write(2) on the stderr handle, so the dump does not allocate from the C runtime heap, lines from other threads do not interleave and the CRT stream lock is not taken (the rule of #3871). The header gives the number of queues and the ring size, and each queue line the submissions recorded and kept. libc gets a small registry of failure reports (LibcRegisterFailureReport_nid_no_patch, Unregister, Run); Run runs the registered reports the first time it is called and returns at once after that. The Windows crash report runs it after the thread dump of an unhandled exception, after SIGABRT (which also covers the APS5_HANG_DUMP_SECS timed dump, since it aborts) and after an invalid CRT parameter, so an abort after a reported exception does not print the rings twice. The driver registers its dump at the first submission and unregisters at static destruction; the dump there waits a bounded time for each ring lock. What the crash-path dump cannot do (a ring held by the crashed thread, rings corrupted by the crash, Linux) is recorded in technical debt. APS5_STALL_WATCHDOG_SECS=<n> (0 to 86400, 0 disables) makes a waiter that has not progressed for n seconds dump the rings once per wait: a WAIT_REG_MEM (progress as for APS5_GPU_WAIT_TIMEOUT_MS: another packet runs or completes), a REWIND waiting 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). Both variables are read at the top of Submit, so an invalid value of either throws at the first submission and never later inside a GPU worker. The order wait behind queue 0 releases its order hold on scope exit, so a throwing dump cannot leave it counted. 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). The queue bound of Submit and of the rings is one constant, SubmissionQueueEnd. Tests: agc_driver_pm4_tests gets ten modes, each its own ctest: agc_driver_pm4_ring (APS5_PM4_RING=4, six submissions on queue 0 and two on 0x20: the dump holds #3..#6 and #1..#2 in order, nothing older), agc_driver_pm4_ring_empty (one line), _ring_disabled (one line), _ring_invalid and agc_driver_pm4_stall_watchdog_invalid (APS5_STALL_WATCHDOG_SECS=1x: the submission throws and is not executed), _ring_report (LibcRunFailureReports_nid_no_patch dumps the rings), _ring_report_heap (Windows: with ucrtbase.dll's HeapAlloc and HeapReAlloc imports counting calls from the reporting thread, the failure report of a submission holding INDEX_BUFFER_SIZE names it and allocates nothing, while Pm4::Name of the same header is seen allocating), and with APS5_STALL_WATCHDOG_SECS=1 a WAIT_REG_MEM (agc_driver_pm4_stall_watchdog), a REWIND (_stall_watchdog_rewind) and a compute submission held behind a queue 0 rendering wait (_stall_watchdog_order), each held for about 2.5 s, dump once and complete when released. The PM4 catalog test checks KnownName against every opcode and custom name. windows_backtrace_failure_report checks that abort() runs the registered reports once and not an unregistered one; windows_backtrace_failure_report_once that abort() does not run them again after an earlier run. With the dump decoding through Pm4::Name, agc_driver_pm4_ring_report_heap fails with "the failure report allocated from the C runtime heap"; with Run resetting its flag, windows_backtrace_failure_report_once prints the report twice. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1.1 KiB
C++
37 lines
1.1 KiB
C++
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include "../prx/libc/include/general/VabiMacros.hpp"
|
|
#include "../prx/libc/include/FailureReport.hpp"
|
|
|
|
extern "C" int* APS5_VABI __error_nid_postfix();
|
|
|
|
namespace {
|
|
|
|
void KeptReport() noexcept {
|
|
std::fputs("kept failure report ran\n", stderr);
|
|
}
|
|
|
|
void DroppedReport() noexcept {
|
|
std::fputs("dropped failure report ran\n", stderr);
|
|
}
|
|
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
if (__error_nid_postfix() == nullptr) return 1;
|
|
if (argc == 2 && std::strcmp(argv[1], "report") == 0) {
|
|
LibcRegisterFailureReport_nid_no_patch(DroppedReport);
|
|
LibcRegisterFailureReport_nid_no_patch(KeptReport);
|
|
LibcRegisterFailureReport_nid_no_patch(KeptReport);
|
|
LibcUnregisterFailureReport_nid_no_patch(DroppedReport);
|
|
}
|
|
if (argc == 2 && std::strcmp(argv[1], "report-once") == 0) {
|
|
LibcRegisterFailureReport_nid_no_patch(KeptReport);
|
|
LibcRunFailureReports_nid_no_patch();
|
|
}
|
|
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
|
std::fputs("aborting\n", stderr);
|
|
std::abort();
|
|
}
|