You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/09/24 10:11:16 UTC

[GitHub] [cloudstack] weizhouapache commented on a change in pull request #5506: kvm: Use lscpu to get cpu max speed

weizhouapache commented on a change in pull request #5506:
URL: https://github.com/apache/cloudstack/pull/5506#discussion_r715489059



##########
File path: plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java
##########
@@ -85,8 +87,18 @@ protected static long getCpuSpeed(final NodeInfo nodeInfo) {
             LOGGER.info(String.format("Retrieved value [%s] from file [%s]. This corresponds to a CPU speed of [%s] MHz.", cpuInfoMaxFreq, cpuInfoMaxFreqFileName, cpuInfoMaxFreq / 1000));
             return cpuInfoMaxFreq / 1000;
         } catch (IOException | NumberFormatException e) {
-            LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Using the value [%s] provided by the Libvirt.", cpuInfoMaxFreqFileName, nodeInfo.mhz), e);
-            return nodeInfo.mhz;
+            try {
+                LOGGER.error(String.format("Unable to retrieve the CPU speed from file [%s]. Trying to fetch it from lscpu",
+                    cpuInfoMaxFreqFileName), e);
+                String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";

Review comment:
       @rhtyd @davidjumani 
   
   there are multiple ways to get the cpu speed. 
   
   while(true);do cat /proc/cpuinfo |grep 'cpu MHz' |head -n1;sleep 0.1;done
   while(true);do virsh nodeinfo |grep 'CPU frequency';sleep 0.1;done
   
   it looks the result by `lscpu` is most stable. I am not sure if it works for all cpu models.
   
   it seems we should not get cpu speed from `/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq`. If cpu supports Intel Turbo Boost Technology, it is the max cpu frequency not the normal cpu frequency.  for example, on my laptop
   ```
   $ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
   4700000
   $ virsh nodeinfo |grep 'CPU frequency'
   CPU frequency:       2800 MHz
   $ cat /proc/cpuinfo |grep 'cpu MHz' |head -n1
   cpu MHz		: 2800.000
   ```
   
   my opinion is: lscpu > nodeInfo.mhz (libvirt-java) -> /proc/cpuinfo > cpuinfo_max_freq




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org