On 6/10/20 8:35 PM, Daniel Henrique Barboza wrote:
These helpers will be used in an auto-fill feature for incomplete
NUMA topologies in the next patch.
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
src/conf/numa_conf.c | 46 ++++++++++++++++++++++++++++++++++++++++
src/conf/numa_conf.h | 3 +++
src/libvirt_private.syms | 1 +
3 files changed, 50 insertions(+)
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index 09811cb51b..d022685284 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -1372,3 +1372,49 @@ virDomainNumaGetMemorySize(virDomainNumaPtr numa)
return ret;
}
+
+
+static int
+virDomainNumaRemoveCPUsFromMap(virBitmapPtr result, virBitmapPtr exclude)
+{
+ size_t i;
+
+ for (i = 0; i < virBitmapSize(exclude); i++) {
+ if (!virBitmapIsBitSet(exclude, i))
+ continue;
+
+ if (virBitmapClearBitExpand(result, i) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
This exactly what virBitmapSubtract() does :-)
+
+int
+virDomainNumaFillCPUsInNode(virDomainNumaPtr numa, size_t node,
+ unsigned int maxCpus)
+{
+ g_autoptr(virBitmap) maxCPUsBitmap = virBitmapNew(maxCpus);
+ size_t i;
+
+ if (node >= virDomainNumaGetNodeCount(numa))
+ return -1;
+
+ virBitmapSetAll(maxCPUsBitmap);
+
+ for (i = 0; i < numa->nmem_nodes; i++) {
+ virBitmapPtr nodeCpus = virDomainNumaGetNodeCpumask(numa, i);
+
+ if (i == node)
+ continue;
+
+ if (virDomainNumaRemoveCPUsFromMap(maxCPUsBitmap, nodeCpus) < 0)
+ return -1;
+ }
+
+ virBitmapFree(numa->mem_nodes[node].cpumask);
+ numa->mem_nodes[node].cpumask = g_steal_pointer(&maxCPUsBitmap);
For some weird reason, I'd feel better if the bitmap is replaced only if
it differs. I can't really explain why.
Michal