mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 09:55:18 +00:00
nodeinfo: Calculate present and online CPUs only once
Move the calls to the respective functions from virNodeParseNode(), which is executed once for every NUMA node, to linuxNodeInfoCPUPopulate(), which is executed just once per host.
This commit is contained in:
parent
05be606282
commit
6395ec1cf0
@ -391,12 +391,14 @@ virNodeParseSocket(const char *dir,
|
|||||||
/* parses a node entry, returning number of processors in the node and
|
/* parses a node entry, returning number of processors in the node and
|
||||||
* filling arguments */
|
* filling arguments */
|
||||||
static int
|
static int
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3)
|
||||||
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
|
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
|
||||||
ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7)
|
ATTRIBUTE_NONNULL(6) ATTRIBUTE_NONNULL(7)
|
||||||
virNodeParseNode(const char *sysfs_prefix,
|
ATTRIBUTE_NONNULL(8)
|
||||||
const char *node,
|
virNodeParseNode(const char *node,
|
||||||
virArch arch,
|
virArch arch,
|
||||||
|
virBitmapPtr present_cpus_map,
|
||||||
|
virBitmapPtr online_cpus_map,
|
||||||
int *sockets,
|
int *sockets,
|
||||||
int *cores,
|
int *cores,
|
||||||
int *threads,
|
int *threads,
|
||||||
@ -409,12 +411,10 @@ virNodeParseNode(const char *sysfs_prefix,
|
|||||||
int processors = 0;
|
int processors = 0;
|
||||||
DIR *cpudir = NULL;
|
DIR *cpudir = NULL;
|
||||||
struct dirent *cpudirent = NULL;
|
struct dirent *cpudirent = NULL;
|
||||||
virBitmapPtr present_cpumap = NULL;
|
|
||||||
virBitmapPtr online_cpus_map = NULL;
|
|
||||||
virBitmapPtr node_cpus_map = NULL;
|
virBitmapPtr node_cpus_map = NULL;
|
||||||
virBitmapPtr sockets_map = NULL;
|
virBitmapPtr sockets_map = NULL;
|
||||||
virBitmapPtr *cores_maps = NULL;
|
virBitmapPtr *cores_maps = NULL;
|
||||||
int npresent_cpus;
|
int npresent_cpus = virBitmapSize(present_cpus_map);
|
||||||
int sock_max = 0;
|
int sock_max = 0;
|
||||||
int sock;
|
int sock;
|
||||||
int core;
|
int core;
|
||||||
@ -432,15 +432,6 @@ virNodeParseNode(const char *sysfs_prefix,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
present_cpumap = nodeGetPresentCPUBitmap(sysfs_prefix);
|
|
||||||
if (!present_cpumap)
|
|
||||||
goto cleanup;
|
|
||||||
online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix);
|
|
||||||
if (!online_cpus_map)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
npresent_cpus = virBitmapSize(present_cpumap);
|
|
||||||
|
|
||||||
/* Keep track of the CPUs that belong to the current node */
|
/* Keep track of the CPUs that belong to the current node */
|
||||||
if (!(node_cpus_map = virBitmapNew(npresent_cpus)))
|
if (!(node_cpus_map = virBitmapNew(npresent_cpus)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -453,7 +444,7 @@ virNodeParseNode(const char *sysfs_prefix,
|
|||||||
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!virBitmapIsBitSet(present_cpumap, cpu))
|
if (!virBitmapIsBitSet(present_cpus_map, cpu))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Mark this CPU as part of the current node */
|
/* Mark this CPU as part of the current node */
|
||||||
@ -566,8 +557,6 @@ virNodeParseNode(const char *sysfs_prefix,
|
|||||||
VIR_FREE(cores_maps);
|
VIR_FREE(cores_maps);
|
||||||
virBitmapFree(sockets_map);
|
virBitmapFree(sockets_map);
|
||||||
virBitmapFree(node_cpus_map);
|
virBitmapFree(node_cpus_map);
|
||||||
virBitmapFree(online_cpus_map);
|
|
||||||
virBitmapFree(present_cpumap);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -579,6 +568,8 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
|
|||||||
virNodeInfoPtr nodeinfo)
|
virNodeInfoPtr nodeinfo)
|
||||||
{
|
{
|
||||||
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
|
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SYSTEM_PATH;
|
||||||
|
virBitmapPtr present_cpus_map = NULL;
|
||||||
|
virBitmapPtr online_cpus_map = NULL;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
DIR *nodedir = NULL;
|
DIR *nodedir = NULL;
|
||||||
struct dirent *nodedirent = NULL;
|
struct dirent *nodedirent = NULL;
|
||||||
@ -670,6 +661,15 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get information about what CPUs are present in the host and what
|
||||||
|
* CPUs are online, so that we don't have to so for each node */
|
||||||
|
present_cpus_map = nodeGetPresentCPUBitmap(sysfs_prefix);
|
||||||
|
if (!present_cpus_map)
|
||||||
|
goto cleanup;
|
||||||
|
online_cpus_map = nodeGetOnlineCPUBitmap(sysfs_prefix);
|
||||||
|
if (!online_cpus_map)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
|
/* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
|
||||||
* core, node, socket, thread and topology information from /sys
|
* core, node, socket, thread and topology information from /sys
|
||||||
*/
|
*/
|
||||||
@ -691,7 +691,9 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
|
|||||||
prefix, nodedirent->d_name) < 0)
|
prefix, nodedirent->d_name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((cpus = virNodeParseNode(sysfs_prefix, sysfs_cpudir, arch,
|
if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
|
||||||
|
present_cpus_map,
|
||||||
|
online_cpus_map,
|
||||||
&socks, &cores,
|
&socks, &cores,
|
||||||
&threads, &offline)) < 0)
|
&threads, &offline)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -722,7 +724,9 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
|
|||||||
if (virAsprintf(&sysfs_cpudir, "%s/cpu", prefix) < 0)
|
if (virAsprintf(&sysfs_cpudir, "%s/cpu", prefix) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((cpus = virNodeParseNode(sysfs_prefix, sysfs_cpudir, arch,
|
if ((cpus = virNodeParseNode(sysfs_cpudir, arch,
|
||||||
|
present_cpus_map,
|
||||||
|
online_cpus_map,
|
||||||
&socks, &cores,
|
&socks, &cores,
|
||||||
&threads, &offline)) < 0)
|
&threads, &offline)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -776,6 +780,8 @@ linuxNodeInfoCPUPopulate(const char *sysfs_prefix,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virBitmapFree(present_cpus_map);
|
||||||
|
virBitmapFree(online_cpus_map);
|
||||||
VIR_FREE(sysfs_nodedir);
|
VIR_FREE(sysfs_nodedir);
|
||||||
VIR_FREE(sysfs_cpudir);
|
VIR_FREE(sysfs_cpudir);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user