diff --git a/lib/constants.py b/lib/constants.py index 86b4fd651f735a899a253991995e0766beac7e2c..9738033bb33811e19ef2940e60abeb12f3944afc 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -704,6 +704,9 @@ HV_PASSTHROUGH = "pci_pass" HV_BLOCKDEV_PREFIX = "blockdev_prefix" HV_REBOOT_BEHAVIOR = "reboot_behavior" HV_CPU_TYPE = "cpu_type" +HV_CPU_CAP = "cpu_cap" +HV_CPU_WEIGHT = "cpu_weight" + HVS_PARAMETER_TYPES = { HV_BOOT_ORDER: VTYPE_STRING, @@ -760,6 +763,8 @@ HVS_PARAMETER_TYPES = { HV_BLOCKDEV_PREFIX: VTYPE_STRING, HV_REBOOT_BEHAVIOR: VTYPE_STRING, HV_CPU_TYPE: VTYPE_STRING, + HV_CPU_CAP: VTYPE_INT, + HV_CPU_WEIGHT: VTYPE_INT, } HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys()) @@ -1701,6 +1706,8 @@ HVC_DEFAULTS = { HV_BLOCKDEV_PREFIX: "sd", HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED, HV_CPU_MASK: CPU_PINNING_ALL, + HV_CPU_CAP: 0, + HV_CPU_WEIGHT: 256, }, HT_XEN_HVM: { HV_BOOT_ORDER: "cd", @@ -1720,6 +1727,8 @@ HVC_DEFAULTS = { HV_PASSTHROUGH: "", HV_REBOOT_BEHAVIOR: INSTANCE_REBOOT_ALLOWED, HV_CPU_MASK: CPU_PINNING_ALL, + HV_CPU_CAP: 0, + HV_CPU_WEIGHT: 256, }, HT_KVM: { HV_KERNEL_PATH: KVM_KERNEL, diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 0f3daec2571d76f6c9475ebb70e40d5f454a61a7..57dcc20d91bccd9a1d513be061d17e5f39b80dbe 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -630,6 +630,9 @@ class XenPvmHypervisor(XenHypervisor): constants.HV_REBOOT_BEHAVIOR: hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS), constants.HV_CPU_MASK: hv_base.OPT_MULTI_CPU_MASK_CHECK, + constants.HV_CPU_CAP: hv_base.NO_CHECK, + constants.HV_CPU_WEIGHT: + (False, lambda x: 0 < x < 65536, "invalid weight", None, None), } @classmethod @@ -672,6 +675,12 @@ class XenPvmHypervisor(XenHypervisor): cpu_pinning = cls._CreateConfigCpus(hvp[constants.HV_CPU_MASK]) if cpu_pinning: config.write("%s\n" % cpu_pinning) + cpu_cap = hvp[constants.HV_CPU_CAP] + if cpu_cap: + config.write("cpu_cap=%d\n" % cpu_cap) + cpu_weight = hvp[constants.HV_CPU_WEIGHT] + if cpu_weight: + config.write("cpu_weight=%d\n" % cpu_weight) config.write("name = '%s'\n" % instance.name) @@ -743,6 +752,9 @@ class XenHvmHypervisor(XenHypervisor): constants.HV_REBOOT_BEHAVIOR: hv_base.ParamInSet(True, constants.REBOOT_BEHAVIORS), constants.HV_CPU_MASK: hv_base.OPT_MULTI_CPU_MASK_CHECK, + constants.HV_CPU_CAP: hv_base.NO_CHECK, + constants.HV_CPU_WEIGHT: + (False, lambda x: 0 < x < 65535, "invalid weight", None, None), } @classmethod @@ -766,6 +778,12 @@ class XenHvmHypervisor(XenHypervisor): cpu_pinning = cls._CreateConfigCpus(hvp[constants.HV_CPU_MASK]) if cpu_pinning: config.write("%s\n" % cpu_pinning) + cpu_cap = hvp[constants.HV_CPU_CAP] + if cpu_cap: + config.write("cpu_cap=%d\n" % cpu_cap) + cpu_weight = hvp[constants.HV_CPU_WEIGHT] + if cpu_weight: + config.write("cpu_weight=%d\n" % cpu_weight) config.write("name = '%s'\n" % instance.name) if hvp[constants.HV_PAE]: diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst index 7e2bda2dce596d199b95a8f9980adfdf067f195d..acedb5b26047b764ae35eb373815f5457c562cff 100644 --- a/man/gnt-instance.rst +++ b/man/gnt-instance.rst @@ -587,6 +587,18 @@ cpu\_mask # Turn off CPU pinning (default setting) gnt-instance modify -H cpu_mask=all my-inst +cpu\_cap + Valid for the Xen hypervisor. + + Set the maximum amount of cpu usage by the VM. The value is a percentage + between 0 and (100 * number of VCPUs). Default cap is 0: unlimited. + +cpu\_weight + Valid for the Xen hypervisor. + + Set the cpu time ratio to be allocated to the VM. Valid values are + between 1 and 65535. Default weight is 256. + usb\_mouse Valid for the KVM hypervisor.