[PATCH v2 06/10] perf evsel: Add function to compute pmu_name

Ian Rogers posted 10 patches 3 years, 1 month ago
There is a newer version of this series
[PATCH v2 06/10] perf evsel: Add function to compute pmu_name
Posted by Ian Rogers 3 years, 1 month ago
The computed pmu_name respects software events and aux event groups,
such that the pmu_name is changed to be that of the aux event leader
or group leader for software events. This is done as a later change
will split events that are in different PMUs into different groups.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++
 tools/perf/util/evsel.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 2dc2c24252bb..9c6b486f8bd4 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -821,6 +821,30 @@ const char *evsel__name(struct evsel *evsel)
 	return "unknown";
 }
 
+const char *evsel__pmu_name(const struct evsel *evsel)
+{
+	const struct evsel *leader;
+
+	/* If the pmu_name is set use it. pmu_name isn't set for CPU and software events. */
+	if (evsel->pmu_name)
+		return evsel->pmu_name;
+	/*
+	 * Software events may be in a group with other uncore PMU events. Use
+	 * the pmu_name of the group leader to avoid breaking the software event
+	 * out of the group.
+	 *
+	 * Aux event leaders, like intel_pt, expect a group with events from
+	 * other PMUs, so substitute the AUX event's PMU in this case.
+	 */
+	leader  = evsel__leader(evsel);
+	if ((evsel->core.attr.type == PERF_TYPE_SOFTWARE || evsel__is_aux_event(leader)) &&
+	    leader->pmu_name) {
+		return leader->pmu_name;
+	}
+
+	return "cpu";
+}
+
 const char *evsel__metric_id(const struct evsel *evsel)
 {
 	if (evsel->metric_id)
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 676c499323e9..72121194d3b1 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -280,6 +280,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size);
 
 int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
 const char *evsel__name(struct evsel *evsel);
+const char *evsel__pmu_name(const struct evsel *evsel);
 const char *evsel__metric_id(const struct evsel *evsel);
 
 static inline bool evsel__is_tool(const struct evsel *evsel)
