Skip to content

Commit 2be0043

Browse files
James-A-Clarkacmel
authored andcommitted
perf tools arm64: Add support for VG register
Add the name of the VG register so it can be used in --user-regs The event will fail to open if the register is requested but not available so only add it to the mask if the kernel supports sve and also if it supports that specific register. Committer notes: Add conditional definition of HWCAP_SVE, as suggested by Leo Yan, to build on older systems where this is not available in the system headers. Reviewed-by: Leo Yan <leo.yan@linaro.org> Signed-off-by: James Clark <james.clark@arm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: German Gomez <german.gomez@arm.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Mark Brown <broonie@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20220525154114.718321-6-james.clark@arm.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent d511578 commit 2be0043

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

tools/perf/arch/arm64/util/perf_regs.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22
#include <errno.h>
33
#include <regex.h>
44
#include <string.h>
5+
#include <sys/auxv.h>
56
#include <linux/kernel.h>
67
#include <linux/zalloc.h>
78

9+
#include "../../../perf-sys.h"
810
#include "../../../util/debug.h"
911
#include "../../../util/event.h"
1012
#include "../../../util/perf_regs.h"
1113

14+
#ifndef HWCAP_SVE
15+
#define HWCAP_SVE (1 << 22)
16+
#endif
17+
1218
const struct sample_reg sample_reg_masks[] = {
1319
SMPL_REG(x0, PERF_REG_ARM64_X0),
1420
SMPL_REG(x1, PERF_REG_ARM64_X1),
@@ -43,6 +49,7 @@ const struct sample_reg sample_reg_masks[] = {
4349
SMPL_REG(lr, PERF_REG_ARM64_LR),
4450
SMPL_REG(sp, PERF_REG_ARM64_SP),
4551
SMPL_REG(pc, PERF_REG_ARM64_PC),
52+
SMPL_REG(vg, PERF_REG_ARM64_VG),
4653
SMPL_REG_END
4754
};
4855

@@ -131,3 +138,34 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
131138

132139
return SDT_ARG_VALID;
133140
}
141+
142+
uint64_t arch__user_reg_mask(void)
143+
{
144+
struct perf_event_attr attr = {
145+
.type = PERF_TYPE_HARDWARE,
146+
.config = PERF_COUNT_HW_CPU_CYCLES,
147+
.sample_type = PERF_SAMPLE_REGS_USER,
148+
.disabled = 1,
149+
.exclude_kernel = 1,
150+
.sample_period = 1,
151+
.sample_regs_user = PERF_REGS_MASK
152+
};
153+
int fd;
154+
155+
if (getauxval(AT_HWCAP) & HWCAP_SVE)
156+
attr.sample_regs_user |= SMPL_REG_MASK(PERF_REG_ARM64_VG);
157+
158+
/*
159+
* Check if the pmu supports perf extended regs, before
160+
* returning the register mask to sample.
161+
*/
162+
if (attr.sample_regs_user != PERF_REGS_MASK) {
163+
event_attr_init(&attr);
164+
fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
165+
if (fd != -1) {
166+
close(fd);
167+
return attr.sample_regs_user;
168+
}
169+
}
170+
return PERF_REGS_MASK;
171+
}

tools/perf/util/perf_regs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static const char *__perf_reg_name_arm64(int id)
103103
return "lr";
104104
case PERF_REG_ARM64_PC:
105105
return "pc";
106+
case PERF_REG_ARM64_VG:
107+
return "vg";
106108
default:
107109
return NULL;
108110
}

0 commit comments

Comments
 (0)