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