fix(agc): reject late profiling output after shutdown #7755

Merged
JJenkx merged 1 commit from upstream-pr/7755 into main 2026-10-20 01:43:53 +00:00
JJenkx commented 2026-10-19 06:07:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T06:07:10Z.


What

After StopProfileOutput_nid_no_patch() drains and joins the diagnostic writer, a late ProfilePrint_nid_no_patch() throws profile output is stopping. This was the final exception during an ordinary close of a Crimson Spires (PPSA03568) profiling run. Independently, the oversized formatting path can increment the dropped-message count after the worker has exited, leaving a subsequent Flush() waiting forever.

Reject late writes with false, matching the queue’s existing rejection result, and stop oversized messages from adding work after shutdown. Accepted output still drains before Stop() returns. Actual writer failures still propagate, including after stop and through all formatting paths. This changes diagnostic output only; it adds no guest API fallback.

Overlap check: #7622 could not be compared automatically because it conflicts with main. Its patch in this header only includes HostThread.hpp and replaces the worker constructor with Libc::StartHostThread; inspected manually, it is independent of this queue shutdown change. No dependency.

Tested

Arch Linux x86-64, GCC, base 46f27623c28b237f6b7dab93862a318e4977cc19, change f085363ef22b4335d0385444c246d64876705465.

  • The new regression against main exits 1 with profile output is stopping. A separate main-only reproducer (Stop(); Print() with 10000 characters and capacity 8192; Flush()) times out after 3 seconds, exit 124.
  • Updated ProfileOutput.cpp passes as a standalone C++20/pthread executable, and under AddressSanitizer + UndefinedBehaviorSanitizer. Tests cover repeated stop, drain ordering, empty and late writes, small/heap/oversized formatting, eight concurrent producers racing stop, bounded overflow and actual writer-error propagation after stop.
  • Full Release libs and CMake agc_profile_output_tests: both build successfully. ctest --test-dir build-full --output-on-failure -R '^agc_profile_output$': 1/1 passed, 0.02 s.
  • python3 tools/check_conventions.py --base origin/main and git diff --check pass.

Native integration validation (Crimson Spires, PPSA03568): prior diagnostic integration head 9f6fc8b877c7f1fc48ad572327c56bc716a6461d exits 134 during ordinary close with profile output is stopping. Adding only this PR’s patch produces integration head 45bab09c33a7f484bb8b69119ee98992ccf0a8e1: ordinary close requested at 129.36 s, process exits 0 at 131.37 s, PID gone and kernel limit restored to 64 MiB. No profile output is stopping or termination exception appears. The focused profiler CTest also passes on the integration build.

The existing integration uses main 9f5d4bd929862fc7c50e6cbb256032cf2095b10f, infinite-depth-bounds and resident/layer-window fixes, and sampled-storage diagnostic counters. Both native runs use the same relinked title, profiling switches, two scheduled Cross inputs at 60/70 seconds after first present and ordinary close at 125 seconds after first present. Cache contents evolve; this establishes shutdown behavior, not a speed comparison. This is a native integration result, not an isolated title test of the PR head on current main.

26 GPU-readback frames were saved; selected frames show the menu and driving cutscene. X11 snapshots at 100/115 seconds repeat despite advancing frame counts, so scene inspection uses GPU frames. AMD RX 6650 XT / RADV Mesa 26.2.4, Arch Linux. No performance result.

