Skip to content

Commit 72c6f57

Browse files
james-c-linaronamhyung
authored andcommitted
perf pmu: Dynamically allocate tool PMU
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: 240505b ("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>
1 parent 556b58c commit 72c6f57

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

tools/perf/util/pmus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static void pmu_read_sysfs(unsigned int to_read_types)
264264

265265
if ((to_read_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) != 0 &&
266266
(read_pmu_types & PERF_TOOL_PMU_TYPE_TOOL_MASK) == 0) {
267-
tool_pmu = perf_pmus__tool_pmu();
267+
tool_pmu = tool_pmu__new();
268268
list_add_tail(&tool_pmu->list, &other_pmus);
269269
}
270270
if ((to_read_types & PERF_TOOL_PMU_TYPE_HWMON_MASK) != 0 &&

tools/perf/util/tool_pmu.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,17 +490,16 @@ int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread)
490490
return 0;
491491
}
492492

493-
struct perf_pmu *perf_pmus__tool_pmu(void)
493+
struct perf_pmu *tool_pmu__new(void)
494494
{
495-
static struct perf_pmu tool = {
496-
.name = "tool",
497-
.type = PERF_PMU_TYPE_TOOL,
498-
.aliases = LIST_HEAD_INIT(tool.aliases),
499-
.caps = LIST_HEAD_INIT(tool.caps),
500-
.format = LIST_HEAD_INIT(tool.format),
501-
};
502-
if (!tool.events_table)
503-
tool.events_table = find_core_events_table("common", "common");
504-
505-
return &tool;
495+
struct perf_pmu *tool = zalloc(sizeof(struct perf_pmu));
496+
497+
tool->name = strdup("tool");
498+
tool->type = PERF_PMU_TYPE_TOOL;
499+
INIT_LIST_HEAD(&tool->aliases);
500+
INIT_LIST_HEAD(&tool->caps);
501+
INIT_LIST_HEAD(&tool->format);
502+
tool->events_table = find_core_events_table("common", "common");
503+
504+
return tool;
506505
}

tools/perf/util/tool_pmu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ int evsel__tool_pmu_open(struct evsel *evsel,
5151
int start_cpu_map_idx, int end_cpu_map_idx);
5252
int evsel__tool_pmu_read(struct evsel *evsel, int cpu_map_idx, int thread);
5353

54-
struct perf_pmu *perf_pmus__tool_pmu(void);
54+
struct perf_pmu *tool_pmu__new(void);
5555

5656
#endif /* __TOOL_PMU_H */

0 commit comments

Comments
 (0)