hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/tools/perf/util/parse-regs-options.c
....@@ -1,17 +1,22 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-#include "perf.h"
3
-#include "util/util.h"
2
+#include <stdbool.h>
3
+#include <stdlib.h>
4
+#include <stdint.h>
5
+#include <string.h>
6
+#include <stdio.h>
47 #include "util/debug.h"
58 #include <subcmd/parse-options.h>
9
+#include "util/perf_regs.h"
610 #include "util/parse-regs-options.h"
711
8
-int
9
-parse_regs(const struct option *opt, const char *str, int unset)
12
+static int
13
+__parse_regs(const struct option *opt, const char *str, int unset, bool intr)
1014 {
1115 uint64_t *mode = (uint64_t *)opt->value;
12
- const struct sample_reg *r;
16
+ const struct sample_reg *r = NULL;
1317 char *s, *os = NULL, *p;
1418 int ret = -1;
19
+ uint64_t mask;
1520
1621 if (unset)
1722 return 0;
....@@ -21,6 +26,11 @@
2126 */
2227 if (*mode)
2328 return -1;
29
+
30
+ if (intr)
31
+ mask = arch__intr_reg_mask();
32
+ else
33
+ mask = arch__user_reg_mask();
2434
2535 /* str may be NULL in case no arg is passed to -I */
2636 if (str) {
....@@ -36,20 +46,25 @@
3646
3747 if (!strcmp(s, "?")) {
3848 fprintf(stderr, "available registers: ");
49
+#ifdef HAVE_PERF_REGS_SUPPORT
3950 for (r = sample_reg_masks; r->name; r++) {
40
- fprintf(stderr, "%s ", r->name);
51
+ if (r->mask & mask)
52
+ fprintf(stderr, "%s ", r->name);
4153 }
54
+#endif
4255 fputc('\n', stderr);
4356 /* just printing available regs */
4457 goto error;
4558 }
59
+#ifdef HAVE_PERF_REGS_SUPPORT
4660 for (r = sample_reg_masks; r->name; r++) {
47
- if (!strcasecmp(s, r->name))
61
+ if ((r->mask & mask) && !strcasecmp(s, r->name))
4862 break;
4963 }
50
- if (!r->name) {
51
- ui__warning("unknown register %s,"
52
- " check man page\n", s);
64
+#endif
65
+ if (!r || !r->name) {
66
+ ui__warning("Unknown register \"%s\", check man page or run \"perf record %s?\"\n",
67
+ s, intr ? "-I" : "--user-regs=");
5368 goto error;
5469 }
5570
....@@ -65,8 +80,20 @@
6580
6681 /* default to all possible regs */
6782 if (*mode == 0)
68
- *mode = PERF_REGS_MASK;
83
+ *mode = mask;
6984 error:
7085 free(os);
7186 return ret;
7287 }
88
+
89
+int
90
+parse_user_regs(const struct option *opt, const char *str, int unset)
91
+{
92
+ return __parse_regs(opt, str, unset, false);
93
+}
94
+
95
+int
96
+parse_intr_regs(const struct option *opt, const char *str, int unset)
97
+{
98
+ return __parse_regs(opt, str, unset, true);
99
+}