Independent Windows regression validation: savvaniss reports three serial runs each on Intel UHD 770 (driver 32.0.101.7088) and AMD RX 9070 XT (driver 32.0.31041.1004), Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release. agc_profile_output passes with PR head f085363ef merged into main 6b8228b2b; the PR test file alone on that main fails with profile output is stopping on both GPUs. Every execution test was built; ANYPS5_NO_SHADER_CACHE=1, with the AMD VkCache emptied first. This is contributor-reported focused regression evidence, not a Windows native-title or performance test.
Additional Linux native integration validation (Smurfs Dreams, PPSA21607 v01.002.000): profiling integration 97a9225d722842fc1e893ceabca3969617230e47 reached the village but exited 134 after the scheduled ordinary close, ending in profile output is stopping. Applying only this PR’s patch produced 11b1d62ade7eb71f13acb05ca78f2ea2ad7f2944: the village still renders, ordinary close was requested at 355.66 s, and the process exited 0 at 357.67 s. PID gone; udmabuf limit restored to 64 MiB; no profiling-stop or termination exception. The CPU-only agc_profile_output CTest passes on both integrations. Both runs use the same relinked title, restored checkpoint, APS5_PROFILE_DRAW=1, APS5_PROFILE_GPU=1, scheduled inputs and close procedure. Caches evolve; this is functional shutdown evidence, not a performance comparison. The base integration is main 3aa35dc014a84b783c2fbe642f8e08341feb1a30 plus #6959 and #6948; this is not an isolated title test of the PR head on current main. RX 6650 XT / RADV Mesa 26.2.4, Linux. Existing pending-storage-image shutdown diagnostics remain.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none (shutdown diagnostic regression; no new title run)
  • GPUs tested: AMD RX 6650 XT / RADV Mesa 26.2.4, Arch Linux (native integration only); contributor-reported Windows Intel UHD 770 and AMD RX 9070 XT focused regression passes (queue tests are CPU-only), linked above
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4916635913 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7755). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-19T06:07:10Z. --- ### What After `StopProfileOutput_nid_no_patch()` drains and joins the diagnostic writer, a late `ProfilePrint_nid_no_patch()` throws `profile output is stopping`. This was the final exception during an ordinary close of a Crimson Spires (PPSA03568) profiling run. Independently, the oversized formatting path can increment the dropped-message count after the worker has exited, leaving a subsequent `Flush()` waiting forever. Reject late writes with `false`, matching the queue’s existing rejection result, and stop oversized messages from adding work after shutdown. Accepted output still drains before `Stop()` returns. Actual writer failures still propagate, including after stop and through all formatting paths. This changes diagnostic output only; it adds no guest API fallback. Overlap check: #7622 could not be compared automatically because it conflicts with main. Its patch in this header only includes `HostThread.hpp` and replaces the worker constructor with `Libc::StartHostThread`; inspected manually, it is independent of this queue shutdown change. No dependency. ### Tested Arch Linux x86-64, GCC, base `46f27623c28b237f6b7dab93862a318e4977cc19`, change `f085363ef22b4335d0385444c246d64876705465`. - The new regression against main exits 1 with `profile output is stopping`. A separate main-only reproducer (`Stop(); Print()` with 10000 characters and capacity 8192; `Flush()`) times out after 3 seconds, exit 124. - Updated `ProfileOutput.cpp` passes as a standalone C++20/pthread executable, and under AddressSanitizer + UndefinedBehaviorSanitizer. Tests cover repeated stop, drain ordering, empty and late writes, small/heap/oversized formatting, eight concurrent producers racing stop, bounded overflow and actual writer-error propagation after stop. - Full Release `libs` and CMake `agc_profile_output_tests`: both build successfully. `ctest --test-dir build-full --output-on-failure -R '^agc_profile_output$'`: 1/1 passed, 0.02 s. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check` pass. **Native integration validation (Crimson Spires, PPSA03568):** prior diagnostic integration head `9f6fc8b877c7f1fc48ad572327c56bc716a6461d` exits 134 during ordinary close with `profile output is stopping`. Adding only this PR’s patch produces integration head `45bab09c33a7f484bb8b69119ee98992ccf0a8e1`: ordinary close requested at 129.36 s, process exits 0 at 131.37 s, PID gone and kernel limit restored to 64 MiB. No `profile output is stopping` or termination exception appears. The focused profiler CTest also passes on the integration build. The existing integration uses main `9f5d4bd929862fc7c50e6cbb256032cf2095b10f`, infinite-depth-bounds and resident/layer-window fixes, and sampled-storage diagnostic counters. Both native runs use the same relinked title, profiling switches, two scheduled Cross inputs at 60/70 seconds after first present and ordinary close at 125 seconds after first present. Cache contents evolve; this establishes shutdown behavior, not a speed comparison. This is a native **integration** result, not an isolated title test of the PR head on current main. 26 GPU-readback frames were saved; selected frames show the menu and driving cutscene. X11 snapshots at 100/115 seconds repeat despite advancing frame counts, so scene inspection uses GPU frames. AMD RX 6650 XT / RADV Mesa 26.2.4, Arch Linux. No performance result. **Independent Windows regression validation:** [savvaniss reports](https://github.com/boykopovar/AnyPS5/pull/7755#issuecomment-6262394831) three serial runs each on Intel UHD 770 (driver 32.0.101.7088) and AMD RX 9070 XT (driver 32.0.31041.1004), Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release. `agc_profile_output` passes with PR head `f085363ef` merged into main `6b8228b2b`; the PR test file alone on that main fails with `profile output is stopping` on both GPUs. Every execution test was built; `ANYPS5_NO_SHADER_CACHE=1`, with the AMD `VkCache` emptied first. This is contributor-reported focused regression evidence, not a Windows native-title or performance test. **Additional Linux native integration validation (Smurfs Dreams, PPSA21607 v01.002.000):** profiling integration `97a9225d722842fc1e893ceabca3969617230e47` reached the village but exited 134 after the scheduled ordinary close, ending in `profile output is stopping`. Applying only this PR’s patch produced `11b1d62ade7eb71f13acb05ca78f2ea2ad7f2944`: the village still renders, ordinary close was requested at 355.66 s, and the process exited 0 at 357.67 s. PID gone; udmabuf limit restored to 64 MiB; no profiling-stop or termination exception. The CPU-only `agc_profile_output` CTest passes on both integrations. Both runs use the same relinked title, restored checkpoint, `APS5_PROFILE_DRAW=1`, `APS5_PROFILE_GPU=1`, scheduled inputs and close procedure. Caches evolve; this is functional shutdown evidence, not a performance comparison. The base integration is main `3aa35dc014a84b783c2fbe642f8e08341feb1a30` plus #6959 and #6948; this is not an isolated title test of the PR head on current main. RX 6650 XT / RADV Mesa 26.2.4, Linux. Existing pending-storage-image shutdown diagnostics remain. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none (shutdown diagnostic regression; no new title run) - [x] GPUs tested: AMD RX 6650 XT / RADV Mesa 26.2.4, Arch Linux (native integration only); contributor-reported Windows Intel UHD 770 and AMD RX 9070 XT focused regression passes (queue tests are CPU-only), linked above - [x] AI-assisted: yes
simonbbby commented 2026-10-19 06:24:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-19T06:24:14Z.


Native macOS confirmation at exact head f085363ef22b4335d0385444c246d64876705465, against parent 46f27623c28b237f6b7dab93862a318e4977cc19: both shutdown failures reproduce here, including through the public profiling wrappers.

macOS 27.2 arm64, AppleClang 21.0.0/libc++, standalone C++20/pthread builds using the exact production header. No other PRs applied.

Probe after a completed Stop() Parent PR
Local queue, Write("late") throws profile output is stopping returns false; Flush() finishes
Local queue, capacity 8192, Print of 10000 characters Print returns; Flush() exceeds 2 s flush finishes; only accepted output was written
ProfilePrint_nid_no_patch after StopProfileOutput_nid_no_patch, small text same exception returns; flush finishes
Same wrappers, text of 4 MiB + 1 (over the default capacity) formatting returns; flush exceeds 2 s flush finishes; no late text written

The oversized timeout is after Stop() returned and after formatting returned, with the accepted output already drained. A local queue reproduces it without the global singleton. This fits the specific chain in the header: the stopped worker has exited, the old oversized path increments dropped, and Flush() waits for dropped == 0 with no worker left to clear it.

Two isolated controls separate the fixes:

  • Restore only the old throwing Write() guard: both small-text probes fail again; both oversized probes still pass.
  • Remove only the new stopping check in the oversized-format path: both oversized probes hang again; both small-text probes still pass.

The unchanged PR ProfileOutput.cpp also passes 50 fresh optimized runs and 20 fresh AddressSanitizer + UndefinedBehaviorSanitizer runs, with no sanitizer diagnostics. That includes accepted-output draining, eight producers racing stop, overflow, and all six real-writer-failure paths (including formatting after stop). Thus the late-output rejection does not swallow the injected writer error in those checks.

This is native queue/wrapper verification, not a macOS title run, full AGC build, or full application-teardown test. No performance or Windows result is claimed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6261071642 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7755#issuecomment-6261071642). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-19T06:24:14Z. --- Native macOS confirmation at exact head `f085363ef22b4335d0385444c246d64876705465`, against parent `46f27623c28b237f6b7dab93862a318e4977cc19`: both shutdown failures reproduce here, including through the public profiling wrappers. macOS 27.2 arm64, AppleClang 21.0.0/libc++, standalone C++20/pthread builds using the exact production header. No other PRs applied. | Probe after a completed `Stop()` | Parent | PR | |---|---|---| | Local queue, `Write("late")` | throws `profile output is stopping` | returns false; `Flush()` finishes | | Local queue, capacity 8192, `Print` of 10000 characters | `Print` returns; `Flush()` exceeds 2 s | flush finishes; only accepted output was written | | `ProfilePrint_nid_no_patch` after `StopProfileOutput_nid_no_patch`, small text | same exception | returns; flush finishes | | Same wrappers, text of 4 MiB + 1 (over the default capacity) | formatting returns; flush exceeds 2 s | flush finishes; no late text written | The oversized timeout is after `Stop()` returned and after formatting returned, with the accepted output already drained. A local queue reproduces it without the global singleton. This fits the specific chain in the header: the stopped worker has exited, the old oversized path increments `dropped`, and `Flush()` waits for `dropped == 0` with no worker left to clear it. Two isolated controls separate the fixes: - Restore only the old throwing `Write()` guard: both small-text probes fail again; both oversized probes still pass. - Remove only the new stopping check in the oversized-format path: both oversized probes hang again; both small-text probes still pass. The unchanged PR `ProfileOutput.cpp` also passes **50 fresh optimized runs** and **20 fresh AddressSanitizer + UndefinedBehaviorSanitizer runs**, with no sanitizer diagnostics. That includes accepted-output draining, eight producers racing stop, overflow, and all six real-writer-failure paths (including formatting after stop). Thus the late-output rejection does not swallow the injected writer error in those checks. This is native queue/wrapper verification, not a macOS title run, full AGC build, or full application-teardown test. No performance or Windows result is claimed.
savvaniss commented 2026-10-19 07:52:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T07:52:18Z.


