Skip to content

Commit

Permalink
perf parse-regs: Add generic support for arch__intr/user_reg_mask()
Browse files Browse the repository at this point in the history
There may be different register mask for use with intr or user on some
platforms, e.g. Icelake.

Add weak functions arch__intr_reg_mask() and arch__user_reg_mask() to
return intr and user register mask respectively.

Check mask before printing or comparing the register name.

Generic code always return PERF_REGS_MASK. No functional change.

Suggested-by: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: Kan Liang <[email protected]>
Tested-by: Ravi Bangoria <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Jiri Olsa <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
Kan Liang authored and acmel committed May 16, 2019
1 parent aeea906 commit af785e7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/perf/util/parse-regs-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
const struct sample_reg *r;
char *s, *os = NULL, *p;
int ret = -1;
uint64_t mask;

if (unset)
return 0;
Expand All @@ -22,6 +23,11 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
if (*mode)
return -1;

if (intr)
mask = arch__intr_reg_mask();
else
mask = arch__user_reg_mask();

/* str may be NULL in case no arg is passed to -I */
if (str) {
/* because str is read-only */
Expand All @@ -37,14 +43,15 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
if (!strcmp(s, "?")) {
fprintf(stderr, "available registers: ");
for (r = sample_reg_masks; r->name; r++) {
fprintf(stderr, "%s ", r->name);
if (r->mask & mask)
fprintf(stderr, "%s ", r->name);
}
fputc('\n', stderr);
/* just printing available regs */
return -1;
}
for (r = sample_reg_masks; r->name; r++) {
if (!strcasecmp(s, r->name))
if ((r->mask & mask) && !strcasecmp(s, r->name))
break;
}
if (!r->name) {
Expand All @@ -65,7 +72,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)

/* default to all possible regs */
if (*mode == 0)
*mode = PERF_REGS_MASK;
*mode = mask;
error:
free(os);
return ret;
Expand Down
10 changes: 10 additions & 0 deletions tools/perf/util/perf_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
return SDT_ARG_SKIP;
}

uint64_t __weak arch__intr_reg_mask(void)
{
return PERF_REGS_MASK;
}

uint64_t __weak arch__user_reg_mask(void)
{
return PERF_REGS_MASK;
}

#ifdef HAVE_PERF_REGS_SUPPORT
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
{
Expand Down
2 changes: 2 additions & 0 deletions tools/perf/util/perf_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ 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);

#ifdef HAVE_PERF_REGS_SUPPORT
#include <perf_regs.h>
Expand Down

0 comments on commit af785e7

Please sign in to comment.