Linux Audio

Check our new training course

Linux BSP development engineering services

Need help to port Linux and bootloaders to your hardware?
Loading...
v4.17
 1// SPDX-License-Identifier: GPL-2.0
 2#include "perf.h"
 3#include "util/util.h"
 
 
 
 4#include "util/debug.h"
 5#include <subcmd/parse-options.h>
 
 6#include "util/parse-regs-options.h"
 7
 8int
 9parse_regs(const struct option *opt, const char *str, int unset)
10{
11	uint64_t *mode = (uint64_t *)opt->value;
12	const struct sample_reg *r;
13	char *s, *os = NULL, *p;
14	int ret = -1;
 
15
16	if (unset)
17		return 0;
18
19	/*
20	 * cannot set it twice
21	 */
22	if (*mode)
23		return -1;
24
 
 
 
 
 
25	/* str may be NULL in case no arg is passed to -I */
26	if (str) {
27		/* because str is read-only */
28		s = os = strdup(str);
29		if (!s)
30			return -1;
31
32		for (;;) {
33			p = strchr(s, ',');
34			if (p)
35				*p = '\0';
36
37			if (!strcmp(s, "?")) {
38				fprintf(stderr, "available registers: ");
 
39				for (r = sample_reg_masks; r->name; r++) {
40					fprintf(stderr, "%s ", r->name);
 
41				}
 
42				fputc('\n', stderr);
43				/* just printing available regs */
44				return -1;
45			}
 
46			for (r = sample_reg_masks; r->name; r++) {
47				if (!strcasecmp(s, r->name))
48					break;
49			}
50			if (!r->name) {
51				ui__warning("unknown register %s,"
52					    " check man page\n", s);
 
53				goto error;
54			}
55
56			*mode |= r->mask;
57
58			if (!p)
59				break;
60
61			s = p + 1;
62		}
63	}
64	ret = 0;
65
66	/* default to all possible regs */
67	if (*mode == 0)
68		*mode = PERF_REGS_MASK;
69error:
70	free(os);
71	return ret;
 
 
 
 
 
 
 
 
 
 
 
 
72}
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2#include <stdbool.h>
 3#include <stdlib.h>
 4#include <stdint.h>
 5#include <string.h>
 6#include <stdio.h>
 7#include "util/debug.h"
 8#include <subcmd/parse-options.h>
 9#include "util/perf_regs.h"
10#include "util/parse-regs-options.h"
11
12static int
13__parse_regs(const struct option *opt, const char *str, int unset, bool intr)
14{
15	uint64_t *mode = (uint64_t *)opt->value;
16	const struct sample_reg *r = NULL;
17	char *s, *os = NULL, *p;
18	int ret = -1;
19	uint64_t mask;
20
21	if (unset)
22		return 0;
23
24	/*
25	 * cannot set it twice
26	 */
27	if (*mode)
28		return -1;
29
30	if (intr)
31		mask = arch__intr_reg_mask();
32	else
33		mask = arch__user_reg_mask();
34
35	/* str may be NULL in case no arg is passed to -I */
36	if (str) {
37		/* because str is read-only */
38		s = os = strdup(str);
39		if (!s)
40			return -1;
41
42		for (;;) {
43			p = strchr(s, ',');
44			if (p)
45				*p = '\0';
46
47			if (!strcmp(s, "?")) {
48				fprintf(stderr, "available registers: ");
49#ifdef HAVE_PERF_REGS_SUPPORT
50				for (r = sample_reg_masks; r->name; r++) {
51					if (r->mask & mask)
52						fprintf(stderr, "%s ", r->name);
53				}
54#endif
55				fputc('\n', stderr);
56				/* just printing available regs */
57				goto error;
58			}
59#ifdef HAVE_PERF_REGS_SUPPORT
60			for (r = sample_reg_masks; r->name; r++) {
61				if ((r->mask & mask) && !strcasecmp(s, r->name))
62					break;
63			}
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=");
68				goto error;
69			}
70
71			*mode |= r->mask;
72
73			if (!p)
74				break;
75
76			s = p + 1;
77		}
78	}
79	ret = 0;
80
81	/* default to all possible regs */
82	if (*mode == 0)
83		*mode = mask;
84error:
85	free(os);
86	return ret;
87}
88
89int
90parse_user_regs(const struct option *opt, const char *str, int unset)
91{
92	return __parse_regs(opt, str, unset, false);
93}
94
95int
96parse_intr_regs(const struct option *opt, const char *str, int unset)
97{
98	return __parse_regs(opt, str, unset, true);
99}