test(agc): shut libc down before agc_shader_helpers returns #6925

Merged
LeandroLP23 merged 1 commit from upstream-pr/6925 into main 2026-10-17 04:29:06 +00:00
LeandroLP23 commented 2026-10-16 18:59:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-16T18:59:50Z.


What

Fixes #6791. On Windows, agc_shader_helpers returned from main with the driver's threads still running. ExitProcess ends those threads first, then the DLLs' static destructors run at DLL_PROCESS_DETACH and wait forever on what the threads left locked. The test prints shader helper preparation tests passed and then never exits.

With debug info (-O3 -g) and gdb -p on hung processes, the main thread is the only thread left. It waits in one of three places, and a fix for one moves the hang to the next:

Where the main thread waits Seen
AsyncLog::Flush (unique_lock on the queue mutex), inlined into Driver::stop from ~Driver on main. The mutex sits at offset 8 of AsyncLog, the lea 0x8(%rax),%rcx in #6791's disassembly
~DeviceUseGate (its condition_variable), from ~Driver after stop returns 9 of 9 hangs with Driver::stop's flush bounded
_execute_onexit_table of libkernel.prx, in a libstdc++ destructor that waits in winpthreads 5 of 5 hangs with the Driver also kept alive at detach

So the cause is the test's exit path, not one lock. The other driver tests (PipelinedDma, PipelinedDispatch, DepthFastClearSubmit, ...) already call LibcRunShutdown_nid_postfix before they return, which stops the driver while its threads are still alive. agc_shader_helpers now does the same, on success and on failure.

#6817 bounds the same test's runtime with a CTest TIMEOUT; the two don't overlap.

Tested

Windows 11 (26300), Radeon 860M (RDNA 3.5, 1002:1114, driver 32.0.13058.8001), WinLibs GCC 15.2.0, ctest -R '^agc_shader_helpers$' --timeout 30, one test per ctest process:

Tree Runs Timed out
main 82ddae75b, Release 27 9
main 82ddae75b, -O3 -g 30 4
this change, -O3 -g (same build) 60 0
  • tools/check_conventions.py --base origin/main passes; git diff --check is clean.
  • Fork CI: linux 1292 of 1295, with agc_shader_helpers passing; the failures are conventions_ci_gate and build_eligibility (fork-only) and agc_driver_graphics (#6792, fixed by #6789). Windows stops on GpuIndirectArgumentsMisalignedWriterAhead.cpp's alignas(65536) as on main (#6452); the relinker jobs fail only the two fork-only tests.

Not tested: macOS.

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
  • Unblocks: none (main's Windows CI)
  • GPUs tested: AMD Radeon 860M (RDNA 3.5), driver 32.0.13058.8001, Windows 11
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4892973548 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6925). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-16T18:59:50Z. --- ### What Fixes #6791. On Windows, `agc_shader_helpers` returned from `main` with the driver's threads still running. `ExitProcess` ends those threads first, then the DLLs' static destructors run at `DLL_PROCESS_DETACH` and wait forever on what the threads left locked. The test prints `shader helper preparation tests passed` and then never exits. With debug info (`-O3 -g`) and `gdb -p` on hung processes, the main thread is the only thread left. It waits in one of three places, and a fix for one moves the hang to the next: | Where the main thread waits | Seen | |---|---| | `AsyncLog::Flush` (`unique_lock` on the queue mutex), inlined into `Driver::stop` from `~Driver` | on `main`. The mutex sits at offset 8 of `AsyncLog`, the `lea 0x8(%rax),%rcx` in #6791's disassembly | | `~DeviceUseGate` (its `condition_variable`), from `~Driver` after `stop` returns | 9 of 9 hangs with `Driver::stop`'s flush bounded | | `_execute_onexit_table` of `libkernel.prx`, in a libstdc++ destructor that waits in winpthreads | 5 of 5 hangs with the `Driver` also kept alive at detach | So the cause is the test's exit path, not one lock. The other driver tests (`PipelinedDma`, `PipelinedDispatch`, `DepthFastClearSubmit`, ...) already call `LibcRunShutdown_nid_postfix` before they return, which stops the driver while its threads are still alive. `agc_shader_helpers` now does the same, on success and on failure. #6817 bounds the same test's runtime with a CTest `TIMEOUT`; the two don't overlap. ### Tested Windows 11 (26300), Radeon 860M (RDNA 3.5, `1002:1114`, driver 32.0.13058.8001), WinLibs GCC 15.2.0, `ctest -R '^agc_shader_helpers$' --timeout 30`, one test per `ctest` process: | Tree | Runs | Timed out | |---|---|---| | `main` `82ddae75b`, Release | 27 | 9 | | `main` `82ddae75b`, `-O3 -g` | 30 | 4 | | this change, `-O3 -g` (same build) | 60 | 0 | - `tools/check_conventions.py --base origin/main` passes; `git diff --check` is clean. - [Fork CI](https://github.com/LeandroLP23/AnyPS5/actions/runs/38951633067): linux 1292 of 1295, with `agc_shader_helpers` passing; the failures are `conventions_ci_gate` and `build_eligibility` (fork-only) and `agc_driver_graphics` (#6792, fixed by #6789). Windows stops on `GpuIndirectArgumentsMisalignedWriterAhead.cpp`'s `alignas(65536)` as on `main` (#6452); the relinker jobs fail only the two fork-only tests. Not tested: macOS. ### Checklist - [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] Unblocks: none (`main`'s Windows CI) - [x] GPUs tested: AMD Radeon 860M (RDNA 3.5), driver 32.0.13058.8001, Windows 11 - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-16 20:59:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T20:59:11Z.


I reviewed the shutdown calls against the existing AGC test pattern on current main. Running LibcRunShutdown_nid_postfix() on success and best-effort from the exception path matches the neighboring driver tests and addresses the reported DLL-detach deadlock path. The issue records the 60/60 Windows post-fix runs; hosted conventions, eligibility, intake and report checks pass here, while the platform/build jobs are skipped. I have no code change to request from this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6224583273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6925#issuecomment-6224583273). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-16T20:59:11Z. --- I reviewed the shutdown calls against the existing AGC test pattern on current `main`. Running `LibcRunShutdown_nid_postfix()` on success and best-effort from the exception path matches the neighboring driver tests and addresses the reported DLL-detach deadlock path. The issue records the 60/60 Windows post-fix runs; hosted conventions, eligibility, intake and report checks pass here, while the platform/build jobs are skipped. I have no code change to request from this review.
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!6925
No description provided.