kvm: allow setting smp cores, threads, sockets
authorGuido Trotter <ultrotter@google.com>
Fri, 11 Jan 2013 15:49:11 +0000 (16:49 +0100)
committerGuido Trotter <ultrotter@google.com>
Mon, 14 Jan 2013 14:03:14 +0000 (15:03 +0100)
This was requested in Issue 322.
Note that maxcpus is not implemented yet, as it should be considered in
a cpu-hotplug global context.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/constants.py
lib/hypervisor/hv_kvm.py
man/gnt-instance.rst

index 759ab3e..3b48426 100644 (file)
@@ -827,6 +827,9 @@ HV_REBOOT_BEHAVIOR = "reboot_behavior"
 HV_CPU_TYPE = "cpu_type"
 HV_CPU_CAP = "cpu_cap"
 HV_CPU_WEIGHT = "cpu_weight"
+HV_CPU_CORES = "cpu_cores"
+HV_CPU_THREADS = "cpu_threads"
+HV_CPU_SOCKETS = "cpu_sockets"
 
 
 HVS_PARAMETER_TYPES = {
@@ -887,6 +890,9 @@ HVS_PARAMETER_TYPES = {
   HV_CPU_TYPE: VTYPE_STRING,
   HV_CPU_CAP: VTYPE_INT,
   HV_CPU_WEIGHT: VTYPE_INT,
+  HV_CPU_CORES: VTYPE_INT,
+  HV_CPU_THREADS: VTYPE_INT,
+  HV_CPU_SOCKETS: VTYPE_INT,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -1951,6 +1957,9 @@ HVC_DEFAULTS = {
     HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED,
     HV_CPU_MASK: CPU_PINNING_ALL,
     HV_CPU_TYPE: "",
+    HV_CPU_CORES: 0,
+    HV_CPU_THREADS: 0,
+    HV_CPU_SOCKETS: 0,
     },
   HT_FAKE: {},
   HT_CHROOT: {
index e77d1c2..8087d49 100644 (file)
@@ -532,6 +532,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS),
     constants.HV_CPU_MASK: hv_base.OPT_MULTI_CPU_MASK_CHECK,
     constants.HV_CPU_TYPE: hv_base.NO_CHECK,
+    constants.HV_CPU_CORES: hv_base.NO_CHECK,
+    constants.HV_CPU_THREADS: hv_base.NO_CHECK,
+    constants.HV_CPU_SOCKETS: hv_base.NO_CHECK,
     }
 
   _MIGRATION_STATUS_RE = re.compile("Migration\s+status:\s+(\w+)",
@@ -617,7 +620,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       elif arg == "-m":
         memory = int(arg_list.pop(0))
       elif arg == "-smp":
-        vcpus = int(arg_list.pop(0))
+        vcpus = int(arg_list.pop(0).split(",")[0])
 
     if instance is None:
       raise errors.HypervisorError("Pid %s doesn't contain a ganeti kvm"
@@ -1000,8 +1003,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         done in L{_ExecuteKVMRuntime}
 
     """
-    # pylint: disable=R0914,R0915
+    # pylint: disable=R0912,R0914,R0915
     _, v_major, v_min, _ = self._GetKVMVersion()
+    hvp = instance.hvparams
 
     pidfile = self._InstancePidFile(instance.name)
     kvm = constants.KVM_PATH
@@ -1010,7 +1014,17 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     # used just by the vnc server, if enabled
     kvm_cmd.extend(["-name", instance.name])
     kvm_cmd.extend(["-m", instance.beparams[constants.BE_MAXMEM]])
-    kvm_cmd.extend(["-smp", instance.beparams[constants.BE_VCPUS]])
+
+    smp_list = ["%s" % instance.beparams[constants.BE_VCPUS]]
+    if hvp[constants.HV_CPU_CORES]:
+      smp_list.append("cores=%s" % hvp[constants.HV_CPU_CORES])
+    if hvp[constants.HV_CPU_THREADS]:
+      smp_list.append("threads=%s" % hvp[constants.HV_CPU_THREADS])
+    if hvp[constants.HV_CPU_SOCKETS]:
+      smp_list.append("sockets=%s" % hvp[constants.HV_CPU_SOCKETS])
+
+    kvm_cmd.extend(["-smp", ",".join(smp_list)])
+
     kvm_cmd.extend(["-pidfile", pidfile])
     kvm_cmd.extend(["-balloon", "virtio"])
     kvm_cmd.extend(["-daemonize"])
@@ -1020,7 +1034,6 @@ class KVMHypervisor(hv_base.BaseHypervisor):
         constants.INSTANCE_REBOOT_EXIT:
       kvm_cmd.extend(["-no-reboot"])
 
-    hvp = instance.hvparams
     kernel_path = hvp[constants.HV_KERNEL_PATH]
     if kernel_path:
       boot_disk = boot_cdrom = boot_floppy = boot_network = False
index f22ee5d..6e40d37 100644 (file)
@@ -634,6 +634,21 @@ reboot\_behavior
 
     It is set to ``reboot`` by default.
 
+cpu\_cores
+    Valid for the KVM hypervisor.
+
+    Number of emulated CPU cores.
+
+cpu\_threads
+    Valid for the KVM hypervisor.
+
+    Number of emulated CPU threads.
+
+cpu\_sockets
+    Valid for the KVM hypervisor.
+
+    Number of emulated CPU sockets.
+
 
 The ``-O (--os-parameters)`` option allows customisation of the OS
 parameters. The actual parameter names and values depends on the OS