Repository navigation
Closed
Milestone
Description
ISSUE TYPE
- Bug Report
COMPONENT NAME
CS Agent
CLOUDSTACK VERSION
4.17.0.1
CONFIGURATION
OS / ENVIRONMENT
Host OS: Ubuntu 20.04.5 LTS
Hypervisor: KVM
SUMMARY
After upgradeing existing agents from 4.16.1 to 4.17.0.1 the retrieval of the CPU Speed fails. Nevertheless the Agents reports CPU Speeds which seem to be the actual running speed of the cores, not the potentially max. availeable speed of the CPU.
STEPS TO REPRODUCE
Upgarde existing CS Agent from 4.16.1 to 4.17.0.1
EXPECTED RESULTS
CPU Speeds are retrieved for the max. availeable CPU speeds
ACTUAL RESULTS
Agent is reporting "live" CPU Speed; Error out of agent.log
2022-08-28 13:36:51,849 INFO [utils.linux.KVMHostInfo] (Agent-Handler-1:null) (logid:) Fetching CPU speed from command "lscpu".
2022-08-28 13:36:51,858 ERROR [utils.linux.KVMHostInfo] (Agent-Handler-1:null) (logid:) Unable to retrieve the CPU speed from lscpu.
java.lang.NullPointerException
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
at java.base/jdk.internal.math.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.base/java.lang.Float.parseFloat(Float.java:455)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getCpuSpeedFromCommandLscpu(KVMHostInfo.java:107)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getCpuSpeed(KVMHostInfo.java:87)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getHostInfoFromLibvirt(KVMHostInfo.java:133)
at org.apache.cloudstack.utils.linux.KVMHostInfo.<init>(KVMHostInfo.java:53)
at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.initialize(LibvirtComputingResource.java:3373)
at com.cloud.agent.Agent.sendStartup(Agent.java:441)
at com.cloud.agent.Agent$ServerHandler.doTask(Agent.java:1099)
at com.cloud.utils.nio.Task.call(Task.java:83)
at com.cloud.utils.nio.Task.call(Task.java:29)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2022-08-28 13:36:51,859 INFO [utils.linux.KVMHostInfo] (Agent-Handler-1:null) (logid:) Fetching CPU speed from file [/sys/devices/system/cpu/cpu0/cpufreq/base_frequency].
2022-08-28 13:36:51,860 ERROR [utils.linux.KVMHostInfo] (Agent-Handler-1:null) (logid:) Unable to retrieve the CPU speed from file [/sys/devices/system/cpu/cpu0/cpufreq/base_frequency]
java.io.FileNotFoundException: /sys/devices/system/cpu/cpu0/cpufreq/base_frequency (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
at java.base/java.io.FileReader.<init>(FileReader.java:60)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getCpuSpeedFromFile(KVMHostInfo.java:118)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getCpuSpeed(KVMHostInfo.java:92)
at org.apache.cloudstack.utils.linux.KVMHostInfo.getHostInfoFromLibvirt(KVMHostInfo.java:133)
at org.apache.cloudstack.utils.linux.KVMHostInfo.<init>(KVMHostInfo.java:53)
at com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.initialize(LibvirtComputingResource.java:3373)
at com.cloud.agent.Agent.sendStartup(Agent.java:441)
at com.cloud.agent.Agent$ServerHandler.doTask(Agent.java:1099)
at com.cloud.utils.nio.Task.call(Task.java:83)
at com.cloud.utils.nio.Task.call(Task.java:29)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
2022-08-28 13:36:51,860 INFO [utils.linux.KVMHostInfo] (Agent-Handler-1:null) (logid:) Using the value [1803] provided by Libvirt.
Activity
s-seitz commentedon Aug 29, 2022
cpu speed is first gathered via a tiny script, before looking for
base_frequency.Just make sure,
lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'works on your kvm-nodes.Most likely, you forgot to install lscpu?
Hudratronium commentedon Aug 29, 2022
lscpu is working as expected on the hosts.
The part of the script you provides is executed, giving no result. And no error.
But from my little knoledge this script will not give you any "Speeds" as you only "grep" the Model name and pipe the "model name" / the line with the modelname for further usage.
s-seitz commentedon Aug 29, 2022
I can confirm it works. At my site it provides a float value of "2.27". As a wild guess: lscpu is heavily localized, so depending on your system's locale, it might not have "Model name" in it's output.
I'ld try
LC_ALL=C lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'. If this provides you a reasonable Value for your CPU frequency, I'ld recommend to change the system's local to "en_US.UTF-8" (or simply non-localized "C").Hudratronium commentedon Aug 29, 2022
lscpu alone is giving me the whole output which is expected, as well as the 'model name'.
System's locale is locale is
en_GB.UTF-8. So nothing spcial by any means.... And currently we don't have any requirement for CS to use a special locale Version. If that's needed we shall edit the docs soon!Tried this
LC_ALL=C lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'and the same result.Results after every step of the pipes:
LC_ALL=C lscpu= FULL lscpu resultLC_ALL=C lscpu | grep -i 'Model name'= Model name: AMD.....LC_ALL=C lscpu | grep -i 'Model name' | head -n 1= Model name: AMD ....LC_ALL=C lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz'= EMPTY with no errorLC_ALL=C lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'= EMPTY with no errorThe 'Model name' for AMD CPUs doesn't contain any value for speeds nor the "egrep" pattern....
s-seitz commentedon Aug 29, 2022
Ah, I've only seen Xeon's here (which provide their nominal speed in the Model name). So, if there's a frequency reported at your site, it's gathered from libvirt/virsh, the 3rd. and last input for cloudstack-agent's frequency discovery.
Maybe, this provides the current, and not the nominal speed?
Sorry, I couldn't be of much help.
Hudratronium commentedon Aug 29, 2022
Thanks for your support anyway.
Seems like this is the case.... Strange thing after a 'mere' update to encounter though.
shwstppr commentedon Aug 30, 2022
@Hudratronium Is it just about the error in the agent logs or are you seeing any change in the behaviour?
Current code tries to find the max CPU speed using the following methods, in the same order:
lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'/sys/devices/system/cpu/cpu0/cpufreq/base_frequencyIn your case method1 and 2 are not returning any value so the value from method 3 is used which comes 1803.
In 4.16.1 as well code used to have method 2 and 3. I'm pretty sure you must be getting logs like the following reported earlier,
Unable to retrieve the CPU speed from file [/sys/devices/system/cpu/cpu0/cpufreq/base_frequency]. Using the value [1803] provided by the Libvirt.. It is just an additional way for finding the CPU speed that has been added in 4.17.0Hudratronium commentedon Aug 30, 2022
@shwstppr
The behaviour has changed as since the upgrade the reported values "changed" to the current cpu speeds. That hasn't been the case in our installation from 4.15. onwards - including the upgrades / restarts of hosts - thats why i was so suprised. That leaded to a situation that
Biggest problem for our usecase: "HA-Features" wouldn't be working in this situation
"Workaround" for us was to set the
host.cpu.manual.speed.mhzoption in the agent.conf manually for our hosts.Regarding the outputs for the different checks performed by the agent:
cpuinfo_max_freq:-Dshwstppr commentedon Aug 30, 2022
@Hudratronium I checked the diff between 4.16.1 and 4.17.0 again and it seems the 2nd method(finding CPU frequency from file) used has changed. Earlier code used to check file
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freqbut now it checks/sys/devices/system/cpu/cpu0/cpufreq/base_frequency. Maybe that caused the difference for you.Can you check if
/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freqis present on your host and if has the desired value?As you mentioned setting option in agent.conf fixes it for you, maybe we can update the documentation?
cc @nvazquez
Hudratronium commentedon Aug 30, 2022
@shwstppr
Okay i guess what has happend....
According to https://www.kernel.org/doc/html/v5.9/admin-guide/pm/cpufreq.html there is no value
base_frequency.The value for 'base_frequency' is only availeable on systems with Intel CPUs using the 'intel_pstate' driver https://www.kernel.org/doc/html/v5.9/admin-guide/pm/intel_pstate.html.
Meaning that the check 1 as well as 2 won't work with with other CPUs (non Intel or without the '@ XXXX MHz' tag in the 'Model name').
Updateing the documentation would be nice - as currently only Intel-CPUs are "savely" supported out of the box.
shwstppr commentedon Sep 1, 2022
@Hudratronium can you please share complete output of
lscpuso maybe we can check if it can use some other regex like CPU MHz or CPU max MHz from below,Also, output of:
virsh nodeinfovirsh sysinfovirsh capabilitiesHudratronium commentedon Sep 1, 2022
@shwstppr
Will try to give as much inforamtion as possible:
lscpu
virsh nodeinfo
virsh sysinfo
virsh capabilities
The problem in this case might be, that the availeable output seems to connected to the used module for the cpu. As mentioned above lscpu using the
intel_pstatemodule will give different sets of results. Currently, as i am using a standard Ubuntu Server 20.04.5, the out-of-the-box used module isacpi-cpufreq. Which supports theCPU max MHz. On the horizon, when the kernel version 5.17 will be used, out-of-the-box we shall see the moduleamd_pstat...I don't know how important the "out-of-the-box" CPU discovery is for the cloudstack agent. Guess there would be a little script needed to check the loaded module and then "query" the intended value... How ever - depending on how important this is.
weizhouapache commentedon Sep 2, 2022
thanks @Hudratronium
it looks we could get correct value by
lscpuorvirsh capabilitiesCPU max MHz: 2650.0000
shwstppr commentedon Sep 2, 2022
@weizhouapache
virsh capabilitiesseem a better option as with my system I getCPU max MHz: 4100.0000from lscpu while virsh capabilities return the correct value,weizhouapache commentedon Sep 2, 2022
@shwstppr
good finding !
kvm: add virsh capabilities method for cpu speed retrieval
kvm: add libvirt host capabilities method for cpu speed retrieval (#6696
shwstppr commentedon Sep 6, 2022
Fixed with #6696