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