Skip to content

Commit 23c3e73

Browse files
committed
libperf cpumap: Grow array of read CPUs in smaller increments
JIRA: https://issues.redhat.com/browse/RHEL-73893 upstream ======== commit bfb9467 Author: Ian Rogers <irogers@google.com> Date: Thu Dec 5 20:40:35 2024 -0800 description =========== Instead of growing the array by 2048, grow by the larger of the current range or 16. As ranges are typical for things like the online CPUs this will mean a single allocation happens. While uncore CPU maps will grow 16 at a time which is a value that is generous except say on large servers. Reviewed-by: Leo Yan <leo.yan@arm.com> Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ben Gainey <ben.gainey@arm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Kyle Meyer <kyle.meyer@hpe.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20241206044035.1062032-9-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Michael Petlan <mpetlan@redhat.com>
1 parent b260d25 commit 23c3e73

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

tools/lib/perf/cpumap.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
212212
goto invalid;
213213

214214
if (nr_cpus == max_entries) {
215-
max_entries += MAX_NR_CPUS;
215+
max_entries += max(end_cpu - start_cpu + 1, 16UL);
216216
tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu));
217217
if (tmp == NULL)
218218
goto invalid;
@@ -226,14 +226,15 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
226226
cpu_list = p;
227227
}
228228

229-
if (nr_cpus > 0)
229+
if (nr_cpus > 0) {
230230
cpus = cpu_map__trim_new(nr_cpus, tmp_cpus);
231-
else if (*cpu_list != '\0') {
231+
} else if (*cpu_list != '\0') {
232232
pr_warning("Unexpected characters at end of cpu list ('%s'), using online CPUs.",
233233
cpu_list);
234234
cpus = perf_cpu_map__new_online_cpus();
235-
} else
235+
} else {
236236
cpus = perf_cpu_map__new_any_cpu();
237+
}
237238
invalid:
238239
free(tmp_cpus);
239240
out:

0 commit comments

Comments
 (0)