fix(agc): make the GPU wait report show both sides of a cross-queue stall #22187
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22187"
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 milescoviello on 2026-11-17T08:06:08Z.
What
When a
WAIT_REG_MEMtimes out,Driver::waitMemory(Synchronization/WaitMemory.cpp) prints oneearlier write by queue … opcode … at …line for every record in the 16384-entry write history that overlaps the awaited address. A label that a queue releases every frame fills that history. In MXGP 26 (PPSA30839), the queue0x20hang I'm chasing logs one timeout followed by about 4,900 identical lines:The report now groups the overlapping records by queue, opcode, target and length, and prints each writer once with the number of its records in the history:
Writers that differ in any of the four fields still get their own lines.
Second commit: the label writes after the wait. The report showed what came before the blocked
WAIT_REG_MEM, and who wrote its label earlier. It didn't show what the blocked queue would write once the wait passed, which is the other half of a cross-queue deadlock: whether the release another queue is waiting for sits behind this wait.waitMemorynow receives the rest of its submission (the call inPacketExecution.cpppassessubmission.commandsafter the wait, and the deferred-wait path passes nothing). The report then lists the first 8 label writes there (RELEASE_MEM,WRITE_DATA, asPm4::DecodeLabelWritedecodes them) with target and value, and a count of the rest:Label writes inside indirect buffers the submission calls are not followed.
Third commit: the real length in the write history.
traceLabel(LabelHistory.cpp) recorded everyRELEASE_MEMandWRITE_DATAwith a length of 4, so the report showed a 64-bit release as+0x4. MXGP's graphics timeline is written that way, while the compute timeline beside it showed+0x8through the second commit's decoder. The history now takes the length fromPm4::DecodeLabelWrite, which the second commit and the rest of the driver already use.DMA_DATAkeeps its byte count, and packets without a decoded write keep 4.Fourth commit: report a label again for a new value. The report printed once per awaited address for the whole run. Titles reuse a timeline label with rising references: MXGP's queues wait on theirs thousands of times (14,772 waits by queue
0x0on its two labels in one traced run). So an early, harmless timeout on a label hid every later one, including the deadlock on that label minutes later. The report now prints once per queue, address and reference.Fifth commit: a wait still blocked however other queues progress. A wait's timeout timer restarts whenever any queue completes a packet or has one in flight (
packetsDone,packetsInFlightare driver-wide). So a wait that stays blocked while another queue keeps working is never reported. In MXGP's deadlock, gdb shows the graphics worker insidewaitMemoryfor the last two minutes, while only the compute queue's timeout printed.waitMemorynow also keeps the time the wait began. Once it has waited ten timeouts (10 s by default, 200 ms withAPS5_GPU_WAIT_TIMEOUT_MS=20), it prints onestill waitingline with the reference and current value, followed by the label writes after it in its submission. The later-writes listing moves into a helper both reports use:Nothing else in a wait changes; the report prints at most once per wait.
Sixth commit: the draw pipeline's queued label. Queue 0 can still hold a label it issued in the draw pipeline, behind queued draws, where the recorder's table does not see it. The timeout report now adds one line: the pipeline's outstanding items, whether they write the awaited range, the value a queued label would leave there, whether the draw finisher is busy, and how many deferred labels the reporting worker holds:
In MXGP 26 (PPSA30839) that line ruled out the pipeline for its stall: graphics waits on its own timeline 0xc0 values ahead of memory with nothing queued anywhere, because it never executed those releases.
Seventh commit: the last value written. The write history now keeps each entry's order and, for a RELEASE_MEM or WRITE_DATA of at most 8 bytes, its value. Each writer line names the last value that writer group wrote, which tells a label whose releases never ran (last value equal to memory) from one whose releases ran and did not land:
Eighth and ninth commits, from review. The set of reported waits now keeps the last reported reference per queue and label instead of one entry per timed-out reference, and a repeat skips only the timeout report, not the still-waiting check of that poll (MarcZX10). A RELEASE_MEM with data select 3 or above writes a GPU clock when it lands, so it keeps no value in the write history, and a writer group whose newest write has none prints none (Dean).
Tested
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:agc_driver_wait_timeout_report(tests/WaitTimeoutReport.cpp,APS5_GPU_WAIT_TIMEOUT_MS=20), built onagc_driver_wait_shutdown's pattern:WRITE_DATA, then waits for a value it never writes;earlier write by queue 0x0 opcode 0x37 at <label>+0x4 (40 in the write history).WRITE_DATAthe submission makes after the wait, aslater in this submission: WRITE_DATA at <address>+0x4 value 0x1.RELEASE_MEMbefore the wait, which the report must list asearlier write by queue 0x0 opcode 0x49 at <label>+0x8 (1 in the write history).3), times out, and must be reported too, withref 0x3.WRITE_DATAevery 2 ms for 400 ms. The wait must be reported once asstill waiting after 200ms (function 3 ref 0x1 value 0x0), followed by its laterWRITE_DATA.agc_driver_wait_timeout_report,agc_driver_wait_shutdown,agc_driver_resolution_shutdownandagc_driver_gated_dispatch_capturepass, 3 runs of 4.agc_driver_(wait|gated|label|flip|rendering|queue|submit)pass, 3 runs each.main'sWaitMemory.cpp, the new test prints the writer line 40 times and fails withthe label's writer was not listed once; the other three still pass.waitMemorycall inPacketExecution.cpppassing no following words, as in the first commit, the test fails withthe write after the wait was not listed.LabelHistory.cpp, the test fails withthe 64-bit RELEASE_MEM was not listed with its 8 bytes.WaitMemory.cpp, the test fails witha later wait on the same label with a new reference was not reported.WaitMemory.cpp, the test fails witha wait blocked while another queue progressed was not reported once as still waiting.agc_driver_wait_timeout_reportpasses 3 of 3 runs. Negative control: with the fifth commit'sWaitMemory.cpp, it fails withthe draw pipeline line does not say that no queued label holds the awaited value.(40 in the write history, the last of value 0x28)and(1 in the write history, the last of value 0x1).agc_driver_wait_timeout_reportpasses 3 of 3 runs. Negative control: with the sixth commit'sWaitMemory.hpp,LabelHistory.cppandWaitMemory.cpp, it fails withthe writer line does not count the label's 40 writes and name the last value written.(2 in the write history)with no value; the second check releases 0x200000001 and requires(3 in the write history, the last of value 0x200000001).agc_driver_wait_timeout_reportandagc_driver_wait_shutdownpass 3 of 3 runs on Linux.main76de27b03a(mergeaf2cfa5651): one conflict inWaitMemory.cpp, wheremainnow reads the awaited label withPm4::LoadLabel. The timed-out report keeps this PR's grouped writer lines and reads the label withPm4::LoadLabel;445ebbeb8breads the still-blocked report's label the same way. Linux, Release: the tests matching^(agc_driver_(wait|gated|label|flip|rendering|queue|submit).*|agc_driver_resolution_shutdown)$pass onmain76de27b03a(23 of 23, 1 run) and on445ebbeb8b(24 of 24 withagc_driver_wait_timeout_report, 3 runs). Not rerun on Windows after this update.maindac08f50bclogged one timed-out wait,queue 0x20 WAIT_REG_MEM_64 at 0x107e805de0 timed out after 1000ms (function 5 ref 0x6c43c ... value 0x6c436), followed by 4942 identical linesearlier write by queue 0x0 opcode 0x49 at 0x107e805de0+0x4. With this PR, writers with the same queue, opcode, target and length are printed once with their count, as the new test checks. I did not rerun the title with this PR.git merge-treeagainstmainis clean.tools/check_conventions.pypasses on the branch and this body.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T15:25:59Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Head
c81baa0577ad34acce2f602d7eef1acbacf3b6ec, basemain. No build and no test run. Reader lookups, with the repository path where one was given:Results
PacketWordsreturns at least 1Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:134:std::ranges::find_ifandstd::min(inPrintLaterWrites) need<algorithm>, andstd::tupleneeds<tuple>. The file includes neither directly, so this compiles only through transitive includes.std::maxalready relied on the same path before this change. Adding the includes would make the file self-contained.Not verified
Driver.hpp,PacketExecution.cpp,LabelHistory.cpp,WaitTimeoutReport.cppand the cmake file, plusWaitMemory.cpparound its polling loop (lines 400–510). The rest of those files was not read.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T15:40:45Z.
Review: COMMENTED
Reviewed GPU wait timeout report — no blocking findings
Nothing blocks this; the points below are optional.
Head reviewed:
60b6d1fa9d4551b78ac6463616e4b75c1dc55f6d, basemain. Only the changed hunks were read, and no build or test was run, so this is a comment, not an approval.What I ran
description.md,commits.md,manifest.json,files.jsonand all ofdiff.patch(7 changed files).DrawPipeline::Queue0().PendingLabel,Overlaps,Outstanding,DrawFinisher/DrawPipeline::Busy,Pm4::PacketWords,waitTimeoutMs.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp(lines 500–520) and the timeout block incore/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp(lines 440–452), plus the include block ofLabelHistory.cpp.Results
files/not openedagc_driver_wait_timeout_reportDraw/DrawPipeline.hppFindings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:455: the staticreportedset is keyed by queue, address and reference, and it is never pruned. A long run whose labels keep rising references adds one entry per timed-out wait, so it grows for the life of the process. The entries are small, so this is a cost to note, not a defect.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:459: when a wait's key was already reported, thecontinuealso skips the new "still waiting" check for that loop pass. The check runs on the next pass, so the report is delayed by one poll, not lost.Not verified
agc_driver_wait_timeout_reportand the 22-test filter). The negative-control results are the author's.DeferredLabels.labels, used for the "deferred labels" count. The header exists, but I did not read its members.WaitMemory.cppincludes<algorithm>and<tuple>implicitly, forstd::ranges::find_if,std::minandstd::tuple. The new include block adds only<cstring>. Not checked.Pm4::DecodeLabelWritecan return zero bytes.LabelHistory.cpp:178would then store length 0, and the report skips that record. Not checked.packetspan passed towaitMemorystarts atcursorinsubmission.commands(PacketExecution.cpp:519). Inferred from the surrounding code, not read in full.To get this to a good state
Nothing is required.
Optional: bound the
reportedset, or clear it per queue, if long runs are expected. A build and run ofagc_driver_wait_timeout_reportwould confirm the test expectations, which I did not run.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T18:18:14Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
33db8cc9cbd1c18248c157e4fef8e0ad84587dd3, basemain, nine commits.WaitMemory.cppwithGrep, and usedrepo_read.py search PacketWordsto checkPm4::PacketWords.Results
PacketWordsnever returns 0Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:457: thereportedmap replaces the oldstd::set, so the#include <set>at line 16 is now unused. Nothing else in the file usesstd::set.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:476:std::ranges::find_ifis used without#include <algorithm>. It compiles through transitive includes, asstd::maxalready does in this file, so this is a hygiene point only.Not verified
awaitedsetup were not checked line by line.DrawPipeline::Queue0(),DrawFinisher::Busy(),deferredLabels()andPm4::DecodeLabelWritewere not checked at head. The calls are assumed to match their declarations.agc_driver_wait_timeout_reporttest were not run here. The author reports three passing runs and the negative controls for each commit; those are author-reported, not run by this review.To get this to a good state
Nothing is required.
Optional: drop the unused
<set>include and add<algorithm>next to the<map>include.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T18:54:21Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
ced681b0933e311af0d33e0e440c22b4e9795236, basemain. The diff is read from the prepared review folder; it was not fetched again.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:452and:511compute the samereferencein the timeout report and in the still-waiting report.:466and:512repeatcurrent. Hoisting both above the two reports would remove the duplicates. No behaviour change.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/LabelHistory.cpp:177:traceLabelruns for every packet (core/libs/prx/libSceAgcDriver/Execution/src/Driver/Packets/PacketExecution.cpp:420), soDecodeLabelWritenow runs on every RELEASE_MEM and WRITE_DATA. The comment incore/libs/prx/libSceAgcDriver/Execution/include/Pm4.hpp:122says the decode does not allocate. Its per-submission cost is not measured.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp:456: the staticreportedmap keeps one entry per queue and label for the life of the process and is never cleared. It is bounded by the number of awaited labels, so the growth is small.Sources
Not verified
DrawPipeline::PendingLabel(core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawPipeline.cpp:591) when a timed-out wait calls it: only the first lines were read.core/libs/prx/libSceAgcDriver/tests/WaitTimeoutReport.cpp(a 200 ms threshold inside a 400 ms loop): not checked under load.packet[2] >> 29, data select 3 or above): not checked against the hardware documentation.WaitMemory.cppoutside the excerpts read (lines 1-20, 151, 405-530): not read.To get this to a good state
Nothing is required. The non-blocking items above are optional.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:16:35Z.
Review: APPROVED
Reviewed — looks good
The change at head
445ebbeb8bc5459c5ae948c9f921121ac36140f5adds grouped writer details, subsequent submission writes, and a once-per-wait stalled report; no blocking defect was verified in the inspected code.What I ran
No commands were run. I read the prepared description, commits, manifest and diff, plus the changed source, test and CMake files listed below. I did not run tests or a build.
Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
The author reports Linux tests and a clean merge preview, but I did not independently verify them. The changed files in the manifest were included and read:
Driver.hpp,WaitMemory.hpp,PacketExecution.cpp,LabelHistory.cpp,WaitMemory.cpp,WaitTimeoutReport.cpp, andagc_driver_wait_timeout_report_tests.cmake.files.jsonwas unavailable through the reader; the file listing showed no excluded changed files.To get this to a good state
Nothing is required.