Outdoors, refresh threads spend ~48 ms/frame waiting on the GUARDS mutex (watch::guard / publish) #8
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/readmet3xt-lab--foxhound#8
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Elsupremo20 on GitHub · 2026-11-27 14:36 UTC · original
Build: trustno1-coder/VIctory-NVIDIA at 959dcaf (foxhound base), built from source, release.
Machine: i7-13700K, RTX 4070 12 GB, 32 GB RAM, Windows 11.
play-nvidia.ps1 -Dlss off -SeriesS(Series S, 1080p).Where: prologue heist, outdoors on foot and on a bike. ~10–11 fps, ~90 ms/frame, ~70 ms "preparing", 6000–9000 draws/frame. The prison holds 15–19 fps.
What I measured
I added rdtsc phase marks (
VICTORY_THIN_PROFILE=1, logged once per second next to the thin translator line) aroundrefresh_front,shadow::update_free,watch::writes,watch::guardand the journal noting. The figures below are the sum over all refresh threads per frame (thread time, not wall time), averaged over 206 one-second samples from the outdoor stretch:So in
watch::writesmost of the time is waiting for the globalGUARDSmutex rather than doing work:guardwaits ~48 ms/frame for the lock against ~16 ms of work under it (the work is mostlyVirtualProtectplussettle).GUARDSagain.GetWriteWatchand the copying are cheap by comparison.Why it seems to happen
The refresh threads queue up behind each other on the exclusive
GUARDSlock, each holding it forVirtualProtectandsettle. Title faults already avoid the lock (VICTORY_FAULT_UNLOCKED/settle), so the contention is between the refresh threads themselves.Prior art
Belobug's "renderer port 6" (
VICTORY_PORT_GUARD, Belobug/VIctory-Belobug-AMD commit 9d723e8 and the five after it) attacks the same contention:GUARDSbecomes anRwLock, taken shared on the common path.VirtualProtectruns while holding only the claim.I tried to port it onto foxhound's
watch.rs(34 of 50 hunks applied cleanly). I stopped because it collides with foxhound's own unlocked-fault/settledesign and theopened/hot andALIASEDtracking, and I didn't want to risk missed writes. Someone who knows that design could probably take the idea (shared lock plus per-block claims,VirtualProtectoutside the exclusive section) more safely.Happy to share the profiler patch (one small
prof.rsplus marks) or run a test build.@readmet3xt-lab on GitHub · 2026-11-28 10:58 UTC · original
v0.2.0-pre.5 (https://github.com/readmet3xt-lab/foxhound/releases/tag/v0.2.0-pre.5) turns
VICTORY_FAULT_UNLOCKED=1on by default, so the game's write faults no longer take the guards' lock. On our test PC that cut the waits on the lock from 36 to 10 ms a frame (all threads together), and frame time by 2 to 3 %. Moving the protection changes themselves outside the lock is not done: in our scenes it would save little, and it risks lost writes. A measurement outdoors with pre.5 would show whether the refresh threads still wait long there.@Elsupremo20 on GitHub · 2026-11-28 17:13 UTC · original
Thanks for the reply. Here is the outdoor measurement you asked for.
Setup: trustno1-coder/VIctory-NVIDIA main at 63b902f (foxhound base), release build, i7-13700K, RTX 4070 12 GB, Series S, DLSS Quality, frame generation x2. Main street of the open world, about 2 minutes each, same spot. Run A and run B were played back to back and differ only in
VICTORY_FAULT_UNLOCKED. Both hadVICTORY_THIN_PROFILE=1, the same phase marks as in the first post. Both also had a local change of ours that reads the guards' clean/absent/held notes from atomic bit mirrors without the lock inguard's first look and inpublish(VICTORY_GUARD_PEEK=1). That is why the first lock wait reads 0.FAULT_UNLOCKED=1guard: waiting for the guards' lockguard: work under the lockupdaterefresh_frontwide (wall)Turning faults unlocked gives about 7 % shorter frames outdoors here. The wait in
guarddrops by about 28 %, and per call from 0.23 to 0.20 ms. The spot had slightly fewer draws in A, so part of the gap may be the scene. Even so, the refresh threads still wait about 47 ms a frame in total, so outdoors the lock is still the largest single item inwatch::writes. We keepVICTORY_FAULT_UNLOCKED=1on.@readmet3xt-lab on GitHub · 2026-11-29 06:15 UTC · original
Thanks for the A/B, that is the measurement I asked for.
VICTORY_FAULT_UNLOCKED=1is on by default since pre.5, so your 7 % is what everyone gets now.v0.8 also has two lock changes ported from VIctory-NVIDIA: a write-watch query now holds only its own pages instead of all memory (
VICTORY_ASK_HOLD_ALL=1restores the old way), and the check for pending card writes no longer takes the lock. Those should cut part of the 47 ms you still see inguardoutdoors, but I haven't measured outdoors on a 4070 myself.Your
VICTORY_GUARD_PEEK=1(the clean, absent and held notes read from atomic bit mirrors inguard's first look and inpublish) sounds like the next step. If you open it as a PR against foxhound, with the same before/after table, I'll review and measure it here.@BEEPITYPORT on GitHub · 2026-12-02 01:41 UTC · original · edited 2026-12-02 01:43 UTC
On the point above that moving protection changes out of the lock "risks lost writes": we tested exactly that with a stress test. It isn't foxhound code; it's a separate VIctory-family tree. The results may help decide how far the per-block idea can go.
Setup. A pagefile section mapped at several addresses. Writer threads store through any of the views, there is a real write-fault handler, and several "askers" seal blocks, copy them and publish them as clean. Lock-free auditors keep checking "a block published clean has a copy equal to memory". Eight rounds per design, RTX 5070 Ti Laptop host, Windows 11.
All four rules turned out to be necessary. One subtle case: a generation bumped by faults does not replace "seal, then copy". A second write to a block that is already open raises no fault, so it bumps nothing.
Scaling on the same machine.
VirtualProtect: about 3.5 million protection changes a second in total, whether 1, 2, 4 or 6 threads protect their own blocks.Related numbers, same tree, our diagnostics build.
GetWriteWatchon a section view fails with error 87, so faults are the only tracker for those pages.ReadFile/WriteFileinto or from a no-access page fail cleanly (998 / 1784). Routing the I/O through the layer's own view of the section works while the title's view stays sealed.We have not measured the frame-rate effect of the per-block design in game, so this only shows which orderings keep every write. The test is a self-contained Rust module (GPL-3.0, like the rest of the family). Glad to share it if it would help check
VICTORY_GUARD_PEEKor a per-block variant.@Elsupremo20 on GitHub · 2026-12-02 16:24 UTC · original
Thank you, this is very useful, and it lands right on our change.
The
publishside ofVICTORY_GUARD_PEEK(closed #125) is the "set, look again, take back" row of your table: it setPUBLISHEDfrom atomic mirrors of the clean/held sets and cleared it again if the block was taken or opened meanwhile. Our own stress tests never caught it. They checked that no write is lost at rest, not the window in which a block is published over a write its journal does not hold.We have reworked it along the lines of your design (not pushed yet, it will come with the new pull request on the current main):
guardseals the blocks it made clean once they are read-only and noted;publishsets the published flag by a compare-exchange on the generation the block was sealed under, andpublished()reads the words too.The read-only first look in
guardkeeps reading bit mirrors, and the protection changes stay serialized by the kernel, as you measured.To check it we added an auditor test in the spirit of yours: while askers guard, publish and get opened again (faults with and without the lock, our own writes, one and three views), auditors check that no block found published is writable with its word unchanged. With a test-only pause that widens the publishing window, the old ordering is caught within seconds (120 to 164 blocks per run), and the new one passes every round (12 repeated runs, plus the whole
victory-gpusuite).Yes, please share your test module. A gist, a repository or an attachment here all work. We would run it against this variant too, and post the results here and in the pull request, with credit to you.
@Elsupremo20 on GitHub · 2026-12-02 17:42 UTC · original
Results of the reworked
VICTORY_GUARD_PEEK(per-block generation, as described above) on the current main, and why we are not opening the pull request for now.Setup. foxhound main at
7dbcdcb(v0.8.3) plus the change, release build, i7-13700K, RTX 4070 12 GB, 32 GB RAM, Windows 11, Series S, frame generation x2. No title profile is installed here, so DLSS was off (the title's own upscaling) and the BCPack table file came fromVICTORY_BCPACK_TABLES. One run of 41 minutes, mostly in the city, withVICTORY_GUARD_PEEK=ab. Only 5 s lines that lie wholly inside one turn were counted (100 off, 97 on), and lines with frames over 200 ms were left out. The lock waits come from a local counter that is not part of the change.GUARDSlockGUARDSlockBy draws per frame the frame rate is the same within noise: 4,000–6,000 draws 14.1 vs 13.9 fps, 6,000–8,000 12.6 vs 12.6, 8,000–10,000 11.1 vs 10.9.
So on the current main the safe form gives fewer lock acquisitions but no measurable time or frame rate. Most of what our first measurement saved is gone already: since then faults take no lock,
guard_aheadbatches a submission's guards, andVICTORY_GUARD_HOT=50/VICTORY_STORE_BESIDEcut the protection changes. The waits left come mostly from the holders this does not touch, and the generation path costs a little of its own (a seal per block an asking makes clean, a compare-exchange per publish, per-block reads inpublished()).What still stands from this work, in case it is useful:
guard, and publishing by compare-exchange on the sealed generation;victory-gpusuite: 623 passed, clippy clean).Both are on a local branch. We can push them, or send the test on its own, if either is wanted. Otherwise we leave the switch out, and we would of course still run BEEPITYPORT's module against it if it is shared.