perf(loader): patch mwaitx/clwb in-place to NOP and accelerate clzero loops #29
No reviewers
Labels
No labels
accessibility
bench-bm-v1
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/PastiiJay--klbf-lab!29
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-29"
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?
@Vladimir-Human on GitHub · 2026-11-25 18:03 UTC · original
Vladimir-Human:perf/klbf-intel-mwaitx-clzero→beta· +1913 −303 · 3 files · 2 commits · openAI-assisted PR.
Summary
Eliminates repeated
#UDVEH faults from console synchronizationmwaitx(0F 01 FB) /monitorx(0F 01 FA) /clwbwaits and tightensclzero(0F 01 FC) cache-line zeroing incrates/victory-loader:mwaitx/monitorx/clwbNOP patching (console_insn.rs,console_insn_decode.rs):PATCH_LOCK, replaces only the single opcode byte (0x01/0xAE -> 0x1F, turningmonitorx/mwaitx/clwbinto multi-byte0F 1FNOPs cleanly without modifying surrounding instruction boundaries), bracketsVirtualProtect(RX -> RWX -> original protection), flushes the instruction cache (FlushInstructionCache), and retries execution at the exact sameRiponce (PatchedInsn) so all subsequent waits incur 0 faults instead of taking a#UDtrap per spin iteration.p66Clwb/PatchedInsndecode arms withp66 && rep == 0so66 F2/F3#UD sequences are never rewritten.VICTORY_PATCH_WAIT=0opt-out cleanly.ClzeroLoopemulation & memory-protection hardening (console_insn.rs,console_insn_decode.rs,crash.rs):clzerozeroing loops directly inside the handler with checked address math (checked_add), explicit flag semantics, and fullPAGE_WRITECOPY/PAGE_EXECUTE_WRITECOPYsupport (m.Protect & 0xFF) while rejectingPAGE_NOACCESSandPAGE_GUARDpages cleanly without staleWRITABLEcaching.console_insn.rs):0x8000_0001:ECX[29](monitorx) and0x8000_0008:EBX[0](clzero) detection so native-fault tests fall back cleanly to direct emulation checks on AMD CPUs that supportMONITORX/CLZEROnatively.Verification (commit
918d5449,betabasec71c7d6)cargo clippy -p victory-loader --all-targets --locked -- -D warnings: 0 warnings (default &--all-features)cargo test -p victory-loader --locked: 37 passed, 0 failed, 1 ignored (unit) + 2/2 (load_probe) + 1/1 (title_dlls) = 40/40cargo test -p victory-loader --all-features --locked: 38 passed, 0 failed, 1 ignored (unit) + 2/2 + 1/1 = 41/41--releasebench_wait_patch_before_vs_after(i5-13400F):BEFORE_UNPATCHED 165.64 ms (100,000 faults)->AFTER_PATCHED 57.20 us (2 faults)(~2,896x faster)git merge-tree --write-treeclean againstklbf-upstream/beta(c71c7d6) and PRs#15.@PastiiJay on GitHub · 2026-11-25 18:38 UTC · original
Thanks a lot @Vladimir-Human! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
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.