watch: VICTORY_GUARD_PEEK, the guards' notes read from atomic bit mirrors (#8) #125

Closed
github-bot wants to merge 0 commits from github-bot/gh-125 into main AGit
Owner

@⁠Elsupremo20 on GitHub · 2026-11-30 15:54 UTC · original
Elsupremo20:guard-peek → main · +160 −9 · 1 files · 47 commits · closed without merging

Follow-up to #8, as suggested there: guard's first look and publish only read the guards' clean, absent and held notes, yet both took the GUARDS lock to do it. This lets them read atomic mirrors of those three sets instead, so the lock is only taken to change something.

What changes

  • Guards::clean, absent and held are made with Blocks::mirrored: every insert/remove also sets/clears a bit in a Bits (CLEAN_BITS, ABSENT_BITS, HELD_BITS). They are still only changed under the lock, with the sets.
  • With VICTORY_GUARD_PEEK=1:
    • the known-view check at the top of guard reads ABSENT_BITS (PROTECTED is read first, as before);
    • guard's first look (the "all clean, nothing beside, nothing unsettled" early return, and the list of absent-and-not-held blocks to ask Windows about) reads the bits. unsettled is checked before and after the clean bits: a fault settles by taking the clean bit, then clearing OPENING's, so a reader that sees OPENING clear and then the clean bit sees it taken;
    • publish sets PUBLISHED from the bits and then re-checks (clean/held still set, nothing beside, nothing unsettled), clearing it again if the block was taken or opened meanwhile. Blocks::remove clears the mirror bit before the caller clears PUBLISHED, so either the re-check or the remover's clear wins.
  • guard_locked's work after its first look is split out as guard_unsure (no behaviour change); both paths call it. The batched path (guard_ahead) still runs entirely under the lock.
  • Off by default. VICTORY_GUARD_PEEK=ab turns it on and off every ten seconds and logs each turn, for an A/B in one run.

Tests

  • askings_that_peek_tell_the_same: the single-thread view tests (a_write_through_another_view_is_reported_at_the_guarded_one, a_write_opens_the_view_it_goes_through, bits_go_at_every_view, ...) with peeking askings, with faults under the lock and without it.
  • no_write_is_lost_when_askings_peek: the many-askers harness (writes_to_views_are_not_lost_peeking, a peeking mask beside unlocked) with peeking on every thread and on half of them; one view and three, resting blocks, faults that take no lock, and batched guards.
  • Both new tests passed 40 repeated runs in a row; the whole victory-gpu lib suite passes (473 passed, 37 ignored), and clippy is clean.

Measurement

foxhound main at 7281175 (v0.8.2) plus this commit, release build. i7-13700K, RTX 4070 12 GB, 32 GB RAM, Windows 11, driver 610.88. Series S, DLSS Quality, frame generation x2. One run of 30 minutes of normal play in the open world with VICTORY_GUARD_PEEK=ab, so both sides saw the same places. Frame-rate lines that straddle a turn change were left out, and so were loading spikes over 200 ms.

To count the lock waits in a release build I made waited count outside diagnostics and logged WAITS per frame at each turn change (a local change, not in this PR; the same counters as the guards part of lock_waits in diagnostics builds).

per frame GUARD_PEEK off GUARD_PEEK on change
frames counted (turns) 13,597 (90) 13,908 (91)
waits for the GUARDS lock 113.2 86.9 −23 %
time waiting for the GUARDS lock 26.3 ms 23.2 ms −12 %
journal read / noted, ranges held (wait time) 8.5 / 4.2 / 1.7 ms 8.8 / 4.7 / 1.5 ms ≈
fps, median of 5 s lines 12.4 13.0 +5 %
frame time, median 80.9 ms 77.1 ms −5 %
preparing, median 47.9 ms 43.4 ms −9 %
draws per frame, mean 7,390 6,946

By draws per frame (fps, mean of 5 s lines): 2,000–6,000: 16.2 → 17.2; 6,000–8,000: 13.0 → 13.1; over 8,000: 10.9 → 11.1. The "on" half had slightly lighter scenes on average, so part of the fps gap may be the scenes; the lock counts are per frame and do not depend on that as much.

