397dc2
From f2670434261a395acfe97a9bd93bd55c6b3fb1f2 Mon Sep 17 00:00:00 2001
397dc2
Message-Id: <f2670434261a395acfe97a9bd93bd55c6b3fb1f2@dist-git>
397dc2
From: Michal Privoznik <mprivozn@redhat.com>
397dc2
Date: Wed, 7 Oct 2020 18:45:41 +0200
397dc2
Subject: [PATCH] numa: expose HMAT APIs
397dc2
MIME-Version: 1.0
397dc2
Content-Type: text/plain; charset=UTF-8
397dc2
Content-Transfer-Encoding: 8bit
397dc2
397dc2
These APIs will be used by QEMU driver when building the command
397dc2
line.
397dc2
397dc2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
397dc2
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
397dc2
(cherry picked from commit 11d8ca9794e80224d0634d67da86a20380c22ab5)
397dc2
397dc2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1749518
397dc2
397dc2
Conflicts:
397dc2
- src/conf/numa_conf.c:
397dc2
- src/conf/numa_conf.h: Both are context.
397dc2
397dc2
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
397dc2
Message-Id: <ad394e2359bfbbff4c9d61ac2bf5faca1eba5943.1602087923.git.mprivozn@redhat.com>
397dc2
Reviewed-by: Ján Tomko <jtomko@redhat.com>
397dc2
---
397dc2
 src/conf/numa_conf.c     | 139 +++++++++++++++++++++++++++++++++++++++
397dc2
 src/conf/numa_conf.h     |  28 ++++++++
397dc2
 src/libvirt_private.syms |   6 ++
397dc2
 3 files changed, 173 insertions(+)
397dc2
397dc2
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
397dc2
index c90fb01bb6..277a695d84 100644
397dc2
--- a/src/conf/numa_conf.c
397dc2
+++ b/src/conf/numa_conf.c
397dc2
@@ -1800,3 +1800,142 @@ virDomainNumaGetMemorySize(virDomainNumaPtr numa)
397dc2
 
397dc2
     return ret;
397dc2
 }
397dc2
+
397dc2
+
397dc2
+bool
397dc2
+virDomainNumaHasHMAT(const virDomainNuma *numa)
397dc2
+{
397dc2
+    size_t i;
397dc2
+
397dc2
+    if (!numa)
397dc2
+        return false;
397dc2
+
397dc2
+    if (numa->ninterconnects)
397dc2
+        return true;
397dc2
+
397dc2
+    for (i = 0; i < numa->nmem_nodes; i++) {
397dc2
+        if (numa->mem_nodes[i].ncaches)
397dc2
+            return true;
397dc2
+    }
397dc2
+
397dc2
+    return false;
397dc2
+}
397dc2
+
397dc2
+
397dc2
+size_t
397dc2
+virDomainNumaGetNodeCacheCount(const virDomainNuma *numa,
397dc2
+                               size_t node)
397dc2
+{
397dc2
+    if (!numa || node >= numa->nmem_nodes)
397dc2
+        return 0;
397dc2
+
397dc2
+    return numa->mem_nodes[node].ncaches;
397dc2
+}
397dc2
+
397dc2
+
397dc2
+int
397dc2
+virDomainNumaGetNodeCache(const virDomainNuma *numa,
397dc2
+                          size_t node,
397dc2
+                          size_t cache,
397dc2
+                          unsigned int *level,
397dc2
+                          unsigned int *size,
397dc2
+                          unsigned int *line,
397dc2
+                          virDomainCacheAssociativity *associativity,
397dc2
+                          virDomainCachePolicy *policy)
397dc2
+{
397dc2
+    const virDomainNumaNode *cell;
397dc2
+
397dc2
+    if (!numa || node >= numa->nmem_nodes)
397dc2
+        return -1;
397dc2
+
397dc2
+    cell = &numa->mem_nodes[node];
397dc2
+
397dc2
+    if (cache >= cell->ncaches)
397dc2
+        return -1;
397dc2
+
397dc2
+    *level = cell->caches[cache].level;
397dc2
+    *size = cell->caches[cache].size;
397dc2
+    *line = cell->caches[cache].line;
397dc2
+    *associativity = cell->caches[cache].associativity;
397dc2
+    *policy = cell->caches[cache].policy;
397dc2
+    return 0;
397dc2
+}
397dc2
+
397dc2
+
397dc2
+ssize_t
397dc2
+virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
397dc2
+                              size_t node)
397dc2
+{
397dc2
+    size_t i;
397dc2
+    unsigned int maxBandwidth = 0;
397dc2
+    ssize_t candidateBandwidth = -1;
397dc2
+    unsigned int minLatency = UINT_MAX;
397dc2
+    ssize_t candidateLatency = -1;
397dc2
+
397dc2
+    if (!numa || node >= numa->nmem_nodes)
397dc2
+        return -1;
397dc2
+
397dc2
+    for (i = 0; i < numa->ninterconnects; i++) {
397dc2
+        const virDomainNumaInterconnect *l = &numa->interconnects[i];
397dc2
+
397dc2
+        if (l->target != node)
397dc2
+            continue;
397dc2
+
397dc2
+        switch (l->type) {
397dc2
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_LATENCY:
397dc2
+            if (l->value < minLatency) {
397dc2
+                minLatency = l->value;
397dc2
+                candidateLatency = l->initiator;
397dc2
+            }
397dc2
+            break;
397dc2
+
397dc2
+        case VIR_DOMAIN_NUMA_INTERCONNECT_TYPE_BANDWIDTH:
397dc2
+            if (l->value > maxBandwidth) {
397dc2
+                maxBandwidth = l->value;
397dc2
+                candidateBandwidth = l->initiator;
397dc2
+            }
397dc2
+            break;
397dc2
+        }
397dc2
+    }
397dc2
+
397dc2
+    if (candidateLatency >= 0)
397dc2
+        return candidateLatency;
397dc2
+
397dc2
+    return candidateBandwidth;
397dc2
+}
397dc2
+
397dc2
+
397dc2
+size_t
397dc2
+virDomainNumaGetInterconnectsCount(const virDomainNuma *numa)
397dc2
+{
397dc2
+    if (!numa)
397dc2
+        return 0;
397dc2
+
397dc2
+    return numa->ninterconnects;
397dc2
+}
397dc2
+
397dc2
+
397dc2
+int
397dc2
+virDomainNumaGetInterconnect(const virDomainNuma *numa,
397dc2
+                             size_t i,
397dc2
+                             virDomainNumaInterconnectType *type,
397dc2
+                             unsigned int *initiator,
397dc2
+                             unsigned int *target,
397dc2
+                             unsigned int *cache,
397dc2
+                             virDomainMemoryLatency *accessType,
397dc2
+                             unsigned long *value)
397dc2
+{
397dc2
+    const virDomainNumaInterconnect *l;
397dc2
+
397dc2
+    if (!numa || i >= numa->ninterconnects)
397dc2
+        return -1;
397dc2
+
397dc2
+    l = &numa->interconnects[i];
397dc2
+    *type = l->type;
397dc2
+    *initiator = l->initiator;
397dc2
+    *target = l->target;
397dc2
+    *cache = l->cache;
397dc2
+    *accessType = l->accessType;
397dc2
+    *value = l->value;
397dc2
+    return 0;
397dc2
+}
397dc2
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
397dc2
index 2963004c94..63843a1cc6 100644
397dc2
--- a/src/conf/numa_conf.h
397dc2
+++ b/src/conf/numa_conf.h
397dc2
@@ -220,3 +220,31 @@ int virDomainNumaDefFormatXML(virBufferPtr buf, virDomainNumaPtr def);
397dc2
 int virDomainNumaDefValidate(const virDomainNuma *def);
