Skip to content

Keep guest vectors in XMM registers between translated instructions - #6

Merged
losfair merged 2 commits into
mainfrom
perf/vector-register-cache
Oct 25, 2026
Merged

losfair merged 2 commits into
mainfrom
perf/vector-register-cache

Conversation

@losfair

@losfair losfair commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

NEON, FP, and crypto lowerings previously loaded and stored guest vectors through the state page between instructions. Cache up to eight frequently used guest vectors in XMM0..7, retaining them across self-loop back-edges and spilling/refilling around helpers and other block boundaries. The AES benchmark loop goes from 20 vector-state memory accesses per iteration to zero.

Recovery metadata records the mapping and whether saved XMM registers or the state page is authoritative, including partial fills/spills, helper returns, and exit trampolines. Location markers are preserved when an instruction marker shares their host address. Scalar, lane, and full-width accesses use cache-aware accessors; scratch results still commit in one host instruction.

The native x86 backend captures live or saved user XMM state, including IRQ-disabled epoch recovery and XSAVE init state. Other ports opt in with KEMU_ARCH_VECTOR_CACHE and their own kemu_arch_read_xmm() hook. Ports without that hook retain the memory-only representation. kemu.jitoff=64 / NO_VCACHE=1 disable caching. Allocation is block-local; cross-block allocation and dynamic eviction remain future work.

Interrupted SVC stubs now distinguish pending syscalls from completed ones. Recovery restarts a pending guest SVC, preventing epoch recovery from skipping a syscall such as rt_sigreturn; after the host syscall, the restored page state remains authoritative. Kernel and userspace tests share this recovery routine.

Validation:

  • 31 core tests, including cache-location recovery, exit trampolines, loop allocation, and relocation of vector-caching blocks.
  • 100,000 general JIT/interpreter differential cases, plus FP, crypto, optional-feature fallback, long-block, and mixed-vector suites. Tests exercise 20 µs asynchronous interruptions, partial writes, wrapping register lists, helper calls, branches and function calls. The FP suite retains its existing treatment of cumulative FPSR differences; register/memory comparisons pass.
  • Independent subagent review and 80,000 additional differential cases passed. Boundary tests cover both SVC stubs before entry and after normal return or rt_sigreturn.
  • The l4h port passed ABI and tagged SIMD/thread/signal checks with the pending hook, cache disabled, one vCPU, interpreter mode, and forced invalidation. A threaded reproducer for the preexisting skipped-SVC bug failed on baseline main and passed five consecutive runs after the fix, both in l4h and native Linux.
  • 2,048 translated blocks relocated with zero mismatches.
  • Linux 6.18 built with LLVM/Rust 1.88 and booted under KVM: ABI (34 checks), TBI (8 checks), a new vector signal/fault test, multithreaded stress and integer/NEON benchmarks pass. Forced recovery (kemu.stress=1) and cache-disabled coverage pass, with no kernel warnings.
  • Crypto checksums match QEMU. Added the recovery/allocation tests, mixed-vector and FP differential runs, and guest signal/fault coverage to CI.

Performance measured at 6949dac on the i7-13700H host, using the same revision and static AArch64 tests/bench/crypto.{c,S} binary in kemu-user: nine interleaved cache-off/cache-on pairs, 2,000,000 iterations, warmed translations, pinned to CPU 0. Values are median ns per benchmarked crypto instruction, including loop and operand-handling overhead.

Benchmark Cache off Cache on Speedup
AES encrypt 5.143 2.567 2.00×
AES decrypt 4.784 2.474 1.93×
PMULL 64-bit 4.811 1.218 3.95×
PMULL 8-bit 8.873 6.250 1.42×
SHA-1 11.919 9.179 1.30×

Reproduce each pair with NO_VCACHE=1 taskset -c 0 tools/kemu-user/target/release/kemu-user --jit build/crypto-bench 2000000 1, then the same command without NO_VCACHE=1; the benchmark source includes its build command.

These are translator microbenchmarks, not native-performance ratios. Separate baseline-main/patched KVM runs passed all checksum checks, but end-to-end OpenSSL timings were too variable to support a speedup claim: even native AES-GCM ranged from 84 to 5,942 MB/s in the final three runs. Shared-host timing noise remains a limitation; this PR does not claim to close the remaining gap to native crypto implementations.

@losfair
losfair marked this pull request as ready for review October 25, 2026 08:05
@losfair
losfair merged commit 0934c93 into main Oct 25, 2026
3 checks passed
@losfair
losfair deleted the perf/vector-register-cache branch October 25, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant