render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
9119d9
From 723e2b82385ad3c32c866ddc75198697f9bd2411 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <723e2b82385ad3c32c866ddc75198697f9bd2411@dist-git>
9119d9
From: Pavel Hrdina <phrdina@redhat.com>
9119d9
Date: Fri, 26 Sep 2014 12:44:00 +0200
9119d9
Subject: [PATCH] cputune_event: queue the event for cputune updates
9119d9
9119d9
Now we have universal tunable event so we can use it for reporting
9119d9
changes to user. The cputune values will be prefixed with "cputune" to
9119d9
distinguish it from other tunable events.
9119d9
9119d9
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
9119d9
(cherry picked from commit 0dce260cc81b284e1073688b6d7900040b679da2)
9119d9
9119d9
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1115898
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 include/libvirt/libvirt.h.in | 63 ++++++++++++++++++++++++++++++++++
9119d9
 src/qemu/qemu_cgroup.c       | 19 ++++++++++-
9119d9
 src/qemu/qemu_driver.c       | 81 ++++++++++++++++++++++++++++++++++++++++++++
9119d9
 3 files changed, 162 insertions(+), 1 deletion(-)
9119d9
9119d9
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
9119d9
index 56c665c..b78f110 100644
9119d9
--- a/include/libvirt/libvirt.h.in
9119d9
+++ b/include/libvirt/libvirt.h.in
9119d9
@@ -5168,6 +5168,66 @@ typedef void (*virConnectDomainEventDeviceRemovedCallback)(virConnectPtr conn,
9119d9
                                                            void *opaque);
9119d9
 
9119d9
 /**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_VCPUPIN:
9119d9
+ *
9119d9
+ * Macro represents formatted pinning for one vcpu specified by id which is
9119d9
+ * appended to the parameter name, for example "cputune.vcpupin1",
9119d9
+ * as VIR_TYPED_PARAM_STRING.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_VCPUPIN "cputune.vcpupin%u"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_EMULATORIN:
9119d9
+ *
9119d9
+ * Macro represents formatted pinning for emulator process,
9119d9
+ * as VIR_TYPED_PARAM_STRING.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_EMULATORIN "cputune.emulatorpin"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_CPU_SHARES:
9119d9
+ *
9119d9
+ * Macro represents proportional weight of the scheduler used on the
9119d9
+ * host cpu, when using the posix scheduler, as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_CPU_SHARES "cputune.cpu_shares"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_VCPU_PERIOD:
9119d9
+ *
9119d9
+ * Macro represents the enforcement period for a quota, in microseconds,
9119d9
+ * for vcpus only, when using the posix scheduler, as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_VCPU_PERIOD "cputune.vcpu_period"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_VCPU_QUOTA:
9119d9
+ *
9119d9
+ * Macro represents the maximum bandwidth to be used within a period for
9119d9
+ * vcpus only, when using the posix scheduler, as VIR_TYPED_PARAM_LLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_VCPU_QUOTA "cputune.vcpu_quota"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_PERIOD:
9119d9
+ *
9119d9
+ * Macro represents the enforcement period for a quota in microseconds,
9119d9
+ * when using the posix scheduler, for all emulator activity not tied to
9119d9
+ * vcpus, as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_PERIOD "cputune.emulator_period"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_QUOTA:
9119d9
+ *
9119d9
+ * Macro represents the maximum bandwidth to be used within a period for
9119d9
+ * all emulator activity not tied to vcpus, when using the posix scheduler,
9119d9
+ * as an VIR_TYPED_PARAM_LLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_QUOTA "cputune.emulator_quota"
9119d9
+
9119d9
+
9119d9
+/**
9119d9
  * virConnectDomainEventTunableCallback:
9119d9
  * @conn: connection object
9119d9
  * @dom: domain on which the event occurred
9119d9
@@ -5179,6 +5239,9 @@ typedef void (*virConnectDomainEventDeviceRemovedCallback)(virConnectPtr conn,
9119d9
  * be freed in the callback handler as it's done internally after the callback
9119d9
  * handler is executed.
9119d9
  *
9119d9
+ * Currently supported name spaces:
9119d9
+ *  "cputune.*"
9119d9
+ *
9119d9
  * The callback signature to use when registering for an event of type
9119d9
  * VIR_DOMAIN_EVENT_ID_TUNABLE with virConnectDomainEventRegisterAny()
9119d9
  */
9119d9
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
9119d9
index 7c6b2c1..300946a 100644
9119d9
--- a/src/qemu/qemu_cgroup.c
9119d9
+++ b/src/qemu/qemu_cgroup.c
9119d9
@@ -34,6 +34,7 @@
9119d9
 #include "virscsi.h"
9119d9
 #include "virstring.h"
