[PATCH v2 RESEND 10/17] util: Introduce virResctrlAllocSetMemoryBandwidth

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Bing Niu <bing.niu@xxxxxxxxx>

Introduce an API to allow setting of the MBA from domain XML.

Signed-off-by: Bing Niu <bing.niu@xxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/util/virresctrl.c    | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virresctrl.h    |  5 +++++
 3 files changed, 54 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index cd598f9..0d2fc5c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2657,6 +2657,7 @@ virResctrlAllocNew;
 virResctrlAllocRemove;
 virResctrlAllocSetCacheSize;
 virResctrlAllocSetID;
+virResctrlAllocSetMemoryBandwidth;
 virResctrlInfoGetCache;
 virResctrlInfoNew;
 
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index dc57c89..f25e7bc 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -965,6 +965,54 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
 }
 
 
+/* virResctrlAllocSetMemoryBandwidth
+ * @alloc: Pointer to an active allocation
+ * @id: node id of MBA to be set
+ * @memory_bandwidth: new memory bandwidth value
+ *
+ * Set the @memory_bandwidth for the node @id entry in the @alloc.
+ *
+ * Returns 0 on success, -1 on failure with error message set.
+ */
+int
+virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
+                                  unsigned int id,
+                                  unsigned int memory_bandwidth)
+{
+    virResctrlAllocMemBWPtr mem_bw = alloc->mem_bw;
+
+    if (memory_bandwidth > 100) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("Memory Bandwidth value exceeding 100 is invalid."));
+        return -1;
+    }
+
+    if (!mem_bw) {
+        if (VIR_ALLOC(mem_bw) < 0)
+            return -1;
+        alloc->mem_bw = mem_bw;
+    }
+
+    if (mem_bw->nbandwidths <= id &&
+        VIR_EXPAND_N(mem_bw->bandwidths, mem_bw->nbandwidths,
+                     id - mem_bw->nbandwidths + 1) < 0)
+        return -1;
+
+    if (mem_bw->bandwidths[id]) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Memory Bandwidth already defined for node %u"),
+                       id);
+        return -1;
+    }
+
+    if (VIR_ALLOC(mem_bw->bandwidths[id]) < 0)
+        return -1;
+
+    *(mem_bw->bandwidths[id]) = memory_bandwidth;
+    return 0;
+}
+
+
 /* virResctrlAllocForeachMemory
  * @alloc: Pointer to an active allocation
  * @cb: Callback function
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 5ea5b27..8d62517 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -96,6 +96,11 @@ virResctrlAllocForeachCache(virResctrlAllocPtr alloc,
                             void *opaque);
 
 int
+virResctrlAllocSetMemoryBandwidth(virResctrlAllocPtr alloc,
+                                  unsigned int id,
+                                  unsigned int memory_bandwidth);
+
+int
 virResctrlAllocForeachMemory(virResctrlAllocPtr resctrl,
                              virResctrlAllocForeachMemoryCallback cb,
                              void *opaque);
-- 
2.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux