]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: print correct number of threads per core if possible
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Fri, 29 Jul 2016 12:13:36 +0000 (14:13 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 3 Aug 2016 11:35:05 +0000 (13:35 +0200)
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>
sys-utils/lscpu.c

index 1da595b3dac7fddcd8b0b7966382c423d853e857..52a944d3a99c8ce9c9d1fd9ac241580b8585e0af 100644 (file)
@@ -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) {