test: bench the guard lock between title write faults and askings #594
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/594"
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 LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-29T11:06:35Z.
What
A test-only, ignored benchmark in the VIctory copy:
watch::many_askers_tests::guard_contention(third_party/victory/crates/victory-gpu/src/watch.rs). No behaviour change.The VIctory copy's view memory is asked about range by range, the way a submission's refreshes guard what they take. Meanwhile title threads write the same memory, so each first write to a guarded block is a fault that opens it. The bench prints how long the askings take, how much time the writers spend in their writes (the fault handler, including its wait for the guards' lock), how many writes were slow, and how many faults went under the shared lock. It runs once with renderer port #6 off and once with it on (
port_guard).Knobs:
BENCH_PAGES,BENCH_SPAN,BENCH_DIRTY,BENCH_WRITERS,BENCH_GAP_US,BENCH_ROUNDS,BENCH_ASKERS,BENCH_REST_US. It ends with oneguard_contention:key=value line per port, for scripts.Why
The plan was to move the fault handler's own
VirtualProtectout of theGUARDSlock: on the VIctory and fork bases, that lock showed 50-76 ms of title-thread wait. On this base, renderer port #6 (VICTORY_PORT_GUARD=1, off by default) already does that. Faults takeGUARDSshared plus their block's claim (BUSY), so the fault'sVirtualProtectruns outside the exclusive lock, and theno_write_*_with_port_6tests cover it. A simpler split for the default path is not safe without those claims. If the lock is released beforeVirtualProtect, a refresh can take it in between and guard the block. The fault's latePAGE_READWRITEthen leaves the block writable whileprotectedsays it is clean, and writes are lost. So I did not open a fix PR. This bench is what decided it.Measured (CPU only, quiet laptop, 3 runs each, medians of 15 rounds)
VirtualProtectalone: 1/2/4/8 threads, each on its own 64 KiB blocks, give 647/663/552/446 RW↔RO pairs per ms in aggregate. Windows serialises it inside a process.guard_contention,BENCH_PAGES=4096 BENCH_DIRTY=1400, port #6 off → on:With the fault's
VirtualProtectoutside the exclusive lock, the fault's lock wait drops to almost nothing. The writers' total time per ms of asking stays the same, though, and the askings get 45-75 % slower once several threads ask at once. The wait moves into the kernel. Only an in-game A/B ofVICTORY_PORT_GUARD=1could show more. The bench keeps the question answerable on later changes towatch.rs.Tests
cargo test -p victory-gpu --release --lib watch: 52 passed (2 ignored, this bench among them).cargo xtask policy: ok.ANYXBOXX_REQUIRE_RUNTIME=1 python -m pytest -n auto: 1983 passed.AI use: written with Claude Code (Claude Opus 5.5), which also ran the measurements on my machine.
🤖 Generated with Claude Code
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.