fix(agc): do not evict host imports used in the current or previous frame #11357

Merged
oneandonlydean merged 3 commits from upstream-pr/11357 into main 2026-10-27 17:23:09 +00:00
oneandonlydean commented 2026-10-26 08:10:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-26T08:10:29Z.


Summary

Host imports used in the current or the previous frame are no longer evicted for another import.

An import was evictable 256 lookups after its last use. A frame makes thousands of lookups, so when the imports a frame uses do not all fit the budget, each new one evicts another of the same frame, and (reasoned from the 256-lookup rule, not measured here) the set is imported again every frame. A frame now ends at a flip packet or a CPU flip (NoteHostImportFrame), and only imports not used in the current or the previous frame are evicted; what does not fit is refused and copied, as below the budget. A frame boundary also expires the remembered evicting refusals; a remembered refusal also ends when a build holding an import two frames old raises its floor. ProtectedUses and the use-count horizon it fed remain only for the stretch before two frames have ended; once frames exist the frame rule decides.

Until two frames have ended, imports age by lookups exactly as on main (so a loading stretch before the first flips behaves as before); after that, without flips (compute-only work) no frame ends and nothing more becomes evictable, so imports that do not fit are copied instead of evicting by recency. A frame end moves its own counter, used only by the remembered-refusal memory; it does not move the imports epoch, so the address-space cache survives a flip with no import change. The debt entry says so.

