Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/vm/VmDetailConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public interface VmDetailConstants {
String SSH_PUBLIC_KEY = "SSH.PublicKey";
String PASSWORD = "password";
String ENCRYPTED_PASSWORD = "Encrypted.Password";
String CPU_HYPERTHREADING = "cpu.hyperthreading";

// VM import with nic, disk and custom params for custom compute offering
String NIC = "nic";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Copy link
Member

@GabrielBrascher GabrielBrascher Jun 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of extracting lines 2300 - 2325 into a method, document, and then create JUnit tests for the new method(s)?

}
vm.addComp(cmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,7 @@ public static class CpuModeDef {
private List<String> _features;
private int _coresPerSocket = -1;
private int _sockets = -1;
private int _threads = 1;

public void setMode(String mode) {
_mode = mode;
Expand All @@ -1501,6 +1502,12 @@ public void setTopology(int coresPerSocket, int sockets) {
_sockets = sockets;
}

public void setTopology(int coresPerSocket, int sockets, int threads) {
_coresPerSocket = coresPerSocket;
_sockets = sockets;
_threads = threads;
}

@Override
public String toString() {
StringBuilder modeBuilder = new StringBuilder();
Expand Down Expand Up @@ -1528,7 +1535,7 @@ public String toString() {

// add topology
if (_sockets > 0 && _coresPerSocket > 0) {
modeBuilder.append("<topology sockets='" + _sockets + "' cores='" + _coresPerSocket + "' threads='1' />");
modeBuilder.append("<topology sockets='" + _sockets + "' cores='" + _coresPerSocket + "' threads=' " + _threads + "' />");
}

// close cpu def
Expand Down