render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From ada52f5411197e518765aa5e09d41fc7a4550861 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <ada52f5411197e518765aa5e09d41fc7a4550861@dist-git>
7a3408
From: Andrea Bolognani <abologna@redhat.com>
7a3408
Date: Wed, 5 Aug 2015 18:18:31 +0200
7a3408
Subject: [PATCH] nodeinfo: Calculate present and online CPUs only once
7a3408
7a3408
Move the calls to the respective functions from virNodeParseNode(),
7a3408
which is executed once for every NUMA node, to
7a3408
linuxNodeInfoCPUPopulate(), which is executed just once per host.
7a3408
7a3408
(cherry picked from commit 6395ec1cf029cfc0be371eea66da7bc379c31c69)
7a3408
7a3408
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1213713
7a3408
7a3408
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/nodeinfo.c | 46 ++++++++++++++++++++++++++--------------------
7a3408
 1 file changed, 26 insertions(+), 20 deletions(-)
7a3408
7a3408
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
7a3408
index 2328a86..6c8849d 100644
7a3408
--- a/src/nodeinfo.c
7a3408
+++ b/src/nodeinfo.c
7a3408
@@ -390,12 +390,14 @@ virNodeParseSocket(const char *dir,
7a3408
 /* parses a node entry, returning number of processors in the node and
7a3408
  * filling arguments */
7a3408
 static int
7a3408
-ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
7a3408
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3)
7a3408
 ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
7a3408
 ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7)
7a3408
-virNodeParseNode(const char *sysfs_prefix,
7a3408
-                 const char *node,
7a3408
+ATTRIBUTE_NONNULL(8)
7a3408
+virNodeParseNode(const char *node,
7a3408
                  virArch arch,
7a3408
+                 virBitmapPtr present_cpus_map,
7a3408
+                 virBitmapPtr online_cpus_map,
7a3408
                  int *sockets,
7a3408
                  int *cores,
7a3408
                  int *threads,
7a3408
@@ -408,12 +410,10 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
     int processors = 0;
7a3408
     DIR *cpudir = NULL;
7a3408
     struct dirent *cpudirent = NULL;
7a3408
-    virBitmapPtr present_cpumap = NULL;
7a3408
-    virBitmapPtr online_cpus_map = NULL;
7a3408
     virBitmapPtr node_cpus_map = NULL;
7a3408
     virBitmapPtr sockets_map = NULL;
7a3408
     virBitmapPtr *cores_maps = NULL;
7a3408
-    int npresent_cpus;
7a3408
+    int npresent_cpus = virBitmapSize(present_cpus_map);
7a3408
     int sock_max = 0;
7a3408
     int sock;
7a3408
     int core;
7a3408
@@ -431,15 +431,6 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
         goto cleanup;
7a3408
     }
7a3408
 
7a3408
-    present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix);
7a3408
-    if (!present_cpumap)
7a3408
-        goto cleanup;
7a3408
-    online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix);
7a3408
-    if (!online_cpus_map)
7a3408
-        goto cleanup;
7a3408
-
7a3408
-    npresent_cpus = virBitmapSize(present_cpumap);
7a3408
-
7a3408
     /* Keep track of the CPUs that belong to the current node */
7a3408
     if (!(node_cpus_map = virBitmapNew(npresent_cpus)))
7a3408
         goto cleanup;
7a3408
@@ -452,7 +443,7 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
         if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
7a3408
             continue;
7a3408
 
7a3408
-        if (!virBitmapIsBitSet(present_cpumap, cpu))
7a3408
+        if (!virBitmapIsBitSet(present_cpus_map, cpu))
7a3408
             continue;
7a3408
 
7a3408
         /* Mark this CPU as part of the current node */
7a3408
@@ -565,8 +556,6 @@ virNodeParseNode(const char *sysfs_prefix,
7a3408
     VIR_FREE(cores_maps);
7a3408
     virBitmapFree(sockets_map);
7a3408
     virBitmapFree(node_cpus_map);
7a3408
-    virBitmapFree(online_cpus_map);
7a3408
-    virBitmapFree(present_cpumap);
7a3408
 
7a3408
     return ret;
7a3408
 }
7a3408
@@ -578,6 +567,8 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
7a3408
                          virNodeInfoPtr nodeinfo)
7a3408
 {
7a3408
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
7a3408
+    virBitmapPtr present_cpus_map = NULL;
7a3408
+    virBitmapPtr online_cpus_map = NULL;
7a3408
     char line[1024];
7a3408
     DIR *nodedir = NULL;
7a3408
     struct dirent *nodedirent = NULL;
7a3408
@@ -669,6 +660,15 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
7a3408
         }
7a3408
     }
7a3408
 
7a3408
+    /* Get information about what CPUs are present in the host and what
7a3408
+     * CPUs are online, so that we don't have to so for each node */
7a3408
+    present_cpus_map = nodeGetPresentCPUBitmap(sysfs_prefix);
7a3408
+    if (!present_cpus_map)
7a3408
+        goto cleanup;
7a3408
+    online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix);
7a3408
+    if (!online_cpus_map)
7a3408
+        goto cleanup;
7a3408
+
7a3408
     /* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
7a3408
      * core, node, socket, thread and topology information from /sys
7a3408
      */
7a3408
@@ -690,7 +690,9 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
7a3408
                         prefix, nodedirent->d_name) < 0)
7a3408
             goto cleanup;
7a3408
 
7a3408
-        if ((cpus = virNodeParseNode(sysfs_prefix, sysfs_cpudir, arch,
7a3408
+        if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
7a3408
+                                     present_cpus_map,
7a3408
+                                     online_cpus_map,
7a3408
                                      &socks, &cores,
7a3408
                                      &threads, &offline)) < 0)
7a3408
             goto cleanup;
7a3408
@@ -721,7 +723,9 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
7a3408
     if (virAsprintf(&sysfs_cpudir, "%s/cpu", prefix) < 0)
7a3408
         goto cleanup;
7a3408
 
7a3408
-    if ((cpus = virNodeParseNode(sysfs_prefix, sysfs_cpudir, arch,
7a3408
+    if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
7a3408
+                                 present_cpus_map,
7a3408
+                                 online_cpus_map,
7a3408
                                  &socks, &cores,
7a3408
                                  &threads, &offline)) < 0)
7a3408
         goto cleanup;
7a3408
@@ -775,6 +779,8 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
7a3408
         ret = -1;
7a3408
     }
7a3408
 
7a3408
+    virBitmapFree(present_cpus_map);
7a3408
+    virBitmapFree(online_cpus_map);
7a3408
     VIR_FREE(sysfs_nodedir);
7a3408
     VIR_FREE(sysfs_cpudir);
7a3408
     return ret;
7a3408
-- 
7a3408
2.5.0
7a3408