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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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 65f1618..5e39bb3 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 9491845..bfa8432 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.
+ *
+ * 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..4d71556 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.2 {
+    global:
+        virDomainGetPerfEvents;
+        virDomainSetPerfEvents;
+} LIBVIRT_1.2.19;
+
 # .... define new API here using predicted next version number ....
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]