diff options
author | Heiko Carstens | 2011-08-10 10:34:28 +0200 |
---|---|---|
committer | Heiko Carstens | 2011-08-14 17:34:12 +0200 |
commit | 9d1a3a18f31388c0a4587943e63cdf2c8a490387 (patch) | |
tree | 92b82ef2737adc64eeed5b7ca0be3eb5778deb02 /sys-utils/lscpu.c | |
parent | lscpu: fix s390 bogomips detection coding style (diff) | |
download | kernel-qcow2-util-linux-9d1a3a18f31388c0a4587943e63cdf2c8a490387.tar.gz kernel-qcow2-util-linux-9d1a3a18f31388c0a4587943e63cdf2c8a490387.tar.xz kernel-qcow2-util-linux-9d1a3a18f31388c0a4587943e63cdf2c8a490387.zip |
lscpu: fix cpu map array sizes
Completely virtualized architectures like s390 may have multiple
virtual sockets and/or cores where each of them has a different
number of cores and cpus.
So the general assumption within the allocation scheme that e.g.
each socket contains the same number of cores is not necessarily
true. To make sure the arrays are always large enough we simply
allocate enough memory so that each array could hold cpu masks
for all present cpus.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r-- | sys-utils/lscpu.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 48c8044d4..4eeb502e1 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -660,11 +660,16 @@ read_topology(struct lscpu_desc *desc, int num) */ if (!desc->nthreads) desc->nthreads = 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. + * E.g. completely virtualized architectures like s390 may + * have multiple sockets of different sizes. + */ + desc->coremaps = xcalloc(desc->ncpus, sizeof(cpu_set_t *)); + desc->socketmaps = xcalloc(desc->ncpus, sizeof(cpu_set_t *)); if (book_siblings) - desc->bookmaps = xcalloc(nbooks, sizeof(cpu_set_t *)); - - desc->socketmaps = xcalloc(nsockets, sizeof(cpu_set_t *)); - desc->coremaps = xcalloc(ncores * nsockets, sizeof(cpu_set_t *)); + desc->bookmaps = xcalloc(desc->ncpus, sizeof(cpu_set_t *)); } add_cpuset_to_array(desc->socketmaps, &desc->nsockets, core_siblings); |