Repository navigation
Conversation
… their first fault A title that paces its frames with monitorx / mwaitx spins on them; on a CPU without them every one was an emulated illegal-instruction exception. Like clwb, each site is now rewritten at its first fault: monitorx to nops, mwaitx to pause + nops. The bytes go in with one atomic 8-byte compare-exchange when the instruction lies inside an aligned 8-byte word; otherwise it stays emulated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016SP4yAAy7ztGPWPR7JHKKa
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! — Devin |
luckyteagirl
left a comment
There was a problem hiding this comment.
Two source-derived concurrency points on the current head. No local build or title run. AI-assisted source review: OpenAI Codex (GPT-6; exact serving variant unavailable) and a Luna subagent.
| let mut bytes = was.to_le_bytes(); | ||
| bytes[off..off + new.len()].copy_from_slice(new); | ||
| // another thread may have rewritten it first: then it holds the same bytes already | ||
| let _ = cell.compare_exchange(was, u64::from_le_bytes(bytes), Ordering::AcqRel, Ordering::Acquire); |
There was a problem hiding this comment.
A failed compare_exchange is currently ignored, but another thread may have rewritten a different monitorx/mwaitx site in this same aligned 8-byte word. If both load the original word, one CAS wins and the other loses; the losing site remains unchanged even though rewrite_code returns true, so later visits fault again. Could this retry after a lost CAS by reloading and merging only the requested bytes? A deterministic test with two adjacent sites would cover it. This is a source-derived interleaving, not a measured title failure.
| // SAFETY: `word` is the aligned word around code the processor just fetched; it is made | ||
| // writable for the one store and given its protection back | ||
| unsafe { | ||
| if VirtualProtect(word as *const c_void, 8, PAGE_EXECUTE_READWRITE, &mut old) == 0 { |
There was a problem hiding this comment.
VirtualProtect(word, 8, ...) changes the whole containing page. Two concurrent calls on that page can save RX/RWX respectively; if the first restores RX before the second restores its saved RWX, the page stays writable and executable. SEEN is unlocked before this span. Could the protect/CAS/restore span be serialized for calls touching the same page, with a concurrent-patch test asserting the original protection afterwards? This is a source-derived interleaving, not a measured title failure.
|
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
Thanks! — Devin |
…tream xcl-dev#2618) Windows eh.rs hunks verbatim reference-only (cfg(windows)-only): rewrite_code (single atomic 8-byte store inside one aligned word, so a concurrent thread runs the old or the new instruction, never a mix), the Monitorx (nops) / Mwaitx (pause + nops) first-fault arms, and both upstream tests verbatim. Linux eh_linux.rs twin: rewrite_code via mprotect(PROT_READ|PROT_WRITE| PROT_EXEC) over the page range covering the word, restoring the previous protection read from /proc/self/maps (x86(-64) needs no cache flush: its I-cache is coherent with data writes); cross-word instructions stay emulated. Tests: code_across_an_aligned_word_is_not_rewritten verbatim, plus a mmap-backed monitorx/mwaitx rewrite test with the same byte sequences (no emulate_console_only call site exists on Linux yet, so the helper is test-only for now: one dead_code warning, like the tree's others). Failing-first: with the store disabled both Linux tests FAILED, green after; eh group 18/18 green.
Repeated monitorx and mwaitx emulation can raise tens of thousands of illegal-instruction exceptions per second on Intel CPUs. Replace each aligned site atomically with nops or pause plus nops after its first fault. Serialize page protection changes, retry word replacement after interference, preserve adjacent rewrites, restore RX protection, flush the instruction cache, and recognize exceptions already in flight at a newly rewritten site. Adapted from PR xcl-dev#2618 by Tarosul and Claude Code (Claude Opus 5.5). That PR measured a retail workload improving from 1.24 to 2-3.5 presents/s. The Windows GNU cross-target check passes; native Windows tests and smoke were unavailable here. Assisted-by: Codex (GPT-5.6-sol)
Repeated monitorx and mwaitx emulation can raise tens of thousands of illegal-instruction exceptions per second on Intel CPUs. Replace each aligned site atomically with nops or pause plus nops after its first fault. Serialize page protection changes, retry word replacement after interference, preserve adjacent rewrites, restore RX protection, flush the instruction cache, and recognize exceptions already in flight at a newly rewritten site. Adapted from PR xcl-dev#2618 by Tarosul and Claude Code (Claude Opus 5.5). That PR measured a retail workload improving from 1.24 to 2-3.5 presents/s. The Windows GNU cross-target check passes; native Windows tests and smoke were unavailable here. Assisted-by: Codex (GPT-5.6-sol)
|
The case in your "Not tested" list (an instruction across an aligned 8-byte word in a real title) happens on another build of the retail title ( What the log shows I added a local log line (not part of the PR) in the two new match arms, printing what In the title's A possible way to cover it (not tried): Numbers Same tree, same cache snapshot copied for each run, 300 s each, runs alternated (3d, 3e, 3d, 3e). Presents are counted in fixed windows after the title's first
From 30 s after entry, all four runs present about 0.23 times a second with or without the PR. At that rate this tree is bound by something other than the title's CPU pacing loop. So these runs do not show whether the rewrite helps: Tested
Not tested
AI use
|
|
Test report: in the world on an Intel CPU with an RTX 4080 16 GB. No gain here, because this machine waits for the GPU; one figure worth a look in the intro. Tested
Not tested
AI use: Claude Code (Claude Fable 5.2) ran this on the owner's machine and wrote the report. |
A title that paces its frames with
monitorx/mwaitxspins on them. On a CPU without them (Intel) every one raises an illegal-instruction exception thatehemulates, the same instruction again and again.clwbis already rewritten to nops at its first fault; this does the same for these two:monitorx→ nops,mwaitx→pause+ nops (a wait that ended at once; the title checks its own condition again, as it must after anymwaitx).Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on19aa5c2: 1426 passed, 11 failed, 47 ignored. Onmainb49be18the same run: 1425 passed, 10 failed, 47 ignored, the same 10 failures (fuzz_validate_and_gpu_0–_3, the twolink_tests,vram::tests::d32s8_targets_take_their_own_size_of_video_memoryand the threetest_title_*integration tests). The 11th,list_x::tests::a_reset_while_the_last_submit_runs_records_on_another_pc_list, passed 3 of 3 times alone.monitorx_and_mwaitx_are_rewritten_at_their_first_fault(both rewritten, rip stepped over them),code_across_an_aligned_word_is_not_rewritten.Regression run
main:
PR:
The 60 s stay in the title's menus; the two sites are rewritten in the first seconds.
Not tested
monitorx/mwaitxnatively and never reach this path.AI use
🤖 Generated with Claude Code