9119d9
 #include "virfile.h"
9119d9
+#include "virtypedparam.h"
9119d9
 
9119d9
 #define VIR_FROM_THIS VIR_FROM_QEMU
9119d9
 
9119d9
@@ -676,6 +677,10 @@ static int
9119d9
 qemuSetupCpuCgroup(virDomainObjPtr vm)
9119d9
 {
9119d9
     qemuDomainObjPrivatePtr priv = vm->privateData;
9119d9
+    virObjectEventPtr event = NULL;
9119d9
+    virTypedParameterPtr eventParams = NULL;
9119d9
+    int eventNparams = 0;
9119d9
+    int eventMaxparams = 0;
9119d9
 
9119d9
     if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPU)) {
9119d9
        if (vm->def->cputune.sharesSpecified) {
9119d9
@@ -694,7 +699,19 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
9119d9
 
9119d9
         if (virCgroupGetCpuShares(priv->cgroup, &val) < 0)
9119d9
             return -1;
9119d9
-        vm->def->cputune.shares = val;
9119d9
+        if (vm->def->cputune.shares != val) {
9119d9
+            vm->def->cputune.shares = val;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_CPUTUNE_CPU_SHARES,
9119d9
+                                        val) < 0)
9119d9
+                return -1;
9119d9
+
9119d9
+            event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
9119d9
+        }
9119d9
+
9119d9
+        if (event)
9119d9
+            qemuDomainEventQueue(vm->privateData, event);
9119d9
     }
9119d9
 
9119d9
     return 0;
9119d9
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
9119d9
index 46be72c..663c98d 100644
9119d9
--- a/src/qemu/qemu_driver.c
9119d9
+++ b/src/qemu/qemu_driver.c
9119d9
@@ -4474,6 +4474,12 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
9119d9
     virBitmapPtr pcpumap = NULL;
9119d9
     virQEMUDriverConfigPtr cfg = NULL;
9119d9
     virCapsPtr caps = NULL;
9119d9
+    virObjectEventPtr event = NULL;
9119d9
+    char paramField[VIR_TYPED_PARAM_FIELD_LENGTH] = "";
9119d9
+    char *str = NULL;
9119d9
+    virTypedParameterPtr eventParams = NULL;
9119d9
+    int eventNparams = 0;
9119d9
+    int eventMaxparams = 0;
9119d9
 
9119d9
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
9119d9
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
9119d9
@@ -4581,6 +4587,18 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
9119d9
 
9119d9
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
9119d9
             goto cleanup;
9119d9
+
9119d9
+        if (snprintf(paramField, VIR_TYPED_PARAM_FIELD_LENGTH,
9119d9
+                     VIR_DOMAIN_EVENT_CPUTUNE_VCPUPIN, vcpu) < 0) {
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+
9119d9
+        str = virBitmapFormat(pcpumap);
9119d9
+        if (virTypedParamsAddString(&eventParams, &eventNparams,
9119d9
+                                    &eventMaxparams, paramField, str) < 0)
9119d9
+            goto cleanup;
9119d9
+
9119d9
+        event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
9119d9
     }
9119d9
 
9119d9
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
9119d9
@@ -4616,6 +4634,9 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
9119d9
         virCgroupFree(&cgroup_vcpu);
9119d9
     if (vm)
9119d9
         virObjectUnlock(vm);
9119d9
+    if (event)
9119d9
+        qemuDomainEventQueue(driver, event);
9119d9
+    VIR_FREE(str);
9119d9
     virBitmapFree(pcpumap);
9119d9
     virObjectUnref(caps);
9119d9
     virObjectUnref(cfg);
