From nobody Mon Feb 9 21:19:14 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B11F214659D for ; Sat, 17 Aug 2024 06:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877122; cv=none; b=KbhmMVwvNAMB7bKAlwq8aQCTH8oGHt+vual5GcAEHUZcc4Roegt7/kA5u6e+IPC8Jv4Acp3UBJqIa3Gve6hDIYgUE1434Rh2TEXOUF/bFrM4qHWD/drAQACRd+CSE2Li5wXGF1rM8wLmhQlwVozsPplYM//139u8FAxWTpSIR14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723877122; c=relaxed/simple; bh=WW1VpISX2ocellr2odfdikhDznsZtCHPvqIBB2Ouivw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=ua+YBFSSEsawe6HJGr07x6xUMAUr+TUrV6ILw227Fh03C3g7lxTy/kmI7ufGLfA3mg37wCjBFTq++IVHknuiiau4CQ3rCo62GLWSbQKcf+v2DwJiEAWjX8WDHedh8Ep9UAKMfoAIecQNsVDww8ULs+97Y21podOhd2NBS3np9zA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FQWMugF3; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FQWMugF3" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e116c697904so4991169276.1 for ; Fri, 16 Aug 2024 23:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723877120; x=1724481920; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=CgTxrjJSN3UEpj2V6TaLEsH3nbDGy1R5SWod1sFWZ8c=; b=FQWMugF39G5RanQ9cS21+F0MOil3LvrnnI6Mhjqo1xUlCz3mUN7PqDJiz6gAhAznaz 7JTWSqmrWTYBvED/TxY0vt5I8qgQ+QoKwg4fp+RcEqLidWg/DgvOEybLofOh7RVywacn kl/3tY+xb/bhJ+DJuitA0V4lVADn31e4eGlYbC/3ccYEYEb4vx7xi5Zpdc888udcYjVv wUBt6C0bQjjVi8umAzCgNDcq05PnF/j5+0DX8LizkbTkk4JdB52I7hJ+lvK5yxp2Dp8v zwf98/XKhHdwzcekKYY26LW0vKcQuOVhQtRdZwW84GEAY9wPfYuOKYxQkCRTDP2l8D42 zZXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723877120; x=1724481920; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CgTxrjJSN3UEpj2V6TaLEsH3nbDGy1R5SWod1sFWZ8c=; b=K3e8BxrOlNSLfMYjQjYkMpwTYyBeaYdyhn4TkrEdxzI6LLZmCbwDMyuegrY4WmiOeu v7MkuUL2evmkCgnEKQV1ImORbdQ3pQxuBSpN1JOixQ8jvLwk2/YTfTnKQkJAk83h//wJ 8XmKHMwK2wK4n4JNr9PwR3FnhDfu5TvMcZ3aK99RkyZfDSWdA2/PrrnhMlx6gl7ywEIn SK/sPXhUQwC+Kixo7gDy+s6hSEyOwHk9yGveeF17tlkXM1yzsp6SvWlhGKr3rGp0WkKg EvVqxAz7whRJ18UG82Mxknkf9gC26R2hWZurux96up9K6bxaEcR5JlxjW0cSCuybJ7zE z8Hg== X-Forwarded-Encrypted: i=1; AJvYcCVpA5xL4brha5JeFxXvNj9+wp3zt3e70mS/gCBh1I29TK8CtcdsDtVqZM16zneVOnigtakf0rJfa9GXByc9P8zgTQohEUdHEd9qEb4I X-Gm-Message-State: AOJu0YxmPE9qzDwhXtm8+UerGk2KCssdVjvkwJdYLLA3NmHudQfvCgSh YQii/USRLfPe3EK7MyZOvTLtqFNc30MexJHia9WELwSqbON5yc0EJzebCbVXLAjO9Y0frYmtlGl iiOTtrA== X-Google-Smtp-Source: AGHT+IERi9GSRMxTnykwrvZUawENrgJqpnxu9ZqGvySjlAvzwYvNnKXGoblaCJvhtARlkORt4uKlhsK9fAHn X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:78c9:5e58:734f:c59f]) (user=irogers job=sendgmr) by 2002:a25:83d0:0:b0:e11:584f:c2ca with SMTP id 3f1490d57ef6-e1180e8eb8emr212527276.6.1723877119735; Fri, 16 Aug 2024 23:45:19 -0700 (PDT) Date: Fri, 16 Aug 2024 23:44:37 -0700 In-Reply-To: <20240817064442.2152089-1-irogers@google.com> Message-Id: <20240817064442.2152089-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240817064442.2152089-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Subject: [PATCH v1 08/13] perf inject: Combine different mmap and mmap2 functions From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Masahiro Yamada , Arnd Bergmann , Jann Horn , Colin Ian King , Casey Chen , Athira Rajeev , Chaitanya S Prakash , James Clark , Ze Gao , Yang Jihong , Yunseong Kim , Weilin Wang , Dominique Martinet , Anne Macedo , Sun Haiyong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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: Ian Rogers --- tools/perf/builtin-inject.c | 199 ++++++++++++++---------------------- 1 file changed, 76 insertions(+), 123 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index 865d16ceead2..d99868953ff2 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -377,44 +377,6 @@ static int perf_event__repipe_sample(const struct perf= _tool *tool, return perf_event__repipe_synth(tool, event); } =20 -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 =3D 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 =3D container_of(tool, struct perf_inject, too= l); - u64 n =3D 0; - int ret; - - /* - * if jit marker, then inject jit mmaps and generate ELF images - */ - ret =3D 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 +=3D 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, co= nst char *filename, return dso; } =20 -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 =3D 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 =3D container_of(tool, struct perf_inject, too= l); =20 - err =3D perf_event__process_mmap2(tool, event, sample, machine); - perf_event__repipe(tool, event, sample, machine); +#ifdef HAVE_JITDUMP + if (inject->jit_mode) { + u64 n =3D 0; + int ret; =20 - 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 =3D 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 +=3D n; + return 0; + } + } +#endif + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { + struct dso *dso =3D findnew_dso(event->mmap.pid, event->mmap.tid, + event->mmap.filename, NULL, machine); =20 - dso =3D 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 ca= se. */ + int err =3D perf_event__process_mmap(tool, event, sample, machine); =20 - return err; + if (err) + return err; + } + return perf_event__repipe(tool, event, sample, machine); } =20 -#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 =3D container_of(tool, struct perf_inject, too= l); - u64 n =3D 0; - int ret; + struct dso *dso =3D NULL; =20 - /* - * if jit marker, then inject jit mmaps and generate ELF images - */ - ret =3D 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 +=3D n; - return 0; +#ifdef HAVE_JITDUMP + if (inject->jit_mode) { + u64 n =3D 0; + int ret; + + /* If jit marker, then inject jit mmaps and generate ELF images. */ + ret =3D 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 +=3D 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 =3D { - .maj =3D event->mmap2.maj, - .min =3D event->mmap2.min, - .ino =3D event->mmap2.ino, - .ino_generation =3D 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 =3D 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 =3D=3D BID_RWS__INJECT_HEADER_ALL) { + if (!(event->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID)) { + struct dso_id dso_id =3D { + .maj =3D event->mmap2.maj, + .min =3D event->mmap2.min, + .ino =3D event->mmap2.ino, + .ino_generation =3D event->mmap2.ino_generation, + }; + + dso =3D 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 ca= se. */ + int err =3D perf_event__process_mmap(tool, event, sample, machine); =20 - dso =3D 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); } =20 static int perf_event__repipe_fork(const struct perf_tool *tool, @@ -2032,10 +1988,7 @@ static int __cmd_inject(struct perf_inject *inject) =20 output_data_offset =3D perf_session__data_offset(session->evlist); =20 - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_ALL) { - inject->tool.mmap =3D perf_event__repipe_buildid_mmap; - inject->tool.mmap2 =3D perf_event__repipe_buildid_mmap2; - } else if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { + if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { inject->tool.sample =3D perf_event__inject_buildid; } else if (inject->sched_stat) { struct evsel *evsel; @@ -2430,8 +2383,8 @@ int cmd_inject(int argc, const char **argv) =20 #ifdef HAVE_JITDUMP if (inject.jit_mode) { - inject.tool.mmap2 =3D perf_event__jit_repipe_mmap2; - inject.tool.mmap =3D perf_event__jit_repipe_mmap; + inject.tool.mmap2 =3D perf_event__repipe_mmap2; + inject.tool.mmap =3D perf_event__repipe_mmap; inject.tool.ordering_requires_timestamps =3D true; /* * JIT MMAP injection injects all MMAP events in one go, so it --=20 2.46.0.184.g6999bdac58-goog