* [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU
@ 2025-02-26 10:40 James Clark
2025-02-26 10:41 ` [PATCH v2 1/3] " James Clark
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: James Clark @ 2025-02-26 10:40 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung, cyy
Cc: James Clark, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, Greg Kroah-Hartman,
Yoshihiro Furudera, Weilin Wang, Junhao He, Jean-Philippe Romain,
linux-kernel
A few minor fixes that I came across when poking around with the Perf
list behavior on hybrid Arm.
Changes since v1:
* Rename perf_pmus__new_tool_pmu() -> tool_pmu__new()
James Clark (3):
perf pmu: Dynamically allocate tool PMU
perf pmu: Don't double count common sysfs and json events
perf list: Document -v option deduplication feature
tools/perf/Documentation/perf-list.txt | 2 +-
tools/perf/builtin-list.c | 2 +-
tools/perf/util/pmu.c | 7 ++++---
tools/perf/util/pmu.h | 5 +++++
tools/perf/util/pmus.c | 2 +-
tools/perf/util/tool_pmu.c | 23 +++++++++++------------
tools/perf/util/tool_pmu.h | 2 +-
7 files changed, 24 insertions(+), 19 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] perf pmu: Dynamically allocate tool PMU
2025-02-26 10:40 [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU James Clark
@ 2025-02-26 10:41 ` James Clark
2025-02-26 10:41 ` [PATCH v2 2/3] perf pmu: Don't double count common sysfs and json events James Clark
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-02-26 10:41 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung, cyy
Cc: James Clark, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, Weilin Wang,
Yoshihiro Furudera, Greg Kroah-Hartman, Jean-Philippe Romain,
Junhao He, linux-kernel
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>
---
tools/perf/util/pmus.c | 2 +-
tools/perf/util/tool_pmu.c | 23 +++++++++++------------
tools/perf/util/tool_pmu.h | 2 +-
3 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c
index 8a0a919415d4..6498021acef0 100644
--- a/tools/perf/util/pmus.c
+++ b/tools/perf/util/pmus.c
@@ -268,7 +268,7 @@ static void pmu_read_sysfs(unsigned int to_read_types)
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 &&
diff --git a/tools/perf/util/tool_pmu.c b/tools/perf/util/tool_pmu.c
index 3a68debe7143..9156745ea180 100644
--- a/tools/perf/util/tool_pmu.c
+++ b/tools/perf/util/tool_pmu.c
@@ -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;
}
diff --git a/tools/perf/util/tool_pmu.h b/tools/perf/util/tool_pmu.h
index a60184859080..c6ad1dd90a56 100644
--- a/tools/perf/util/tool_pmu.h
+++ b/tools/perf/util/tool_pmu.h
@@ -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 */
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] perf pmu: Don't double count common sysfs and json events
2025-02-26 10:40 [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU James Clark
2025-02-26 10:41 ` [PATCH v2 1/3] " James Clark
@ 2025-02-26 10:41 ` James Clark
2025-02-26 10:41 ` [PATCH v2 3/3] perf list: Document -v option deduplication feature James Clark
2025-02-27 16:50 ` [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-02-26 10:41 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung, cyy
Cc: James Clark, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, Greg Kroah-Hartman,
Weilin Wang, Yoshihiro Furudera, Jean-Philippe Romain, Junhao He,
linux-kernel
After pmu_add_cpu_aliases() is called, perf_pmu__num_events() returns an
incorrect value that double counts common events and doesn't match the
actual count of events in the alias list. This is because after
'cpu_aliases_added == true', the number of events returned is
'sysfs_aliases + cpu_json_aliases'. But when adding 'case
EVENT_SRC_SYSFS' events, 'sysfs_aliases' and 'cpu_json_aliases' are both
incremented together, failing to account that these ones overlap and
only add a single item to the list. Fix it by adding another counter for
overlapping events which doesn't influence 'cpu_json_aliases'.
There doesn't seem to be a current issue because it's used in perf list
before pmu_add_cpu_aliases() so the correct value is returned. Other
uses in tests may also miss it for other reasons like only looking at
uncore events. However it's marked as a fixes commit in case any new fix
with new uses of perf_pmu__num_events() is backported.
Fixes: d9c5f5f94c2d ("perf pmu: Count sys and cpuid JSON events separately")
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/util/pmu.c | 7 ++++---
tools/perf/util/pmu.h | 5 +++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index ec3878c890a9..72aa6167c090 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -596,7 +596,7 @@ static int perf_pmu__new_alias(struct perf_pmu *pmu, const char *name,
};
if (pmu_events_table__find_event(pmu->events_table, pmu, name,
update_alias, &data) == 0)
- pmu->cpu_json_aliases++;
+ pmu->cpu_common_json_aliases++;
}
pmu->sysfs_aliases++;
break;
@@ -1884,9 +1884,10 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu)
if (pmu->cpu_aliases_added)
nr += pmu->cpu_json_aliases;
else if (pmu->events_table)
- nr += pmu_events_table__num_events(pmu->events_table, pmu) - pmu->cpu_json_aliases;
+ nr += pmu_events_table__num_events(pmu->events_table, pmu) -
+ pmu->cpu_common_json_aliases;
else
- assert(pmu->cpu_json_aliases == 0);
+ assert(pmu->cpu_json_aliases == 0 && pmu->cpu_common_json_aliases == 0);
if (perf_pmu__is_tool(pmu))
nr -= tool_pmu__num_skip_events();
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index f5306428c03f..b93014cc3670 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -136,6 +136,11 @@ struct perf_pmu {
uint32_t cpu_json_aliases;
/** @sys_json_aliases: Number of json event aliases loaded matching the PMU's identifier. */
uint32_t sys_json_aliases;
+ /**
+ * @cpu_common_json_aliases: Number of json events that overlapped with sysfs when
+ * loading all sysfs events.
+ */
+ uint32_t cpu_common_json_aliases;
/** @sysfs_aliases_loaded: Are sysfs aliases loaded from disk? */
bool sysfs_aliases_loaded;
/**
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] perf list: Document -v option deduplication feature
2025-02-26 10:40 [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU James Clark
2025-02-26 10:41 ` [PATCH v2 1/3] " James Clark
2025-02-26 10:41 ` [PATCH v2 2/3] perf pmu: Don't double count common sysfs and json events James Clark
@ 2025-02-26 10:41 ` James Clark
2025-02-27 16:50 ` [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: James Clark @ 2025-02-26 10:41 UTC (permalink / raw)
To: linux-perf-users, irogers, namhyung, cyy
Cc: James Clark, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Adrian Hunter, Liang, Kan, Greg Kroah-Hartman,
Weilin Wang, Yoshihiro Furudera, Junhao He, Jean-Philippe Romain,
linux-kernel
-v disables deduplication of similarly suffixed PMUs so add it to the
help and doc strings.
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
---
tools/perf/Documentation/perf-list.txt | 2 +-
tools/perf/builtin-list.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/Documentation/perf-list.txt b/tools/perf/Documentation/perf-list.txt
index c3ffd93f94d7..8914f12d2b85 100644
--- a/tools/perf/Documentation/perf-list.txt
+++ b/tools/perf/Documentation/perf-list.txt
@@ -27,7 +27,7 @@ Don't print descriptions.
-v::
--long-desc::
-Print longer event descriptions.
+Print longer event descriptions and all similar PMUs with alphanumeric suffixes.
--debug::
Enable debugging output.
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index c19826f218a0..fed482adb039 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -527,7 +527,7 @@ int cmd_list(int argc, const char **argv)
OPT_BOOLEAN('d', "desc", &default_ps.desc,
"Print extra event descriptions. --no-desc to not print."),
OPT_BOOLEAN('v', "long-desc", &default_ps.long_desc,
- "Print longer event descriptions."),
+ "Print longer event descriptions and all similar PMUs with alphanumeric suffixes."),
OPT_BOOLEAN(0, "details", &default_ps.detailed,
"Print information on the perf event names and expressions used internally by events."),
OPT_STRING('o', "output", &output_path, "file", "output file name"),
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU
2025-02-26 10:40 [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU James Clark
` (2 preceding siblings ...)
2025-02-26 10:41 ` [PATCH v2 3/3] perf list: Document -v option deduplication feature James Clark
@ 2025-02-27 16:50 ` Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-02-27 16:50 UTC (permalink / raw)
To: linux-perf-users, irogers, cyy, James Clark
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Liang, Kan, Greg Kroah-Hartman, Yoshihiro Furudera, Weilin Wang,
Junhao He, Jean-Philippe Romain, linux-kernel
On Wed, 26 Feb 2025 10:40:59 +0000, James Clark wrote:
> A few minor fixes that I came across when poking around with the Perf
> list behavior on hybrid Arm.
>
> Changes since v1:
> * Rename perf_pmus__new_tool_pmu() -> tool_pmu__new()
>
> James Clark (3):
> perf pmu: Dynamically allocate tool PMU
> perf pmu: Don't double count common sysfs and json events
> perf list: Document -v option deduplication feature
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-27 16:50 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-26 10:40 [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU James Clark
2025-02-26 10:41 ` [PATCH v2 1/3] " James Clark
2025-02-26 10:41 ` [PATCH v2 2/3] perf pmu: Don't double count common sysfs and json events James Clark
2025-02-26 10:41 ` [PATCH v2 3/3] perf list: Document -v option deduplication feature James Clark
2025-02-27 16:50 ` [PATCH v2 0/3] perf pmu: Dynamically allocate tool PMU Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).