summaryrefslogtreecommitdiffstats
path: root/sys-utils/lscpu.c
diff options
context:
space:
mode:
authorHeiko Carstens2016-07-29 14:13:36 +0200
committerKarel Zak2016-08-03 13:35:05 +0200
commit2c497d328840c8cf6d915675fd6168ff616517d3 (patch)
tree93e89e56034d8e98b9ddd734ea98b364b60ce33a /sys-utils/lscpu.c
parentlspcu: minor manpage improvement (diff)
downloadkernel-qcow2-util-linux-2c497d328840c8cf6d915675fd6168ff616517d3.tar.gz
kernel-qcow2-util-linux-2c497d328840c8cf6d915675fd6168ff616517d3.tar.xz
kernel-qcow2-util-linux-2c497d328840c8cf6d915675fd6168ff616517d3.zip
lscpu: print correct number of threads per core if possible
lscpu calculates the number of threads per core by dividing the number of online cpus with the number of cores. This may or may not give the correct number of threads per core depending on the number of online CPUs (and which CPUs are online). At least on s390 there is a new "max thread id" field within /proc/cpuinfo present which reliably allows us to tell the number of threads per core. Let's use this instead, like we already have also special treatment to figure out the number core per socket etc. on s390. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r--sys-utils/lscpu.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 1da595b3d..52a944d3a 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -216,6 +216,7 @@ struct lscpu_desc {
char *stepping;
char *bogomips;
char *flags;
+ char *mtid; /* maximum thread id (s390) */
int dispatching; /* none, horizontal or vertical */
int mode; /* rm, lm or/and tm */
@@ -566,6 +567,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
else if (lookup(buf, "bogomips per cpu", &desc->bogomips)) ; /* s390 */
else if (lookup(buf, "cpu", &desc->cpu)) ;
else if (lookup(buf, "revision", &desc->revision)) ;
+ else if (lookup(buf, "max thread id", &desc->mtid)) ; /* s390 */
else if (lookup_cache(buf, desc)) ;
else
continue;
@@ -1804,9 +1806,11 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
}
if (desc->nsockets) {
- int cores_per_socket, sockets_per_book, books_per_drawer, drawers;
+ int threads_per_core, cores_per_socket, sockets_per_book;
+ int books_per_drawer, drawers;
- cores_per_socket = sockets_per_book = books_per_drawer = drawers = 0;
+ threads_per_core = cores_per_socket = sockets_per_book = 0;
+ books_per_drawer = drawers = 0;
/* s390 detects its cpu topology via /proc/sysinfo, if present.
* Using simply the cpu topology masks in sysfs will not give
* usable results since everything is virtualized. E.g.
@@ -1830,7 +1834,10 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
if (fd)
fclose(fd);
}
- print_n(_("Thread(s) per core:"), desc->nthreads / desc->ncores);
+ if (desc->mtid)
+ threads_per_core = atoi(desc->mtid) + 1;
+ print_n(_("Thread(s) per core:"),
+ threads_per_core ?: desc->nthreads / desc->ncores);
print_n(_("Core(s) per socket:"),
cores_per_socket ?: desc->ncores / desc->nsockets);
if (desc->nbooks) {