[libvirt] [PATCH v2 1/8] perf: add new public APIs for perf event

Daniel P. Berrange berrange at redhat.com
Tue Dec 8 10:42:08 UTC 2015


On Mon, Dec 07, 2015 at 03:53:52PM +0800, Qiaowei Ren wrote:
> API agreed on in
> https://www.redhat.com/archives/libvir-list/2015-October/msg00872.html
> 
> * include/libvirt/libvirt-domain.h (virDomainGetPerfEvents,
> virDomainSetPerfEvents): New declarations.
> * src/libvirt_public.syms: Export new symbols.
> * src/driver-hypervisor.h (virDrvDomainGetPerfEvents,
> virDrvDomainSetPerfEvents): New typedefs.
> * src/libvirt-domain.c: Implement virDomainGetPerfEvents and
> virDomainSetPerfEvents.
> 
> Signed-off-by: Qiaowei Ren <qiaowei.ren at intel.com>
> ---
>  include/libvirt/libvirt-domain.h | 18 ++++++++
>  src/driver-hypervisor.h          | 12 ++++++
>  src/libvirt-domain.c             | 93 ++++++++++++++++++++++++++++++++++++++++
>  src/libvirt_public.syms          |  6 +++
>  4 files changed, 129 insertions(+)
> 
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index a1ea6a5..cc1b29b 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -1802,6 +1802,24 @@ int virDomainListGetStats(virDomainPtr *doms,
>  void virDomainStatsRecordListFree(virDomainStatsRecordPtr *stats);
>  
>  /*
> + * Perf Event API
> + */
> +
> +/**
> + * VIR_PERF_PARAM_CMT:
> + *
> + * Macro for typed parameter name that represents CMT perf event.
> + */
> +# define VIR_PERF_PARAM_CMT "cmt"
> +
> +int virDomainGetPerfEvents(virDomainPtr dom,
> +                           virTypedParameterPtr *params,
> +                           int *nparams);
> +int virDomainSetPerfEvents(virDomainPtr dom,
> +                           virTypedParameterPtr params,
> +                           int nparams);
> +
> +/*
>   * BlockJob API
>   */
>  
> diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
> index ae2ec4d..aedbc83 100644
> --- a/src/driver-hypervisor.h
> +++ b/src/driver-hypervisor.h
> @@ -958,6 +958,16 @@ typedef int
>                                  unsigned int flags);
>  
>  typedef int
> +(*virDrvDomainGetPerfEvents)(virDomainPtr dom,
> +                             virTypedParameterPtr *params,
> +                             int *nparams);
> +
> +typedef int
> +(*virDrvDomainSetPerfEvents)(virDomainPtr dom,
> +                             virTypedParameterPtr params,
> +                             int nparams);
> +
> +typedef int
>  (*virDrvDomainBlockJobAbort)(virDomainPtr dom,
>                               const char *path,
>                               unsigned int flags);
> @@ -1413,6 +1423,8 @@ struct _virHypervisorDriver {
>      virDrvConnectSetKeepAlive connectSetKeepAlive;
>      virDrvConnectIsAlive connectIsAlive;
>      virDrvNodeSuspendForDuration nodeSuspendForDuration;
> +    virDrvDomainGetPerfEvents domainGetPerfEvents;
> +    virDrvDomainSetPerfEvents domainSetPerfEvents;
>      virDrvDomainSetBlockIoTune domainSetBlockIoTune;
>      virDrvDomainGetBlockIoTune domainGetBlockIoTune;
>      virDrvDomainGetCPUStats domainGetCPUStats;
> diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
> index b91388e..f105803 100644
> --- a/src/libvirt-domain.c
> +++ b/src/libvirt-domain.c
> @@ -9564,6 +9564,99 @@ virDomainOpenChannel(virDomainPtr dom,
>  
>  
>  /**
> + * virDomainGetPerfEvents:
> + * @domain: a domain object
> + * @params: where to store perf events setting
> + * @nparams: number of items in @params
> + *
> + * Get all perf events setting. Possible fields returned in @params are
> + * defined by VIR_DOMAIN_PERF_* macros and new fields will likely be
> + * introduced in the future.

You called the constants  VIR_PERF in the header - either this doc needs
changing or the constants need renaming to VIR_DOMAIN_PERF

> + *
> + * Returns -1 in case of failure, 0 in case of success.
> + */
> +int virDomainGetPerfEvents(virDomainPtr domain,
> +                           virTypedParameterPtr *params,
> +                           int *nparams)
> +{
> +    virConnectPtr conn;
> +
> +    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%p",
> +                     params, nparams);
> +
> +    virResetLastError();
> +
> +    virCheckDomainReturn(domain, -1);
> +    virCheckNonNullArgGoto(params, error);
> +    virCheckNonNullArgGoto(nparams, error);
> +
> +    conn = domain->conn;
> +
> +    if (conn->driver->domainGetPerfEvents) {
> +        int ret;
> +        ret = conn->driver->domainGetPerfEvents(domain, params, nparams);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +    virReportUnsupportedError();
> +
> + error:
> +    virDispatchError(domain->conn);
> +    return -1;
> +}
> +
> +
> +/**
> + * virDomainSetPerfEvents:
> + * @domain: a domain object
> + * @params: pointer to perf events parameter object
> + * @nparams: number of perf event parameters (this value can be the same
> + *           less than the number of parameters supported)
> + *
> + * Enable or disable the particular list of perf events you care about.
> + *
> + * Returns -1 in case of error, 0 in case of success.
> + */
> +int virDomainSetPerfEvents(virDomainPtr domain,
> +                           virTypedParameterPtr params,
> +                           int nparams)
> +{
> +    virConnectPtr conn;
> +
> +    VIR_DOMAIN_DEBUG(domain, "params=%p, nparams=%d",
> +                     params, nparams);
> +    VIR_TYPED_PARAMS_DEBUG(params, nparams);
> +
> +    virResetLastError();
> +
> +    virCheckDomainReturn(domain, -1);
> +    conn = domain->conn;
> +
> +    virCheckReadOnlyGoto(conn->flags, error);
> +    virCheckNonNullArgGoto(params, error);
> +    virCheckPositiveArgGoto(nparams, error);
> +
> +    if (virTypedParameterValidateSet(conn, params, nparams) < 0)
> +        goto error;
> +
> +    if (conn->driver->domainSetPerfEvents) {
> +        int ret;
> +        ret = conn->driver->domainSetPerfEvents(domain, params, nparams);
> +        if (ret < 0)
> +            goto error;
> +        return ret;
> +    }
> +
> +    virReportUnsupportedError();
> +
> + error:
> +    virDispatchError(domain->conn);
> +    return -1;
> +}
> +
> +
> +/**
>   * virDomainBlockJobAbort:
>   * @dom: pointer to domain object
>   * @disk: path to the block device, or device shorthand
> diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
> index dd94191..03206e7 100644
> --- a/src/libvirt_public.syms
> +++ b/src/libvirt_public.syms
> @@ -725,4 +725,10 @@ LIBVIRT_1.2.19 {
>          virDomainRename;
>  } LIBVIRT_1.2.17;
>  
> +LIBVIRT_1.3.0 {
> +    global:
> +        virDomainGetPerfEvents;
> +        virDomainSetPerfEvents;
> +} LIBVIRT_1.2.19;

This will need to be 1.3.1 next time you post this


ACK with the minor fixes

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list