Gather the total number of physical cores needed for the next patch and add the data to the tests. The incorrect value in test 7 is expected as the test is based on data from a machine that has incorrect NUMA information. --- src/libvirt_private.syms | 1 + src/nodeinfo.c | 37 ++++++++++++++++++++++------- src/nodeinfo.h | 2 ++ tests/nodeinfodata/linux-x86-test1.expected | 2 +- tests/nodeinfodata/linux-x86-test2.expected | 2 +- tests/nodeinfodata/linux-x86-test3.expected | 2 +- tests/nodeinfodata/linux-x86-test4.expected | 2 +- tests/nodeinfodata/linux-x86-test5.expected | 2 +- tests/nodeinfodata/linux-x86-test6.expected | 2 +- tests/nodeinfodata/linux-x86-test7.expected | 2 +- tests/nodeinfodata/linux-x86-test8.expected | 2 +- tests/nodeinfotest.c | 11 +++++---- 12 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7be58ee..031937f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -918,6 +918,7 @@ nodeGetCPUMap; nodeGetCPUStats; nodeGetFreeMemory; nodeGetInfo; +nodeGetInfoCores; nodeGetMemoryParameters; nodeGetMemoryStats; nodeSetMemoryParameters; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 477104f..b21fc3a 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -90,7 +90,8 @@ freebsdNodeGetCPUCount(void) /* NB, this is not static as we need to call it from the testsuite */ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, const char *sysfs_dir, - virNodeInfoPtr nodeinfo); + virNodeInfoPtr nodeinfo, + unsigned int *totalcores); static int linuxNodeGetCPUStats(FILE *procstat, int cpuNum, @@ -228,12 +229,13 @@ CPU_COUNT(cpu_set_t *set) static int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) -ATTRIBUTE_NONNULL(5) +ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6) virNodeParseNode(const char *node, int *sockets, int *cores, int *threads, - int *offline) + int *offline, + unsigned int *totalcores) { int ret = -1; int processors = 0; @@ -357,6 +359,7 @@ virNodeParseNode(const char *node, continue; core = CPU_COUNT(&core_maps[i]); + *totalcores += core; if (core > *cores) *cores = core; } @@ -376,7 +379,8 @@ cleanup: int linuxNodeInfoCPUPopulate(FILE *cpuinfo, const char *sysfs_dir, - virNodeInfoPtr nodeinfo) + virNodeInfoPtr nodeinfo, + unsigned int *totalcoresinfo) { char line[1024]; DIR *nodedir = NULL; @@ -386,6 +390,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, int ret = -1; char *sysfs_nodedir = NULL; char *sysfs_cpudir = NULL; + unsigned int totalcores = 0; nodeinfo->cpus = 0; nodeinfo->mhz = 0; @@ -503,7 +508,7 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo, } if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores, - &threads, &offline)) < 0) + &threads, &offline, &totalcores)) < 0) goto cleanup; VIR_FREE(sysfs_cpudir); @@ -538,8 +543,9 @@ fallback: goto cleanup; } + totalcores = 0; if ((cpus = virNodeParseNode(sysfs_cpudir, &socks, &cores, - &threads, &offline)) < 0) + &threads, &offline, &totalcores)) < 0) goto cleanup; nodeinfo->nodes = 1; @@ -582,6 +588,9 @@ done: nodeinfo->threads = 1; } + if (totalcoresinfo) + *totalcoresinfo = totalcores; + ret = 0; cleanup: @@ -864,7 +873,10 @@ error: } #endif -int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) + +int +nodeGetInfoCores(virNodeInfoPtr nodeinfo, + unsigned int *totalcores) { virArch hostarch = virArchFromHost(); @@ -881,7 +893,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) return -1; } - ret = linuxNodeInfoCPUPopulate(cpuinfo, SYSFS_SYSTEM_PATH, nodeinfo); + ret = linuxNodeInfoCPUPopulate(cpuinfo, SYSFS_SYSTEM_PATH, + nodeinfo, totalcores); if (ret < 0) goto cleanup; @@ -936,6 +949,14 @@ cleanup: #endif } + +int +nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo) +{ + return nodeGetInfoCores(nodeinfo, NULL); +} + + int nodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED, int cpuNum ATTRIBUTE_UNUSED, virNodeCPUStatsPtr params ATTRIBUTE_UNUSED, diff --git a/src/nodeinfo.h b/src/nodeinfo.h index 350f3c3..02b136d 100644 --- a/src/nodeinfo.h +++ b/src/nodeinfo.h @@ -28,6 +28,8 @@ # include "capabilities.h" int nodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo); +int nodeGetInfoCores(virNodeInfoPtr nodeinfo, unsigned int *totalcores); + int nodeCapsInitNUMA(virCapsPtr caps); int nodeGetCPUStats(virConnectPtr conn, diff --git a/tests/nodeinfodata/linux-x86-test1.expected b/tests/nodeinfodata/linux-x86-test1.expected index 4c86824..3136949 100644 --- a/tests/nodeinfodata/linux-x86-test1.expected +++ b/tests/nodeinfodata/linux-x86-test1.expected @@ -1 +1 @@ -CPUs: 2/2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1 +CPUs: 2/2, MHz: 2800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Total cores: 2 diff --git a/tests/nodeinfodata/linux-x86-test2.expected b/tests/nodeinfodata/linux-x86-test2.expected index 33bfbf3..34ab5f7 100644 --- a/tests/nodeinfodata/linux-x86-test2.expected +++ b/tests/nodeinfodata/linux-x86-test2.expected @@ -1 +1 @@ -CPUs: 2/2, MHz: 800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1 +CPUs: 2/2, MHz: 800, Nodes: 1, Sockets: 1, Cores: 2, Threads: 1, Total cores: 2 diff --git a/tests/nodeinfodata/linux-x86-test3.expected b/tests/nodeinfodata/linux-x86-test3.expected index 0306f86..85ca9e0 100644 --- a/tests/nodeinfodata/linux-x86-test3.expected +++ b/tests/nodeinfodata/linux-x86-test3.expected @@ -1 +1 @@ -CPUs: 48/48, MHz: 2100, Nodes: 8, Sockets: 1, Cores: 6, Threads: 1 +CPUs: 48/48, MHz: 2100, Nodes: 8, Sockets: 1, Cores: 6, Threads: 1, Total cores: 48 diff --git a/tests/nodeinfodata/linux-x86-test4.expected b/tests/nodeinfodata/linux-x86-test4.expected index 0c8f956..3f01271 100644 --- a/tests/nodeinfodata/linux-x86-test4.expected +++ b/tests/nodeinfodata/linux-x86-test4.expected @@ -1 +1 @@ -CPUs: 16/16, MHz: 1064, Nodes: 2, Sockets: 1, Cores: 8, Threads: 1 +CPUs: 16/16, MHz: 1064, Nodes: 2, Sockets: 1, Cores: 8, Threads: 1, Total cores: 16 diff --git a/tests/nodeinfodata/linux-x86-test5.expected b/tests/nodeinfodata/linux-x86-test5.expected index e63cf76..f5a2dfb 100644 --- a/tests/nodeinfodata/linux-x86-test5.expected +++ b/tests/nodeinfodata/linux-x86-test5.expected @@ -1 +1 @@ -CPUs: 4/4, MHz: 1861, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1 +CPUs: 4/4, MHz: 1861, Nodes: 1, Sockets: 1, Cores: 4, Threads: 1, Total cores: 4 diff --git a/tests/nodeinfodata/linux-x86-test6.expected b/tests/nodeinfodata/linux-x86-test6.expected index 7ffcb8e..6d2e6a9 100644 --- a/tests/nodeinfodata/linux-x86-test6.expected +++ b/tests/nodeinfodata/linux-x86-test6.expected @@ -1 +1 @@ -CPUs: 6/8, MHz: 1596, Nodes: 1, Sockets: 1, Cores: 4, Threads: 2 +CPUs: 6/8, MHz: 1596, Nodes: 1, Sockets: 1, Cores: 4, Threads: 2, Total cores: 4 diff --git a/tests/nodeinfodata/linux-x86-test7.expected b/tests/nodeinfodata/linux-x86-test7.expected index e56360d..b32095e 100644 --- a/tests/nodeinfodata/linux-x86-test7.expected +++ b/tests/nodeinfodata/linux-x86-test7.expected @@ -1 +1 @@ -CPUs: 24/24, MHz: 2200, Nodes: 1, Sockets: 1, Cores: 24, Threads: 1 +CPUs: 24/24, MHz: 2200, Nodes: 1, Sockets: 1, Cores: 24, Threads: 1, Total cores: 12 diff --git a/tests/nodeinfodata/linux-x86-test8.expected b/tests/nodeinfodata/linux-x86-test8.expected index 124ed32..44ec1b5 100644 --- a/tests/nodeinfodata/linux-x86-test8.expected +++ b/tests/nodeinfodata/linux-x86-test8.expected @@ -1 +1 @@ -CPUs: 64/64, MHz: 2593, Nodes: 1, Sockets: 1, Cores: 64, Threads: 1 +CPUs: 64/64, MHz: 2593, Nodes: 1, Sockets: 1, Cores: 64, Threads: 1, Total cores: 64 diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c index d900eb9..076e28e 100644 --- a/tests/nodeinfotest.c +++ b/tests/nodeinfotest.c @@ -27,7 +27,8 @@ main(void) extern int linuxNodeInfoCPUPopulate(FILE *cpuinfo, char *sysfs_dir, - virNodeInfoPtr nodeinfo); + virNodeInfoPtr nodeinfo, + unsigned int *totalcores); static int linuxTestCompareFiles(const char *cpuinfofile, @@ -39,6 +40,7 @@ linuxTestCompareFiles(const char *cpuinfofile, char *expectData = NULL; virNodeInfo nodeinfo; FILE *cpuinfo; + unsigned int totalcores = 0; if (virtTestLoadFile(outputfile, &expectData) < 0) goto fail; @@ -48,7 +50,8 @@ linuxTestCompareFiles(const char *cpuinfofile, goto fail; memset(&nodeinfo, 0, sizeof(nodeinfo)); - if (linuxNodeInfoCPUPopulate(cpuinfo, sysfs_dir, &nodeinfo) < 0) { + if (linuxNodeInfoCPUPopulate(cpuinfo, sysfs_dir, + &nodeinfo, &totalcores) < 0) { if (virTestGetDebug()) { virErrorPtr error = virSaveLastError(); if (error && error->code != VIR_ERR_OK) @@ -62,10 +65,10 @@ linuxTestCompareFiles(const char *cpuinfofile, if (virAsprintf(&actualData, "CPUs: %u/%u, MHz: %u, Nodes: %u, Sockets: %u, " - "Cores: %u, Threads: %u\n", + "Cores: %u, Threads: %u, Total cores: %u\n", nodeinfo.cpus, VIR_NODEINFO_MAXCPUS(nodeinfo), nodeinfo.mhz, nodeinfo.nodes, nodeinfo.sockets, - nodeinfo.cores, nodeinfo.threads) < 0) + nodeinfo.cores, nodeinfo.threads, totalcores) < 0) goto fail; if (STRNEQ(actualData, expectData)) { -- 1.8.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list