[libvirt] [PATCHv2 04/10] libvirt: add public APIs for resource monitoring group

Wang Huaqiang huaqiang.wang at intel.com
Mon Jul 9 07:00:52 UTC 2018


support functions to create, destory and monitoring resctl
monioring group.
---
 include/libvirt/libvirt-domain.h | 13 ++++++
 src/conf/domain_conf.c           |  2 +
 src/driver-hypervisor.h          | 13 ++++++
 src/libvirt-domain.c             | 96 ++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms          |  6 +++
 5 files changed, 130 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 796f2e1..c703346 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4785,5 +4785,18 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr domain,
                                    virTypedParameterPtr *params,
                                    int *nparams,
                                    unsigned int flags);
+/*
+ * cpures API
+ */
+int virDomainSetCPUResmon(virDomainPtr domain,
+                          const char *vcpustr,
+                          const char *mongroup,
+                          int action,
+                          unsigned int flags);
+
+int virDomainGetCPUResmonSts(virDomainPtr domain,
+                             const char *mongroup,
+                             char **sts);
+
 
 #endif /* __VIR_LIBVIRT_DOMAIN_H__ */
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0cdad79..393439a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19219,6 +19219,7 @@ virDomainCpuResmonDefRemove(virDomainDefPtr def,
 
     if (!monid) {
         virReportError(VIR_ERR_INVALID_ARG,
+                       "%s",
                        _("Cannot remove resource monitoring group: "
                          "group name is NULL"));
         goto error;
@@ -19228,6 +19229,7 @@ virDomainCpuResmonDefRemove(virDomainDefPtr def,
         const char *id = virResctrlMonGetID(def->resmons[i]->mon);
         if (!id) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "%s",
                            _("Cannot remove resource monitoring group: "
                              "error in get monitoring group name"));
         goto error;
diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h
index eef31eb..8b736da 100644
--- a/src/driver-hypervisor.h
+++ b/src/driver-hypervisor.h
@@ -1321,6 +1321,17 @@ typedef int
                                         int *nparams,
                                         unsigned int flags);
 
+typedef int
+(*virDrvDomainSetCPUResmon)(virDomainPtr domain,
+                            const char *vcpustr,
+                            const char *monid,
+                            int action,
+                            unsigned int flags);
+
+typedef char *
+(*virDrvDomainGetCPUResmonSts)(virDomainPtr domain,
+                               const char *monid);
+
 
 typedef struct _virHypervisorDriver virHypervisorDriver;
 typedef virHypervisorDriver *virHypervisorDriverPtr;
@@ -1572,6 +1583,8 @@ struct _virHypervisorDriver {
     virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU;
     virDrvNodeGetSEVInfo nodeGetSEVInfo;
     virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo;
+    virDrvDomainSetCPUResmon  domainSetCPUResmon;
+    virDrvDomainGetCPUResmonSts  domainGetCPUResmonSts;
 };
 
 
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index ab7266d..8b080fc 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -11488,6 +11488,11 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
  *                               long long. It is produced by the
  *                               emulation_faults perf event
  *
+ * VIR_DOMAIN_STATS_CPURES
+ *     "cpu.cacheoccupancy"  - the usage of l3 cache (bytes) by applications
+ *                  running on the platform as unsigned long long. It is
+ *                  retrieved from resctrl file system.
+ *
  * Note that entire stats groups or individual stat fields may be missing from
  * the output in case they are not supported by the given hypervisor, are not
  * applicable for the current state of the guest domain, or their retrieval
@@ -12220,3 +12225,94 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr domain,
     virDispatchError(domain->conn);
     return -1;
 }
+
+
+/**
+ * virDomainSetCPUResmon:
+ * @domain : a domain object
+ * @vcpustr: string specifying vcpus list
+ * @mongroup:  mon group id
+ * @action : action to be performed
+ *           1 for enabling a rdt monitroing group
+ *           2 for disabling a rdt monitroing group
+ *           not valid for others
+ * @flags  : bitwise-OR of virDomainModificationImpact
+ *
+ * Enable or disable resctrl monitoring.
+ *
+ * Returns -1 in case of failure, 0 in case of success.
+ */
+int
+virDomainSetCPUResmon(virDomainPtr domain,
+                      const char *vcpustr,
+                      const char *mongroup,
+                      int action,
+                      unsigned int flags)
+{
+    int ret;
+    virConnectPtr conn;
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+
+    conn = domain->conn;
+
+    if (conn->driver->domainSetCPUResmon) {
+        ret = conn->driver->domainSetCPUResmon(
+                                               domain,
+                                               vcpustr,
+                                               mongroup,
+                                               action,
+                                               flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virReportUnsupportedError();
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+
+/**
+ * virDomainGetCPUResmonSts:
+ * @domain: a domain object
+ * @mongroup:  mon group id
+ * @status: pointer of a string buffer for holding resctrl mon
+ * group status string, caller is responsible for free it.
+ *
+ * Get domain resctrl status.
+ *
+ * Returns -1 in case of failure, 0 in case of success.
+ */
+int
+virDomainGetCPUResmonSts(virDomainPtr domain,
+                         const char *mongroup,
+                         char **status)
+{
+    /* *allstatus*, the magic string for retrieving all domain's status */
+    const char *monid = mongroup ? mongroup : "*allstatus*";
+    virConnectPtr conn;
+
+    virResetLastError();
+
+    virCheckDomainReturn(domain, -1);
+
+    conn = domain->conn;
+
+    if (conn->driver->domainGetCPUResmonSts) {
+        *status = conn->driver->domainGetCPUResmonSts(domain, monid);
+        if (*status)
+            return 0;
+
+        goto error;
+    }
+
+    virReportUnsupportedError();
+ error:
+    virDispatchError(domain->conn);
+    return -1;
+}
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index d4cdbd8..0b75146 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -809,4 +809,10 @@ LIBVIRT_4.5.0 {
         virNWFilterBindingGetFilterName;
 } LIBVIRT_4.4.0;
 
+LIBVIRT_4.6.0 {
+    global:
+        virDomainSetCPUResmon;
+        virDomainGetCPUResmonSts;
+} LIBVIRT_4.5.0;
+
 # .... define new API here using predicted next version number ....
-- 
2.7.4




More information about the libvir-list mailing list