From nobody Tue Nov 26 03:52:19 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 53F3D1C3F3C for ; Tue, 22 Oct 2024 17:31:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618273; cv=none; b=Lhme8MHgsJ6sucaGjGVK5RzH4ZolJEdQDdOfcy1Gt6YPcRqmvWnHmstD+3snQI+F9T0CJF2ttVVGd+olaUFmWeCi7ILC1YdkOCaqHKX6C9NAoLa9KMBM32tElaQghrl7/uaBn7iZpld0sRwJezvetVFBVsV8NHT1WnlnVOoados= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729618273; c=relaxed/simple; bh=/crqTxCEFIJ8zM+Mn3jruBiNWQfecVziDkUeZ96I01M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JWoB4dWdQn8IWQPk0/ilgWxuqVs6TmbvbC2DpigQh7VnDMzNGJCGt9lKcoM2baGannqKPUUFM1WYIFfD7TSUOwwizfqFhB2WLEbYSbpfEeuq9WcRO08o6ZFokvPZPR6uTaXRGWopRzoqnOaBSgph1N1J1qWBeYiPcaQj5/De8+I= 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=X/xM0Zz2; arc=none smtp.client-ip=209.85.219.202 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="X/xM0Zz2" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e290b8b69f8so9841980276.2 for ; Tue, 22 Oct 2024 10:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1729618271; x=1730223071; 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=fhvpBUz7ScY2P9mICu9O6uJW+157JnJHgqfTK+JmiWc=; b=X/xM0Zz20LSfhjyoT1Mm5HLnhGBBsrMhAmY6xgCdSOjmmDRpuK4gTWQWmSr7frF1n4 /Y4uOCnDW2riR+yqmcrM7Ali/48Zi2k6wyQf6wWePP0Xw93DnSxcDuP3qhWANc0bXMB3 oCOY95Xv7ClUacw4Kw1CJiPe7yne8Nh70cG1fIjv/qTRpTCZNdHMb7LX2+Lu3Dt6lU2Z uohbBeNooOygcq1/zczIVe44uyCvhBFOONoCXuiidLaXZBzzCN2Ycw8iv7WBGfISxAuW FoamERyxX277pFchhVjDk5xgjF947dUlIbZtIERfMNDi7OPLTiall0AuS9FEhK/1Y4nA 1/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729618271; x=1730223071; 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=fhvpBUz7ScY2P9mICu9O6uJW+157JnJHgqfTK+JmiWc=; b=wuYBjlzLNrJl3CJ5tHt9TXFMcpcAd/cGqFvE7CwJrnB5w6eGtUBLHiTztNmxiVV+YA pFa7BqrbutC/Gs4j8JFG63bTecSeKxiPOkZvXWEclaryQkLi/Rb1LNmWIxKTOznRfVPL JnNOud38P5V1XDvcgVqJoOGFlkcjeIcz5mEZMWCPJjwD7ukUb97Pd+ek8BH8X/780ruV gFrA8BYMF77/jYNZPhvCPcdaxUKfez/wD/XlqdmgtEJuJ9q02QB91MUDlMqU70758uQL rI7/MjenDVcCbqqk0Z1kf71xfQtf88MrIvWmkPKY48XzLoIVzZKnTCBh2+aJZMHRYm1H uz7Q== X-Forwarded-Encrypted: i=1; AJvYcCXpc7DfXGHlfpP7GqMi7hCzE1H4LBdot9/HtDOmtyMgT/sJ085KmdAJM3yL9+4v6azvFkQye6xRD4X/994=@vger.kernel.org X-Gm-Message-State: AOJu0Yzkr6Bq5R8Yx3EA+3F1hkbFKoU8UH3oLcKowv0indBooILEKbQn gZLrBBh8GUbLU8NUtqJFONgB9K/oeJWBu2KSdwL74Pn+nDtkfCDgrO6QhXpv27udT7OkynF1eYR SyrM/Kw== X-Google-Smtp-Source: AGHT+IHDnq+abCllals/kqnWsGmCM/mFjJoZMc4Oom4dfZXS3a6TCKQxUeC1YZSC/YAiejk1FxZfEJUjmYXh X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:57ba:88e0:aaf6:282]) (user=irogers job=sendgmr) by 2002:a25:d8c4:0:b0:e2b:d0e9:130f with SMTP id 3f1490d57ef6-e2bd0e914admr8223276.0.1729618271277; Tue, 22 Oct 2024 10:31:11 -0700 (PDT) Date: Tue, 22 Oct 2024 10:30:07 -0700 In-Reply-To: <20241022173015.437550-1-irogers@google.com> Message-Id: <20241022173015.437550-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241022173015.437550-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Subject: [PATCH v3 09/16] perf script: Move script_fetch_insn to trace-event-scripting.c 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 , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add native_arch as a parameter to script_fetch_insn rather than relying on the builtin-script value that won't be initialized for the dlfilter and python Context use cases. Assume both of those cases are running natively. Switch the weak arch_fetch_insn to being guarded by ifdefs as weak functions are outside of the C specification. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 15 +-------------- .../scripts/python/Perf-Trace-Util/Context.c | 2 +- tools/perf/util/dlfilter.c | 3 ++- tools/perf/util/python.c | 6 ------ tools/perf/util/trace-event-scripting.c | 16 ++++++++++++++++ tools/perf/util/trace-event.h | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index b838470657d4..63a00dad02c6 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1586,19 +1586,6 @@ static int perf_sample__fprintf_callindent(struct pe= rf_sample *sample, return len + dlen; } =20 -__weak void arch_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - -void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine) -{ - if (sample->insn_len =3D=3D 0 && native_arch) - arch_fetch_insn(sample, thread, machine); -} - static int perf_sample__fprintf_insn(struct perf_sample *sample, struct evsel *evsel, struct perf_event_attr *attr, @@ -1608,7 +1595,7 @@ static int perf_sample__fprintf_insn(struct perf_samp= le *sample, { int printed =3D 0; =20 - script_fetch_insn(sample, thread, machine); + script_fetch_insn(sample, thread, machine, native_arch); =20 if (PRINT_FIELD(INSNLEN)) printed +=3D fprintf(fp, " ilen: %d", sample->insn_len); diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/pe= rf/scripts/python/Perf-Trace-Util/Context.c index d742daaa5d5a..60dcfe56d4d9 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/Context.c +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c @@ -93,7 +93,7 @@ static PyObject *perf_sample_insn(PyObject *obj, PyObject= *args) if (c->sample->ip && !c->sample->insn_len && thread__maps(c->al->thread))= { struct machine *machine =3D maps__machine(thread__maps(c->al->thread)); =20 - script_fetch_insn(c->sample, c->al->thread, machine); + script_fetch_insn(c->sample, c->al->thread, machine, /*native_arch=3D*/t= rue); } if (!c->sample->insn_len) Py_RETURN_NONE; /* N.B. This is a return statement */ diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index 7d180bdaedbc..ddacef881af2 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -234,7 +234,8 @@ static const __u8 *dlfilter__insn(void *ctx, __u32 *len) struct machine *machine =3D maps__machine(thread__maps(al->thread)); =20 if (machine) - script_fetch_insn(d->sample, al->thread, machine); + script_fetch_insn(d->sample, al->thread, machine, + /*native_arch=3D*/true); } } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 3d938fe2de6a..22edadd64e5f 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1317,12 +1317,6 @@ struct kwork_work *perf_kwork_add_work(struct perf_k= work *kwork __maybe_unused, return NULL; } =20 -void script_fetch_insn(struct perf_sample *sample __maybe_unused, - struct thread *thread __maybe_unused, - struct machine *machine __maybe_unused) -{ -} - int perf_sample__sprintf_flags(u32 flags __maybe_unused, char *str __maybe= _unused, size_t sz __maybe_unused) { diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index ad62d8e5a368..543e78b17e5f 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -13,6 +13,7 @@ #include #endif =20 +#include "archinsn.h" #include "debug.h" #include "trace-event.h" #include "evsel.h" @@ -269,3 +270,18 @@ void setup_perl_scripting(void) } #endif #endif + +#if !defined(__i386__) && !defined(__x86_64__) +void arch_fetch_insn(struct perf_sample *sample __maybe_unused, + struct thread *thread __maybe_unused, + struct machine *machine __maybe_unused) +{ +} +#endif + +void script_fetch_insn(struct perf_sample *sample, struct thread *thread, + struct machine *machine, bool native_arch) +{ + if (sample->insn_len =3D=3D 0 && native_arch) + arch_fetch_insn(sample, thread, machine); +} diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 81fceaf297ba..e0bb42e6509e 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -120,7 +120,7 @@ struct scripting_ops *script_spec__lookup(const char *s= pec); int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, - struct machine *machine); + struct machine *machine, bool native_arch); =20 void setup_perl_scripting(void); void setup_python_scripting(void); --=20 2.47.0.163.g1226f6d8fa-goog