Repository navigation
Conversation
…_OUTSIDE, off) `Tracked::take`/`taken` hold `watch::GUARDS` while `protect_noting` runs VirtualProtect over every run they take, and the title's write faults queue behind that lock (Marvisak#3425). With VICTORY_GUARD_OUTSIDE=1 a take only notes its runs guarded under the lock (`Guards::arming`) and changes their protection after letting go of it (`Arming::finish`), before its caller copies them. What a take answers stays the same: - another take of a page being armed waits for it (condvar `ARMED`), or it could copy before the guard stands and miss a write landing after; - runs with pages shown at another mapping (`alias_of`) stay under the lock, guarded with their other mappings; `title_memory_aliased` waits for armed pages before linking them; - a page opened while armed (fault, `writing`, remap) is noted disturbed and made writable again once the take is done; the fault handler lets a write to such a page through; - a page that cannot be made read-only ends as under the lock: taken as zeros if nothing is mapped, else still changed, with its saved bytes. Off by default. Tests: `refreshes_under_writes_lose_nothing` (fails if the wait or the alias check is removed), `armed_pages_opened_or_unmapped_end_as _under_the_lock`, and the benchmark `guard_contention` (#[ignore]). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@KainanP I'll do once my agents are done, current queue ends in ~3 hours from now. Since the game needs a bunch of VRAM, I can't run the game twice for now :/ A bit off-topic but I've spawned 4 other agents for performance analysis regarding the frametime. We went from ~900ms to ~170ms this night, so chasing this is currently my focus. As I said, once the queue ends I'll start the A/B run. |
|
I took the Arc B580 half of the A/B. No verdict yet, and I would not want you to read a number from what I have. What works now: I can drive the title into the prison yard unattended (a click on the PLAYER label plus Enter; its first screen is mouse-driven, which is what defeated my earlier menu-only captures). Tree: What happened: three of four runs ended with the device removed (
The Why I am not just re-running until it works: each attempt costs 4 minutes and one in three dies on #2671's fault, so getting a matched pair is luck, and I have already burned several. Two options, your call: (a) I keep grinding until I land a paired off/on where both survive — honest but slow; (b) @neonbyte1's 5090/Wine setup is stable and already queued for this, and I contribute the harness ( One thing from the same session that is worth your attention, since it is adjacent: your contention finding on #3356 ( Synthetic tests only in the tree; the runs are my own dump. Machine: Windows 11 x64, Ryzen 5 5600, 32 GB, Arc B580 12 GB. |
|
Thanks @borosf, and agreed: with the off arm dying before the yard there's no matched pair, so no number should be read from it. The one thing I'd take from your on-run is that the AI use: Claude Code (Claude Opus 5.5). |
|
Laptop numbers, head a73feeb: Windows 11, Ryzen 7 8845HS (8C/16T), toolchain 1.98.1. Stability:
9460 runs made read-only outside the lock, 0 kept under it. So here the lock wait drops by about a quarter and the worst writes get shorter, but total time in writes is slightly up, there are more slow writes, and the refresh is ~20% slower (it now waits ~5 ms). On this 8-core laptop the net effect looks neutral to slightly negative; one benchmark run, so treat it as one data point. AI-assisted (Claude). |
Refs #3425.
What this does
Tracked::takeandTracked::takenholdwatch::GUARDSwhileprotect_notingcallsVirtualProtecton every run they take. The write-fault handler needs the same lock. #3425 measures title threads waiting about 52 ms/frame in the handler behind it (RTX 5090/Wine), and borosf's Arc B580 numbers there show 76 ms/frame. I found no open PR that moves the protection change itself out of the lock. #3343 and #2849 batch the unprotect/protect calls, #3035 moves the saved-bytes read, and #3455 turnsGUARDSinto an RwLock (the protect still runs under the write lock).With
VICTORY_GUARD_OUTSIDE=1, a take notes its runs as guarded under the lock (Guards::arming). It changes their protection after releasing the lock (Arming::finish) and before its caller copies them. Off by default: without the variable the code path is the same as before, apart from anis_empty()check.This ports the idea from our fork's fxceless/victory-fork#1315. The code there doesn't map onto this one (the fork guards 64 KiB blocks with a journal, while VIctory has
busyandalias_of), so this is a rewrite, not a cherry-pick.Why the answers stay the same
ARMED). Otherwise it could count the page as guarded, copy it, and miss a write that lands before the guard is in place.alias_of) are guarded under the lock along with their other mappings, as before.title_memory_aliasedwaits for armed pages before linking them.writingor a remap opens a page while it is being armed, the page is marked changed as before and noted asdisturbed.finishthen makes it writable again. A stale fault on such a page (the thread faulted before the opening and retries afterfinish's change) is let through by the handler.Tests (CPU only,
watch.rs)refreshes_under_writes_lose_nothing: five copies (two overlapping copies of a write-watched pool, plus copies of both mappings of twin views) are refreshed together on separate threads while 4 writers write. It checks that every word written before a refresh is in every copy covering it, and that a quiet refresh afterwards leaves each copy equal to title memory. A test-only spin before the out-of-lock protect widens the window a preempted take would leave.alias_ofcheck is removed (5/5 runs, by round 7, with "copy 2 lost a write").disturbedbranch the process crashes with an access violation.armed_pages_opened_or_unmapped_end_as_under_the_lockguard_contention(#[ignore], benchmark):cargo test -p victory-gpu --release --lib guard_contention -- --ignored --nocapture, with sizes set byBENCH_*variables (see its doc).victory-gpu --libsuite also passes withVICTORY_GUARD_OUTSIDE=1: WARP with--features diagnostics, 248/248. On an RTX 4060 Laptop, the only failures are the two that also fail onmainthere (the 1M view-heap cap:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), plus a timing flake indescriptor::hostthat shows up in both modes.-D warningspasses both default and--all-features, and xtask policy passes.Measurements (honest version: no win in the synthetic)
guard_contentionruns on a 256 MB write-watched pool split into 32-page copies. Before each refresh 1,400 pages are written, then writers keep writing random words every 20 µs during the refresh. Off and on alternate within one process, 31 rounds, medians. Machine: 24 threads, about 11–40 % foreign load (another build running).GUARDSoff → onVirtualProtect(open) under the lock. This PR doesn't touch that path.This matches what we saw in the fork. There, on a 5080, guard waits went from 23 to 0.5 ms with no change in frame time (fxceless/victory-fork#1379). The synthetic doesn't model the title's real write pattern, though, and #3425's profile puts about 49 ms/frame of
GUARDShold time on the takes. So the only real test is in-game, which is why this is a draft and off by default.A/B request. @neonbyte1 (5090/Wine) and @borosf (Arc B580): could you run the prison-yard scene with and without
VICTORY_GUARD_OUTSIDE=1, with thediagnosticsbuild soheld_times,GuardWaitUs,HandlerUsandProtectUsare in the log? Frame time is what decides it. If it doesn't move, I'll close this.AI use: written with Claude Code (Claude Opus 5.5): port design, implementation, tests, mutation checks and benchmark runs, all run on KainanP's machine.
🤖 Generated with Claude Code