Blob Blame History Raw
From f2670434261a395acfe97a9bd93bd55c6b3fb1f2 Mon Sep 17 00:00:00 2001
Message-Id: <f2670434261a395acfe97a9bd93bd55c6b3fb1f2@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Wed, 7 Oct 2020 18:45:41 +0200
Subject: [PATCH] numa: expose HMAT APIs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

These APIs will be used by QEMU driver when building the command
line.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
(cherry picked from commit 11d8ca9794e80224d0634d67da86a20380c22ab5)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518

Conflicts:
- src/conf/numa_conf.c:
- src/conf/numa_conf.h: Both are context.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <ad394e2359bfbbff4c9d61ac2bf5faca1eba5943.1602087923.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/numa_conf.c     | 139 +++++++++++++++++++++++++++++++++++++++
 src/conf/numa_conf.h     |  28 ++++++++
 src/libvirt_private.syms |   6 ++
 3 files changed, 173 insertions(+)

diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
index c90fb01bb6..277a695d84 100644
--- a/src/conf/numa_conf.c
+++ b/src/conf/numa_conf.c
@@ -1800,3 +1800,142 @@ virDomainNumaGetMemorySize(virDomainNumaPtr numa)
 
     return ret;
 }
+
+
+bool
+virDomainNumaHasHMAT(const virDomainNuma *numa)
+{
+    size_t i;
+
+    if (!numa)
+        return false;
+
+    if (numa->ninterconnects)
+        return true;
+
+    for (i = 0; i < numa->nmem_nodes; i++) {
+        if (numa->mem_nodes[i].ncaches)
+            return true;
+    }
+
+    return false;
+}
+
+
+size_t
+virDomainNumaGetNodeCacheCount(const virDomainNuma *numa,
+                               size_t node)
+{
+    if (!numa || node >= numa->nmem_nodes)
+        return 0;
+
+    return numa->mem_nodes[node].ncaches;
+}
+
+
+int
+virDomainNumaGetNodeCache(const virDomainNuma *numa,
+                          size_t node,
+                          size_t cache,
+                          unsigned int *level,
+                          unsigned int *size,
+                          unsigned int *line,
+                          virDomainCacheAssociativity *associativity,
+                          virDomainCachePolicy *policy)
+{
+    const virDomainNumaNode *cell;
+
+    if (!numa || node >= numa->nmem_nodes)
+        return -1;
+
+    cell = &numa->mem_nodes[node];
+
+    if (cache >= cell->ncaches)
+        return -1;
+
+    *level = cell->caches[cache].level;
+    *size = cell->caches[cache].size;
+    *line = cell->caches[cache].line;
+    *associativity = cell->caches[cache].associativity;
+    *policy = cell->caches[cache].policy;
+    return 0;
+}
+
+
+ssize_t
+virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
+                              size_t node)
+{
+    size_t i;
+    unsigned int maxBandwidth = 0;
+    ssize_t candidateBandwidth = -1;
+    unsigned int minLatency = UINT_MAX;
+    ssize_t candidateLatency = -1;
+
+    if (!numa || node >= numa->nmem_nodes)
+        return -1;
+
+    for (i = 0; i < numa->ninterconnects; i++) {
+        const virDomainNumaInterconnect *l = &numa->interconnects[i];
+
+        if (l->target != node)
+            continue;
+
+        switch (l->type) {
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_LATENCY:
+            if (l->value < minLatency) {
+                minLatency = l->value;
+                candidateLatency = l->initiator;
+            }
+            break;
+
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
+            if (l->value > maxBandwidth) {
+                maxBandwidth = l->value;
+                candidateBandwidth = l->initiator;
+            }
+            break;
+        }
+    }
+
+    if (candidateLatency >= 0)
+        return candidateLatency;
+
+    return candidateBandwidth;
+}
+
+
+size_t
+virDomainNumaGetInterconnectsCount(const virDomainNuma *numa)
+{
+    if (!numa)
+        return 0;
+
+    return numa->ninterconnects;
+}
+
+
+int
+virDomainNumaGetInterconnect(const virDomainNuma *numa,
+                             size_t i,
+                             virDomainNumaInterconnectType *type,
+                             unsigned int *initiator,
+                             unsigned int *target,
+                             unsigned int *cache,
+                             virDomainMemoryLatency *accessType,
+                             unsigned long *value)
+{
+    const virDomainNumaInterconnect *l;
+
+    if (!numa || i >= numa->ninterconnects)
+        return -1;
+
+    l = &numa->interconnects[i];
+    *type = l->type;
+    *initiator = l->initiator;
+    *target = l->target;
+    *cache = l->cache;
+    *accessType = l->accessType;
+    *value = l->value;
+    return 0;
+}
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
index 2963004c94..63843a1cc6 100644
--- a/src/conf/numa_conf.h
+++ b/src/conf/numa_conf.h
@@ -220,3 +220,31 @@ int virDomainNumaDefFormatXML(virBufferPtr buf, virDomainNumaPtr def);
 int virDomainNumaDefValidate(const virDomainNuma *def);
 
 unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa);
+
+bool virDomainNumaHasHMAT(const virDomainNuma *numa);
+
+size_t virDomainNumaGetNodeCacheCount(const virDomainNuma *numa,
+                                       size_t node);
+
+int virDomainNumaGetNodeCache(const virDomainNuma *numa,
+                              size_t node,
+                              size_t cache,
+                              unsigned int *level,
+                              unsigned int *size,
+                              unsigned int *line,
+                              virDomainCacheAssociativity *associativity,
+                              virDomainCachePolicy *policy);
+
+ssize_t virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
+                                      size_t node);
+
+size_t virDomainNumaGetInterconnectsCount(const virDomainNuma *numa);
+
+int virDomainNumaGetInterconnect(const virDomainNuma *numa,
+                                 size_t i,
+                                 virDomainNumaInterconnectType *type,
+                                 unsigned int *initiator,
+                                 unsigned int *target,
+                                 unsigned int *cache,
+                                 virDomainMemoryLatency *accessType,
+                                 unsigned long *value);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index de95e3b116..fdd104cd25 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -820,14 +820,20 @@ virDomainNumaCheckABIStability;
 virDomainNumaEquals;
 virDomainNumaFree;
 virDomainNumaGetCPUCountTotal;
+virDomainNumaGetInterconnect;
+virDomainNumaGetInterconnectsCount;
 virDomainNumaGetMaxCPUID;
 virDomainNumaGetMemorySize;
+virDomainNumaGetNodeCache;
+virDomainNumaGetNodeCacheCount;
 virDomainNumaGetNodeCount;
 virDomainNumaGetNodeCpumask;
 virDomainNumaGetNodeDiscard;
 virDomainNumaGetNodeDistance;
+virDomainNumaGetNodeInitiator;
 virDomainNumaGetNodeMemoryAccessMode;
 virDomainNumaGetNodeMemorySize;
+virDomainNumaHasHMAT;
 virDomainNumaNew;
 virDomainNumaNodeDistanceIsUsingDefaults;
 virDomainNumaNodesDistancesAreBeingSet;
-- 
2.29.2