On a 24-thread/6-core SPARC T1, lscpu would wrongly output "5 threads per core". It seems that the 6c T1 is simply an 8c T1 where 2c are disabled (offering a lesser model for a lower price, and all that marketing fluff). So the machine description header of the 6c T1 reports 32 threads, but only goes on to provide 24 elements thereafter, which is why Linux will report threads 24-31 as "offline". So far so good. But lscpu would take the number of all (online and offline) threads (32) and divides it by the number of online cores (6), which yields an odd 5.33 threads/core. Simply pick the number of online threads. [Also, remove stray "(s)"s that do not belong there, and properly declare threads, avoid using "CPU" (which is an overloaded term meaning either thread, or package/NUMA node).] Signed-off-by: Jan Engelhardt <jengelh@xxxxxxxxxx> --- sys-utils/lscpu.c | 31 ++++++++++++++++--------------- 1 files changed, 16 insertions(+), 15 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 79c6857..c4da29b 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -81,7 +81,7 @@ enum { MODE_64BIT = (1 << 2) }; -/* cache(s) description */ +/* cache description */ struct cpu_cache { char *name; char *size; @@ -366,7 +366,7 @@ read_basicinfo(struct lscpu_desc *desc) err(EXIT_FAILURE, _("error: uname failed")); desc->arch = xstrdup(utsbuf.machine); - /* count CPU(s) */ + /* count threads */ while(path_exist(_PATH_SYS_SYSTEM "/cpu/cpu%d", desc->ncpus)) desc->ncpus++; @@ -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,6 @@ 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; desc->socketmaps = calloc(nsockets, sizeof(cpu_set_t *)); if (!desc->socketmaps) @@ -830,11 +831,11 @@ print_readable(struct lscpu_desc *desc, int hex) #else print_s(_("Byte Order:"), "Big Endian"); #endif - print_n(_("CPU(s):"), desc->ncpus); + print_n(_("Threads:"), desc->ncpus); if (desc->online) - print_cpuset(hex ? _("On-line CPU(s) mask:") : - _("On-line CPU(s) list:"), + print_cpuset(hex ? _("On-line thread mask:") : + _("On-line thread list:"), desc->online, hex); if (desc->online && CPU_COUNT_S(setsize, desc->online) != desc->ncpus) { @@ -852,20 +853,20 @@ print_readable(struct lscpu_desc *desc, int hex) if (!is_cpu_online(desc, i)) CPU_SET_S(i, setsize, set); } - print_cpuset(hex ? _("Off-line CPU(s) mask:") : - _("Off-line CPU(s) list:"), + print_cpuset(hex ? _("Off-line thread mask:") : + _("Off-line thread list:"), set, hex); cpuset_free(set); } if (desc->nsockets) { - print_n(_("Thread(s) per core:"), desc->nthreads / desc->ncores); - print_n(_("Core(s) per socket:"), desc->ncores / desc->nsockets); - print_n(_("CPU socket(s):"), desc->nsockets); + print_n(_("Threads per core:"), desc->nthreads / desc->ncores); + print_n(_("Cores per socket:"), desc->ncores / desc->nsockets); + print_n(_("CPU sockets:"), desc->nsockets); } if (desc->nnodes) - print_n(_("NUMA node(s):"), desc->nnodes); + print_n(_("NUMA nodes:"), desc->nnodes); if (desc->vendor) print_s(_("Vendor ID:"), desc->vendor); if (desc->family) @@ -900,7 +901,7 @@ print_readable(struct lscpu_desc *desc, int hex) } for (i = 0; i < desc->nnodes; i++) { - snprintf(buf, sizeof(buf), _("NUMA node%d CPU(s):"), i); + snprintf(buf, sizeof(buf), _("NUMA node%d threads:"), i); print_cpuset(buf, desc->nodemaps[i], hex); } } -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html