fix(agc): read polled guest labels with acquire loads #20185

Merged
chitters2004 merged 3 commits from upstream-pr/20185 into main 2026-11-22 05:26:59 +00:00
chitters2004 commented 2026-11-14 19:42:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by chitters2004 on 2026-11-14T19:42:20Z.


What

The PM4 wait (Pm4::WaitSatisfiedUnchecked) and the other guest-label polls read labels through volatile pointers, while other threads store those labels atomically. That's a data race, and ThreadSanitizer reports it. The polls are:

  • the awaited-slot and held-at-submit checks in Submission.cpp;
  • the own-store check, the wait trace and the timeout report in WaitMemory.cpp;
  • the wait epoch in WaitStatistics.cpp.

They now go through a new Pm4::LoadLabel(address, bytes), an std::atomic_ref acquire load.

  • On x86-64 it compiles to the same mov as the volatile read (checked with g++ -O2); on arm64 ldr becomes ldar.
  • The held-at-submit path only checks 4-byte alignment, so it does two 4-byte loads.
  • The debt entry "Plain label read in the PM4 wait" is removed: this change is its close condition. docs/dev/BUILD.md's TSan note is reworded: polls are acquire loads now, but guest memory is still written with plain stores (copies, replay restores), so TSan still reports those stores against the polls.

