[PATCHv2 2/9] limit cpu bandwidth only for vcpus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes the behaviour of xml element cputune.period
and cputune.quota to limit cpu bandwidth only for vcpus, and no
longer limit cpu bandwidth for the whole guest.

The reasons to do this are:

  - This matches docs of cputune.period and cputune.quota.
  - The other parts excepting vcpus are treated as "hypervisor",
    and there are seperate period/quota settings for hypervisor
    in the subsequent patches
---
 src/qemu/qemu_cgroup.c |   34 ++++++-------------------
 src/qemu/qemu_driver.c |   66 ------------------------------------------------
 2 files changed, 8 insertions(+), 92 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 91dcedd..13163b6 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -490,11 +490,16 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, virDomainObjPtr vm)
     unsigned int i;
     unsigned long long period = vm->def->cputune.period;
     long long quota = vm->def->cputune.quota;
-    long long vm_quota = 0;
 
     if (driver->cgroup == NULL)
         return 0; /* Not supported, so claim success */
 
+    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
+        qemuReportError(VIR_ERR_SYSTEM_ERROR,
+                        _("cgroup cpu is not active"));
+        return -1;
+    }
+
     rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 0);
     if (rc != 0) {
         virReportSystemError(-rc,
@@ -503,26 +508,6 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, virDomainObjPtr vm)
         goto cleanup;
     }
 
-    /* Set cpu bandwidth for the vm */
-    if (period || quota) {
-        if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
-            /* Ensure that we can multiply by vcpus without overflowing. */
-            if (quota > LLONG_MAX / vm->def->vcpus) {
-                virReportSystemError(EINVAL,
-                                     _("%s"),
-                                     "Unable to set cpu bandwidth quota");
-                goto cleanup;
-            }
-
-            if (quota > 0)
-                vm_quota = quota * vm->def->vcpus;
-            else
-                vm_quota = quota;
-            if (qemuSetupCgroupCpuBandwidth(cgroup, period, vm_quota) < 0)
-                goto cleanup;
-        }
-    }
-
     if (priv->nvcpupids == 0 || priv->vcpupids[0] == vm->pid) {
         /* If we does not know VCPU<->PID mapping or all vcpu runs in the same
          * thread, we cannot control each vcpu.
@@ -551,16 +536,13 @@ int qemuSetupCgroupForVcpu(struct qemud_driver *driver, virDomainObjPtr vm)
         }
 
         if (period || quota) {
-            if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
-                if (qemuSetupCgroupCpuBandwidth(cgroup_vcpu, period, quota) < 0)
-                    goto cleanup;
-            }
+            if (qemuSetupCgroupCpuBandwidth(cgroup_vcpu, period, quota) < 0)
+                goto cleanup;
         }
 
         virCgroupFree(&cgroup_vcpu);
     }
 
-    virCgroupFree(&cgroup_vcpu);
     virCgroupFree(&cgroup);
     return 0;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b0b7816..c880f05 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7123,70 +7123,10 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virCgroupPtr cgroup_vcpu = NULL;
     int rc;
-    long long vm_quota = 0;
-    long long old_quota = 0;
-    unsigned long long old_period = 0;
 
     if (period == 0 && quota == 0)
         return 0;
 
-    /* Ensure that we can multiply by vcpus without overflowing. */
-    if (quota > LLONG_MAX / vm->def->vcpus) {
-        virReportSystemError(EINVAL,
-                             _("%s"),
-                             "Unable to set cpu bandwidth quota");
-        goto cleanup;
-    }
-
-    if (quota > 0)
-        vm_quota = quota * vm->def->vcpus;
-    else
-        vm_quota = quota;
-
-    rc = virCgroupGetCpuCfsQuota(cgroup, &old_quota);
-    if (rc < 0) {
-        virReportSystemError(-rc, "%s",
-                             _("unable to get cpu bandwidth tunable"));
-        goto cleanup;
-    }
-
-    rc = virCgroupGetCpuCfsPeriod(cgroup, &old_period);
-    if (rc < 0) {
-        virReportSystemError(-rc, "%s",
-                             _("unable to get cpu bandwidth period tunable"));
-        goto cleanup;
-    }
-
-    /*
-     * If quota will be changed to a small value, we should modify vcpu's quota
-     * first. Otherwise, we should modify vm's quota first.
-     *
-     * If period will be changed to a small value, we should modify vm's period
-     * first. Otherwise, we should modify vcpu's period first.
-     *
-     * If both quota and period will be changed to a big/small value, we cannot
-     * modify period and quota together.
-     */
-    if ((quota != 0) && (period != 0)) {
-        if (((quota > old_quota) && (period > old_period)) ||
-            ((quota < old_quota) && (period < old_period))) {
-            /* modify period */
-            if (qemuSetVcpusBWLive(vm, cgroup, period, 0) < 0)
-                goto cleanup;
-
-            /* modify quota */
-            if (qemuSetVcpusBWLive(vm, cgroup, 0, quota) < 0)
-                goto cleanup;
-            return 0;
-        }
-    }
-
-    if (((vm_quota != 0) && (vm_quota > old_quota)) ||
-        ((period != 0) && (period < old_period)))
-        /* Set cpu bandwidth for the vm */
-        if (qemuSetupCgroupCpuBandwidth(cgroup, period, vm_quota) < 0)
-            goto cleanup;
-
     /* If we does not know VCPU<->PID mapping or all vcpu runs in the same
      * thread, we cannot control each vcpu. So we only modify cpu bandwidth
      * when each vcpu has a separated thread.
@@ -7209,12 +7149,6 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
         }
     }
 
-    if (((vm_quota != 0) && (vm_quota <= old_quota)) ||
-        ((period != 0) && (period >= old_period)))
-        /* Set cpu bandwidth for the vm */
-        if (qemuSetupCgroupCpuBandwidth(cgroup, period, vm_quota) < 0)
-            goto cleanup;
-
     return 0;
 
 cleanup:
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]