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@xxxxxxxxxx> --- sys-utils/lscpu.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 1da595b3dac7..52a944d3a99c 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) { -- 2.6.6 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html