]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Allow > UINT_MAX of cache for NUMA nodes
authorLin Yang <lin.a.yang@intel.com>
Sat, 5 Nov 2022 00:20:20 +0000 (17:20 -0700)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 8 Nov 2022 08:49:43 +0000 (09:49 +0100)
The high-bandwidth memory (HBM) in cache mode might be greater than
UINT_MAX of cache per NUMA node, so change to unsigned long long.

Signed-off-by: Lin Yang <lin.a.yang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/conf/capabilities.c
src/conf/numa_conf.c
src/conf/numa_conf.h

index e498c77efc6cc0b591fc27b205198bb7f6c58a1c..85c06f0d2b9523477a3d85682a0bd66e44333bea 100644 (file)
@@ -1549,10 +1549,10 @@ virCapabilitiesGetNUMAPagesInfo(int node,
 
 
 static int
-virCapabilitiesGetNodeCacheReadFile(const char *prefix,
-                                    const char *dir,
-                                    const char *file,
-                                    unsigned int *value)
+virCapabilitiesGetNodeCacheReadFileUint(const char *prefix,
+                                        const char *dir,
+                                        const char *file,
+                                        unsigned int *value)
 {
     g_autofree char *path = g_build_filename(prefix, dir, file, NULL);
     int rv = virFileReadValueUint(value, "%s", path);
@@ -1570,6 +1570,28 @@ virCapabilitiesGetNodeCacheReadFile(const char *prefix,
 }
 
 
+static int
+virCapabilitiesGetNodeCacheReadFileUllong(const char *prefix,
+                                          const char *dir,
+                                          const char *file,
+                                          unsigned long long *value)
+{
+    g_autofree char *path = g_build_filename(prefix, dir, file, NULL);
+    int rv = virFileReadValueUllong(value, "%s", path);
+
+    if (rv < 0) {
+        if (rv == -2) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("File '%s' does not exist"),
+                           path);
+        }
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 virCapsHostNUMACellCacheComparator(const void *a,
                                    const void *b)
@@ -1612,18 +1634,18 @@ virCapabilitiesGetNodeCache(int node,
             return -1;
         }
 
-        if (virCapabilitiesGetNodeCacheReadFile(path, entry->d_name,
-                                                "size", &cache.size) < 0)
+        if (virCapabilitiesGetNodeCacheReadFileUllong(path, entry->d_name,
+                                                      "size", &cache.size) < 0)
             return -1;
 
         cache.size >>= 10; /* read in bytes but stored in kibibytes */
 
-        if (virCapabilitiesGetNodeCacheReadFile(path, entry->d_name,
-                                                "line_size", &cache.line) < 0)
+        if (virCapabilitiesGetNodeCacheReadFileUint(path, entry->d_name,
+                                                    "line_size", &cache.line) < 0)
             return -1;
 
-        if (virCapabilitiesGetNodeCacheReadFile(path, entry->d_name,
-                                                "indexing", &indexing) < 0)
+        if (virCapabilitiesGetNodeCacheReadFileUint(path, entry->d_name,
+                                                    "indexing", &indexing) < 0)
             return -1;
 
         /* see enum cache_indexing in kernel */
@@ -1638,8 +1660,8 @@ virCapabilitiesGetNodeCache(int node,
                 return -1;
         }
 
-        if (virCapabilitiesGetNodeCacheReadFile(path, entry->d_name,
-                                                "write_policy", &write_policy) < 0)
+        if (virCapabilitiesGetNodeCacheReadFileUint(path, entry->d_name,
+                                                    "write_policy", &write_policy) < 0)
             return -1;
 
         /* see enum cache_write_policy in kernel */
@@ -1793,26 +1815,26 @@ virCapabilitiesHostNUMAInitInterconnectsNode(GArray *interconnects,
     if (!virFileExists(path))
         return 0;
 
-    if (virCapabilitiesGetNodeCacheReadFile(path, "initiators",
-                                            "read_bandwidth",
-                                            &read_bandwidth) < 0)
+    if (virCapabilitiesGetNodeCacheReadFileUint(path, "initiators",
+                                                "read_bandwidth",
+                                                &read_bandwidth) < 0)
         return -1;
-    if (virCapabilitiesGetNodeCacheReadFile(path, "initiators",
-                                            "write_bandwidth",
-                                            &write_bandwidth) < 0)
+    if (virCapabilitiesGetNodeCacheReadFileUint(path, "initiators",
+                                                "write_bandwidth",
+                                                &write_bandwidth) < 0)
         return -1;
 
     /* Bandwidths are read in MiB but stored in KiB */
     read_bandwidth <<= 10;
     write_bandwidth <<= 10;
 
-    if (virCapabilitiesGetNodeCacheReadFile(path, "initiators",
-                                            "read_latency",
-                                            &read_latency) < 0)
+    if (virCapabilitiesGetNodeCacheReadFileUint(path, "initiators",
+                                                "read_latency",
+                                                &read_latency) < 0)
         return -1;
-    if (virCapabilitiesGetNodeCacheReadFile(path, "initiators",
-                                            "write_latency",
-                                            &write_latency) < 0)
+    if (virCapabilitiesGetNodeCacheReadFileUint(path, "initiators",
+                                                "write_latency",
+                                                &write_latency) < 0)
         return -1;
 
     initPath = g_strdup_printf("%s/initiators", path);
index 688aa7b40914e9be1cdafbce580195ff6e53424f..b55bb3ffcb8142308af70199eabb3530373642e6 100644 (file)
@@ -1765,7 +1765,7 @@ virNumaCacheFormat(virBuffer *buf,
         }
 
         virBufferAsprintf(&childBuf,
-                          "<size value='%u' unit='KiB'/>\n",
+                          "<size value='%llu' unit='KiB'/>\n",
                           cache->size);
 
         if (cache->line) {
index 1d1e816870f6040a4bf8a5cb7b0c9c1a9ad5b995..bbb928abb20bc7d36044fc48ab4b278d7802809e 100644 (file)
@@ -263,7 +263,7 @@ void virNumaDistanceFormat(virBuffer *buf,
 typedef struct _virNumaCache virNumaCache;
 struct _virNumaCache {
     unsigned int level; /* cache level */
-    unsigned int size;  /* cache size */
+    unsigned long long size;  /* cache size */
     unsigned int line;  /* line size, !!! in bytes !!! */
     virNumaCacheAssociativity associativity; /* cache associativity */
     virNumaCachePolicy policy; /* cache policy */