linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tstoyanov@vmware.com>
To: Andres Freund <andres@anarazel.de>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>,
	Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH] tools/lib/traceevent, tools/perf: Move struct tep_handler definition in a local header file
Date: Fri, 26 Jul 2019 08:25:53 +0000	[thread overview]
Message-ID: <CACqStocyU4TEwqBnCOgjaG6MsCaxi1+ZQgJFACNPxw7DBBSsyw@mail.gmail.com> (raw)
In-Reply-To: <20190726035829.4xcw5k2exx4omlvg@alap3.anarazel.de>

Hi Andres,

On Fri, Jul 26, 2019 at 6:58 AM Andres Freund <andres@anarazel.de> wrote:
>
> Hi,
>
...
>
> Is just plain wrong, as:
>
> > -             return pevent->events[idx];
> > +             return (all_events + idx);
>
> that's not a valid conversion. ->events isn't an array of tep_handle,
> it's an array of tep_handle* (and even if it were, the previous notation
> would have needed to dereference the value to make it comparable). What
> this does is look idx behind the individually allocated event. Which is
> incorrect.
>
You are right, it is a bug.
>
...
>
> The following patch fixes this for me. I can polish it up, but I'm
> wondering if I'm missing something here?
>
> diff --git i/tools/lib/traceevent/event-parse.h w/tools/lib/traceevent/event-parse.h
> index 642f68ab5fb2..7ebc9b5308d4 100644
> --- i/tools/lib/traceevent/event-parse.h
> +++ w/tools/lib/traceevent/event-parse.h
> @@ -517,6 +517,7 @@ int tep_read_number_field(struct tep_format_field *field, const void *data,
>                           unsigned long long *value);
>
>  struct tep_event *tep_get_first_event(struct tep_handle *tep);
> +struct tep_event *tep_get_event(struct tep_handle *tep, int index);
>  int tep_get_events_count(struct tep_handle *tep);
>  struct tep_event *tep_find_event(struct tep_handle *tep, int id);
>
> diff --git i/tools/perf/util/trace-event-parse.c w/tools/perf/util/trace-event-parse.c
> index 62bc61155dd1..6a035ffd58ac 100644
> --- i/tools/perf/util/trace-event-parse.c
> +++ w/tools/perf/util/trace-event-parse.c
> @@ -179,28 +179,26 @@ struct tep_event *trace_find_next_event(struct tep_handle *pevent,
>  {
>         static int idx;
>         int events_count;
> -       struct tep_event *all_events;
>
> -       all_events = tep_get_first_event(pevent);
>         events_count = tep_get_events_count(pevent);
> -       if (!pevent || !all_events || events_count < 1)
> +       if (!pevent || events_count < 1)
>                 return NULL;
>
>         if (!event) {
>                 idx = 0;
> -               return all_events;
> +               return tep_get_event(pevent, 0);
>         }
>
> -       if (idx < events_count && event == (all_events + idx)) {
> +       if (idx < events_count && event == tep_get_event(pevent, idx)) {
>                 idx++;
>                 if (idx == events_count)
>                         return NULL;
> -               return (all_events + idx);
> +               return tep_get_event(pevent, idx);
>         }
>
>         for (idx = 1; idx < events_count; idx++) {
> -               if (event == (all_events + (idx - 1)))
> -                       return (all_events + idx);
> +               if (event == tep_get_event(pevent, idx - 1))
> +                       return tep_get_event(pevent, idx);
>         }
>         return NULL;
>  }
>
>

I'm OK with the first part of the patch, the changes in
tools/lib/traceevent/event-parse.h.
tep_get_event() is an API and is omitted in the header by mistake, it
should be there.

As for the fix for the crash itself, I think it would be better to
implement your suggestion -
removing trace_find_next_event() at all and replacing it with
tep_get_events_count() and
tep_get_event() loop.

>
>
> Not related to this crash, but it also seems that the whole
> trace_find_next_event() API ought to be removed. Back when it was
>
> -struct event *trace_find_next_event(struct event *event)
> -{
> -       if (!event)
> -               return event_list;
> -
> -       return event->next;
> -}
>
> it made some sense, but the changes in
>
> commit aaf045f72335653b24784d6042be8e4aee114403
> Author: Steven Rostedt <srostedt@redhat.com>
> Date:   2012-04-06 00:47:56 +0200
>
>     perf: Have perf use the new libtraceevent.a library
>
> seem to make the current API somewhat absurd, as evidenced by the
> complexity in trace_find_next_event(). I mean even just removing that
> function and changing the two callsites to simple for loops with
> tep_get_events_count() & tep_get_event() ought to be a lot better.
>
> Greetings,
>
> Andres Freund

Thanks!

-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

  reply	other threads:[~2019-07-26  8:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-05 16:22 [PATCH] tools/lib/traceevent, tools/perf: Move struct tep_handler definition in a local header file Steven Rostedt
2018-10-05 16:28 ` Steven Rostedt
2018-10-08 17:32   ` Arnaldo Carvalho de Melo
2018-10-08 19:54     ` Steven Rostedt
2018-10-08 17:31 ` Arnaldo Carvalho de Melo
2018-10-09  5:33 ` [tip:perf/core] tools lib traceevent, perf tools: " tip-bot for Tzvetomir Stoyanov
2019-07-26  3:58 ` [PATCH] tools/lib/traceevent, tools/perf: " Andres Freund
2019-07-26  8:25   ` Tzvetomir Stoyanov [this message]
2019-07-26 13:12   ` Steven Rostedt
2019-07-26 20:55     ` Andres Freund
2019-07-26 21:00       ` Steven Rostedt
2019-08-01 14:09       ` Steven Rostedt
  -- strict thread matches above, loose matches on Subject: below --
2018-08-13 15:06 Tzvetomir Stoyanov (VMware)
2018-10-03  0:05 ` Steven Rostedt

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=CACqStocyU4TEwqBnCOgjaG6MsCaxi1+ZQgJFACNPxw7DBBSsyw@mail.gmail.com \
    --to=tstoyanov@vmware.com \
    --cc=acme@kernel.org \
    --cc=andres@anarazel.de \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.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).