perf(loader): patch mwaitx/clwb in-place to NOP and accelerate clzero loops #29
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T18:03:27Z.
AI-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.Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T18:38:16Z.
Thanks a lot @Vladimir-Human! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T17:54:04Z.
Re-ported onto
stable-amd(v26.11.6) in #176 (https://github.com/PastiiJay/klbf-lab/pull/176).Pull request closed