fix(agc): answer a collect memo hit with the generation of the last finished tracker update #6169
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6169"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mitul72 on 2026-10-15T00:10:53Z.
What
Race: a per-thread collect memo hit read the tracker generation without the tracker mutex. A walk on another thread bumps the generation before it stamps the blocks it finds written, so the hit could return a value that walk then stamps blocks with. A caller that recorded it as its verified generation then trusts those blocks in every later
UnchangedSinceand never refreshes them.The tracker now publishes the generation each time its mutex is released (
TrackerLock), after every stamp of that update is in place, and a memo hit returns the published value. CompletedMarkWrittenbumps are still seen at once; a value older than the live one only makes a check fail and refresh.Test
agc_collect_memo_generationis deterministic. It buildsGuestMemory.cppinto its own executable (Linux only, CMakeNOT WIN32) together with a fake write watch that defines the libc write-watch functions itself, so the test executable's definitions override the ones inlibc. The fake holds a walk after its generation bump, a memo hit is taken on another thread meanwhile, and the test checks that the write the walk then stamps is not trusted against the generation the hit returned. Overriding the functions is what lets the test hold a walk at an exact point, which the real write watch does not allow; on Windows the walk calls the GuestArena functions instead, hence Linux only.Tested
Linux, RX 9060 XT (RADV GFX12, local Mesa). Full
ctestpasses exceptagc_driver_tessellation, which segfaults inside RADV while linking pipeline libraries on unmodified upstream703aa8f63as well.agc_collect_memo_generationfails 5 of 5 runs with the previousGuestMemory.cppand passes 20 of 20 with the fix. It is registered for Linux only: on Windows the collect walk goes through the GuestArena functions instead of the libc write watch, and overriding those through MinGW import libraries is not verified.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T01:02:46Z.
Ran this on PR head 077fec730 (merge base
ab9a47684, which is current main).Setup: PR head checked out as-is (not rebased), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), Linux. The test is CPU-only; no GPU was used.
So on this setup the test fails without the change and passes with it.
Not checked: Windows (the PR has a _WIN32 branch), other platforms, or any title. Many open PRs also touch GuestMemory.cpp; I checked overlap only by file, not by function.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:52:30Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4.agc_collect_memo_generation(this PR's test) fails onmainplus this PR (2 of 2). It passes on the PR head as submitted (merge baseab9a47684).Most likely cause: since the merge base,
main(3b34d1fdb) added a second memo path incollectWrites, the per-epoch map (if (epochCollectMapEnabled()),GuestMemory.cpp:1191onmain). Its hit still returnstracker.generation.load(std::memory_order_relaxed)(GuestMemory.cpp:1195onmain). This PR only changes the thread memo hit (GuestMemory.cpp:1192on its head) to returntracker.stable, so the epoch-map hit still returns the generation a walk in progress later stamps a write with.Suggested fix: return
tracker.stable.load(std::memory_order_acquire)in the epoch-map hit as well. I tried that on the merge and the test passes.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-18T16:52:09Z.
Review: CHANGES_REQUESTED
Thanks for the fix and the deterministic test. It is not complete against current
main:core/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cpp:1249: the per-epoch map hit (epochCollectMapEnabled(), added tomainafter your merge base) still returnstracker.generation.load(std::memory_order_relaxed), so it has the same race. Returntracker.stable.load(std::memory_order_acquire)there too.agc_collect_memo_generationfails onmain+ this PR ("a memoized collect returned the generation a walk in progress then stamped a write with"), as @nicolasfalesy reported. Please rebase on currentmain, apply the change and confirm the test passes on the merged tree.Imported from boykopovar/AnyPS5. Originally posted by mitul72 on 2026-10-20T18:02:17Z.
Thanks @Dextroid17 and @nicolasfalesy for testing, and @adriadam10 for the review. I've been a little busy lately, but I'll update this against current
maintoday.Imported from boykopovar/AnyPS5. Originally posted by mitul72 on 2026-10-21T01:23:22Z.
@adriadam10 Rebased onto
main(d97361bd0) and applied it: the per-epoch map hit now returnstracker.stableas well.One more change was needed on the new base:
MarkWrittennow drops the tracker mutex aroundbeforeUnwatchand stamps again after relocking, so publishing on that release would hand out a generation the same update then stamps with. That release now goes throughSuspend/Resume, which don't publish; every other release still does. The test also linksPerformanceTraceThread.cppnow, like the other tests that buildGuestMemory.cpp.On the merged tree
agc_collect_memo_generationpasses, and it fails again with the epoch-map line reverted. Of theagctests, 836/839 pass; the three failures (guest_memory_lifetime,image_array_window_past_layer_limit,tessellation) fail the same way on plainmainon this machine (RX 9060 XT, RADV).