From: Jiri Olsa <jolsa@redhat.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>, Andrii Nakryiko <andriin@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>, Kajol Jain <kjain@linux.ibm.com>,
Andi Kleen <ak@linux.intel.com>,
John Garry <john.garry@huawei.com>,
Jin Yao <yao.jin@linux.intel.com>,
Kan Liang <kan.liang@linux.intel.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Kim Phillips <kim.phillips@amd.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Leo Yan <leo.yan@linaro.org>, LKML <linux-kernel@vger.kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v2 7/7] perf expr: Migrate expr ids table to a hashmap
Date: Sat, 16 May 2020 00:41:50 +0200 [thread overview]
Message-ID: <20200515224150.GC3577540@krava> (raw)
In-Reply-To: <CAP-5=fUp4ECBntUamWK53LhTbT9W5w5A0frFyOMxoWK0Q2o60A@mail.gmail.com>
On Fri, May 15, 2020 at 02:35:43PM -0700, Ian Rogers wrote:
> On Fri, May 15, 2020 at 12:41 PM Jiri Olsa <jolsa@redhat.com> wrote:
> >
> > On Fri, May 15, 2020 at 09:50:07AM -0700, Ian Rogers wrote:
> >
> > SNIP
> >
> > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> > > index b071df373f8b..37be5a368d6e 100644
> > > --- a/tools/perf/util/metricgroup.c
> > > +++ b/tools/perf/util/metricgroup.c
> > > @@ -85,8 +85,7 @@ static void metricgroup__rblist_init(struct rblist *metric_events)
> > >
> > > struct egroup {
> > > struct list_head nd;
> > > - int idnum;
> > > - const char **ids;
> > > + struct expr_parse_ctx pctx;
> > > const char *metric_name;
> > > const char *metric_expr;
> > > const char *metric_unit;
> > > @@ -94,19 +93,21 @@ struct egroup {
> > > };
> > >
> > > static struct evsel *find_evsel_group(struct evlist *perf_evlist,
> > > - const char **ids,
> > > - int idnum,
> > > + struct expr_parse_ctx *pctx,
> > > struct evsel **metric_events,
> > > bool *evlist_used)
> > > {
> > > struct evsel *ev;
> > > - int i = 0, j = 0;
> > > bool leader_found;
> > > + const size_t idnum = hashmap__size(&pctx->ids);
> > > + size_t i = 0;
> > > + int j = 0;
> > > + double *val_ptr;
> > >
> > > evlist__for_each_entry (perf_evlist, ev) {
> > > if (evlist_used[j++])
> > > continue;
> > > - if (!strcmp(ev->name, ids[i])) {
> > > + if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) {
> >
> > hum, you sure it's doing the same thing as before?
> >
> > hashmap__find will succede all the time in here, while the
> > previous code was looking for the start of the group ...
> > the logic in here is little convoluted, so maybe I'm
> > missing some point in here ;-)
>
> If we have a metric like "A + B" and another like "C / D" then by
> we'll generate a string (the extra_events strbuf in the code) like
> "{A,B}:W,{C,D}:W" from __metricgroup__add_metric. This will turn into
> an evlist in metricgroup__parse_groups of A,B,C,D. The code is trying
> to associate the events A,B with the first metric and C,D with the
> second. The code doesn't support sharing of events and events are
> marked as used and can't be part of other metrics. The evlist order is
> also reflective of the order of metrics, so if there were metrics "A +
> B + C" and "A + B", as the first metric is first in the evlist we
> don't run the risk of C being placed with A and B in a different
> group.
>
> The old code used the order of events to match within a metric and say
> for metric "A+B+C" we want to match A then B, and so on. The new code
> acts more like a set, so "A + B + C" becomes a set containing A, B and
> C, we check A is in the set then B and then C. For both pieces of code
> they are only working because of the evlist_used "bitmap" and that the
> order in the evlists and metrics matches.
>
> The current code could just use ordering to match first n1 events with
> the first metric, the next n2 events with the second and so on. So
> both the find now, and the strcmp before always return true in this
> branch.
>
> In the RFC patch set I want to share events and so I do checks related
> to the group leader so that I know when moving from one group to
> another in the evlist. The find/strcmp becomes load bearing as I will
> re-use events as long as they match.
> https://lore.kernel.org/lkml/20200508053629.210324-14-irogers@google.com/
>
> > jirka
> >
> > > if (!metric_events[i])
> > > metric_events[i] = ev;
> > > i++;
> > > @@ -118,7 +119,8 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,
> > > memset(metric_events, 0,
> > > sizeof(struct evsel *) * idnum);
>
> This re-check was unnecessary in the old code and unnecessary even
> more so now as the hashmap_find is given exactly the same arguments.
> I'll remove it in v3 while addressing Andrii's memory leak fixes.
ok, that was my other confusion, because it's useless ;-)
thanks for the explanation,
jirka
>
> Thanks,
> Ian
>
> > > - if (!strcmp(ev->name, ids[i])) {
> > > + if (hashmap__find(&pctx->ids, ev->name,
> > > + (void **)&val_ptr)) {
> > > if (!metric_events[i])
> > > metric_events[i] = ev;
> >
> > SNIP
> >
>
next prev parent reply other threads:[~2020-05-15 22:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 16:50 [PATCH v2 0/7] Copy hashmap to tools/perf/util, use in perf expr Ian Rogers
2020-05-15 16:50 ` [PATCH v2 1/7] libbpf: Fix memory leak and possible double-free in hashmap__clear Ian Rogers
2020-05-15 16:50 ` [PATCH v2 2/7] libbpf hashmap: Remove unused #include Ian Rogers
2020-05-15 19:39 ` Andrii Nakryiko
2020-05-15 16:50 ` [PATCH v2 3/7] libbpf hashmap: Fix signedness warnings Ian Rogers
2020-05-15 19:40 ` Andrii Nakryiko
2020-05-15 16:50 ` [PATCH v2 4/7] tools lib/api: Copy libbpf hashmap to tools/perf/util Ian Rogers
2020-05-15 19:41 ` Andrii Nakryiko
2020-05-15 16:50 ` [PATCH v2 5/7] perf test: Provide a subtest callback to ask for the reason for skipping a subtest Ian Rogers
2020-05-15 16:50 ` [PATCH v2 6/7] perf test: Improve pmu event metric testing Ian Rogers
2020-05-15 16:50 ` [PATCH v2 7/7] perf expr: Migrate expr ids table to a hashmap Ian Rogers
2020-05-15 19:39 ` Andrii Nakryiko
2020-05-15 22:03 ` Ian Rogers
2020-05-15 19:41 ` Jiri Olsa
2020-05-15 21:35 ` Ian Rogers
2020-05-15 22:41 ` Jiri Olsa [this message]
2020-05-15 22:41 ` Jiri Olsa
2020-05-15 22:59 ` Ian Rogers
2020-05-15 17:00 ` [PATCH v2 0/7] Copy hashmap to tools/perf/util, use in perf expr Arnaldo Carvalho de Melo
2020-05-15 19:42 ` Andrii Nakryiko
2020-05-15 21:18 ` arnaldo.melo
2020-05-15 21:47 ` Ian Rogers
2020-05-15 23:09 ` Daniel Borkmann
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=20200515224150.GC3577540@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eranian@google.com \
--cc=irogers@google.com \
--cc=john.fastabend@gmail.com \
--cc=john.garry@huawei.com \
--cc=kafai@fb.com \
--cc=kan.liang@linux.intel.com \
--cc=kim.phillips@amd.com \
--cc=kjain@linux.ibm.com \
--cc=kpsingh@chromium.org \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yao.jin@linux.intel.com \
--cc=yhs@fb.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).