Tested

  • ThreadSanitizer, gcc 13 RelWithDebInfo with ANYPS5_ENABLE_TSAN=ON, Linux, llvmpipe, halt_on_error=0, no suppressions. Same machine, main 6786420207 vs this branch, 3 runs each:

    test main this branch
    agc_driver_flip fails 3/3, 2 reports each passes 3/3, 0 reports
    agc_driver_pm4_rewind_trace fails 3/3, 6 reports each passes 3/3, 0 reports
    • On main, every report pairs an atomic store with the volatile read in Pm4::WaitSatisfiedUnchecked.
    • With the fix, every agc_driver_pm4* test passes under TSan except agc_driver_pm4 (3 reports) and agc_driver_pm4_replay (1). All four of those reports have a plain memcpy writer (replay restore), the class this change doesn't touch.
    • An earlier full count on main 74900e8b0f (flip, frame replay, pm4, pm4 replay, guest PM4; 76 tests) went from 45 reports to 28; the remaining 28 all have a plain writer.
  • tools/check_conventions.py --base origin/main: passes.

  • Fork CI on this tree (run 43629894526): the Linux gate and the Windows build pass the listed tests.

    • Its TSan job still fails the frame-replay tests. Those reports pair a plain memcpy writer (replay restore, GuestMemory::Write) with the now-atomic polls: the writer-side class described above.
    • A follow-up PR makes those writers atomic and brings them to 0.

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
  • GPUs tested: llvmpipe (LLVM 20.1.2), Ubuntu 24.04; CPU rasterizer only, no hardware GPU run
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5315472256 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20185). Originally posted by [chitters2004](https://github.com/chitters2004) on 2026-11-14T19:42:20Z. --- ### What The PM4 wait (`Pm4::WaitSatisfiedUnchecked`) and the other guest-label polls read labels through `volatile` pointers, while other threads store those labels atomically. That's a data race, and ThreadSanitizer reports it. The polls are: - the awaited-slot and held-at-submit checks in `Submission.cpp`; - the own-store check, the wait trace and the timeout report in `WaitMemory.cpp`; - the wait epoch in `WaitStatistics.cpp`. They now go through a new `Pm4::LoadLabel(address, bytes)`, an `std::atomic_ref` acquire load. - On x86-64 it compiles to the same `mov` as the volatile read (checked with g++ -O2); on arm64 `ldr` becomes `ldar`. - The held-at-submit path only checks 4-byte alignment, so it does two 4-byte loads. - The debt entry "Plain label read in the PM4 wait" is removed: this change is its close condition. `docs/dev/BUILD.md`'s TSan note is reworded: polls are acquire loads now, but guest memory is still written with plain stores (copies, replay restores), so TSan still reports those stores against the polls. ### Tested - ThreadSanitizer, gcc 13 RelWithDebInfo with `ANYPS5_ENABLE_TSAN=ON`, Linux, llvmpipe, `halt_on_error=0`, no suppressions. Same machine, main 6786420207 vs this branch, 3 runs each: | test | main | this branch | |---|---|---| | `agc_driver_flip` | fails 3/3, 2 reports each | passes 3/3, 0 reports | | `agc_driver_pm4_rewind_trace` | fails 3/3, 6 reports each | passes 3/3, 0 reports | - On main, every report pairs an atomic store with the volatile read in `Pm4::WaitSatisfiedUnchecked`. - With the fix, every `agc_driver_pm4*` test passes under TSan except `agc_driver_pm4` (3 reports) and `agc_driver_pm4_replay` (1). All four of those reports have a plain `memcpy` writer (replay restore), the class this change doesn't touch. - An earlier full count on main 74900e8b0f (flip, frame replay, pm4, pm4 replay, guest PM4; 76 tests) went from 45 reports to 28; the remaining 28 all have a plain writer. - `tools/check_conventions.py --base origin/main`: passes. - Fork CI on this tree (run 43629894526): the Linux gate and the Windows build pass the listed tests. - Its TSan job still fails the frame-replay tests. Those reports pair a plain `memcpy` writer (replay restore, `GuestMemory::Write`) with the now-atomic polls: the writer-side class described above. - A follow-up PR makes those writers atomic and brings them to 0. ### 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 - [x] GPUs tested: llvmpipe (LLVM 20.1.2), Ubuntu 24.04; CPU rasterizer only, no hardware GPU run - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-14 20:48:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T20:48:42Z.

Review: COMMENTED


Reviewed — comments

The change is consistent with the stated goal, but I could not run the reported checks, so a formal approval is not justified.

What I ran

Reviewed head 0d4d85d8e1af9f53defb66127fde944085cc8951 using the prepared diff and pinned reader. No tests or build commands were run.

Results

Check Result Note
Diff and targeted code review passed All seven changed paths inspected
Tests and build not run No command execution available
Reported CI and TSan checks not run Reported in the PR description only

Negative control

Not run; no test command could be run in this review.

Findings

Blocking

None.

Non-blocking

None.

Sources

The acquire-load helper and its changed poll call sites are visible in the pinned PM4 header, wait implementation, submission paths, wait-memory paths, and wait statistics.

Not verified

The PR description reports TSan, convention-check, and CI results, but they were not run here. review/files.json was unavailable; the manifest lists seven changed files, and all seven changed paths were inspected through the diff and targeted reader ranges. Full file texts were not read. The debt entry and build documentation were checked at their changed sections.

To get this to a good state

Nothing is required. Optional: run the reported checks on this head to independently confirm the PR description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5907082086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20185#pullrequestreview-5907082086). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T20:48:42Z. **Review:** COMMENTED --- # Reviewed — comments The change is consistent with the stated goal, but I could not run the reported checks, so a formal approval is not justified. ## What I ran Reviewed head `0d4d85d8e1af9f53defb66127fde944085cc8951` using the prepared diff and pinned reader. No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted code review | passed | All seven changed paths inspected | | Tests and build | not run | No command execution available | | Reported CI and TSan checks | not run | Reported in the PR description only | ## Negative control Not run; no test command could be run in this review. ## Findings ### Blocking None. ### Non-blocking None. ## Sources The acquire-load helper and its changed poll call sites are visible in the [pinned PM4 header](https://github.com/boykopovar/AnyPS5/blob/0d4d85d8e1af9f53defb66127fde944085cc8951/core/libs/prx/libSceAgcDriver/Execution/include/Pm4.hpp), [wait implementation](https://github.com/boykopovar/AnyPS5/blob/0d4d85d8e1af9f53defb66127fde944085cc8951/core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp), [submission paths](https://github.com/boykopovar/AnyPS5/blob/0d4d85d8e1af9f53defb66127fde944085cc8951/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Queues/Submission.cpp), [wait-memory paths](https://github.com/boykopovar/AnyPS5/blob/0d4d85d8e1af9f53defb66127fde944085cc8951/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitMemory.cpp), and [wait statistics](https://github.com/boykopovar/AnyPS5/blob/0d4d85d8e1af9f53defb66127fde944085cc8951/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Synchronization/WaitStatistics.cpp). ## Not verified The PR description reports TSan, convention-check, and CI results, but they were not run here. `review/files.json` was unavailable; the manifest lists seven changed files, and all seven changed paths were inspected through the diff and targeted reader ranges. Full file texts were not read. The debt entry and build documentation were checked at their changed sections. ## To get this to a good state Nothing is required. Optional: run the reported checks on this head to independently confirm the PR description.
MarcZX10 commented 2026-11-15 02:41:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-15T02:41:00Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the reviewed code and added tests support merging.

What I ran

Reviewed head e3d9cefb3a6bc4aefbb8736b636d34cb0105d2d0 against base main. I read the prepared description, commit list, manifest, full diff, and all changed lines in the ten changed files using repo_read.py's review reader. I also read the relevant wait decoding and guest-memory access context. No commands or tests were run by me; test results below are author-reported.

Results

Check Result Note
Diff and changed lines passed All ten changed files reviewed
Added wait acquire tests passed Coverage includes checked and unchecked 32-bit and 64-bit waits
Build and runtime checks not run Author reports CI and local results

Negative control

Not run; no test modification or injected failure was performed.

Findings

Blocking

None.

Non-blocking

None.

Sources

Behavior claims are based on the reviewed diff and repository files at the specified head; no external links were used.

Not verified

I did not run the test suite, TSan, convention checker, or CI, and did not verify the author-reported runs. I read all changed lines listed in the manifest; no changed file was excluded by the bundle. I did not read every unchanged line of the ten changed files or unrelated repository files.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5908673062 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20185#pullrequestreview-5908673062). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-15T02:41:00Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the reviewed code and added tests support merging. ## What I ran Reviewed head `e3d9cefb3a6bc4aefbb8736b636d34cb0105d2d0` against base `main`. I read the prepared description, commit list, manifest, full diff, and all changed lines in the ten changed files using `repo_read.py`'s review reader. I also read the relevant wait decoding and guest-memory access context. No commands or tests were run by me; test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed lines | passed | All ten changed files reviewed | | Added wait acquire tests | passed | Coverage includes checked and unchecked 32-bit and 64-bit waits | | Build and runtime checks | not run | Author reports CI and local results | ## Negative control Not run; no test modification or injected failure was performed. ## Findings ### Blocking None. ### Non-blocking None. ## Sources Behavior claims are based on the reviewed diff and repository files at the specified head; no external links were used. ## Not verified I did not run the test suite, TSan, convention checker, or CI, and did not verify the author-reported runs. I read all changed lines listed in the manifest; no changed file was excluded by the bundle. I did not read every unchanged line of the ten changed files or unrelated repository files. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-20 13:12:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:12:56Z.

Review: COMMENTED


Reviewed — comments

Changes are required before merge: resolve the documented mismatch between wait and label store widths, which means the acquire load may not pair with the publishing store.

What I ran

Reviewed head 2e95be1bfebdda57fcd550801f10c2f503fea1fc. I read the prepared description, commits, manifest, diff, and all ten changed files listed in the manifest. I did not run tests or builds; repo_read.py was the only reader used. The author reports TSan and CI results in the description; those were not independently run or verified.

Results

Check Result Note
Changed-file review passed All ten manifest files read
Tests and build not run Author-reported results only
CI not run Author-reported results only

Findings

Blocking

None. The mismatch is documented as a limitation in the changed debt entry, but the reviewed code does not establish that it causes a concrete defect on this change.

Non-blocking

  • The new load uses the wait's access width, while label stores may use a different width. The updated debt entry describes the consequence: an acquire load overlapping a differently sized atomic store does not formally synchronize with that release. Consider tracking the producer's store width and loading at that width, or otherwise ensuring the wait and publisher use a common atomic width. See core/libs/prx/libSceAgcDriver/Execution/include/Pm4.hpp:116 and docs/dev/debt/libSceAgcDriver.md:487.

Not verified

  • No tests, builds, or CI jobs were run in this review; the reported TSan and CI outcomes are author-supplied.
  • No physical-console or hardware-GPU behavior was verified. The description says its GPU tests used llvmpipe.
  • files.json was unavailable through the reader; the manifest lists ten changed files and all ten were read. No additional exclusions were inspected.

To get this to a good state

Nothing is required. The width mismatch is optional follow-up feedback, as described above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5993235485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/20185#pullrequestreview-5993235485). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T13:12:56Z. **Review:** COMMENTED --- # Reviewed — comments Changes are required before merge: resolve the documented mismatch between wait and label store widths, which means the acquire load may not pair with the publishing store. ## What I ran Reviewed head `2e95be1bfebdda57fcd550801f10c2f503fea1fc`. I read the prepared description, commits, manifest, diff, and all ten changed files listed in the manifest. I did not run tests or builds; `repo_read.py` was the only reader used. The author reports TSan and CI results in the description; those were not independently run or verified. ## Results | Check | Result | Note | |---|---|---| | Changed-file review | passed | All ten manifest files read | | Tests and build | not run | Author-reported results only | | CI | not run | Author-reported results only | ## Findings ### Blocking None. The mismatch is documented as a limitation in the changed debt entry, but the reviewed code does not establish that it causes a concrete defect on this change. ### Non-blocking - The new load uses the wait's access width, while label stores may use a different width. The updated debt entry describes the consequence: an acquire load overlapping a differently sized atomic store does not formally synchronize with that release. Consider tracking the producer's store width and loading at that width, or otherwise ensuring the wait and publisher use a common atomic width. See `core/libs/prx/libSceAgcDriver/Execution/include/Pm4.hpp:116` and `docs/dev/debt/libSceAgcDriver.md:487`. ## Not verified - No tests, builds, or CI jobs were run in this review; the reported TSan and CI outcomes are author-supplied. - No physical-console or hardware-GPU behavior was verified. The description says its GPU tests used llvmpipe. - `files.json` was unavailable through the reader; the manifest lists ten changed files and all ten were read. No additional exclusions were inspected. ## To get this to a good state Nothing is required. The width mismatch is optional follow-up feedback, as described above.
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!20185
No description provided.