Skip to content

Commit fb22c5c

Browse files
authored
kvm: correctly set vm cpu topology (apache#6870)
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 4588835 commit fb22c5c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2629,7 +2629,8 @@ private CpuModeDef createCpuModeDef(VirtualMachineTO vmTO, int vcpus) {
26292629
if (VirtualMachine.Type.User.equals(vmTO.getType())) {
26302630
cmd.setFeatures(_cpuFeatures);
26312631
}
2632-
setCpuTopology(cmd, vcpus, vmTO.getDetails());
2632+
int vCpusInDef = vmTO.getVcpuMaxLimit() == null ? vcpus : vmTO.getVcpuMaxLimit();
2633+
setCpuTopology(cmd, vCpusInDef, vmTO.getDetails());
26332634
return cmd;
26342635
}
26352636

@@ -4706,7 +4707,7 @@ public boolean isSecureMode(String bootMode) {
47064707
return false;
47074708
}
47084709

4709-
private void setCpuTopology(CpuModeDef cmd, int vcpus, Map<String, String> details) {
4710+
private void setCpuTopology(CpuModeDef cmd, int vCpusInDef, Map<String, String> details) {
47104711
if (!enableManuallySettingCpuTopologyOnKvmVm) {
47114712
s_logger.debug(String.format("Skipping manually setting CPU topology on VM's XML due to it is disabled in agent.properties {\"property\": \"%s\", \"value\": %s}.",
47124713
AgentProperties.ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM.getName(), enableManuallySettingCpuTopologyOnKvmVm));
@@ -4717,19 +4718,19 @@ private void setCpuTopology(CpuModeDef cmd, int vcpus, Map<String, String> detai
47174718
if (details != null) {
47184719
final String coresPerSocket = details.get(VmDetailConstants.CPU_CORE_PER_SOCKET);
47194720
final int intCoresPerSocket = NumbersUtil.parseInt(coresPerSocket, numCoresPerSocket);
4720-
if (intCoresPerSocket > 0 && vcpus % intCoresPerSocket == 0) {
4721+
if (intCoresPerSocket > 0 && vCpusInDef % intCoresPerSocket == 0) {
47214722
numCoresPerSocket = intCoresPerSocket;
47224723
}
47234724
}
47244725
if (numCoresPerSocket <= 0) {
4725-
if (vcpus % 6 == 0) {
4726+
if (vCpusInDef % 6 == 0) {
47264727
numCoresPerSocket = 6;
4727-
} else if (vcpus % 4 == 0) {
4728+
} else if (vCpusInDef % 4 == 0) {
47284729
numCoresPerSocket = 4;
47294730
}
47304731
}
47314732
if (numCoresPerSocket > 0) {
4732-
cmd.setTopology(numCoresPerSocket, vcpus / numCoresPerSocket);
4733+
cmd.setTopology(numCoresPerSocket, vCpusInDef / numCoresPerSocket);
47334734
}
47344735
}
47354736

0 commit comments

Comments
 (0)