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. you can try following commands
   
   ```
   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
   $ lscpu | grep -i 'Model name' | head -n 1 | egrep -o 
'[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'
   2.80
   ```
   
   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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to