libperf: Make perf_cpu_map__alloc() available as an internal function for tools/perf...
authorIan Rogers <irogers@google.com>
Wed, 12 Apr 2023 15:54:44 +0000 (12:54 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 12 Apr 2023 17:44:24 +0000 (14:44 -0300)
We had the open coded equivalent in perf_cpu_map__empty_new(), so reuse
what is in libperf.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Link: https://lore.kernel.org/lkml/20230407230405.2931830-3-irogers@google.com
[ Split from a larger patch ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/cpumap.c
tools/lib/perf/include/internal/cpumap.h
tools/perf/util/cpumap.c

index 6cd0be7..0833423 100644 (file)
@@ -10,7 +10,7 @@
 #include <ctype.h>
 #include <limits.h>
 
-static struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus)
+struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus)
 {
        struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus);
 
index 35dd296..f5bffb1 100644 (file)
@@ -24,6 +24,7 @@ struct perf_cpu_map {
 #define MAX_NR_CPUS    2048
 #endif
 
+struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus);
 int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu);
 bool perf_cpu_map__is_subset(const struct perf_cpu_map *a, const struct perf_cpu_map *b);
 
index c8484b7..072831f 100644 (file)
@@ -160,7 +160,7 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
 
 struct perf_cpu_map *perf_cpu_map__empty_new(int nr)
 {
-       struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
+       struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr);
 
        if (cpus != NULL) {
                int i;