9119d9
@@ -4740,6 +4761,12 @@ qemuDomainPinEmulator(virDomainPtr dom,
9119d9
     virBitmapPtr pcpumap = NULL;
9119d9
     virQEMUDriverConfigPtr cfg = NULL;
9119d9
     virCapsPtr caps = NULL;
9119d9
+    virObjectEventPtr event = NULL;
9119d9
+    char * str = NULL;
9119d9
+    virTypedParameterPtr eventParams = NULL;
9119d9
+    int eventNparams = 0;
9119d9
+    int eventMaxparams = 0;
9119d9
+
9119d9
 
9119d9
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
9119d9
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
9119d9
@@ -4845,6 +4872,15 @@ qemuDomainPinEmulator(virDomainPtr dom,
9119d9
 
9119d9
         if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
9119d9
             goto cleanup;
9119d9
+
9119d9
+        str = virBitmapFormat(pcpumap);
9119d9
+        if (virTypedParamsAddString(&eventParams, &eventNparams,
9119d9
+                                    &eventMaxparams,
9119d9
+                                    VIR_DOMAIN_EVENT_CPUTUNE_EMULATORIN,
9119d9
+                                    str) < 0)
9119d9
+            goto cleanup;
9119d9
+
9119d9
+        event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
9119d9
     }
9119d9
 
9119d9
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
9119d9
@@ -4874,6 +4910,9 @@ qemuDomainPinEmulator(virDomainPtr dom,
9119d9
  cleanup:
9119d9
     if (cgroup_emulator)
9119d9
         virCgroupFree(&cgroup_emulator);
9119d9
+    if (event)
9119d9
+        qemuDomainEventQueue(driver, event);
9119d9
+    VIR_FREE(str);
9119d9
     virBitmapFree(pcpumap);
9119d9
     virObjectUnref(caps);
9119d9
     if (vm)
9119d9
@@ -9201,6 +9240,10 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
     virQEMUDriverConfigPtr cfg = NULL;
9119d9
     virCapsPtr caps = NULL;
9119d9
     qemuDomainObjPrivatePtr priv;
9119d9
+    virObjectEventPtr event = NULL;
9119d9
+    virTypedParameterPtr eventParams = NULL;
9119d9
+    int eventNparams = 0;
9119d9
+    int eventMaxNparams = 0;
9119d9
 
9119d9
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
9119d9
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
9119d9
@@ -9271,6 +9314,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
 
9119d9
                 vm->def->cputune.shares = val;
9119d9
                 vm->def->cputune.sharesSpecified = true;
9119d9
+
9119d9
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                            &eventMaxNparams,
9119d9
+                                            VIR_DOMAIN_EVENT_CPUTUNE_CPU_SHARES,
9119d9
+                                            val) < 0)
9119d9
+                    goto cleanup;
9119d9
             }
9119d9
 
9119d9
             if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
9119d9
@@ -9288,6 +9337,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
                     goto cleanup;
9119d9
 
9119d9
                 vm->def->cputune.period = value_ul;
9119d9
+
9119d9
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                            &eventMaxNparams,
9119d9
+                                            VIR_DOMAIN_EVENT_CPUTUNE_VCPU_PERIOD,
9119d9
+                                            value_ul) < 0)
9119d9
+                    goto cleanup;
9119d9
             }
9119d9
 
9119d9
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
9119d9
@@ -9302,6 +9357,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
                     goto cleanup;
9119d9
 
9119d9
                 vm->def->cputune.quota = value_l;
9119d9
+
9119d9
+                if (virTypedParamsAddLLong(&eventParams, &eventNparams,
9119d9
+                                           &eventMaxNparams,
9119d9
+                                           VIR_DOMAIN_EVENT_CPUTUNE_VCPU_QUOTA,
9119d9
+                                           value_l) < 0)
9119d9
+                    goto cleanup;
9119d9
             }
9119d9
 
9119d9
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
9119d9
@@ -9317,6 +9378,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
                     goto cleanup;
9119d9
 
9119d9
                 vm->def->cputune.emulator_period = value_ul;
9119d9
+
9119d9
+                if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                            &eventMaxNparams,
9119d9
+                                            VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_PERIOD,
9119d9
+                                            value_ul) < 0)
9119d9
+                    goto cleanup;
9119d9
             }
9119d9
 
9119d9
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
9119d9
@@ -9332,6 +9399,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
                     goto cleanup;
9119d9
 
9119d9
                 vm->def->cputune.emulator_quota = value_l;
9119d9
+
9119d9
+                if (virTypedParamsAddLLong(&eventParams, &eventNparams,
9119d9
+                                           &eventMaxNparams,
9119d9
+                                           VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_QUOTA,
9119d9
+                                           value_l) < 0)
9119d9
+                    goto cleanup;
9119d9
             }
9119d9
 
9119d9
             if (flags & VIR_DOMAIN_AFFECT_CONFIG)
9119d9
@@ -9342,6 +9415,12 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
     if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
9119d9
         goto cleanup;
9119d9
 
9119d9
+    if (eventNparams) {
9119d9
+        event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
9119d9
+        eventNparams = 0;
9119d9
+        if (event)
9119d9
+            qemuDomainEventQueue(driver, event);
9119d9
+    }
9119d9
 
9119d9
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
9119d9
         rc = virDomainSaveConfig(cfg->configDir, vmdef);
9119d9
@@ -9358,6 +9437,8 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
9119d9
     virDomainDefFree(vmdef);
9119d9
     if (vm)
9119d9
         virObjectUnlock(vm);
9119d9
+    if (eventNparams)
9119d9
+        virTypedParamsFree(eventParams, eventNparams);
9119d9
     virObjectUnref(caps);
9119d9
     virObjectUnref(cfg);
9119d9
     return ret;
9119d9
-- 
9119d9
2.1.1
9119d9