linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Ian Rogers <irogers@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 46/59] perf tools: Add add_numeric callback to struct parse_events_ops
Date: Mon, 8 Nov 2021 22:34:23 +0100	[thread overview]
Message-ID: <YYmX35S+QpbRFbOX@krava> (raw)
In-Reply-To: <CAP-5=fUZyxqJXDuH1kS7fVXy4osCfQGcv9d5yUwuLHjUZumo5g@mail.gmail.com>

On Mon, Nov 08, 2021 at 10:27:10AM -0800, Ian Rogers wrote:
> On Mon, Nov 8, 2021 at 5:41 AM Jiri Olsa <jolsa@redhat.com> wrote:
> >
> > Adding add_numeric callback to struct parse_events_ops,
> > to allow custom numeric parsing code.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/lib/perf/include/internal/parse-events.h |  5 +++++
> >  tools/perf/util/parse-events.c                 |  2 ++
> >  tools/perf/util/parse-events.h                 |  4 ----
> >  tools/perf/util/parse-events.y                 | 12 ++++++++----
> >  4 files changed, 15 insertions(+), 8 deletions(-)
> >
> > diff --git a/tools/lib/perf/include/internal/parse-events.h b/tools/lib/perf/include/internal/parse-events.h
> > index 78dd3f989346..cbcf799f8969 100644
> > --- a/tools/lib/perf/include/internal/parse-events.h
> > +++ b/tools/lib/perf/include/internal/parse-events.h
> > @@ -102,6 +102,11 @@ struct parse_events_ops {
> >         int (*add_pmu_multi)(struct parse_events_state *parse_state,
> >                              char *str, struct list_head *head,
> >                              struct list_head **listp);
> > +
> > +       int (*add_numeric)(struct parse_events_state *parse_state,
> > +                          struct list_head *list,
> > +                          u32 type, u64 config,
> > +                          struct list_head *head_config);
> >  };
> >
> >  struct parse_events_state {
> > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> > index c67634c9de0d..a05e1bdb4e60 100644
> > --- a/tools/perf/util/parse-events.c
> > +++ b/tools/perf/util/parse-events.c
> > @@ -1306,6 +1306,7 @@ int parse_events_add_tracepoint(struct parse_events_state *parse_state,
> >                                             err, head_config);
> >  }
> >
> > +static
> >  int parse_events_add_numeric(struct parse_events_state *parse_state,
> >                              struct list_head *list,
> >                              u32 type, u64 config,
> > @@ -2904,4 +2905,5 @@ static struct parse_events_ops parse_state_ops = {
> >         .perf_evsel__delete = perf_evsel__delete_helper,
> >         .add_pmu            = parse_events_add_pmu,
> >         .add_pmu_multi      = parse_events_multi_pmu_add,
> > +       .add_numeric        = parse_events_add_numeric,
> 
> Some documentation on the ops would be awesome :-) Especially as this
> is allowing configuration and it is not immediately clear what that
> could mean when changes happen.

so the ops are to help with perf specific code like 'evsel allocation
and one chicken and egg problem we have in event parsing

to move flex/bison code to libperf I need to move all functions called
from that code to libperf.. and some of those functions end up calling
parser again - the pmu_loopup for terms parsing, which is sharing
parser/flexer code with event parsing

having the ops allows us to keep this 'so far unmovable code' in perf
and move just the flexer/bison, which is the base for everything

I expect some of the callbacks will go away at the end, because the
code for them will be completely in libperf, so there would be no
need for special perf implementation

but yes, I'll put some docs on them

thanks,
jirka

> 
> Thanks,
> Ian
> 
> >  };
> > diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> > index fa03f8f70f33..40d192cace03 100644
> > --- a/tools/perf/util/parse-events.h
> > +++ b/tools/perf/util/parse-events.h
> > @@ -79,10 +79,6 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
> >                               struct list_head *list,
> >                               struct bpf_object *obj,
> >                               struct list_head *head_config);
> > -int parse_events_add_numeric(struct parse_events_state *parse_state,
> > -                            struct list_head *list,
> > -                            u32 type, u64 config,
> > -                            struct list_head *head_config);
> >  int parse_events_add_tool(struct parse_events_state *parse_state,
> >                           struct list_head *list,
> >                           int tool_event);
> > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > index f903690b3c8a..b23691397374 100644
> > --- a/tools/perf/util/parse-events.y
> > +++ b/tools/perf/util/parse-events.y
> > @@ -436,6 +436,7 @@ PE_VALUE_SYM_SW
> >  event_legacy_symbol:
> >  value_sym '/' event_config '/'
> >  {
> > +       struct parse_events_state *parse_state = _parse_state;
> >         struct list_head *list;
> >         int type = $1 >> 16;
> >         int config = $1 & 255;
> > @@ -443,7 +444,7 @@ value_sym '/' event_config '/'
> >
> >         list = alloc_list();
> >         ABORT_ON(!list);
> > -       err = parse_events_add_numeric(_parse_state, list, type, config, $3);
> > +       err = parse_state->ops->add_numeric(parse_state, list, type, config, $3);
> >         parse_events_terms__delete($3);
> >         if (err) {
> >                 free_list_evsel(_parse_state, list);
> > @@ -454,13 +455,14 @@ value_sym '/' event_config '/'
> >  |
> >  value_sym sep_slash_slash_dc
> >  {
> > +       struct parse_events_state *parse_state = _parse_state;
> >         struct list_head *list;
> >         int type = $1 >> 16;
> >         int config = $1 & 255;
> >
> >         list = alloc_list();
> >         ABORT_ON(!list);
> > -       ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
> > +       ABORT_ON(parse_state->ops->add_numeric(parse_state, list, type, config, NULL));
> >         $$ = list;
> >  }
> >  |
> > @@ -646,12 +648,13 @@ PE_NAME ':' PE_NAME
> >  event_legacy_numeric:
> >  PE_VALUE ':' PE_VALUE opt_event_config
> >  {
> > +       struct parse_events_state *parse_state = _parse_state;
> >         struct list_head *list;
> >         int err;
> >
> >         list = alloc_list();
> >         ABORT_ON(!list);
> > -       err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4);
> > +       err = parse_state->ops->add_numeric(_parse_state, list, (u32)$1, $3, $4);
> >         parse_events_terms__delete($4);
> >         if (err) {
> >                 free(list);
> > @@ -663,12 +666,13 @@ PE_VALUE ':' PE_VALUE opt_event_config
> >  event_legacy_raw:
> >  PE_RAW opt_event_config
> >  {
> > +       struct parse_events_state *parse_state = _parse_state;
> >         struct list_head *list;
> >         int err;
> >
> >         list = alloc_list();
> >         ABORT_ON(!list);
> > -       err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2);
> > +       err = parse_state->ops->add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2);
> >         parse_events_terms__delete($2);
> >         if (err) {
> >                 free(list);
> > --
> > 2.31.1
> >
> 


  reply	other threads:[~2021-11-08 21:34 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 13:36 [RFC 00/59] libperf: Move in event parse code Jiri Olsa
2021-11-08 13:36 ` [PATCH 01/59] libperf: Move pmu-events.h file to libperf Jiri Olsa
2021-11-08 13:36 ` [PATCH 03/59] libperf: Move pmu-events build " Jiri Olsa
2021-11-08 13:36 ` [PATCH 04/59] libperf: Move perf_pmu__format_parse " Jiri Olsa
2021-11-08 13:36 ` [PATCH 05/59] tools api fs: Move in the fncache from perf Jiri Olsa
2021-11-08 17:46   ` Ian Rogers
2021-11-08 21:15     ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 06/59] libperf: Move in the pmu hybrid support Jiri Olsa
2021-11-08 13:36 ` [PATCH 07/59] libperf: Move name to perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 08/59] libperf: Move auto_merge_stats " Jiri Olsa
2021-11-08 13:36 ` [PATCH 09/59] libperf: Move config_terms " Jiri Olsa
2021-11-08 13:36 ` [PATCH 10/59] libperf: Move metric_id " Jiri Olsa
2021-11-08 13:36 ` [PATCH 11/59] libperf: Move tool_event " Jiri Olsa
2021-11-08 13:36 ` [PATCH 12/59] libperf: Move unit " Jiri Olsa
2021-11-08 13:36 ` [PATCH 13/59] libperf: Move exclude_GH " Jiri Olsa
2021-11-08 17:53   ` Ian Rogers
2021-11-08 21:16     ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 14/59] libperf: Move sample_read " Jiri Olsa
2021-11-08 13:36 ` [PATCH 15/59] libperf: Move precise_max " Jiri Olsa
2021-11-08 13:36 ` [PATCH 16/59] libperf: Move weak_group " Jiri Olsa
2021-11-08 13:36 ` [PATCH 17/59] libperf: Move bpf_counter " Jiri Olsa
2021-11-08 13:36 ` [PATCH 18/59] libperf: Move group_name " Jiri Olsa
2021-11-08 17:58   ` Ian Rogers
2021-11-08 18:07     ` Arnaldo Carvalho de Melo
2021-11-08 21:19       ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 19/59] perf tools: Fix parse_events_term__num call Jiri Olsa
2021-11-08 18:15   ` Ian Rogers
2021-11-08 21:21     ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 20/59] perf tools: Pass parse_state all the way down to __add_event Jiri Olsa
2021-11-08 13:36 ` [PATCH 21/59] perf tools: Pass parse_state all the way down to add_tracepoint Jiri Olsa
2021-11-08 13:36 ` [PATCH 22/59] perf tools: Add evsel__new callback to parse_state_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 23/59] perf tools: Add evsel__new_tp " Jiri Olsa
2021-11-08 13:36 ` [PATCH 24/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__str Jiri Olsa
2021-11-08 13:36 ` [PATCH 25/59] perf tools: Add loc_term and loc_val helpers to parse_events_term__num Jiri Olsa
2021-11-08 13:36 ` [PATCH 26/59] libperf: Move in the event_symbols_hw/event_symbols_sw Jiri Olsa
2021-11-08 13:36 ` [PATCH 27/59] libperf: Move in struct parse_events_term code Jiri Olsa
2021-11-08 13:36 ` [PATCH 28/59] perf tools: Add perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 29/59] perf tools: Change struct parse_events_state::evlist to perf_evlist Jiri Olsa
2021-11-08 13:36 ` [PATCH 30/59] libperf: Move in struct parse_events_state Jiri Olsa
2021-11-08 18:21   ` Ian Rogers
2021-11-08 21:24     ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 31/59] perf tools: Move event_attr_init in evsel__new_idx function Jiri Olsa
2021-11-08 13:36 ` [PATCH 32/59] libperf: Move in perf_pmu__warn_invalid_config function Jiri Olsa
2021-11-08 13:36 ` [PATCH 33/59] libperf: Move in perf_evsel__add_event function Jiri Olsa
2021-11-08 13:36 ` [PATCH 34/59] perf tools: Move parse_events_update_lists to parser unit Jiri Olsa
2021-11-08 13:36 ` [PATCH 35/59] libperf: Add perf_evsel__is_group_leader function Jiri Olsa
2021-11-08 13:36 ` [PATCH 36/59] perf tools: Make parse_events__modifier_event work over perf_evsel Jiri Olsa
2021-11-08 13:36 ` [PATCH 37/59] perf tool: Pass perf_guest in struct parse_events_state Jiri Olsa
2021-11-08 13:36 ` [PATCH 38/59] libperf: Move in parse_events__modifier_group/event functions Jiri Olsa
2021-11-08 13:36 ` [PATCH 39/59] libperf: Move in parse_events__handle_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 40/59] libperf: Move in parse_events_evlist_error function Jiri Olsa
2021-11-08 13:36 ` [PATCH 41/59] perf tools: Add perf_evsel__delete callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 42/59] libperf: Move in parse_events_name function Jiri Olsa
2021-11-08 18:23   ` Ian Rogers
2021-11-08 21:24     ` Jiri Olsa
2021-11-08 13:36 ` [PATCH 43/59] perf tools: Move out parse_events_add_pmu fallback from parser code Jiri Olsa
2021-11-08 13:36 ` [PATCH 44/59] perf tools: Add add_pmu callback to struct parse_events_ops Jiri Olsa
2021-11-08 13:36 ` [PATCH 45/59] perf tools: Add add_pmu_multi " Jiri Olsa
2021-11-08 13:36 ` [PATCH 46/59] perf tools: Add add_numeric " Jiri Olsa
2021-11-08 18:27   ` Ian Rogers
2021-11-08 21:34     ` Jiri Olsa [this message]
2021-11-08 13:36 ` [PATCH 47/59] perf tools: Add add_cache " Jiri Olsa
2021-11-08 13:36 ` [PATCH 48/59] perf tools: Add add_breakpoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 49/59] perf tools: Add add_tracepoint " Jiri Olsa
2021-11-08 13:37 ` [PATCH 50/59] perf tools: Add add_bpf " Jiri Olsa
2021-11-08 13:37 ` [PATCH 51/59] perf tools: Add add_tool " Jiri Olsa
2021-11-08 13:37 ` [PATCH 52/59] perf tools: Add set_leader " Jiri Olsa
2021-11-08 13:37 ` [PATCH 53/59] perf tools: Add parse_check " Jiri Olsa
2021-11-08 13:37 ` [PATCH 54/59] perf tools: Move PE_* enums in parse_events__scanner Jiri Olsa
2021-11-08 13:37 ` [PATCH 55/59] libperf: Move in parse-events flex/bison parser Jiri Olsa
2021-11-08 13:37 ` [PATCH 56/59] libperf: Move in parse_events_add_breakpoint function Jiri Olsa
2021-11-08 13:37 ` [PATCH 57/59] libperf: Move in some lib objects from perf Jiri Olsa
2021-11-08 13:37 ` [PATCH 58/59] libperf: Add libperf_parse_events function Jiri Olsa
2021-11-08 13:37 ` [PATCH 59/59] libperf: Add parse-events test Jiri Olsa
2021-11-08 18:32   ` Ian Rogers
2021-11-08 21:37     ` Jiri Olsa
2021-11-08 18:50 ` [RFC 00/59] libperf: Move in event parse code Ian Rogers
2021-11-08 21:50   ` Jiri Olsa

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=YYmX35S+QpbRFbOX@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /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).