Repository navigation
Hot Path TCG Direct RAM Read Windows
Lifecycle: Performance - Unproven · Type: Speculative memory shortcut
State: Source-backed; runtime value is not established.
Status: Architecturally possible, but not yet promoted as an xemu shortcut target; no specific translated region has been measured.
Mechanism class: Speculative guarded shortcut / region-level SoftMMU bypass.
Reviewed source:
322986f4c5502b3fa887a9605ac8cd88e9b2c579Scope: x86 TCG backend and system-mode guest RAM reads.
Current TCG system-mode loads already have an important fast path. For each guest memory access, generated code performs a per-vCPU software-TLB lookup/compare; a TLB hit produces a direct host address and the generated code performs the load without leaving translated execution. Slow or specially flagged mappings take the helper path.
The proposed shortcut would go one level further for a measured translated region that performs several reads from one stable RAM window: validate the mapping/window once, then emit multiple direct reads without repeating the normal software-TLB sequence for every access.
This is a real bypass concept, but it is not yet a validated xemu-owned target. It changes a mature QEMU memory contract and should not be placed beside renderer shortcuts until profiling and generated-code inspection identify a concrete region where repeated TLB checks are material.
flowchart TD
A[Translated guest load] --> B[Generated software-TLB load and compare]
B -->|TLB hit, ordinary allowed mapping| C[Compute direct host address]
C --> D[Generated host load]
B -->|Miss or flagged mapping| E[Exit to slow helper]
E --> F[Resolve RAM/MMIO/fault/watch/dirty behavior]
F --> D
prepare_host_addr() explicitly prepares the host address for the fast path and records a slow path when required. This means xemu is not currently calling a generic C memory function for every ordinary RAM read.
flowchart TD
A[Enter measured translated read region] --> B{Plan identity and mapping epoch still valid?}
B -->|No| R[Execute generic translated region]
B -->|Yes| C{Entire read window is ordinary readable RAM?}
C -->|No| R
C -->|Yes| D[Compute/pin host base for bounded region]
D --> E[Emit multiple direct reads without per-access TLB checks]
E --> F[Exit before page/mapping/protection boundary]
R --> F
The direct route reads current memory values. It must never cache the loaded values themselves.
The proposal currently lacks four pieces of evidence:
- A concrete hot guest PC/translated region. No xemu trace in this review identifies a multi-read block where per-access TLB checks dominate.
- Generated-code proof. The expected repeated sequence must be visible in the exact Release binary before assuming it can be removed.
- An xemu-specific ownership seam. This is primarily QEMU TCG/SoftMMU architecture, not a local renderer/device path.
- A bounded invalidation design. Mapping, permissions, watchpoints, dirty tracking, self-modifying code, MMIO substitution, and snapshot restoration all participate.
Until those exist, the page records a research gate rather than an implementation plan.
A future prototype should start with reads only and require:
- one exact translated region/TB identity;
- one bounded virtual/physical page window;
- ordinary RAM mapping only;
- stable mapping/protection epoch;
- no page crossing beyond the validated span;
- no watchpoint or instrumentation requiring per-access slow behavior;
- no MMIO, ROM behavior, or dynamically rerouted MemoryRegion;
- no write dirty-tracking or self-modifying-code responsibilities;
- deoptimization/fallback when any condition changes.
Writes should remain out of the first prototype because they add dirty-memory, migration/display, code invalidation, and ordering obligations.
The guest observes values, faults, permissions, watchpoints, MMIO side effects, and memory ordering. It does not observe the software-TLB lookup itself.
The exact contract is:
Every admitted direct read must return the same value or fault as the normal TCG/SoftMMU route at that guest instruction, and every mapping or instrumentation change must force fallback before the next affected read.
- Remap the same guest address to different RAM.
- Replace the page with MMIO.
- Cross a page boundary inside the candidate region.
- Revoke read permission and require the same guest fault.
- Add a watchpoint or debugger instrumentation.
- Restore a snapshot with different mappings.
- Trigger TLB flush and TB invalidation.
- Modify executable guest code in the region.
- Use an access requiring byte swapping, alignment handling, or another MemOp difference.
- Verify the fallback executes the original generic region rather than an approximate result.
exact executable and DWARF identity
hot guest PC / TB identity
number of reads per region execution
software-TLB instructions per access
TLB hit rate
region executions per frame/work unit
sampled or timed cost of the generated lookup sequence
candidate window eligibility rate
mapping/invalidation frequency
Disassembly must show the intended sequence disappeared in the prototype. Function-level sampling alone is insufficient because much of the cost lives in generated guest code.
direct_window_candidates
direct_window_admitted
direct_window_reject_mapping
direct_window_reject_boundary
direct_window_reject_instrumentation
direct_window_fallbacks
direct_reads_executed
tlb_checks_avoided
window_invalidations
fault_mismatches
value_mismatches
- Silently bypassing MMIO or MemoryRegion dispatch.
- Missing permission/fault transitions.
- Bypassing watchpoints or debugging instrumentation.
- Stale mapping after TLB flush, restore, or device remap.
- Crossing a page with different attributes.
- Introducing a fork-specific TCG specialization that is difficult to rebase or upstream.
- Entry validation costing as much as the repeated checks it replaces.
- Optimizing a sequence that the host compiler/backend already handles efficiently.
- Use Release + matching DWARF and guest-PC attribution to identify a target.
- Inspect generated machine code and count repeated TLB sequences.
- Build a throwaway read-only prototype for that one region.
- Run mapping, MMIO, boundary, permission, watchpoint, restore, and SMC negative controls.
- Compare fixed-work duration and representative titles, not only microbenchmarks.
- Evaluate whether the design belongs in upstream QEMU rather than a fork-local shortcut.
- Promote to an xemu shortcut page only after the region, route, and benefit are concrete.
Deferred architecture research. It is applicable to the software stack in principle, but the current source review does not justify calling it an actionable xemu shortcut. The existing per-vCPU TLB/direct-host fast path must be acknowledged as the baseline.
- CPU & vCPU Execution
- Memory & DMA
- Debugging Lag & Hot-Path Analysis
- Debugging Tools & Commands
- Assumption-Based Shortcut Validation
Primary reference: This subject page is the design and research reference for Direct-RAM Read Windows. Pull requests are implementation/test history only.
Lifecycle: Performance - Unproven · Mechanism: Speculative multi-access SoftMMU shortcut
Reviewed source:322986f4c5502b3fa887a9605ac8cd88e9b2c579· Acceptance class: intended exact or behavior-preserving for its admitted scope
Validate one stable RAM window for a recognized translated region and use direct host loads for several reads instead of repeating software-TLB preparation for each access.
This entry remains Unproven: the source path and opportunity are concrete, but no accepted xemu runtime result has established that the candidate improves representative workloads. The page defines what must be bypassed, what remains mandatory, and how the hypothesis can be rejected.
| File / function | Role |
|---|---|
tcg/i386/tcg-target.c.inc |
prepare_host_addr() and generated qemu_ld memory paths |
target/i386/tcg/translate.c |
translated-region structure and exit boundaries |
flowchart TD
N0["Each guest read"]
N1["Software TLB lookup/tag check"]
N0 --> N1
N2["Compute host address or helper slow path"]
N1 --> N2
N3["Load value"]
N2 --> N3
N4["Repeat for nearby reads"]
N3 --> N4
flowchart TD
N0["Recognized region entry validates mapping epoch/window"]
N1["Derive host base once"]
N0 --> N1
N2["Several bounded direct reads"]
N1 --> N2
N3["Exit on boundary/invalidation"]
N2 --> N3
N4["Reference path on mismatch"]
N3 --> N4
Current TCG already has a direct path after each TLB hit, so the candidate must prove repeated lookup sequences are a measurable cost in a specific hot block. It is not justified by source appearance alone. The first prototype should be read-only and tied to one generated region.
- Repeated software-TLB tag/address preparation within an admitted region
- Some repeated branch/helper setup
- Current memory values
- Fault/permission behavior
- Watchpoints
- MMIO exclusion
- Mapping invalidation
- Reference fallback
if (plan.mapping_epoch != cpu->mapping_epoch ||
!plan.covers(guest_base, access_span)) {
goto generic_region;
}
host_base = plan.host_base + (guest_base - plan.guest_base);
value0 = load_le32(host_base + off0);
value1 = load_le32(host_base + off1);The sketch defines the intended boundary; it is not a complete patch and does not replace source review, ownership design, or focused tests.
- All accesses stay in the admitted RAM mapping with required permissions/alignment.
- Mapping/protection/watchpoint/debug changes invalidate the plan.
- Fault ordering and partial execution match the reference scope.
- MMIO/ROM/device aliases are rejected.
A plan belongs to a translated block/region and is keyed by mapping epoch plus guest range. Code invalidation, TLB flush/remap, snapshot restore, watchpoint changes, and page protection invalidate or force generic execution.
The maintained reference path remains the fallback whenever admission, capability, lifetime, or validation is uncertain. A fast result with an unproven dependency is not acceptable as an exact optimization.
- Can remove repeated generated checks in memory-heavy loops
- Leaves values live/current rather than caching contents
- Narrow read-only prototype possible
- Generated-code inspection gives a clear oracle
- Large TCG/SoftMMU engineering commitment
- Existing TLB hit path may already be cheap
- Fault/watchpoint semantics are difficult
- Entry validation may erase savings
- Architecture/backend portability
Counters must be cheap, subsystem-owned, and snapshotted outside the hot loop. Record at least:
- hot_block_execution_count
- guest_reads_in_candidate_regions
- TLB_fast_checks_avoided
- slow_path_entries
- entry_validation_failures
- generated_host_instructions
- host samples per block
A local reduction is not enough. Evidence must connect route reachability and removed work to fixed guest progress, CPU/GPU time where applicable, and p95/p99 behavior.
- Map/remap same virtual address
- Cross page boundary
- Revoke permission
- Watchpoint
- MMIO substitution
- Snapshot restore
- Read-only hot loop
- Generated-code diff
- Fault/exception progress
Correctness runs may use validation layers, detailed comparisons, and fault injection. Performance acceptance must use optimized Release builds with matching symbols and minimal instrumentation.
Move from Unproven only after a concrete hot guest PC/block shows significant repeated lookup cost and a narrow prototype preserves memory semantics.
Reject if profiling cannot identify such a block, entry checks dominate, or correctness requires recreating the general SoftMMU path.
CPU-and-vCPU-Execution · Performance-Unproven · Debugging-Lag-and-Hot-Path-Analysis · Memory-and-DMA
PR pages may be linked as supporting evidence, but they are not substitutes for this reference.
DSP tooling guide and navigation updated November 2, 2026 for experimental PR #384, source 8f51d237. Capture/replay usage and limits.
The earlier wiki-wide review was published November 1, 2026. Emulator source: b7140848. Reviewed wiki content: 1d2b671. Current status · Release availability · Publication process.
- Home
- Current status
- Stable versus main
- Implemented mechanisms
- Controls and defaults
- Measured results and limits
- Complete change register
- System
- CPU and vCPU
- Memory and DMA
- Graphics / NV2A
- APU and audio
- Timing and timers
- Platform and I/O
- Hardware observations
- Fidelity boundaries
- Methodology
- PGR2 routes
- Debugging lag / hot paths
- Tools and commands
- DSP capture, replay and fuzzing
- HLE readiness and public XISO proof
- Concurrent DSP shadow and OpenAL proof
- DSP HLE operation inventory
- DSP HLE fix examples and testing
- Development
- Upstream shortlist
- Wiki maintenance
- Research / retired work
- Optimization catalog
- Hot-path shortcuts
- Researched experiments
- Unproven proposal directory
- PR lessons
- September26 snapshot
Repository · PRs · Issues