Damans227 commented on code in PR #14383:
URL: https://github.com/apache/cloudstack/pull/14383#discussion_r4259070914


##########
plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java:
##########
@@ -136,25 +146,30 @@ protected static long getCpuSpeed(final String 
cpabilities, final NodeInfo nodeI
         return speed;
     }
 
-    private static long getCpuSpeedFromCommandLscpu() {
+    /**
+     * Retrieves the CPU speed, in MHz, from the "lscpu" command. The base 
frequency advertised in the model name is preferred because the CPU speed is 
used to
+     * calculate the capacity of the host and the CPU quota of the VMs with 
CPU cap enabled; thus, it must be a frequency that the CPU is able to sustain.
+     * "CPU max MHz" may include the turbo frequency; therefore, it is only 
used when the model name does not advertise a frequency.
+     */
+    protected static long getCpuSpeedFromCommandLscpu() {
         long speed = 0L;
         LOGGER.info("Fetching CPU speed from command \"lscpu\".");
         try {
-            String command = "lscpu | grep -i 'CPU max MHz' | head -n 1 | sed 
's/^.*: //' | xargs";
+            String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep 
-o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
+            if(isHostS390x()) {
+                command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | 
tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";
+            }
             String result = Script.runSimpleBashScript(command);
-            speed = (long) (Float.parseFloat(result));
+            speed = (long) (Float.parseFloat(result) * 1000);
             LOGGER.info(String.format("Command [%s] resulted in the value [%s] 
for CPU speed.", command, speed));
             return speed;
         } catch (NullPointerException | NumberFormatException e) {
             LOGGER.error(String.format("Unable to retrieve the CPU speed from 
lscpu."), e);
         }
         try {
-            String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep 
-o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
-            if(isHostS390x()) {
-                command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | 
tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";
-            }
+            String command = LSCPU_CPU_MAX_MHZ_COMMAND;

Review Comment:
   amd model names have no GHz in them (e.g. "AMD EPYC 7763 64-Core 
Processor"), so amd hosts still land here and get the boost clock as host 
speed. same as before #12190, so fine for this pr, but is it on the list for 
the main follow-up?



##########
ui/public/locales/en.json:
##########
@@ -1215,6 +1215,7 @@
 "label.home": "Home",
 "label.host": "IP address",
 "label.host.alerts": "Hosts in alert state",
+"label.host.cpu.max.speed": "CPU maximum frequency (turbo)",

Review Comment:
   with acpi-cpufreq this is base + 1 MHz, as the description says, so the ui 
would show the base clock labelled as turbo. maybe drop "(turbo)" and just say 
"CPU maximum frequency"?



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