397dc2
 
397dc2
 unsigned int virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa);
397dc2
+
397dc2
+bool virDomainNumaHasHMAT(const virDomainNuma *numa);
397dc2
+
397dc2
+size_t virDomainNumaGetNodeCacheCount(const virDomainNuma *numa,
397dc2
+                                       size_t node);
397dc2
+
397dc2
+int virDomainNumaGetNodeCache(const virDomainNuma *numa,
397dc2
+                              size_t node,
397dc2
+                              size_t cache,
397dc2
+                              unsigned int *level,
397dc2
+                              unsigned int *size,
397dc2
+                              unsigned int *line,
397dc2
+                              virDomainCacheAssociativity *associativity,
397dc2
+                              virDomainCachePolicy *policy);
397dc2
+
397dc2
+ssize_t virDomainNumaGetNodeInitiator(const virDomainNuma *numa,
397dc2
+                                      size_t node);
397dc2
+
397dc2
+size_t virDomainNumaGetInterconnectsCount(const virDomainNuma *numa);
397dc2
+
397dc2
+int virDomainNumaGetInterconnect(const virDomainNuma *numa,
397dc2
+                                 size_t i,
397dc2
+                                 virDomainNumaInterconnectType *type,
397dc2
+                                 unsigned int *initiator,
397dc2
+                                 unsigned int *target,
397dc2
+                                 unsigned int *cache,
397dc2
+                                 virDomainMemoryLatency *accessType,
397dc2
+                                 unsigned long *value);
397dc2
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
397dc2
index de95e3b116..fdd104cd25 100644
397dc2
--- a/src/libvirt_private.syms
397dc2
+++ b/src/libvirt_private.syms
397dc2
@@ -820,14 +820,20 @@ virDomainNumaCheckABIStability;
397dc2
 virDomainNumaEquals;
397dc2
 virDomainNumaFree;
397dc2
 virDomainNumaGetCPUCountTotal;
397dc2
+virDomainNumaGetInterconnect;
397dc2
+virDomainNumaGetInterconnectsCount;
397dc2
 virDomainNumaGetMaxCPUID;
397dc2
 virDomainNumaGetMemorySize;
397dc2
+virDomainNumaGetNodeCache;
397dc2
+virDomainNumaGetNodeCacheCount;
397dc2
 virDomainNumaGetNodeCount;
397dc2
 virDomainNumaGetNodeCpumask;
397dc2
 virDomainNumaGetNodeDiscard;
397dc2
 virDomainNumaGetNodeDistance;
397dc2
+virDomainNumaGetNodeInitiator;
397dc2
 virDomainNumaGetNodeMemoryAccessMode;
397dc2
 virDomainNumaGetNodeMemorySize;
397dc2
+virDomainNumaHasHMAT;
397dc2
 virDomainNumaNew;
397dc2
 virDomainNumaNodeDistanceIsUsingDefaults;
397dc2
 virDomainNumaNodesDistancesAreBeingSet;
397dc2
-- 
397dc2
2.29.2
397dc2