2023-10-16 09:35:37

by Yang Jihong

[permalink] [raw]
Subject: [PATCH] perf pmu: Filter out search events table of software pmu in perf_pmu__lookup()

For software pmu, the events_table is empty, reducing unnecessary search.

Signed-off-by: Yang Jihong <[email protected]>
---
tools/perf/util/pmu.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 6428e2648289..59c8394a4efa 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -1033,7 +1033,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
pmu->id = pmu_id(name);
pmu->max_precise = pmu_max_precise(dirfd, pmu);
pmu->alias_name = pmu_find_alias_name(pmu, dirfd);
- pmu->events_table = perf_pmu__find_events_table(pmu);
+ if (!perf_pmu__is_software(pmu))
+ pmu->events_table = perf_pmu__find_events_table(pmu);
pmu_add_sys_aliases(pmu);
list_add_tail(&pmu->list, pmus);

--
2.34.1


2023-10-16 21:04:57

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH] perf pmu: Filter out search events table of software pmu in perf_pmu__lookup()

On Mon, Oct 16, 2023 at 2:35 AM Yang Jihong <[email protected]> wrote:
>
> For software pmu, the events_table is empty, reducing unnecessary search.
>
> Signed-off-by: Yang Jihong <[email protected]>

I'd rather that all PMUs behaved in the same manner without ifs that
will catch people/me out later on. perf_pmu__is_software tells whether
the kernel context is software and therefore whether events can be
grouped with a hardware event. As a test for whether json exists or
not I'd rather stick to values derived from the json.

Thanks,
Ian

> ---
> tools/perf/util/pmu.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 6428e2648289..59c8394a4efa 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -1033,7 +1033,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
> pmu->id = pmu_id(name);
> pmu->max_precise = pmu_max_precise(dirfd, pmu);
> pmu->alias_name = pmu_find_alias_name(pmu, dirfd);
> - pmu->events_table = perf_pmu__find_events_table(pmu);
> + if (!perf_pmu__is_software(pmu))
> + pmu->events_table = perf_pmu__find_events_table(pmu);
> pmu_add_sys_aliases(pmu);
> list_add_tail(&pmu->list, pmus);
>
> --
> 2.34.1
>