0a7476
From bef145fd9b22a310ce7ab8e4cd033bcbe9d40fa9 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <bef145fd9b22a310ce7ab8e4cd033bcbe9d40fa9@dist-git>
0a7476
From: Martin Kletzander <mkletzan@redhat.com>
0a7476
Date: Mon, 15 Apr 2019 17:33:02 +0200
0a7476
Subject: [PATCH] resctrl: Do not calculate free bandwidth for MBA
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
For CAT we calculate unallocated parts of the cache, however with MBA this does
0a7476
not make sense as the purpose of that is to limit the bandwidth and the setting
0a7476
is only proportional relative to bandwidth settings for other groups.
0a7476
0a7476
This means it makes sense to set the values to 100% even if there are other
0a7476
groups with some allocations and that we don't need to find the available
0a7476
(unallocated) bandwidth in all the groups.
0a7476
0a7476
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
0a7476
(cherry picked from commit 408aeebcef1e81e55bebb4f2d47403d04ee16c0f)
0a7476
0a7476
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1468650
0a7476
0a7476
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
0a7476
Message-Id: <75b61f0528c91997bf86e6e65b6f4673bad44d75.1555342313.git.phrdina@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/util/virresctrl.c | 52 ++++++++++++-------------------------------
0a7476
 1 file changed, 14 insertions(+), 38 deletions(-)
0a7476
0a7476
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
0a7476
index 4b5442f879..f5e4bef7dc 100644
0a7476
--- a/src/util/virresctrl.c
0a7476
+++ b/src/util/virresctrl.c
0a7476
@@ -1509,22 +1509,6 @@ virResctrlAllocSubtract(virResctrlAllocPtr dst,
0a7476
 }
0a7476
 
0a7476
 
0a7476
-static void
0a7476
-virResctrlMemoryBandwidthSubtract(virResctrlAllocPtr free,
0a7476
-                                  virResctrlAllocPtr used)
0a7476
-{
0a7476
-    size_t i;
0a7476
-
0a7476
-    if (!used->mem_bw)
0a7476
-        return;
0a7476
-
0a7476
-    for (i = 0; i < used->mem_bw->nbandwidths; i++) {
0a7476
-        if (used->mem_bw->bandwidths[i])
0a7476
-            *(free->mem_bw->bandwidths[i]) -= *(used->mem_bw->bandwidths[i]);
0a7476
-    }
0a7476
-}
0a7476
-
0a7476
-
0a7476
 static virResctrlAllocPtr
0a7476
 virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
0a7476
 {
0a7476
@@ -1588,15 +1572,18 @@ virResctrlAllocNewFromInfo(virResctrlInfoPtr info)
0a7476
 }
0a7476
 
0a7476
 /*
0a7476
- * This function creates an allocation that represents all unused parts of
0a7476
- * all caches and memory bandwidth in the system. It uses virResctrlInfo
0a7476
- * for creating a new full allocation with all bits set (using the
0a7476
- * virResctrlAllocNewFromInfo()), sets memory bandwidth 100%, and then scans
0a7476
- * for all allocations under /sys/fs/resctrl and subtracts each one of them
0a7476
- * from it. That way it can then return an allocation with only bit set
0a7476
- * being those that are not mentioned in any other allocation for CAT and
0a7476
- * available memory bandwidth for MBA. It is used for two things, calculating
0a7476
- * the masks and bandwidth available when creating allocations and from tests.
0a7476
+ * This function creates an allocation that represents all unused parts of all
0a7476
+ * caches in the system.  It uses virResctrlInfo for creating a new full
0a7476
+ * allocation with all bits set (using virResctrlAllocNewFromInfo()) and then
0a7476
+ * scans for all allocations under /sys/fs/resctrl and subtracts each one of
0a7476
+ * them from it.  That way it can then return an allocation with only bit set
0a7476
+ * being those that are not mentioned in any other allocation.  It is used for
0a7476
+ * two things, a) calculating the masks when creating allocations and b) from
0a7476
+ * tests.
0a7476
+ *
0a7476
+ * MBA (Memory Bandwidth Allocation) is not taken into account as it is a
0a7476
+ * limiting setting, not an allocating one.  The way it works is also vastly
0a7476
+ * different from CAT.
0a7476
  */
0a7476
 virResctrlAllocPtr
0a7476
 virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
0a7476
@@ -1642,7 +1629,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
0a7476
             goto error;
0a7476
         }
0a7476
 
0a7476
-        virResctrlMemoryBandwidthSubtract(ret, alloc);
0a7476
         virResctrlAllocSubtract(ret, alloc);
0a7476
         virObjectUnref(alloc);
0a7476
         alloc = NULL;
0a7476
@@ -1795,12 +1781,10 @@ virResctrlAllocFindUnused(virResctrlAllocPtr alloc,
0a7476
 
0a7476
 static int
0a7476
 virResctrlAllocMemoryBandwidth(virResctrlInfoPtr resctrl,
0a7476
-                               virResctrlAllocPtr alloc,
0a7476
-                               virResctrlAllocPtr free)
0a7476
+                               virResctrlAllocPtr alloc)
0a7476
 {
0a7476
     size_t i;
0a7476
     virResctrlAllocMemBWPtr mem_bw_alloc = alloc->mem_bw;
0a7476
-    virResctrlAllocMemBWPtr mem_bw_free = free->mem_bw;
0a7476
     virResctrlInfoMemBWPtr mem_bw_info = resctrl->membw_info;
0a7476
 
0a7476
     if (!mem_bw_alloc)
0a7476
@@ -1840,14 +1824,6 @@ virResctrlAllocMemoryBandwidth(virResctrlInfoPtr resctrl,
0a7476
                            i, mem_bw_info->max_id);
0a7476
             return -1;
0a7476
         }
0a7476
-        if (*(mem_bw_alloc->bandwidths[i]) > *(mem_bw_free->bandwidths[i])) {
0a7476
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
0a7476
-                           _("Not enough room for allocation of %u%% "
0a7476
-                             "bandwidth on node %zd, available bandwidth %u%%"),
0a7476
-                           *(mem_bw_alloc->bandwidths[i]), i,
0a7476
-                           *(mem_bw_free->bandwidths[i]));
0a7476
-            return -1;
0a7476
-        }
0a7476
     }
0a7476
     return 0;
0a7476
 }
0a7476
@@ -1914,7 +1890,7 @@ virResctrlAllocAssign(virResctrlInfoPtr resctrl,
0a7476
     if (!alloc_default)
0a7476
         goto cleanup;
0a7476
 
0a7476
-    if (virResctrlAllocMemoryBandwidth(resctrl, alloc, alloc_free) < 0)
0a7476
+    if (virResctrlAllocMemoryBandwidth(resctrl, alloc) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (virResctrlAllocCopyMasks(alloc, alloc_default) < 0)
0a7476
-- 
0a7476
2.21.0
0a7476