winterhazel commented on code in PR #14383:
URL: https://github.com/apache/cloudstack/pull/14383#discussion_r4354599366
##########
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:
Yes, see #14384.
--
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]