xref: /linux/tools/perf/util/parse-events.c (revision d3d1e86da07b4565815e3dbcd082f53017d215f8)
11b290d67SFrederic Weisbecker #include "../../../include/linux/hw_breakpoint.h"
286470930SIngo Molnar #include "util.h"
36b58e7f1SUlrich Drepper #include "../perf.h"
4361c99a6SArnaldo Carvalho de Melo #include "evlist.h"
569aad6f1SArnaldo Carvalho de Melo #include "evsel.h"
686470930SIngo Molnar #include "parse-options.h"
786470930SIngo Molnar #include "parse-events.h"
886470930SIngo Molnar #include "exec_cmd.h"
986470930SIngo Molnar #include "string.h"
105aab621bSArnaldo Carvalho de Melo #include "symbol.h"
115beeded1SJason Baron #include "cache.h"
128755a8f2SArjan van de Ven #include "header.h"
13549104f2SClark Williams #include "debugfs.h"
1486470930SIngo Molnar 
1586470930SIngo Molnar struct event_symbol {
169cffa8d5SPaul Mackerras 	u8		type;
179cffa8d5SPaul Mackerras 	u64		config;
1883a0944fSIngo Molnar 	const char	*symbol;
1983a0944fSIngo Molnar 	const char	*alias;
2086470930SIngo Molnar };
2186470930SIngo Molnar 
22bcd3279fSFrederic Weisbecker enum event_result {
23bcd3279fSFrederic Weisbecker 	EVT_FAILED,
24bcd3279fSFrederic Weisbecker 	EVT_HANDLED,
25bcd3279fSFrederic Weisbecker 	EVT_HANDLED_ALL
26bcd3279fSFrederic Weisbecker };
27bcd3279fSFrederic Weisbecker 
285beeded1SJason Baron char debugfs_path[MAXPATHLEN];
295beeded1SJason Baron 
3051e26842SJaswinder Singh Rajput #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
3151e26842SJaswinder Singh Rajput #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
3286470930SIngo Molnar 
3386470930SIngo Molnar static struct event_symbol event_symbols[] = {
3474d5b588SJaswinder Singh Rajput   { CHW(CPU_CYCLES),			"cpu-cycles",			"cycles"		},
35129c04cbSIngo Molnar   { CHW(STALLED_CYCLES_FRONTEND),	"stalled-cycles-frontend",	"idle-cycles-frontend"	},
36129c04cbSIngo Molnar   { CHW(STALLED_CYCLES_BACKEND),	"stalled-cycles-backend",	"idle-cycles-backend"	},
3774d5b588SJaswinder Singh Rajput   { CHW(INSTRUCTIONS),			"instructions",			""			},
3874d5b588SJaswinder Singh Rajput   { CHW(CACHE_REFERENCES),		"cache-references",		""			},
3974d5b588SJaswinder Singh Rajput   { CHW(CACHE_MISSES),			"cache-misses",			""			},
4074d5b588SJaswinder Singh Rajput   { CHW(BRANCH_INSTRUCTIONS),		"branch-instructions",		"branches"		},
4174d5b588SJaswinder Singh Rajput   { CHW(BRANCH_MISSES),			"branch-misses",		""			},
4274d5b588SJaswinder Singh Rajput   { CHW(BUS_CYCLES),			"bus-cycles",			""			},
4386470930SIngo Molnar 
4474d5b588SJaswinder Singh Rajput   { CSW(CPU_CLOCK),			"cpu-clock",			""			},
4574d5b588SJaswinder Singh Rajput   { CSW(TASK_CLOCK),			"task-clock",			""			},
46c0c22dbfSJaswinder Singh Rajput   { CSW(PAGE_FAULTS),			"page-faults",			"faults"		},
4774d5b588SJaswinder Singh Rajput   { CSW(PAGE_FAULTS_MIN),		"minor-faults",			""			},
4874d5b588SJaswinder Singh Rajput   { CSW(PAGE_FAULTS_MAJ),		"major-faults",			""			},
4974d5b588SJaswinder Singh Rajput   { CSW(CONTEXT_SWITCHES),		"context-switches",		"cs"			},
5074d5b588SJaswinder Singh Rajput   { CSW(CPU_MIGRATIONS),		"cpu-migrations",		"migrations"		},
51f7d79860SAnton Blanchard   { CSW(ALIGNMENT_FAULTS),		"alignment-faults",		""			},
52f7d79860SAnton Blanchard   { CSW(EMULATION_FAULTS),		"emulation-faults",		""			},
5386470930SIngo Molnar };
5486470930SIngo Molnar 
55cdd6c482SIngo Molnar #define __PERF_EVENT_FIELD(config, name) \
56cdd6c482SIngo Molnar 	((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
5786470930SIngo Molnar 
58cdd6c482SIngo Molnar #define PERF_EVENT_RAW(config)		__PERF_EVENT_FIELD(config, RAW)
59cdd6c482SIngo Molnar #define PERF_EVENT_CONFIG(config)	__PERF_EVENT_FIELD(config, CONFIG)
60cdd6c482SIngo Molnar #define PERF_EVENT_TYPE(config)		__PERF_EVENT_FIELD(config, TYPE)
61cdd6c482SIngo Molnar #define PERF_EVENT_ID(config)		__PERF_EVENT_FIELD(config, EVENT)
6286470930SIngo Molnar 
63*d3d1e86dSIngo Molnar static const char *hw_event_names[PERF_COUNT_HW_MAX] = {
6486470930SIngo Molnar 	"cycles",
6586470930SIngo Molnar 	"instructions",
6686470930SIngo Molnar 	"cache-references",
6786470930SIngo Molnar 	"cache-misses",
6886470930SIngo Molnar 	"branches",
6986470930SIngo Molnar 	"branch-misses",
7086470930SIngo Molnar 	"bus-cycles",
71*d3d1e86dSIngo Molnar 	"stalled-cycles-frontend",
72*d3d1e86dSIngo Molnar 	"stalled-cycles-backend",
7386470930SIngo Molnar };
7486470930SIngo Molnar 
75*d3d1e86dSIngo Molnar static const char *sw_event_names[PERF_COUNT_SW_MAX] = {
76749141d9SIngo Molnar 	"cpu-clock",
77749141d9SIngo Molnar 	"task-clock",
7886470930SIngo Molnar 	"page-faults",
7986470930SIngo Molnar 	"context-switches",
8086470930SIngo Molnar 	"CPU-migrations",
8186470930SIngo Molnar 	"minor-faults",
8286470930SIngo Molnar 	"major-faults",
83f7d79860SAnton Blanchard 	"alignment-faults",
84f7d79860SAnton Blanchard 	"emulation-faults",
8586470930SIngo Molnar };
8686470930SIngo Molnar 
8786470930SIngo Molnar #define MAX_ALIASES 8
8886470930SIngo Molnar 
8983a0944fSIngo Molnar static const char *hw_cache[][MAX_ALIASES] = {
909590b7baSAnton Blanchard  { "L1-dcache",	"l1-d",		"l1d",		"L1-data",		},
919590b7baSAnton Blanchard  { "L1-icache",	"l1-i",		"l1i",		"L1-instruction",	},
92e5c59547SJaswinder Singh Rajput  { "LLC",	"L2"							},
93e5c59547SJaswinder Singh Rajput  { "dTLB",	"d-tlb",	"Data-TLB",				},
94e5c59547SJaswinder Singh Rajput  { "iTLB",	"i-tlb",	"Instruction-TLB",			},
95e5c59547SJaswinder Singh Rajput  { "branch",	"branches",	"bpu",		"btb",		"bpc",	},
9686470930SIngo Molnar };
9786470930SIngo Molnar 
9883a0944fSIngo Molnar static const char *hw_cache_op[][MAX_ALIASES] = {
99e5c59547SJaswinder Singh Rajput  { "load",	"loads",	"read",					},
100e5c59547SJaswinder Singh Rajput  { "store",	"stores",	"write",				},
101e5c59547SJaswinder Singh Rajput  { "prefetch",	"prefetches",	"speculative-read", "speculative-load",	},
10286470930SIngo Molnar };
10386470930SIngo Molnar 
10483a0944fSIngo Molnar static const char *hw_cache_result[][MAX_ALIASES] = {
105e5c59547SJaswinder Singh Rajput  { "refs",	"Reference",	"ops",		"access",		},
106e5c59547SJaswinder Singh Rajput  { "misses",	"miss",							},
10786470930SIngo Molnar };
10886470930SIngo Molnar 
10906813f6cSJaswinder Singh Rajput #define C(x)		PERF_COUNT_HW_CACHE_##x
11006813f6cSJaswinder Singh Rajput #define CACHE_READ	(1 << C(OP_READ))
11106813f6cSJaswinder Singh Rajput #define CACHE_WRITE	(1 << C(OP_WRITE))
11206813f6cSJaswinder Singh Rajput #define CACHE_PREFETCH	(1 << C(OP_PREFETCH))
11306813f6cSJaswinder Singh Rajput #define COP(x)		(1 << x)
11406813f6cSJaswinder Singh Rajput 
11506813f6cSJaswinder Singh Rajput /*
11606813f6cSJaswinder Singh Rajput  * cache operartion stat
11706813f6cSJaswinder Singh Rajput  * L1I : Read and prefetch only
11806813f6cSJaswinder Singh Rajput  * ITLB and BPU : Read-only
11906813f6cSJaswinder Singh Rajput  */
12006813f6cSJaswinder Singh Rajput static unsigned long hw_cache_stat[C(MAX)] = {
12106813f6cSJaswinder Singh Rajput  [C(L1D)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12206813f6cSJaswinder Singh Rajput  [C(L1I)]	= (CACHE_READ | CACHE_PREFETCH),
12306813f6cSJaswinder Singh Rajput  [C(LL)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12406813f6cSJaswinder Singh Rajput  [C(DTLB)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12506813f6cSJaswinder Singh Rajput  [C(ITLB)]	= (CACHE_READ),
12606813f6cSJaswinder Singh Rajput  [C(BPU)]	= (CACHE_READ),
12706813f6cSJaswinder Singh Rajput };
12806813f6cSJaswinder Singh Rajput 
1296b58e7f1SUlrich Drepper #define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
130f6bdafefSJason Baron 	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
1316b58e7f1SUlrich Drepper 	if (sys_dirent.d_type == DT_DIR &&				       \
132f6bdafefSJason Baron 	   (strcmp(sys_dirent.d_name, ".")) &&				       \
133f6bdafefSJason Baron 	   (strcmp(sys_dirent.d_name, "..")))
134f6bdafefSJason Baron 
135ae07b63fSPeter Zijlstra static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
136ae07b63fSPeter Zijlstra {
137ae07b63fSPeter Zijlstra 	char evt_path[MAXPATHLEN];
138ae07b63fSPeter Zijlstra 	int fd;
139ae07b63fSPeter Zijlstra 
140ae07b63fSPeter Zijlstra 	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
141ae07b63fSPeter Zijlstra 			sys_dir->d_name, evt_dir->d_name);
142ae07b63fSPeter Zijlstra 	fd = open(evt_path, O_RDONLY);
143ae07b63fSPeter Zijlstra 	if (fd < 0)
144ae07b63fSPeter Zijlstra 		return -EINVAL;
145ae07b63fSPeter Zijlstra 	close(fd);
146ae07b63fSPeter Zijlstra 
147ae07b63fSPeter Zijlstra 	return 0;
148ae07b63fSPeter Zijlstra }
149ae07b63fSPeter Zijlstra 
1506b58e7f1SUlrich Drepper #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
151f6bdafefSJason Baron 	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
1526b58e7f1SUlrich Drepper 	if (evt_dirent.d_type == DT_DIR &&				       \
153f6bdafefSJason Baron 	   (strcmp(evt_dirent.d_name, ".")) &&				       \
154ae07b63fSPeter Zijlstra 	   (strcmp(evt_dirent.d_name, "..")) &&				       \
155ae07b63fSPeter Zijlstra 	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
156f6bdafefSJason Baron 
157270bbbe8SLi Zefan #define MAX_EVENT_LENGTH 512
158f6bdafefSJason Baron 
159f6bdafefSJason Baron 
1601ef2ed10SFrederic Weisbecker struct tracepoint_path *tracepoint_id_to_path(u64 config)
161f6bdafefSJason Baron {
1621ef2ed10SFrederic Weisbecker 	struct tracepoint_path *path = NULL;
163f6bdafefSJason Baron 	DIR *sys_dir, *evt_dir;
164f6bdafefSJason Baron 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
165f6bdafefSJason Baron 	char id_buf[4];
166725b1368SEric Dumazet 	int fd;
167f6bdafefSJason Baron 	u64 id;
168f6bdafefSJason Baron 	char evt_path[MAXPATHLEN];
169725b1368SEric Dumazet 	char dir_path[MAXPATHLEN];
170f6bdafefSJason Baron 
171549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
1721ef2ed10SFrederic Weisbecker 		return NULL;
173f6bdafefSJason Baron 
1745beeded1SJason Baron 	sys_dir = opendir(debugfs_path);
175f6bdafefSJason Baron 	if (!sys_dir)
176725b1368SEric Dumazet 		return NULL;
177f6bdafefSJason Baron 
1786b58e7f1SUlrich Drepper 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
179725b1368SEric Dumazet 
180725b1368SEric Dumazet 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
181725b1368SEric Dumazet 			 sys_dirent.d_name);
182725b1368SEric Dumazet 		evt_dir = opendir(dir_path);
183725b1368SEric Dumazet 		if (!evt_dir)
1846b58e7f1SUlrich Drepper 			continue;
185725b1368SEric Dumazet 
1866b58e7f1SUlrich Drepper 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
187725b1368SEric Dumazet 
188725b1368SEric Dumazet 			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
189f6bdafefSJason Baron 				 evt_dirent.d_name);
190725b1368SEric Dumazet 			fd = open(evt_path, O_RDONLY);
191f6bdafefSJason Baron 			if (fd < 0)
192f6bdafefSJason Baron 				continue;
193f6bdafefSJason Baron 			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
194f6bdafefSJason Baron 				close(fd);
195f6bdafefSJason Baron 				continue;
196f6bdafefSJason Baron 			}
197f6bdafefSJason Baron 			close(fd);
198f6bdafefSJason Baron 			id = atoll(id_buf);
199f6bdafefSJason Baron 			if (id == config) {
200f6bdafefSJason Baron 				closedir(evt_dir);
201f6bdafefSJason Baron 				closedir(sys_dir);
20259b4caebSJulia Lawall 				path = zalloc(sizeof(*path));
2031ef2ed10SFrederic Weisbecker 				path->system = malloc(MAX_EVENT_LENGTH);
2041ef2ed10SFrederic Weisbecker 				if (!path->system) {
2051ef2ed10SFrederic Weisbecker 					free(path);
2061ef2ed10SFrederic Weisbecker 					return NULL;
2071ef2ed10SFrederic Weisbecker 				}
2081ef2ed10SFrederic Weisbecker 				path->name = malloc(MAX_EVENT_LENGTH);
2091ef2ed10SFrederic Weisbecker 				if (!path->name) {
2101ef2ed10SFrederic Weisbecker 					free(path->system);
2111ef2ed10SFrederic Weisbecker 					free(path);
2121ef2ed10SFrederic Weisbecker 					return NULL;
2131ef2ed10SFrederic Weisbecker 				}
2141ef2ed10SFrederic Weisbecker 				strncpy(path->system, sys_dirent.d_name,
2151ef2ed10SFrederic Weisbecker 					MAX_EVENT_LENGTH);
2161ef2ed10SFrederic Weisbecker 				strncpy(path->name, evt_dirent.d_name,
2171ef2ed10SFrederic Weisbecker 					MAX_EVENT_LENGTH);
2181ef2ed10SFrederic Weisbecker 				return path;
219f6bdafefSJason Baron 			}
220f6bdafefSJason Baron 		}
221f6bdafefSJason Baron 		closedir(evt_dir);
222f6bdafefSJason Baron 	}
223f6bdafefSJason Baron 
224f6bdafefSJason Baron 	closedir(sys_dir);
2251ef2ed10SFrederic Weisbecker 	return NULL;
2261ef2ed10SFrederic Weisbecker }
2271ef2ed10SFrederic Weisbecker 
2281ef2ed10SFrederic Weisbecker #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
2291ef2ed10SFrederic Weisbecker static const char *tracepoint_id_to_name(u64 config)
2301ef2ed10SFrederic Weisbecker {
2311ef2ed10SFrederic Weisbecker 	static char buf[TP_PATH_LEN];
2321ef2ed10SFrederic Weisbecker 	struct tracepoint_path *path;
2331ef2ed10SFrederic Weisbecker 
2341ef2ed10SFrederic Weisbecker 	path = tracepoint_id_to_path(config);
2351ef2ed10SFrederic Weisbecker 	if (path) {
2361ef2ed10SFrederic Weisbecker 		snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name);
2371ef2ed10SFrederic Weisbecker 		free(path->name);
2381ef2ed10SFrederic Weisbecker 		free(path->system);
2391ef2ed10SFrederic Weisbecker 		free(path);
2401ef2ed10SFrederic Weisbecker 	} else
2411ef2ed10SFrederic Weisbecker 		snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown");
2421ef2ed10SFrederic Weisbecker 
2431ef2ed10SFrederic Weisbecker 	return buf;
244f6bdafefSJason Baron }
245f6bdafefSJason Baron 
24606813f6cSJaswinder Singh Rajput static int is_cache_op_valid(u8 cache_type, u8 cache_op)
24706813f6cSJaswinder Singh Rajput {
24806813f6cSJaswinder Singh Rajput 	if (hw_cache_stat[cache_type] & COP(cache_op))
24906813f6cSJaswinder Singh Rajput 		return 1;	/* valid */
25006813f6cSJaswinder Singh Rajput 	else
25106813f6cSJaswinder Singh Rajput 		return 0;	/* invalid */
25206813f6cSJaswinder Singh Rajput }
25306813f6cSJaswinder Singh Rajput 
254e5c59547SJaswinder Singh Rajput static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
255e5c59547SJaswinder Singh Rajput {
256e5c59547SJaswinder Singh Rajput 	static char name[50];
257e5c59547SJaswinder Singh Rajput 
258e5c59547SJaswinder Singh Rajput 	if (cache_result) {
259e5c59547SJaswinder Singh Rajput 		sprintf(name, "%s-%s-%s", hw_cache[cache_type][0],
260e5c59547SJaswinder Singh Rajput 			hw_cache_op[cache_op][0],
261e5c59547SJaswinder Singh Rajput 			hw_cache_result[cache_result][0]);
262e5c59547SJaswinder Singh Rajput 	} else {
263e5c59547SJaswinder Singh Rajput 		sprintf(name, "%s-%s", hw_cache[cache_type][0],
264e5c59547SJaswinder Singh Rajput 			hw_cache_op[cache_op][1]);
265e5c59547SJaswinder Singh Rajput 	}
266e5c59547SJaswinder Singh Rajput 
267e5c59547SJaswinder Singh Rajput 	return name;
268e5c59547SJaswinder Singh Rajput }
269e5c59547SJaswinder Singh Rajput 
2701424dc96SDavid Ahern const char *event_type(int type)
2711424dc96SDavid Ahern {
2721424dc96SDavid Ahern 	switch (type) {
2731424dc96SDavid Ahern 	case PERF_TYPE_HARDWARE:
2741424dc96SDavid Ahern 		return "hardware";
2751424dc96SDavid Ahern 
2761424dc96SDavid Ahern 	case PERF_TYPE_SOFTWARE:
2771424dc96SDavid Ahern 		return "software";
2781424dc96SDavid Ahern 
2791424dc96SDavid Ahern 	case PERF_TYPE_TRACEPOINT:
2801424dc96SDavid Ahern 		return "tracepoint";
2811424dc96SDavid Ahern 
2821424dc96SDavid Ahern 	case PERF_TYPE_HW_CACHE:
2831424dc96SDavid Ahern 		return "hardware-cache";
2841424dc96SDavid Ahern 
2851424dc96SDavid Ahern 	default:
2861424dc96SDavid Ahern 		break;
2871424dc96SDavid Ahern 	}
2881424dc96SDavid Ahern 
2891424dc96SDavid Ahern 	return "unknown";
2901424dc96SDavid Ahern }
2911424dc96SDavid Ahern 
29269aad6f1SArnaldo Carvalho de Melo const char *event_name(struct perf_evsel *evsel)
29386470930SIngo Molnar {
29469aad6f1SArnaldo Carvalho de Melo 	u64 config = evsel->attr.config;
29569aad6f1SArnaldo Carvalho de Melo 	int type = evsel->attr.type;
2968f18aec5SPeter Zijlstra 
297f0c55bcfSStephane Eranian 	if (evsel->name)
298f0c55bcfSStephane Eranian 		return evsel->name;
299f0c55bcfSStephane Eranian 
3008f18aec5SPeter Zijlstra 	return __event_name(type, config);
3018f18aec5SPeter Zijlstra }
3028f18aec5SPeter Zijlstra 
30383a0944fSIngo Molnar const char *__event_name(int type, u64 config)
3048f18aec5SPeter Zijlstra {
30586470930SIngo Molnar 	static char buf[32];
30686470930SIngo Molnar 
3078f18aec5SPeter Zijlstra 	if (type == PERF_TYPE_RAW) {
3089486aa38SArnaldo Carvalho de Melo 		sprintf(buf, "raw 0x%" PRIx64, config);
30986470930SIngo Molnar 		return buf;
31086470930SIngo Molnar 	}
31186470930SIngo Molnar 
31286470930SIngo Molnar 	switch (type) {
31386470930SIngo Molnar 	case PERF_TYPE_HARDWARE:
3141fc570adSIngo Molnar 		if (config < PERF_COUNT_HW_MAX && hw_event_names[config])
31586470930SIngo Molnar 			return hw_event_names[config];
31686470930SIngo Molnar 		return "unknown-hardware";
31786470930SIngo Molnar 
31886470930SIngo Molnar 	case PERF_TYPE_HW_CACHE: {
3199cffa8d5SPaul Mackerras 		u8 cache_type, cache_op, cache_result;
32086470930SIngo Molnar 
32186470930SIngo Molnar 		cache_type   = (config >>  0) & 0xff;
32286470930SIngo Molnar 		if (cache_type > PERF_COUNT_HW_CACHE_MAX)
32386470930SIngo Molnar 			return "unknown-ext-hardware-cache-type";
32486470930SIngo Molnar 
32586470930SIngo Molnar 		cache_op     = (config >>  8) & 0xff;
32686470930SIngo Molnar 		if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX)
32786470930SIngo Molnar 			return "unknown-ext-hardware-cache-op";
32886470930SIngo Molnar 
32986470930SIngo Molnar 		cache_result = (config >> 16) & 0xff;
33086470930SIngo Molnar 		if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX)
33186470930SIngo Molnar 			return "unknown-ext-hardware-cache-result";
33286470930SIngo Molnar 
33306813f6cSJaswinder Singh Rajput 		if (!is_cache_op_valid(cache_type, cache_op))
33406813f6cSJaswinder Singh Rajput 			return "invalid-cache";
33586470930SIngo Molnar 
336e5c59547SJaswinder Singh Rajput 		return event_cache_name(cache_type, cache_op, cache_result);
33786470930SIngo Molnar 	}
33886470930SIngo Molnar 
33986470930SIngo Molnar 	case PERF_TYPE_SOFTWARE:
3401fc570adSIngo Molnar 		if (config < PERF_COUNT_SW_MAX && sw_event_names[config])
34186470930SIngo Molnar 			return sw_event_names[config];
34286470930SIngo Molnar 		return "unknown-software";
34386470930SIngo Molnar 
344f6bdafefSJason Baron 	case PERF_TYPE_TRACEPOINT:
345f6bdafefSJason Baron 		return tracepoint_id_to_name(config);
346f6bdafefSJason Baron 
34786470930SIngo Molnar 	default:
34886470930SIngo Molnar 		break;
34986470930SIngo Molnar 	}
35086470930SIngo Molnar 
35186470930SIngo Molnar 	return "unknown";
35286470930SIngo Molnar }
35386470930SIngo Molnar 
35483a0944fSIngo Molnar static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
35586470930SIngo Molnar {
35686470930SIngo Molnar 	int i, j;
35761c45981SPaul Mackerras 	int n, longest = -1;
35886470930SIngo Molnar 
35986470930SIngo Molnar 	for (i = 0; i < size; i++) {
36061c45981SPaul Mackerras 		for (j = 0; j < MAX_ALIASES && names[i][j]; j++) {
36161c45981SPaul Mackerras 			n = strlen(names[i][j]);
36261c45981SPaul Mackerras 			if (n > longest && !strncasecmp(*str, names[i][j], n))
36361c45981SPaul Mackerras 				longest = n;
36461c45981SPaul Mackerras 		}
36561c45981SPaul Mackerras 		if (longest > 0) {
36661c45981SPaul Mackerras 			*str += longest;
36786470930SIngo Molnar 			return i;
36886470930SIngo Molnar 		}
36986470930SIngo Molnar 	}
37086470930SIngo Molnar 
3718953645fSIngo Molnar 	return -1;
37286470930SIngo Molnar }
37386470930SIngo Molnar 
374bcd3279fSFrederic Weisbecker static enum event_result
375cdd6c482SIngo Molnar parse_generic_hw_event(const char **str, struct perf_event_attr *attr)
37686470930SIngo Molnar {
37761c45981SPaul Mackerras 	const char *s = *str;
37861c45981SPaul Mackerras 	int cache_type = -1, cache_op = -1, cache_result = -1;
37986470930SIngo Molnar 
38061c45981SPaul Mackerras 	cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX);
38186470930SIngo Molnar 	/*
38286470930SIngo Molnar 	 * No fallback - if we cannot get a clear cache type
38386470930SIngo Molnar 	 * then bail out:
38486470930SIngo Molnar 	 */
38586470930SIngo Molnar 	if (cache_type == -1)
386bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
38786470930SIngo Molnar 
38861c45981SPaul Mackerras 	while ((cache_op == -1 || cache_result == -1) && *s == '-') {
38961c45981SPaul Mackerras 		++s;
39061c45981SPaul Mackerras 
39161c45981SPaul Mackerras 		if (cache_op == -1) {
39261c45981SPaul Mackerras 			cache_op = parse_aliases(&s, hw_cache_op,
39361c45981SPaul Mackerras 						PERF_COUNT_HW_CACHE_OP_MAX);
39461c45981SPaul Mackerras 			if (cache_op >= 0) {
39561c45981SPaul Mackerras 				if (!is_cache_op_valid(cache_type, cache_op))
39661c45981SPaul Mackerras 					return 0;
39761c45981SPaul Mackerras 				continue;
39861c45981SPaul Mackerras 			}
39961c45981SPaul Mackerras 		}
40061c45981SPaul Mackerras 
40161c45981SPaul Mackerras 		if (cache_result == -1) {
40261c45981SPaul Mackerras 			cache_result = parse_aliases(&s, hw_cache_result,
40361c45981SPaul Mackerras 						PERF_COUNT_HW_CACHE_RESULT_MAX);
40461c45981SPaul Mackerras 			if (cache_result >= 0)
40561c45981SPaul Mackerras 				continue;
40661c45981SPaul Mackerras 		}
40761c45981SPaul Mackerras 
40861c45981SPaul Mackerras 		/*
40961c45981SPaul Mackerras 		 * Can't parse this as a cache op or result, so back up
41061c45981SPaul Mackerras 		 * to the '-'.
41161c45981SPaul Mackerras 		 */
41261c45981SPaul Mackerras 		--s;
41361c45981SPaul Mackerras 		break;
41461c45981SPaul Mackerras 	}
41561c45981SPaul Mackerras 
41686470930SIngo Molnar 	/*
41786470930SIngo Molnar 	 * Fall back to reads:
41886470930SIngo Molnar 	 */
4198953645fSIngo Molnar 	if (cache_op == -1)
4208953645fSIngo Molnar 		cache_op = PERF_COUNT_HW_CACHE_OP_READ;
42186470930SIngo Molnar 
42286470930SIngo Molnar 	/*
42386470930SIngo Molnar 	 * Fall back to accesses:
42486470930SIngo Molnar 	 */
42586470930SIngo Molnar 	if (cache_result == -1)
42686470930SIngo Molnar 		cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
42786470930SIngo Molnar 
42886470930SIngo Molnar 	attr->config = cache_type | (cache_op << 8) | (cache_result << 16);
42986470930SIngo Molnar 	attr->type = PERF_TYPE_HW_CACHE;
43086470930SIngo Molnar 
43161c45981SPaul Mackerras 	*str = s;
432bcd3279fSFrederic Weisbecker 	return EVT_HANDLED;
43386470930SIngo Molnar }
43486470930SIngo Molnar 
435bcd3279fSFrederic Weisbecker static enum event_result
436bcd3279fSFrederic Weisbecker parse_single_tracepoint_event(char *sys_name,
437bcd3279fSFrederic Weisbecker 			      const char *evt_name,
438bcd3279fSFrederic Weisbecker 			      unsigned int evt_length,
439cdd6c482SIngo Molnar 			      struct perf_event_attr *attr,
440bcd3279fSFrederic Weisbecker 			      const char **strp)
441bcd3279fSFrederic Weisbecker {
442bcd3279fSFrederic Weisbecker 	char evt_path[MAXPATHLEN];
443bcd3279fSFrederic Weisbecker 	char id_buf[4];
444bcd3279fSFrederic Weisbecker 	u64 id;
445bcd3279fSFrederic Weisbecker 	int fd;
446bcd3279fSFrederic Weisbecker 
447bcd3279fSFrederic Weisbecker 	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
448bcd3279fSFrederic Weisbecker 		 sys_name, evt_name);
449bcd3279fSFrederic Weisbecker 
450bcd3279fSFrederic Weisbecker 	fd = open(evt_path, O_RDONLY);
451bcd3279fSFrederic Weisbecker 	if (fd < 0)
452bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
453bcd3279fSFrederic Weisbecker 
454bcd3279fSFrederic Weisbecker 	if (read(fd, id_buf, sizeof(id_buf)) < 0) {
455bcd3279fSFrederic Weisbecker 		close(fd);
456bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
457bcd3279fSFrederic Weisbecker 	}
458bcd3279fSFrederic Weisbecker 
459bcd3279fSFrederic Weisbecker 	close(fd);
460bcd3279fSFrederic Weisbecker 	id = atoll(id_buf);
461bcd3279fSFrederic Weisbecker 	attr->config = id;
462bcd3279fSFrederic Weisbecker 	attr->type = PERF_TYPE_TRACEPOINT;
4634c635a4eSCorey Ashford 	*strp += strlen(sys_name) + evt_length + 1; /* + 1 for the ':' */
464bcd3279fSFrederic Weisbecker 
4655710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_RAW;
4665710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_TIME;
4675710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_CPU;
4685710fcadSStephane Eranian 
4695710fcadSStephane Eranian 	attr->sample_period = 1;
4705710fcadSStephane Eranian 
4715710fcadSStephane Eranian 
472bcd3279fSFrederic Weisbecker 	return EVT_HANDLED;
473bcd3279fSFrederic Weisbecker }
474bcd3279fSFrederic Weisbecker 
475bcd3279fSFrederic Weisbecker /* sys + ':' + event + ':' + flags*/
476bcd3279fSFrederic Weisbecker #define MAX_EVOPT_LEN	(MAX_EVENT_LENGTH * 2 + 2 + 128)
477bcd3279fSFrederic Weisbecker static enum event_result
47817ea1b70SArnaldo Carvalho de Melo parse_multiple_tracepoint_event(const struct option *opt, char *sys_name,
47917ea1b70SArnaldo Carvalho de Melo 				const char *evt_exp, char *flags)
480bcd3279fSFrederic Weisbecker {
481bcd3279fSFrederic Weisbecker 	char evt_path[MAXPATHLEN];
482bcd3279fSFrederic Weisbecker 	struct dirent *evt_ent;
483bcd3279fSFrederic Weisbecker 	DIR *evt_dir;
484bcd3279fSFrederic Weisbecker 
485bcd3279fSFrederic Weisbecker 	snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name);
486bcd3279fSFrederic Weisbecker 	evt_dir = opendir(evt_path);
487bcd3279fSFrederic Weisbecker 
488bcd3279fSFrederic Weisbecker 	if (!evt_dir) {
489bcd3279fSFrederic Weisbecker 		perror("Can't open event dir");
490bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
491bcd3279fSFrederic Weisbecker 	}
492bcd3279fSFrederic Weisbecker 
493bcd3279fSFrederic Weisbecker 	while ((evt_ent = readdir(evt_dir))) {
494bcd3279fSFrederic Weisbecker 		char event_opt[MAX_EVOPT_LEN + 1];
495bcd3279fSFrederic Weisbecker 		int len;
496bcd3279fSFrederic Weisbecker 
497bcd3279fSFrederic Weisbecker 		if (!strcmp(evt_ent->d_name, ".")
498bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "..")
499bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "enable")
500bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "filter"))
501bcd3279fSFrederic Weisbecker 			continue;
502bcd3279fSFrederic Weisbecker 
503fb1d2edfSMasami Hiramatsu 		if (!strglobmatch(evt_ent->d_name, evt_exp))
504fb1d2edfSMasami Hiramatsu 			continue;
505fb1d2edfSMasami Hiramatsu 
506180570fdSUlrich Drepper 		len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s%s%s", sys_name,
507180570fdSUlrich Drepper 			       evt_ent->d_name, flags ? ":" : "",
508180570fdSUlrich Drepper 			       flags ?: "");
509bcd3279fSFrederic Weisbecker 		if (len < 0)
510bcd3279fSFrederic Weisbecker 			return EVT_FAILED;
511bcd3279fSFrederic Weisbecker 
51217ea1b70SArnaldo Carvalho de Melo 		if (parse_events(opt, event_opt, 0))
513bcd3279fSFrederic Weisbecker 			return EVT_FAILED;
514bcd3279fSFrederic Weisbecker 	}
515bcd3279fSFrederic Weisbecker 
516bcd3279fSFrederic Weisbecker 	return EVT_HANDLED_ALL;
517bcd3279fSFrederic Weisbecker }
518bcd3279fSFrederic Weisbecker 
51917ea1b70SArnaldo Carvalho de Melo static enum event_result
52017ea1b70SArnaldo Carvalho de Melo parse_tracepoint_event(const struct option *opt, const char **strp,
521cdd6c482SIngo Molnar 		       struct perf_event_attr *attr)
522f6bdafefSJason Baron {
523f6bdafefSJason Baron 	const char *evt_name;
5244c635a4eSCorey Ashford 	char *flags = NULL, *comma_loc;
525f6bdafefSJason Baron 	char sys_name[MAX_EVENT_LENGTH];
526f6bdafefSJason Baron 	unsigned int sys_length, evt_length;
527f6bdafefSJason Baron 
528549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
529f6bdafefSJason Baron 		return 0;
530f6bdafefSJason Baron 
531f6bdafefSJason Baron 	evt_name = strchr(*strp, ':');
532f6bdafefSJason Baron 	if (!evt_name)
533bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
534f6bdafefSJason Baron 
535f6bdafefSJason Baron 	sys_length = evt_name - *strp;
536f6bdafefSJason Baron 	if (sys_length >= MAX_EVENT_LENGTH)
537f6bdafefSJason Baron 		return 0;
538f6bdafefSJason Baron 
539f6bdafefSJason Baron 	strncpy(sys_name, *strp, sys_length);
540f6bdafefSJason Baron 	sys_name[sys_length] = '\0';
541f6bdafefSJason Baron 	evt_name = evt_name + 1;
5423a9f131fSFrederic Weisbecker 
5434c635a4eSCorey Ashford 	comma_loc = strchr(evt_name, ',');
5444c635a4eSCorey Ashford 	if (comma_loc) {
5454c635a4eSCorey Ashford 		/* take the event name up to the comma */
5464c635a4eSCorey Ashford 		evt_name = strndup(evt_name, comma_loc - evt_name);
5474c635a4eSCorey Ashford 	}
5483a9f131fSFrederic Weisbecker 	flags = strchr(evt_name, ':');
5493a9f131fSFrederic Weisbecker 	if (flags) {
5501fc35b29SIngo Molnar 		/* split it out: */
5511fc35b29SIngo Molnar 		evt_name = strndup(evt_name, flags - evt_name);
5523a9f131fSFrederic Weisbecker 		flags++;
5533a9f131fSFrederic Weisbecker 	}
5543a9f131fSFrederic Weisbecker 
555f6bdafefSJason Baron 	evt_length = strlen(evt_name);
556f6bdafefSJason Baron 	if (evt_length >= MAX_EVENT_LENGTH)
557bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
558fb1d2edfSMasami Hiramatsu 	if (strpbrk(evt_name, "*?")) {
559dd9a9ad5SArnaldo Carvalho de Melo 		*strp += strlen(sys_name) + evt_length + 1; /* 1 == the ':' */
56017ea1b70SArnaldo Carvalho de Melo 		return parse_multiple_tracepoint_event(opt, sys_name, evt_name,
561fb1d2edfSMasami Hiramatsu 						       flags);
562f006d25aSHan Pingtian 	} else {
563bcd3279fSFrederic Weisbecker 		return parse_single_tracepoint_event(sys_name, evt_name,
564bdef3b02SFrederic Weisbecker 						     evt_length, attr, strp);
565f6bdafefSJason Baron 	}
566f006d25aSHan Pingtian }
567f6bdafefSJason Baron 
5681b290d67SFrederic Weisbecker static enum event_result
5691b290d67SFrederic Weisbecker parse_breakpoint_type(const char *type, const char **strp,
5701b290d67SFrederic Weisbecker 		      struct perf_event_attr *attr)
5711b290d67SFrederic Weisbecker {
5721b290d67SFrederic Weisbecker 	int i;
5731b290d67SFrederic Weisbecker 
5741b290d67SFrederic Weisbecker 	for (i = 0; i < 3; i++) {
5751b290d67SFrederic Weisbecker 		if (!type[i])
5761b290d67SFrederic Weisbecker 			break;
5771b290d67SFrederic Weisbecker 
5781b290d67SFrederic Weisbecker 		switch (type[i]) {
5791b290d67SFrederic Weisbecker 		case 'r':
5801b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_R;
5811b290d67SFrederic Weisbecker 			break;
5821b290d67SFrederic Weisbecker 		case 'w':
5831b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_W;
5841b290d67SFrederic Weisbecker 			break;
5851b290d67SFrederic Weisbecker 		case 'x':
5861b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_X;
5871b290d67SFrederic Weisbecker 			break;
5881b290d67SFrederic Weisbecker 		default:
5891b290d67SFrederic Weisbecker 			return EVT_FAILED;
5901b290d67SFrederic Weisbecker 		}
5911b290d67SFrederic Weisbecker 	}
5921b290d67SFrederic Weisbecker 	if (!attr->bp_type) /* Default */
5931b290d67SFrederic Weisbecker 		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
5941b290d67SFrederic Weisbecker 
5951b290d67SFrederic Weisbecker 	*strp = type + i;
5961b290d67SFrederic Weisbecker 
5971b290d67SFrederic Weisbecker 	return EVT_HANDLED;
5981b290d67SFrederic Weisbecker }
5991b290d67SFrederic Weisbecker 
6001b290d67SFrederic Weisbecker static enum event_result
6011b290d67SFrederic Weisbecker parse_breakpoint_event(const char **strp, struct perf_event_attr *attr)
6021b290d67SFrederic Weisbecker {
6031b290d67SFrederic Weisbecker 	const char *target;
6041b290d67SFrederic Weisbecker 	const char *type;
6051b290d67SFrederic Weisbecker 	char *endaddr;
6061b290d67SFrederic Weisbecker 	u64 addr;
6071b290d67SFrederic Weisbecker 	enum event_result err;
6081b290d67SFrederic Weisbecker 
6091b290d67SFrederic Weisbecker 	target = strchr(*strp, ':');
6101b290d67SFrederic Weisbecker 	if (!target)
6111b290d67SFrederic Weisbecker 		return EVT_FAILED;
6121b290d67SFrederic Weisbecker 
6131b290d67SFrederic Weisbecker 	if (strncmp(*strp, "mem", target - *strp) != 0)
6141b290d67SFrederic Weisbecker 		return EVT_FAILED;
6151b290d67SFrederic Weisbecker 
6161b290d67SFrederic Weisbecker 	target++;
6171b290d67SFrederic Weisbecker 
6181b290d67SFrederic Weisbecker 	addr = strtoull(target, &endaddr, 0);
6191b290d67SFrederic Weisbecker 	if (target == endaddr)
6201b290d67SFrederic Weisbecker 		return EVT_FAILED;
6211b290d67SFrederic Weisbecker 
6221b290d67SFrederic Weisbecker 	attr->bp_addr = addr;
6231b290d67SFrederic Weisbecker 	*strp = endaddr;
6241b290d67SFrederic Weisbecker 
6251b290d67SFrederic Weisbecker 	type = strchr(target, ':');
6261b290d67SFrederic Weisbecker 
6271b290d67SFrederic Weisbecker 	/* If no type is defined, just rw as default */
6281b290d67SFrederic Weisbecker 	if (!type) {
6291b290d67SFrederic Weisbecker 		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
6301b290d67SFrederic Weisbecker 	} else {
6311b290d67SFrederic Weisbecker 		err = parse_breakpoint_type(++type, strp, attr);
6321b290d67SFrederic Weisbecker 		if (err == EVT_FAILED)
6331b290d67SFrederic Weisbecker 			return EVT_FAILED;
6341b290d67SFrederic Weisbecker 	}
6351b290d67SFrederic Weisbecker 
636aa59a485SFrederic Weisbecker 	/*
637aa59a485SFrederic Weisbecker 	 * We should find a nice way to override the access length
638aa59a485SFrederic Weisbecker 	 * Provide some defaults for now
639aa59a485SFrederic Weisbecker 	 */
640aa59a485SFrederic Weisbecker 	if (attr->bp_type == HW_BREAKPOINT_X)
641aa59a485SFrederic Weisbecker 		attr->bp_len = sizeof(long);
642aa59a485SFrederic Weisbecker 	else
6431b290d67SFrederic Weisbecker 		attr->bp_len = HW_BREAKPOINT_LEN_4;
644aa59a485SFrederic Weisbecker 
6451b290d67SFrederic Weisbecker 	attr->type = PERF_TYPE_BREAKPOINT;
6461b290d67SFrederic Weisbecker 
6471b290d67SFrederic Weisbecker 	return EVT_HANDLED;
6481b290d67SFrederic Weisbecker }
6491b290d67SFrederic Weisbecker 
65074d5b588SJaswinder Singh Rajput static int check_events(const char *str, unsigned int i)
65174d5b588SJaswinder Singh Rajput {
65261c45981SPaul Mackerras 	int n;
65374d5b588SJaswinder Singh Rajput 
65461c45981SPaul Mackerras 	n = strlen(event_symbols[i].symbol);
655b908debdSIngo Molnar 	if (!strncasecmp(str, event_symbols[i].symbol, n))
65661c45981SPaul Mackerras 		return n;
65761c45981SPaul Mackerras 
65861c45981SPaul Mackerras 	n = strlen(event_symbols[i].alias);
659b908debdSIngo Molnar 	if (n) {
660b908debdSIngo Molnar 		if (!strncasecmp(str, event_symbols[i].alias, n))
66161c45981SPaul Mackerras 			return n;
662b908debdSIngo Molnar 	}
663b908debdSIngo Molnar 
66461c45981SPaul Mackerras 	return 0;
66561c45981SPaul Mackerras }
66661c45981SPaul Mackerras 
667bcd3279fSFrederic Weisbecker static enum event_result
668cdd6c482SIngo Molnar parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
66961c45981SPaul Mackerras {
67061c45981SPaul Mackerras 	const char *str = *strp;
67161c45981SPaul Mackerras 	unsigned int i;
67261c45981SPaul Mackerras 	int n;
67361c45981SPaul Mackerras 
67461c45981SPaul Mackerras 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
67561c45981SPaul Mackerras 		n = check_events(str, i);
67661c45981SPaul Mackerras 		if (n > 0) {
67761c45981SPaul Mackerras 			attr->type = event_symbols[i].type;
67861c45981SPaul Mackerras 			attr->config = event_symbols[i].config;
67961c45981SPaul Mackerras 			*strp = str + n;
680bcd3279fSFrederic Weisbecker 			return EVT_HANDLED;
68161c45981SPaul Mackerras 		}
68261c45981SPaul Mackerras 	}
683bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
68461c45981SPaul Mackerras }
68561c45981SPaul Mackerras 
686bcd3279fSFrederic Weisbecker static enum event_result
687cdd6c482SIngo Molnar parse_raw_event(const char **strp, struct perf_event_attr *attr)
68861c45981SPaul Mackerras {
68961c45981SPaul Mackerras 	const char *str = *strp;
69061c45981SPaul Mackerras 	u64 config;
69161c45981SPaul Mackerras 	int n;
69261c45981SPaul Mackerras 
69361c45981SPaul Mackerras 	if (*str != 'r')
694bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
69561c45981SPaul Mackerras 	n = hex2u64(str + 1, &config);
69661c45981SPaul Mackerras 	if (n > 0) {
69761c45981SPaul Mackerras 		*strp = str + n + 1;
69861c45981SPaul Mackerras 		attr->type = PERF_TYPE_RAW;
69961c45981SPaul Mackerras 		attr->config = config;
700bcd3279fSFrederic Weisbecker 		return EVT_HANDLED;
70161c45981SPaul Mackerras 	}
702bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
70361c45981SPaul Mackerras }
70461c45981SPaul Mackerras 
705bcd3279fSFrederic Weisbecker static enum event_result
706cdd6c482SIngo Molnar parse_numeric_event(const char **strp, struct perf_event_attr *attr)
70761c45981SPaul Mackerras {
70861c45981SPaul Mackerras 	const char *str = *strp;
70961c45981SPaul Mackerras 	char *endp;
71061c45981SPaul Mackerras 	unsigned long type;
71161c45981SPaul Mackerras 	u64 config;
71261c45981SPaul Mackerras 
71361c45981SPaul Mackerras 	type = strtoul(str, &endp, 0);
71461c45981SPaul Mackerras 	if (endp > str && type < PERF_TYPE_MAX && *endp == ':') {
71561c45981SPaul Mackerras 		str = endp + 1;
71661c45981SPaul Mackerras 		config = strtoul(str, &endp, 0);
71761c45981SPaul Mackerras 		if (endp > str) {
71861c45981SPaul Mackerras 			attr->type = type;
71961c45981SPaul Mackerras 			attr->config = config;
72061c45981SPaul Mackerras 			*strp = endp;
721bcd3279fSFrederic Weisbecker 			return EVT_HANDLED;
72261c45981SPaul Mackerras 		}
72361c45981SPaul Mackerras 	}
724bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
72561c45981SPaul Mackerras }
72661c45981SPaul Mackerras 
727ceb53fbfSIngo Molnar static int
728cdd6c482SIngo Molnar parse_event_modifier(const char **strp, struct perf_event_attr *attr)
72961c45981SPaul Mackerras {
73061c45981SPaul Mackerras 	const char *str = *strp;
731ab608344SPeter Zijlstra 	int exclude = 0;
732ab608344SPeter Zijlstra 	int eu = 0, ek = 0, eh = 0, precise = 0;
73361c45981SPaul Mackerras 
734ceb53fbfSIngo Molnar 	if (!*str)
73561c45981SPaul Mackerras 		return 0;
736ceb53fbfSIngo Molnar 
737ceb53fbfSIngo Molnar 	if (*str++ != ':')
738ceb53fbfSIngo Molnar 		return -1;
739ceb53fbfSIngo Molnar 
74061c45981SPaul Mackerras 	while (*str) {
741ab608344SPeter Zijlstra 		if (*str == 'u') {
742ab608344SPeter Zijlstra 			if (!exclude)
743ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
74461c45981SPaul Mackerras 			eu = 0;
745ab608344SPeter Zijlstra 		} else if (*str == 'k') {
746ab608344SPeter Zijlstra 			if (!exclude)
747ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
74861c45981SPaul Mackerras 			ek = 0;
749ab608344SPeter Zijlstra 		} else if (*str == 'h') {
750ab608344SPeter Zijlstra 			if (!exclude)
751ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
75261c45981SPaul Mackerras 			eh = 0;
753ab608344SPeter Zijlstra 		} else if (*str == 'p') {
754ab608344SPeter Zijlstra 			precise++;
755ab608344SPeter Zijlstra 		} else
75661c45981SPaul Mackerras 			break;
757ab608344SPeter Zijlstra 
75861c45981SPaul Mackerras 		++str;
75961c45981SPaul Mackerras 	}
760ceb53fbfSIngo Molnar 	if (str < *strp + 2)
761ceb53fbfSIngo Molnar 		return -1;
762ceb53fbfSIngo Molnar 
76361c45981SPaul Mackerras 	*strp = str;
764ceb53fbfSIngo Molnar 
76561c45981SPaul Mackerras 	attr->exclude_user   = eu;
76661c45981SPaul Mackerras 	attr->exclude_kernel = ek;
76761c45981SPaul Mackerras 	attr->exclude_hv     = eh;
768ab608344SPeter Zijlstra 	attr->precise_ip     = precise;
769ceb53fbfSIngo Molnar 
77074d5b588SJaswinder Singh Rajput 	return 0;
77174d5b588SJaswinder Singh Rajput }
77274d5b588SJaswinder Singh Rajput 
77386470930SIngo Molnar /*
77486470930SIngo Molnar  * Each event can have multiple symbolic names.
77586470930SIngo Molnar  * Symbolic names are (almost) exactly matched.
77686470930SIngo Molnar  */
777bcd3279fSFrederic Weisbecker static enum event_result
77817ea1b70SArnaldo Carvalho de Melo parse_event_symbols(const struct option *opt, const char **str,
77917ea1b70SArnaldo Carvalho de Melo 		    struct perf_event_attr *attr)
78086470930SIngo Molnar {
781bcd3279fSFrederic Weisbecker 	enum event_result ret;
78286470930SIngo Molnar 
78317ea1b70SArnaldo Carvalho de Melo 	ret = parse_tracepoint_event(opt, str, attr);
784bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
785bcd3279fSFrederic Weisbecker 		goto modifier;
786bcd3279fSFrederic Weisbecker 
787bcd3279fSFrederic Weisbecker 	ret = parse_raw_event(str, attr);
788bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
789bcd3279fSFrederic Weisbecker 		goto modifier;
790bcd3279fSFrederic Weisbecker 
791bcd3279fSFrederic Weisbecker 	ret = parse_numeric_event(str, attr);
792bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
793bcd3279fSFrederic Weisbecker 		goto modifier;
794bcd3279fSFrederic Weisbecker 
795bcd3279fSFrederic Weisbecker 	ret = parse_symbolic_event(str, attr);
796bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
797bcd3279fSFrederic Weisbecker 		goto modifier;
798bcd3279fSFrederic Weisbecker 
799bcd3279fSFrederic Weisbecker 	ret = parse_generic_hw_event(str, attr);
800bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
801bcd3279fSFrederic Weisbecker 		goto modifier;
802bcd3279fSFrederic Weisbecker 
8031b290d67SFrederic Weisbecker 	ret = parse_breakpoint_event(str, attr);
8041b290d67SFrederic Weisbecker 	if (ret != EVT_FAILED)
8051b290d67SFrederic Weisbecker 		goto modifier;
8061b290d67SFrederic Weisbecker 
80785df6f68SMarti Raudsepp 	fprintf(stderr, "invalid or unsupported event: '%s'\n", *str);
80885df6f68SMarti Raudsepp 	fprintf(stderr, "Run 'perf list' for a list of valid events\n");
809bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
810bcd3279fSFrederic Weisbecker 
811bcd3279fSFrederic Weisbecker modifier:
812ceb53fbfSIngo Molnar 	if (parse_event_modifier(str, attr) < 0) {
813ceb53fbfSIngo Molnar 		fprintf(stderr, "invalid event modifier: '%s'\n", *str);
814ceb53fbfSIngo Molnar 		fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n");
815ceb53fbfSIngo Molnar 
816ceb53fbfSIngo Molnar 		return EVT_FAILED;
817ceb53fbfSIngo Molnar 	}
81886470930SIngo Molnar 
819bcd3279fSFrederic Weisbecker 	return ret;
82086470930SIngo Molnar }
82186470930SIngo Molnar 
822361c99a6SArnaldo Carvalho de Melo int parse_events(const struct option *opt, const char *str, int unset __used)
82386470930SIngo Molnar {
824361c99a6SArnaldo Carvalho de Melo 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
825cdd6c482SIngo Molnar 	struct perf_event_attr attr;
826bcd3279fSFrederic Weisbecker 	enum event_result ret;
827f0c55bcfSStephane Eranian 	const char *ostr;
82886470930SIngo Molnar 
82961c45981SPaul Mackerras 	for (;;) {
830f0c55bcfSStephane Eranian 		ostr = str;
83161c45981SPaul Mackerras 		memset(&attr, 0, sizeof(attr));
83217ea1b70SArnaldo Carvalho de Melo 		ret = parse_event_symbols(opt, &str, &attr);
833bcd3279fSFrederic Weisbecker 		if (ret == EVT_FAILED)
83461c45981SPaul Mackerras 			return -1;
83561c45981SPaul Mackerras 
83661c45981SPaul Mackerras 		if (!(*str == 0 || *str == ',' || isspace(*str)))
83761c45981SPaul Mackerras 			return -1;
83886470930SIngo Molnar 
839bcd3279fSFrederic Weisbecker 		if (ret != EVT_HANDLED_ALL) {
84069aad6f1SArnaldo Carvalho de Melo 			struct perf_evsel *evsel;
841361c99a6SArnaldo Carvalho de Melo 			evsel = perf_evsel__new(&attr, evlist->nr_entries);
84269aad6f1SArnaldo Carvalho de Melo 			if (evsel == NULL)
84369aad6f1SArnaldo Carvalho de Melo 				return -1;
844361c99a6SArnaldo Carvalho de Melo 			perf_evlist__add(evlist, evsel);
845f0c55bcfSStephane Eranian 
846f0c55bcfSStephane Eranian 			evsel->name = calloc(str - ostr + 1, 1);
847f0c55bcfSStephane Eranian 			if (!evsel->name)
848f0c55bcfSStephane Eranian 				return -1;
849f0c55bcfSStephane Eranian 			strncpy(evsel->name, ostr, str - ostr);
850bcd3279fSFrederic Weisbecker 		}
85186470930SIngo Molnar 
85261c45981SPaul Mackerras 		if (*str == 0)
85361c45981SPaul Mackerras 			break;
85461c45981SPaul Mackerras 		if (*str == ',')
85561c45981SPaul Mackerras 			++str;
85661c45981SPaul Mackerras 		while (isspace(*str))
85761c45981SPaul Mackerras 			++str;
85886470930SIngo Molnar 	}
85986470930SIngo Molnar 
86086470930SIngo Molnar 	return 0;
86186470930SIngo Molnar }
86286470930SIngo Molnar 
863361c99a6SArnaldo Carvalho de Melo int parse_filter(const struct option *opt, const char *str,
864c171b552SLi Zefan 		 int unset __used)
865c171b552SLi Zefan {
866361c99a6SArnaldo Carvalho de Melo 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
86769aad6f1SArnaldo Carvalho de Melo 	struct perf_evsel *last = NULL;
868c171b552SLi Zefan 
869361c99a6SArnaldo Carvalho de Melo 	if (evlist->nr_entries > 0)
870361c99a6SArnaldo Carvalho de Melo 		last = list_entry(evlist->entries.prev, struct perf_evsel, node);
87169aad6f1SArnaldo Carvalho de Melo 
87269aad6f1SArnaldo Carvalho de Melo 	if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
873c171b552SLi Zefan 		fprintf(stderr,
874c171b552SLi Zefan 			"-F option should follow a -e tracepoint option\n");
875c171b552SLi Zefan 		return -1;
876c171b552SLi Zefan 	}
877c171b552SLi Zefan 
87869aad6f1SArnaldo Carvalho de Melo 	last->filter = strdup(str);
87969aad6f1SArnaldo Carvalho de Melo 	if (last->filter == NULL) {
880c171b552SLi Zefan 		fprintf(stderr, "not enough memory to hold filter string\n");
881c171b552SLi Zefan 		return -1;
882c171b552SLi Zefan 	}
883c171b552SLi Zefan 
884c171b552SLi Zefan 	return 0;
885c171b552SLi Zefan }
886c171b552SLi Zefan 
88786470930SIngo Molnar static const char * const event_type_descriptors[] = {
88886470930SIngo Molnar 	"Hardware event",
88986470930SIngo Molnar 	"Software event",
89086470930SIngo Molnar 	"Tracepoint event",
89186470930SIngo Molnar 	"Hardware cache event",
89241bdcb23SLiming Wang 	"Raw hardware event descriptor",
89341bdcb23SLiming Wang 	"Hardware breakpoint",
89486470930SIngo Molnar };
89586470930SIngo Molnar 
89686470930SIngo Molnar /*
897f6bdafefSJason Baron  * Print the events from <debugfs_mount_point>/tracing/events
898f6bdafefSJason Baron  */
899f6bdafefSJason Baron 
900668b8788SArnaldo Carvalho de Melo void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
901f6bdafefSJason Baron {
902f6bdafefSJason Baron 	DIR *sys_dir, *evt_dir;
903f6bdafefSJason Baron 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
904f6bdafefSJason Baron 	char evt_path[MAXPATHLEN];
905725b1368SEric Dumazet 	char dir_path[MAXPATHLEN];
906f6bdafefSJason Baron 
907549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
908f6bdafefSJason Baron 		return;
909f6bdafefSJason Baron 
9105beeded1SJason Baron 	sys_dir = opendir(debugfs_path);
911f6bdafefSJason Baron 	if (!sys_dir)
912725b1368SEric Dumazet 		return;
913f6bdafefSJason Baron 
9146b58e7f1SUlrich Drepper 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
915668b8788SArnaldo Carvalho de Melo 		if (subsys_glob != NULL &&
916668b8788SArnaldo Carvalho de Melo 		    !strglobmatch(sys_dirent.d_name, subsys_glob))
917668b8788SArnaldo Carvalho de Melo 			continue;
918725b1368SEric Dumazet 
919725b1368SEric Dumazet 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
920725b1368SEric Dumazet 			 sys_dirent.d_name);
921725b1368SEric Dumazet 		evt_dir = opendir(dir_path);
922725b1368SEric Dumazet 		if (!evt_dir)
9236b58e7f1SUlrich Drepper 			continue;
924725b1368SEric Dumazet 
9256b58e7f1SUlrich Drepper 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
926668b8788SArnaldo Carvalho de Melo 			if (event_glob != NULL &&
927668b8788SArnaldo Carvalho de Melo 			    !strglobmatch(evt_dirent.d_name, event_glob))
928668b8788SArnaldo Carvalho de Melo 				continue;
929668b8788SArnaldo Carvalho de Melo 
930f6bdafefSJason Baron 			snprintf(evt_path, MAXPATHLEN, "%s:%s",
931f6bdafefSJason Baron 				 sys_dirent.d_name, evt_dirent.d_name);
932689d3018SMarti Raudsepp 			printf("  %-42s [%s]\n", evt_path,
93341bdcb23SLiming Wang 				event_type_descriptors[PERF_TYPE_TRACEPOINT]);
934f6bdafefSJason Baron 		}
935f6bdafefSJason Baron 		closedir(evt_dir);
936f6bdafefSJason Baron 	}
937f6bdafefSJason Baron 	closedir(sys_dir);
938f6bdafefSJason Baron }
939f6bdafefSJason Baron 
940f6bdafefSJason Baron /*
94120c457b8SThomas Renninger  * Check whether event is in <debugfs_mount_point>/tracing/events
94220c457b8SThomas Renninger  */
94320c457b8SThomas Renninger 
94420c457b8SThomas Renninger int is_valid_tracepoint(const char *event_string)
94520c457b8SThomas Renninger {
94620c457b8SThomas Renninger 	DIR *sys_dir, *evt_dir;
94720c457b8SThomas Renninger 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
94820c457b8SThomas Renninger 	char evt_path[MAXPATHLEN];
94920c457b8SThomas Renninger 	char dir_path[MAXPATHLEN];
95020c457b8SThomas Renninger 
95120c457b8SThomas Renninger 	if (debugfs_valid_mountpoint(debugfs_path))
95220c457b8SThomas Renninger 		return 0;
95320c457b8SThomas Renninger 
95420c457b8SThomas Renninger 	sys_dir = opendir(debugfs_path);
95520c457b8SThomas Renninger 	if (!sys_dir)
95620c457b8SThomas Renninger 		return 0;
95720c457b8SThomas Renninger 
95820c457b8SThomas Renninger 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
95920c457b8SThomas Renninger 
96020c457b8SThomas Renninger 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
96120c457b8SThomas Renninger 			 sys_dirent.d_name);
96220c457b8SThomas Renninger 		evt_dir = opendir(dir_path);
96320c457b8SThomas Renninger 		if (!evt_dir)
96420c457b8SThomas Renninger 			continue;
96520c457b8SThomas Renninger 
96620c457b8SThomas Renninger 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
96720c457b8SThomas Renninger 			snprintf(evt_path, MAXPATHLEN, "%s:%s",
96820c457b8SThomas Renninger 				 sys_dirent.d_name, evt_dirent.d_name);
96920c457b8SThomas Renninger 			if (!strcmp(evt_path, event_string)) {
97020c457b8SThomas Renninger 				closedir(evt_dir);
97120c457b8SThomas Renninger 				closedir(sys_dir);
97220c457b8SThomas Renninger 				return 1;
97320c457b8SThomas Renninger 			}
97420c457b8SThomas Renninger 		}
97520c457b8SThomas Renninger 		closedir(evt_dir);
97620c457b8SThomas Renninger 	}
97720c457b8SThomas Renninger 	closedir(sys_dir);
97820c457b8SThomas Renninger 	return 0;
97920c457b8SThomas Renninger }
98020c457b8SThomas Renninger 
981668b8788SArnaldo Carvalho de Melo void print_events_type(u8 type)
982668b8788SArnaldo Carvalho de Melo {
983668b8788SArnaldo Carvalho de Melo 	struct event_symbol *syms = event_symbols;
984668b8788SArnaldo Carvalho de Melo 	unsigned int i;
985668b8788SArnaldo Carvalho de Melo 	char name[64];
986668b8788SArnaldo Carvalho de Melo 
987668b8788SArnaldo Carvalho de Melo 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
988668b8788SArnaldo Carvalho de Melo 		if (type != syms->type)
989668b8788SArnaldo Carvalho de Melo 			continue;
990668b8788SArnaldo Carvalho de Melo 
991668b8788SArnaldo Carvalho de Melo 		if (strlen(syms->alias))
992668b8788SArnaldo Carvalho de Melo 			snprintf(name, sizeof(name),  "%s OR %s",
993668b8788SArnaldo Carvalho de Melo 				 syms->symbol, syms->alias);
994668b8788SArnaldo Carvalho de Melo 		else
995668b8788SArnaldo Carvalho de Melo 			snprintf(name, sizeof(name), "%s", syms->symbol);
996668b8788SArnaldo Carvalho de Melo 
997668b8788SArnaldo Carvalho de Melo 		printf("  %-42s [%s]\n", name,
998668b8788SArnaldo Carvalho de Melo 			event_type_descriptors[type]);
999668b8788SArnaldo Carvalho de Melo 	}
1000668b8788SArnaldo Carvalho de Melo }
1001668b8788SArnaldo Carvalho de Melo 
1002668b8788SArnaldo Carvalho de Melo int print_hwcache_events(const char *event_glob)
1003668b8788SArnaldo Carvalho de Melo {
1004668b8788SArnaldo Carvalho de Melo 	unsigned int type, op, i, printed = 0;
1005668b8788SArnaldo Carvalho de Melo 
1006668b8788SArnaldo Carvalho de Melo 	for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
1007668b8788SArnaldo Carvalho de Melo 		for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
1008668b8788SArnaldo Carvalho de Melo 			/* skip invalid cache type */
1009668b8788SArnaldo Carvalho de Melo 			if (!is_cache_op_valid(type, op))
1010668b8788SArnaldo Carvalho de Melo 				continue;
1011668b8788SArnaldo Carvalho de Melo 
1012668b8788SArnaldo Carvalho de Melo 			for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
1013668b8788SArnaldo Carvalho de Melo 				char *name = event_cache_name(type, op, i);
1014668b8788SArnaldo Carvalho de Melo 
1015668b8788SArnaldo Carvalho de Melo 				if (event_glob != NULL &&
1016668b8788SArnaldo Carvalho de Melo 				    !strglobmatch(name, event_glob))
1017668b8788SArnaldo Carvalho de Melo 					continue;
1018668b8788SArnaldo Carvalho de Melo 
1019668b8788SArnaldo Carvalho de Melo 				printf("  %-42s [%s]\n", name,
1020668b8788SArnaldo Carvalho de Melo 					event_type_descriptors[PERF_TYPE_HW_CACHE]);
1021668b8788SArnaldo Carvalho de Melo 				++printed;
1022668b8788SArnaldo Carvalho de Melo 			}
1023668b8788SArnaldo Carvalho de Melo 		}
1024668b8788SArnaldo Carvalho de Melo 	}
1025668b8788SArnaldo Carvalho de Melo 
1026668b8788SArnaldo Carvalho de Melo 	return printed;
1027668b8788SArnaldo Carvalho de Melo }
1028668b8788SArnaldo Carvalho de Melo 
102920c457b8SThomas Renninger /*
103086470930SIngo Molnar  * Print the help text for the event symbols:
103186470930SIngo Molnar  */
1032668b8788SArnaldo Carvalho de Melo void print_events(const char *event_glob)
103386470930SIngo Molnar {
103486470930SIngo Molnar 	struct event_symbol *syms = event_symbols;
1035668b8788SArnaldo Carvalho de Melo 	unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
103674d5b588SJaswinder Singh Rajput 	char name[40];
103786470930SIngo Molnar 
1038689d3018SMarti Raudsepp 	printf("\n");
1039689d3018SMarti Raudsepp 	printf("List of pre-defined events (to be used in -e):\n");
104086470930SIngo Molnar 
104186470930SIngo Molnar 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
104241bdcb23SLiming Wang 		type = syms->type;
104386470930SIngo Molnar 
1044668b8788SArnaldo Carvalho de Melo 		if (type != prev_type && printed) {
1045689d3018SMarti Raudsepp 			printf("\n");
1046668b8788SArnaldo Carvalho de Melo 			printed = 0;
1047668b8788SArnaldo Carvalho de Melo 			ntypes_printed++;
1048668b8788SArnaldo Carvalho de Melo 		}
1049668b8788SArnaldo Carvalho de Melo 
1050668b8788SArnaldo Carvalho de Melo 		if (event_glob != NULL &&
1051668b8788SArnaldo Carvalho de Melo 		    !(strglobmatch(syms->symbol, event_glob) ||
1052668b8788SArnaldo Carvalho de Melo 		      (syms->alias && strglobmatch(syms->alias, event_glob))))
1053668b8788SArnaldo Carvalho de Melo 			continue;
105486470930SIngo Molnar 
105574d5b588SJaswinder Singh Rajput 		if (strlen(syms->alias))
105674d5b588SJaswinder Singh Rajput 			sprintf(name, "%s OR %s", syms->symbol, syms->alias);
105774d5b588SJaswinder Singh Rajput 		else
105874d5b588SJaswinder Singh Rajput 			strcpy(name, syms->symbol);
1059689d3018SMarti Raudsepp 		printf("  %-42s [%s]\n", name,
106086470930SIngo Molnar 			event_type_descriptors[type]);
106186470930SIngo Molnar 
106286470930SIngo Molnar 		prev_type = type;
1063668b8788SArnaldo Carvalho de Melo 		++printed;
106486470930SIngo Molnar 	}
106586470930SIngo Molnar 
1066668b8788SArnaldo Carvalho de Melo 	if (ntypes_printed) {
1067668b8788SArnaldo Carvalho de Melo 		printed = 0;
1068689d3018SMarti Raudsepp 		printf("\n");
1069668b8788SArnaldo Carvalho de Melo 	}
1070668b8788SArnaldo Carvalho de Melo 	print_hwcache_events(event_glob);
107173c24cb8SJaswinder Singh Rajput 
1072668b8788SArnaldo Carvalho de Melo 	if (event_glob != NULL)
1073668b8788SArnaldo Carvalho de Melo 		return;
107473c24cb8SJaswinder Singh Rajput 
1075689d3018SMarti Raudsepp 	printf("\n");
107641bdcb23SLiming Wang 	printf("  %-42s [%s]\n",
10771cf4a063SArnaldo Carvalho de Melo 		"rNNN (see 'perf list --help' on how to encode it)",
10781cf4a063SArnaldo Carvalho de Melo 	       event_type_descriptors[PERF_TYPE_RAW]);
1079689d3018SMarti Raudsepp 	printf("\n");
108086470930SIngo Molnar 
108141bdcb23SLiming Wang 	printf("  %-42s [%s]\n",
108241bdcb23SLiming Wang 			"mem:<addr>[:access]",
108341bdcb23SLiming Wang 			event_type_descriptors[PERF_TYPE_BREAKPOINT]);
10841b290d67SFrederic Weisbecker 	printf("\n");
10851b290d67SFrederic Weisbecker 
1086668b8788SArnaldo Carvalho de Melo 	print_tracepoint_events(NULL, NULL);
1087f6bdafefSJason Baron 
108886470930SIngo Molnar 	exit(129);
108986470930SIngo Molnar }
1090