]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf pmu: Dynamically allocate tool PMU
authorJames Clark <james.clark@linaro.org>
Wed, 26 Feb 2025 10:41:00 +0000 (10:41 +0000)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 27 Feb 2025 00:23:47 +0000 (16:23 -0800)
perf_pmus__destroy() treats all PMUs as allocated and free's them so we
can't have any static PMUs that are added to the PMU lists. Fix it by
allocating the tool PMU in the same way as the others. Current users of
the tool PMU already use find_pmu() and not perf_pmus__tool_pmu(), so
rename the function to add 'new' to avoid it being misused in the
future.

perf_pmus__fake_pmu() can remain as static as it's not added to the
PMU lists.

Fixes the following error:

  $ perf bench internals pmu-scan

  # Running 'internals/pmu-scan' benchmark:
  Computing performance of sysfs PMU event scan for 100 times
  munmap_chunk(): invalid pointer
  Aborted (core dumped)

Fixes: 240505b2d0ad ("perf tool_pmu: Factor tool events into their own PMU")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250226104111.564443-2-james.clark@linaro.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/pmus.c
tools/perf/util/tool_pmu.c
tools/perf/util/tool_pmu.h

index afd59d678fd02c48faa7d3800ed08afbfa63f393..dd7c2ffdab38ef43729fdf2be626d095bb13e4b5 100644 (file)
@@ -264,7 +264,7 @@ skip_pe_pmus:
 
        if ((to_read_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) != 0 &&
            (read_pmu_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) == 0) {
-               tool_pmu = perf_pmus__tool_pmu();
+               tool_pmu = tool_pmu__new();
                list_add_tail(&tool_pmu->list, &other_pmus);
        }
        if ((to_read_types & PERF_TOOL_PMU_TYPE_HWMON_MASK) != 0 &&
index 3a68debe71437eb96b18b9455824e6e614ec2c45..9156745ea180d33fe62c939b7a4f9912fe943760 100644 (file)
@@ -490,17 +490,16 @@ int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread)
        return 0;
 }
 
-struct perf_pmu *perf_pmus__tool_pmu(void)
+struct perf_pmu *tool_pmu__new(void)
 {
-       static struct perf_pmu tool = {
-               .name = "tool",
-               .type = PERF_PMU_TYPE_TOOL,
-               .aliases = LIST_HEAD_INIT(tool.aliases),
-               .caps = LIST_HEAD_INIT(tool.caps),
-               .format = LIST_HEAD_INIT(tool.format),
-       };
-       if (!tool.events_table)
-               tool.events_table = find_core_events_table("common", "common");
-
-       return &tool;
+       struct perf_pmu *tool = zalloc(sizeof(struct perf_pmu));
+
+       tool->name = strdup("tool");
+       tool->type = PERF_PMU_TYPE_TOOL;
+       INIT_LIST_HEAD(&tool->aliases);
+       INIT_LIST_HEAD(&tool->caps);
+       INIT_LIST_HEAD(&tool->format);
+       tool->events_table = find_core_events_table("common", "common");
+
+       return tool;
 }
index a60184859080f1d930250147c920a01b5cd6664c..c6ad1dd90a56d48bab3191f9e37b92052f7a608a 100644 (file)
@@ -51,6 +51,6 @@ int evsel__tool_pmu_open(struct evsel *evsel,
                         int start_cpu_map_idx, int end_cpu_map_idx);
 int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread);
 
-struct perf_pmu *perf_pmus__tool_pmu(void);
+struct perf_pmu *tool_pmu__new(void);
 
 #endif /* __TOOL_PMU_H */