Commit 048a7a93 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf inject: Combine different mmap and mmap2 functions

There are repipe, build ID and JIT dump variants of the mmap and mmap2
repipe functions. The organization doesn't allow JIT dump to work with
build ID injection and the structure is less than clear. Combine the
function and enable the different behaviors based on ifs.
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-9-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0ed4c8c3
......@@ -377,44 +377,6 @@ static int perf_event__repipe_sample(const struct perf_tool *tool,
return perf_event__repipe_synth(tool, event);
}
static int perf_event__repipe_mmap(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
int err;
err = perf_event__process_mmap(tool, event, sample, machine);
perf_event__repipe(tool, event, sample, machine);
return err;
}
#ifdef HAVE_JITDUMP
static int perf_event__jit_repipe_mmap(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);
u64 n = 0;
int ret;
/*
* 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;
}
return perf_event__repipe_mmap(tool, event, sample, machine);
}
#endif
static struct dso *findnew_dso(int pid, int tid, const char *filename,
const struct dso_id *id, struct machine *machine)
{
......@@ -460,114 +422,108 @@ static struct dso *findnew_dso(int pid, int tid, const char *filename,
return dso;
}
static int perf_event__repipe_buildid_mmap(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
struct dso *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);
return perf_event__repipe(tool, event, sample, machine);
}
static int perf_event__repipe_mmap2(const struct perf_tool *tool,
static int perf_event__repipe_mmap(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
int err;
struct perf_inject *inject = container_of(tool, struct perf_inject, tool);
err = perf_event__process_mmap2(tool, event, sample, machine);
perf_event__repipe(tool, event, sample, machine);
#ifdef HAVE_JITDUMP
if (inject->jit_mode) {
u64 n = 0;
int ret;
if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
struct dso *dso;
/* 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);
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
event->mmap2.filename, NULL, machine);
if (dso) {
/* mark it not to inject build-id */
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);
return err;
if (err)
return err;
}
return perf_event__repipe(tool, event, sample, machine);
}
#ifdef HAVE_JITDUMP
static int perf_event__jit_repipe_mmap2(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *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);
u64 n = 0;
int ret;
struct dso *dso = NULL;
/*
* if jit marker, then inject jit mmaps and generate ELF images
*/
ret = jit_process(inject->session, &inject->output, machine,
event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n);
if (ret < 0)
return ret;
if (ret) {
inject->bytes_written += n;
return 0;
#ifdef HAVE_JITDUMP
if (inject->jit_mode) {
u64 n = 0;
int ret;
/* If jit marker, then inject jit mmaps and generate ELF images. */
ret = jit_process(inject->session, &inject->output, machine,
event->mmap2.filename, event->mmap2.pid, event->mmap2.tid, &n);
if (ret < 0)
return ret;
if (ret) {
inject->bytes_written += n;
return 0;
}
}
return perf_event__repipe_mmap2(tool, event, sample, machine);
}
#endif
static int perf_event__repipe_buildid_mmap2(const struct perf_tool *tool,
union perf_event *event,
struct perf_sample *sample,
struct machine *machine)
{
struct dso_id dso_id = {
.maj = event->mmap2.maj,
.min = event->mmap2.min,
.ino = event->mmap2.ino,
.ino_generation = event->mmap2.ino_generation,
};
struct dso *dso;
if (event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID) {
/* cannot use dso_id since it'd have invalid info */
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
event->mmap2.filename, NULL, machine);
if (dso) {
/* mark it not to inject build-id */
dso__set_hit(dso);
}
dso__put(dso);
perf_event__repipe(tool, event, sample, machine);
return 0;
}
if (inject->build_id_style == BID_RWS__INJECT_HEADER_ALL) {
if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) {
struct dso_id dso_id = {
.maj = event->mmap2.maj,
.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)) {
dso__set_hit(dso);
dso__inject_build_id(dso, tool, machine, sample->cpumode,
event->mmap2.flags);
}
} else {
/* Create the thread, map, etc. Not done for the unordered inject all case. */
int err = perf_event__process_mmap(tool, event, sample, machine);
dso = findnew_dso(event->mmap2.pid, event->mmap2.tid,
event->mmap2.filename, &dso_id, machine);
if (dso && !dso__hit(dso)) {
dso__set_hit(dso);
dso__inject_build_id(dso, tool, machine, sample->cpumode,
event->mmap2.flags);
if (err) {
dso__put(dso);
return err;
}
}
dso__put(dso);
perf_event__repipe(tool, event, sample, machine);
return 0;
return perf_event__repipe(tool, event, sample, machine);
}
static int perf_event__repipe_fork(const struct perf_tool *tool,
......@@ -2032,10 +1988,7 @@ static int __cmd_inject(struct perf_inject *inject)
output_data_offset = perf_session__data_offset(session->evlist);
if (inject->build_id_style == BID_RWS__INJECT_HEADER_ALL) {
inject->tool.mmap = perf_event__repipe_buildid_mmap;
inject->tool.mmap2 = perf_event__repipe_buildid_mmap2;
} else if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY) {
if (inject->build_id_style == BID_RWS__INJECT_HEADER_LAZY) {
inject->tool.sample = perf_event__inject_buildid;
} else if (inject->sched_stat) {
struct evsel *evsel;
......@@ -2430,8 +2383,8 @@ int cmd_inject(int argc, const char **argv)
#ifdef HAVE_JITDUMP
if (inject.jit_mode) {
inject.tool.mmap2 = perf_event__jit_repipe_mmap2;
inject.tool.mmap = perf_event__jit_repipe_mmap;
inject.tool.mmap2 = perf_event__repipe_mmap2;
inject.tool.mmap = perf_event__repipe_mmap;
inject.tool.ordering_requires_timestamps = true;
/*
* JIT MMAP injection injects all MMAP events in one go, so it
......
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