]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: fix fallback nthreads calculation
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Wed, 10 Aug 2011 08:34:29 +0000 (10:34 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 18 Oct 2011 05:12:41 +0000 (07:12 +0200)
The fallback calculation of nthreads did not consider books.
In order to avoid division/multiply by/with zero make sure each number
used is at least "1".

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
sys-utils/lscpu.c

index 210a4c2431823bae5655792ddb83666442468f51..9755be50ae23739c6befb0cf10cac7cd6ae39bc1 100644 (file)
@@ -649,17 +649,21 @@ read_topology(struct lscpu_desc *desc, int num)
                nthreads = CPU_COUNT_S(setsize, thread_siblings);
                /* cores within one socket */
                ncores = CPU_COUNT_S(setsize, core_siblings) / nthreads;
-               /* number of sockets within one book */
-               nsockets = desc->ncpus / nthreads / ncores;
+               /* number of sockets within one book.
+                * Because of odd / non-present cpu maps and to keep
+                * calculation easy we make sure that nsockets and
+                * nbooks is at least 1.
+                */
+               nsockets = desc->ncpus / nthreads / ncores ?: 1;
                /* number of books */
-               nbooks = desc->ncpus / nthreads / ncores / nsockets;
+               nbooks = desc->ncpus / nthreads / ncores / nsockets ?: 1;
 
                /* all threads, see also read_basicinfo()
-                * -- this is fallback for kernels where is not
+                * -- fallback for kernels without
                 *    /sys/devices/system/cpu/online.
                 */
                if (!desc->nthreads)
-                       desc->nthreads = nsockets * ncores * nthreads;
+                       desc->nthreads = nbooks * nsockets * ncores * nthreads;
                /* For each map we make sure that it can have up to ncpus
                 * entries. This is because we cannot reliably calculate the
                 * number of cores, sockets and books on all architectures.