render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From b6573a089823817a1aa7ae19d7df3aed4845508e Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <b6573a089823817a1aa7ae19d7df3aed4845508e@dist-git>
0a7476
From: Bing Niu <bing.niu@intel.com>
0a7476
Date: Mon, 15 Apr 2019 17:32:52 +0200
0a7476
Subject: [PATCH] util: Introduce virResctrlAllocForeachMemory
0a7476
MIME-Version: 1.0
0a7476
Content-Type: text/plain; charset=UTF-8
0a7476
Content-Transfer-Encoding: 8bit
0a7476
0a7476
Introduce an API that will traverse the memory bandwidth data calling
0a7476
a callback function for each defined bandwidth entry.
0a7476
0a7476
Signed-off-by: Bing Niu <bing.niu@intel.com>
0a7476
Reviewed-by: John Ferlan <jferlan@redhat.com>
0a7476
(cherry picked from commit 10e699dac9f86a4a266a43a5190def7756f3b762)
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: <40beb201ddf7c987958e792e47925e8438a5984f.1555342313.git.phrdina@redhat.com>
0a7476
Reviewed-by: Ján Tomko <jtomko@redhat.com>
0a7476
---
0a7476
 src/libvirt_private.syms |  1 +
0a7476
 src/util/virresctrl.c    | 33 +++++++++++++++++++++++++++++++++
0a7476
 src/util/virresctrl.h    |  9 +++++++++
0a7476
 3 files changed, 43 insertions(+)
0a7476
0a7476
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
0a7476
index a3b30bf675..de328d7d22 100644
0a7476
--- a/src/libvirt_private.syms
0a7476
+++ b/src/libvirt_private.syms
0a7476
@@ -2658,6 +2658,7 @@ virResctrlAllocAddPID;
0a7476
 virResctrlAllocCreate;
0a7476
 virResctrlAllocDeterminePath;
0a7476
 virResctrlAllocForeachCache;
0a7476
+virResctrlAllocForeachMemory;
0a7476
 virResctrlAllocFormat;
0a7476
 virResctrlAllocGetID;
0a7476
 virResctrlAllocGetUnused;
0a7476
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
0a7476
index 21a9247cb6..45fc6fc847 100644
0a7476
--- a/src/util/virresctrl.c
0a7476
+++ b/src/util/virresctrl.c
0a7476
@@ -965,6 +965,39 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
0a7476
 }
0a7476
 
0a7476
 
0a7476
+/* virResctrlAllocForeachMemory
0a7476
+ * @alloc: Pointer to an active allocation
0a7476
+ * @cb: Callback function
0a7476
+ * @opaque: Opaque data to be passed to @cb
0a7476
+ *
0a7476
+ * If available, traverse the defined memory bandwidth allocations and
0a7476
+ * call the @cb function.
0a7476
+ *
0a7476
+ * Returns 0 on success, -1 and immediate failure if the @cb has any failure.
0a7476
+ */
0a7476
+int
0a7476
+virResctrlAllocForeachMemory(virResctrlAllocPtr alloc,
0a7476
+                             virResctrlAllocForeachMemoryCallback cb,
0a7476
+                             void *opaque)
0a7476
+{
0a7476
+    size_t i = 0;
0a7476
+    virResctrlAllocMemBWPtr mem_bw;
0a7476
+
0a7476
+    if (!alloc || !alloc->mem_bw)
0a7476
+        return 0;
0a7476
+
0a7476
+    mem_bw = alloc->mem_bw;
0a7476
+    for (i = 0; i < mem_bw->nbandwidths; i++) {
0a7476
+        if (mem_bw->bandwidths[i]) {
0a7476
+            if (cb(i, *mem_bw->bandwidths[i], opaque) < 0)
0a7476
+                return -1;
0a7476
+        }
0a7476
+    }
0a7476
+
0a7476
+    return 0;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 int
0a7476
 virResctrlAllocSetID(virResctrlAllocPtr alloc,
0a7476
                      const char *id)
0a7476
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
0a7476
index d657c06008..5ea5b27d3b 100644
0a7476
--- a/src/util/virresctrl.h
0a7476
+++ b/src/util/virresctrl.h
0a7476
@@ -73,6 +73,10 @@ typedef int virResctrlAllocForeachCacheCallback(unsigned int level,
0a7476
                                                 unsigned long long size,
0a7476
                                                 void *opaque);
0a7476
 
0a7476
+typedef int virResctrlAllocForeachMemoryCallback(unsigned int id,
0a7476
+                                                 unsigned int size,
0a7476
+                                                 void *opaque);
0a7476
+
0a7476
 virResctrlAllocPtr
0a7476
 virResctrlAllocNew(void);
0a7476
 
0a7476
@@ -91,6 +95,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
0a7476
                             virResctrlAllocForeachCacheCallback cb,
0a7476
                             void *opaque);
0a7476
 
0a7476
+int
0a7476
+virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl,
0a7476
+                             virResctrlAllocForeachMemoryCallback cb,
0a7476
+                             void *opaque);
0a7476
+
0a7476
 int
0a7476
 virResctrlAllocSetID(virResctrlAllocPtr alloc,
0a7476
                      const char *id);
0a7476
-- 
0a7476
2.21.0
0a7476