c313de
From e624d2040a5a8e16e670accc52e110393d9fb2b8 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <e624d2040a5a8e16e670accc52e110393d9fb2b8@dist-git>
c313de
From: Andrea Bolognani <abologna@redhat.com>
c313de
Date: Tue, 11 Jun 2019 10:55:02 +0200
c313de
Subject: [PATCH] util: Introduce virNumaNodesetToCPUset()
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
This helper converts a set of NUMA node to the set of CPUs
c313de
they contain.
c313de
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
(cherry picked from commit 2d2b26f96fed1e95dd4495168cee73c5c4092634)
c313de
c313de
https://bugzilla.redhat.com/show_bug.cgi?id=1716908
c313de
c313de
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
c313de
Message-Id: <20190611085506.12564-3-abologna@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/libvirt_private.syms |  1 +
c313de
 src/util/virnuma.c       | 55 ++++++++++++++++++++++++++++++++++++++++
c313de
 src/util/virnuma.h       |  2 ++
c313de
 3 files changed, 58 insertions(+)
c313de
c313de
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c313de
index 05c96c29e2..7c48908a54 100644
c313de
--- a/src/libvirt_private.syms
c313de
+++ b/src/libvirt_private.syms
c313de
@@ -2485,6 +2485,7 @@ virNumaGetPages;
c313de
 virNumaIsAvailable;
c313de
 virNumaNodeIsAvailable;
c313de
 virNumaNodesetIsAvailable;
c313de
+virNumaNodesetToCPUset;
c313de
 virNumaSetPagePoolSize;
c313de
 virNumaSetupMemoryPolicy;
c313de
 
c313de
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
c313de
index fd15714553..75f80dcd30 100644
c313de
--- a/src/util/virnuma.c
c313de
+++ b/src/util/virnuma.c
c313de
@@ -311,6 +311,49 @@ virNumaGetNodeCPUs(int node,
c313de
 # undef MASK_CPU_ISSET
c313de
 # undef n_bits
c313de
 
c313de
+/**
c313de
+ * virNumaNodesetToCPUset:
c313de
+ * @nodeset: bitmap containing a set of NUMA nodes
c313de
+ * @cpuset: return location for a bitmap containing a set of CPUs
c313de
+ *
c313de
+ * Convert a set of NUMA node to the set of CPUs they contain.
c313de
+ *
c313de
+ * Returns 0 on success, <0 on failure.
c313de
+ */
c313de
+int
c313de
+virNumaNodesetToCPUset(virBitmapPtr nodeset,
c313de
+                       virBitmapPtr *cpuset)
c313de
+{
c313de
+    VIR_AUTOPTR(virBitmap) allNodesCPUs = NULL;
c313de
+    size_t nodesetSize;
c313de
+    size_t i;
c313de
+
c313de
+    *cpuset = NULL;
c313de
+
c313de
+    if (!nodeset)
c313de
+        return 0;
c313de
+
c313de
+    allNodesCPUs = virBitmapNewEmpty();
c313de
+    nodesetSize = virBitmapSize(nodeset);
c313de
+
c313de
+    for (i = 0; i < nodesetSize; i++) {
c313de
+        VIR_AUTOPTR(virBitmap) nodeCPUs = NULL;
c313de
+
c313de
+        if (!virBitmapIsBitSet(nodeset, i))
c313de
+            continue;
c313de
+
c313de
+        if (virNumaGetNodeCPUs(i, &nodeCPUs) < 0)
c313de
+            return -1;
c313de
+
c313de
+        if (virBitmapUnion(allNodesCPUs, nodeCPUs) < 0)
c313de
+            return -1;
c313de
+    }
c313de
+
c313de
+    VIR_STEAL_PTR(*cpuset, allNodesCPUs);
c313de
+
c313de
+    return 0;
c313de
+}
c313de
+
c313de
 #else /* !WITH_NUMACTL */
c313de
 
c313de
 int
c313de
@@ -365,6 +408,18 @@ virNumaGetNodeCPUs(int node ATTRIBUTE_UNUSED,
c313de
                    _("NUMA isn't available on this host"));
c313de
     return -1;
c313de
 }
c313de
+
c313de
+int
c313de
+virNumaNodesetToCPUset(virBitmapPtr nodeset ATTRIBUTE_UNUSED,
c313de
+                       virBitmapPtr *cpuset)
c313de
+{
c313de
+    *cpuset = NULL;
c313de
+
c313de
+    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
c313de
+                   _("NUMA isn't available on this host"));
c313de
+    return -1;
c313de
+}
c313de
+
c313de
 #endif /* !WITH_NUMACTL */
c313de
 
c313de
 /**
c313de
diff --git a/src/util/virnuma.h b/src/util/virnuma.h
c313de
index a3ffb6d6c7..df7911db4e 100644
c313de
--- a/src/util/virnuma.h
c313de
+++ b/src/util/virnuma.h
c313de
@@ -48,6 +48,8 @@ int virNumaGetNodeMemory(int node,
c313de
 unsigned int virNumaGetMaxCPUs(void);
c313de
 
c313de
 int virNumaGetNodeCPUs(int node, virBitmapPtr *cpus) ATTRIBUTE_NOINLINE;
c313de
+int virNumaNodesetToCPUset(virBitmapPtr nodeset,
c313de
+                           virBitmapPtr *cpuset);
c313de
 
c313de
 int virNumaGetPageInfo(int node,
c313de
                        unsigned int page_size,
c313de
-- 
c313de
2.22.0
c313de