All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Stephane Eranian <eranian@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>, lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Song Liu <songliubraving@fb.com>,
	"Frank Ch. Eigler" <fche@redhat.com>,
	Ian Rogers <irogers@google.com>,
	Alexey Budankov <alexey.budankov@linux.intel.com>,
	Andi Kleen <ak@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: Re: [PATCH 02/26] perf: Introduce mmap3 version of mmap event
Date: Mon, 14 Sep 2020 12:31:34 -0300	[thread overview]
Message-ID: <20200914153134.GD160517@kernel.org> (raw)
In-Reply-To: <CABPqkBTk+SwTAxXDa6HL8TqvEmUunfMZxpAtx6CebNbd+3hEHw@mail.gmail.com>

Em Sun, Sep 13, 2020 at 11:41:00PM -0700, Stephane Eranian escreveu:
> On Sun, Sep 13, 2020 at 2:03 PM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Add new version of mmap event. The MMAP3 record is an
> > augmented version of MMAP2, it adds build id value to
> > identify the exact binary object behind memory map:
> >
> >   struct {
> >     struct perf_event_header header;
> >
> >     u32                      pid, tid;
> >     u64                      addr;
> >     u64                      len;
> >     u64                      pgoff;
> >     u32                      maj;
> >     u32                      min;
> >     u64                      ino;
> >     u64                      ino_generation;
> >     u32                      prot, flags;
> >     u32                      reserved;
> >     u8                       buildid[20];
> >     char                     filename[];
> >     struct sample_id         sample_id;
> >   };
> >
> > Adding 4 bytes reserved field to align buildid data to 8 bytes,
> > so sample_id data is properly aligned.
> >
> > The mmap3 event is enabled by new mmap3 bit in perf_event_attr
> > struct.  When set for an event, it enables the build id retrieval
> > and will use mmap3 format for the event.
> >
> > Keeping track of mmap3 events and calling build_id_parse
> > in perf_event_mmap_event only if we have any defined.
> >
> > Having build id attached directly to the mmap event will help
> > tool like perf to skip final search through perf data for
> > binaries that are needed in the report time. Also it prevents
> > possible race when the binary could be removed or replaced
> > during profiling.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  include/uapi/linux/perf_event.h | 27 ++++++++++++++++++++++-
> >  kernel/events/core.c            | 38 +++++++++++++++++++++++++++------
> >  2 files changed, 57 insertions(+), 8 deletions(-)
> >
> > diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
> > index 077e7ee69e3d..facfc3c673ed 100644
> > --- a/include/uapi/linux/perf_event.h
> > +++ b/include/uapi/linux/perf_event.h
> > @@ -384,7 +384,8 @@ struct perf_event_attr {
> >                                 aux_output     :  1, /* generate AUX records instead of events */
> >                                 cgroup         :  1, /* include cgroup events */
> >                                 text_poke      :  1, /* include text poke events */
> > -                               __reserved_1   : 30;
> > +                               mmap3          :  1, /* include bpf events */
> > +                               __reserved_1   : 29;
> >
> what happens if I set mmap3 and mmap2?
> 
> I think using mmap3 for every mmap may be overkill as you add useless
> 20 bytes to an mmap record.

So use just PERF_RECORD_MMAP2.

I think if the user says: I need buildids, then, in kernels with support
for getting the buildid in MMAP records, use it as its more accurate,
otherwise fall back to traversing all records at the end to go over lots
of files haversting those build-ids.

If the user says I don't want build-ids, nothing changes, no collection
at the end, perf continues using PERF_RECORD_MMAP2.

> I am not sure if your code handles the case where mmap3 is not needed
> because there is no buildid, e.g, anonymous memory.
> It seems to me you've written the patch in such a way that if the user
> tool supports mmap3, then it supersedes mmap2, and thus
> you need all the fields of mmap2. But if could be more interesting to
> return either MMAP2 or MMAP3 depending on tool support
> and type of mmap, that would certainly save 20 bytes on any anon mmap.
> But maybe that logic is already in your patch and I missed it.

Right, it should take into account if the user asked for build-ids or
not in addition to checking if the kernel supports MMAP3.

- Arnaldo

> 
> >         union {
> >                 __u32           wakeup_events;    /* wakeup every n events */
> > @@ -1060,6 +1061,30 @@ enum perf_event_type {
> >          */
> >         PERF_RECORD_TEXT_POKE                   = 20,
> >
> > +       /*
> > +        * The MMAP3 records are an augmented version of MMAP2, they add
> > +        * build id value to identify the exact binary behind map
> > +        *
> > +        * struct {
> > +        *      struct perf_event_header        header;
> > +        *
> > +        *      u32                             pid, tid;
> > +        *      u64                             addr;
> > +        *      u64                             len;
> > +        *      u64                             pgoff;
> > +        *      u32                             maj;
> > +        *      u32                             min;
> > +        *      u64                             ino;
> > +        *      u64                             ino_generation;
> > +        *      u32                             prot, flags;
> > +        *      u32                             reserved;
> > +        *      u8                              buildid[20];
> > +        *      char                            filename[];
> > +        *      struct sample_id                sample_id;
> > +        * };
> > +        */
> > +       PERF_RECORD_MMAP3                       = 21,
> > +
> >         PERF_RECORD_MAX,                        /* non-ABI */
> >  };
> >
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index 7ed5248f0445..719894492dac 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -51,6 +51,7 @@
> >  #include <linux/proc_ns.h>
> >  #include <linux/mount.h>
> >  #include <linux/min_heap.h>
> > +#include <linux/buildid.h>
> >
> >  #include "internal.h"
> >
> > @@ -386,6 +387,7 @@ static DEFINE_PER_CPU(int, perf_sched_cb_usages);
> >  static DEFINE_PER_CPU(struct pmu_event_list, pmu_sb_events);
> >
> >  static atomic_t nr_mmap_events __read_mostly;
> > +static atomic_t nr_mmap3_events __read_mostly;
> >  static atomic_t nr_comm_events __read_mostly;
> >  static atomic_t nr_namespaces_events __read_mostly;
> >  static atomic_t nr_task_events __read_mostly;
> > @@ -4588,7 +4590,7 @@ static bool is_sb_event(struct perf_event *event)
> >                 return false;
> >
> >         if (attr->mmap || attr->mmap_data || attr->mmap2 ||
> > -           attr->comm || attr->comm_exec ||
> > +           attr->mmap3 || attr->comm || attr->comm_exec ||
> >             attr->task || attr->ksymbol ||
> >             attr->context_switch || attr->text_poke ||
> >             attr->bpf_event)
> > @@ -4644,6 +4646,8 @@ static void unaccount_event(struct perf_event *event)
> >                 dec = true;
> >         if (event->attr.mmap || event->attr.mmap_data)
> >                 atomic_dec(&nr_mmap_events);
> > +       if (event->attr.mmap3)
> > +               atomic_dec(&nr_mmap3_events);
> >         if (event->attr.comm)
> >                 atomic_dec(&nr_comm_events);
> >         if (event->attr.namespaces)
> > @@ -7465,7 +7469,7 @@ static void perf_pmu_output_stop(struct perf_event *event)
> >  /*
> >   * task tracking -- fork/exit
> >   *
> > - * enabled by: attr.comm | attr.mmap | attr.mmap2 | attr.mmap_data | attr.task
> > + * enabled by: attr.comm | attr.mmap | attr.mmap2 | attr.mmap3 | attr.mmap_data | attr.task
> >   */
> >
> >  struct perf_task_event {
> > @@ -7486,8 +7490,8 @@ struct perf_task_event {
> >  static int perf_event_task_match(struct perf_event *event)
> >  {
> >         return event->attr.comm  || event->attr.mmap ||
> > -              event->attr.mmap2 || event->attr.mmap_data ||
> > -              event->attr.task;
> > +              event->attr.mmap2 || event->attr.mmap3 ||
> > +              event->attr.mmap_data || event->attr.task;
> >  }
> >
> >  static void perf_event_task_output(struct perf_event *event,
> > @@ -7913,6 +7917,7 @@ struct perf_mmap_event {
> >         u64                     ino;
> >         u64                     ino_generation;
> >         u32                     prot, flags;
> > +       u8                      buildid[BUILD_ID_SIZE];
> >
> >         struct {
> >                 struct perf_event_header        header;
> > @@ -7933,7 +7938,7 @@ static int perf_event_mmap_match(struct perf_event *event,
> >         int executable = vma->vm_flags & VM_EXEC;
> >
> >         return (!executable && event->attr.mmap_data) ||
> > -              (executable && (event->attr.mmap || event->attr.mmap2));
> > +              (executable && (event->attr.mmap || event->attr.mmap2 || event->attr.mmap3));
> >  }
> >
> >  static void perf_event_mmap_output(struct perf_event *event,
> > @@ -7949,7 +7954,7 @@ static void perf_event_mmap_output(struct perf_event *event,
> >         if (!perf_event_mmap_match(event, data))
> >                 return;
> >
> > -       if (event->attr.mmap2) {
> > +       if (event->attr.mmap2 || event->attr.mmap3) {
> >                 mmap_event->event_id.header.type = PERF_RECORD_MMAP2;
> >                 mmap_event->event_id.header.size += sizeof(mmap_event->maj);
> >                 mmap_event->event_id.header.size += sizeof(mmap_event->min);
> > @@ -7959,6 +7964,12 @@ static void perf_event_mmap_output(struct perf_event *event,
> >                 mmap_event->event_id.header.size += sizeof(mmap_event->flags);
> >         }
> >
> > +       if (event->attr.mmap3) {
> > +               mmap_event->event_id.header.type = PERF_RECORD_MMAP3;
> > +               mmap_event->event_id.header.size += sizeof(u32);
> > +               mmap_event->event_id.header.size += sizeof(mmap_event->buildid);
> > +       }
> > +
> >         perf_event_header__init_id(&mmap_event->event_id.header, &sample, event);
> >         ret = perf_output_begin(&handle, event,
> >                                 mmap_event->event_id.header.size);
> > @@ -7970,7 +7981,7 @@ static void perf_event_mmap_output(struct perf_event *event,
> >
> >         perf_output_put(&handle, mmap_event->event_id);
> >
> > -       if (event->attr.mmap2) {
> > +       if (event->attr.mmap2 || event->attr.mmap3) {
> >                 perf_output_put(&handle, mmap_event->maj);
> >                 perf_output_put(&handle, mmap_event->min);
> >                 perf_output_put(&handle, mmap_event->ino);
> > @@ -7979,6 +7990,13 @@ static void perf_event_mmap_output(struct perf_event *event,
> >                 perf_output_put(&handle, mmap_event->flags);
> >         }
> >
> > +       if (event->attr.mmap3) {
> > +               u32 reserved = 0;
> > +
> > +               perf_output_put(&handle, reserved);
> > +               __output_copy(&handle, mmap_event->buildid, BUILD_ID_SIZE);
> > +       }
> > +
> >         __output_copy(&handle, mmap_event->file_name,
> >                                    mmap_event->file_size);
> >
> > @@ -8098,6 +8116,9 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
> >         mmap_event->prot = prot;
> >         mmap_event->flags = flags;
> >
> > +       if (atomic_read(&nr_mmap3_events))
> > +               build_id_parse(vma, mmap_event->buildid);
> > +
> >         if (!(vma->vm_flags & VM_EXEC))
> >                 mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA;
> >
> > @@ -8241,6 +8262,7 @@ void perf_event_mmap(struct vm_area_struct *vma)
> >                 /* .ino_generation (attr_mmap2 only) */
> >                 /* .prot (attr_mmap2 only) */
> >                 /* .flags (attr_mmap2 only) */
> > +               /* .buildid (attr_mmap3 only) */
> >         };
> >
> >         perf_addr_filters_adjust(vma);
> > @@ -11040,6 +11062,8 @@ static void account_event(struct perf_event *event)
> >                 inc = true;
> >         if (event->attr.mmap || event->attr.mmap_data)
> >                 atomic_inc(&nr_mmap_events);
> > +       if (event->attr.mmap3)
> > +               atomic_inc(&nr_mmap3_events);
> >         if (event->attr.comm)
> >                 atomic_inc(&nr_comm_events);
> >         if (event->attr.namespaces)
> > --
> > 2.26.2
> >

-- 

- Arnaldo

  parent reply	other threads:[~2020-09-14 15:33 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-13 21:02 [RFC 00/26] perf: Add mmap3 support Jiri Olsa
2020-09-13 21:02 ` [PATCH 01/26] bpf: Move stack_map_get_build_id into lib Jiri Olsa
2020-09-14  6:09   ` Song Liu
2020-09-13 21:02 ` [PATCH 02/26] perf: Introduce mmap3 version of mmap event Jiri Olsa
2020-09-14  5:38   ` Namhyung Kim
2020-09-14  6:20     ` Song Liu
2020-09-14 19:38       ` Jiri Olsa
2020-09-14 15:28     ` Arnaldo Carvalho de Melo
2020-09-14 16:35       ` peterz
2020-09-14 17:08         ` Ian Rogers
2020-09-14 20:07           ` Jiri Olsa
2020-09-15  5:49             ` Adrian Hunter
2020-09-14 19:38         ` Jiri Olsa
2020-09-14 19:39       ` Jiri Olsa
2020-09-14 22:00         ` Arnaldo Carvalho de Melo
2020-09-15  5:39           ` Adrian Hunter
2020-09-14 19:38     ` Jiri Olsa
2020-09-15  2:54       ` Namhyung Kim
2020-09-14  6:41   ` Stephane Eranian
2020-09-14  9:08     ` peterz
2020-09-14 15:32       ` Arnaldo Carvalho de Melo
2020-09-14 17:26       ` Stephane Eranian
2020-09-14 19:56         ` Jiri Olsa
2020-09-15  0:03         ` Ian Rogers
2020-09-14 15:31     ` Arnaldo Carvalho de Melo [this message]
2020-09-14 19:50       ` Jiri Olsa
2020-09-14 22:38         ` Arnaldo Carvalho de Melo
2020-09-14 19:45     ` Jiri Olsa
2020-09-14  9:36   ` peterz
2020-09-13 21:02 ` [PATCH 03/26] tools headers uapi: Sync tools/include/uapi/linux/perf_event.h Jiri Olsa
2020-09-14  5:39   ` Namhyung Kim
2020-09-13 21:02 ` [PATCH 04/26] perf tools: Add filename__decompress function Jiri Olsa
2020-09-14 15:35   ` Arnaldo Carvalho de Melo
2020-09-14 20:43     ` Jiri Olsa
2020-09-17 18:54       ` Arnaldo Carvalho de Melo
2020-09-18 10:51         ` Jiri Olsa
2020-09-13 21:02 ` [PATCH 05/26] perf tools: Add build_id__is_defined function Jiri Olsa
2020-09-14  5:44   ` Namhyung Kim
2020-09-14 16:03     ` Arnaldo Carvalho de Melo
2020-09-14 20:49       ` Jiri Olsa
2020-09-14 20:47     ` Jiri Olsa
2020-09-14 21:51       ` Arnaldo Carvalho de Melo
2020-09-13 21:02 ` [PATCH 06/26] perf tools: Add support to read build id from compressed elf Jiri Olsa
2020-09-14 16:04   ` Arnaldo Carvalho de Melo
2020-09-14 20:49     ` Jiri Olsa
2020-09-13 21:02 ` [PATCH 07/26] perf tools: Add check for existing link in buildid dir Jiri Olsa
2020-09-14  5:54   ` Namhyung Kim
2020-09-14 20:18     ` Jiri Olsa
2020-09-13 21:02 ` [PATCH 08/26] perf tools: Use struct extra_kernel_map in machine__process_kernel_mmap_event Jiri Olsa
2020-09-13 21:02 ` [PATCH 09/26] perf tools: Try load vmlinux from buildid database Jiri Olsa
2020-09-14  6:25   ` Namhyung Kim
2020-09-14 20:29     ` Jiri Olsa
2020-09-15  2:58       ` Namhyung Kim
2020-09-13 21:02 ` [PATCH 10/26] perf tools: Enable mmap3 map event when supported Jiri Olsa
2020-09-14 16:05   ` Arnaldo Carvalho de Melo
2020-09-13 21:02 ` [PATCH 11/26] perf tools: Add mmap3 support Jiri Olsa
2020-09-13 21:02 ` [PATCH 12/26] perf tools: Set build id for kernel dso objects Jiri Olsa
2020-09-13 21:03 ` [PATCH 13/26] perf tools: Plug in mmap3 event Jiri Olsa
2020-09-13 21:03 ` [PATCH 14/26] perf tools: Add mmap3 events to --show-mmap-events option Jiri Olsa
2020-09-14  6:30   ` Namhyung Kim
2020-09-14 20:29     ` Jiri Olsa
2020-09-13 21:03 ` [PATCH 15/26] perf tools: Synthesize proc tasks with mmap3 Jiri Olsa
2020-09-14 16:07   ` Arnaldo Carvalho de Melo
2020-09-14 20:51     ` Jiri Olsa
2020-09-13 21:03 ` [PATCH 16/26] perf tools: Synthesize modules " Jiri Olsa
2020-09-14 16:07   ` Arnaldo Carvalho de Melo
2020-09-15 20:17     ` Ian Rogers
2020-09-16  8:20       ` Jiri Olsa
2020-09-16 14:07         ` Arnaldo Carvalho de Melo
2020-09-16 14:17           ` peterz
2020-09-16 15:10             ` Arnaldo Carvalho de Melo
2020-09-16 15:20               ` peterz
2020-09-16 15:21               ` Jiri Olsa
2020-09-16 15:42                 ` Arnaldo Carvalho de Melo
2020-09-13 21:03 ` [PATCH 17/26] perf tools: Synthesize kernel " Jiri Olsa
2020-09-14 16:08   ` Arnaldo Carvalho de Melo
2020-09-13 21:03 ` [PATCH 18/26] perf tests: Add mmap3 support for perf record test Jiri Olsa
2020-09-13 21:03 ` [PATCH 19/26] perf tools: Add buildid-list support for mmap3 Jiri Olsa
2020-09-13 21:03 ` [PATCH 20/26] perf tools: Add build_id_cache__add function Jiri Olsa
2020-09-14 16:13   ` Arnaldo Carvalho de Melo
2020-09-13 21:03 ` [PATCH 21/26] perf tools: Add machine__for_each_dso function Jiri Olsa
2020-09-14 16:15   ` Arnaldo Carvalho de Melo
2020-09-13 21:03 ` [PATCH 22/26] perf tools: Use machine__for_each_dso in perf_session__cache_build_ids Jiri Olsa
2020-09-13 21:03 ` [PATCH 23/26] perf tools: Add __perf_session__cache_build_ids function Jiri Olsa
2020-09-13 21:03 ` [PATCH 24/26] perf tools: Add buildid-list --store option Jiri Olsa
2020-09-14  6:42   ` Namhyung Kim
2020-09-14 15:14     ` Arnaldo Carvalho de Melo
2020-09-14 20:42       ` Jiri Olsa
2020-09-14 20:42     ` Jiri Olsa
2020-09-13 21:03 ` [PATCH 25/26] perf tools: Move debuginfo download code into get_debuginfo Jiri Olsa
2020-09-13 21:03 ` [PATCH 26/26] perf tools: Add report --store option Jiri Olsa
2020-09-14  5:25 ` [RFC 00/26] perf: Add mmap3 support Namhyung Kim
2020-09-14 15:13   ` Arnaldo Carvalho de Melo

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=20200914153134.GD160517@kernel.org \
    --to=acme@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.budankov@linux.intel.com \
    --cc=eranian@google.com \
    --cc=fche@redhat.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=songliubraving@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.