test(agc): keep the queue-idle store out of the file write cases #7745

Merged
jotitadev merged 1 commit from upstream-pr/7745 into main 2026-10-19 10:54:18 +00:00
jotitadev commented 2026-10-19 05:42:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T05:42:40Z.


What

agc_driver_storage_file_write failed on the Linux job of an unrelated pull request (#6690, which only touches GuestSceNet.cpp; job 117871904717, lavapipe, 0.81 s against about 0.1 s for a normal run):

sceKernelWrite: 0 incorrect file bytes out of 131035
AGC graphics: file write: an unrelated pending GPU image was flushed

The test expects the unrelated surface's image to stay pending through all twelve cases, and the source image to stay pending until the write flushes it. Queue 0 stores every pending image once the queues stay quiet for 50 ms (IdleResultsQuietPeriod in QueueWorker.cpp, from afbc3c8eb), so a pause of 50 ms or more anywhere in the test, which a loaded runner can cause, flushes both images and fails one of those checks. #7535 (open) wakes queue 0 sooner when storage results are pending, so it would make this more likely, not less.

Each case now takes the GPU mutex right after its producer. StoreIdleResults takes the same mutex, and it is recursive, so the write and the readback under the hold run as before. If the idle store reached an image before the hold, the case produces it again. The unrelated check moves inside the case, under the same hold. The file contents check is unchanged.

Tested

Intel i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, measured on main 3904ce6cf (the test file is the same on current main). lavapipe is Mesa 26.0.3 with GALLIUM_OVERRIDE_CPU_CAPS=avx, as the CI job sets it. The CI log shows /dev/udmabuf is not usable there, so the lavapipe runs deny it through an LD_PRELOAD shim, which prints the same [gpu] open /dev/udmabuf: Permission denied line as the CI log.

Without load, the test does not fail on main on this machine (0 of 1400 runs, 4 copies at a time). To reproduce a loaded runner, each copy is stopped with SIGSTOP for 70 ms every 20 ms while it runs:

2 copies at a time, stopped 70 ms every 20 ms main this change
lavapipe 64 of 100 fail 0 of 200 fail
RTX 3070 (NVIDIA 595.99.02) 24 of 50 fail 0 of 50 fail
  • On main most of the failures are the CI message (58 of the 64 on lavapipe). The others are an empty or invalid write flushed its source (2), the GPU producer left no pending image (1) and the GPU producer wrote only zeros (3).
  • On main, a 60 ms sleep after the first producer is enough to get the CI message every time. 40 ms passes.
  • Without the stops, on this change: lavapipe 0 of 400, RTX 3070 0 of 100.
  • The test still catches the bug it was added for. With FlushGpuWrites taken out of PrepareHostRead, every case reports 85957 incorrect file bytes and the test fails, on lavapipe and on the RTX 3070.
  • python3 tools/check_conventions.py --base origin/main passes.

Not checked: Windows, where the test also runs. The change uses only the cross-platform GpuMutex.

Separate from this change: the wrote only zeros failures come from a host read that overlaps the idle store. FlushPending moves an image from pending.textures to pending.flushing before it writes it back, so a host read on another thread (GuestMemory::Read, a file write) finds nothing pending, returns without waiting, and reads guest memory before the write-back lands. A small fixture that runs FlushAllPending under the GPU mutex on one thread and GuestMemory::Read on another sees zeros in 190 of 200 reads on lavapipe and in 191 of 200 on the RTX 3070. This change keeps that race out of the test, but it does not fix it.

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
  • GPUs tested: NVIDIA RTX 3070 (Linux, 595.99.02), lavapipe (Mesa 26.0.3)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4916438645 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7745). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T05:42:40Z. --- ### What `agc_driver_storage_file_write` failed on the Linux job of an unrelated pull request (#6690, which only touches `GuestSceNet.cpp`; job 117871904717, lavapipe, 0.81 s against about 0.1 s for a normal run): ``` sceKernelWrite: 0 incorrect file bytes out of 131035 AGC graphics: file write: an unrelated pending GPU image was flushed ``` The test expects the `unrelated` surface's image to stay pending through all twelve cases, and the source image to stay pending until the write flushes it. Queue 0 stores every pending image once the queues stay quiet for 50 ms (`IdleResultsQuietPeriod` in `QueueWorker.cpp`, from afbc3c8eb), so a pause of 50 ms or more anywhere in the test, which a loaded runner can cause, flushes both images and fails one of those checks. #7535 (open) wakes queue 0 sooner when storage results are pending, so it would make this more likely, not less. Each case now takes the GPU mutex right after its producer. `StoreIdleResults` takes the same mutex, and it is recursive, so the write and the readback under the hold run as before. If the idle store reached an image before the hold, the case produces it again. The `unrelated` check moves inside the case, under the same hold. The file contents check is unchanged. ### Tested Intel i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, measured on `main` `3904ce6cf` (the test file is the same on current `main`). lavapipe is Mesa 26.0.3 with `GALLIUM_OVERRIDE_CPU_CAPS=avx`, as the CI job sets it. The CI log shows `/dev/udmabuf` is not usable there, so the lavapipe runs deny it through an `LD_PRELOAD` shim, which prints the same `[gpu] open /dev/udmabuf: Permission denied` line as the CI log. Without load, the test does not fail on `main` on this machine (0 of 1400 runs, 4 copies at a time). To reproduce a loaded runner, each copy is stopped with `SIGSTOP` for 70 ms every 20 ms while it runs: | 2 copies at a time, stopped 70 ms every 20 ms | `main` | this change | |---|---|---| | lavapipe | 64 of 100 fail | 0 of 200 fail | | RTX 3070 (NVIDIA 595.99.02) | 24 of 50 fail | 0 of 50 fail | - On `main` most of the failures are the CI message (58 of the 64 on lavapipe). The others are `an empty or invalid write flushed its source` (2), `the GPU producer left no pending image` (1) and `the GPU producer wrote only zeros` (3). - On `main`, a 60 ms sleep after the first producer is enough to get the CI message every time. 40 ms passes. - Without the stops, on this change: lavapipe 0 of 400, RTX 3070 0 of 100. - The test still catches the bug it was added for. With `FlushGpuWrites` taken out of `PrepareHostRead`, every case reports 85957 incorrect file bytes and the test fails, on lavapipe and on the RTX 3070. - `python3 tools/check_conventions.py --base origin/main` passes. Not checked: Windows, where the test also runs. The change uses only the cross-platform `GpuMutex`. Separate from this change: the `wrote only zeros` failures come from a host read that overlaps the idle store. `FlushPending` moves an image from `pending.textures` to `pending.flushing` before it writes it back, so a host read on another thread (`GuestMemory::Read`, a file write) finds nothing pending, returns without waiting, and reads guest memory before the write-back lands. A small fixture that runs `FlushAllPending` under the GPU mutex on one thread and `GuestMemory::Read` on another sees zeros in 190 of 200 reads on lavapipe and in 191 of 200 on the RTX 3070. This change keeps that race out of the test, but it does not fix it. ### 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 - [x] GPUs tested: NVIDIA RTX 3070 (Linux, 595.99.02), lavapipe (Mesa 26.0.3) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jotitadev commented 2026-10-19 05:42:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T05:42:47Z.


The product-side race mentioned in the description is now tracked in #7744 (a host read on another thread does not wait for an image the queue-idle store is writing back). This PR only keeps the test deterministic.

Written with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6260541153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7745#issuecomment-6260541153). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T05:42:47Z. --- The product-side race mentioned in the description is now tracked in #7744 (a host read on another thread does not wait for an image the queue-idle store is writing back). This PR only keeps the test deterministic. Written with AI assistance (Claude Code).
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!7745
No description provided.