From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.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>, Ian Rogers <irogers@google.com>,
Stephane Eranian <eranian@google.com>,
Alexei Budankov <abudankov@huawei.com>,
Andi Kleen <ak@linux.intel.com>,
Adrian Hunter <adrian.hunter@intel.com>
Subject: Re: [PATCH 03/15] perf: Add build id data in mmap2 event
Date: Tue, 15 Dec 2020 12:52:26 -0300 [thread overview]
Message-ID: <20201215155226.GK258566@kernel.org> (raw)
In-Reply-To: <20201214105457.543111-4-jolsa@kernel.org>
Em Mon, Dec 14, 2020 at 11:54:45AM +0100, Jiri Olsa escreveu:
> Adding support to carry build id data in mmap2 event.
>
> The build id data replaces maj/min/ino/ino_generation
> fields, which are also used to identify map's binary,
> so it's ok to replace them with build id data:
>
> union {
> struct {
> u32 maj;
> u32 min;
> u64 ino;
> u64 ino_generation;
> };
> struct {
> u8 build_id_size;
> u8 __reserved_1;
> u16 __reserved_2;
> u8 build_id[20];
> };
> };
Alexei/Daniel, this one depends on BPFs build id routines to be exported
for use by the perf kernel subsys, PeterZ already acked this, so can you
guys consider getting the first three patches in this series via the bpf
tree?
The BPF bits were acked by Song.
- Arnaldo
> Replaced maj/min/ino/ino_generation fields give us size
> of 24 bytes. We use 20 bytes for build id data, 1 byte
> for size and rest is unused.
>
> There's new misc bit for mmap2 to signal there's build
> id data in it:
>
> #define PERF_RECORD_MISC_MMAP_BUILD_ID (1 << 14)
>
> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> include/uapi/linux/perf_event.h | 42 +++++++++++++++++++++++++++++----
> kernel/events/core.c | 32 +++++++++++++++++++++----
> 2 files changed, 65 insertions(+), 9 deletions(-)
>
> diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
> index b95d3c485d27..45a216bea048 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;
> + build_id : 1, /* use build id in mmap2 events */
> + __reserved_1 : 29;
>
> union {
> __u32 wakeup_events; /* wakeup every n events */
> @@ -657,6 +658,22 @@ struct perf_event_mmap_page {
> __u64 aux_size;
> };
>
> +/*
> + * The current state of perf_event_header::misc bits usage:
> + * ('|' used bit, '-' unused bit)
> + *
> + * 012 CDEF
> + * |||---------||||
> + *
> + * Where:
> + * 0-2 CPUMODE_MASK
> + *
> + * C PROC_MAP_PARSE_TIMEOUT
> + * D MMAP_DATA / COMM_EXEC / FORK_EXEC / SWITCH_OUT
> + * E MMAP_BUILD_ID / EXACT_IP / SCHED_OUT_PREEMPT
> + * F (reserved)
> + */
> +
> #define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
> #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
> #define PERF_RECORD_MISC_KERNEL (1 << 0)
> @@ -688,6 +705,7 @@ struct perf_event_mmap_page {
> *
> * PERF_RECORD_MISC_EXACT_IP - PERF_RECORD_SAMPLE of precise events
> * PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
> + * PERF_RECORD_MISC_MMAP_BUILD_ID - PERF_RECORD_MMAP2 event
> *
> *
> * PERF_RECORD_MISC_EXACT_IP:
> @@ -697,9 +715,13 @@ struct perf_event_mmap_page {
> *
> * PERF_RECORD_MISC_SWITCH_OUT_PREEMPT:
> * Indicates that thread was preempted in TASK_RUNNING state.
> + *
> + * PERF_RECORD_MISC_MMAP_BUILD_ID:
> + * Indicates that mmap2 event carries build id data.
> */
> #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
> #define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
> +#define PERF_RECORD_MISC_MMAP_BUILD_ID (1 << 14)
> /*
> * Reserve the last bit to indicate some extended misc field
> */
> @@ -911,10 +933,20 @@ enum perf_event_type {
> * u64 addr;
> * u64 len;
> * u64 pgoff;
> - * u32 maj;
> - * u32 min;
> - * u64 ino;
> - * u64 ino_generation;
> + * union {
> + * struct {
> + * u32 maj;
> + * u32 min;
> + * u64 ino;
> + * u64 ino_generation;
> + * };
> + * struct {
> + * u8 build_id_size;
> + * u8 __reserved_1;
> + * u16 __reserved_2;
> + * u8 build_id[20];
> + * };
> + * };
> * u32 prot, flags;
> * char filename[];
> * struct sample_id sample_id;
> diff --git a/kernel/events/core.c b/kernel/events/core.c
> index dc568ca295bd..6cbd04a24d3a 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"
>
> @@ -395,6 +396,7 @@ static atomic_t nr_ksymbol_events __read_mostly;
> static atomic_t nr_bpf_events __read_mostly;
> static atomic_t nr_cgroup_events __read_mostly;
> static atomic_t nr_text_poke_events __read_mostly;
> +static atomic_t nr_build_id_events __read_mostly;
>
> static LIST_HEAD(pmus);
> static DEFINE_MUTEX(pmus_lock);
> @@ -4665,6 +4667,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.build_id)
> + atomic_dec(&nr_build_id_events);
> if (event->attr.comm)
> atomic_dec(&nr_comm_events);
> if (event->attr.namespaces)
> @@ -7934,6 +7938,8 @@ struct perf_mmap_event {
> u64 ino;
> u64 ino_generation;
> u32 prot, flags;
> + u8 build_id[BUILD_ID_SIZE_MAX];
> + u32 build_id_size;
>
> struct {
> struct perf_event_header header;
> @@ -7965,6 +7971,7 @@ static void perf_event_mmap_output(struct perf_event *event,
> struct perf_sample_data sample;
> int size = mmap_event->event_id.header.size;
> u32 type = mmap_event->event_id.header.type;
> + bool use_build_id;
> int ret;
>
> if (!perf_event_mmap_match(event, data))
> @@ -7989,13 +7996,25 @@ static void perf_event_mmap_output(struct perf_event *event,
> mmap_event->event_id.pid = perf_event_pid(event, current);
> mmap_event->event_id.tid = perf_event_tid(event, current);
>
> + use_build_id = event->attr.build_id && mmap_event->build_id_size;
> +
> + if (event->attr.mmap2 && use_build_id)
> + mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID;
> +
> perf_output_put(&handle, mmap_event->event_id);
>
> if (event->attr.mmap2) {
> - perf_output_put(&handle, mmap_event->maj);
> - perf_output_put(&handle, mmap_event->min);
> - perf_output_put(&handle, mmap_event->ino);
> - perf_output_put(&handle, mmap_event->ino_generation);
> + if (use_build_id) {
> + u8 size[4] = { (u8) mmap_event->build_id_size, 0, 0, 0 };
> +
> + __output_copy(&handle, size, 4);
> + __output_copy(&handle, mmap_event->build_id, BUILD_ID_SIZE_MAX);
> + } else {
> + perf_output_put(&handle, mmap_event->maj);
> + perf_output_put(&handle, mmap_event->min);
> + perf_output_put(&handle, mmap_event->ino);
> + perf_output_put(&handle, mmap_event->ino_generation);
> + }
> perf_output_put(&handle, mmap_event->prot);
> perf_output_put(&handle, mmap_event->flags);
> }
> @@ -8124,6 +8143,9 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
>
> mmap_event->event_id.header.size = sizeof(mmap_event->event_id) + size;
>
> + if (atomic_read(&nr_build_id_events))
> + build_id_parse(vma, mmap_event->build_id, &mmap_event->build_id_size);
> +
> perf_iterate_sb(perf_event_mmap_output,
> mmap_event,
> NULL);
> @@ -11060,6 +11082,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.build_id)
> + atomic_inc(&nr_build_id_events);
> if (event->attr.comm)
> atomic_inc(&nr_comm_events);
> if (event->attr.namespaces)
> --
> 2.26.2
>
--
- Arnaldo
next prev parent reply other threads:[~2020-12-15 15:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 10:54 [PATCHv5 00/15] perf: Add mmap2 build id support Jiri Olsa
2020-12-14 10:54 ` [PATCH 01/15] bpf: Move stack_map_get_build_id into lib Jiri Olsa
2020-12-15 15:49 ` Arnaldo Carvalho de Melo
2020-12-14 10:54 ` [PATCH 02/15] bpf: Add size arg to build_id_parse function Jiri Olsa
2020-12-14 10:54 ` [PATCH 03/15] perf: Add build id data in mmap2 event Jiri Olsa
2020-12-15 15:52 ` Arnaldo Carvalho de Melo [this message]
2020-12-15 22:01 ` Daniel Borkmann
2020-12-25 22:35 ` Jiri Olsa
2020-12-28 13:56 ` Arnaldo Carvalho de Melo
2020-12-14 10:54 ` [PATCH 04/15] tools headers uapi: Sync tools/include/uapi/linux/perf_event.h Jiri Olsa
2020-12-14 10:54 ` [PATCH 05/15] perf tools: Do not swap mmap2 fields in case it contains build id Jiri Olsa
2020-12-14 10:54 ` [PATCH 06/15] perf tools: Add support to read build id from compressed elf Jiri Olsa
2020-12-15 15:55 ` Arnaldo Carvalho de Melo
2020-12-28 13:01 ` Arnaldo Carvalho de Melo
2020-12-14 10:54 ` [PATCH 07/15] perf tools: Store build id from mmap2 events Jiri Olsa
2020-12-14 10:54 ` [PATCH 08/15] perf tools: Allow mmap2 event to synthesize kernel image Jiri Olsa
2020-12-14 10:54 ` [PATCH 09/15] perf tools: Allow mmap2 event to synthesize modules Jiri Olsa
2020-12-14 10:54 ` [PATCH 10/15] perf tools: Synthesize build id for kernel/modules/tasks Jiri Olsa
2020-12-14 10:54 ` [PATCH 11/15] perf tools: Add support to display build id for mmap2 events Jiri Olsa
2020-12-14 10:54 ` [PATCH 12/15] perf buildid-cache: Add support to add build ids from perf data Jiri Olsa
2020-12-14 10:54 ` [PATCH 13/15] perf buildid-cache: Add --debuginfod option Jiri Olsa
2020-12-15 15:53 ` Arnaldo Carvalho de Melo
2020-12-14 10:54 ` [PATCH 14/15] perf buildid-list: Add support for mmap2's buildid events Jiri Olsa
2020-12-14 10:54 ` [PATCH 15/15] perf record: Add --buildid-mmap option to enable mmap's build id Jiri Olsa
2020-12-28 13:44 ` Arnaldo Carvalho de Melo
2020-12-28 23:02 ` Jiri Olsa
2020-12-15 13:43 ` [PATCHv5 00/15] perf: Add mmap2 build id support Namhyung Kim
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=20201215155226.GK258566@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=abudankov@huawei.com \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexei.starovoitov@gmail.com \
--cc=daniel@iogearbox.net \
--cc=eranian@google.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=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox