提交 ed504ba3 编写于 作者: M Michal Privoznik

virDomain{Get,Set}PerfEvents: support --config --live --current

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: NMichal Privoznik <mprivozn@redhat.com>
上级 30cd5983
...@@ -10054,9 +10054,12 @@ qemuDomainSetPerfEvents(virDomainPtr dom, ...@@ -10054,9 +10054,12 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
virPerfEventType type; virPerfEventType type;
bool enabled; 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; return -1;
if (!(vm = qemuDomObjFromDomain(dom))) if (!(vm = qemuDomObjFromDomain(dom)))
...@@ -10071,31 +10074,37 @@ qemuDomainSetPerfEvents(virDomainPtr dom, ...@@ -10071,31 +10074,37 @@ qemuDomainSetPerfEvents(virDomainPtr dom,
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < nparams; i++) { if (def) {
virTypedParameterPtr param = &params[i]; for (i = 0; i < nparams; i++) {
enabled = params->value.b; virTypedParameterPtr param = &params[i];
type = virPerfEventTypeFromString(param->field); enabled = params->value.b;
type = virPerfEventTypeFromString(param->field);
if (!enabled && virPerfEventDisable(priv->perf, type)) if (!enabled && virPerfEventDisable(priv->perf, type))
goto cleanup; goto cleanup;
if (enabled && virPerfEventEnable(priv->perf, type, vm->pid)) if (enabled && virPerfEventEnable(priv->perf, type, vm->pid))
goto cleanup; goto cleanup;
if (def) {
def->perf->events[type] = enabled ? def->perf->events[type] = enabled ?
VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; 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 ? persistentDef->perf->events[type] = enabled ?
VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO; 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; ret = 0;
...@@ -10112,39 +10121,53 @@ qemuDomainGetPerfEvents(virDomainPtr dom, ...@@ -10112,39 +10121,53 @@ qemuDomainGetPerfEvents(virDomainPtr dom,
int *nparams, int *nparams,
unsigned int flags) unsigned int flags)
{ {
size_t i;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
qemuDomainObjPrivatePtr priv; qemuDomainObjPrivatePtr priv;
int ret = -1; virDomainDefPtr def;
virTypedParameterPtr par = NULL; virTypedParameterPtr par = NULL;
int maxpar = 0; int maxpar = 0;
int npar = 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))) if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
priv = vm->privateData;
if (virDomainGetPerfEventsEnsureACL(dom->conn, vm->def) < 0) if (virDomainGetPerfEventsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup; goto cleanup;
if (!(def = virDomainObjGetOneDef(vm, flags)))
goto cleanup;
priv = vm->privateData;
for (i = 0; i < VIR_PERF_EVENT_LAST; i++) { 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, if (virTypedParamsAddBoolean(&par, &npar, &maxpar,
virPerfEventTypeToString(i), virPerfEventTypeToString(i),
virPerfEventIsEnabled(priv->perf, i)) < 0) { perf_enabled) < 0)
virTypedParamsFree(par, npar);
goto cleanup; goto cleanup;
}
} }
*params = par; *params = par;
*nparams = npar; *nparams = npar;
par = NULL;
npar = 0;
ret = 0; ret = 0;
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
virTypedParamsFree(par, npar);
return ret; return ret;
} }
......
...@@ -32,10 +32,6 @@ typedef enum { ...@@ -32,10 +32,6 @@ typedef enum {
VIR_ENUM_DECL(virPerfEvent); VIR_ENUM_DECL(virPerfEvent);
# define VIR_PERF_PARAMETERS \
VIR_PERF_PARAM_CMT, VIR_TYPED_PARAM_BOOLEAN, \
NULL
struct virPerf; struct virPerf;
typedef struct virPerf *virPerfPtr; typedef struct virPerf *virPerfPtr;
......
...@@ -8560,6 +8560,9 @@ static const vshCmdOptDef opts_perf[] = { ...@@ -8560,6 +8560,9 @@ static const vshCmdOptDef opts_perf[] = {
.type = VSH_OT_STRING, .type = VSH_OT_STRING,
.help = N_("perf events which will be disabled") .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} {.name = NULL}
}; };
...@@ -8601,6 +8604,17 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd) ...@@ -8601,6 +8604,17 @@ cmdPerf(vshControl *ctl, const vshCmd *cmd)
bool ret = false; bool ret = false;
const char *enable = NULL, *disable = NULL; const char *enable = NULL, *disable = NULL;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; 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))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
......
...@@ -2146,6 +2146,7 @@ Specifying -1 as a value for these limits is interpreted as unlimited. ...@@ -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>] =item B<perf> I<domain> [I<--enable> B<eventSpec>]
[I<--disable> B<eventSpec>] [I<--disable> B<eventSpec>]
[[I<--config>] [I<--live>] | [I<--current>]]
Get the current perf events setting or enable/disable specific perf Get the current perf events setting or enable/disable specific perf
events for a guest domain. events for a guest domain.
...@@ -2165,6 +2166,13 @@ separated by commas. However, just "cmt" event is supported presently. CMT is a ...@@ -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 PQos (Platform Qos) feature to monitor the usage of cache by applications
running on the platform. 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>] =item B<blkiotune> I<domain> [I<--weight> B<weight>]
[I<--device-weights> B<device-weights>] [I<--device-weights> B<device-weights>]
[I<--device-read-iops-sec> B<device-read-iops-sec>] [I<--device-read-iops-sec> B<device-read-iops-sec>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册