Skip to content

Agent unable to retrieve CPU Speed of host after upgrading to 4.17.0.1 #6680

Closed

Description

@Hudratronium
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

  1. s-seitz commented on Aug 29, 2022

    @s-seitz

    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?

  2. Hudratronium commented on Aug 29, 2022

    @Hudratronium
    Author

    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.

  3. s-seitz commented on Aug 29, 2022

    @s-seitz

    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").

  4. Hudratronium commented on Aug 29, 2022

    @Hudratronium
    Author

    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 result
    LC_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 error
    LC_ALL=C lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g' = EMPTY with no error

    The 'Model name' for AMD CPUs doesn't contain any value for speeds nor the "egrep" pattern....

  5. s-seitz commented on Aug 29, 2022

    @s-seitz

    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.

  6. Hudratronium commented on Aug 29, 2022

    @Hudratronium
    Author

    Thanks for your support anyway.
    Seems like this is the case.... Strange thing after a 'mere' update to encounter though.

  7. shwstppr commented on Aug 30, 2022

    @shwstppr
    Contributor

    @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:

    1. Using lscpu - output of the command - lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'
    2. Using cpu frequency file - content of file /sys/devices/system/cpu/cpu0/cpufreq/base_frequency
    3. From libvirt.
      In 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.0

  8. Hudratronium commented on Aug 30, 2022

    @Hudratronium
    Author

    @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

    1. Service Offerings haven't been working anymore (couldn't find useable hosts as the cpu speed was way to low)
    2. Migration tasks failed as no suitable hosts were availeable anymore
      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.mhz option in the agent.conf manually for our hosts.

    Regarding the outputs for the different checks performed by the agent:

    1. LSCPU script seems not to be working with AMD CPUs, as the "speed" isn't part of the name. lscpu would deliver correct values never the less - but one would need to check those / choose the "right" ones
    2. File is not availeable under Ubuntu 20.04 - at least for my AMD devices. I could offer something like cpuinfo_max_freq :-D
    3. The value from libvirt - which seemed to be kind of variable - was way off. As i don't know how / which value is used i can't really give a impression what values are returned in our setup. From our findings the scope was between 1,3GHz up to 2,7Ghz. All Hosts with the same CPU Modell and same "host"-configuration.
  9. shwstppr commented on Aug 30, 2022

    @shwstppr
    Contributor

    @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_freq but 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_freq is 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

  10. added this to the 4.17.1.0 milestone on Aug 30, 2022
  11. Hudratronium commented on Aug 30, 2022

    @Hudratronium
    Author

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

  12. shwstppr commented on Sep 1, 2022

    @shwstppr
    Contributor

    @Hudratronium can you please share complete output of lscpu so maybe we can check if it can use some other regex like CPU MHz or CPU max MHz from below,

    ⇒  lscpu                                
    Architecture:                    x86_64
    CPU op-mode(s):                  32-bit, 64-bit
    Byte Order:                      Little Endian
    Address sizes:                   39 bits physical, 48 bits virtual
    CPU(s):                          12
    On-line CPU(s) list:             0-11
    Thread(s) per core:              2
    Core(s) per socket:              6
    Socket(s):                       1
    NUMA node(s):                    1
    Vendor ID:                       GenuineIntel
    CPU family:                      6
    Model:                           158
    Model name:                      Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Stepping:                        10
    CPU MHz:                         900.006
    CPU max MHz:                     4100.0000
    CPU min MHz:                     800.0000
    BogoMIPS:                        4399.99
    

    Also, output of:
    virsh nodeinfo
    virsh sysinfo
    virsh capabilities

  13. Hudratronium commented on Sep 1, 2022

    @Hudratronium
    Author

    @shwstppr

    Will try to give as much inforamtion as possible:

    lscpu

    Architecture:                    x86_64
    CPU op-mode(s):                  32-bit, 64-bit
    Byte Order:                      Little Endian
    Address sizes:                   48 bits physical, 48 bits virtual
    CPU(s):                          48
    On-line CPU(s) list:             0-47
    Thread(s) per core:              2
    Core(s) per socket:              24
    Socket(s):                       1
    NUMA node(s):                    1
    Vendor ID:                       AuthenticAMD
    CPU family:                      25
    Model:                           1
    Model name:                      AMD EPYC 7413 24-Core Processor
    Stepping:                        1
    Frequency boost:                 enabled
    CPU MHz:                         2892.925
    CPU max MHz:                     2650.0000
    CPU min MHz:                     1500.0000
    BogoMIPS:                        5289.83
    Virtualization:                  AMD-V
    

    virsh nodeinfo

    CPU model:           x86_64
    CPU(s):              48
    CPU frequency:       1494 MHz
    CPU socket(s):       1
    Core(s) per socket:  24
    Thread(s) per core:  2
    NUMA cell(s):        1
    Memory size:         263476088 KiB
    

    virsh sysinfo

    <sysinfo type='smbios'>
      <processor>
        <entry name='socket_destination'>CPU1</entry>
        <entry name='type'>Central Processor</entry>
        <entry name='family'>Zen</entry>
        <entry name='manufacturer'>AMD</entry>
        <entry name='signature'>Family 25, Model 1, Stepping 1</entry>
        <entry name='version'>AMD EPYC 7413 24-Core Processor</entry>
        <entry name='external_clock'>2000 MHz</entry>
        <entry name='max_speed'>3900 MHz</entry>
        <entry name='status'>Populated, Enabled</entry>
        <entry name='serial_number'>Not Specified</entry>
        <entry name='part_number'>Not Specified</entry>
      </processor>
    </sysinfo>
    

    virsh capabilities

    <capabilities>
      <host>
        <cpu>
          <arch>x86_64</arch>
          <model>EPYC-Rome</model>
          <vendor>AMD</vendor>
          <microcode version='167776605'/>
          <counter name='tsc' frequency='2645030000'/>
          <topology sockets='1' cores='24' threads='2'/>
          <pages unit='KiB' size='4'/>
          <pages unit='KiB' size='2048'/>
          <pages unit='KiB' size='1048576'/>
        </cpu>
      </host>
    </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_pstate module 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 is acpi-cpufreq. Which supports the CPU max MHz. On the horizon, when the kernel version 5.17 will be used, out-of-the-box we shall see the module amd_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.

  14. weizhouapache commented on Sep 2, 2022

    @weizhouapache
    Member

    @shwstppr

    Will try to give as much inforamtion as possible:

    lscpu

    Architecture:                    x86_64
    CPU op-mode(s):                  32-bit, 64-bit
    Byte Order:                      Little Endian
    Address sizes:                   48 bits physical, 48 bits virtual
    CPU(s):                          48
    On-line CPU(s) list:             0-47
    Thread(s) per core:              2
    Core(s) per socket:              24
    Socket(s):                       1
    NUMA node(s):                    1
    Vendor ID:                       AuthenticAMD
    CPU family:                      25
    Model:                           1
    Model name:                      AMD EPYC 7413 24-Core Processor
    Stepping:                        1
    Frequency boost:                 enabled
    CPU MHz:                         2892.925
    CPU max MHz:                     2650.0000
    CPU min MHz:                     1500.0000
    BogoMIPS:                        5289.83
    Virtualization:                  AMD-V
    

    virsh nodeinfo

    CPU model:           x86_64
    CPU(s):              48
    CPU frequency:       1494 MHz
    CPU socket(s):       1
    Core(s) per socket:  24
    Thread(s) per core:  2
    NUMA cell(s):        1
    Memory size:         263476088 KiB
    

    virsh sysinfo

    <sysinfo type='smbios'>
      <processor>
        <entry name='socket_destination'>CPU1</entry>
        <entry name='type'>Central Processor</entry>
        <entry name='family'>Zen</entry>
        <entry name='manufacturer'>AMD</entry>
        <entry name='signature'>Family 25, Model 1, Stepping 1</entry>
        <entry name='version'>AMD EPYC 7413 24-Core Processor</entry>
        <entry name='external_clock'>2000 MHz</entry>
        <entry name='max_speed'>3900 MHz</entry>
        <entry name='status'>Populated, Enabled</entry>
        <entry name='serial_number'>Not Specified</entry>
        <entry name='part_number'>Not Specified</entry>
      </processor>
    </sysinfo>
    

    virsh capabilities

    <capabilities>
      <host>
        <cpu>
          <arch>x86_64</arch>
          <model>EPYC-Rome</model>
          <vendor>AMD</vendor>
          <microcode version='167776605'/>
          <counter name='tsc' frequency='2645030000'/>
          <topology sockets='1' cores='24' threads='2'/>
          <pages unit='KiB' size='4'/>
          <pages unit='KiB' size='2048'/>
          <pages unit='KiB' size='1048576'/>
        </cpu>
      </host>
    </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_pstate module 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 is acpi-cpufreq. Which supports the CPU max MHz. On the horizon, when the kernel version 5.17 will be used, out-of-the-box we shall see the module amd_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.

    thanks @Hudratronium

    it looks we could get correct value by lscpu or virsh capabilities

    CPU max MHz: 2650.0000

      <counter name='tsc' frequency='2645030000'/>
    
  15. shwstppr commented on Sep 2, 2022

    @shwstppr
    Contributor

    @weizhouapache virsh capabilities seem a better option as with my system I get CPU max MHz: 4100.0000 from lscpu while virsh capabilities return the correct value,

    ⇒  virsh capabilities 
    <capabilities>
    
      <host>
        <uuid>3956624c-2d45-11b2-a85c-dca73c02f24f</uuid>
        <cpu>
          <arch>x86_64</arch>
          <model>Skylake-Client-noTSX-IBRS</model>
          <vendor>Intel</vendor>
          <microcode version='240'/>
          <counter name='tsc' frequency='2207998000' scaling='no'/>
    
  16. weizhouapache commented on Sep 2, 2022

    @weizhouapache
    Member

    @weizhouapache virsh capabilities seem a better option as with my system I get CPU max MHz: 4100.0000 from lscpu while virsh capabilities return the correct value,

    ⇒  virsh capabilities 
    <capabilities>
    
      <host>
        <uuid>3956624c-2d45-11b2-a85c-dca73c02f24f</uuid>
        <cpu>
          <arch>x86_64</arch>
          <model>Skylake-Client-noTSX-IBRS</model>
          <vendor>Intel</vendor>
          <microcode version='240'/>
          <counter name='tsc' frequency='2207998000' scaling='no'/>
    

    @shwstppr
    good finding !

  17. added 2 commits that reference this issue on Sep 2, 2022
    3fece73
    b831f23
  18. shwstppr commented on Sep 6, 2022

    @shwstppr
    Contributor

    Fixed with #6696

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions