| Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 1 | #include "../../../include/linux/hw_breakpoint.h" | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 2 | #include "util.h" | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 3 | #include "../perf.h" | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 4 | #include "evsel.h" | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 5 | #include "parse-options.h" | 
|  | 6 | #include "parse-events.h" | 
|  | 7 | #include "exec_cmd.h" | 
| Arnaldo Carvalho de Melo | a0055ae | 2009-06-01 17:50:19 -0300 | [diff] [blame] | 8 | #include "string.h" | 
| Arnaldo Carvalho de Melo | 5aab621 | 2010-03-25 19:59:00 -0300 | [diff] [blame] | 9 | #include "symbol.h" | 
| Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 10 | #include "cache.h" | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 11 | #include "header.h" | 
| Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame] | 12 | #include "debugfs.h" | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 13 |  | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 14 | int				nr_counters; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 15 |  | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 16 | LIST_HEAD(evsel_list); | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 17 |  | 
|  | 18 | struct event_symbol { | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 19 | u8		type; | 
|  | 20 | u64		config; | 
|  | 21 | const char	*symbol; | 
|  | 22 | const char	*alias; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 23 | }; | 
|  | 24 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 25 | enum event_result { | 
|  | 26 | EVT_FAILED, | 
|  | 27 | EVT_HANDLED, | 
|  | 28 | EVT_HANDLED_ALL | 
|  | 29 | }; | 
|  | 30 |  | 
| Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 31 | char debugfs_path[MAXPATHLEN]; | 
|  | 32 |  | 
| Jaswinder Singh Rajput | 51e2684 | 2009-06-22 16:43:14 +0530 | [diff] [blame] | 33 | #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x | 
|  | 34 | #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 35 |  | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 36 | static struct event_symbol event_symbols[] = { | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 37 | { CHW(CPU_CYCLES),		"cpu-cycles",		"cycles"	}, | 
|  | 38 | { CHW(INSTRUCTIONS),		"instructions",		""		}, | 
|  | 39 | { CHW(CACHE_REFERENCES),	"cache-references",	""		}, | 
|  | 40 | { CHW(CACHE_MISSES),		"cache-misses",		""		}, | 
|  | 41 | { CHW(BRANCH_INSTRUCTIONS),	"branch-instructions",	"branches"	}, | 
|  | 42 | { CHW(BRANCH_MISSES),		"branch-misses",	""		}, | 
|  | 43 | { CHW(BUS_CYCLES),		"bus-cycles",		""		}, | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 44 |  | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 45 | { CSW(CPU_CLOCK),		"cpu-clock",		""		}, | 
|  | 46 | { CSW(TASK_CLOCK),		"task-clock",		""		}, | 
| Jaswinder Singh Rajput | c0c22db | 2009-06-22 20:47:26 +0530 | [diff] [blame] | 47 | { CSW(PAGE_FAULTS),		"page-faults",		"faults"	}, | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 48 | { CSW(PAGE_FAULTS_MIN),	"minor-faults",		""		}, | 
|  | 49 | { CSW(PAGE_FAULTS_MAJ),	"major-faults",		""		}, | 
|  | 50 | { CSW(CONTEXT_SWITCHES),	"context-switches",	"cs"		}, | 
|  | 51 | { CSW(CPU_MIGRATIONS),	"cpu-migrations",	"migrations"	}, | 
| Anton Blanchard | f7d7986 | 2009-10-18 01:09:29 +0000 | [diff] [blame] | 52 | { CSW(ALIGNMENT_FAULTS),	"alignment-faults",	""		}, | 
|  | 53 | { CSW(EMULATION_FAULTS),	"emulation-faults",	""		}, | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 54 | }; | 
|  | 55 |  | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 56 | #define __PERF_EVENT_FIELD(config, name) \ | 
|  | 57 | ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT) | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 58 |  | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 59 | #define PERF_EVENT_RAW(config)	__PERF_EVENT_FIELD(config, RAW) | 
|  | 60 | #define PERF_EVENT_CONFIG(config)	__PERF_EVENT_FIELD(config, CONFIG) | 
|  | 61 | #define PERF_EVENT_TYPE(config)	__PERF_EVENT_FIELD(config, TYPE) | 
|  | 62 | #define PERF_EVENT_ID(config)		__PERF_EVENT_FIELD(config, EVENT) | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 63 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 64 | static const char *hw_event_names[] = { | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 65 | "cycles", | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 66 | "instructions", | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 67 | "cache-references", | 
|  | 68 | "cache-misses", | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 69 | "branches", | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 70 | "branch-misses", | 
|  | 71 | "bus-cycles", | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 72 | }; | 
|  | 73 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 74 | static const char *sw_event_names[] = { | 
| Ingo Molnar | 44175b6 | 2009-06-13 13:35:00 +0200 | [diff] [blame] | 75 | "cpu-clock-msecs", | 
|  | 76 | "task-clock-msecs", | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 77 | "page-faults", | 
|  | 78 | "context-switches", | 
|  | 79 | "CPU-migrations", | 
|  | 80 | "minor-faults", | 
|  | 81 | "major-faults", | 
| Anton Blanchard | f7d7986 | 2009-10-18 01:09:29 +0000 | [diff] [blame] | 82 | "alignment-faults", | 
|  | 83 | "emulation-faults", | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 84 | }; | 
|  | 85 |  | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 86 | #define MAX_ALIASES 8 | 
|  | 87 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 88 | static const char *hw_cache[][MAX_ALIASES] = { | 
| Anton Blanchard | 9590b7b | 2009-07-06 22:01:31 +1000 | [diff] [blame] | 89 | { "L1-dcache",	"l1-d",		"l1d",		"L1-data",		}, | 
|  | 90 | { "L1-icache",	"l1-i",		"l1i",		"L1-instruction",	}, | 
| Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 91 | { "LLC",	"L2"							}, | 
|  | 92 | { "dTLB",	"d-tlb",	"Data-TLB",				}, | 
|  | 93 | { "iTLB",	"i-tlb",	"Instruction-TLB",			}, | 
|  | 94 | { "branch",	"branches",	"bpu",		"btb",		"bpc",	}, | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 95 | }; | 
|  | 96 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 97 | static const char *hw_cache_op[][MAX_ALIASES] = { | 
| Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 98 | { "load",	"loads",	"read",					}, | 
|  | 99 | { "store",	"stores",	"write",				}, | 
|  | 100 | { "prefetch",	"prefetches",	"speculative-read", "speculative-load",	}, | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 101 | }; | 
|  | 102 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 103 | static const char *hw_cache_result[][MAX_ALIASES] = { | 
| Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 104 | { "refs",	"Reference",	"ops",		"access",		}, | 
|  | 105 | { "misses",	"miss",							}, | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 106 | }; | 
|  | 107 |  | 
| Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 108 | #define C(x)		PERF_COUNT_HW_CACHE_##x | 
|  | 109 | #define CACHE_READ	(1 << C(OP_READ)) | 
|  | 110 | #define CACHE_WRITE	(1 << C(OP_WRITE)) | 
|  | 111 | #define CACHE_PREFETCH	(1 << C(OP_PREFETCH)) | 
|  | 112 | #define COP(x)		(1 << x) | 
|  | 113 |  | 
|  | 114 | /* | 
|  | 115 | * cache operartion stat | 
|  | 116 | * L1I : Read and prefetch only | 
|  | 117 | * ITLB and BPU : Read-only | 
|  | 118 | */ | 
|  | 119 | static unsigned long hw_cache_stat[C(MAX)] = { | 
|  | 120 | [C(L1D)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | 
|  | 121 | [C(L1I)]	= (CACHE_READ | CACHE_PREFETCH), | 
|  | 122 | [C(LL)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | 
|  | 123 | [C(DTLB)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), | 
|  | 124 | [C(ITLB)]	= (CACHE_READ), | 
|  | 125 | [C(BPU)]	= (CACHE_READ), | 
|  | 126 | }; | 
|  | 127 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 128 | #define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \ | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 129 | while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \ | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 130 | if (sys_dirent.d_type == DT_DIR &&				       \ | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 131 | (strcmp(sys_dirent.d_name, ".")) &&				       \ | 
|  | 132 | (strcmp(sys_dirent.d_name, ".."))) | 
|  | 133 |  | 
| Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 134 | static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir) | 
|  | 135 | { | 
|  | 136 | char evt_path[MAXPATHLEN]; | 
|  | 137 | int fd; | 
|  | 138 |  | 
|  | 139 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | 
|  | 140 | sys_dir->d_name, evt_dir->d_name); | 
|  | 141 | fd = open(evt_path, O_RDONLY); | 
|  | 142 | if (fd < 0) | 
|  | 143 | return -EINVAL; | 
|  | 144 | close(fd); | 
|  | 145 |  | 
|  | 146 | return 0; | 
|  | 147 | } | 
|  | 148 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 149 | #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \ | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 150 | while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \ | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 151 | if (evt_dirent.d_type == DT_DIR &&				       \ | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 152 | (strcmp(evt_dirent.d_name, ".")) &&				       \ | 
| Peter Zijlstra | ae07b63 | 2009-08-06 16:48:54 +0200 | [diff] [blame] | 153 | (strcmp(evt_dirent.d_name, "..")) &&				       \ | 
|  | 154 | (!tp_event_has_id(&sys_dirent, &evt_dirent))) | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 155 |  | 
| Li Zefan | 270bbbe | 2009-09-17 16:34:51 +0800 | [diff] [blame] | 156 | #define MAX_EVENT_LENGTH 512 | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 157 |  | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 158 |  | 
| Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 159 | struct tracepoint_path *tracepoint_id_to_path(u64 config) | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 160 | { | 
| Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 161 | struct tracepoint_path *path = NULL; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 162 | DIR *sys_dir, *evt_dir; | 
|  | 163 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 164 | char id_buf[4]; | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 165 | int fd; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 166 | u64 id; | 
|  | 167 | char evt_path[MAXPATHLEN]; | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 168 | char dir_path[MAXPATHLEN]; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 169 |  | 
| Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame] | 170 | if (debugfs_valid_mountpoint(debugfs_path)) | 
| Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 171 | return NULL; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 172 |  | 
| Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 173 | sys_dir = opendir(debugfs_path); | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 174 | if (!sys_dir) | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 175 | return NULL; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 176 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 177 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 178 |  | 
|  | 179 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, | 
|  | 180 | sys_dirent.d_name); | 
|  | 181 | evt_dir = opendir(dir_path); | 
|  | 182 | if (!evt_dir) | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 183 | continue; | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 184 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 185 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 186 |  | 
|  | 187 | snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 188 | evt_dirent.d_name); | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 189 | fd = open(evt_path, O_RDONLY); | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 190 | if (fd < 0) | 
|  | 191 | continue; | 
|  | 192 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | 
|  | 193 | close(fd); | 
|  | 194 | continue; | 
|  | 195 | } | 
|  | 196 | close(fd); | 
|  | 197 | id = atoll(id_buf); | 
|  | 198 | if (id == config) { | 
|  | 199 | closedir(evt_dir); | 
|  | 200 | closedir(sys_dir); | 
| Julia Lawall | 59b4cae | 2009-12-06 10:16:30 +0100 | [diff] [blame] | 201 | path = zalloc(sizeof(*path)); | 
| Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 202 | path->system = malloc(MAX_EVENT_LENGTH); | 
|  | 203 | if (!path->system) { | 
|  | 204 | free(path); | 
|  | 205 | return NULL; | 
|  | 206 | } | 
|  | 207 | path->name = malloc(MAX_EVENT_LENGTH); | 
|  | 208 | if (!path->name) { | 
|  | 209 | free(path->system); | 
|  | 210 | free(path); | 
|  | 211 | return NULL; | 
|  | 212 | } | 
|  | 213 | strncpy(path->system, sys_dirent.d_name, | 
|  | 214 | MAX_EVENT_LENGTH); | 
|  | 215 | strncpy(path->name, evt_dirent.d_name, | 
|  | 216 | MAX_EVENT_LENGTH); | 
|  | 217 | return path; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 218 | } | 
|  | 219 | } | 
|  | 220 | closedir(evt_dir); | 
|  | 221 | } | 
|  | 222 |  | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 223 | closedir(sys_dir); | 
| Frederic Weisbecker | 1ef2ed1 | 2009-08-28 03:09:58 +0200 | [diff] [blame] | 224 | return NULL; | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1) | 
|  | 228 | static const char *tracepoint_id_to_name(u64 config) | 
|  | 229 | { | 
|  | 230 | static char buf[TP_PATH_LEN]; | 
|  | 231 | struct tracepoint_path *path; | 
|  | 232 |  | 
|  | 233 | path = tracepoint_id_to_path(config); | 
|  | 234 | if (path) { | 
|  | 235 | snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name); | 
|  | 236 | free(path->name); | 
|  | 237 | free(path->system); | 
|  | 238 | free(path); | 
|  | 239 | } else | 
|  | 240 | snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown"); | 
|  | 241 |  | 
|  | 242 | return buf; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 243 | } | 
|  | 244 |  | 
| Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 245 | static int is_cache_op_valid(u8 cache_type, u8 cache_op) | 
|  | 246 | { | 
|  | 247 | if (hw_cache_stat[cache_type] & COP(cache_op)) | 
|  | 248 | return 1;	/* valid */ | 
|  | 249 | else | 
|  | 250 | return 0;	/* invalid */ | 
|  | 251 | } | 
|  | 252 |  | 
| Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 253 | static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result) | 
|  | 254 | { | 
|  | 255 | static char name[50]; | 
|  | 256 |  | 
|  | 257 | if (cache_result) { | 
|  | 258 | sprintf(name, "%s-%s-%s", hw_cache[cache_type][0], | 
|  | 259 | hw_cache_op[cache_op][0], | 
|  | 260 | hw_cache_result[cache_result][0]); | 
|  | 261 | } else { | 
|  | 262 | sprintf(name, "%s-%s", hw_cache[cache_type][0], | 
|  | 263 | hw_cache_op[cache_op][1]); | 
|  | 264 | } | 
|  | 265 |  | 
|  | 266 | return name; | 
|  | 267 | } | 
|  | 268 |  | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 269 | const char *event_name(struct perf_evsel *evsel) | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 270 | { | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 271 | u64 config = evsel->attr.config; | 
|  | 272 | int type = evsel->attr.type; | 
| Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 273 |  | 
|  | 274 | return __event_name(type, config); | 
|  | 275 | } | 
|  | 276 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 277 | const char *__event_name(int type, u64 config) | 
| Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 278 | { | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 279 | static char buf[32]; | 
|  | 280 |  | 
| Peter Zijlstra | 8f18aec | 2009-08-06 19:40:28 +0200 | [diff] [blame] | 281 | if (type == PERF_TYPE_RAW) { | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 282 | sprintf(buf, "raw 0x%llx", config); | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 283 | return buf; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | switch (type) { | 
|  | 287 | case PERF_TYPE_HARDWARE: | 
| Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 288 | if (config < PERF_COUNT_HW_MAX) | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 289 | return hw_event_names[config]; | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 290 | return "unknown-hardware"; | 
|  | 291 |  | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 292 | case PERF_TYPE_HW_CACHE: { | 
| Paul Mackerras | 9cffa8d | 2009-06-19 22:21:42 +1000 | [diff] [blame] | 293 | u8 cache_type, cache_op, cache_result; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 294 |  | 
|  | 295 | cache_type   = (config >>  0) & 0xff; | 
|  | 296 | if (cache_type > PERF_COUNT_HW_CACHE_MAX) | 
|  | 297 | return "unknown-ext-hardware-cache-type"; | 
|  | 298 |  | 
|  | 299 | cache_op     = (config >>  8) & 0xff; | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 300 | if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX) | 
|  | 301 | return "unknown-ext-hardware-cache-op"; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 302 |  | 
|  | 303 | cache_result = (config >> 16) & 0xff; | 
| Ingo Molnar | 8faf3b5 | 2009-06-06 13:58:12 +0200 | [diff] [blame] | 304 | if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX) | 
|  | 305 | return "unknown-ext-hardware-cache-result"; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 306 |  | 
| Jaswinder Singh Rajput | 06813f6 | 2009-06-25 17:16:07 +0530 | [diff] [blame] | 307 | if (!is_cache_op_valid(cache_type, cache_op)) | 
|  | 308 | return "invalid-cache"; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 309 |  | 
| Jaswinder Singh Rajput | e5c5954 | 2009-06-25 18:25:22 +0530 | [diff] [blame] | 310 | return event_cache_name(cache_type, cache_op, cache_result); | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 311 | } | 
|  | 312 |  | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 313 | case PERF_TYPE_SOFTWARE: | 
| Peter Zijlstra | f4dbfa8 | 2009-06-11 14:06:28 +0200 | [diff] [blame] | 314 | if (config < PERF_COUNT_SW_MAX) | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 315 | return sw_event_names[config]; | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 316 | return "unknown-software"; | 
|  | 317 |  | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 318 | case PERF_TYPE_TRACEPOINT: | 
|  | 319 | return tracepoint_id_to_name(config); | 
|  | 320 |  | 
| Ingo Molnar | 5242519 | 2009-05-26 09:17:18 +0200 | [diff] [blame] | 321 | default: | 
|  | 322 | break; | 
|  | 323 | } | 
|  | 324 |  | 
|  | 325 | return "unknown"; | 
|  | 326 | } | 
|  | 327 |  | 
| Ingo Molnar | 83a0944 | 2009-08-15 12:26:57 +0200 | [diff] [blame] | 328 | static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size) | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 329 | { | 
|  | 330 | int i, j; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 331 | int n, longest = -1; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 332 |  | 
|  | 333 | for (i = 0; i < size; i++) { | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 334 | for (j = 0; j < MAX_ALIASES && names[i][j]; j++) { | 
|  | 335 | n = strlen(names[i][j]); | 
|  | 336 | if (n > longest && !strncasecmp(*str, names[i][j], n)) | 
|  | 337 | longest = n; | 
|  | 338 | } | 
|  | 339 | if (longest > 0) { | 
|  | 340 | *str += longest; | 
|  | 341 | return i; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 342 | } | 
|  | 343 | } | 
|  | 344 |  | 
| Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 345 | return -1; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 346 | } | 
|  | 347 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 348 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 349 | parse_generic_hw_event(const char **str, struct perf_event_attr *attr) | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 350 | { | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 351 | const char *s = *str; | 
|  | 352 | int cache_type = -1, cache_op = -1, cache_result = -1; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 353 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 354 | cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX); | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 355 | /* | 
|  | 356 | * No fallback - if we cannot get a clear cache type | 
|  | 357 | * then bail out: | 
|  | 358 | */ | 
|  | 359 | if (cache_type == -1) | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 360 | return EVT_FAILED; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 361 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 362 | while ((cache_op == -1 || cache_result == -1) && *s == '-') { | 
|  | 363 | ++s; | 
|  | 364 |  | 
|  | 365 | if (cache_op == -1) { | 
|  | 366 | cache_op = parse_aliases(&s, hw_cache_op, | 
|  | 367 | PERF_COUNT_HW_CACHE_OP_MAX); | 
|  | 368 | if (cache_op >= 0) { | 
|  | 369 | if (!is_cache_op_valid(cache_type, cache_op)) | 
|  | 370 | return 0; | 
|  | 371 | continue; | 
|  | 372 | } | 
|  | 373 | } | 
|  | 374 |  | 
|  | 375 | if (cache_result == -1) { | 
|  | 376 | cache_result = parse_aliases(&s, hw_cache_result, | 
|  | 377 | PERF_COUNT_HW_CACHE_RESULT_MAX); | 
|  | 378 | if (cache_result >= 0) | 
|  | 379 | continue; | 
|  | 380 | } | 
|  | 381 |  | 
|  | 382 | /* | 
|  | 383 | * Can't parse this as a cache op or result, so back up | 
|  | 384 | * to the '-'. | 
|  | 385 | */ | 
|  | 386 | --s; | 
|  | 387 | break; | 
|  | 388 | } | 
|  | 389 |  | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 390 | /* | 
|  | 391 | * Fall back to reads: | 
|  | 392 | */ | 
| Ingo Molnar | 8953645 | 2009-06-06 21:04:17 +0200 | [diff] [blame] | 393 | if (cache_op == -1) | 
|  | 394 | cache_op = PERF_COUNT_HW_CACHE_OP_READ; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 395 |  | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 396 | /* | 
|  | 397 | * Fall back to accesses: | 
|  | 398 | */ | 
|  | 399 | if (cache_result == -1) | 
|  | 400 | cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS; | 
|  | 401 |  | 
|  | 402 | attr->config = cache_type | (cache_op << 8) | (cache_result << 16); | 
|  | 403 | attr->type = PERF_TYPE_HW_CACHE; | 
|  | 404 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 405 | *str = s; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 406 | return EVT_HANDLED; | 
| Ingo Molnar | 8326f44 | 2009-06-05 20:22:46 +0200 | [diff] [blame] | 407 | } | 
|  | 408 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 409 | static enum event_result | 
|  | 410 | parse_single_tracepoint_event(char *sys_name, | 
|  | 411 | const char *evt_name, | 
|  | 412 | unsigned int evt_length, | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 413 | struct perf_event_attr *attr, | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 414 | const char **strp) | 
|  | 415 | { | 
|  | 416 | char evt_path[MAXPATHLEN]; | 
|  | 417 | char id_buf[4]; | 
|  | 418 | u64 id; | 
|  | 419 | int fd; | 
|  | 420 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 421 | snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, | 
|  | 422 | sys_name, evt_name); | 
|  | 423 |  | 
|  | 424 | fd = open(evt_path, O_RDONLY); | 
|  | 425 | if (fd < 0) | 
|  | 426 | return EVT_FAILED; | 
|  | 427 |  | 
|  | 428 | if (read(fd, id_buf, sizeof(id_buf)) < 0) { | 
|  | 429 | close(fd); | 
|  | 430 | return EVT_FAILED; | 
|  | 431 | } | 
|  | 432 |  | 
|  | 433 | close(fd); | 
|  | 434 | id = atoll(id_buf); | 
|  | 435 | attr->config = id; | 
|  | 436 | attr->type = PERF_TYPE_TRACEPOINT; | 
| Corey Ashford | 4c635a4 | 2010-11-30 14:27:01 -0800 | [diff] [blame] | 437 | *strp += strlen(sys_name) + evt_length + 1; /* + 1 for the ':' */ | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 438 |  | 
| Stephane Eranian | 5710fca | 2010-04-21 18:06:01 +0200 | [diff] [blame] | 439 | attr->sample_type |= PERF_SAMPLE_RAW; | 
|  | 440 | attr->sample_type |= PERF_SAMPLE_TIME; | 
|  | 441 | attr->sample_type |= PERF_SAMPLE_CPU; | 
|  | 442 |  | 
|  | 443 | attr->sample_period = 1; | 
|  | 444 |  | 
|  | 445 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 446 | return EVT_HANDLED; | 
|  | 447 | } | 
|  | 448 |  | 
|  | 449 | /* sys + ':' + event + ':' + flags*/ | 
|  | 450 | #define MAX_EVOPT_LEN	(MAX_EVENT_LENGTH * 2 + 2 + 128) | 
|  | 451 | static enum event_result | 
| Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 452 | parse_multiple_tracepoint_event(char *sys_name, const char *evt_exp, | 
|  | 453 | char *flags) | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 454 | { | 
|  | 455 | char evt_path[MAXPATHLEN]; | 
|  | 456 | struct dirent *evt_ent; | 
|  | 457 | DIR *evt_dir; | 
|  | 458 |  | 
|  | 459 | snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name); | 
|  | 460 | evt_dir = opendir(evt_path); | 
|  | 461 |  | 
|  | 462 | if (!evt_dir) { | 
|  | 463 | perror("Can't open event dir"); | 
|  | 464 | return EVT_FAILED; | 
|  | 465 | } | 
|  | 466 |  | 
|  | 467 | while ((evt_ent = readdir(evt_dir))) { | 
|  | 468 | char event_opt[MAX_EVOPT_LEN + 1]; | 
|  | 469 | int len; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 470 |  | 
|  | 471 | if (!strcmp(evt_ent->d_name, ".") | 
|  | 472 | || !strcmp(evt_ent->d_name, "..") | 
|  | 473 | || !strcmp(evt_ent->d_name, "enable") | 
|  | 474 | || !strcmp(evt_ent->d_name, "filter")) | 
|  | 475 | continue; | 
|  | 476 |  | 
| Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 477 | if (!strglobmatch(evt_ent->d_name, evt_exp)) | 
|  | 478 | continue; | 
|  | 479 |  | 
| Ulrich Drepper | 180570f | 2009-12-06 13:25:30 -0500 | [diff] [blame] | 480 | len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s%s%s", sys_name, | 
|  | 481 | evt_ent->d_name, flags ? ":" : "", | 
|  | 482 | flags ?: ""); | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 483 | if (len < 0) | 
|  | 484 | return EVT_FAILED; | 
|  | 485 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 486 | if (parse_events(NULL, event_opt, 0)) | 
|  | 487 | return EVT_FAILED; | 
|  | 488 | } | 
|  | 489 |  | 
|  | 490 | return EVT_HANDLED_ALL; | 
|  | 491 | } | 
|  | 492 |  | 
|  | 493 |  | 
|  | 494 | static enum event_result parse_tracepoint_event(const char **strp, | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 495 | struct perf_event_attr *attr) | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 496 | { | 
|  | 497 | const char *evt_name; | 
| Corey Ashford | 4c635a4 | 2010-11-30 14:27:01 -0800 | [diff] [blame] | 498 | char *flags = NULL, *comma_loc; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 499 | char sys_name[MAX_EVENT_LENGTH]; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 500 | unsigned int sys_length, evt_length; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 501 |  | 
| Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame] | 502 | if (debugfs_valid_mountpoint(debugfs_path)) | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 503 | return 0; | 
|  | 504 |  | 
|  | 505 | evt_name = strchr(*strp, ':'); | 
|  | 506 | if (!evt_name) | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 507 | return EVT_FAILED; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 508 |  | 
|  | 509 | sys_length = evt_name - *strp; | 
|  | 510 | if (sys_length >= MAX_EVENT_LENGTH) | 
|  | 511 | return 0; | 
|  | 512 |  | 
|  | 513 | strncpy(sys_name, *strp, sys_length); | 
|  | 514 | sys_name[sys_length] = '\0'; | 
|  | 515 | evt_name = evt_name + 1; | 
| Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 516 |  | 
| Corey Ashford | 4c635a4 | 2010-11-30 14:27:01 -0800 | [diff] [blame] | 517 | comma_loc = strchr(evt_name, ','); | 
|  | 518 | if (comma_loc) { | 
|  | 519 | /* take the event name up to the comma */ | 
|  | 520 | evt_name = strndup(evt_name, comma_loc - evt_name); | 
|  | 521 | } | 
| Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 522 | flags = strchr(evt_name, ':'); | 
|  | 523 | if (flags) { | 
| Ingo Molnar | 1fc35b2 | 2009-09-13 09:44:29 +0200 | [diff] [blame] | 524 | /* split it out: */ | 
|  | 525 | evt_name = strndup(evt_name, flags - evt_name); | 
| Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 526 | flags++; | 
| Frederic Weisbecker | 3a9f131 | 2009-08-13 10:27:18 +0200 | [diff] [blame] | 527 | } | 
|  | 528 |  | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 529 | evt_length = strlen(evt_name); | 
|  | 530 | if (evt_length >= MAX_EVENT_LENGTH) | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 531 | return EVT_FAILED; | 
| Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 532 | if (strpbrk(evt_name, "*?")) { | 
| Corey Ashford | 4c635a4 | 2010-11-30 14:27:01 -0800 | [diff] [blame] | 533 | *strp += strlen(sys_name) + evt_length; | 
| Masami Hiramatsu | fb1d2ed | 2010-01-05 17:47:17 -0500 | [diff] [blame] | 534 | return parse_multiple_tracepoint_event(sys_name, evt_name, | 
|  | 535 | flags); | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 536 | } else | 
|  | 537 | return parse_single_tracepoint_event(sys_name, evt_name, | 
| Frederic Weisbecker | bdef3b0 | 2010-04-14 20:05:17 +0200 | [diff] [blame] | 538 | evt_length, attr, strp); | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 539 | } | 
|  | 540 |  | 
| Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 541 | static enum event_result | 
|  | 542 | parse_breakpoint_type(const char *type, const char **strp, | 
|  | 543 | struct perf_event_attr *attr) | 
|  | 544 | { | 
|  | 545 | int i; | 
|  | 546 |  | 
|  | 547 | for (i = 0; i < 3; i++) { | 
|  | 548 | if (!type[i]) | 
|  | 549 | break; | 
|  | 550 |  | 
|  | 551 | switch (type[i]) { | 
|  | 552 | case 'r': | 
|  | 553 | attr->bp_type |= HW_BREAKPOINT_R; | 
|  | 554 | break; | 
|  | 555 | case 'w': | 
|  | 556 | attr->bp_type |= HW_BREAKPOINT_W; | 
|  | 557 | break; | 
|  | 558 | case 'x': | 
|  | 559 | attr->bp_type |= HW_BREAKPOINT_X; | 
|  | 560 | break; | 
|  | 561 | default: | 
|  | 562 | return EVT_FAILED; | 
|  | 563 | } | 
|  | 564 | } | 
|  | 565 | if (!attr->bp_type) /* Default */ | 
|  | 566 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; | 
|  | 567 |  | 
|  | 568 | *strp = type + i; | 
|  | 569 |  | 
|  | 570 | return EVT_HANDLED; | 
|  | 571 | } | 
|  | 572 |  | 
|  | 573 | static enum event_result | 
|  | 574 | parse_breakpoint_event(const char **strp, struct perf_event_attr *attr) | 
|  | 575 | { | 
|  | 576 | const char *target; | 
|  | 577 | const char *type; | 
|  | 578 | char *endaddr; | 
|  | 579 | u64 addr; | 
|  | 580 | enum event_result err; | 
|  | 581 |  | 
|  | 582 | target = strchr(*strp, ':'); | 
|  | 583 | if (!target) | 
|  | 584 | return EVT_FAILED; | 
|  | 585 |  | 
|  | 586 | if (strncmp(*strp, "mem", target - *strp) != 0) | 
|  | 587 | return EVT_FAILED; | 
|  | 588 |  | 
|  | 589 | target++; | 
|  | 590 |  | 
|  | 591 | addr = strtoull(target, &endaddr, 0); | 
|  | 592 | if (target == endaddr) | 
|  | 593 | return EVT_FAILED; | 
|  | 594 |  | 
|  | 595 | attr->bp_addr = addr; | 
|  | 596 | *strp = endaddr; | 
|  | 597 |  | 
|  | 598 | type = strchr(target, ':'); | 
|  | 599 |  | 
|  | 600 | /* If no type is defined, just rw as default */ | 
|  | 601 | if (!type) { | 
|  | 602 | attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; | 
|  | 603 | } else { | 
|  | 604 | err = parse_breakpoint_type(++type, strp, attr); | 
|  | 605 | if (err == EVT_FAILED) | 
|  | 606 | return EVT_FAILED; | 
|  | 607 | } | 
|  | 608 |  | 
| Frederic Weisbecker | aa59a48 | 2010-06-24 21:36:19 +0200 | [diff] [blame] | 609 | /* | 
|  | 610 | * We should find a nice way to override the access length | 
|  | 611 | * Provide some defaults for now | 
|  | 612 | */ | 
|  | 613 | if (attr->bp_type == HW_BREAKPOINT_X) | 
|  | 614 | attr->bp_len = sizeof(long); | 
|  | 615 | else | 
|  | 616 | attr->bp_len = HW_BREAKPOINT_LEN_4; | 
|  | 617 |  | 
| Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 618 | attr->type = PERF_TYPE_BREAKPOINT; | 
|  | 619 |  | 
|  | 620 | return EVT_HANDLED; | 
|  | 621 | } | 
|  | 622 |  | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 623 | static int check_events(const char *str, unsigned int i) | 
|  | 624 | { | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 625 | int n; | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 626 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 627 | n = strlen(event_symbols[i].symbol); | 
|  | 628 | if (!strncmp(str, event_symbols[i].symbol, n)) | 
|  | 629 | return n; | 
|  | 630 |  | 
|  | 631 | n = strlen(event_symbols[i].alias); | 
|  | 632 | if (n) | 
|  | 633 | if (!strncmp(str, event_symbols[i].alias, n)) | 
|  | 634 | return n; | 
|  | 635 | return 0; | 
|  | 636 | } | 
|  | 637 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 638 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 639 | parse_symbolic_event(const char **strp, struct perf_event_attr *attr) | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 640 | { | 
|  | 641 | const char *str = *strp; | 
|  | 642 | unsigned int i; | 
|  | 643 | int n; | 
|  | 644 |  | 
|  | 645 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { | 
|  | 646 | n = check_events(str, i); | 
|  | 647 | if (n > 0) { | 
|  | 648 | attr->type = event_symbols[i].type; | 
|  | 649 | attr->config = event_symbols[i].config; | 
|  | 650 | *strp = str + n; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 651 | return EVT_HANDLED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 652 | } | 
|  | 653 | } | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 654 | return EVT_FAILED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 655 | } | 
|  | 656 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 657 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 658 | parse_raw_event(const char **strp, struct perf_event_attr *attr) | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 659 | { | 
|  | 660 | const char *str = *strp; | 
|  | 661 | u64 config; | 
|  | 662 | int n; | 
|  | 663 |  | 
|  | 664 | if (*str != 'r') | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 665 | return EVT_FAILED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 666 | n = hex2u64(str + 1, &config); | 
|  | 667 | if (n > 0) { | 
|  | 668 | *strp = str + n + 1; | 
|  | 669 | attr->type = PERF_TYPE_RAW; | 
|  | 670 | attr->config = config; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 671 | return EVT_HANDLED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 672 | } | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 673 | return EVT_FAILED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 674 | } | 
|  | 675 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 676 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 677 | parse_numeric_event(const char **strp, struct perf_event_attr *attr) | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 678 | { | 
|  | 679 | const char *str = *strp; | 
|  | 680 | char *endp; | 
|  | 681 | unsigned long type; | 
|  | 682 | u64 config; | 
|  | 683 |  | 
|  | 684 | type = strtoul(str, &endp, 0); | 
|  | 685 | if (endp > str && type < PERF_TYPE_MAX && *endp == ':') { | 
|  | 686 | str = endp + 1; | 
|  | 687 | config = strtoul(str, &endp, 0); | 
|  | 688 | if (endp > str) { | 
|  | 689 | attr->type = type; | 
|  | 690 | attr->config = config; | 
|  | 691 | *strp = endp; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 692 | return EVT_HANDLED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 693 | } | 
|  | 694 | } | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 695 | return EVT_FAILED; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 696 | } | 
|  | 697 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 698 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 699 | parse_event_modifier(const char **strp, struct perf_event_attr *attr) | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 700 | { | 
|  | 701 | const char *str = *strp; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 702 | int exclude = 0; | 
|  | 703 | int eu = 0, ek = 0, eh = 0, precise = 0; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 704 |  | 
|  | 705 | if (*str++ != ':') | 
|  | 706 | return 0; | 
|  | 707 | while (*str) { | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 708 | if (*str == 'u') { | 
|  | 709 | if (!exclude) | 
|  | 710 | exclude = eu = ek = eh = 1; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 711 | eu = 0; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 712 | } else if (*str == 'k') { | 
|  | 713 | if (!exclude) | 
|  | 714 | exclude = eu = ek = eh = 1; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 715 | ek = 0; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 716 | } else if (*str == 'h') { | 
|  | 717 | if (!exclude) | 
|  | 718 | exclude = eu = ek = eh = 1; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 719 | eh = 0; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 720 | } else if (*str == 'p') { | 
|  | 721 | precise++; | 
|  | 722 | } else | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 723 | break; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 724 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 725 | ++str; | 
|  | 726 | } | 
|  | 727 | if (str >= *strp + 2) { | 
|  | 728 | *strp = str; | 
|  | 729 | attr->exclude_user   = eu; | 
|  | 730 | attr->exclude_kernel = ek; | 
|  | 731 | attr->exclude_hv     = eh; | 
| Peter Zijlstra | ab60834 | 2010-04-08 23:03:20 +0200 | [diff] [blame] | 732 | attr->precise_ip     = precise; | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 733 | return 1; | 
|  | 734 | } | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 735 | return 0; | 
|  | 736 | } | 
|  | 737 |  | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 738 | /* | 
|  | 739 | * Each event can have multiple symbolic names. | 
|  | 740 | * Symbolic names are (almost) exactly matched. | 
|  | 741 | */ | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 742 | static enum event_result | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 743 | parse_event_symbols(const char **str, struct perf_event_attr *attr) | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 744 | { | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 745 | enum event_result ret; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 746 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 747 | ret = parse_tracepoint_event(str, attr); | 
|  | 748 | if (ret != EVT_FAILED) | 
|  | 749 | goto modifier; | 
|  | 750 |  | 
|  | 751 | ret = parse_raw_event(str, attr); | 
|  | 752 | if (ret != EVT_FAILED) | 
|  | 753 | goto modifier; | 
|  | 754 |  | 
|  | 755 | ret = parse_numeric_event(str, attr); | 
|  | 756 | if (ret != EVT_FAILED) | 
|  | 757 | goto modifier; | 
|  | 758 |  | 
|  | 759 | ret = parse_symbolic_event(str, attr); | 
|  | 760 | if (ret != EVT_FAILED) | 
|  | 761 | goto modifier; | 
|  | 762 |  | 
|  | 763 | ret = parse_generic_hw_event(str, attr); | 
|  | 764 | if (ret != EVT_FAILED) | 
|  | 765 | goto modifier; | 
|  | 766 |  | 
| Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 767 | ret = parse_breakpoint_event(str, attr); | 
|  | 768 | if (ret != EVT_FAILED) | 
|  | 769 | goto modifier; | 
|  | 770 |  | 
| Marti Raudsepp | 85df6f6 | 2009-10-27 00:33:04 +0000 | [diff] [blame] | 771 | fprintf(stderr, "invalid or unsupported event: '%s'\n", *str); | 
|  | 772 | fprintf(stderr, "Run 'perf list' for a list of valid events\n"); | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 773 | return EVT_FAILED; | 
|  | 774 |  | 
|  | 775 | modifier: | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 776 | parse_event_modifier(str, attr); | 
| Ingo Molnar | a21ca2c | 2009-06-06 09:58:57 +0200 | [diff] [blame] | 777 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 778 | return ret; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 779 | } | 
|  | 780 |  | 
| Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 781 | static int store_event_type(const char *orgname) | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 782 | { | 
|  | 783 | char filename[PATH_MAX], *c; | 
|  | 784 | FILE *file; | 
| Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 785 | int id, n; | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 786 |  | 
| Ashwin Chaugule | 63c9e01 | 2009-10-04 15:49:34 -0700 | [diff] [blame] | 787 | sprintf(filename, "%s/", debugfs_path); | 
|  | 788 | strncat(filename, orgname, strlen(orgname)); | 
|  | 789 | strcat(filename, "/id"); | 
|  | 790 |  | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 791 | c = strchr(filename, ':'); | 
|  | 792 | if (c) | 
|  | 793 | *c = '/'; | 
|  | 794 |  | 
|  | 795 | file = fopen(filename, "r"); | 
|  | 796 | if (!file) | 
| Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 797 | return 0; | 
|  | 798 | n = fscanf(file, "%i", &id); | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 799 | fclose(file); | 
| Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 800 | if (n < 1) { | 
|  | 801 | pr_err("cannot store event ID\n"); | 
|  | 802 | return -EINVAL; | 
|  | 803 | } | 
|  | 804 | return perf_header__push_event(id, orgname); | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 805 | } | 
|  | 806 |  | 
| Ingo Molnar | f37a291 | 2009-07-01 12:37:06 +0200 | [diff] [blame] | 807 | int parse_events(const struct option *opt __used, const char *str, int unset __used) | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 808 | { | 
| Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 809 | struct perf_event_attr attr; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 810 | enum event_result ret; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 811 |  | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 812 | if (strchr(str, ':')) | 
| Arnaldo Carvalho de Melo | ae99fb2 | 2009-12-28 22:48:33 -0200 | [diff] [blame] | 813 | if (store_event_type(str) < 0) | 
|  | 814 | return -1; | 
| Arjan van de Ven | 8755a8f | 2009-09-12 07:52:51 +0200 | [diff] [blame] | 815 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 816 | for (;;) { | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 817 | memset(&attr, 0, sizeof(attr)); | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 818 | ret = parse_event_symbols(&str, &attr); | 
|  | 819 | if (ret == EVT_FAILED) | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 820 | return -1; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 821 |  | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 822 | if (!(*str == 0 || *str == ',' || isspace(*str))) | 
|  | 823 | return -1; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 824 |  | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 825 | if (ret != EVT_HANDLED_ALL) { | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 826 | struct perf_evsel *evsel; | 
|  | 827 | evsel = perf_evsel__new(attr.type, attr.config, | 
|  | 828 | nr_counters); | 
|  | 829 | if (evsel == NULL) | 
|  | 830 | return -1; | 
|  | 831 | list_add_tail(&evsel->node, &evsel_list); | 
|  | 832 | ++nr_counters; | 
| Frederic Weisbecker | bcd3279 | 2009-09-11 23:19:45 +0200 | [diff] [blame] | 833 | } | 
| Paul Mackerras | 61c4598 | 2009-07-01 13:04:34 +1000 | [diff] [blame] | 834 |  | 
|  | 835 | if (*str == 0) | 
|  | 836 | break; | 
|  | 837 | if (*str == ',') | 
|  | 838 | ++str; | 
|  | 839 | while (isspace(*str)) | 
|  | 840 | ++str; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 841 | } | 
|  | 842 |  | 
|  | 843 | return 0; | 
|  | 844 | } | 
|  | 845 |  | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 846 | int parse_filter(const struct option *opt __used, const char *str, | 
|  | 847 | int unset __used) | 
|  | 848 | { | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 849 | struct perf_evsel *last = NULL; | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 850 |  | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 851 | if (!list_empty(&evsel_list)) | 
|  | 852 | last = list_entry(evsel_list.prev, struct perf_evsel, node); | 
|  | 853 |  | 
|  | 854 | if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) { | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 855 | fprintf(stderr, | 
|  | 856 | "-F option should follow a -e tracepoint option\n"); | 
|  | 857 | return -1; | 
|  | 858 | } | 
|  | 859 |  | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 860 | last->filter = strdup(str); | 
|  | 861 | if (last->filter == NULL) { | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 862 | fprintf(stderr, "not enough memory to hold filter string\n"); | 
|  | 863 | return -1; | 
|  | 864 | } | 
| Li Zefan | c171b55 | 2009-10-15 11:22:07 +0800 | [diff] [blame] | 865 |  | 
|  | 866 | return 0; | 
|  | 867 | } | 
|  | 868 |  | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 869 | static const char * const event_type_descriptors[] = { | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 870 | "Hardware event", | 
|  | 871 | "Software event", | 
|  | 872 | "Tracepoint event", | 
|  | 873 | "Hardware cache event", | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 874 | "Raw hardware event descriptor", | 
|  | 875 | "Hardware breakpoint", | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 876 | }; | 
|  | 877 |  | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 878 | /* | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 879 | * Print the events from <debugfs_mount_point>/tracing/events | 
|  | 880 | */ | 
|  | 881 |  | 
|  | 882 | static void print_tracepoint_events(void) | 
|  | 883 | { | 
|  | 884 | DIR *sys_dir, *evt_dir; | 
|  | 885 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 886 | char evt_path[MAXPATHLEN]; | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 887 | char dir_path[MAXPATHLEN]; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 888 |  | 
| Clark Williams | 549104f | 2009-11-08 09:03:07 -0600 | [diff] [blame] | 889 | if (debugfs_valid_mountpoint(debugfs_path)) | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 890 | return; | 
|  | 891 |  | 
| Jason Baron | 5beeded | 2009-07-21 14:16:29 -0400 | [diff] [blame] | 892 | sys_dir = opendir(debugfs_path); | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 893 | if (!sys_dir) | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 894 | return; | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 895 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 896 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 897 |  | 
|  | 898 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, | 
|  | 899 | sys_dirent.d_name); | 
|  | 900 | evt_dir = opendir(dir_path); | 
|  | 901 | if (!evt_dir) | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 902 | continue; | 
| Eric Dumazet | 725b136 | 2009-09-24 15:39:09 +0200 | [diff] [blame] | 903 |  | 
| Ulrich Drepper | 6b58e7f | 2009-09-04 16:39:51 -0300 | [diff] [blame] | 904 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 905 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | 
|  | 906 | sys_dirent.d_name, evt_dirent.d_name); | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 907 | printf("  %-42s [%s]\n", evt_path, | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 908 | event_type_descriptors[PERF_TYPE_TRACEPOINT]); | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 909 | } | 
|  | 910 | closedir(evt_dir); | 
|  | 911 | } | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 912 | closedir(sys_dir); | 
|  | 913 | } | 
|  | 914 |  | 
|  | 915 | /* | 
| Thomas Renninger | 20c457b | 2011-01-03 17:50:45 +0100 | [diff] [blame] | 916 | * Check whether event is in <debugfs_mount_point>/tracing/events | 
|  | 917 | */ | 
|  | 918 |  | 
|  | 919 | int is_valid_tracepoint(const char *event_string) | 
|  | 920 | { | 
|  | 921 | DIR *sys_dir, *evt_dir; | 
|  | 922 | struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; | 
|  | 923 | char evt_path[MAXPATHLEN]; | 
|  | 924 | char dir_path[MAXPATHLEN]; | 
|  | 925 |  | 
|  | 926 | if (debugfs_valid_mountpoint(debugfs_path)) | 
|  | 927 | return 0; | 
|  | 928 |  | 
|  | 929 | sys_dir = opendir(debugfs_path); | 
|  | 930 | if (!sys_dir) | 
|  | 931 | return 0; | 
|  | 932 |  | 
|  | 933 | for_each_subsystem(sys_dir, sys_dirent, sys_next) { | 
|  | 934 |  | 
|  | 935 | snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, | 
|  | 936 | sys_dirent.d_name); | 
|  | 937 | evt_dir = opendir(dir_path); | 
|  | 938 | if (!evt_dir) | 
|  | 939 | continue; | 
|  | 940 |  | 
|  | 941 | for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) { | 
|  | 942 | snprintf(evt_path, MAXPATHLEN, "%s:%s", | 
|  | 943 | sys_dirent.d_name, evt_dirent.d_name); | 
|  | 944 | if (!strcmp(evt_path, event_string)) { | 
|  | 945 | closedir(evt_dir); | 
|  | 946 | closedir(sys_dir); | 
|  | 947 | return 1; | 
|  | 948 | } | 
|  | 949 | } | 
|  | 950 | closedir(evt_dir); | 
|  | 951 | } | 
|  | 952 | closedir(sys_dir); | 
|  | 953 | return 0; | 
|  | 954 | } | 
|  | 955 |  | 
|  | 956 | /* | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 957 | * Print the help text for the event symbols: | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 958 | */ | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 959 | void print_events(void) | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 960 | { | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 961 | struct event_symbol *syms = event_symbols; | 
| Jaswinder Singh Rajput | 73c24cb8 | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 962 | unsigned int i, type, op, prev_type = -1; | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 963 | char name[40]; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 964 |  | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 965 | printf("\n"); | 
|  | 966 | printf("List of pre-defined events (to be used in -e):\n"); | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 967 |  | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 968 | for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) { | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 969 | type = syms->type; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 970 |  | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 971 | if (type != prev_type) | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 972 | printf("\n"); | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 973 |  | 
| Jaswinder Singh Rajput | 74d5b58 | 2009-06-22 16:44:28 +0530 | [diff] [blame] | 974 | if (strlen(syms->alias)) | 
|  | 975 | sprintf(name, "%s OR %s", syms->symbol, syms->alias); | 
|  | 976 | else | 
|  | 977 | strcpy(name, syms->symbol); | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 978 | printf("  %-42s [%s]\n", name, | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 979 | event_type_descriptors[type]); | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 980 |  | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 981 | prev_type = type; | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 982 | } | 
|  | 983 |  | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 984 | printf("\n"); | 
| Jaswinder Singh Rajput | 73c24cb8 | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 985 | for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) { | 
|  | 986 | for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) { | 
|  | 987 | /* skip invalid cache type */ | 
|  | 988 | if (!is_cache_op_valid(type, op)) | 
|  | 989 | continue; | 
|  | 990 |  | 
|  | 991 | for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) { | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 992 | printf("  %-42s [%s]\n", | 
| Jaswinder Singh Rajput | 73c24cb8 | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 993 | event_cache_name(type, op, i), | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 994 | event_type_descriptors[PERF_TYPE_HW_CACHE]); | 
| Jaswinder Singh Rajput | 73c24cb8 | 2009-07-01 18:36:18 +0530 | [diff] [blame] | 995 | } | 
|  | 996 | } | 
|  | 997 | } | 
|  | 998 |  | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 999 | printf("\n"); | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 1000 | printf("  %-42s [%s]\n", | 
| Arnaldo Carvalho de Melo | 1cf4a06 | 2010-05-07 14:07:05 -0300 | [diff] [blame] | 1001 | "rNNN (see 'perf list --help' on how to encode it)", | 
|  | 1002 | event_type_descriptors[PERF_TYPE_RAW]); | 
| Marti Raudsepp | 689d301 | 2009-10-27 00:33:05 +0000 | [diff] [blame] | 1003 | printf("\n"); | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1004 |  | 
| Liming Wang | 41bdcb2 | 2009-12-29 16:37:07 +0800 | [diff] [blame] | 1005 | printf("  %-42s [%s]\n", | 
|  | 1006 | "mem:<addr>[:access]", | 
|  | 1007 | event_type_descriptors[PERF_TYPE_BREAKPOINT]); | 
| Frederic Weisbecker | 1b290d6 | 2009-11-23 15:42:35 +0100 | [diff] [blame] | 1008 | printf("\n"); | 
|  | 1009 |  | 
| Jason Baron | f6bdafe | 2009-07-21 12:20:22 -0400 | [diff] [blame] | 1010 | print_tracepoint_events(); | 
|  | 1011 |  | 
| Thomas Gleixner | 86847b6 | 2009-06-06 12:24:17 +0200 | [diff] [blame] | 1012 | exit(129); | 
| Ingo Molnar | 8ad8db3 | 2009-05-26 11:10:09 +0200 | [diff] [blame] | 1013 | } | 
| Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1014 |  | 
|  | 1015 | int perf_evsel_list__create_default(void) | 
|  | 1016 | { | 
|  | 1017 | struct perf_evsel *evsel = perf_evsel__new(PERF_TYPE_HARDWARE, | 
|  | 1018 | PERF_COUNT_HW_CPU_CYCLES, 0); | 
|  | 1019 | if (evsel == NULL) | 
|  | 1020 | return -ENOMEM; | 
|  | 1021 |  | 
|  | 1022 | list_add(&evsel->node, &evsel_list); | 
|  | 1023 | ++nr_counters; | 
|  | 1024 | return 0; | 
|  | 1025 | } | 
| Arnaldo Carvalho de Melo | 70d544d | 2011-01-03 16:51:39 -0200 | [diff] [blame] | 1026 |  | 
|  | 1027 | void perf_evsel_list__delete(void) | 
|  | 1028 | { | 
|  | 1029 | struct perf_evsel *pos, *n; | 
|  | 1030 |  | 
|  | 1031 | list_for_each_entry_safe(pos, n, &evsel_list, node) { | 
|  | 1032 | list_del_init(&pos->node); | 
|  | 1033 | perf_evsel__delete(pos); | 
|  | 1034 | } | 
|  | 1035 | nr_counters = 0; | 
|  | 1036 | } |