Intel and AMD Windows data: agc_profile_output fails on main and passes with this PR, on an Intel UHD 770 and an AMD RX 9070 XT.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head f085363ef merged into main 6b8228b2b. "Without" means this PR's test file on main 6b8228b2b, with none of its other changes.

Tests, ×3 UHD 770 RX 9070 XT
This head: agc_profile_output pass pass
Without fails: profile output is stopping same

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262394831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7755#issuecomment-6262394831). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T07:52:18Z. --- Intel and AMD Windows data: `agc_profile_output` fails on `main` and passes with this PR, on an Intel UHD 770 and an AMD RX 9070 XT. Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, `ANYPS5_NO_SHADER_CACHE=1`, serial CTest. Intel UHD Graphics 770 (`8086:a780`), driver 32.0.101.7088. AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31041.1004, with `VkCache` emptied first. This head `f085363ef` merged into `main` `6b8228b2b`. "Without" means this PR's test file on `main` `6b8228b2b`, with none of its other changes. | Tests, ×3 | UHD 770 | RX 9070 XT | |---|---|---| | This head: `agc_profile_output` | pass | pass | | Without | fails: `profile output is stopping` | same | AI-assisted: yes (Claude Code)
JJenkx commented 2026-10-19 23:40:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-19T23:40:29Z.


Linux title shutdown corroboration: Snoopy (PPSA28795) reached the backyard with draw profiling enabled, then an ordinary window close completed with native exit 0. The process was gone and the harness restored its kernel configuration. I inspected the final gameplay capture.

The preceding run on integration 31418b2d60 terminated with exit 134 and profile output is stopping after the same ordinary-close schedule. Cherry-picking this PR as ed307c29dafd was the only source change for the successful run. Both used the same relinked title, pipelined draws/DMA, full SPIR-V optimization, draw profiling/cache diagnostics, input schedule, and close at 270 seconds.

This is an integration regression check: the common base is f3fe95b4b9 plus the DCC-clear and partial draw-history changes, not current main. It supports the teardown fix and makes no performance claim. Local evidence: sync190 baseline and sync192-snoopy-profile-stop candidate; candidate build and the focused agc_profile_output test also passed.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6279778398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7755#issuecomment-6279778398). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-19T23:40:29Z. --- Linux title shutdown corroboration: Snoopy (PPSA28795) reached the backyard with draw profiling enabled, then an ordinary window close completed with native exit 0. The process was gone and the harness restored its kernel configuration. I inspected the final gameplay capture. The preceding run on integration `31418b2d60` terminated with exit 134 and `profile output is stopping` after the same ordinary-close schedule. Cherry-picking this PR as `ed307c29dafd` was the only source change for the successful run. Both used the same relinked title, pipelined draws/DMA, full SPIR-V optimization, draw profiling/cache diagnostics, input schedule, and close at 270 seconds. This is an integration regression check: the common base is `f3fe95b4b9` plus the DCC-clear and partial draw-history changes, not current main. It supports the teardown fix and makes no performance claim. Local evidence: `sync190` baseline and `sync192-snoopy-profile-stop` candidate; candidate build and the focused `agc_profile_output` test also passed. AI-assisted: yes.
adriadam10 commented 2026-10-20 01:44:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T01:44:56Z.


Checked the three Print/Write paths after Stop(): late writes now return false like the queue-full rejection, the oversized path no longer bumps dropped after the worker exited (so Flush() can't hang), and a real writer failure is still rethrown first. The new tests fail on main and cover repeated stop, concurrent producers racing stop and writer errors after stop; the macOS and Windows runs in the thread agree; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281377392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7755#issuecomment-6281377392). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T01:44:56Z. --- Checked the three `Print`/`Write` paths after `Stop()`: late writes now return false like the queue-full rejection, the oversized path no longer bumps `dropped` after the worker exited (so `Flush()` can't hang), and a real writer failure is still rethrown first. The new tests fail on main and cover repeated stop, concurrent producers racing stop and writer errors after stop; the macOS and Windows runs in the thread agree; merged.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7755
No description provided.