Blame SOURCES/0172-lscpu-chcpu-Avoid-use-of-the-old-CPU-macros.patch

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