diff options
author | Heiko Carstens | 2011-08-10 10:34:29 +0200 |
---|---|---|
committer | Heiko Carstens | 2011-08-14 17:34:17 +0200 |
commit | 32a46618bc615200829864210a906cd39f99e02e (patch) | |
tree | 6940f5c82ccef253cdb548fcb73e3841a1243935 /sys-utils/lscpu.c | |
parent | lscpu: fix cpu map array sizes (diff) | |
download | kernel-qcow2-util-linux-32a46618bc615200829864210a906cd39f99e02e.tar.gz kernel-qcow2-util-linux-32a46618bc615200829864210a906cd39f99e02e.tar.xz kernel-qcow2-util-linux-32a46618bc615200829864210a906cd39f99e02e.zip |
lscpu: fix fallback nthreads calculation
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>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r-- | sys-utils/lscpu.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 4eeb502e1..c5e5f2d30 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -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. |