Tests

  • New importEvictionFramesTests: three ranges under a budget for two, each used by its own build every frame with more lookups than a frame's worth of imports between uses; the first two keep their imports, the third is refused every frame, and a range unused for two frames is evicted.

  • RunAddressCopyCapTests (agc_address_copy_cap, agc_address_copy_cap_remembered) now runs with 0, 1 and 2 frame notes in one process (the notes accumulate, so the third run starts with one frame already ended and adds two): with no frame history the cap retry is served as on main instead of being refused and aborting.

  • importEvictionFramesTests also checks that ending a frame with no import change leaves the imports epoch unchanged.

  • agc_driver_eop_interrupts checks that a flip packet and a CPU flip from a thread that never submitted queue 0 each end a host import frame.

  • Existing tests whose setup assumed the old 256-lookup rule now advance frames in their setup (importAtMapOverBudgetTests, importCoverageHintBudgetTests, failedImportJoinProbeBudgetTests, evictingRefusalMemoryTests, evictingRefusalAgingTests); their assertions are unchanged.

  • Linux, Intel i9-14900KF, NVIDIA GeForce RTX 4090: ctest -R 'agc_address_copy_cap|agc_driver_graphics_maps_fallback|agc_driver_eop_interrupts|public_headers': 69 of 69 passed, 0 failed, 0 not run.

  • Not run: Windows; a game run; a measured before/after of the re-import thrash (the shutdown host imports made/refused counts would show it); the Windows lane of the new checks.

  • Mutant check of the new test: with the frame protection removed (evictable() back to "not the latest use"), importEvictionFramesTests fails with "a range over the budget evicted an import used in the same frame (frame 0)"; unmutated it passes.

  • Mutant checks, each failing as intended: fallback disabled (both cap tests abort); frame note removed from the flip packet path or from the CPU-flip path (agc_driver_eop_interrupts fails); epoch bump added back to a frame end (agc_driver_graphics_maps_fallback fails); the frame counter removed from the refusal memory (agc_driver_graphics_maps_fallback fails).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5014131823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11357). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-26T08:10:29Z. --- ## Summary Host imports used in the current or the previous frame are no longer evicted for another import. An import was evictable 256 lookups after its last use. A frame makes thousands of lookups, so when the imports a frame uses do not all fit the budget, each new one evicts another of the same frame, and (reasoned from the 256-lookup rule, not measured here) the set is imported again every frame. A frame now ends at a flip packet or a CPU flip (`NoteHostImportFrame`), and only imports not used in the current or the previous frame are evicted; what does not fit is refused and copied, as below the budget. A frame boundary also expires the remembered evicting refusals; a remembered refusal also ends when a build holding an import two frames old raises its floor. `ProtectedUses` and the use-count horizon it fed remain only for the stretch before two frames have ended; once frames exist the frame rule decides. Until two frames have ended, imports age by lookups exactly as on main (so a loading stretch before the first flips behaves as before); after that, without flips (compute-only work) no frame ends and nothing more becomes evictable, so imports that do not fit are copied instead of evicting by recency. A frame end moves its own counter, used only by the remembered-refusal memory; it does not move the imports epoch, so the address-space cache survives a flip with no import change. The debt entry says so. ## Tests - New `importEvictionFramesTests`: three ranges under a budget for two, each used by its own build every frame with more lookups than a frame's worth of imports between uses; the first two keep their imports, the third is refused every frame, and a range unused for two frames is evicted. - `RunAddressCopyCapTests` (`agc_address_copy_cap`, `agc_address_copy_cap_remembered`) now runs with 0, 1 and 2 frame notes in one process (the notes accumulate, so the third run starts with one frame already ended and adds two): with no frame history the cap retry is served as on main instead of being refused and aborting. - `importEvictionFramesTests` also checks that ending a frame with no import change leaves the imports epoch unchanged. - `agc_driver_eop_interrupts` checks that a flip packet and a CPU flip from a thread that never submitted queue 0 each end a host import frame. - Existing tests whose setup assumed the old 256-lookup rule now advance frames in their setup (`importAtMapOverBudgetTests`, `importCoverageHintBudgetTests`, `failedImportJoinProbeBudgetTests`, `evictingRefusalMemoryTests`, `evictingRefusalAgingTests`); their assertions are unchanged. - Linux, Intel i9-14900KF, NVIDIA GeForce RTX 4090: `ctest -R 'agc_address_copy_cap|agc_driver_graphics_maps_fallback|agc_driver_eop_interrupts|public_headers'`: 69 of 69 passed, 0 failed, 0 not run. - Not run: Windows; a game run; a measured before/after of the re-import thrash (the shutdown `host imports` made/refused counts would show it); the Windows lane of the new checks. - Mutant check of the new test: with the frame protection removed (`evictable()` back to "not the latest use"), `importEvictionFramesTests` fails with "a range over the budget evicted an import used in the same frame (frame 0)"; unmutated it passes. - Mutant checks, each failing as intended: fallback disabled (both cap tests abort); frame note removed from the flip packet path or from the CPU-flip path (`agc_driver_eop_interrupts` fails); epoch bump added back to a frame end (`agc_driver_graphics_maps_fallback` fails); the frame counter removed from the refusal memory (`agc_driver_graphics_maps_fallback` fails). AI-assisted: yes
MarcZX10 commented 2026-10-26 08:16:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T08:16:41Z.

Review: CHANGES_REQUESTED


I reviewed exact head 9e7edf6e0ca53ac01b0067e1e2ba27dd4928d725. The frame-floor policy and regression description are coherent, and the author reports the focused graphics tests and mutant check passing. I am requesting changes for repository validation and integration items:

  • The required conventions check fails: the PR body omits the template's What, Tested, and Checklist sections. Please fill those sections in the repository template format and rerun the check.
  • The same check flags the new docs/dev/debt/libSceAgcDriver.md entry at 4,108 characters, over the 1,000-character limit. Please reduce it to the actual unverified behavior/gap and preserve the other debt entries.
  • Current main is 204c6747d0a1cbaf932def3dea0778810cc3935e; this branch is 1 commit ahead and 46 behind. The merge preview is clean, but main added a separate host-import debt entry since this branch's base. Please rebase and retain both entries, then rerun conventions and the focused graphics/public-header tests on the resulting head.

