summaryrefslogtreecommitdiffstats
path: root/sys-utils/lscpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r--sys-utils/lscpu.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 79c6857e2..c3bb536cd 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -113,15 +113,15 @@ struct lscpu_desc {
/* sockets -- based on core_siblings (internal kernel map of cpuX's
* hardware threads within the same physical_package_id (socket)) */
- int nsockets; /* number of all sockets */
+ int nsockets; /* number of all online sockets */
cpu_set_t **socketmaps; /* unique core_siblings */
/* cores -- based on thread_siblings (internel kernel map of cpuX's
* hardware threads within the same core as cpuX) */
- int ncores; /* number of all cores */
+ int ncores; /* number of all online cores */
cpu_set_t **coremaps; /* unique thread_siblings */
- int nthreads; /* number of threads */
+ int nthreads; /* number of online threads */
int ncaches;
struct cpu_cache *caches;
@@ -415,8 +415,11 @@ read_basicinfo(struct lscpu_desc *desc)
maxcpus = desc->ncpus > 2048 ? desc->ncpus : 2048;
/* get mask for online CPUs */
- if (path_exist(_PATH_SYS_SYSTEM "/cpu/online"))
+ if (path_exist(_PATH_SYS_SYSTEM "/cpu/online")) {
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
desc->online = path_cpulist(_PATH_SYS_SYSTEM "/cpu/online");
+ desc->nthreads = CPU_COUNT_S(setsize, desc->online);
+ }
}
static int
@@ -586,8 +589,13 @@ read_topology(struct lscpu_desc *desc, int num)
ncores = CPU_COUNT_S(setsize, core_siblings) / nthreads;
/* number of sockets */
nsockets = desc->ncpus / nthreads / ncores;
- /* all threads */
- desc->nthreads = nsockets * ncores * nthreads;
+
+ /* all threads, see also read_basicinfo()
+ * -- this is fallback for kernels where is not
+ * /sys/devices/system/cpu/online.
+ */
+ if (!desc->nthreads)
+ desc->nthreads = nsockets * ncores * nthreads;
desc->socketmaps = calloc(nsockets, sizeof(cpu_set_t *));
if (!desc->socketmaps)