GabrielBrascher commented on a change in pull request #4178:
URL: https://github.com/apache/cloudstack/pull/4178#discussion_r447212031



##########
File path: 
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
##########
@@ -2297,12 +2297,32 @@ public LibvirtVMDef createVMFromSpec(final 
VirtualMachineTO vmTO) {
                 cmd.setFeatures(_cpuFeatures);
             }
             // multi cores per socket, for larger core configs
-            if (vcpus % 6 == 0) {
-                final int sockets = vcpus / 6;
-                cmd.setTopology(6, sockets);
-            } else if (vcpus % 4 == 0) {
-                final int sockets = vcpus / 4;
-                cmd.setTopology(4, sockets);
+            String coresPerSocket = null;
+            Boolean coresthreads = null;
+            if (vmTO.getDetails() != null) {
+                coresPerSocket = 
vmTO.getDetails().get(VmDetailConstants.CPU_CORE_PER_SOCKET);
+                coresthreads = 
Boolean.valueOf(vmTO.getDetails().get(VmDetailConstants.CPU_HYPERTHREADING));
+
+                s_logger.debug("user custom set coresPerSocket:" + 
coresPerSocket + ", coresThreads:" + coresthreads + "  ,   vmTO:" + 
vmTO.getUuid());
+            }
+            if (coresPerSocket != null) {
+                final int numCoresPerSocket = 
NumbersUtil.parseInt(coresPerSocket, 1);
+                if (vcpus % numCoresPerSocket == 0) {
+                    final int sockets = vcpus / numCoresPerSocket;
+                    if(coresthreads && numCoresPerSocket % 2 == 0) {
+                        cmd.setTopology(numCoresPerSocket /2, sockets,2);
+                    } else {
+                        cmd.setTopology(numCoresPerSocket, sockets);
+                    }
+                }
+            } else {
+                if (vcpus % 6 == 0) {
+                    final int sockets = vcpus / 6;
+                    cmd.setTopology(6, sockets);
+                } else if (vcpus % 4 == 0) {
+                    final int sockets = vcpus / 4;
+                    cmd.setTopology(4, sockets);
+                }

Review comment:
       What do you think of extracting lines 2300 - 2325 into a method? That 
would allow adding Javadoc and UNIT test.




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

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


Reply via email to