1
0
forked from pool/util-linux
util-linux/util-linux-lscpu-chcpu-new-cpu-macros.patch

111 lines
3.6 KiB
Diff

From 538b50cb0a4aac56b6b3b6e4d1e8ce886854c6d8 Mon Sep 17 00:00:00 2001
From: Stanislav Brabec <sbrabec@suse.cz>
Date: Wed, 9 May 2018 18:08:32 +0200
Subject: [PATCH] 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 <sbrabec@suse.cz>
Cc: Michael Matz <matz@suse.de>
---
sys-utils/chcpu.c | 6 +++---
sys-utils/lscpu.c | 13 +++++++++----
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/sys-utils/chcpu.c b/sys-utils/chcpu.c
index 12e52d887..f32b7a6fc 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 %u 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 %u 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 %u does not exist"), cpu);
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 2132511a5..fd6d63bbf 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -478,7 +478,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);
@@ -1109,10 +1109,11 @@ cpu_max_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
{
int i;
float cpu_freq = 0.0;
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
if (desc->present) {
for (i = 0; i < desc->ncpuspos; i++) {
- if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+ if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
&& desc->maxmhz[i]) {
float freq = atof(desc->maxmhz[i]);
@@ -1131,10 +1132,11 @@ cpu_min_mhz(struct lscpu_desc *desc, char *buf, size_t bufsz)
{
int i;
float cpu_freq = -1.0;
+ size_t setsize = CPU_ALLOC_SIZE(maxcpus);
if (desc->present) {
for (i = 0; i < desc->ncpuspos; i++) {
- if (CPU_ISSET(real_cpu_num(desc, i), desc->present)
+ if (CPU_ISSET_S(real_cpu_num(desc, i), setsize, desc->present)
&& desc->minmhz[i]) {
float freq = atof(desc->minmhz[i]);
@@ -1931,6 +1933,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' },
@@ -2034,10 +2037,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.16.3