This handles only the /proc/cpuinfo part of virHostCPUGetInfo().
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
src/util/virhostcpu.c | 60 +++++++++++++++++++++++++++++++++------------------
1 file changed, 39 insertions(+), 21 deletions(-)
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c485a9721..4d5c56659 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -508,33 +508,17 @@ virHostCPUHasValidSubcoreConfiguration(int threads_per_subcore)
return ret;
}
-int
-virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
- virArch arch,
- unsigned int *cpus,
- unsigned int *mhz,
- unsigned int *nodes,
- unsigned int *sockets,
- unsigned int *cores,
- unsigned int *threads)
+
+static int
+virHostCPUGetInfoParseCPUInfo(FILE *cpuinfo,
+ virArch arch,
+ unsigned int *mhz)
{
- virBitmapPtr present_cpus_map = NULL;
- virBitmapPtr online_cpus_map = NULL;
char line[1024];
- DIR *nodedir = NULL;
- struct dirent *nodedirent = NULL;
- int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
- int threads_per_subcore = 0;
- unsigned int node;
int ret = -1;
- char *sysfs_nodedir = NULL;
- char *sysfs_cpudir = NULL;
- int direrr;
*mhz = 0;
- *cpus = *nodes = *sockets = *cores = *threads = 0;
- /* Start with parsing CPU clock speed from /proc/cpuinfo */
while (fgets(line, sizeof(line), cpuinfo) != NULL) {
if (ARCH_IS_X86(arch)) {
char *buf = line;
@@ -614,6 +598,40 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
}
}
+ ret = 0;
+
+ cleanup:
+ return ret;
+}
+
+int
+virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
+ virArch arch,
+ unsigned int *cpus,
+ unsigned int *mhz,
+ unsigned int *nodes,
+ unsigned int *sockets,
+ unsigned int *cores,
+ unsigned int *threads)
+{
+ virBitmapPtr present_cpus_map = NULL;
+ virBitmapPtr online_cpus_map = NULL;
+ DIR *nodedir = NULL;
+ struct dirent *nodedirent = NULL;
+ int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
+ int threads_per_subcore = 0;
+ unsigned int node;
+ int ret = -1;
+ char *sysfs_nodedir = NULL;
+ char *sysfs_cpudir = NULL;
+ int direrr;
+
+ *cpus = *nodes = *sockets = *cores = *threads = 0;
+
+ /* Start with parsing CPU clock speed from /proc/cpuinfo */
+ if (virHostCPUGetInfoParseCPUInfo(cpuinfo, arch, mhz) < 0)
+ goto cleanup;
+
/* 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 = virHostCPUGetPresentBitmap();
--
2.14.3