The CI product jobs are skipped by path policy; I have not independently run the reported Linux graphics tests or a game workload. The author also notes the CPU-flip boundary path lacks a unit test, so please include coverage for that call path if it can be driven by the existing test harness.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5649089665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11357#pullrequestreview-5649089665). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T08:16:41Z. **Review:** CHANGES_REQUESTED --- I reviewed exact head `9e7edf6e0ca53ac01b0067e1e2ba27dd4928d725`. The frame-floor policy and regression description are coherent, and the author reports the focused graphics tests and mutant check passing. I am requesting changes for repository validation and integration items: - The required `conventions` check fails: the PR body omits the template's `What`, `Tested`, and `Checklist` sections. Please fill those sections in the repository template format and rerun the check. - The same check flags the new `docs/dev/debt/libSceAgcDriver.md` entry at 4,108 characters, over the 1,000-character limit. Please reduce it to the actual unverified behavior/gap and preserve the other debt entries. - Current main is `204c6747d0a1cbaf932def3dea0778810cc3935e`; this branch is 1 commit ahead and 46 behind. The merge preview is clean, but main added a separate host-import debt entry since this branch's base. Please rebase and retain both entries, then rerun conventions and the focused graphics/public-header tests on the resulting head. The CI product jobs are skipped by path policy; I have not independently run the reported Linux graphics tests or a game workload. The author also notes the CPU-flip boundary path lacks a unit test, so please include coverage for that call path if it can be driven by the existing test harness.
MarcZX10 commented 2026-10-26 09:46:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T09:46:52Z.

Review: CHANGES_REQUESTED


Follow-up on exact current head 9e7edf6e0ca53ac01b0067e1e2ba27dd4928d725. The Windows comparison reported by ycbuzi is a concrete regression: agc_address_copy_cap and agc_address_copy_cap_remembered pass on current main 4e43321bd6 and abort on this head with the address-copy-cap message. The report says the other 33 selected graphics tests, including the new frame-eviction test, pass on three GPUs.

The frame-based eviction policy explains why the existing address-copy-cap fixtures now hit the fallback copy path: RunAddressCopyCapTests exercises 300 lookups but never calls NoteHostImportFrame, so its idle import is never two frames old and cannot be evicted. Please update these fixtures to model the required frame boundaries and preserve their intended assertions, or adjust the policy if these are valid no-flip workloads; then rerun both tests on Windows and the focused graphics tests on Linux. Please do not suppress the cap failure or weaken the new same-frame protection.

The hosted conventions check still fails on this head, and the PR body/debt entry issues from my earlier review remain to be resolved. Product jobs are skipped by path policy. I did not independently reproduce the Windows result locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5650059263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11357#pullrequestreview-5650059263). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T09:46:52Z. **Review:** CHANGES_REQUESTED --- Follow-up on exact current head `9e7edf6e0ca53ac01b0067e1e2ba27dd4928d725`. The Windows comparison reported by ycbuzi is a concrete regression: `agc_address_copy_cap` and `agc_address_copy_cap_remembered` pass on current `main` `4e43321bd6` and abort on this head with the address-copy-cap message. The report says the other 33 selected graphics tests, including the new frame-eviction test, pass on three GPUs. The frame-based eviction policy explains why the existing address-copy-cap fixtures now hit the fallback copy path: `RunAddressCopyCapTests` exercises 300 lookups but never calls `NoteHostImportFrame`, so its idle import is never two frames old and cannot be evicted. Please update these fixtures to model the required frame boundaries and preserve their intended assertions, or adjust the policy if these are valid no-flip workloads; then rerun both tests on Windows and the focused graphics tests on Linux. Please do not suppress the cap failure or weaken the new same-frame protection. The hosted `conventions` check still fails on this head, and the PR body/debt entry issues from my earlier review remain to be resolved. Product jobs are skipped by path policy. I did not independently reproduce the Windows result locally.
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!11357
No description provided.