-- 
2.40.0.rc0.216.gc4246ad0f0-goog
Re: [PATCH v2 06/10] perf evsel: Add function to compute pmu_name
Posted by Namhyung Kim 3 years, 1 month ago
On Thu, Mar 2, 2023 at 1:26 PM Ian Rogers <irogers@google.com> wrote:
>
> The computed pmu_name respects software events and aux event groups,
> such that the pmu_name is changed to be that of the aux event leader
> or group leader for software events. This is done as a later change
> will split events that are in different PMUs into different groups.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++
>  tools/perf/util/evsel.h |  1 +
>  2 files changed, 25 insertions(+)
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 2dc2c24252bb..9c6b486f8bd4 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -821,6 +821,30 @@ const char *evsel__name(struct evsel *evsel)
>         return "unknown";
>  }
>
> +const char *evsel__pmu_name(const struct evsel *evsel)
> +{
> +       const struct evsel *leader;
> +
> +       /* If the pmu_name is set use it. pmu_name isn't set for CPU and software events. */
> +       if (evsel->pmu_name)
> +               return evsel->pmu_name;

I'm wondering if we can just use evsel->pmu->name if it's set.

> +       /*
> +        * Software events may be in a group with other uncore PMU events. Use
> +        * the pmu_name of the group leader to avoid breaking the software event
> +        * out of the group.
> +        *
> +        * Aux event leaders, like intel_pt, expect a group with events from
> +        * other PMUs, so substitute the AUX event's PMU in this case.
> +        */

Looks like we need to rename this function as it doesn't simply return
the pmu name in the above cases.  Maybe evsel__group_pmu_name() ?

Thanks,
Namhyung


> +       leader  = evsel__leader(evsel);
> +       if ((evsel->core.attr.type == PERF_TYPE_SOFTWARE || evsel__is_aux_event(leader)) &&
> +           leader->pmu_name) {
> +               return leader->pmu_name;
> +       }
> +
> +       return "cpu";
> +}
> +
>  const char *evsel__metric_id(const struct evsel *evsel)
>  {
>         if (evsel->metric_id)
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 676c499323e9..72121194d3b1 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -280,6 +280,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size);
>
>  int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
>  const char *evsel__name(struct evsel *evsel);
> +const char *evsel__pmu_name(const struct evsel *evsel);
>  const char *evsel__metric_id(const struct evsel *evsel);
>
>  static inline bool evsel__is_tool(const struct evsel *evsel)
> --
> 2.40.0.rc0.216.gc4246ad0f0-goog
>
Re: [PATCH v2 06/10] perf evsel: Add function to compute pmu_name
Posted by Ian Rogers 3 years, 1 month ago
On Thu, Mar 2, 2023 at 4:19 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Thu, Mar 2, 2023 at 1:26 PM Ian Rogers <irogers@google.com> wrote:
> >
> > The computed pmu_name respects software events and aux event groups,
> > such that the pmu_name is changed to be that of the aux event leader
> > or group leader for software events. This is done as a later change
> > will split events that are in different PMUs into different groups.
> >
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  tools/perf/util/evsel.c | 24 ++++++++++++++++++++++++
> >  tools/perf/util/evsel.h |  1 +
> >  2 files changed, 25 insertions(+)
> >
> > diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> > index 2dc2c24252bb..9c6b486f8bd4 100644
> > --- a/tools/perf/util/evsel.c
> > +++ b/tools/perf/util/evsel.c
> > @@ -821,6 +821,30 @@ const char *evsel__name(struct evsel *evsel)
> >         return "unknown";
> >  }
> >
> > +const char *evsel__pmu_name(const struct evsel *evsel)
> > +{
> > +       const struct evsel *leader;
> > +
> > +       /* If the pmu_name is set use it. pmu_name isn't set for CPU and software events. */
> > +       if (evsel->pmu_name)
> > +               return evsel->pmu_name;
>
> I'm wondering if we can just use evsel->pmu->name if it's set.

Agreed. I think that can be looked into in follow up work.

> > +       /*
> > +        * Software events may be in a group with other uncore PMU events. Use
> > +        * the pmu_name of the group leader to avoid breaking the software event
> > +        * out of the group.
> > +        *
> > +        * Aux event leaders, like intel_pt, expect a group with events from
> > +        * other PMUs, so substitute the AUX event's PMU in this case.
> > +        */
>
> Looks like we need to rename this function as it doesn't simply return
> the pmu name in the above cases.  Maybe evsel__group_pmu_name() ?

Agreed, that is a better name. I'll add it in v3.

Thanks,
Ian

> Thanks,
> Namhyung
>
>
> > +       leader  = evsel__leader(evsel);
> > +       if ((evsel->core.attr.type == PERF_TYPE_SOFTWARE || evsel__is_aux_event(leader)) &&
> > +           leader->pmu_name) {
> > +               return leader->pmu_name;
> > +       }
> > +
> > +       return "cpu";
> > +}
> > +
> >  const char *evsel__metric_id(const struct evsel *evsel)
> >  {
> >         if (evsel->metric_id)
> > diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> > index 676c499323e9..72121194d3b1 100644
> > --- a/tools/perf/util/evsel.h
> > +++ b/tools/perf/util/evsel.h
> > @@ -280,6 +280,7 @@ int arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size);
> >
> >  int __evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size);
> >  const char *evsel__name(struct evsel *evsel);
> > +const char *evsel__pmu_name(const struct evsel *evsel);
> >  const char *evsel__metric_id(const struct evsel *evsel);
> >
> >  static inline bool evsel__is_tool(const struct evsel *evsel)
> > --
> > 2.40.0.rc0.216.gc4246ad0f0-goog
> >