Commit 9a4e47ef authored by Leo Yan's avatar Leo Yan Committed by Namhyung Kim

perf parse-regs: Introduce a weak function arch__sample_reg_masks()

Every architecture can provide a register list for sampling. If an
architecture doesn't support register sampling, it won't define the data
structure 'sample_reg_masks'. Consequently, any code using this
structure must be protected by the macro 'HAVE_PERF_REGS_SUPPORT'.

This patch defines a weak function, arch__sample_reg_masks(), which will
be replaced by an architecture-defined function for returning the
architecture's register list. With this refactoring, the function always
exists, the condition checking for 'HAVE_PERF_REGS_SUPPORT' is not
needed anymore, so remove it.
Signed-off-by: default avatarLeo Yan <leo.yan@linux.dev>
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Will Deacon <will@kernel.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Ming Wang <wangming01@loongson.cn>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: linux-csky@vger.kernel.org
Cc: linux-riscv@lists.infradead.org
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240214113947.240957-4-leo.yan@linux.dev
parent ec87c99d
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../../util/perf_regs.h" #include "../../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -12,5 +12,7 @@ ...@@ -12,5 +12,7 @@
void arch__add_leaf_frame_record_opts(struct record_opts *opts) void arch__add_leaf_frame_record_opts(struct record_opts *opts)
{ {
const struct sample_reg *sample_reg_masks = arch__sample_reg_masks();
opts->sample_user_regs |= sample_reg_masks[PERF_REG_ARM64_LR].mask; opts->sample_user_regs |= sample_reg_masks[PERF_REG_ARM64_LR].mask;
} }
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define HWCAP_SVE (1 << 22) #define HWCAP_SVE (1 << 22)
#endif #endif
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG(x0, PERF_REG_ARM64_X0), SMPL_REG(x0, PERF_REG_ARM64_X0),
SMPL_REG(x1, PERF_REG_ARM64_X1), SMPL_REG(x1, PERF_REG_ARM64_X1),
SMPL_REG(x2, PERF_REG_ARM64_X2), SMPL_REG(x2, PERF_REG_ARM64_X2),
...@@ -175,3 +175,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -175,3 +175,8 @@ uint64_t arch__user_reg_mask(void)
} }
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../util/perf_regs.h" #include "../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../../util/perf_regs.h" #include "../../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../util/perf_regs.h" #include "../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#define PVR_POWER9 0x004E #define PVR_POWER9 0x004E
#define PVR_POWER10 0x0080 #define PVR_POWER10 0x0080
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG(r0, PERF_REG_POWERPC_R0), SMPL_REG(r0, PERF_REG_POWERPC_R0),
SMPL_REG(r1, PERF_REG_POWERPC_R1), SMPL_REG(r1, PERF_REG_POWERPC_R1),
SMPL_REG(r2, PERF_REG_POWERPC_R2), SMPL_REG(r2, PERF_REG_POWERPC_R2),
...@@ -232,3 +232,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -232,3 +232,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../util/perf_regs.h" #include "../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "perf_regs.h" #include "perf_regs.h"
#include "../../util/perf_regs.h" #include "../../util/perf_regs.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END SMPL_REG_END
}; };
...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void) ...@@ -15,3 +15,8 @@ uint64_t arch__user_reg_mask(void)
{ {
return PERF_REGS_MASK; return PERF_REGS_MASK;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "../../../util/pmu.h" #include "../../../util/pmu.h"
#include "../../../util/pmus.h" #include "../../../util/pmus.h"
const struct sample_reg sample_reg_masks[] = { static const struct sample_reg sample_reg_masks[] = {
SMPL_REG(AX, PERF_REG_X86_AX), SMPL_REG(AX, PERF_REG_X86_AX),
SMPL_REG(BX, PERF_REG_X86_BX), SMPL_REG(BX, PERF_REG_X86_BX),
SMPL_REG(CX, PERF_REG_X86_CX), SMPL_REG(CX, PERF_REG_X86_CX),
...@@ -276,6 +276,11 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op) ...@@ -276,6 +276,11 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
return SDT_ARG_VALID; return SDT_ARG_VALID;
} }
const struct sample_reg *arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
uint64_t arch__intr_reg_mask(void) uint64_t arch__intr_reg_mask(void)
{ {
struct perf_event_attr attr = { struct perf_event_attr attr = {
......
...@@ -46,22 +46,18 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr) ...@@ -46,22 +46,18 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
if (!strcmp(s, "?")) { if (!strcmp(s, "?")) {
fprintf(stderr, "available registers: "); fprintf(stderr, "available registers: ");
#ifdef HAVE_PERF_REGS_SUPPORT for (r = arch__sample_reg_masks(); r->name; r++) {
for (r = sample_reg_masks; r->name; r++) {
if (r->mask & mask) if (r->mask & mask)
fprintf(stderr, "%s ", r->name); fprintf(stderr, "%s ", r->name);
} }
#endif
fputc('\n', stderr); fputc('\n', stderr);
/* just printing available regs */ /* just printing available regs */
goto error; goto error;
} }
#ifdef HAVE_PERF_REGS_SUPPORT for (r = arch__sample_reg_masks(); r->name; r++) {
for (r = sample_reg_masks; r->name; r++) {
if ((r->mask & mask) && !strcasecmp(s, r->name)) if ((r->mask & mask) && !strcasecmp(s, r->name))
break; break;
} }
#endif
if (!r || !r->name) { if (!r || !r->name) {
ui__warning("Unknown register \"%s\", check man page or run \"perf record %s?\"\n", ui__warning("Unknown register \"%s\", check man page or run \"perf record %s?\"\n",
s, intr ? "-I" : "--user-regs="); s, intr ? "-I" : "--user-regs=");
......
...@@ -21,6 +21,15 @@ uint64_t __weak arch__user_reg_mask(void) ...@@ -21,6 +21,15 @@ uint64_t __weak arch__user_reg_mask(void)
return 0; return 0;
} }
static const struct sample_reg sample_reg_masks[] = {
SMPL_REG_END
};
const struct sample_reg * __weak arch__sample_reg_masks(void)
{
return sample_reg_masks;
}
const char *perf_reg_name(int id, const char *arch) const char *perf_reg_name(int id, const char *arch)
{ {
const char *reg_name = NULL; const char *reg_name = NULL;
......
...@@ -26,8 +26,7 @@ enum { ...@@ -26,8 +26,7 @@ enum {
int arch_sdt_arg_parse_op(char *old_op, char **new_op); int arch_sdt_arg_parse_op(char *old_op, char **new_op);
uint64_t arch__intr_reg_mask(void); uint64_t arch__intr_reg_mask(void);
uint64_t arch__user_reg_mask(void); uint64_t arch__user_reg_mask(void);
const struct sample_reg *arch__sample_reg_masks(void);
extern const struct sample_reg sample_reg_masks[];
const char *perf_reg_name(int id, const char *arch); const char *perf_reg_name(int id, const char *arch);
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id); int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
......
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