Skip to content

Fix lscpu speed checking order - #12190

Open
guillemtp wants to merge 1 commit into
apache:4.22from
guillemtp:cpu-lscpu-speed-detection-fix
Open

Fix lscpu speed checking order#12190
guillemtp wants to merge 1 commit into
apache:4.22from
guillemtp:cpu-lscpu-speed-detection-fix

Conversation

@guillemtp

Copy link
Copy Markdown

Description

On KVM hosts, when agent checks the CPU speed it starts from lscpu before other mechanisms. It does a first check obtaining the CPU frequency from Model Name and if it's not specified in model name it takes from dynamic MHz option.

Dynamic MHz and frequency specified in model name can be different. Normally, dynamic MHz is bigger if the model name specifies. This means that we can have a registered host in CloudStack with a smaller frequency that it can achieve.

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

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

The following host has been registered with a frequency of 2.4Ghz, which can achieve 3.4GHz. Here the commands that executes the KVMHostInfo.java:

imatge

How Has This Been Tested?

Overriding the lscpu command as the following and restarting the cloudstack agent shows the hosts in CloudStack control plane with the right frequency:

sudo mv /usr/bin/lscpu /usr/bin/lscpu.real
sudo tee /usr/bin/lscpu >/dev/null << 'EOF'
#!/bin/bash
# Wrapper per lscpu: elimina la freqüència del Model name
/usr/bin/lscpu.real "$@" | sed -E 's/(Model name:\s+.*)@ [0-9.]+[GM]Hz/\1/'
EOF

sudo chmod +x /usr/bin/lscpu

@boring-cyborg

boring-cyborg Bot commented Dec 4, 2025

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@codecov

codecov Bot commented Dec 8, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.12233% with 548 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.88%. Comparing base (d700e2d) to head (1a047ba).
⚠️ Report is 350 commits behind head on 4.22.

Files with missing lines Patch % Lines
...m/cloud/agent/api/to/VirtualMachineMetadataTO.java 0.00% 91 Missing ⚠️
...om/cloud/upgrade/SystemVmTemplateRegistration.java 79.83% 57 Missing and 16 partials ⚠️
...ain/java/com/cloud/utils/db/TransactionLegacy.java 13.84% 50 Missing and 6 partials ⚠️
...g/apache/cloudstack/mom/webhook/WebhookFilter.java 35.18% 22 Missing and 13 partials ⚠️
.../cloudstack/mom/webhook/WebhookApiServiceImpl.java 86.04% 6 Missing and 12 partials ⚠️
...in/java/com/cloud/agent/api/storage/OVFHelper.java 15.78% 16 Missing ⚠️
.../storage/vmsnapshot/DefaultVMSnapshotStrategy.java 0.00% 15 Missing ⚠️
...java/com/cloud/upgrade/DatabaseUpgradeChecker.java 17.64% 14 Missing ⚠️
...e/cloudstack/backup/dao/BackupOfferingDaoImpl.java 0.00% 13 Missing ⚠️
.../api/command/offering/DomainAndZoneIdResolver.java 78.72% 0 Missing and 10 partials ⚠️
... and 101 more
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #12190      +/-   ##
============================================
+ Coverage     17.61%   17.88%   +0.26%     
- Complexity    15647    16059     +412     
============================================
  Files          5913     5934      +21     
  Lines        530557   532088    +1531     
  Branches      64835    65065     +230     
============================================
+ Hits          93456    95138    +1682     
+ Misses       426589   426307     -282     
- Partials      10512    10643     +131     
Flag Coverage Δ
uitests 3.57% <ø> (-0.03%) ⬇️
unittests 18.98% <53.12%> (+0.29%) ⬆️

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 15943

@DaanHoogland

Copy link
Copy Markdown
Contributor

