From: Leo Yan <leo.yan@linaro.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
John Garry <john.g.garry@oracle.com>,
Will Deacon <will@kernel.org>, James Clark <james.clark@arm.com>,
Mike Leach <mike.leach@linaro.org>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Guo Ren <guoren@kernel.org>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>, Eric Lin <eric.lin@sifive.com>,
Kan Liang <kan.liang@linux.intel.com>,
Qi Liu <liuqi115@huawei.com>, Sandipan Das <sandipan.das@amd.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-perf-users@vger.kernel.org, linux-csky@vger.kernel.org,
linux-riscv@lists.infradead.org
Cc: Leo Yan <leo.yan@linaro.org>
Subject: [PATCH v1 2/5] perf parse-regs: Introduce functions arch__reg_{ip|sp}()
Date: Sat, 20 May 2023 10:55:34 +0800 [thread overview]
Message-ID: <20230520025537.1811986-3-leo.yan@linaro.org> (raw)
In-Reply-To: <20230520025537.1811986-1-leo.yan@linaro.org>
Ideally, we want util/perf_regs.c to be general enough and doesn't bind
with specific architecture.
But since util/perf_regs.c uses the macros PERF_REG_IP and PERF_REG_SP
which are defined by architecture, thus util/perf_regs.c is dependent on
architecture header (see util/perf_regs.h includes "<perf_regs.h>", here
perf_regs.h is architecture specific header).
As a step to generalize util/perf_regs.c, this commit introduces weak
functions arch__reg_ip() and arch__reg_sp() and every architecture can
define their own functions; thus, util/perf_regs.c doesn't need to use
PERF_REG_IP and PERF_REG_SP anymore.
This is a preparation to get rid of architecture specific header from
util/perf_regs.h.
Signed-off-by: Leo Yan <leo.yan@linaro.org>
---
tools/perf/arch/arm/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/arm64/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/csky/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/mips/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/powerpc/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/riscv/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/s390/util/perf_regs.c | 10 ++++++++++
tools/perf/arch/x86/util/perf_regs.c | 10 ++++++++++
tools/perf/util/perf_regs.c | 10 ++++++++++
tools/perf/util/perf_regs.h | 4 +++-
tools/perf/util/unwind-libdw.c | 2 +-
tools/perf/util/unwind.h | 4 ++--
12 files changed, 96 insertions(+), 4 deletions(-)
diff --git a/tools/perf/arch/arm/util/perf_regs.c b/tools/perf/arch/arm/util/perf_regs.c
index 2833e101a7c6..37aa3a2091bd 100644
--- a/tools/perf/arch/arm/util/perf_regs.c
+++ b/tools/perf/arch/arm/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_ARM_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_ARM_SP;
+}
diff --git a/tools/perf/arch/arm64/util/perf_regs.c b/tools/perf/arch/arm64/util/perf_regs.c
index 006692c9b040..dbe7f00b222b 100644
--- a/tools/perf/arch/arm64/util/perf_regs.c
+++ b/tools/perf/arch/arm64/util/perf_regs.c
@@ -169,3 +169,13 @@ uint64_t arch__user_reg_mask(void)
}
return PERF_REGS_MASK;
}
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_ARM64_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_ARM64_SP;
+}
diff --git a/tools/perf/arch/csky/util/perf_regs.c b/tools/perf/arch/csky/util/perf_regs.c
index 2864e2e3776d..d230d7e640fd 100644
--- a/tools/perf/arch/csky/util/perf_regs.c
+++ b/tools/perf/arch/csky/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_CSKY_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_CSKY_SP;
+}
diff --git a/tools/perf/arch/mips/util/perf_regs.c b/tools/perf/arch/mips/util/perf_regs.c
index 2864e2e3776d..64882ebc9287 100644
--- a/tools/perf/arch/mips/util/perf_regs.c
+++ b/tools/perf/arch/mips/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_MIPS_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_MIPS_R29;
+}
diff --git a/tools/perf/arch/powerpc/util/perf_regs.c b/tools/perf/arch/powerpc/util/perf_regs.c
index 8d07a78e742a..c84cd79986a8 100644
--- a/tools/perf/arch/powerpc/util/perf_regs.c
+++ b/tools/perf/arch/powerpc/util/perf_regs.c
@@ -226,3 +226,13 @@ uint64_t arch__intr_reg_mask(void)
}
return mask;
}
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_POWERPC_NIP;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_POWERPC_R1;
+}
diff --git a/tools/perf/arch/riscv/util/perf_regs.c b/tools/perf/arch/riscv/util/perf_regs.c
index 2864e2e3776d..13bbddd139d0 100644
--- a/tools/perf/arch/riscv/util/perf_regs.c
+++ b/tools/perf/arch/riscv/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_RISCV_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_RISCV_SP;
+}
diff --git a/tools/perf/arch/s390/util/perf_regs.c b/tools/perf/arch/s390/util/perf_regs.c
index 2864e2e3776d..9b2297471090 100644
--- a/tools/perf/arch/s390/util/perf_regs.c
+++ b/tools/perf/arch/s390/util/perf_regs.c
@@ -4,3 +4,13 @@
const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_S390_PC;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_S390_R15;
+}
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c
index 0ed177991ad0..c752a6e9cba6 100644
--- a/tools/perf/arch/x86/util/perf_regs.c
+++ b/tools/perf/arch/x86/util/perf_regs.c
@@ -312,3 +312,13 @@ uint64_t arch__intr_reg_mask(void)
return PERF_REGS_MASK;
}
+
+uint64_t arch__reg_ip(void)
+{
+ return PERF_REG_X86_IP;
+}
+
+uint64_t arch__reg_sp(void)
+{
+ return PERF_REG_X86_SP;
+}
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index 8720ec6cf147..334c9a2b785d 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -20,6 +20,16 @@ uint64_t __weak arch__user_reg_mask(void)
return PERF_REGS_MASK;
}
+uint64_t __weak arch__reg_ip(void)
+{
+ return 0;
+}
+
+uint64_t __weak arch__reg_sp(void)
+{
+ return 0;
+}
+
#ifdef HAVE_PERF_REGS_SUPPORT
const char *perf_reg_name(int id, const char *arch)
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index ab4ec3f2a170..0a1460aaad37 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -26,13 +26,15 @@ enum {
int arch_sdt_arg_parse_op(char *old_op, char **new_op);
uint64_t arch__intr_reg_mask(void);
uint64_t arch__user_reg_mask(void);
+uint64_t arch__reg_ip(void);
+uint64_t arch__reg_sp(void);
#ifdef HAVE_PERF_REGS_SUPPORT
extern const struct sample_reg sample_reg_masks[];
#include <perf_regs.h>
-#define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
+#define DWARF_MINIMAL_REGS ((1ULL << arch__reg_ip()) | (1ULL << arch__reg_sp()))
const char *perf_reg_name(int id, const char *arch);
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
diff --git a/tools/perf/util/unwind-libdw.c b/tools/perf/util/unwind-libdw.c
index bdccfc511b7e..f308f2ea512b 100644
--- a/tools/perf/util/unwind-libdw.c
+++ b/tools/perf/util/unwind-libdw.c
@@ -252,7 +252,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
if (!ui->dwfl)
goto out;
- err = perf_reg_value(&ip, &data->user_regs, PERF_REG_IP);
+ err = perf_reg_value(&ip, &data->user_regs, arch__reg_ip());
if (err)
goto out;
diff --git a/tools/perf/util/unwind.h b/tools/perf/util/unwind.h
index b2a03fa5289b..0a98ea9d8c94 100644
--- a/tools/perf/util/unwind.h
+++ b/tools/perf/util/unwind.h
@@ -43,11 +43,11 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
#endif
#ifndef LIBUNWIND__ARCH_REG_SP
-#define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
+#define LIBUNWIND__ARCH_REG_SP arch__reg_sp()
#endif
#ifndef LIBUNWIND__ARCH_REG_IP
-#define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
+#define LIBUNWIND__ARCH_REG_IP arch__reg_ip()
#endif
int LIBUNWIND__ARCH_REG_ID(int regnum);
--
2.39.2
next prev parent reply other threads:[~2023-05-20 2:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-20 2:55 [PATCH v1 0/5] perf parse-regs: Refactor arch related functions Leo Yan
2023-05-20 2:55 ` [PATCH v1 1/5] perf parse-regs: Refactor arch register parsing functions Leo Yan
2023-05-20 2:55 ` Leo Yan [this message]
2023-05-22 8:57 ` [PATCH v1 2/5] perf parse-regs: Introduce functions arch__reg_{ip|sp}() James Clark
2023-05-22 12:07 ` Leo Yan
2023-05-22 16:34 ` James Clark
2023-05-22 18:08 ` Ian Rogers
2023-05-23 6:49 ` Leo Yan
2023-05-20 2:55 ` [PATCH v1 3/5] perf parse-regs: Remove unused macros PERF_REG_{IP|SP} Leo Yan
2023-05-20 2:55 ` [PATCH v1 4/5] perf parse-regs: Remove PERF_REGS_{MAX|MASK} from common code Leo Yan
2023-05-20 2:55 ` [PATCH v1 5/5] perf parse-regs: Move out arch specific header from util/perf_regs.h Leo Yan
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=20230520025537.1811986-3-leo.yan@linaro.org \
--to=leo.yan@linaro.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=aou@eecs.berkeley.edu \
--cc=eric.lin@sifive.com \
--cc=guoren@kernel.org \
--cc=irogers@google.com \
--cc=james.clark@arm.com \
--cc=john.g.garry@oracle.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=liuqi115@huawei.com \
--cc=mark.rutland@arm.com \
--cc=mike.leach@linaro.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=sandipan.das@amd.com \
--cc=will@kernel.org \
/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).