From: Joao Martins <joao.m.martins@oracle.com>
To: Jim Fehlig <jfehlig@suse.com>, libvir-list@redhat.com
Cc: xen-devel@lists.xen.org
Subject: Re: [PATCH v3 1/8] libxl: implement virDomainGetCPUStats
Date: Tue, 17 Nov 2015 10:58:04 +0000 [thread overview]
Message-ID: <564B083C.1050002@oracle.com> (raw)
In-Reply-To: <564A9815.9080705@suse.com>
On 11/17/2015 02:59 AM, Jim Fehlig wrote:
> On 11/13/2015 06:14 AM, Joao Martins wrote:
>> Introduce support for domainGetCPUStats API call and consequently
>> allow us to use `virsh cpu-stats`. The latter returns a more brief
>> output than the one provided by`virsh vcpuinfo`.
>>
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>> Changes since v1:
>> - Remove libxl_vcpuinfo_dispose() in favor or using
>> libxl_vcpuinfo_list_free(), and also removing VIR_FREE call
>> - Dispose libxl_dominfo after succesfull call to
>> libxl_domain_info()
>> - Fixed identation of parameters
>> - Bump version to 1.2.22
>> ---
>> src/libxl/libxl_driver.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 110 insertions(+)
>>
>> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
>> index fcdcbdb..50f6e34 100644
>> --- a/src/libxl/libxl_driver.c
>> +++ b/src/libxl/libxl_driver.c
>> @@ -73,6 +73,8 @@ VIR_LOG_INIT("libxl.libxl_driver");
>> #define LIBXL_CONFIG_FORMAT_XM "xen-xm"
>> #define LIBXL_CONFIG_FORMAT_SEXPR "xen-sxpr"
>>
>> +#define LIBXL_NB_TOTAL_CPU_STAT_PARAM 1
>> +
>> #define HYPERVISOR_CAPABILITIES "/proc/xen/capabilities"
>> #define HYPERVISOR_XENSTORED "/dev/xen/xenstored"
>>
>> @@ -4641,6 +4643,113 @@ libxlDomainIsUpdated(virDomainPtr dom)
>> }
>>
>> static int
>> +libxlDomainGetTotalCPUStats(libxlDriverPrivatePtr driver,
>> + virDomainObjPtr vm,
>> + virTypedParameterPtr params,
>> + unsigned int nparams)
>> +{
>> + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
>> + libxl_dominfo d_info;
>> + int ret = -1;
>> +
>> + if (nparams == 0)
>> + return LIBXL_NB_TOTAL_CPU_STAT_PARAM;
>> +
>> + if (libxl_domain_info(cfg->ctx, &d_info, vm->def->id) != 0) {
>> + virReportError(VIR_ERR_INTERNAL_ERROR,
>> + _("libxl_domain_info failed for domain '%d'"),
>> + vm->def->id);
>> + return ret;
>> + }
>> +
>> + if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_CPU_STATS_CPUTIME,
>> + VIR_TYPED_PARAM_ULLONG, d_info.cpu_time) < 0)
>> + nparams = ret;
>> +
>> + libxl_dominfo_dispose(&d_info);
>> + return nparams;
>
> Having a local 'ret' variable but returning nparams was a bit confusing to me.
> I've changed this in my local branch to
>
> if (virTypedParameterAssign(¶ms[0], VIR_DOMAIN_CPU_STATS_CPUTIME,
> VIR_TYPED_PARAM_ULLONG, d_info.cpu_time) < 0)
> goto cleanup;
>
> ret = nparams;
>
> cleanup:
> libxl_dominfo_dispose(&d_info);
> return ret;
>
OK. I solely did it to avoid the additional goto, but wasn't so clear in the end.
>> +}
>> +
>> +static int
>> +libxlDomainGetPerCPUStats(libxlDriverPrivatePtr driver,
>> + virDomainObjPtr vm,
>> + virTypedParameterPtr params,
>> + unsigned int nparams,
>> + int start_cpu,
>> + unsigned int ncpus)
>> +{
>> + libxl_vcpuinfo *vcpuinfo;
>> + int maxcpu, hostcpus;
>> + size_t i;
>> + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
>> + int ret = -1;
>> +
>> + if (nparams == 0 && ncpus != 0)
>> + return LIBXL_NB_TOTAL_CPU_STAT_PARAM;
>> + else if (nparams == 0)
>> + return vm->def->maxvcpus;
>> +
>> + if ((vcpuinfo = libxl_list_vcpu(cfg->ctx, vm->def->id, &maxcpu,
>> + &hostcpus)) == NULL) {
>> + virReportError(VIR_ERR_INTERNAL_ERROR,
>> + _("Failed to list vcpus for domain '%d' with libxenlight"),
>> + vm->def->id);
>> + return ret;
>> + }
>> +
>> + for (i = start_cpu; i < maxcpu && i < ncpus; ++i) {
>> + if (virTypedParameterAssign(¶ms[(i-start_cpu)],
>> + VIR_DOMAIN_CPU_STATS_CPUTIME,
>> + VIR_TYPED_PARAM_ULLONG,
>> + vcpuinfo[i].vcpu_time) < 0)
>> + goto cleanup;
>> + }
>> + ret = nparams;
>> +
>> + cleanup:
>> + libxl_vcpuinfo_list_free(vcpuinfo, maxcpu);
>> + return ret;
>> +}
>> +
>> +static int
>> +libxlDomainGetCPUStats(virDomainPtr dom,
>> + virTypedParameterPtr params,
>> + unsigned int nparams,
>> + int start_cpu,
>> + unsigned int ncpus,
>> + unsigned int flags)
>> +{
>> + libxlDriverPrivatePtr driver = dom->conn->privateData;
>> + virDomainObjPtr vm = NULL;
>> + int ret = -1;
>> +
>> + virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
>> +
>> + if (!(vm = libxlDomObjFromDomain(dom)))
>> + goto cleanup;
>> +
>> + if (virDomainGetCPUStatsEnsureACL(dom->conn, vm->def) < 0)
>> + goto cleanup;
>> +
>> + if (!virDomainObjIsActive(vm)) {
>> + virReportError(VIR_ERR_OPERATION_INVALID,
>> + "%s", _("domain is not running"));
>> + goto cleanup;
>> + }
>> +
>> + if (start_cpu == -1)
>> + ret = libxlDomainGetTotalCPUStats(driver, vm, params, nparams);
>> + else
>> + ret = libxlDomainGetPerCPUStats(driver, vm, params, nparams,
>> + start_cpu, ncpus);
>> +
>> + cleanup:
>> + if (vm)
>> + virObjectUnlock(vm);
>> + return ret;
>> +}
>> +
>> +static int
>> libxlConnectDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eventID,
>> virConnectDomainEventGenericCallback callback,
>> void *opaque, virFreeCallback freecb)
>> @@ -5233,6 +5342,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
>> #endif
>> .nodeGetFreeMemory = libxlNodeGetFreeMemory, /* 0.9.0 */
>> .nodeGetCellsFreeMemory = libxlNodeGetCellsFreeMemory, /* 1.1.1 */
>> + .domainGetCPUStats = libxlDomainGetCPUStats, /* 1.2.22 */
>
> ACK with the above nit fixed. I'll push this one too after verifying whether
> next release is 1.2.22 or 1.3.0.
Great, Thanks! :D
Cheers,
Joao
>
> Regards,
> Jim
>
next prev parent reply other threads:[~2015-11-17 10:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1447420488-5312-1-git-send-email-joao.m.martins@oracle.com>
2015-11-13 13:14 ` [PATCH v3 1/8] libxl: implement virDomainGetCPUStats Joao Martins
2015-11-13 13:14 ` [PATCH v3 2/8] libxl: implement virDomainMemorystats Joao Martins
2015-11-13 13:14 ` [PATCH v3 3/8] libxl: implement virDomainInterfaceStats Joao Martins
2015-11-13 13:14 ` [PATCH v3 4/8] util: add virDiskNameParse to handle disk and partition idx Joao Martins
2015-11-18 20:57 ` Jim Fehlig
2015-11-13 13:14 ` [PATCH v3 5/8] libxl: implement virDomainBlockStats Joao Martins
2015-11-13 13:14 ` [PATCH v3 6/8] libxl: implement virConnectGetAllDomainStats Joao Martins
2015-11-13 13:14 ` [PATCH v3 7/8] libxl: implement virDomainGetJobInfo Joao Martins
2015-11-13 13:14 ` [PATCH v3 8/8] libxl: implement virDomainGetJobStats Joao Martins
[not found] ` <1447420488-5312-4-git-send-email-joao.m.martins@oracle.com>
2015-11-17 2:48 ` [PATCH v3 3/8] libxl: implement virDomainInterfaceStats Jim Fehlig
[not found] ` <564A9571.8000609@suse.com>
2015-11-17 11:31 ` Joao Martins
2015-11-17 23:38 ` Jim Fehlig
[not found] ` <564BBA71.8000704@suse.com>
2015-11-18 18:14 ` Joao Martins
[not found] ` <1447420488-5312-2-git-send-email-joao.m.martins@oracle.com>
2015-11-17 2:59 ` [PATCH v3 1/8] libxl: implement virDomainGetCPUStats Jim Fehlig
[not found] ` <564A9815.9080705@suse.com>
2015-11-17 10:58 ` Joao Martins [this message]
2015-11-18 17:33 ` [libvirt] " Jim Fehlig
2015-11-18 18:18 ` Joao Martins
[not found] ` <1447420488-5312-3-git-send-email-joao.m.martins@oracle.com>
2015-11-17 2:53 ` [PATCH v3 2/8] libxl: implement virDomainMemorystats Jim Fehlig
2015-11-17 23:15 ` Jim Fehlig
[not found] ` <564BB51A.4090501@suse.com>
2015-11-18 18:05 ` Joao Martins
[not found] ` <564CBDD1.3060908@oracle.com>
2015-11-18 20:48 ` Jim Fehlig
2015-11-18 22:31 ` Konrad Rzeszutek Wilk
[not found] ` <1447420488-5312-6-git-send-email-joao.m.martins@oracle.com>
2015-11-18 19:01 ` [PATCH v3 5/8] libxl: implement virDomainBlockStats Jim Fehlig
[not found] ` <564CCAF4.80406@suse.com>
2015-11-19 13:46 ` Joao Martins
[not found] ` <1447420488-5312-7-git-send-email-joao.m.martins@oracle.com>
2015-11-18 22:03 ` [PATCH v3 6/8] libxl: implement virConnectGetAllDomainStats Jim Fehlig
[not found] ` <564CF595.5080602@suse.com>
2015-11-19 14:03 ` Joao Martins
[not found] ` <1447420488-5312-9-git-send-email-joao.m.martins@oracle.com>
2015-12-03 18:48 ` [PATCH v3 8/8] libxl: implement virDomainGetJobStats Jim Fehlig
[not found] ` <56608E76.3010908@suse.com>
2015-12-03 19:29 ` Joao Martins
[not found] ` <56609810.3090705@oracle.com>
2015-12-15 22:42 ` Jim Fehlig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=564B083C.1050002@oracle.com \
--to=joao.m.martins@oracle.com \
--cc=jfehlig@suse.com \
--cc=libvir-list@redhat.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.