What is left of the GUARDS wait (23 ms a frame here) comes from the users of the lock this does not touch: the title's write faults that still go the locked way, guard's protect loop after its first look, and guard_ahead.

An earlier, shorter run of the same A/B without DLSS (24 minutes, no lock counter) gave preparing 68.1 → 62.5 ms (median) and fps 10.1 → 10.3, i.e. the same direction, smaller. On trustno1-coder/VIctory-NVIDIA at 63b902f (before v0.8's lock changes) the same change had cut the refresh threads' time in guard by about a fifth outdoors.

All numbers are from one PC; I'd be glad to see how it measures on yours.

🤖 Generated with Claude Code

**@⁠Elsupremo20** on GitHub · 2026-11-30 15:54 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/125) `Elsupremo20:guard-peek` → `main` · +160 −9 · 1 files · 47 commits · closed without merging Follow-up to #8, as suggested there: `guard`'s first look and `publish` only **read** the guards' `clean`, `absent` and `held` notes, yet both took the `GUARDS` lock to do it. This lets them read atomic mirrors of those three sets instead, so the lock is only taken to change something. ## What changes - `Guards::clean`, `absent` and `held` are made with `Blocks::mirrored`: every `insert`/`remove` also sets/clears a bit in a `Bits` (`CLEAN_BITS`, `ABSENT_BITS`, `HELD_BITS`). They are still only changed under the lock, with the sets. - With `VICTORY_GUARD_PEEK=1`: - the known-view check at the top of `guard` reads `ABSENT_BITS` (`PROTECTED` is read first, as before); - `guard`'s first look (the "all clean, nothing beside, nothing unsettled" early return, and the list of absent-and-not-held blocks to ask Windows about) reads the bits. `unsettled` is checked before and after the clean bits: a fault settles by taking the clean bit, then clearing `OPENING`'s, so a reader that sees `OPENING` clear and then the clean bit sees it taken; - `publish` sets `PUBLISHED` from the bits and then re-checks (clean/held still set, nothing beside, nothing unsettled), clearing it again if the block was taken or opened meanwhile. `Blocks::remove` clears the mirror bit before the caller clears `PUBLISHED`, so either the re-check or the remover's clear wins. - `guard_locked`'s work after its first look is split out as `guard_unsure` (no behaviour change); both paths call it. The batched path (`guard_ahead`) still runs entirely under the lock. - Off by default. `VICTORY_GUARD_PEEK=ab` turns it on and off every ten seconds and logs each turn, for an A/B in one run. ## Tests - `askings_that_peek_tell_the_same`: the single-thread view tests (`a_write_through_another_view_is_reported_at_the_guarded_one`, `a_write_opens_the_view_it_goes_through`, `bits_go_at_every_view`, ...) with peeking askings, with faults under the lock and without it. - `no_write_is_lost_when_askings_peek`: the many-askers harness (`writes_to_views_are_not_lost_peeking`, a `peeking` mask beside `unlocked`) with peeking on every thread and on half of them; one view and three, resting blocks, faults that take no lock, and batched guards. - Both new tests passed 40 repeated runs in a row; the whole `victory-gpu` lib suite passes (473 passed, 37 ignored), and clippy is clean. ## Measurement foxhound `main` at 7281175 (v0.8.2) plus this commit, release build. i7-13700K, RTX 4070 12 GB, 32 GB RAM, Windows 11, driver 610.88. Series S, DLSS Quality, frame generation x2. One run of 30 minutes of normal play in the open world with `VICTORY_GUARD_PEEK=ab`, so both sides saw the same places. Frame-rate lines that straddle a turn change were left out, and so were loading spikes over 200 ms. To count the lock waits in a release build I made `waited` count outside `diagnostics` and logged `WAITS` per frame at each turn change (a local change, **not** in this PR; the same counters as the `guards` part of `lock_waits` in diagnostics builds). | per frame | `GUARD_PEEK` off | `GUARD_PEEK` on | change | |---|---:|---:|---:| | frames counted (turns) | 13,597 (90) | 13,908 (91) | | | waits for the `GUARDS` lock | 113.2 | **86.9** | −23 % | | time waiting for the `GUARDS` lock | 26.3 ms | **23.2 ms** | −12 % | | journal read / noted, ranges held (wait time) | 8.5 / 4.2 / 1.7 ms | 8.8 / 4.7 / 1.5 ms | ≈ | | fps, median of 5 s lines | 12.4 | **13.0** | +5 % | | frame time, median | 80.9 ms | **77.1 ms** | −5 % | | preparing, median | 47.9 ms | **43.4 ms** | −9 % | | draws per frame, mean | 7,390 | 6,946 | | By draws per frame (fps, mean of 5 s lines): 2,000–6,000: 16.2 → 17.2; 6,000–8,000: 13.0 → 13.1; over 8,000: 10.9 → 11.1. The "on" half had slightly lighter scenes on average, so part of the fps gap may be the scenes; the lock counts are per frame and do not depend on that as much. What is left of the `GUARDS` wait (23 ms a frame here) comes from the users of the lock this does not touch: the title's write faults that still go the locked way, `guard`'s protect loop after its first look, and `guard_ahead`. An earlier, shorter run of the same A/B without DLSS (24 minutes, no lock counter) gave preparing 68.1 → 62.5 ms (median) and fps 10.1 → 10.3, i.e. the same direction, smaller. On trustno1-coder/VIctory-NVIDIA at 63b902f (before v0.8's lock changes) the same change had cut the refresh threads' time in `guard` by about a fifth outdoors. All numbers are from one PC; I'd be glad to see how it measures on yours. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
guard's first look and publish only read the guards' clean, absent and held
notes, yet both took the GUARDS lock for it. Outdoors the refresh threads
spent most of their time in guard waiting for that lock (#8).

The three sets are now mirrored in Bits (set and cleared with the sets,
under the lock). With VICTORY_GUARD_PEEK=1 the known-view check, guard's
first look and publish read the mirrors without the lock; publish re-checks
after setting PUBLISHED, so a block taken or opened meanwhile is not left
published. guard_locked's work after its first look is split out as
guard_unsure, which both paths share. Off by default; =ab turns it on and
off every ten seconds for an A/B in one run.

Tests: askings_that_peek_tell_the_same runs the single-thread view tests
with peeking askings (faults with and without the lock), and
no_write_is_lost_when_askings_peek runs the many-askers harness with
peeking on every thread or half of them (40 repeated runs, no failure).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 15:57:22 +00:00
github-bot closed this pull request 2026-12-01 01:10:27 +00:00
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 01:34 UTC · original

Thanks. On hold only for order: it is off by default, and watch.rs is changed by several PRs being tested for the next release, so this will need a rebase onto main once they land. Please add the ab comparison on the current main with the rebase.

Main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), so a follow-up has to start from the current main, or this branch be rebased onto it.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 01:34 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/125#issuecomment-7297658313) Thanks. On hold only for order: it is off by default, and `watch.rs` is changed by several PRs being tested for the next release, so this will need a rebase onto main once they land. Please add the `ab` comparison on the current main with the rebase. Main's history was rewritten on 2026-12-01 (text-only changes; every commit hash changed), so a follow-up has to start from the current main, or this branch be rebased onto it.
Author
Owner

@⁠readmet3xt-lab on GitHub · 2026-12-01 01:36 UTC · original

One more note: GitHub closed this pull request by itself when main's history was rewritten, and it cannot be reopened. That is not a rejection. The points above still apply; please open a new pull request from the current main when you have them.

**@⁠readmet3xt-lab** on GitHub · 2026-12-01 01:36 UTC · [original](https://github.com/readmet3xt-lab/foxhound/pull/125#issuecomment-7297686734) One more note: GitHub closed this pull request by itself when main's history was rewritten, and it cannot be reopened. That is not a rejection. The points above still apply; please open a new pull request from the current main when you have them.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.