Skip to content

X86_64 msr cpuid refactor#5899

Open
ShadowCurse wants to merge 2 commits into
firecracker-microvm:mainfrom
ShadowCurse:x86_64_msr_cpuid_refactor
Open

X86_64 msr cpuid refactor#5899
ShadowCurse wants to merge 2 commits into
firecracker-microvm:mainfrom
ShadowCurse:x86_64_msr_cpuid_refactor

Conversation

@ShadowCurse

Copy link
Copy Markdown
Contributor

Changes

Replace Btree type with direct underlying CpuId and Msrs types to reduce the number of state transitions and memory allocations.

This change makes the binary ~30KiB smaller and reduces the max RSS with 32 vcpus by 50-80 KiB.

Reason

Reduction in number of state transitions, memory allocations and code simplicity.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.03%. Comparing base (9e8b921) to head (65eadce).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5899      +/-   ##
==========================================
+ Coverage   83.00%   83.03%   +0.02%     
==========================================
  Files         277      277              
  Lines       30106    30097       -9     
==========================================
+ Hits        24989    24990       +1     
+ Misses       5117     5107      -10     
Flag Coverage Δ
5.10-m5n.metal 83.33% <99.02%> (+0.02%) ⬆️
5.10-m6a.metal 82.69% <99.02%> (+0.03%) ⬆️
5.10-m6g.metal 79.94% <ø> (ø)
5.10-m6i.metal 83.33% <99.02%> (+0.02%) ⬆️
5.10-m7a.metal-48xl 82.68% <99.02%> (+0.04%) ⬆️
5.10-m7g.metal 79.94% <ø> (ø)
5.10-m7i.metal-24xl 83.30% <99.02%> (+0.02%) ⬆️
5.10-m7i.metal-48xl 83.30% <99.02%> (+0.02%) ⬆️
5.10-m8g.metal-24xl 79.94% <ø> (-0.01%) ⬇️
5.10-m8g.metal-48xl 79.94% <ø> (-0.01%) ⬇️
5.10-m8i.metal-48xl 83.30% <99.02%> (+0.02%) ⬆️
5.10-m8i.metal-96xl 83.30% <99.02%> (+0.02%) ⬆️
6.1-m5n.metal 83.36% <99.02%> (+0.02%) ⬆️
6.1-m6a.metal 82.72% <99.02%> (+0.04%) ⬆️
6.1-m6g.metal 79.94% <ø> (-0.01%) ⬇️
6.1-m6i.metal 83.35% <99.02%> (+0.02%) ⬆️
6.1-m7a.metal-48xl 82.71% <99.02%> (+0.04%) ⬆️
6.1-m7g.metal 79.94% <ø> (-0.01%) ⬇️
6.1-m7i.metal-24xl 83.37% <99.02%> (+0.02%) ⬆️
6.1-m7i.metal-48xl 83.37% <99.02%> (+0.02%) ⬆️
6.1-m8g.metal-24xl 79.93% <ø> (-0.01%) ⬇️
6.1-m8g.metal-48xl 79.94% <ø> (ø)
6.1-m8i.metal-48xl 83.37% <99.02%> (+0.02%) ⬆️
6.1-m8i.metal-96xl 83.37% <99.02%> (+0.02%) ⬆️
6.18-m5n.metal 83.36% <99.02%> (+0.02%) ⬆️
6.18-m6a.metal 82.71% <99.02%> (+0.03%) ⬆️
6.18-m6g.metal 79.94% <ø> (-0.01%) ⬇️
6.18-m6i.metal 83.36% <99.02%> (+0.03%) ⬆️
6.18-m7a.metal-48xl 82.71% <99.02%> (+0.04%) ⬆️
6.18-m7g.metal 79.94% <ø> (-0.01%) ⬇️
6.18-m7i.metal-24xl 83.37% <99.02%> (+0.02%) ⬆️
6.18-m7i.metal-48xl 83.37% <99.02%> (+0.03%) ⬆️
6.18-m8g.metal-24xl 79.93% <ø> (-0.01%) ⬇️
6.18-m8g.metal-48xl 79.93% <ø> (-0.01%) ⬇️
6.18-m8i.metal-48xl 83.37% <99.02%> (+0.02%) ⬆️
6.18-m8i.metal-96xl 83.37% <99.02%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ShadowCurse ShadowCurse force-pushed the x86_64_msr_cpuid_refactor branch from 034dae0 to 26f6cb4 Compare May 19, 2026 13:47
@ShadowCurse ShadowCurse force-pushed the x86_64_msr_cpuid_refactor branch from 26f6cb4 to b9dacb8 Compare May 26, 2026 13:59
@ShadowCurse ShadowCurse self-assigned this May 26, 2026
Previously we were using Btree as an underlying data type for the
`Cpuid` type. This required us to convert from `CpuId` type which is
what KVM provides for transformations and then convert back into `CpuId`
when we need to set it back to KVM. These conversions are unnecessary
since the `CpuId` type can be used for the same purpose without any need
for intermediate transition to Btree.

This commit does this swap to using `CpuId` directly. In addition to
removing a need for transition code, this change reduces the number of
dynamic allocations/deallocations used in the Btree implementation. The
only edge case of updating entries is handled by new `cpuid_insert`
function which ensures we preserve the Btree de-duplicating quality.
Since the number of entries in `CpuId` is quite low, doing linear
searches will not cause any noticable performance change.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Similarly to the previous commit, replace Btree type for Msrs handling
with kvm_bindings::Msrs to remove the unnecessary state transitions and
memory allocations. Uniqueness of entries is preserved with
`msrs_insert` function.

Together with previous commit this reduces the binary sizy by ~30KiB and
reduces the maximum RSS during `test_all_vcpus_online` test by 50-80 KiB

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
@ShadowCurse ShadowCurse force-pushed the x86_64_msr_cpuid_refactor branch from b9dacb8 to 65eadce Compare June 8, 2026 13:47
@ShadowCurse ShadowCurse requested a review from zulinx86 June 8, 2026 14:45
@ShadowCurse ShadowCurse marked this pull request as ready for review June 8, 2026 14:45
@ShadowCurse ShadowCurse added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Jun 8, 2026
@ShadowCurse ShadowCurse changed the title X86 64 msr cpuid refactor X86_64 msr cpuid refactor Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant