watch: the journal's lock let go across the kernel's asking (VICTORY_JOURNAL_UNLOCKED=1), and what it waits for on the frame line #1099
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1102"
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 fxceless/victory-fork. Originally posted by alexis27yt on 2026-11-25T19:29:48Z.
The write-watch journal (
crate::watch) held its lock across the kernel's asking (GetWriteWatchwith reset). An asking over big memory takes milliseconds, and every other answer of the journal waited for it, including those the journal gives alone (ranges asked ahead,asked). The queues prepare their submissions each on its own thread (HostQueue::submitlocks per queue), so one queue's asking holds up another's.Two parts
1. On the frame line, always on (no switch):
journal: N askings X ms (Y with the lock held), Z ms waiting for the lock, W for other askings to land. The time waited is only measured when the lock is taken (atry_lockfirst, so the uncontended case adds nothing). This tells, from any run in the world, whether the wait matters in game, which I can't measure myself.2.
VICTORY_JOURNAL_UNLOCKED=1(off by default):writesasks the kernel with the lock let go, holding a ticket instead.ask_ahead,ask_once) and view memory (the guards) are as they were. Their kernel time shows on the line as "with the lock held", so the line also says whether those are worth the same treatment.Tests (i5-12400F, Windows 11)
journal_tests::no_write_is_lost_with_the_lock_held_or_let_go: 2 writers, 5 askers over overlapping ranges (one asks ahead and answers from the journal), 1.5 s with the lock held and 1.5 s let go. A write that began after an asker's answer and ended before its next asking must show in that next answer at a higher number. Passes both ways, with the rest ofwatch::.journal_tests::what_a_small_asking_waits_for_beside_a_big_one(ignored, a measurement): a 4-page asking every 200 µs while another thread asks about 1 GB with a tenth of it written. Two rounds:This is synthetic. What it is worth in a frame depends on how often two queues' preparing overlaps, which is what part 1 shows. No frame-rate claim: I can't run the title.
🤖 Generated with Claude Code
cargo test --workspaceon 4e17478 — 496 passed, 0 failed #117Imported from fxceless/victory-fork. Originally posted by rafaconvaitis on 2026-11-25T22:33:01Z.
Native RTX 4070 (616.64), Ryzen 9 5900X, Series S, pinned Flamingo 63d976b. I profiled the fixed view from the cell after a verified reload and camera inputs. Parallel shadow refresh stayed off. The 90-second window contains 664 presents at 7.709 effective FPS and 85 complete detail samples.
Median shadow updates cost 35.37 ms per frame. Within that work, calls to watch::writes took 17.23 ms, stale-range reads 14.41 ms, the oldest-stamp scan 0.78 ms, stale-page bookkeeping 0.63 ms, and pending-range collection 0.38 ms. Whole-range reads were zero in this scene. Ask-ahead outside shadow updates cost 0.21 ms, and GPU write registration 0.74 ms. The last two metrics measure their own work and exclude a pending refresh flushed ahead of them.
The 17.23 ms is inclusive call time. This trace does not attribute it to journal contention, kernel calls, or guard handling individually. It gives a native reference for the lock and kernel timing proposed here.
Imported from fxceless/victory-fork. Originally posted by rafaconvaitis on 2026-11-25T23:07:47Z.
I followed up with an opt-in instrumented native D3D12 Series S run on an RTX 4070, pinned to Flamingo
63d976b, from the same v3 prison checkpoint in a fixed view. The 90 s capture had 616 presents and 83 write-watch detail samples. These values are per-report medians, with thewritestime included in the shadow update.watch::writes: 16.24 ms.writes: guard handling 9.55 ms, view lookup 2.33 ms, publication 2.75 ms, ahead answers 0.90 ms.try_lockWouldBlock: 0.00 ms (at displayed precision). Time in the directGetWriteWatchcall: 0.00 ms (same precision).This is a single native
VIEW_SETscene. The measurements point to guard handling for this scene and bound the benefit of unlocking only around the directGetWriteWatchcall here. I did not test the PR patch itself in this follow-up.Imported from fxceless/victory-fork. Originally posted by slauko on 2026-11-26T15:39:48Z.
A port to a Linux/Wine line (RTX 3080 Ti, vkd3d-proton
ec20719, uiliannn's base), with a warning first: it hung the title here.What I ported is your core, without the tickets:
writesdrops the journal's lock beforeGetWriteWatch, askings are made one at a time behind their own mutex (this line has one submit thread, no second queue), the answer goes into a thread-local buffer, and the journal is taken again to insert. Builds, clippy clean, and thenm61: the title went into its shader translation and never came back — no frame line for three minutes, process and wineserver alive, log ending onmwait: thread 468 waited 0.6 ms for the value at 0x11e6950. Reverted; the tree is back on the locked version.So this is a "works on my machine" data point in reverse — it may be my simplification (no tickets, so an asking and an insert are not atomic together), or the lock order with the guards' lock, which
writestakes behind the journal's lock when a range has to be guarded. I have not investigated further; your version keeps the lock in the default path and I would not flip it on this stack without the tickets.The numbers that say how much there is to win here, on a cell frame of ~5,000 draws:
writescallsThe kernel's own time inside the calls is 11.5–15.9 ms of that 40; the rest was the journal's range query and its answer, per call. With ~35,000 calls a frame, the per-call cost dominates long before any lock wait does — so on a line with one submit thread the win of letting the lock go is bounded by 16 ms, and the merge above was worth 34.
Imported from fxceless/victory-fork. Originally posted by slauko on 2026-11-26T17:05:08Z.
A correction to my numbers above, before anyone ports the merge because of them: it holds the title on its prologue card.
writescalls, 5.9-6.4 ms asking and preparing 57-63 ms were measured on a prologue frame, not in the cell.m66-m79): the title sits on the prologue's card at 3,000-3,100 draws, 121-137 ms, and never goes on.m76: 4,976 draws, 209.8-214.8 ms); sorted, in recording order and capped at 4 MiB all do not (m77,m78), andVICTORY_REFRESH_SCAN=0does not either (m79).m80, 201.4-205.1, 4,968-5,000 draws), the asking 34.3-34.6 ms at ~34,000 calls.So the call count is still the lever (34,000 calls, 34 ms of asking), but merging the ranges changes something the intro's transition needs and is not a safe port as it stands. The other reading stands: the kernel's own time inside those calls is 11.5-15.9 ms, so letting the journal's lock go is bounded well below the count.
Imported from fxceless/victory-fork. Originally posted by slauko on 2026-11-26T18:03:28Z.
The follow-up I promised, and it settles the shape: taking the asking out of the per-range path works on the clock and breaks the picture.
What I built (Linux/Wine, RTX 3080 Ti, vkd3d-proton
ec20719): oneGetWriteWatchper copy for everything the submission refreshes of it, taken after the settle, and every range'supdateserved from that answer — the order of the updates unchanged, the copies still per page.m80)m87), 200.3 ms (m88)m87looked clean (no Xid, picture intact).m88, same build, is visibly broken: floating polygons, garbage geometry, black clipping on the character. That is the failure the shape invites — the answer is taken before the lists run, and pages the title writes after that asking are gone for this submission.So: reverted (commit
0360aad5on my line), and the asking stays per range here. Four shapes of this lever are now measured and rejected on this stack: merging touching ranges (34 ms of asking saved, keeps the title on its prologue card), one asking per flush (211.7 ms), one per copy per submission with a widened span (Xid in the window, inconclusive), and this one (fast, wrong picture). The 34 ms of asking are not recoverable by moving the asking out of the range.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.