Repository navigation
cpu_emulation: count each emulated site and time the #UD trap; first retail boot measurement on Intel (RT-500 follow-up, depends on #7111) - #8537
Open
AlexLopezDevelop wants to merge 8 commits into
Conversation
… desktop CPU may lack The runtime runs the Xbox Series (Zen 2) executable natively, so an instruction the host CPU lacks raises #UD where it is reached. tools/cpu_feature_scan.py streams dumpbin /disasm like inline_scan.py, maps each instruction to its CPUID feature or privilege class (AMD-only, newer-Intel-only, not on Zen 2, privileged, kernel call, host query, baseline), and splits the counts by .pdata range. docs/cpu_features.md records the 1.0.2.1 result (counts only): 19 SSE4a, 10 CLZERO and 4 MONITORX/MWAITX sites (AMD only) and 8 CLWB sites, all real code; the privileged hits are jump-table data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the first Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Q/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB) The executable uses SSE4a INSERTQ, CLZERO and MONITORX/MWAITX (AMD only) and CLWB (Intel since Ice Lake) without asking CPUID (docs/cpu_features.md). A host without one raises #UD there. src/cpu_emulation.h adds a vectored handler that recognises those encodings at the faulting RIP, does the same work on the CONTEXT and steps past the instruction; gta6rt installs it before any image code runs, after the startup trace's handler so it runs first. One [rt] line names what the host lacks, one more per instruction on first use. cpu_emulation_test checks the decoder on hand-written encodings, the bit-field helpers and apply() on a synthetic CONTEXT, then runs every form for real from an executable buffer: natively on a Zen host, through the handler on an Intel one, with the same expected values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ult; accept 66 on 0F 01 FC/FA/FB A line CLZERO cannot write now reaches the next handlers as the access violation (or guard-page violation) the instruction raises, with the write flag and the line address, instead of the #UD. The 66 prefix and segment overrides are accepted on CLZERO/MONITORX/MWAITX; F2/F3 (other instructions there, F3 0F 01 FA is MCOMMIT) and LOCK stay #UD. Points raised by SirKingg on ItsNotRexed#7055. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… xmm1[127:64]; AMD prefix forms; no SEH - INSERTQ xmm, xmm took the length and index from swapped fields. The APM (vol. 4) has the length in xmm2[69:64] and the index in xmm2[77:72]; a Ryzen 9800X3D and a Ryzen 5700X agree (TheHoracio, Mayzkl on ItsNotRexed#7111). The measured 0x0810 case is a unit check now. - INSERTQ/EXTRQ zero xmm1[127:64], as the Zen 3 measured in the same review does in all four forms. - Decode REX bytes among the legacy prefixes (a non-final REX is ignored) and accept F2/F3 on CLZERO, as Zen 3 runs them (ItsNotRexed#7055's reviews); F2/F3 stay #UD on MONITORX/MWAITX. - Check the CLZERO line's page and the instruction bytes' readability with VirtualQuery instead of catching a fault in a local __try, which clang-cl without /EHa does not cover for inline stores (venetanji on ItsNotRexed#7111). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on and xg_xs test targets) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…low-up) Every instruction the #UD handler emulates is counted against its address, with the handler's own TSC ticks, in a fixed lock-free table. gta6rt writes a `cpu_emulated` startup-trace event per new site, prints a per-site summary at a normal exit, and every N seconds with LEONIDA_CPU_EMU_STATS=N so a run that crashes still leaves its counts. cpu_emulation_test checks the table and, with --bench, prints the cost of the whole #UD round trip against a NOP loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cost cpu_features.md records the first measurement on an Intel i9-9900K: one CLWB site, 16-18 hits up to boot stop 19, about 2 us per #UD round trip. The runtime README documents the per-site summary, LEONIDA_CPU_EMU_STATS and the cpu_emulated trace event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: new RT item, #7496 (comment)
Depends on: #7111 (this branch is on its head
39b757a6d; it only adds toruntime/src/cpu_emulation.hand the files below)What and why
docs/cpu_features.mdin #7111 ends with "Not measured: which of these sites a boot reaches, and in which order." This adds the counters to answer that, and the first answer.#UDhandler (runtime/src/cpu_emulation.h): every emulated instruction is counted against its address, with the handler's own TSC ticks, in a fixed 256-entry open-addressing table filled with compare-and-swap, so the handler never allocates or takes a lock. A site that does not fit is still emulated and counted as dropped.runtime/src/main.cpp): acpu_emulatedstartup-trace event at each new site (instruction,atas module+RVA); a per-site summary on stderr at a normal exit; and withLEONIDA_CPU_EMU_STATS=Nthe same summary every N seconds while the counts change, so a run that ends in a crash or an assert keeps its counts. Nothing is printed when nothing is emulated (any Zen 2 or later host).cpu_emulation_testchecks the table (first hit reported once, hits and ticks per address, snapshot order, and the live CLWB sites on a host without CLWB). With--benchit prints the cost of one emulated instruction, the whole#UDround trip, against the same loop with a NOP; it checks nothing there, so a slow machine cannot fail it.docs/cpu_features.mdgets the measurement below,runtime/README.mdthe switch and the trace event.Measurement (counts only, nothing from the executable)
Intel Core i9-9900K (Coffee Lake: no SSE4a, CLZERO, MONITORX or CLWB), Windows 11, own 1.0.2.1 copy,
mainwith the open boot-chain PRs merged locally (stops 1-20, #7111, #7516 for the BVH builder):--bench, CLWB, 200,000 iterations)The boot stops about 4 s in, at a fatal assert right after the first device slot 41 command signature. So far the trap path costs nothing that matters, and the load-time patching from my claim is not needed for the sites a boot reaches today. The vector-code SSE4a sites are the ones to watch: at about 2 µs a trap, around 8,000 hits a frame would cost a 60 Hz frame. Anyone whose boot gets further on an Intel CPU can re-run with
LEONIDA_CPU_EMU_STATS=5and update the table.Also seen in passing, for whoever owns stop 18: on this RTX 2080 Ti (driver 621.24) the console BVH builder's first
CreateComputePipelineStatehit the title's 30 s watchdog on both a cold and a warm driver cache (two runs, about 33 s each); with #7516 the boot goes past it.Tested
cpu_emulation_testandcpu_emulation_test --bench: all checks pass on the i9-9900K (every form through the handler).gta6rt --runon the retail executable as above, with--traceandLEONIDA_CPU_EMU_STATS=2/3: thecpu_emulatedevent and the summary appear, and the counts match between the trace and the summary.python -I tests/test_docs_*.pyandtests/test_boot_trace.py: pass, excepttest_docs_links.py, which fails on RT-500: gta6rt emulates the Zen 2 instructions an Intel CPU lacks (INSERTQ/EXTRQ, CLZERO, MONITORX/MWAITX, CLWB) #7111's head too (an anchor indocs/dev-tools.md); not touched here.LEONIDA_D3D12=vulkan.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (Not applicable: no translator change.)🤖 Generated with Claude Code