[kernel][whp] E: Skip PIC initialization with xAPIC-only mode#13
Draft
esaurez wants to merge 3 commits into
Draft
[kernel][whp] E: Skip PIC initialization with xAPIC-only mode#13esaurez wants to merge 3 commits into
esaurez wants to merge 3 commits into
Conversation
- Reduce PIT-based calibration window from 10 ms to 1 ms. - Replace PIT-based calibration with RDTSC spin loop when CPUID leaf 0x16 is available, eliminating ~100 VM exits during boot. - Fall back to PIT-based calibration (1 ms window) when leaf 0x16 is unavailable instead of guessing TSC frequency. - Add max-iteration guard to RDTSC spin loop to prevent hangs. - Fix CPUID helper to check max supported leaf and set ECX=0 explicitly for well-defined subleaf selection.
Hyper-V zeros out CPUID leaf 0x16 on the host, so get_base_frequency_mhz() returns 0. Use WHvGetCapability(ProcessorClockFrequency) instead, which returns the actual TSC frequency in Hz. Without this fix, the guest falls back to PIT-based calibration (184 extra VM exits) instead of the fast RDTSC path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When the xAPIC timer has been successfully initialized via try_init_xapic_timer() on WHP+microvm, skip legacy 8259 PIC initialization entirely. The WHP LAPIC emulator handles timer delivery and EOI via MMIO without VM exits. This eliminates ~47 PIC I/O port exits per cold-start (ports 0x20/0x21/0xA0/0xA1), reducing total exits from ~62 to ~15. Each exit costs ~470us on WHP (two hypercalls: DispatchVp + SetVpRegisters), so this saves ~5-22ms depending on system load. The new XapicOnly interrupt controller variant: - Uses xAPIC for EOI (MMIO, handled in-kernel by Hyper-V) - No-ops for unmask (LAPIC timer already unmasked during calibration) - IKC interrupts are injected via WHvRequestInterrupt through the LAPIC, not through PIC routing Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Replica of nanvix#1971.
Summary
Skip legacy 8259 PIC initialization on WHP+microvm when xAPIC is available, reducing VM exits from ~62 to ~15 per cold-start.
Problem
On WHP, every guest I/O port access causes a full VM exit to userspace. PIC initialization writes ICW1-ICW4 commands to ports 0x20/0x21/0xA0/0xA1, totaling ~47 PMIO exits that are handled as no-ops by the VMM.
Implementation
Added XapicOnly(Xapic) variant to InterruptControllerType. Also includes a prerequisite fix: use WHvGetCapability(ProcessorClockFrequency) instead of get_base_frequency_mhz() for the TSC control register.
Measured Improvements (p50)
Depends on #11 (CPUID frequency override).