aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bbot/agent/machine.cxx23
1 files changed, 14 insertions, 9 deletions
diff --git a/bbot/agent/machine.cxx b/bbot/agent/machine.cxx
index af007ae..5ea5f1e 100644
--- a/bbot/agent/machine.cxx
+++ b/bbot/agent/machine.cxx
@@ -215,15 +215,20 @@ namespace bbot
if (sizeof (sockaddr_un::sun_path) <= monitor.size ())
throw invalid_argument ("monitor unix socket path too long");
- // Map logical CPUs to sockets/cores/threads. Failed that, QEMU just makes
- // it a machine with that number of sockets and some operating systems
- // (like Windows) only can do two.
+ // Map logical CPUs to sockets/cores/threads keeping the number of and
+ // cores even. Failed that, QEMU just makes it a machine with that number
+ // of sockets and some operating systems (like Windows) can only do two.
//
- size_t cpu (ops.cpu ());
+ // Note that for best results you may want to adjust (e.g., by over-
+ // committing) the number of CPUs to be power of 2.
+ //
+ size_t cpus (ops.cpu ()), cores (cpus);
+
+ size_t sockets (cores >= 16 && cores % 4 == 0 ? 2 :
+ cores >= 64 && cores % 8 == 0 ? 4 : 1);
+ cores /= sockets;
- size_t sockets (cpu <= 8 ? 1 : cpu <= 64 ? 2 : 4);
- size_t cores (cpu / sockets);
- size_t threads (cores <= 4 ? 1 : 2);
+ size_t threads (cores >= 8 && cores % 4 == 0 ? 2 : 1);
cores /= threads;
// We probably don't want to commit all the available RAM to the VM since
@@ -231,7 +236,7 @@ namespace bbot
// heuristics that we will use is 4G or 1G per CPU, whichever is greater
// and the rest divide equally between the host and the VM.
//
- size_t ram ((cpu < 4 ? 4 : cpu) * 1024 * 1024); // Kb.
+ size_t ram ((cpus < 4 ? 4 : cpus) * 1024 * 1024); // Kb.
if (ram > ops.ram ())
ram = ops.ram ();
@@ -308,7 +313,7 @@ namespace bbot
"-no-reboot", // Exit on VM reboot.
"-m", to_string (ram / 1024) + "M",
"-cpu", "host",
- "-smp", (to_string (cpu) +
+ "-smp", (to_string (cpus) +
",sockets=" + to_string (sockets) +
",cores=" + to_string (cores) +
",threads=" + to_string (threads)),