Debian build failed, retrying that.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-14916)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 60202 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12190-t14916-kvm-ol8.zip
Smoke tests completed. 142 look OK, 8 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestAccounts>:setup Error 0.00 test_accounts.py
ContextSuite context=TestAddVmToSubDomain>:setup Error 0.00 test_accounts.py
test_DeleteDomain Error 10.11 test_accounts.py
test_forceDeleteDomain Failure 10.00 test_accounts.py
ContextSuite context=TestRemoveUserFromAccount>:setup Error 10.89 test_accounts.py
ContextSuite context=TestTemplateHierarchy>:setup Error 12.38 test_accounts.py
ContextSuite context=TestDeployVmWithAffinityGroup>:setup Error 0.00 test_affinity_groups_projects.py
ContextSuite context=TestAnnotations>:setup Error 0.00 test_annotations.py
test_query_async_job_result Error 0.00 test_async_job.py
test_01_host_tags Error 60.57 test_host_tags.py
test_01_migrate_VM_and_root_volume Error 76.29 test_vm_life_cycle.py
test_02_migrate_VM_with_two_data_disks Error 23.59 test_vm_life_cycle.py
test_03_secured_to_nonsecured_vm_migration Error 373.88 test_vm_life_cycle.py
test_04_nonsecured_to_secured_vm_migration Error 0.01 test_vm_life_cycle.py
test_01_redundant_vpc_site2site_vpn Failure 425.49 test_vpc_vpn.py
test_hostha_enable_ha_when_host_disabled Error 3.68 test_hostha_kvm.py
test_hostha_enable_ha_when_host_in_maintenance Error 304.81 test_hostha_kvm.py

@github-actions

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland 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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes CPU speed detection on KVM hosts by reordering the priority of CPU frequency detection methods in the lscpu command. The change ensures that hosts report their maximum achievable CPU frequency rather than the base frequency from the model name.

  • Swaps the order of CPU frequency detection: now tries "CPU max MHz" first, then falls back to model name frequency
  • Preserves S390x architecture-specific handling with the model name frequency detection block

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@blueorangutan

Copy link
Copy Markdown

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

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

@blueorangutan

Copy link
Copy Markdown

[SF] Trillian test result (tid-15048)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 54458 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12190-t15048-kvm-ol8.zip
Smoke tests completed. 148 look OK, 2 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File
test_03_deploy_and_scale_kubernetes_cluster Failure 28.97 test_kubernetes_clusters.py
test_01_redundant_vpc_site2site_vpn Failure 379.10 test_vpc_vpn.py

@DaanHoogland

Copy link
Copy Markdown
Contributor

@harikrishna-patnala @sureshanaparti , can you please review?

@blueorangutan

Copy link
Copy Markdown

[LL] Trillian Build Failed (tid-7170)

@rajujith

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@rajujith a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

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

@guillemtp

Copy link
Copy Markdown
Author

Hi @guillemtp can you please target this PR against the branch 4.22?

@nvazquez I've change it

@nvazquez

nvazquez commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Sorry @guillemtp you have changed the targed branch but the code remains on top of the main branch, that is why all these conflicts are shown. Let me help changing again the target branch and will help with the next steps

@nvazquez
nvazquez changed the base branch from 4.22 to main September 7, 2026 13:49
@nvazquez

nvazquez commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@guillemtp I have reverted the target PR back to main branch and only your changes are being displayed again.

For rebasing to the branch 4.22 please consider the following steps, assuming the origin remote is your fork of the repository and upstream is the Apache CloudStack upstream repository:

  • git fetch upstream

  • git checkout 4.22

  • git pull --rebase upstream 4.22 (get the latest 4.22 branch code)

  • git checkout cpu-lscpu-speed-detection-fix

  • git pull --rebase origin cpu-lscpu-speed-detection-fix

  • git format-patch -1 (this will create a patch file)

  • git reset --hard 4.22

  • git am <PATCH_FILE> (usually starts with 0001-xx)

  • git push origin cpu-lscpu-speed-detection-fix -f

After that, you can change again the target PR to 4.22 on Github.

Please let me know if you have any questions

@nvazquez nvazquez moved this from Ready to conflict/waiting in CloudStack Testing Sep 7, 2026
@nvazquez

nvazquez commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@guillemtp I can help rebasing and getting the commit on top of the 4.22 branch, please let me know if I can proceed with this or you are happy doing it

@guillemtp

Copy link
Copy Markdown
Author

@guillemtp I can help rebasing and getting the commit on top of the 4.22 branch, please let me know if I can proceed with this or you are happy doing it

Yes @nvazquez, I've invited you to collaborate on the project. Sorry because I was some days off and I've cloudstack quite aside now.

@nvazquez

nvazquez commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @guillemtp I have rebased the PR against 4.22.

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@nvazquez 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.

@blueorangutan

Copy link
Copy Markdown

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

@nvazquez nvazquez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks @guillemtp - manually tested OK

KVM host:

root@nvs-kvm01:~# lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'
2.90
root@nvs-kvm01:~# lscpu | grep -i 'CPU max MHz' | head -n 1 | sed 's/^.*: //' | xargs
4800.0000

Before the fix:
Image

After the fix:
Image

@nvazquez

nvazquez commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

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

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

10 participants