render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
404507
From af86f99a7745f9d54c3f4e42f58130478e6aa9f5 Mon Sep 17 00:00:00 2001
404507
Message-Id: <af86f99a7745f9d54c3f4e42f58130478e6aa9f5@dist-git>
404507
From: Martin Kletzander <mkletzan@redhat.com>
404507
Date: Wed, 31 Jan 2018 16:32:26 +0100
404507
Subject: [PATCH] conf: Use virResctrlInfo in capabilities
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1289368
404507
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
(cherry picked from commit 3bbae43d8cc79ef1cd0b9a4ea2440203a0edc959)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
---
404507
 src/conf/capabilities.c | 53 ++++++++++++++++++++++++-------------------------
404507
 src/conf/capabilities.h |  2 ++
404507
 2 files changed, 28 insertions(+), 27 deletions(-)
404507
404507
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
404507
index e93eaed2f0..edf9f54f77 100644
404507
--- a/src/conf/capabilities.c
404507
+++ b/src/conf/capabilities.c
404507
@@ -245,6 +245,7 @@ virCapabilitiesDispose(void *object)
404507
     VIR_FREE(caps->host.netprefix);
404507
     VIR_FREE(caps->host.pagesSize);
404507
     virCPUDefFree(caps->host.cpu);
404507
+    virObjectUnref(caps->host.resctrl);
404507
 }
404507
 
404507
 /**
404507
@@ -1592,6 +1593,20 @@ virCapsHostCacheBankSorter(const void *a,
404507
 }
404507
 
404507
 
404507
+static int
404507
+virCapabilitiesInitResctrl(virCapsPtr caps)
404507
+{
404507
+    if (caps->host.resctrl)
404507
+        return 0;
404507
+
404507
+    caps->host.resctrl = virResctrlInfoNew();
404507
+    if (!caps->host.resctrl)
404507
+        return -1;
404507
+
404507
+    return virResctrlGetInfo(caps->host.resctrl);
404507
+}
404507
+
404507
+
404507
 int
404507
 virCapabilitiesInitCaches(virCapsPtr caps)
404507
 {
404507
@@ -1600,7 +1615,6 @@ virCapabilitiesInitCaches(virCapsPtr caps)
404507
     ssize_t pos = -1;
404507
     DIR *dirp = NULL;
404507
     int ret = -1;
404507
-    int typeret;
404507
     char *path = NULL;
404507
     char *type = NULL;
404507
     struct dirent *ent = NULL;
404507
@@ -1611,6 +1625,9 @@ virCapabilitiesInitCaches(virCapsPtr caps)
404507
      * lose information. */
404507
     const int cache_min_level = 3;
404507
 
404507
+    if (virCapabilitiesInitResctrl(caps) < 0)
404507
+        return -1;
404507
+
404507
     /* offline CPUs don't provide cache info */
404507
     if (virFileReadValueBitmap(&cpus, "%s/cpu/online", SYSFS_SYSTEM_PATH) < 0)
404507
         return -1;
404507
@@ -1676,32 +1693,6 @@ virCapabilitiesInitCaches(virCapsPtr caps)
404507
                                        SYSFS_SYSTEM_PATH, pos, ent->d_name) < 0)
404507
                 goto cleanup;
404507
 
404507
-            typeret = virResctrlGetCacheControlType(bank->level);
404507
-            if (typeret < 0)
404507
-                goto cleanup;
404507
-
404507
-            if (typeret == 1) {
404507
-                if (virResctrlGetCacheInfo(bank->level,
404507
-                                           bank->size,
404507
-                                           VIR_CACHE_TYPE_BOTH,
404507
-                                           &bank->controls,
404507
-                                           &bank->ncontrols) < 0)
404507
-                    goto cleanup;
404507
-            } else if (typeret == 2) {
404507
-                if (virResctrlGetCacheInfo(bank->level,
404507
-                                           bank->size,
404507
-                                           VIR_CACHE_TYPE_CODE,
404507
-                                           &bank->controls,
404507
-                                           &bank->ncontrols) < 0)
404507
-                    goto cleanup;
404507
-                if (virResctrlGetCacheInfo(bank->level,
404507
-                                           bank->size,
404507
-                                           VIR_CACHE_TYPE_DATA,
404507
-                                           &bank->controls,
404507
-                                           &bank->ncontrols) < 0)
404507
-                    goto cleanup;
404507
-            }
404507
-
404507
             kernel_type = virCacheKernelTypeFromString(type);
404507
             if (kernel_type < 0) {
404507
                 virReportError(VIR_ERR_INTERNAL_ERROR,
404507
@@ -1717,6 +1708,14 @@ virCapabilitiesInitCaches(virCapsPtr caps)
404507
                     break;
404507
             }
404507
             if (i == caps->host.ncaches) {
404507
+                /* If it is a new cache, then update its resctrl information. */
404507
+                if (virResctrlInfoGetCache(caps->host.resctrl,
404507
+                                           bank->level,
404507
+                                           bank->size,
404507
+                                           &bank->ncontrols,
404507
+                                           &bank->controls) < 0)
404507
+                    goto cleanup;
404507
+
404507
                 if (VIR_APPEND_ELEMENT(caps->host.caches,
404507
                                        caps->host.ncaches,
404507
                                        bank) < 0) {
404507
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
404507
index 27b88cb5ed..694a3590bf 100644
404507
--- a/src/conf/capabilities.h
404507
+++ b/src/conf/capabilities.h
404507
@@ -170,6 +170,8 @@ struct _virCapsHost {
404507
     size_t nnumaCell_max;
404507
     virCapsHostNUMACellPtr *numaCell;
404507
 
404507
+    virResctrlInfoPtr resctrl;
404507
+
404507
     size_t ncaches;
404507
     virCapsHostCacheBankPtr *caches;
404507
 
404507
-- 
404507
2.16.1
404507