[vmm][whp] Override CPUID leaf 0x16 with WHP clock frequency#11
Draft
esaurez wants to merge 2 commits into
Draft
[vmm][whp] Override CPUID leaf 0x16 with WHP clock frequency#11esaurez wants to merge 2 commits into
esaurez wants to merge 2 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 (Processor Frequency Information) even on CPUs that support it (e.g. Skylake-SP). This prevents the guest kernel from using RDTSC-based LAPIC timer calibration, forcing a fallback to the PIT busy-wait loop which generates ~908 VM exits. Query the host TSC frequency via WHvGetCapability(ProcessorClockFrequency) and inject it into CPUID leaf 0x16 EAX via WHvPartitionPropertyCodeCpuidResultList before partition setup. The guest kernel (on the LAPIC calibration branch) sees a non-zero base frequency and uses an RDTSC spin loop instead of PIT, eliminating ~908 PMIO read exits. Benchmark results (p50, 50 iterations): Before (dev): 81,106 us total, 59,384 us guest_exec After (this fix): 67,029 us total, 48,641 us guest_exec Improvement: 17.4% total, 18.1% guest_exec Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 22, 2026
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#1919.
Problem
Hyper-V zeros out CPUID leaf 0x16 (Processor Frequency Information) even on CPUs that support it. The guest kernel checks this leaf for TSC base frequency to enable RDTSC-based LAPIC timer calibration. When leaf 0x16 returns 0, it falls back to the PIT busy-wait loop, generating ~908 unnecessary VM exits.
Fix
The VMM now queries the host TSC frequency via WHvGetCapability(ProcessorClockFrequency), converts Hz to MHz, and injects it into CPUID leaf 0x16 EAX via WHvPartitionPropertyCodeCpuidResultList.
Benchmark Results (p50, 50 iterations)
Depends on: enhancement-kernel-lapic-calibration-whp (guest-side RDTSC calibration)