The host which has a deconfigured core is treated as though the topology is
not correct and the SMT is not reliable. Which is not true, so report the topology
correctly by detecting if the host is actually in a proper SMT mode with
the deconfigured core.
Signed-off-by: Nitesh Konkar <nitkon12(a)linux.vnet.ibm.com>
---
Steps to reproduce:
This is what `virsh capabilities` shows in a
10-core POWER8 system (8 threads per core):
$ virsh capabilities | grep threads
<topology sockets='1' cores='10' threads='8'/>
There are 10 CPUs online, given SMT is off (`ppc64_cpu --smt=off`):
$ cat /sys/devices/system/cpu/online
0,8,16,24,32,40,48,56,64,72
Now, if one core is disabled/offlined (e.g., the last one, number 72)...
$ echo 0 | sudo tee /sys/devices/system/cpu/cpu72/online
Then this messes up with `virsh capabilities` number of cores (now 80) and threads (now 1)
:
$ virsh capabilities | grep threads
<topology sockets='1' cores='80' threads='1'/>
It goes back to normal if that CPU is enabled/onlined again:
$ echo 1 | sudo tee /sys/devices/system/cpu/cpu72/online
1
$ virsh capabilities | grep threads
<topology sockets='1' cores='10' threads='8'/>
src/util/virhostcpu.c | 8 ++++++--
tests/virhostcpudata/linux-ppc64-deconf-cpus.expected | 2 +-
2 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c485a97..5301583 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -524,6 +524,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
DIR *nodedir = NULL;
struct dirent *nodedirent = NULL;
int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
+ int total_online_cpus = 0;
int threads_per_subcore = 0;
unsigned int node;
int ret = -1;
@@ -623,6 +624,8 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
if (!online_cpus_map)
goto cleanup;
+ total_online_cpus = virBitmapCountBits(online_cpus_map);
+
/* OK, we've parsed clock speed out of /proc/cpuinfo. Get the
* core, node, socket, thread and topology information from /sys
*/
@@ -746,10 +749,11 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
* the nodeinfo structure isn't designed to carry the full topology so
* we're going to lie about the detected topology to notify the user
* to check the host capabilities for the actual topology. */
- if ((*nodes *
+ if (((*nodes *
*sockets *
*cores *
- *threads) != (*cpus + offline)) {
+ *threads) != (*cpus + offline)) &&
+ ((total_online_cpus * threads_per_subcore) != (*cpus + offline))) {
*nodes = 1;
*sockets = 1;
*cores = *cpus + offline;
diff --git a/tests/virhostcpudata/linux-ppc64-deconf-cpus.expected
b/tests/virhostcpudata/linux-ppc64-deconf-cpus.expected
index 113bfa8..7998a8f 100644
--- a/tests/virhostcpudata/linux-ppc64-deconf-cpus.expected
+++ b/tests/virhostcpudata/linux-ppc64-deconf-cpus.expected
@@ -1 +1 @@
-CPUs: 80/80, MHz: 3690, Nodes: 1, Sockets: 1, Cores: 80, Threads: 1
+CPUs: 80/96, MHz: 3690, Nodes: 4, Sockets: 1, Cores: 3, Threads: 8
--
1.8.3.1