linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	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>,
	Stephane Eranian <eranian@google.com>,
	Alexei Budankov <abudankov@huawei.com>,
	Andi Kleen <ak@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH 09/15] perf tools: Allow mmap2 event to synthesize modules
Date: Mon, 14 Dec 2020 11:54:51 +0100	[thread overview]
Message-ID: <20201214105457.543111-10-jolsa@kernel.org> (raw)
In-Reply-To: <20201214105457.543111-1-jolsa@kernel.org>

Allow mmap2 event to synthesize kernel modules,
so we can synthesize module's build id data in
following changes.

It's enabled by new symbol_conf.buildid_mmap2
bool, which will be switched in following
changes.

Acked-by: Ian Rogers <irogers@google.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/synthetic-events.c | 49 +++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index a5f271fa2ae4..c209377106f5 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -596,16 +596,17 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
 	int rc = 0;
 	struct map *pos;
 	struct maps *maps = machine__kernel_maps(machine);
-	union perf_event *event = zalloc((sizeof(event->mmap) +
-					  machine->id_hdr_size));
+	union perf_event *event;
+	size_t size = symbol_conf.buildid_mmap2 ?
+			sizeof(event->mmap2) : sizeof(event->mmap);
+
+	event = zalloc(size + machine->id_hdr_size);
 	if (event == NULL) {
 		pr_debug("Not enough memory synthesizing mmap event "
 			 "for kernel modules\n");
 		return -1;
 	}
 
-	event->header.type = PERF_RECORD_MMAP;
-
 	/*
 	 * kernel uses 0 for user space maps, see kernel/perf_event.c
 	 * __perf_event_mmap
@@ -616,23 +617,37 @@ int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t
 		event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
 
 	maps__for_each_entry(maps, pos) {
-		size_t size;
-
 		if (!__map__is_kmodule(pos))
 			continue;
 
-		size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
-		event->mmap.header.type = PERF_RECORD_MMAP;
-		event->mmap.header.size = (sizeof(event->mmap) -
-				        (sizeof(event->mmap.filename) - size));
-		memset(event->mmap.filename + size, 0, machine->id_hdr_size);
-		event->mmap.header.size += machine->id_hdr_size;
-		event->mmap.start = pos->start;
-		event->mmap.len   = pos->end - pos->start;
-		event->mmap.pid   = machine->pid;
+		if (symbol_conf.buildid_mmap2) {
+			size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
+			event->mmap2.header.type = PERF_RECORD_MMAP2;
+			event->mmap2.header.size = (sizeof(event->mmap2) -
+						(sizeof(event->mmap2.filename) - size));
+			memset(event->mmap2.filename + size, 0, machine->id_hdr_size);
+			event->mmap2.header.size += machine->id_hdr_size;
+			event->mmap2.start = pos->start;
+			event->mmap2.len   = pos->end - pos->start;
+			event->mmap2.pid   = machine->pid;
+
+			memcpy(event->mmap2.filename, pos->dso->long_name,
+			       pos->dso->long_name_len + 1);
+		} else {
+			size = PERF_ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
+			event->mmap.header.type = PERF_RECORD_MMAP;
+			event->mmap.header.size = (sizeof(event->mmap) -
+						(sizeof(event->mmap.filename) - size));
+			memset(event->mmap.filename + size, 0, machine->id_hdr_size);
+			event->mmap.header.size += machine->id_hdr_size;
+			event->mmap.start = pos->start;
+			event->mmap.len   = pos->end - pos->start;
+			event->mmap.pid   = machine->pid;
+
+			memcpy(event->mmap.filename, pos->dso->long_name,
+			       pos->dso->long_name_len + 1);
+		}
 
-		memcpy(event->mmap.filename, pos->dso->long_name,
-		       pos->dso->long_name_len + 1);
 		if (perf_tool__process_synth_event(tool, event, machine, process) != 0) {
 			rc = -1;
 			break;
-- 
2.26.2


  parent reply	other threads:[~2020-12-14 10:57 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
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 ` Jiri Olsa [this message]
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=20201214105457.543111-10-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=abudankov@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --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 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).