Patch immediate-form SSE4a (insertq/extrq) in-place and reduce refresh-flush lock contention #367
No reviewers
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!367
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-367"
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?
@HDFreitas on GitHub · 2026-12-01 19:22 UTC · original
HDFreitas:perf/sse4a-patch-and-refresh-fastpath→main· +281 −32 · 4 files · 1 commits · closed without mergingSummary
This PR reduces CPU overhead on Intel systems and in the submitting thread's refresh flushes:
In-place native stub patching for immediate-form SSE4a (
insertq/extrq) (crates/victory-loader/src/console_insn.rs):insertq/extrqinstructions (>= 6bytes, e.g.,insertq xmm0, xmm1, 16, 16) previously raisedSTATUS_ILLEGAL_INSTRUCTIONon every execution — reaching 524,288+ kernel exceptions in ~6 minutes (~1,800–2,200 faults/s) during gameplay on an Intel i9-9900K.clzeroloop trampoline mechanism: replaces the first 5 bytes atomically viacmpxchg16bwith ajmp rel32to a small native stub in a nearby executable page (preserving all GPRs, other XMM registers, andRFLAGS, and zeroing the destination XMM's high quadword to match emulation / Zen 5).Vec<(usize, usize)>) ensures modules >2 GiB apart can still allocate a reachable stub page.VICTORY_PATCH_SSE4A(on by default; setVICTORY_PATCH_SSE4A=0to fall back to per-fault emulation).Lock-free fast path and lower journal RwLock contention in refresh flushes (
crates/victory-gpu/src/shadow.rs,watch.rs,host.rs):unfilledpage count inCopiedand a monotonicmin_taken: AtomicU64lower bound onShadowonce all pages have been copied at least once.watch::nothing_new_minsoShadow::nothing_new_incan confirm unchanged copies without lockingShadow::copiedor scanningcopied.pages.written_fastlookup window from<= 4to<= 8pages (up to 512 KiB).wide_chunksbatch size inrefresh_frontandflush_allfrom32to128, cuttingJournalRwLockread-lock acquisitions and atomic counter updates by 4x across worker threads.Measurements (Intel i9-9900K @ 5 GHz, 32 GB RAM, RTX 3060 12 GB, Windows 11, Series S 1080p + DLSS)
console_insn): dropped from 524,288 faults in 6 min to 1 single fault at startup (patched on first hit, 0 subsequent faults).preparing: dropped from 57–65 ms/frame (stock v0.8.2) to 31.7–35.3 ms/frame (refreshesdown from 14–16 ms to 10.5–12.0 ms).frame_of_refreshesmicrobenchmark:21.62 ms→21.06 msmean (all-copies submission4.69 ms→4.47 ms).Verification
cargo clippy --locked -p victory-loader -p victory-gpu --tests -- -D warnings: clean (0 warnings).cargo test --release --locked -p victory-loader console_insn: 6/6 passed, including newsse4a_immediate_becomes_native_stubtest that executes patchedinsertqandextrqinstructions natively and verifies low/high quadwords andRFLAGSpreservation.cargo test --release --locked -p victory-gpu refresh_tests: 6/6 passed.@readmet3xt-lab on GitHub · 2026-12-01 21:09 UTC · original
Thank you. The refresh half is taken. Please split out the SSE4a half as its own pull request: the console-instruction emulation has since been rewritten, so that half would need rebasing on the new code.
@HDFreitas on GitHub · 2026-12-01 21:13 UTC · original
Split out the SSE4a half into #386 as requested (happy to rebase it once the console-instruction rewrite lands on main/next). Closing this PR since the refresh half has been taken.
Pull request closed