From 255a3b8bb8cbcb3f689cc3332983983bfbf9eca0 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Wed, 9 May 2018 18:08:32 +0200 Subject: [PATCH 172/173] lscpu, chcpu: Avoid use of the old CPU macros The old CPU macros are limited to 1024 cores. As a result, lscpu cannot count sockets on large systems. Use new scalable macros. Signed-off-by: Stanislav Brabec Cc: Michael Matz Addresses: http://bugzilla.redhat.com/show_bug.cgi?id=1579439 Upstream: http://github.com/karelzak/util-linux/commit/538b50cb0a4aac56b6b3b6e4d1e8ce886854c6d8 --- sys-utils/chcpu.c | 6 +++--- sys-utils/lscpu.c | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c index ada0eaacc..7843dfb22 100644 --- a/sys-utils/chcpu.c +++ b/sys-utils/chcpu.c @@ -81,7 +81,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable) size_t fails = 0; for (cpu = 0; cpu < setsize; cpu++) { - if (!CPU_ISSET(cpu, cpu_set)) + if (!CPU_ISSET_S(cpu, setsize, cpu_set)) continue; if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) { warnx(_("CPU %d does not exist"), cpu); @@ -127,7 +127,7 @@ static int cpu_enable(cpu_set_t *cpu_set, size_t setsize, int enable) } else { printf(_("CPU %d disabled\n"), cpu); if (onlinecpus) - CPU_CLR(cpu, onlinecpus); + CPU_CLR_S(cpu, setsize, onlinecpus); } } } @@ -173,7 +173,7 @@ static int cpu_configure(cpu_set_t *cpu_set, size_t setsize, int configure) size_t fails = 0; for (cpu = 0; cpu < setsize; cpu++) { - if (!CPU_ISSET(cpu, cpu_set)) + if (!CPU_ISSET_S(cpu, setsize, cpu_set)) continue; if (!path_exist(_PATH_SYS_CPU "/cpu%d", cpu)) { warnx(_("CPU %d does not exist"), cpu); diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index 4c15de1d4..002ad0d1c 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -626,7 +626,7 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod) desc->idx2cpunum = xcalloc(desc->ncpuspos, sizeof(int)); for (num = 0, idx = 0; num < maxcpus; num++) { - if (CPU_ISSET(num, tmp)) + if (CPU_ISSET_S(num, setsize, tmp)) desc->idx2cpunum[idx++] = num; } cpuset_free(tmp); @@ -2038,6 +2038,7 @@ int main(int argc, char *argv[]) int c, i; int columns[ARRAY_SIZE(coldescs)], ncolumns = 0; int cpu_modifier_specified = 0; + size_t setsize; static const struct option longopts[] = { { "all", no_argument, NULL, 'a' }, @@ -2134,10 +2135,12 @@ int main(int argc, char *argv[]) read_basicinfo(desc, mod); + setsize = CPU_ALLOC_SIZE(maxcpus); + for (i = 0; i < desc->ncpuspos; i++) { /* only consider present CPUs */ if (desc->present && - !CPU_ISSET(real_cpu_num(desc, i), desc->present)) + !CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)) continue; read_topology(desc, i); read_cache(desc, i); -- 2.14.4