Message ID | 20240721202113.380750-2-leo.yan@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | perf auxtrace: Support multiple AUX events | expand |
On 21/07/24 23:21, Leo Yan wrote: > Rather than iterating the whole PMU list for finding the associated PMU > device for an evsel, this commit optimizes to directly use evsel's 'pmu' > pointer for accessing PMU device. > > Signed-off-by: Leo Yan <leo.yan@arm.com> > --- > tools/perf/util/pmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 986166bc7c78..798cd5a2ebc4 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -1199,7 +1199,7 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) > > bool evsel__is_aux_event(const struct evsel *evsel) > { > - struct perf_pmu *pmu = evsel__find_pmu(evsel); > + struct perf_pmu *pmu = evsel->pmu; Assumes event parser has populated evsel->pmu for auxtrace events. Could use a comment to that effect. > > return pmu && pmu->auxtrace; > }
Hi Adrian, On 7/22/24 11:40, Adrian Hunter wrote: [...] > On 21/07/24 23:21, Leo Yan wrote: >> Rather than iterating the whole PMU list for finding the associated PMU >> device for an evsel, this commit optimizes to directly use evsel's 'pmu' >> pointer for accessing PMU device. >> >> Signed-off-by: Leo Yan <leo.yan@arm.com> >> --- >> tools/perf/util/pmu.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index 986166bc7c78..798cd5a2ebc4 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -1199,7 +1199,7 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) >> >> bool evsel__is_aux_event(const struct evsel *evsel) >> { >> - struct perf_pmu *pmu = evsel__find_pmu(evsel); >> + struct perf_pmu *pmu = evsel->pmu; > > Assumes event parser has populated evsel->pmu for auxtrace events. > Could use a comment to that effect. Sure, will add a comment for this. Thanks, Leo >> >> return pmu && pmu->auxtrace; >> } >
On Sun, Jul 21, 2024 at 1:21 PM Leo Yan <leo.yan@arm.com> wrote: > > Rather than iterating the whole PMU list for finding the associated PMU > device for an evsel, this commit optimizes to directly use evsel's 'pmu' > pointer for accessing PMU device. The code doesn't do that: https://git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/util/pmus.c?h=perf-tools-next#n698 ``` struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) { struct perf_pmu *pmu = evsel->pmu; if (!pmu) { pmu = perf_pmus__find_by_type(evsel->core.attr.type); ((struct evsel *)evsel)->pmu = pmu; } return pmu; } ``` That is, if the evsel->pmu is not NULL then just return it, otherwise find the pmu using the type from the attribute. Any linear such should happen at most once unless the pmu is NULL from event parsing or perf_pmus__find_by_type. The PMU may be NULL for legacy events and if sysfs isn't mounted. If you are encountering that then maybe we need a flag to say don't find the PMU for this evsel as it is known NULL. Thanks, Ian > Signed-off-by: Leo Yan <leo.yan@arm.com> > --- > tools/perf/util/pmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 986166bc7c78..798cd5a2ebc4 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -1199,7 +1199,7 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) > > bool evsel__is_aux_event(const struct evsel *evsel) > { > - struct perf_pmu *pmu = evsel__find_pmu(evsel); > + struct perf_pmu *pmu = evsel->pmu; > > return pmu && pmu->auxtrace; > } > -- > 2.34.1 >
On 7/22/2024 5:16 PM, Ian Rogers wrote: > On Sun, Jul 21, 2024 at 1:21 PM Leo Yan <leo.yan@arm.com> wrote: >> >> Rather than iterating the whole PMU list for finding the associated PMU >> device for an evsel, this commit optimizes to directly use evsel's 'pmu' >> pointer for accessing PMU device. > > The code doesn't do that: > ``` > struct perf_pmu *evsel__find_pmu(const struct evsel *evsel) > { > struct perf_pmu *pmu = evsel->pmu; > > if (!pmu) { > pmu = perf_pmus__find_by_type(evsel->core.attr.type); > ((struct evsel *)evsel)->pmu = pmu; > } > return pmu; > } > ``` > That is, if the evsel->pmu is not NULL then just return it, otherwise > find the pmu using the type from the attribute. Any linear such should > happen at most once unless the pmu is NULL from event parsing or > perf_pmus__find_by_type. So evsel__find_pmu() is good enough. > The PMU may be NULL for legacy events and if > sysfs isn't mounted. If you are encountering that then maybe we need a > flag to say don't find the PMU for this evsel as it is known NULL. I don't see a case of the PMU pointer is NULL. So don't need this flag. My bad for misreading the code :\ Thanks a lot for pointing out. Leo
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 986166bc7c78..798cd5a2ebc4 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1199,7 +1199,7 @@ void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu) bool evsel__is_aux_event(const struct evsel *evsel) { - struct perf_pmu *pmu = evsel__find_pmu(evsel); + struct perf_pmu *pmu = evsel->pmu; return pmu && pmu->auxtrace; }
Rather than iterating the whole PMU list for finding the associated PMU device for an evsel, this commit optimizes to directly use evsel's 'pmu' pointer for accessing PMU device. Signed-off-by: Leo Yan <leo.yan@arm.com> --- tools/perf/util/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)