]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomain{Get,Set}PerfEvents: support --config --live --current
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 30 Mar 2016 16:33:29 +0000 (18:33 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 31 Mar 2016 08:42:46 +0000 (10:42 +0200)
Now that we have @flags we can support changing perf events just
in active or inactive configuration regardless of the other.
Previously, calling virDomainSetPerfEvents set events in both
active and inactive configuration at once. Even though we allow
users to set perf events that are to be enabled once domain is
started up. The virDomainGetPerfEvents API was flawed too. It
returned just runtime info.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_driver.c
src/util/virperf.h
tools/virsh-domain.c
tools/virsh.pod

index cbd520b52c7baaac5788247c490562a7102b7e18..c80f1dae363e4be5b0d0e2cbdf8cae1c9b639e88 100644 (file)
@@ -10054,9 +10054,12 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
     virPerfEventType type;
     bool enabled;
 
-    virCheckFlags(0, -1);
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
 
-    if (virTypedParamsValidate(params, nparams, VIR_PERF_PARAMETERS) < 0)
+    if (virTypedParamsValidate(params, nparams,
+                               VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN,
+                               NULL) < 0)
         return -1;
 
     if (!(vm = qemuDomObjFromDomain(dom)))
@@ -10071,31 +10074,37 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
     if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
         goto cleanup;
 
-    for (i = 0; i < nparams; i++) {
-        virTypedParameterPtr param = &params[i];
-        enabled = params->value.b;
-        type = virPerfEventTypeFromString(param->field);
+    if (def) {
+        for (i = 0; i < nparams; i++) {
+            virTypedParameterPtr param = &params[i];
+            enabled = params->value.b;
+            type = virPerfEventTypeFromString(param->field);
 
-        if (!enabled && virPerfEventDisable(priv->perf, type))
-            goto cleanup;
-        if (enabled && virPerfEventEnable(priv->perf, type, vm->pid))
-            goto cleanup;
+            if (!enabled && virPerfEventDisable(priv->perf, type))
+                goto cleanup;
+            if (enabled && virPerfEventEnable(priv->perf, type, vm->pid))
+                goto cleanup;
 
-        if (def) {
             def->perf->events[type] = enabled ?
                 VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
-
-            if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
-                goto cleanup;
         }
 
-        if (persistentDef) {
+        if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
+            goto cleanup;
+    }
+
+    if (persistentDef) {
+        for (i = 0; i < nparams; i++) {
+            virTypedParameterPtr param = &params[i];
+            enabled = params->value.b;
+            type = virPerfEventTypeFromString(param->field);
+
             persistentDef->perf->events[type] = enabled ?
                 VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
-
-            if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
-                goto cleanup;
         }
+
+        if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
+            goto cleanup;
     }
 
     ret = 0;
@@ -10112,39 +10121,53 @@ qemuDomainGetPerfEvents(virDomainPtr dom,
                         int *nparams,
                         unsigned int flags)
 {
-    size_t i;
     virDomainObjPtr vm = NULL;
     qemuDomainObjPrivatePtr priv;
-    int ret = -1;
+    virDomainDefPtr def;
     virTypedParameterPtr par = NULL;
     int maxpar = 0;
     int npar = 0;
+    size_t i;
+    int ret = -1;
 
-    virCheckFlags(0, -1);
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_TYPED_PARAM_STRING_OKAY, -1);
 
     if (!(vm = qemuDomObjFromDomain(dom)))
         goto cleanup;
 
-    priv = vm->privateData;
-
     if (virDomainGetPerfEventsEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
+    if (!(def = virDomainObjGetOneDef(vm, flags)))
+        goto cleanup;
+
+    priv = vm->privateData;
+
     for (i = 0; i < VIR_PERF_EVENT_LAST; i++) {
+        bool perf_enabled;
+
+        if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+            perf_enabled = def->perf->events[i] == VIR_TRISTATE_BOOL_YES;
+        else
+            perf_enabled = virPerfEventIsEnabled(priv->perf, i);
+
         if (virTypedParamsAddBoolean(&par, &npar, &maxpar,
                                      virPerfEventTypeToString(i),
-                                     virPerfEventIsEnabled(priv->perf, i)) < 0) {
-            virTypedParamsFree(par, npar);
+                                     perf_enabled) < 0)
             goto cleanup;
-        }
     }
 
     *params = par;
     *nparams = npar;
+    par = NULL;
+    npar = 0;
     ret = 0;
 
  cleanup:
     virDomainObjEndAPI(&vm);
+    virTypedParamsFree(par, npar);
     return ret;
 }
 
index 4c36b78f3d41c7083397aea0f2369e006c16f2f0..8ec87530b94a125c3bcd45e945e9c44e5fec96d1 100644 (file)
@@ -32,10 +32,6 @@ typedef enum {
 
 VIR_ENUM_DECL(virPerfEvent);
 
-# define VIR_PERF_PARAMETERS                                   \
-    VIR_PERF_PARAM_CMT,              VIR_TYPED_PARAM_BOOLEAN,   \
-    NULL
-
 struct virPerf;
 typedef struct virPerf *virPerfPtr;
 
index f3aa1bb592ef6a611bb22e453185732ac405e5b0..d0d2dd08d973e5ce040a9d9b57bcc8cd66ef3758 100644 (file)
@@ -8560,6 +8560,9 @@ static const vshCmdOptDef opts_perf[] = {
      .type = VSH_OT_STRING,
      .help = N_("perf events which will be disabled")
     },
+    VIRSH_COMMON_OPT_DOMAIN_CONFIG,
+    VIRSH_COMMON_OPT_DOMAIN_LIVE,
+    VIRSH_COMMON_OPT_DOMAIN_CURRENT,
     {.name = NULL}
 };
 
@@ -8601,6 +8604,17 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     const char *enable = NULL, *disable = NULL;
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    bool current = vshCommandOptBool(cmd, "current");
+    bool config = vshCommandOptBool(cmd, "config");
+    bool live = vshCommandOptBool(cmd, "live");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+    VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+    if (config)
+        flags |= VIR_DOMAIN_AFFECT_CONFIG;
+    if (live)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
index a9915b09f469ceff9c677023e66ffd6b07e87a41..d2cc5b2946cf0a77c81dddd72de2986143fc3be5 100644 (file)
@@ -2146,6 +2146,7 @@ Specifying -1 as a value for these limits is interpreted as unlimited.
 
 =item B<perf> I<domain> [I<--enable> B<eventSpec>]
 [I<--disable> B<eventSpec>]
+[[I<--config>] [I<--live>] | [I<--current>]]
 
 Get the current perf events setting or enable/disable specific perf
 events for a guest domain.
@@ -2165,6 +2166,13 @@ separated by commas. However, just "cmt" event is supported presently. CMT is a
 PQos (Platform Qos) feature to monitor the usage of cache by applications
 running on the platform.
 
+If I<--live> is specified, affect a running guest.
+If I<--config> is specified, affect the next boot of a persistent guest.
+If I<--current> is specified, affect the current guest state.
+Both I<--live> and I<--config> flags may be given, but I<--current> is
+exclusive. If no flag is specified, behavior is different depending
+on hypervisor.
+
 =item B<blkiotune> I<domain> [I<--weight> B<weight>]
 [I<--device-weights> B<device-weights>]
 [I<--device-read-iops-sec> B<device-read-iops-sec>]