Skip to content

kvm: use the base CPU frequency as the host speed and expose the maximum frequency as a host detail - #14383

Open
winterhazel wants to merge 1 commit into
apache:4.22from
winterhazel:fix-cpu-speed
Open

winterhazel wants to merge 1 commit into
apache:4.22from
winterhazel:fix-cpu-speed

Conversation

@winterhazel

Copy link
Copy Markdown
Member

Description

This PR is a minimal follow-up to #12190. A few refactorings and adjustments will be done in a separate PR targeting main.

#12190 changed the order in which the KVM Agent retrieves the CPU speed from lscpu, so that CPU max MHz is preferred over the frequency advertised in the model name. However, the host CPU speed is not only informative. It is used to:

  • calculate the CPU capacity of the host (cores * speed);
  • calculate the CPU quota of VMs that use a compute offering with CPU cap enabled (VM speed / host speed).

CPU max MHz may include the turbo frequency, which the CPU is not able to sustain; thus, it is not a suitable value for these calculations. Besides that, its meaning depends on the cpufreq driver in use: with intel_pstate/amd-pstate it is the turbo frequency, with acpi-cpufreq it is the base frequency plus 1 MHz, and without a cpufreq driver it is not reported at all.

As a consequence, the change impacts existing VMs with CPU cap enabled. Considering a host with a base frequency of 2.9 GHz and a maximum frequency of 4.8 GHz, a VM using a CPU cap enabled offering with 2.9 GHz does not have its CPU time limited. After #12190, once the Agent reconnects and the VM is started or migrated, it is able to use only ~60% of the CPU time, making users feel that the performance of their VMs degraded out of nowhere.

Therefore, this PR:

  • restores the previous order of the lscpu checks to the same behavior that existed before Fix lscpu speed checking order #12190;
  • exposes the maximum frequency of the CPU as a new host detail (host.cpu.max.speed.mhz), which is returned in the details of the listHosts API and shown in the details of the host in the UI as CPU maximum frequency (turbo). This value is only informative; it is not used in capacity or CPU quota calculations.

Operators that want a host to be registered with a specific CPU speed, such as the turbo frequency, can still do so through the host.cpu.manual.speed.mhz property in agent.properties.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Tests are still pending.

@winterhazel

Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@codecov

codecov Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.01%. Comparing base (437adc8) to head (1f3f14c).
⚠️ Report is 2 commits behind head on 4.22.

Files with missing lines Patch % Lines
...org/apache/cloudstack/utils/linux/KVMHostInfo.java 73.68% 4 Missing and 1 partial ⚠️
...ervisor/kvm/resource/LibvirtComputingResource.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #14383      +/-   ##
============================================
- Coverage     18.02%   18.01%   -0.01%     
+ Complexity    16247    16246       -1     
============================================
  Files          5936     5936              
  Lines        535823   535880      +57     
  Branches      65612    65615       +3     
============================================
- Hits          96572    96564       -8     
- Misses       428252   428317      +65     
  Partials      10999    10999              
Flag Coverage Δ
uitests 4.04% <ø> (ø)
unittests 19.09% <66.66%> (-0.01%) ⬇️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19514

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants