]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Introduce virResctrlAllocForeachMemory
authorBing Niu <bing.niu@intel.com>
Mon, 30 Jul 2018 03:12:33 +0000 (11:12 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 13 Aug 2018 18:19:41 +0000 (14:19 -0400)
Introduce an API that will traverse the memory bandwidth data calling
a callback function for each defined bandwidth entry.

Signed-off-by: Bing Niu <bing.niu@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/libvirt_private.syms
src/util/virresctrl.c
src/util/virresctrl.h

index 62c875104341bffee4274a2e256a41ba0e2e77d4..971b12c383d67a49a7648fe2be5186fb4e220595 100644 (file)
@@ -2648,6 +2648,7 @@ virResctrlAllocAddPID;
 virResctrlAllocCreate;
 virResctrlAllocDeterminePath;
 virResctrlAllocForeachCache;
+virResctrlAllocForeachMemory;
 virResctrlAllocFormat;
 virResctrlAllocGetID;
 virResctrlAllocGetUnused;
index 21a9247cb60798bf076cdc596145e8e79741c7a1..45fc6fc84791807bede18aa5d0d09960b039f357 100644 (file)
@@ -965,6 +965,39 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
 }
 
 
+/* virResctrlAllocForeachMemory
+ * @alloc: Pointer to an active allocation
+ * @cb: Callback function
+ * @opaque: Opaque data to be passed to @cb
+ *
+ * If available, traverse the defined memory bandwidth allocations and
+ * call the @cb function.
+ *
+ * Returns 0 on success, -1 and immediate failure if the @cb has any failure.
+ */
+int
+virResctrlAllocForeachMemory(virResctrlAllocPtr alloc,
+                             virResctrlAllocForeachMemoryCallback cb,
+                             void *opaque)
+{
+    size_t i = 0;
+    virResctrlAllocMemBWPtr mem_bw;
+
+    if (!alloc || !alloc->mem_bw)
+        return 0;
+
+    mem_bw = alloc->mem_bw;
+    for (i = 0; i < mem_bw->nbandwidths; i++) {
+        if (mem_bw->bandwidths[i]) {
+            if (cb(i, *mem_bw->bandwidths[i], opaque) < 0)
+                return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 int
 virResctrlAllocSetID(virResctrlAllocPtr alloc,
                      const char *id)
index d657c0600817122425c7563e82c73cd413594c36..5ea5b27d3bccf3b5840c60d0fa560324ee997f9f 100644 (file)
@@ -73,6 +73,10 @@ typedef int virResctrlAllocForeachCacheCallback(unsigned int level,
                                                 unsigned long long size,
                                                 void *opaque);
 
+typedef int virResctrlAllocForeachMemoryCallback(unsigned int id,
+                                                 unsigned int size,
+                                                 void *opaque);
+
 virResctrlAllocPtr
 virResctrlAllocNew(void);
 
@@ -91,6 +95,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
                             virResctrlAllocForeachCacheCallback cb,
                             void *opaque);
 
+int
+virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl,
+                             virResctrlAllocForeachMemoryCallback cb,
+                             void *opaque);
+
 int
 virResctrlAllocSetID(virResctrlAllocPtr alloc,
                      const char *id);