linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: "Wang, Weilin" <weilin.wang@intel.com>
Cc: Kan Liang <kan.liang@linux.intel.com>,
	Namhyung Kim <namhyung@kernel.org>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	 "Hunter, Adrian" <adrian.hunter@intel.com>,
	 "linux-perf-users@vger.kernel.org"
	<linux-perf-users@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Taylor, Perry" <perry.taylor@intel.com>,
	 "Alt, Samantha" <samantha.alt@intel.com>,
	"Biggers, Caleb" <caleb.biggers@intel.com>,
	 Mark Rutland <mark.rutland@arm.com>
Subject: Re: [RFC PATCH v4 14/15] perf stat: Add tool events support in hardware-grouping
Date: Wed, 10 Apr 2024 10:47:12 -0700	[thread overview]
Message-ID: <CAP-5=fVtLbRva9KLMdDPNMkF-F9LDp-3C10RymC-QbYdtwEbQA@mail.gmail.com> (raw)
In-Reply-To: <CO6PR11MB56358253F9CE3C3772A665EEEE072@CO6PR11MB5635.namprd11.prod.outlook.com>

On Tue, Apr 9, 2024 at 1:51 PM Wang, Weilin <weilin.wang@intel.com> wrote:
>
>
>
> > -----Original Message-----
> > From: Ian Rogers <irogers@google.com>
> > Sent: Saturday, March 23, 2024 10:56 PM
> > To: Wang, Weilin <weilin.wang@intel.com>
> > Cc: Kan Liang <kan.liang@linux.intel.com>; Namhyung Kim
> > <namhyung@kernel.org>; Arnaldo Carvalho de Melo <acme@kernel.org>;
> > Peter Zijlstra <peterz@infradead.org>; Ingo Molnar <mingo@redhat.com>;
> > Alexander Shishkin <alexander.shishkin@linux.intel.com>; Jiri Olsa
> > <jolsa@kernel.org>; Hunter, Adrian <adrian.hunter@intel.com>; linux-perf-
> > users@vger.kernel.org; linux-kernel@vger.kernel.org; Taylor, Perry
> > <perry.taylor@intel.com>; Alt, Samantha <samantha.alt@intel.com>; Biggers,
> > Caleb <caleb.biggers@intel.com>; Mark Rutland <mark.rutland@arm.com>
> > Subject: Re: [RFC PATCH v4 14/15] perf stat: Add tool events support in
> > hardware-grouping
> >
> > On Thu, Feb 8, 2024 at 7:14 PM <weilin.wang@intel.com> wrote:
> > >
> > > From: Weilin Wang <weilin.wang@intel.com>
> > >
> > > Add tool events into default_core grouping strings if find tool events so
> > > that metrics use tool events could be correctly calculated. Need this step
> > > to support TopdownL4-L5.
> > >
> > > Signed-off-by: Weilin Wang <weilin.wang@intel.com>
> > > ---
> > >  tools/perf/util/metricgroup.c | 49
> > ++++++++++++++++++++++++++++++++++-
> > >  1 file changed, 48 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> > > index cfdbb5f7fb77..e5b8456d0405 100644
> > > --- a/tools/perf/util/metricgroup.c
> > > +++ b/tools/perf/util/metricgroup.c
> > > @@ -1486,6 +1486,35 @@ static void find_tool_events(const struct
> > list_head *metric_list,
> > >         }
> > >  }
> > >
> > > +/**
> > > + * get_tool_event_str - Generate and return a string with all the used tool
> > > + * event names.
> > > + */
> > > +static int get_tool_event_str(struct strbuf *events,
> > > +                             const bool tool_events[PERF_TOOL_MAX],
> > > +                             bool *has_tool_event)
> > > +{
> > > +       int i = 0;
> > > +       int ret;
> > > +
> > > +       perf_tool_event__for_each_event(i) {
> > > +               if (tool_events[i]) {
> > > +                       const char *tmp = strdup(perf_tool_event__to_str(i));
> > > +
> > > +                       if (!tmp)
> > > +                               return -ENOMEM;
> > > +                       *has_tool_event = true;
> > > +                       ret = strbuf_addstr(events, ",");
> > > +                       if (ret)
> > > +                               return ret;
> > > +                       ret = strbuf_addstr(events, tmp);
> > > +                       if (ret)
> > > +                               return ret;
> > > +               }
> > > +       }
> > > +       return 0;
> > > +}
> > > +
> > >  /**
> > >   * build_combined_expr_ctx - Make an expr_parse_ctx with
> > all !group_events
> > >   *                           metric IDs, as the IDs are held in a set,
> > > @@ -2049,6 +2078,7 @@ static int assign_event_grouping(struct
> > metricgroup__event_info *e,
> > >
> > >  static int hw_aware_metricgroup__build_event_string(struct list_head
> > *group_strs,
> > >                                            const char *modifier,
> > > +                                          const bool tool_events[PERF_TOOL_MAX],
> > >                                            struct list_head *groups)
> > >  {
> > >         struct metricgroup__pmu_group_list *p;
> > > @@ -2056,8 +2086,12 @@ static int
> > hw_aware_metricgroup__build_event_string(struct list_head *group_strs
> > >         struct metricgroup__group_events *ge;
> > >         bool no_group = true;
> > >         int ret = 0;
> > > +       struct strbuf tool_event_str = STRBUF_INIT;
> > > +       bool has_tool_event = false;
> > >
> > >  #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0)
> > > +       ret = get_tool_event_str(&tool_event_str, tool_events,
> > &has_tool_event);
> >
> > Does metricgroup__build_event_string need updating to use this helper
> > function too?
>
> Hi Ian,
>
> In parse_ids, tool events are inserted to the ids that passed to
> metricgroup__build_event_string. If we want to use this function here, I think
> we also need to update the code in parse_ids to not insert tool events.
>
> I could add this change if you think we should do this update.

I like code-reuse and sharing logic whenever possible, it seems
potentially messy though. I'll leave it up to your judgement as to
whether it is worth cleaning up. Perhaps there should be a TODO if
not.

Thanks,
Ian

> Thanks,
> Weilin
>
> >
> > Thanks,
> > Ian
> >
> > > +       RETURN_IF_NON_ZERO(ret);
> > >
> > >         list_for_each_entry(p, groups, nd) {
> > >                 list_for_each_entry(g, &p->group_head, nd) {
> > > @@ -2129,6 +2163,12 @@ static int
> > hw_aware_metricgroup__build_event_string(struct list_head *group_strs
> > >                         }
> > >                         ret = strbuf_addf(events, "}:W");
> > >                         RETURN_IF_NON_ZERO(ret);
> > > +
> > > +                       if (!strcmp(p->pmu_name, "default_core") && has_tool_event)
> > {
> > > +                               ret = strbuf_addstr(events, tool_event_str.buf);
> > > +                               RETURN_IF_NON_ZERO(ret);
> > > +                       }
> > > +
> > >                         pr_debug("events-buf: %s\n", events->buf);
> > >                         list_add_tail(&new_group_str->nd, group_strs);
> > >                 }
> > > @@ -2214,6 +2254,7 @@ static int hw_aware_build_grouping(struct
> > expr_parse_ctx *ctx,
> > >                 if (ret)
> > >                         goto err_out;
> > >         }
> > > +
> > >         ret = get_pmu_counter_layouts(&pmu_info_list, ltable);
> > >         if (ret)
> > >                 goto err_out;
> > > @@ -2259,6 +2300,7 @@ static void
> > metricgroup__free_grouping_strs(struct list_head
> > >   */
> > >  static int hw_aware_parse_ids(struct perf_pmu *fake_pmu,
> > >                              struct expr_parse_ctx *ids, const char *modifier,
> > > +                            const bool tool_events[PERF_TOOL_MAX],
> > >                              struct evlist **out_evlist)
> > >  {
> > >         struct parse_events_error parse_error;
> > > @@ -2272,7 +2314,8 @@ static int hw_aware_parse_ids(struct perf_pmu
> > *fake_pmu,
> > >         ret = hw_aware_build_grouping(ids, &grouping);
> > >         if (ret)
> > >                 goto out;
> > > -       ret = hw_aware_metricgroup__build_event_string(&grouping_str,
> > modifier, &grouping);
> > > +       ret = hw_aware_metricgroup__build_event_string(&grouping_str,
> > modifier,
> > > +                                                     tool_events, &grouping);
> > >         if (ret)
> > >                 goto out;
> > >
> > > @@ -2407,6 +2450,7 @@ static int hw_aware_parse_groups(struct evlist
> > *perf_evlist,
> > >         struct evlist *combined_evlist = NULL;
> > >         LIST_HEAD(metric_list);
> > >         struct metric *m;
> > > +       bool tool_events[PERF_TOOL_MAX] = {false};
> > >         int ret;
> > >         bool metric_no_group = false;
> > >         bool metric_no_merge = false;
> > > @@ -2425,11 +2469,14 @@ static int hw_aware_parse_groups(struct evlist
> > *perf_evlist,
> > >         if (!metric_no_merge) {
> > >                 struct expr_parse_ctx *combined = NULL;
> > >
> > > +               find_tool_events(&metric_list, tool_events);
> > > +
> > >                 ret = hw_aware_build_combined_expr_ctx(&metric_list,
> > &combined);
> > >
> > >                 if (!ret && combined && hashmap__size(combined->ids)) {
> > >                         ret = hw_aware_parse_ids(fake_pmu, combined,
> > >                                                 /*modifier=*/NULL,
> > > +                                               tool_events,
> > >                                                 &combined_evlist);
> > >                 }
> > >
> > > --
> > > 2.42.0
> > >

  reply	other threads:[~2024-04-10 17:47 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09  3:14 [RFC PATCH v4 00/15] Perf stat metric grouping with hardware information weilin.wang
2024-02-09  3:14 ` [RFC PATCH v4 01/15] perf stat: Add new field in stat_config to enable hardware aware grouping weilin.wang
2024-02-09  3:14 ` [RFC PATCH v4 02/15] perf stat: Add basic functions for the " weilin.wang
2024-02-09  3:14 ` [RFC PATCH v4 03/15] perf pmu-events: Add functions in jevent.py to parse counter and event info for " weilin.wang
2024-03-24  4:49   ` Ian Rogers
2024-03-26 22:41     ` Wang, Weilin
2024-03-27  0:02       ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 04/15] find_bit: add _find_last_and_bit() to support finding the most significant set bit weilin.wang
2024-03-24  4:19   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 05/15] perf stat: Add functions to set counter bitmaps for hardware-grouping method weilin.wang
2024-03-24  4:51   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 06/15] perf stat: Add functions to get counter info weilin.wang
2024-03-24  4:58   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 07/15] perf stat: Add functions to create new group and assign events into groups weilin.wang
2024-03-24  5:00   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 08/15] perf stat: Add build string function and topdown events handling in hardware-grouping weilin.wang
2024-02-09  3:14 ` [RFC PATCH v4 09/15] perf stat: Add function to handle special events " weilin.wang
2024-03-24  5:20   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 10/15] perf stat: Add function to combine metrics for hardware-grouping weilin.wang
2024-02-09  3:14 ` [RFC PATCH v4 11/15] perf stat: Handle taken alone in hardware-grouping weilin.wang
2024-03-24  5:24   ` Ian Rogers
2024-03-26 23:06     ` Wang, Weilin
2024-03-27  0:05       ` Ian Rogers
2024-03-27  0:40         ` Wang, Weilin
2024-02-09  3:14 ` [RFC PATCH v4 12/15] perf stat: Handle NMI " weilin.wang
2024-03-24  5:26   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 13/15] perf stat: Code refactoring " weilin.wang
2024-03-24  5:46   ` Ian Rogers
2024-02-09  3:14 ` [RFC PATCH v4 14/15] perf stat: Add tool events support " weilin.wang
2024-03-24  5:56   ` Ian Rogers
2024-04-09 20:51     ` Wang, Weilin
2024-04-10 17:47       ` Ian Rogers [this message]
2024-02-09  3:14 ` [RFC PATCH v4 15/15] perf stat: Add hardware-grouping cmd option to perf stat weilin.wang
2024-03-24  5:56   ` Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP-5=fVtLbRva9KLMdDPNMkF-F9LDp-3C10RymC-QbYdtwEbQA@mail.gmail.com' \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=caleb.biggers@intel.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=perry.taylor@intel.com \
    --cc=peterz@infradead.org \
    --cc=samantha.alt@intel.com \
    --cc=weilin.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).