Host retirement: 64 cache-line-aligned shards with lock-free watermark skip (VICTORY_LOCK_TRIM) #433
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/433"
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 readmet3xt-lab/foxhound. Originally posted by Pototoooo on 2026-12-02T09:35:18Z.
Summary
Completes RFC #413 patch 09 (part 2, MIT-0) after
618da3c(VICTORY_LOCK_TRIMinwatch.rs) andrelease_dynamic_batchindescriptor.rs:RETIRED,retire,retire_resource,retire_resources,bury,bury_lag,bury_timed) out ofcrates/victory-gpu/src/host.rsintocrates/victory-gpu/src/host/retire.rs(also reducinghost.rsby ~10.5 KiB).RETIRED: Mutex<VecDeque<(u64, Retired)>>with 64 cache-line-aligned (#[repr(align(64))]) per-thread shards (Shard) so concurrent thin-recording, staging, descriptor, and submission threads do not contend or false-share when retiring resources.AtomicU64watermark updated under the shard lock on push-into-empty and on every drain inbury(), allowingbury()to skip empty or unready shards without taking any lock (VICTORY_LOCK_TRIM=0disables the watermark skip and checks every shard under its lock, matchingwatch.rs).Invariant check
drain_up_to(finished)drains strictly from the front (take_while(|(at, _)| *at <= finished)), so a shard can yield items if and only if its queue is non-empty andfront.0 <= finished. Becauseoldestis updated toq.front().map_or(u64::MAX, |(at, _)| *at)undershard.queue's lock on push-into-empty and after every drain,oldest == u64::MAX || oldest > finishedskips locking if and only iftake_whilewould drain zero items.Verification
host::retire::tests:shard_watermark_tracks_front_through_pushes_and_drains(empty, ordered push, overtaking push, partial drain, full drain)shard_alignment_prevents_false_sharingbury_drains_across_multiple_threads_and_shards(8 concurrent producer threads across shards + lag boundary check + async drop)cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-gpu -p victory-hle -p victory-core -p victory-pipeline -p victory-loader --locked --lib: all passing (victory-gpu622,victory-hle196,victory-loader60,victory-core13,victory-pipeline7; 0 failed)xtaskasset-policy check passes onhost/retire.rs(17,434bytes);host.rsshrinks from717,220to706,735bytes (pre-existing size over the 640 KiB limit onmainis unrelated).After procotos-art's RFC #413 patch 09, part 2 (MIT-0).
Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T16:51:03Z.
Good refactor — extracting retirement into its own module makes the code much more navigable, and the per-shard watermark skip is the right pattern (same philosophy as our summary bitmap in #472 — check a cheap atomic before grabbing the lock).
The
#[repr(align(64))]on each shard prevents false sharing, which is important sincebury()iterates all 64 on the submitting thread. No conflict with our journal sharding or barriers work — different data structures, different files.One thought: the watermark
front_fenceskip meansbury()only locks shards whose front item might be ready. For the common case where GPU is 2-3 frames ahead, most shards will be skipped — nice.Imported from readmet3xt-lab/foxhound. Originally posted by Pototoooo on 2026-12-03T03:09:38Z.
Thanks for taking a look, @GValdezN! Agreed — the
front_fenceatomic watermark keepsbury()lock-free for shards whose front submission isn't ready yet, and isolating retirement intohost/retire.rskeeps it cleanly decoupled from the journal and barrier paths.Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-03T03:44:41Z.
Replay-bench measurement: the earlier ~3% slowdown did not repeat; no measurable difference on v0.8.3.3
Measured: PR head
4c227c3merged onto release v0.8.3.3 (same code as main7dbcdcb), 4 measured runs in two separate jobs (each job after a warm-up run that is not counted), against 8 runs of v0.8.3.3 without the PR, same route (~6.5 min). The PR's default (VICTORY_LOCK_TRIMnot set) was used.The first job's two runs were both below the slowest release run (36.15 fps); the repeat job's two runs are inside the release's range. Mean over all 4 PR runs: 36.01 fps vs 36.60 (-1.6%), with 2 of 4 runs inside the release range. That is not enough to call a slowdown, so: no measurable difference on this route. The first job's lower numbers remain unexplained.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
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.