render / rpms / libvirt

Forked from rpms/libvirt 4 months ago
Clone
404507
From 4574632d3d8eb9be947f0dd052a5d5a72fc306b7 Mon Sep 17 00:00:00 2001
404507
Message-Id: <4574632d3d8eb9be947f0dd052a5d5a72fc306b7@dist-git>
404507
From: Martin Kletzander <mkletzan@redhat.com>
404507
Date: Wed, 31 Jan 2018 16:32:41 +0100
404507
Subject: [PATCH] util: Use default group's mask for unspecified resctrl
404507
 allocations
404507
404507
Introduce virResctrlAllocCopyMasks() and use that to initially copy the default
404507
group schemata to the allocation before reserving any parts of the cache.  The
404507
reason for this is that when new group is created the schemata will have unknown
404507
data in it.  If there was previously group with the same CLoS ID, it will have
404507
the previous valies, if not it will have all bits set.  And we need to set all
404507
unspecified (in the XML) allocations to the same one as the default group.
404507
404507
Some non-Linux functions now need to be made public due to this change.
404507
404507
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1289368
404507
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
(cherry picked from commit c39ce914dd88c35a66d1088f0688da24fea8cfcd)
404507
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
404507
---
404507
 src/util/virresctrl.c | 72 +++++++++++++++++++++++++++++++++++----------------
404507
 1 file changed, 50 insertions(+), 22 deletions(-)
404507
404507
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
404507
index df6461a046..a0ea274871 100644
404507
--- a/src/util/virresctrl.c
404507
+++ b/src/util/virresctrl.c
404507
@@ -667,8 +667,6 @@ virResctrlAllocGetType(virResctrlAllocPtr resctrl,
404507
 }
404507
 
404507
 
404507
-#ifdef __linux__
404507
-
404507
 static int
404507
 virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl,
404507
                           unsigned int level,
404507
@@ -696,8 +694,6 @@ virResctrlAllocUpdateMask(virResctrlAllocPtr resctrl,
404507
     return virBitmapCopy(a_type->masks[cache], mask);
404507
 }
404507
 
404507
-#endif
404507
-
404507
 
404507
 static int
404507
 virResctrlAllocUpdateSize(virResctrlAllocPtr resctrl,
404507
@@ -917,8 +913,6 @@ virResctrlAllocFormat(virResctrlAllocPtr resctrl)
404507
 }
404507
 
404507
 
404507
-#ifdef __linux__
404507
-
404507
 static int
404507
 virResctrlAllocParseProcessCache(virResctrlInfoPtr resctrl,
404507
                                  virResctrlAllocPtr alloc,
404507
@@ -1090,6 +1084,8 @@ virResctrlAllocGetDefault(virResctrlInfoPtr resctrl)
404507
 }
404507
 
404507
 
404507
+#ifdef __linux__
404507
+
404507
 static void
404507
 virResctrlAllocSubtractPerType(virResctrlAllocPerTypePtr dst,
404507
                                virResctrlAllocPerTypePtr src)
404507
@@ -1298,23 +1294,8 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
404507
     ssize_t last_bits = 0;
404507
     ssize_t last_pos = -1;
404507
 
404507
-    /* If there is no reservation requested we need to set all bits.  That's due
404507
-     * to weird interface of the resctrl sysfs.  It's also the reason why we
404507
-     * cannot reserve the whole cache in one allocation. */
404507
-    if (!size) {
404507
-        a_mask = virBitmapNew(i_type->bits);
404507
-        if (!a_mask)
404507
-            return -1;
404507
-
404507
-        virBitmapSetAll(a_mask);
404507
-
404507
-        if (virResctrlAllocSetMask(a_type, cache, a_mask) < 0) {
404507
-            virBitmapFree(a_mask);
404507
-            return -1;
404507
-        }
404507
-
404507
+    if (!size)
404507
         return 0;
404507
-    }
404507
 
404507
     if (cache >= f_type->nmasks) {
404507
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
404507
@@ -1417,6 +1398,44 @@ virResctrlAllocFindUnused(virResctrlAllocPerTypePtr a_type,
404507
 }
404507
 
404507
 
404507
+static int
404507
+virResctrlAllocCopyMasks(virResctrlAllocPtr dst,
404507
+                         virResctrlAllocPtr src)
404507
+{
404507
+    unsigned int level = 0;
404507
+
404507
+    for (level = 0; level < src->nlevels; level++) {
404507
+        virResctrlAllocPerLevelPtr s_level = src->levels[level];
404507
+        unsigned int type = 0;
404507
+
404507
+        if (!s_level)
404507
+            continue;
404507
+
404507
+        for (type = 0; type < VIR_CACHE_TYPE_LAST; type++) {
404507
+            virResctrlAllocPerTypePtr s_type = s_level->types[type];
404507
+            virResctrlAllocPerTypePtr d_type = NULL;
404507
+            unsigned int cache = 0;
404507
+
404507
+            if (!s_type)
404507
+                continue;
404507
+
404507
+            d_type = virResctrlAllocGetType(dst, level, type);
404507
+            if (!d_type)
404507
+                return -1;
404507
+
404507
+            for (cache = 0; cache < s_type->nmasks; cache++) {
404507
+                virBitmapPtr mask = s_type->masks[cache];
404507
+
404507
+                if (mask && virResctrlAllocUpdateMask(dst, level, type, cache, mask) < 0)
404507
+                    return -1;
404507
+            }
404507
+        }
404507
+    }
404507
+
404507
+    return 0;
404507
+}
404507
+
404507
+
404507
 /*
404507
  * This function is called when creating an allocation in the system.  What it
404507
  * does is that it gets all the unused bits using virResctrlAllocGetUnused() and
404507
@@ -1430,11 +1449,19 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
404507
     int ret = -1;
404507
     unsigned int level = 0;
404507
     virResctrlAllocPtr alloc_free = NULL;
404507
+    virResctrlAllocPtr alloc_default = NULL;
404507
 
404507
     alloc_free = virResctrlAllocGetUnused(resctrl);
404507
     if (!alloc_free)
404507
         return -1;
404507
 
404507
+    alloc_default = virResctrlAllocGetDefault(resctrl);
404507
+    if (!alloc_default)
404507
+        return -1;
404507
+
404507
+    if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0)
404507
+        return -1;
404507
+
404507
     for (level = 0; level < alloc->nlevels; level++) {
404507
         virResctrlAllocPerLevelPtr a_level = alloc->levels[level];
404507
         virResctrlAllocPerLevelPtr f_level = NULL;
404507
@@ -1482,6 +1509,7 @@ virResctrlAllocMasksAssign(virResctrlInfoPtr resctrl,
404507
     ret = 0;
404507
  cleanup:
404507
     virObjectUnref(alloc_free);
404507
+    virObjectUnref(alloc_default);
404507
     return ret;
404507
 }
404507
 
404507
-- 
404507
2.16.1
404507