Skip to content

Commit 60db7af

Browse files
committed
Merge: perf: increase MAX_NR_CPUS to 4096
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/319 JIRA: https://issues.redhat.com/browse/RHEL-73893 Some big systems already reached the 2048 CPU limit, we need to bump it. Signed-off-by: Michael Petlan <mpetlan@redhat.com> Approved-by: Tony Camuso <tcamuso@redhat.com> Approved-by: Jerome Marchand <jmarchan@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Jan Stancek <jstancek@redhat.com>
2 parents 52b0c8a + 23c3e73 commit 60db7af

File tree

16 files changed

+47
-87
lines changed

16 files changed

+47
-87
lines changed

tools/lib/perf/Documentation/libperf.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ SYNOPSIS
3939

4040
struct perf_cpu_map *perf_cpu_map__new_any_cpu(void);
4141
struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
42-
struct perf_cpu_map *perf_cpu_map__read(FILE *file);
4342
struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
4443
struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
4544
struct perf_cpu_map *other);

tools/lib/perf/cpumap.c

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include <ctype.h>
1111
#include <limits.h>
1212
#include "internal.h"
13+
#include <api/fs/fs.h>
14+
15+
#define MAX_NR_CPUS 4096
1316

1417
void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus)
1518
{
@@ -100,12 +103,12 @@ static struct perf_cpu_map *cpu_map__new_sysconf(void)
100103
static struct perf_cpu_map *cpu_map__new_sysfs_online(void)
101104
{
102105
struct perf_cpu_map *cpus = NULL;
103-
FILE *onlnf;
106+
char *buf = NULL;
107+
size_t buf_len;
104108

105-
onlnf = fopen("/sys/devices/system/cpu/online", "r");
106-
if (onlnf) {
107-
cpus = perf_cpu_map__read(onlnf);
108-
fclose(onlnf);
109+
if (sysfs__read_str("devices/system/cpu/online", &buf, &buf_len) >= 0) {
110+
cpus = perf_cpu_map__new(buf);
111+
free(buf);
109112
}
110113
return cpus;
111114
}
@@ -158,62 +161,6 @@ static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, const struct perf_cpu
158161
return cpus;
159162
}
160163

161-
struct perf_cpu_map *perf_cpu_map__read(FILE *file)
162-
{
163-
struct perf_cpu_map *cpus = NULL;
164-
int nr_cpus = 0;
165-
struct perf_cpu *tmp_cpus = NULL, *tmp;
166-
int max_entries = 0;
167-
int n, cpu, prev;
168-
char sep;
169-
170-
sep = 0;
171-
prev = -1;
172-
for (;;) {
173-
n = fscanf(file, "%u%c", &cpu, &sep);
174-
if (n <= 0)
175-
break;
176-
if (prev >= 0) {
177-
int new_max = nr_cpus + cpu - prev - 1;
178-
179-
WARN_ONCE(new_max >= MAX_NR_CPUS, "Perf can support %d CPUs. "
180-
"Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
181-
182-
if (new_max >= max_entries) {
183-
max_entries = new_max + MAX_NR_CPUS / 2;
184-
tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu));
185-
if (tmp == NULL)
186-
goto out_free_tmp;
187-
tmp_cpus = tmp;
188-
}
189-
190-
while (++prev < cpu)
191-
tmp_cpus[nr_cpus++].cpu = prev;
192-
}
193-
if (nr_cpus == max_entries) {
194-
max_entries += MAX_NR_CPUS;
195-
tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu));
196-
if (tmp == NULL)
197-
goto out_free_tmp;
198-
tmp_cpus = tmp;
199-
}
200-
201-
tmp_cpus[nr_cpus++].cpu = cpu;
202-
if (n == 2 && sep == '-')
203-
prev = cpu;
204-
else
205-
prev = -1;
206-
if (n == 1 || sep == '\n')
207-
break;
208-
}
209-
210-
if (nr_cpus > 0)
211-
cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
212-
out_free_tmp:
213-
free(tmp_cpus);
214-
return cpus;
215-
}
216-
217164
struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
218165
{
219166
struct perf_cpu_map *cpus = NULL;
@@ -238,15 +185,15 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
238185
p = NULL;
239186
start_cpu = strtoul(cpu_list, &p, 0);
240187
if (start_cpu >= INT_MAX
241-
|| (*p != '\0' && *p != ',' && *p != '-'))
188+
|| (*p != '\0' && *p != ',' && *p != '-' && *p != '\n'))
242189
goto invalid;
243190

