Commit 05c4cfeb authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf inject: Combine mmap and mmap2 handling

The handling of mmap and mmap2 events is near identical. Add a common
helper function and call that by the two event handling functions.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anne Macedo <retpolanne@posteo.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Casey Chen <cachen@purestorage.com>
Cc: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Cc: Colin Ian King <colin.i.king@gmail.com>
Cc: Dominique Martinet <asmadeus@codewreck.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jann Horn <jannh@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sun Haiyong <sunhaiyong@loongson.cn>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Yunseong Kim <yskelg@gmail.com>
Cc: Ze Gao <zegao2021@gmail.com>
Link: https://lore.kernel.org/r/20240817064442.2152089-10-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 048a7a93
...@@ -422,55 +422,21 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename, ...@@ -422,55 +422,21 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename,
return dso; return dso;
} }
static int perf_event__repipe_mmap(const struct perf_tool *tool, static int perf_event__repipe_common_mmap(const struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
struct machine *machine) struct machine *machine,
{ __u32 pid, __u32 tid, __u32 flags,
struct perf_inject *inject = container_of(tool, struct perf_inject, tool); const char *filename,
const struct dso_id *dso_id,
#ifdef HAVE_JITDUMP int (*perf_event_process)(const struct perf_tool *tool,
if (inject->jit_mode) { union perf_event *event,
u64 n = 0; struct perf_sample *sample,
int ret; struct machine *machine))
/* If jit marker, then inject jit mmaps and generate ELF images. */
ret = jit_process(inject->session, &inject->output, machine,
event->mmap.filename, event->mmap.pid, event->mmap.tid, &n);
if (ret < 0)
return ret;
if (ret) {
inject->bytes_written += n;
return 0;
}
}
#endif
if (inject->build_id_style == BID_RWS__INJECT_HEADER_ALL) {
struct dso *dso = findnew_dso(event->mmap.pid, event->mmap.tid,
event->mmap.filename, NULL, machine);
if (dso && !dso__hit(dso)) {
dso__set_hit(dso);
dso__inject_build_id(dso, tool, machine, sample->cpumode, 0);
}
dso__put(dso);
} else {
/* Create the thread, map, etc. Not done for the unordered inject all case. */
int err = perf_event__process_mmap(tool, event, sample, machine);
if (err)
return err;
}
return perf_event__repipe(tool, event, sample, machine);
}
static int perf_event__repipe_mmap2(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{ {
struct perf_inject *inject = container_of(tool, struct perf_inject, tool); struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
struct dso *dso = NULL; struct dso *dso = NULL;
bool dso_sought = false;
#ifdef HAVE_JITDUMP #ifdef HAVE_JITDUMP
if (inject->jit_mode) { if (inject->jit_mode) {
...@@ -479,7 +445,7 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool, ...@@ -479,7 +445,7 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool,
/* If jit marker, then inject jit mmaps and generate ELF images. */ /* If jit marker, then inject jit mmaps and generate ELF images. */
ret = jit_process(inject->session, &inject->output, machine, ret = jit_process(inject->session, &inject->output, machine,
event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n); filename, pid, tid, &n);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret) { if (ret) {
...@@ -489,33 +455,26 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool, ...@@ -489,33 +455,26 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool,
} }
#endif #endif
if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) { if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid, dso = findnew_dso(pid, tid, filename, dso_id, machine);
event->mmap2.filename, NULL, machine); dso_sought = true;
if (dso) { if (dso) {
/* mark it not to inject build-id */ /* mark it not to inject build-id */
dso__set_hit(dso); dso__set_hit(dso);
} }
} }
if (inject->build_id_style == BID_RWS__INJECT_HEADER_ALL) { if (inject->build_id_style == BID_RWS__INJECT_HEADER_ALL) {
if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { if (!dso_sought) {
struct dso_id dso_id = { dso = findnew_dso(pid, tid, filename, dso_id, machine);
.maj = event->mmap2.maj, dso_sought = true;
.min = event->mmap2.min,
.ino = event->mmap2.ino,
.ino_generation = event->mmap2.ino_generation,
};
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
event->mmap2.filename, &dso_id, machine);
} }
if (dso && !dso__hit(dso)) { if (dso && !dso__hit(dso)) {
dso__set_hit(dso); dso__set_hit(dso);
dso__inject_build_id(dso, tool, machine, sample->cpumode, dso__inject_build_id(dso, tool, machine, sample->cpumode, flags);
event->mmap2.flags);
} }
} else { } else {
/* Create the thread, map, etc. Not done for the unordered inject all case. */ /* Create the thread, map, etc. Not done for the unordered inject all case. */
int err = perf_event__process_mmap(tool, event, sample, machine); int err = perf_event_process(tool, event, sample, machine);
if (err) { if (err) {
dso__put(dso); dso__put(dso);
...@@ -526,6 +485,41 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool, ...@@ -526,6 +485,41 @@ static int perf_event__repipe_mmap2(const struct perf_tool *tool,
return perf_event__repipe(tool, event, sample, machine); return perf_event__repipe(tool, event, sample, machine);
} }
static int perf_event__repipe_mmap(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
return perf_event__repipe_common_mmap(
tool, event, sample, machine,
event->mmap.pid, event->mmap.tid, /*flags=*/0,
event->mmap.filename, /*dso_id=*/NULL,
perf_event__process_mmap);
}
static int perf_event__repipe_mmap2(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
struct dso_id id;
struct dso_id *dso_id = NULL;
if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) {
id.maj = event->mmap2.maj;
id.min = event->mmap2.min;
id.ino = event->mmap2.ino;
id.ino_generation = event->mmap2.ino_generation;
dso_id = &id;
}
return perf_event__repipe_common_mmap(
tool, event, sample, machine,
event->mmap2.pid, event->mmap2.tid, event->mmap2.flags,
event->mmap2.filename, dso_id,
perf_event__process_mmap2);
}
static int perf_event__repipe_fork(const struct perf_tool *tool, static int perf_event__repipe_fork(const struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment