Skip to contentSkip to conversation

perf regs: Refactor use of arch__sample_reg_masks to perf_reg_name

PATCH Superseded Ian Rogers 1 participant 1 message Jan 20

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf regs: Refactor use of arch__sample_reg_masks to perf_reg_name

arch__sample_reg_masks isn't supported on ARM(32), csky, loongarch, MIPS, RISC-V and s390. The table returned by the function just has the name of a register paired with the corresponding sample_regs_user mask value. For a given perf register we can compute the name with perf_reg_name and the mask is just 1 left-shifted by the perf register number. Change __parse_regs to use this method for finding registers rather than arch__sample_reg_masks, thereby adding __parse_regs support for ARM(32), csky, loongarch, MIPS, RISC-V and s390. As arch__sample_reg_masks is then unused, remove the now unneeded declarations.

---
The idea for this patch came up in conversation with Dapeng Mi to avoid additional functions and tables for x86 APX support:
https://lore.kernel.org/lkml/CAP-5=fWOsvAXuu8qx0tk9q8j8BoXPMJB3Gxto+iu6wf06i4cVA@mail.gmail.com/

The patch is on top of the dwfl clean up patches that switch perf register functions to using e_machine as an argument rather than the arch string, this means that EM_HOST can be used with perf_reg_name:
https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/arch/arm/util/perf_regs.c          |   9 --
 tools/perf/arch/arm64/util/machine.c          |  14 +--
 tools/perf/arch/arm64/util/perf_regs.c        |  45 +------
 tools/perf/arch/csky/util/perf_regs.c         |   9 --
 tools/perf/arch/loongarch/util/perf_regs.c    |   9 --
 tools/perf/arch/mips/util/perf_regs.c         |   9 --
 tools/perf/arch/powerpc/util/perf_regs.c      |  68 -----------
 tools/perf/arch/riscv/util/perf_regs.c        |   9 --
 tools/perf/arch/s390/util/perf_regs.c         |   9 --
 tools/perf/arch/x86/util/perf_regs.c          |  47 --------
 .../util/arm64-frame-pointer-unwind-support.c |   3 +-
 tools/perf/util/parse-regs-options.c          | 114 +++++++++++-------
 tools/perf/util/perf_regs.c                   |   9 --
 tools/perf/util/perf_regs.h                   |  12 --
 14 files changed, 79 insertions(+), 287 deletions(-)
tools/perf/arch/arm/util/perf_regs.c +0 -9
index f94a0210c7b7..03a5bc0cf64c 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/arm64/util/machine.c +4 -10
index aab1cc2bc283..80fb13c958d9 100644
@@ -1,18 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
 
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include "debug.h"
-#include "symbol.h"
-#include "callchain.h"
+#include "callchain.h" // prototype of arch__add_leaf_frame_record_opts
 #include "perf_regs.h"
 #include "record.h"
-#include "util/perf_regs.h"
+
+#define SMPL_REG_MASK(b) (1ULL << (b))
 
 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 |= SMPL_REG_MASK(PERF_REG_ARM64_LR);
 }
tools/perf/arch/arm64/util/perf_regs.c +2 -43

58 lines not on this page · raw message

tools/perf/arch/csky/util/perf_regs.c +0 -9
index 6b1665f41180..2cf7a54106e0 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/loongarch/util/perf_regs.c +0 -9
index f94a0210c7b7..03a5bc0cf64c 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/mips/util/perf_regs.c +0 -9
index 6b1665f41180..2cf7a54106e0 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/powerpc/util/perf_regs.c +0 -68

77 lines not on this page · raw message

tools/perf/arch/riscv/util/perf_regs.c +0 -9
index 6b1665f41180..2cf7a54106e0 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/s390/util/perf_regs.c +0 -9
index 6b1665f41180..2cf7a54106e0 100644
@@ -2,10 +2,6 @@
 #include "perf_regs.h"
 #include "../../util/perf_regs.h"
 
-static const struct sample_reg sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 uint64_t arch__intr_reg_mask(void)
 {
 	return PERF_REGS_MASK;
@@ -15,8 +11,3 @@ uint64_t arch__user_reg_mask(void)
 {
 	return PERF_REGS_MASK;
 }
-
-const struct sample_reg *arch__sample_reg_masks(void)
-{
-	return sample_reg_masks;
-}
tools/perf/arch/x86/util/perf_regs.c +0 -47

59 lines not on this page · raw message

tools/perf/util/arm64-frame-pointer-unwind-support.c +2 -1
index 958afe8b821e..858ce2b01812 100644
@@ -2,7 +2,6 @@
 #include "arm64-frame-pointer-unwind-support.h"
 #include "callchain.h"
 #include "event.h"
-#include "perf_regs.h" // SMPL_REG_MASK
 #include "unwind.h"
 #include <string.h>
 
@@ -15,6 +14,8 @@ struct entries {
 	size_t length;
 };
 
+#define SMPL_REG_MASK(b) (1ULL << (b))
+
 static bool get_leaf_frame_caller_enabled(struct perf_sample *sample)
 {
 	struct regs_dump *regs;
tools/perf/util/parse-regs-options.c +71 -43

136 lines not on this page · raw message

tools/perf/util/perf_regs.c +0 -9
index b58d59b84fb1..ec602da1aeb6 100644
@@ -22,15 +22,6 @@ uint64_t __weak arch__user_reg_mask(void)
 	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, uint16_t e_machine)
 {
 	const char *reg_name = NULL;
tools/perf/util/perf_regs.h +0 -12
index 7bfc6a34c02b..2c2a8de6912d 100644
@@ -7,17 +7,6 @@
 
 struct regs_dump;
 
-struct sample_reg {
-	const char *name;
-	uint64_t mask;
-};
-
-#define SMPL_REG_MASK(b) (1ULL << (b))
-#define SMPL_REG(n, b) { .name = #n, .mask = SMPL_REG_MASK(b) }
-#define SMPL_REG2_MASK(b) (3ULL << (b))
-#define SMPL_REG2(n, b) { .name = #n, .mask = SMPL_REG2_MASK(b) }
-#define SMPL_REG_END { .name = NULL }
-
 enum {
 	SDT_ARG_VALID = 0,
 	SDT_ARG_SKIP,
@@ -26,7 +15,6 @@ 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);
-const struct sample_reg *arch__sample_reg_masks(void);
 
 const char *perf_reg_name(int id, uint16_t e_machine);
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
Signature · 1 line
2.52.0.457.g6b5491de43-goog