244191
if (*p == '-') {
245192
cpu_list = ++p;
246193
p = NULL;
247194
end_cpu = strtoul(cpu_list, &p, 0);
248195

249-
if (end_cpu >= INT_MAX || (*p != '\0' && *p != ','))
196+
if (end_cpu >= INT_MAX || (*p != '\0' && *p != ',' && *p != '\n'))
250197
goto invalid;
251198

252199
if (end_cpu < start_cpu)
@@ -265,7 +212,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
265212
goto invalid;
266213

267214
if (nr_cpus == max_entries) {
268-
max_entries += MAX_NR_CPUS;
215+
max_entries += max(end_cpu - start_cpu + 1, 16UL);
269216
tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu));
270217
if (tmp == NULL)
271218
goto invalid;
@@ -279,14 +226,15 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
279226
cpu_list = p;
280227
}
281228

282-
if (nr_cpus > 0)
229+
if (nr_cpus > 0) {
283230
cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
284-
else if (*cpu_list != '\0') {
231+
} else if (*cpu_list != '\0') {
285232
pr_warning("Unexpected characters at end of cpu list ('%s'), using online CPUs.",
286233
cpu_list);
287234
cpus = perf_cpu_map__new_online_cpus();
288-
} else
235+
} else {
289236
cpus = perf_cpu_map__new_any_cpu();
237+
}
290238
invalid:
291239
free(tmp_cpus);
292240
out:

tools/lib/perf/include/internal/cpumap.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ DECLARE_RC_STRUCT(perf_cpu_map) {
2121
struct perf_cpu map[];
2222
};
2323

24-
#ifndef MAX_NR_CPUS
25-
#define MAX_NR_CPUS 2048
26-
#endif
27-
2824
struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
2925
int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
3026
bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);

tools/lib/perf/include/perf/cpumap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#define __LIBPERF_CPUMAP_H
44

55
#include <perf/core.h>
6-
#include <stdio.h>
76
#include <stdbool.h>
87

98
/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map's indices. */
@@ -37,7 +36,6 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new_online_cpus(void);
3736
* perf_cpu_map__new_online_cpus is returned.
3837
*/
3938
LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list);
40-
LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file);
4139
LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
4240
LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig,
4341
struct perf_cpu_map *other);

tools/lib/perf/libperf.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ LIBPERF_0.0.1 {
66
perf_cpu_map__get;
77
perf_cpu_map__put;
88
perf_cpu_map__new;
9-
perf_cpu_map__read;
109
perf_cpu_map__nr;
1110
perf_cpu_map__cpu;
1211
perf_cpu_map__has_any_cpu_or_is_empty;

tools/perf/builtin-annotate.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* a histogram of results, along various sorting keys.
88
*/
99
#include "builtin.h"
10+
#include "perf.h"
1011

1112
#include "util/color.h"
1213
#include <linux/list.h>

tools/perf/builtin-diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* DSOs and symbol information, sort them and produce a diff.
77
*/
88
#include "builtin.h"
9+
#include "perf.h"
910

1011
#include "util/debug.h"
1112
#include "util/event.h"

tools/perf/builtin-kwork.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "builtin.h"
9+
#include "perf.h"
910

1011
#include "util/data.h"
1112
#include "util/evlist.h"

tools/perf/builtin-mem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <sys/stat.h>
55
#include <unistd.h>
66
#include "builtin.h"
7+
#include "perf.h"
78

89
#include <subcmd/parse-options.h>
910
#include "util/auxtrace.h"

tools/perf/builtin-sched.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include "builtin.h"
3+
#include "perf.h"
34
#include "perf-sys.h"
45

56
#include "util/cpumap.h"

0 commit comments

Comments
 (0)