Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1 | /* |
| 2 | * builtin-test.c |
| 3 | * |
| 4 | * Builtin regression testing command: ever growing number of sanity tests |
| 5 | */ |
| 6 | #include "builtin.h" |
| 7 | |
| 8 | #include "util/cache.h" |
| 9 | #include "util/debug.h" |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 10 | #include "util/debugfs.h" |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 11 | #include "util/evlist.h" |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 12 | #include "util/parse-options.h" |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 13 | #include "util/parse-events.h" |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 14 | #include "util/symbol.h" |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 15 | #include "util/thread_map.h" |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 16 | #include "../../include/linux/hw_breakpoint.h" |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 17 | |
Peter Zijlstra | 08aa0d1 | 2011-11-21 14:42:47 +0100 | [diff] [blame] | 18 | #include <sys/mman.h> |
| 19 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 20 | static int vmlinux_matches_kallsyms_filter(struct map *map __used, struct symbol *sym) |
| 21 | { |
| 22 | bool *visited = symbol__priv(sym); |
| 23 | *visited = true; |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | static int test__vmlinux_matches_kallsyms(void) |
| 28 | { |
| 29 | int err = -1; |
| 30 | struct rb_node *nd; |
| 31 | struct symbol *sym; |
| 32 | struct map *kallsyms_map, *vmlinux_map; |
| 33 | struct machine kallsyms, vmlinux; |
| 34 | enum map_type type = MAP__FUNCTION; |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 35 | long page_size = sysconf(_SC_PAGE_SIZE); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 36 | struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", }; |
| 37 | |
| 38 | /* |
| 39 | * Step 1: |
| 40 | * |
| 41 | * Init the machines that will hold kernel, modules obtained from |
| 42 | * both vmlinux + .ko files and from /proc/kallsyms split by modules. |
| 43 | */ |
| 44 | machine__init(&kallsyms, "", HOST_KERNEL_ID); |
| 45 | machine__init(&vmlinux, "", HOST_KERNEL_ID); |
| 46 | |
| 47 | /* |
| 48 | * Step 2: |
| 49 | * |
| 50 | * Create the kernel maps for kallsyms and the DSO where we will then |
| 51 | * load /proc/kallsyms. Also create the modules maps from /proc/modules |
| 52 | * and find the .ko files that match them in /lib/modules/`uname -r`/. |
| 53 | */ |
| 54 | if (machine__create_kernel_maps(&kallsyms) < 0) { |
| 55 | pr_debug("machine__create_kernel_maps "); |
| 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Step 3: |
| 61 | * |
| 62 | * Load and split /proc/kallsyms into multiple maps, one per module. |
| 63 | */ |
| 64 | if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) { |
| 65 | pr_debug("dso__load_kallsyms "); |
| 66 | goto out; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Step 4: |
| 71 | * |
| 72 | * kallsyms will be internally on demand sorted by name so that we can |
| 73 | * find the reference relocation * symbol, i.e. the symbol we will use |
| 74 | * to see if the running kernel was relocated by checking if it has the |
| 75 | * same value in the vmlinux file we load. |
| 76 | */ |
| 77 | kallsyms_map = machine__kernel_map(&kallsyms, type); |
| 78 | |
| 79 | sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL); |
| 80 | if (sym == NULL) { |
| 81 | pr_debug("dso__find_symbol_by_name "); |
| 82 | goto out; |
| 83 | } |
| 84 | |
| 85 | ref_reloc_sym.addr = sym->start; |
| 86 | |
| 87 | /* |
| 88 | * Step 5: |
| 89 | * |
| 90 | * Now repeat step 2, this time for the vmlinux file we'll auto-locate. |
| 91 | */ |
| 92 | if (machine__create_kernel_maps(&vmlinux) < 0) { |
| 93 | pr_debug("machine__create_kernel_maps "); |
| 94 | goto out; |
| 95 | } |
| 96 | |
| 97 | vmlinux_map = machine__kernel_map(&vmlinux, type); |
| 98 | map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym; |
| 99 | |
| 100 | /* |
| 101 | * Step 6: |
| 102 | * |
| 103 | * Locate a vmlinux file in the vmlinux path that has a buildid that |
| 104 | * matches the one of the running kernel. |
| 105 | * |
| 106 | * While doing that look if we find the ref reloc symbol, if we find it |
| 107 | * we'll have its ref_reloc_symbol.unrelocated_addr and then |
| 108 | * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines |
| 109 | * to fixup the symbols. |
| 110 | */ |
| 111 | if (machine__load_vmlinux_path(&vmlinux, type, |
| 112 | vmlinux_matches_kallsyms_filter) <= 0) { |
| 113 | pr_debug("machine__load_vmlinux_path "); |
| 114 | goto out; |
| 115 | } |
| 116 | |
| 117 | err = 0; |
| 118 | /* |
| 119 | * Step 7: |
| 120 | * |
| 121 | * Now look at the symbols in the vmlinux DSO and check if we find all of them |
| 122 | * in the kallsyms dso. For the ones that are in both, check its names and |
| 123 | * end addresses too. |
| 124 | */ |
| 125 | for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) { |
Arnaldo Carvalho de Melo | d367875 | 2010-12-21 23:38:37 -0200 | [diff] [blame] | 126 | struct symbol *pair, *first_pair; |
| 127 | bool backwards = true; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 128 | |
| 129 | sym = rb_entry(nd, struct symbol, rb_node); |
Arnaldo Carvalho de Melo | d367875 | 2010-12-21 23:38:37 -0200 | [diff] [blame] | 130 | |
| 131 | if (sym->start == sym->end) |
| 132 | continue; |
| 133 | |
| 134 | first_pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL); |
| 135 | pair = first_pair; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 136 | |
| 137 | if (pair && pair->start == sym->start) { |
| 138 | next_pair: |
| 139 | if (strcmp(sym->name, pair->name) == 0) { |
| 140 | /* |
| 141 | * kallsyms don't have the symbol end, so we |
| 142 | * set that by using the next symbol start - 1, |
| 143 | * in some cases we get this up to a page |
| 144 | * wrong, trace_kmalloc when I was developing |
| 145 | * this code was one such example, 2106 bytes |
| 146 | * off the real size. More than that and we |
| 147 | * _really_ have a problem. |
| 148 | */ |
| 149 | s64 skew = sym->end - pair->end; |
| 150 | if (llabs(skew) < page_size) |
| 151 | continue; |
| 152 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 153 | pr_debug("%#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n", |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 154 | sym->start, sym->name, sym->end, pair->end); |
| 155 | } else { |
Arnaldo Carvalho de Melo | d367875 | 2010-12-21 23:38:37 -0200 | [diff] [blame] | 156 | struct rb_node *nnd; |
| 157 | detour: |
| 158 | nnd = backwards ? rb_prev(&pair->rb_node) : |
| 159 | rb_next(&pair->rb_node); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 160 | if (nnd) { |
| 161 | struct symbol *next = rb_entry(nnd, struct symbol, rb_node); |
| 162 | |
| 163 | if (next->start == sym->start) { |
| 164 | pair = next; |
| 165 | goto next_pair; |
| 166 | } |
| 167 | } |
Arnaldo Carvalho de Melo | d367875 | 2010-12-21 23:38:37 -0200 | [diff] [blame] | 168 | |
| 169 | if (backwards) { |
| 170 | backwards = false; |
| 171 | pair = first_pair; |
| 172 | goto detour; |
| 173 | } |
| 174 | |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 175 | pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n", |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 176 | sym->start, sym->name, pair->name); |
| 177 | } |
| 178 | } else |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 179 | pr_debug("%#" PRIx64 ": %s not on kallsyms\n", sym->start, sym->name); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 180 | |
| 181 | err = -1; |
| 182 | } |
| 183 | |
| 184 | if (!verbose) |
| 185 | goto out; |
| 186 | |
| 187 | pr_info("Maps only in vmlinux:\n"); |
| 188 | |
| 189 | for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) { |
| 190 | struct map *pos = rb_entry(nd, struct map, rb_node), *pair; |
| 191 | /* |
| 192 | * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while |
| 193 | * the kernel will have the path for the vmlinux file being used, |
| 194 | * so use the short name, less descriptive but the same ("[kernel]" in |
| 195 | * both cases. |
| 196 | */ |
| 197 | pair = map_groups__find_by_name(&kallsyms.kmaps, type, |
| 198 | (pos->dso->kernel ? |
| 199 | pos->dso->short_name : |
| 200 | pos->dso->name)); |
| 201 | if (pair) |
| 202 | pair->priv = 1; |
| 203 | else |
| 204 | map__fprintf(pos, stderr); |
| 205 | } |
| 206 | |
| 207 | pr_info("Maps in vmlinux with a different name in kallsyms:\n"); |
| 208 | |
| 209 | for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) { |
| 210 | struct map *pos = rb_entry(nd, struct map, rb_node), *pair; |
| 211 | |
| 212 | pair = map_groups__find(&kallsyms.kmaps, type, pos->start); |
| 213 | if (pair == NULL || pair->priv) |
| 214 | continue; |
| 215 | |
| 216 | if (pair->start == pos->start) { |
| 217 | pair->priv = 1; |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 218 | pr_info(" %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as", |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 219 | pos->start, pos->end, pos->pgoff, pos->dso->name); |
| 220 | if (pos->pgoff != pair->pgoff || pos->end != pair->end) |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 221 | pr_info(": \n*%" PRIx64 "-%" PRIx64 " %" PRIx64 "", |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 222 | pair->start, pair->end, pair->pgoff); |
| 223 | pr_info(" %s\n", pair->dso->name); |
| 224 | pair->priv = 1; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | pr_info("Maps only in kallsyms:\n"); |
| 229 | |
| 230 | for (nd = rb_first(&kallsyms.kmaps.maps[type]); |
| 231 | nd; nd = rb_next(nd)) { |
| 232 | struct map *pos = rb_entry(nd, struct map, rb_node); |
| 233 | |
| 234 | if (!pos->priv) |
| 235 | map__fprintf(pos, stderr); |
| 236 | } |
| 237 | out: |
| 238 | return err; |
| 239 | } |
| 240 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 241 | #include "util/cpumap.h" |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 242 | #include "util/evsel.h" |
| 243 | #include <sys/types.h> |
| 244 | |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 245 | static int trace_event__id(const char *evname) |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 246 | { |
| 247 | char *filename; |
| 248 | int err = -1, fd; |
| 249 | |
| 250 | if (asprintf(&filename, |
Jiri Olsa | baf040a | 2011-07-14 11:25:34 +0200 | [diff] [blame] | 251 | "%s/syscalls/%s/id", |
Arnaldo Carvalho de Melo | ebf294b | 2011-11-16 14:03:07 -0200 | [diff] [blame] | 252 | tracing_events_path, evname) < 0) |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 253 | return -1; |
| 254 | |
| 255 | fd = open(filename, O_RDONLY); |
| 256 | if (fd >= 0) { |
| 257 | char id[16]; |
| 258 | if (read(fd, id, sizeof(id)) > 0) |
| 259 | err = atoi(id); |
| 260 | close(fd); |
| 261 | } |
| 262 | |
| 263 | free(filename); |
| 264 | return err; |
| 265 | } |
| 266 | |
| 267 | static int test__open_syscall_event(void) |
| 268 | { |
| 269 | int err = -1, fd; |
| 270 | struct thread_map *threads; |
| 271 | struct perf_evsel *evsel; |
Lin Ming | 23a2f3a | 2011-01-07 11:11:09 +0800 | [diff] [blame] | 272 | struct perf_event_attr attr; |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 273 | unsigned int nr_open_calls = 111, i; |
| 274 | int id = trace_event__id("sys_enter_open"); |
| 275 | |
| 276 | if (id < 0) { |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 277 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 278 | return -1; |
| 279 | } |
| 280 | |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 281 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 282 | if (threads == NULL) { |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 283 | pr_debug("thread_map__new\n"); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 284 | return -1; |
| 285 | } |
| 286 | |
Lin Ming | 23a2f3a | 2011-01-07 11:11:09 +0800 | [diff] [blame] | 287 | memset(&attr, 0, sizeof(attr)); |
| 288 | attr.type = PERF_TYPE_TRACEPOINT; |
| 289 | attr.config = id; |
| 290 | evsel = perf_evsel__new(&attr, 0); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 291 | if (evsel == NULL) { |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 292 | pr_debug("perf_evsel__new\n"); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 293 | goto out_thread_map_delete; |
| 294 | } |
| 295 | |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 296 | if (perf_evsel__open_per_thread(evsel, threads, false, NULL) < 0) { |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 297 | pr_debug("failed to open counter: %s, " |
| 298 | "tweak /proc/sys/kernel/perf_event_paranoid?\n", |
| 299 | strerror(errno)); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 300 | goto out_evsel_delete; |
| 301 | } |
| 302 | |
| 303 | for (i = 0; i < nr_open_calls; ++i) { |
| 304 | fd = open("/etc/passwd", O_RDONLY); |
| 305 | close(fd); |
| 306 | } |
| 307 | |
| 308 | if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) { |
Arnaldo Carvalho de Melo | 5d2cd90 | 2011-04-14 11:20:14 -0300 | [diff] [blame] | 309 | pr_debug("perf_evsel__read_on_cpu\n"); |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 310 | goto out_close_fd; |
| 311 | } |
| 312 | |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 313 | if (evsel->counts->cpu[0].val != nr_open_calls) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 314 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n", |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 315 | nr_open_calls, evsel->counts->cpu[0].val); |
Arnaldo Carvalho de Melo | 454a3bb | 2011-01-04 10:40:08 -0200 | [diff] [blame] | 316 | goto out_close_fd; |
| 317 | } |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 318 | |
| 319 | err = 0; |
| 320 | out_close_fd: |
| 321 | perf_evsel__close_fd(evsel, 1, threads->nr); |
| 322 | out_evsel_delete: |
| 323 | perf_evsel__delete(evsel); |
| 324 | out_thread_map_delete: |
| 325 | thread_map__delete(threads); |
| 326 | return err; |
| 327 | } |
| 328 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 329 | #include <sched.h> |
| 330 | |
| 331 | static int test__open_syscall_event_on_all_cpus(void) |
| 332 | { |
| 333 | int err = -1, fd, cpu; |
| 334 | struct thread_map *threads; |
| 335 | struct cpu_map *cpus; |
| 336 | struct perf_evsel *evsel; |
| 337 | struct perf_event_attr attr; |
| 338 | unsigned int nr_open_calls = 111, i; |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 339 | cpu_set_t cpu_set; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 340 | int id = trace_event__id("sys_enter_open"); |
| 341 | |
| 342 | if (id < 0) { |
| 343 | pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); |
| 344 | return -1; |
| 345 | } |
| 346 | |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 347 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 348 | if (threads == NULL) { |
| 349 | pr_debug("thread_map__new\n"); |
| 350 | return -1; |
| 351 | } |
| 352 | |
| 353 | cpus = cpu_map__new(NULL); |
Han Pingtian | 98d77b7 | 2011-01-15 07:00:50 +0800 | [diff] [blame] | 354 | if (cpus == NULL) { |
| 355 | pr_debug("cpu_map__new\n"); |
| 356 | goto out_thread_map_delete; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 357 | } |
| 358 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 359 | |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 360 | CPU_ZERO(&cpu_set); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 361 | |
| 362 | memset(&attr, 0, sizeof(attr)); |
| 363 | attr.type = PERF_TYPE_TRACEPOINT; |
| 364 | attr.config = id; |
| 365 | evsel = perf_evsel__new(&attr, 0); |
| 366 | if (evsel == NULL) { |
| 367 | pr_debug("perf_evsel__new\n"); |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 368 | goto out_thread_map_delete; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 369 | } |
| 370 | |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 371 | if (perf_evsel__open(evsel, cpus, threads, false, NULL) < 0) { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 372 | pr_debug("failed to open counter: %s, " |
| 373 | "tweak /proc/sys/kernel/perf_event_paranoid?\n", |
| 374 | strerror(errno)); |
| 375 | goto out_evsel_delete; |
| 376 | } |
| 377 | |
| 378 | for (cpu = 0; cpu < cpus->nr; ++cpu) { |
| 379 | unsigned int ncalls = nr_open_calls + cpu; |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 380 | /* |
| 381 | * XXX eventually lift this restriction in a way that |
| 382 | * keeps perf building on older glibc installations |
| 383 | * without CPU_ALLOC. 1024 cpus in 2010 still seems |
| 384 | * a reasonable upper limit tho :-) |
| 385 | */ |
| 386 | if (cpus->map[cpu] >= CPU_SETSIZE) { |
| 387 | pr_debug("Ignoring CPU %d\n", cpus->map[cpu]); |
| 388 | continue; |
| 389 | } |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 390 | |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 391 | CPU_SET(cpus->map[cpu], &cpu_set); |
| 392 | if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { |
Han Pingtian | ffb5e0f | 2011-01-20 19:47:07 +0800 | [diff] [blame] | 393 | pr_debug("sched_setaffinity() failed on CPU %d: %s ", |
| 394 | cpus->map[cpu], |
| 395 | strerror(errno)); |
| 396 | goto out_close_fd; |
| 397 | } |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 398 | for (i = 0; i < ncalls; ++i) { |
| 399 | fd = open("/etc/passwd", O_RDONLY); |
| 400 | close(fd); |
| 401 | } |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 402 | CPU_CLR(cpus->map[cpu], &cpu_set); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /* |
| 406 | * Here we need to explicitely preallocate the counts, as if |
| 407 | * we use the auto allocation it will allocate just for 1 cpu, |
| 408 | * as we start by cpu 0. |
| 409 | */ |
| 410 | if (perf_evsel__alloc_counts(evsel, cpus->nr) < 0) { |
| 411 | pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus->nr); |
| 412 | goto out_close_fd; |
| 413 | } |
| 414 | |
Arnaldo Carvalho de Melo | d2af968 | 2011-01-14 16:24:49 -0200 | [diff] [blame] | 415 | err = 0; |
| 416 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 417 | for (cpu = 0; cpu < cpus->nr; ++cpu) { |
| 418 | unsigned int expected; |
| 419 | |
Arnaldo Carvalho de Melo | 57b84e5 | 2011-01-22 23:14:20 -0200 | [diff] [blame] | 420 | if (cpus->map[cpu] >= CPU_SETSIZE) |
| 421 | continue; |
| 422 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 423 | if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) { |
Arnaldo Carvalho de Melo | 5d2cd90 | 2011-04-14 11:20:14 -0300 | [diff] [blame] | 424 | pr_debug("perf_evsel__read_on_cpu\n"); |
Arnaldo Carvalho de Melo | d2af968 | 2011-01-14 16:24:49 -0200 | [diff] [blame] | 425 | err = -1; |
| 426 | break; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | expected = nr_open_calls + cpu; |
| 430 | if (evsel->counts->cpu[cpu].val != expected) { |
Arnaldo Carvalho de Melo | 9486aa3 | 2011-01-22 20:37:02 -0200 | [diff] [blame] | 431 | pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n", |
Han Pingtian | ffb5e0f | 2011-01-20 19:47:07 +0800 | [diff] [blame] | 432 | expected, cpus->map[cpu], evsel->counts->cpu[cpu].val); |
Arnaldo Carvalho de Melo | d2af968 | 2011-01-14 16:24:49 -0200 | [diff] [blame] | 433 | err = -1; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 437 | out_close_fd: |
| 438 | perf_evsel__close_fd(evsel, 1, threads->nr); |
| 439 | out_evsel_delete: |
| 440 | perf_evsel__delete(evsel); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 441 | out_thread_map_delete: |
| 442 | thread_map__delete(threads); |
| 443 | return err; |
| 444 | } |
| 445 | |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 446 | /* |
| 447 | * This test will generate random numbers of calls to some getpid syscalls, |
| 448 | * then establish an mmap for a group of events that are created to monitor |
| 449 | * the syscalls. |
| 450 | * |
| 451 | * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated |
| 452 | * sample.id field to map back to its respective perf_evsel instance. |
| 453 | * |
| 454 | * Then it checks if the number of syscalls reported as perf events by |
| 455 | * the kernel corresponds to the number of syscalls made. |
| 456 | */ |
| 457 | static int test__basic_mmap(void) |
| 458 | { |
| 459 | int err = -1; |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 460 | union perf_event *event; |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 461 | struct thread_map *threads; |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 462 | struct cpu_map *cpus; |
| 463 | struct perf_evlist *evlist; |
| 464 | struct perf_event_attr attr = { |
| 465 | .type = PERF_TYPE_TRACEPOINT, |
| 466 | .read_format = PERF_FORMAT_ID, |
| 467 | .sample_type = PERF_SAMPLE_ID, |
| 468 | .watermark = 0, |
| 469 | }; |
| 470 | cpu_set_t cpu_set; |
| 471 | const char *syscall_names[] = { "getsid", "getppid", "getpgrp", |
| 472 | "getpgid", }; |
| 473 | pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp, |
| 474 | (void*)getpgid }; |
| 475 | #define nsyscalls ARRAY_SIZE(syscall_names) |
| 476 | int ids[nsyscalls]; |
| 477 | unsigned int nr_events[nsyscalls], |
| 478 | expected_nr_events[nsyscalls], i, j; |
| 479 | struct perf_evsel *evsels[nsyscalls], *evsel; |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 480 | int sample_size = __perf_evsel__sample_size(attr.sample_type); |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 481 | |
| 482 | for (i = 0; i < nsyscalls; ++i) { |
| 483 | char name[64]; |
| 484 | |
| 485 | snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); |
| 486 | ids[i] = trace_event__id(name); |
| 487 | if (ids[i] < 0) { |
| 488 | pr_debug("Is debugfs mounted on /sys/kernel/debug?\n"); |
| 489 | return -1; |
| 490 | } |
| 491 | nr_events[i] = 0; |
| 492 | expected_nr_events[i] = random() % 257; |
| 493 | } |
| 494 | |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 495 | threads = thread_map__new(-1, getpid(), UINT_MAX); |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 496 | if (threads == NULL) { |
| 497 | pr_debug("thread_map__new\n"); |
| 498 | return -1; |
| 499 | } |
| 500 | |
| 501 | cpus = cpu_map__new(NULL); |
Han Pingtian | 54489c18 | 2011-01-25 07:39:00 +0800 | [diff] [blame] | 502 | if (cpus == NULL) { |
| 503 | pr_debug("cpu_map__new\n"); |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 504 | goto out_free_threads; |
| 505 | } |
| 506 | |
| 507 | CPU_ZERO(&cpu_set); |
| 508 | CPU_SET(cpus->map[0], &cpu_set); |
| 509 | sched_setaffinity(0, sizeof(cpu_set), &cpu_set); |
| 510 | if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { |
| 511 | pr_debug("sched_setaffinity() failed on CPU %d: %s ", |
| 512 | cpus->map[0], strerror(errno)); |
| 513 | goto out_free_cpus; |
| 514 | } |
| 515 | |
Arnaldo Carvalho de Melo | 7e2ed09 | 2011-01-30 11:59:43 -0200 | [diff] [blame] | 516 | evlist = perf_evlist__new(cpus, threads); |
Han Pingtian | 54489c18 | 2011-01-25 07:39:00 +0800 | [diff] [blame] | 517 | if (evlist == NULL) { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 518 | pr_debug("perf_evlist__new\n"); |
| 519 | goto out_free_cpus; |
| 520 | } |
| 521 | |
| 522 | /* anonymous union fields, can't be initialized above */ |
| 523 | attr.wakeup_events = 1; |
| 524 | attr.sample_period = 1; |
| 525 | |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 526 | for (i = 0; i < nsyscalls; ++i) { |
| 527 | attr.config = ids[i]; |
| 528 | evsels[i] = perf_evsel__new(&attr, i); |
| 529 | if (evsels[i] == NULL) { |
| 530 | pr_debug("perf_evsel__new\n"); |
| 531 | goto out_free_evlist; |
| 532 | } |
| 533 | |
| 534 | perf_evlist__add(evlist, evsels[i]); |
| 535 | |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 536 | if (perf_evsel__open(evsels[i], cpus, threads, false, NULL) < 0) { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 537 | pr_debug("failed to open counter: %s, " |
| 538 | "tweak /proc/sys/kernel/perf_event_paranoid?\n", |
| 539 | strerror(errno)); |
| 540 | goto out_close_fd; |
| 541 | } |
| 542 | } |
| 543 | |
Arnaldo Carvalho de Melo | 7e2ed09 | 2011-01-30 11:59:43 -0200 | [diff] [blame] | 544 | if (perf_evlist__mmap(evlist, 128, true) < 0) { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 545 | pr_debug("failed to mmap events: %d (%s)\n", errno, |
| 546 | strerror(errno)); |
| 547 | goto out_close_fd; |
| 548 | } |
| 549 | |
| 550 | for (i = 0; i < nsyscalls; ++i) |
| 551 | for (j = 0; j < expected_nr_events[i]; ++j) { |
| 552 | int foo = syscalls[i](); |
| 553 | ++foo; |
| 554 | } |
| 555 | |
Arnaldo Carvalho de Melo | aece948 | 2011-05-15 09:39:00 -0300 | [diff] [blame] | 556 | while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) { |
Arnaldo Carvalho de Melo | 8d50e5b | 2011-01-29 13:02:00 -0200 | [diff] [blame] | 557 | struct perf_sample sample; |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 558 | |
| 559 | if (event->header.type != PERF_RECORD_SAMPLE) { |
| 560 | pr_debug("unexpected %s event\n", |
Arnaldo Carvalho de Melo | 8115d60 | 2011-01-29 14:01:45 -0200 | [diff] [blame] | 561 | perf_event__name(event->header.type)); |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 562 | goto out_munmap; |
| 563 | } |
| 564 | |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 565 | err = perf_event__parse_sample(event, attr.sample_type, sample_size, |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 566 | false, &sample, false); |
Frederic Weisbecker | 5538bec | 2011-05-22 02:17:22 +0200 | [diff] [blame] | 567 | if (err) { |
| 568 | pr_err("Can't parse sample, err = %d\n", err); |
| 569 | goto out_munmap; |
| 570 | } |
| 571 | |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 572 | evsel = perf_evlist__id2evsel(evlist, sample.id); |
| 573 | if (evsel == NULL) { |
| 574 | pr_debug("event with id %" PRIu64 |
| 575 | " doesn't map to an evsel\n", sample.id); |
| 576 | goto out_munmap; |
| 577 | } |
| 578 | nr_events[evsel->idx]++; |
| 579 | } |
| 580 | |
| 581 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 582 | if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) { |
| 583 | pr_debug("expected %d %s events, got %d\n", |
| 584 | expected_nr_events[evsel->idx], |
| 585 | event_name(evsel), nr_events[evsel->idx]); |
| 586 | goto out_munmap; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | err = 0; |
| 591 | out_munmap: |
Arnaldo Carvalho de Melo | 7e2ed09 | 2011-01-30 11:59:43 -0200 | [diff] [blame] | 592 | perf_evlist__munmap(evlist); |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 593 | out_close_fd: |
| 594 | for (i = 0; i < nsyscalls; ++i) |
| 595 | perf_evsel__close_fd(evsels[i], 1, threads->nr); |
| 596 | out_free_evlist: |
| 597 | perf_evlist__delete(evlist); |
| 598 | out_free_cpus: |
| 599 | cpu_map__delete(cpus); |
| 600 | out_free_threads: |
| 601 | thread_map__delete(threads); |
| 602 | return err; |
| 603 | #undef nsyscalls |
| 604 | } |
| 605 | |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 606 | #define TEST_ASSERT_VAL(text, cond) \ |
| 607 | do { \ |
Jiri Olsa | 65c1e04 | 2011-12-15 16:30:39 +0100 | [diff] [blame] | 608 | if (!(cond)) { \ |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 609 | pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \ |
| 610 | return -1; \ |
| 611 | } \ |
| 612 | } while (0) |
| 613 | |
| 614 | static int test__checkevent_tracepoint(struct perf_evlist *evlist) |
| 615 | { |
| 616 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 617 | struct perf_evsel, node); |
| 618 | |
| 619 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 620 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type); |
| 621 | TEST_ASSERT_VAL("wrong sample_type", |
| 622 | (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) == |
| 623 | evsel->attr.sample_type); |
| 624 | TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period); |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist) |
| 629 | { |
| 630 | struct perf_evsel *evsel; |
| 631 | |
| 632 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); |
| 633 | |
| 634 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 635 | TEST_ASSERT_VAL("wrong type", |
| 636 | PERF_TYPE_TRACEPOINT == evsel->attr.type); |
| 637 | TEST_ASSERT_VAL("wrong sample_type", |
| 638 | (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) |
| 639 | == evsel->attr.sample_type); |
| 640 | TEST_ASSERT_VAL("wrong sample_period", |
| 641 | 1 == evsel->attr.sample_period); |
| 642 | } |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | static int test__checkevent_raw(struct perf_evlist *evlist) |
| 647 | { |
| 648 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 649 | struct perf_evsel, node); |
| 650 | |
| 651 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 652 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type); |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 653 | TEST_ASSERT_VAL("wrong config", 0x1a == evsel->attr.config); |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static int test__checkevent_numeric(struct perf_evlist *evlist) |
| 658 | { |
| 659 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 660 | struct perf_evsel, node); |
| 661 | |
| 662 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 663 | TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type); |
| 664 | TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config); |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int test__checkevent_symbolic_name(struct perf_evlist *evlist) |
| 669 | { |
| 670 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 671 | struct perf_evsel, node); |
| 672 | |
| 673 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 674 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
| 675 | TEST_ASSERT_VAL("wrong config", |
| 676 | PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config); |
| 677 | return 0; |
| 678 | } |
| 679 | |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame^] | 680 | static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist) |
| 681 | { |
| 682 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 683 | struct perf_evsel, node); |
| 684 | |
| 685 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 686 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type); |
| 687 | TEST_ASSERT_VAL("wrong config", |
| 688 | PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config); |
| 689 | TEST_ASSERT_VAL("wrong period", |
| 690 | 100000 == evsel->attr.sample_period); |
| 691 | TEST_ASSERT_VAL("wrong config1", |
| 692 | 0 == evsel->attr.config1); |
| 693 | TEST_ASSERT_VAL("wrong config2", |
| 694 | 1 == evsel->attr.config2); |
| 695 | return 0; |
| 696 | } |
| 697 | |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 698 | static int test__checkevent_symbolic_alias(struct perf_evlist *evlist) |
| 699 | { |
| 700 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 701 | struct perf_evsel, node); |
| 702 | |
| 703 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 704 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type); |
| 705 | TEST_ASSERT_VAL("wrong config", |
| 706 | PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config); |
| 707 | return 0; |
| 708 | } |
| 709 | |
| 710 | static int test__checkevent_genhw(struct perf_evlist *evlist) |
| 711 | { |
| 712 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 713 | struct perf_evsel, node); |
| 714 | |
| 715 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 716 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type); |
| 717 | TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config); |
| 718 | return 0; |
| 719 | } |
| 720 | |
| 721 | static int test__checkevent_breakpoint(struct perf_evlist *evlist) |
| 722 | { |
| 723 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 724 | struct perf_evsel, node); |
| 725 | |
| 726 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 727 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 728 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 729 | TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) == |
| 730 | evsel->attr.bp_type); |
| 731 | TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 == |
| 732 | evsel->attr.bp_len); |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static int test__checkevent_breakpoint_x(struct perf_evlist *evlist) |
| 737 | { |
| 738 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 739 | struct perf_evsel, node); |
| 740 | |
| 741 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 742 | TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 743 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 744 | TEST_ASSERT_VAL("wrong bp_type", |
| 745 | HW_BREAKPOINT_X == evsel->attr.bp_type); |
| 746 | TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len); |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | static int test__checkevent_breakpoint_r(struct perf_evlist *evlist) |
| 751 | { |
| 752 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 753 | struct perf_evsel, node); |
| 754 | |
| 755 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 756 | TEST_ASSERT_VAL("wrong type", |
| 757 | PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 758 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 759 | TEST_ASSERT_VAL("wrong bp_type", |
| 760 | HW_BREAKPOINT_R == evsel->attr.bp_type); |
| 761 | TEST_ASSERT_VAL("wrong bp_len", |
| 762 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static int test__checkevent_breakpoint_w(struct perf_evlist *evlist) |
| 767 | { |
| 768 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 769 | struct perf_evsel, node); |
| 770 | |
| 771 | TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries); |
| 772 | TEST_ASSERT_VAL("wrong type", |
| 773 | PERF_TYPE_BREAKPOINT == evsel->attr.type); |
| 774 | TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config); |
| 775 | TEST_ASSERT_VAL("wrong bp_type", |
| 776 | HW_BREAKPOINT_W == evsel->attr.bp_type); |
| 777 | TEST_ASSERT_VAL("wrong bp_len", |
| 778 | HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len); |
| 779 | return 0; |
| 780 | } |
| 781 | |
Jiri Olsa | 65c1e04 | 2011-12-15 16:30:39 +0100 | [diff] [blame] | 782 | static int test__checkevent_tracepoint_modifier(struct perf_evlist *evlist) |
| 783 | { |
| 784 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 785 | struct perf_evsel, node); |
| 786 | |
| 787 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 788 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 789 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 790 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 791 | |
| 792 | return test__checkevent_tracepoint(evlist); |
| 793 | } |
| 794 | |
| 795 | static int |
| 796 | test__checkevent_tracepoint_multi_modifier(struct perf_evlist *evlist) |
| 797 | { |
| 798 | struct perf_evsel *evsel; |
| 799 | |
| 800 | TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1); |
| 801 | |
| 802 | list_for_each_entry(evsel, &evlist->entries, node) { |
| 803 | TEST_ASSERT_VAL("wrong exclude_user", |
| 804 | !evsel->attr.exclude_user); |
| 805 | TEST_ASSERT_VAL("wrong exclude_kernel", |
| 806 | evsel->attr.exclude_kernel); |
| 807 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 808 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 809 | } |
| 810 | |
| 811 | return test__checkevent_tracepoint_multi(evlist); |
| 812 | } |
| 813 | |
| 814 | static int test__checkevent_raw_modifier(struct perf_evlist *evlist) |
| 815 | { |
| 816 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 817 | struct perf_evsel, node); |
| 818 | |
| 819 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 820 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 821 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 822 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 823 | |
| 824 | return test__checkevent_raw(evlist); |
| 825 | } |
| 826 | |
| 827 | static int test__checkevent_numeric_modifier(struct perf_evlist *evlist) |
| 828 | { |
| 829 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 830 | struct perf_evsel, node); |
| 831 | |
| 832 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 833 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 834 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 835 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 836 | |
| 837 | return test__checkevent_numeric(evlist); |
| 838 | } |
| 839 | |
| 840 | static int test__checkevent_symbolic_name_modifier(struct perf_evlist *evlist) |
| 841 | { |
| 842 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 843 | struct perf_evsel, node); |
| 844 | |
| 845 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 846 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 847 | TEST_ASSERT_VAL("wrong exclude_hv", !evsel->attr.exclude_hv); |
| 848 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 849 | |
| 850 | return test__checkevent_symbolic_name(evlist); |
| 851 | } |
| 852 | |
| 853 | static int test__checkevent_symbolic_alias_modifier(struct perf_evlist *evlist) |
| 854 | { |
| 855 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 856 | struct perf_evsel, node); |
| 857 | |
| 858 | TEST_ASSERT_VAL("wrong exclude_user", !evsel->attr.exclude_user); |
| 859 | TEST_ASSERT_VAL("wrong exclude_kernel", evsel->attr.exclude_kernel); |
| 860 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 861 | TEST_ASSERT_VAL("wrong precise_ip", !evsel->attr.precise_ip); |
| 862 | |
| 863 | return test__checkevent_symbolic_alias(evlist); |
| 864 | } |
| 865 | |
| 866 | static int test__checkevent_genhw_modifier(struct perf_evlist *evlist) |
| 867 | { |
| 868 | struct perf_evsel *evsel = list_entry(evlist->entries.next, |
| 869 | struct perf_evsel, node); |
| 870 | |
| 871 | TEST_ASSERT_VAL("wrong exclude_user", evsel->attr.exclude_user); |
| 872 | TEST_ASSERT_VAL("wrong exclude_kernel", !evsel->attr.exclude_kernel); |
| 873 | TEST_ASSERT_VAL("wrong exclude_hv", evsel->attr.exclude_hv); |
| 874 | TEST_ASSERT_VAL("wrong precise_ip", evsel->attr.precise_ip); |
| 875 | |
| 876 | return test__checkevent_genhw(evlist); |
| 877 | } |
| 878 | |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 879 | static struct test__event_st { |
| 880 | const char *name; |
| 881 | __u32 type; |
| 882 | int (*check)(struct perf_evlist *evlist); |
| 883 | } test__events[] = { |
| 884 | { |
| 885 | .name = "syscalls:sys_enter_open", |
| 886 | .check = test__checkevent_tracepoint, |
| 887 | }, |
| 888 | { |
| 889 | .name = "syscalls:*", |
| 890 | .check = test__checkevent_tracepoint_multi, |
| 891 | }, |
| 892 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 893 | .name = "r1a", |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 894 | .check = test__checkevent_raw, |
| 895 | }, |
| 896 | { |
| 897 | .name = "1:1", |
| 898 | .check = test__checkevent_numeric, |
| 899 | }, |
| 900 | { |
| 901 | .name = "instructions", |
| 902 | .check = test__checkevent_symbolic_name, |
| 903 | }, |
| 904 | { |
Jiri Olsa | 8f707d8 | 2012-03-15 20:09:16 +0100 | [diff] [blame^] | 905 | .name = "cycles/period=100000,config2/", |
| 906 | .check = test__checkevent_symbolic_name_config, |
| 907 | }, |
| 908 | { |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 909 | .name = "faults", |
| 910 | .check = test__checkevent_symbolic_alias, |
| 911 | }, |
| 912 | { |
| 913 | .name = "L1-dcache-load-miss", |
| 914 | .check = test__checkevent_genhw, |
| 915 | }, |
| 916 | { |
| 917 | .name = "mem:0", |
| 918 | .check = test__checkevent_breakpoint, |
| 919 | }, |
| 920 | { |
| 921 | .name = "mem:0:x", |
| 922 | .check = test__checkevent_breakpoint_x, |
| 923 | }, |
| 924 | { |
| 925 | .name = "mem:0:r", |
| 926 | .check = test__checkevent_breakpoint_r, |
| 927 | }, |
| 928 | { |
| 929 | .name = "mem:0:w", |
| 930 | .check = test__checkevent_breakpoint_w, |
| 931 | }, |
Jiri Olsa | 65c1e04 | 2011-12-15 16:30:39 +0100 | [diff] [blame] | 932 | { |
| 933 | .name = "syscalls:sys_enter_open:k", |
| 934 | .check = test__checkevent_tracepoint_modifier, |
| 935 | }, |
| 936 | { |
| 937 | .name = "syscalls:*:u", |
| 938 | .check = test__checkevent_tracepoint_multi_modifier, |
| 939 | }, |
| 940 | { |
Jiri Olsa | 89812fc | 2012-03-15 20:09:15 +0100 | [diff] [blame] | 941 | .name = "r1a:kp", |
Jiri Olsa | 65c1e04 | 2011-12-15 16:30:39 +0100 | [diff] [blame] | 942 | .check = test__checkevent_raw_modifier, |
| 943 | }, |
| 944 | { |
| 945 | .name = "1:1:hp", |
| 946 | .check = test__checkevent_numeric_modifier, |
| 947 | }, |
| 948 | { |
| 949 | .name = "instructions:h", |
| 950 | .check = test__checkevent_symbolic_name_modifier, |
| 951 | }, |
| 952 | { |
| 953 | .name = "faults:u", |
| 954 | .check = test__checkevent_symbolic_alias_modifier, |
| 955 | }, |
| 956 | { |
| 957 | .name = "L1-dcache-load-miss:kp", |
| 958 | .check = test__checkevent_genhw_modifier, |
| 959 | }, |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 960 | }; |
| 961 | |
| 962 | #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st)) |
| 963 | |
| 964 | static int test__parse_events(void) |
| 965 | { |
| 966 | struct perf_evlist *evlist; |
| 967 | u_int i; |
| 968 | int ret = 0; |
| 969 | |
| 970 | for (i = 0; i < TEST__EVENTS_CNT; i++) { |
| 971 | struct test__event_st *e = &test__events[i]; |
| 972 | |
| 973 | evlist = perf_evlist__new(NULL, NULL); |
| 974 | if (evlist == NULL) |
| 975 | break; |
| 976 | |
| 977 | ret = parse_events(evlist, e->name, 0); |
| 978 | if (ret) { |
| 979 | pr_debug("failed to parse event '%s', err %d\n", |
| 980 | e->name, ret); |
| 981 | break; |
| 982 | } |
| 983 | |
| 984 | ret = e->check(evlist); |
| 985 | if (ret) |
| 986 | break; |
| 987 | |
| 988 | perf_evlist__delete(evlist); |
| 989 | } |
| 990 | |
| 991 | return ret; |
| 992 | } |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 993 | |
| 994 | static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp, |
| 995 | size_t *sizep) |
| 996 | { |
| 997 | cpu_set_t *mask; |
| 998 | size_t size; |
| 999 | int i, cpu = -1, nrcpus = 1024; |
| 1000 | realloc: |
| 1001 | mask = CPU_ALLOC(nrcpus); |
| 1002 | size = CPU_ALLOC_SIZE(nrcpus); |
| 1003 | CPU_ZERO_S(size, mask); |
| 1004 | |
| 1005 | if (sched_getaffinity(pid, size, mask) == -1) { |
| 1006 | CPU_FREE(mask); |
| 1007 | if (errno == EINVAL && nrcpus < (1024 << 8)) { |
| 1008 | nrcpus = nrcpus << 2; |
| 1009 | goto realloc; |
| 1010 | } |
| 1011 | perror("sched_getaffinity"); |
| 1012 | return -1; |
| 1013 | } |
| 1014 | |
| 1015 | for (i = 0; i < nrcpus; i++) { |
| 1016 | if (CPU_ISSET_S(i, size, mask)) { |
| 1017 | if (cpu == -1) { |
| 1018 | cpu = i; |
| 1019 | *maskp = mask; |
| 1020 | *sizep = size; |
| 1021 | } else |
| 1022 | CPU_CLR_S(i, size, mask); |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | if (cpu == -1) |
| 1027 | CPU_FREE(mask); |
| 1028 | |
| 1029 | return cpu; |
| 1030 | } |
| 1031 | |
| 1032 | static int test__PERF_RECORD(void) |
| 1033 | { |
| 1034 | struct perf_record_opts opts = { |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1035 | .no_delay = true, |
| 1036 | .freq = 10, |
| 1037 | .mmap_pages = 256, |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1038 | }; |
| 1039 | cpu_set_t *cpu_mask = NULL; |
| 1040 | size_t cpu_mask_size = 0; |
| 1041 | struct perf_evlist *evlist = perf_evlist__new(NULL, NULL); |
| 1042 | struct perf_evsel *evsel; |
| 1043 | struct perf_sample sample; |
| 1044 | const char *cmd = "sleep"; |
| 1045 | const char *argv[] = { cmd, "1", NULL, }; |
| 1046 | char *bname; |
| 1047 | u64 sample_type, prev_time = 0; |
| 1048 | bool found_cmd_mmap = false, |
| 1049 | found_libc_mmap = false, |
| 1050 | found_vdso_mmap = false, |
| 1051 | found_ld_mmap = false; |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1052 | int err = -1, errs = 0, i, wakeups = 0, sample_size; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1053 | u32 cpu; |
| 1054 | int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, }; |
| 1055 | |
| 1056 | if (evlist == NULL || argv == NULL) { |
| 1057 | pr_debug("Not enough memory to create evlist\n"); |
| 1058 | goto out; |
| 1059 | } |
| 1060 | |
| 1061 | /* |
| 1062 | * We need at least one evsel in the evlist, use the default |
| 1063 | * one: "cycles". |
| 1064 | */ |
| 1065 | err = perf_evlist__add_default(evlist); |
| 1066 | if (err < 0) { |
| 1067 | pr_debug("Not enough memory to create evsel\n"); |
| 1068 | goto out_delete_evlist; |
| 1069 | } |
| 1070 | |
| 1071 | /* |
| 1072 | * Create maps of threads and cpus to monitor. In this case |
| 1073 | * we start with all threads and cpus (-1, -1) but then in |
| 1074 | * perf_evlist__prepare_workload we'll fill in the only thread |
| 1075 | * we're monitoring, the one forked there. |
| 1076 | */ |
| 1077 | err = perf_evlist__create_maps(evlist, opts.target_pid, |
Arnaldo Carvalho de Melo | 0d37aa3 | 2012-01-19 14:08:15 -0200 | [diff] [blame] | 1078 | opts.target_tid, UINT_MAX, opts.cpu_list); |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1079 | if (err < 0) { |
| 1080 | pr_debug("Not enough memory to create thread/cpu maps\n"); |
| 1081 | goto out_delete_evlist; |
| 1082 | } |
| 1083 | |
| 1084 | /* |
| 1085 | * Prepare the workload in argv[] to run, it'll fork it, and then wait |
| 1086 | * for perf_evlist__start_workload() to exec it. This is done this way |
| 1087 | * so that we have time to open the evlist (calling sys_perf_event_open |
| 1088 | * on all the fds) and then mmap them. |
| 1089 | */ |
| 1090 | err = perf_evlist__prepare_workload(evlist, &opts, argv); |
| 1091 | if (err < 0) { |
| 1092 | pr_debug("Couldn't run the workload!\n"); |
| 1093 | goto out_delete_evlist; |
| 1094 | } |
| 1095 | |
| 1096 | /* |
| 1097 | * Config the evsels, setting attr->comm on the first one, etc. |
| 1098 | */ |
| 1099 | evsel = list_entry(evlist->entries.next, struct perf_evsel, node); |
| 1100 | evsel->attr.sample_type |= PERF_SAMPLE_CPU; |
| 1101 | evsel->attr.sample_type |= PERF_SAMPLE_TID; |
| 1102 | evsel->attr.sample_type |= PERF_SAMPLE_TIME; |
| 1103 | perf_evlist__config_attrs(evlist, &opts); |
| 1104 | |
| 1105 | err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask, |
| 1106 | &cpu_mask_size); |
| 1107 | if (err < 0) { |
| 1108 | pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno)); |
| 1109 | goto out_delete_evlist; |
| 1110 | } |
| 1111 | |
| 1112 | cpu = err; |
| 1113 | |
| 1114 | /* |
| 1115 | * So that we can check perf_sample.cpu on all the samples. |
| 1116 | */ |
| 1117 | if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, cpu_mask) < 0) { |
| 1118 | pr_debug("sched_setaffinity: %s\n", strerror(errno)); |
| 1119 | goto out_free_cpu_mask; |
| 1120 | } |
| 1121 | |
| 1122 | /* |
| 1123 | * Call sys_perf_event_open on all the fds on all the evsels, |
| 1124 | * grouping them if asked to. |
| 1125 | */ |
| 1126 | err = perf_evlist__open(evlist, opts.group); |
| 1127 | if (err < 0) { |
| 1128 | pr_debug("perf_evlist__open: %s\n", strerror(errno)); |
| 1129 | goto out_delete_evlist; |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * mmap the first fd on a given CPU and ask for events for the other |
| 1134 | * fds in the same CPU to be injected in the same mmap ring buffer |
| 1135 | * (using ioctl(PERF_EVENT_IOC_SET_OUTPUT)). |
| 1136 | */ |
| 1137 | err = perf_evlist__mmap(evlist, opts.mmap_pages, false); |
| 1138 | if (err < 0) { |
| 1139 | pr_debug("perf_evlist__mmap: %s\n", strerror(errno)); |
| 1140 | goto out_delete_evlist; |
| 1141 | } |
| 1142 | |
| 1143 | /* |
| 1144 | * We'll need these two to parse the PERF_SAMPLE_* fields in each |
| 1145 | * event. |
| 1146 | */ |
| 1147 | sample_type = perf_evlist__sample_type(evlist); |
| 1148 | sample_size = __perf_evsel__sample_size(sample_type); |
| 1149 | |
| 1150 | /* |
| 1151 | * Now that all is properly set up, enable the events, they will |
| 1152 | * count just on workload.pid, which will start... |
| 1153 | */ |
| 1154 | perf_evlist__enable(evlist); |
| 1155 | |
| 1156 | /* |
| 1157 | * Now! |
| 1158 | */ |
| 1159 | perf_evlist__start_workload(evlist); |
| 1160 | |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1161 | while (1) { |
| 1162 | int before = total_events; |
| 1163 | |
| 1164 | for (i = 0; i < evlist->nr_mmaps; i++) { |
| 1165 | union perf_event *event; |
| 1166 | |
| 1167 | while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) { |
| 1168 | const u32 type = event->header.type; |
| 1169 | const char *name = perf_event__name(type); |
| 1170 | |
| 1171 | ++total_events; |
| 1172 | if (type < PERF_RECORD_MAX) |
| 1173 | nr_events[type]++; |
| 1174 | |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1175 | err = perf_event__parse_sample(event, sample_type, |
| 1176 | sample_size, true, |
| 1177 | &sample, false); |
| 1178 | if (err < 0) { |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1179 | if (verbose) |
| 1180 | perf_event__fprintf(event, stderr); |
| 1181 | pr_debug("Couldn't parse sample\n"); |
| 1182 | goto out_err; |
| 1183 | } |
| 1184 | |
| 1185 | if (verbose) { |
| 1186 | pr_info("%" PRIu64" %d ", sample.time, sample.cpu); |
| 1187 | perf_event__fprintf(event, stderr); |
| 1188 | } |
| 1189 | |
| 1190 | if (prev_time > sample.time) { |
| 1191 | pr_debug("%s going backwards in time, prev=%" PRIu64 ", curr=%" PRIu64 "\n", |
| 1192 | name, prev_time, sample.time); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1193 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | prev_time = sample.time; |
| 1197 | |
| 1198 | if (sample.cpu != cpu) { |
| 1199 | pr_debug("%s with unexpected cpu, expected %d, got %d\n", |
| 1200 | name, cpu, sample.cpu); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1201 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | if ((pid_t)sample.pid != evlist->workload.pid) { |
| 1205 | pr_debug("%s with unexpected pid, expected %d, got %d\n", |
| 1206 | name, evlist->workload.pid, sample.pid); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1207 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | if ((pid_t)sample.tid != evlist->workload.pid) { |
| 1211 | pr_debug("%s with unexpected tid, expected %d, got %d\n", |
| 1212 | name, evlist->workload.pid, sample.tid); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1213 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if ((type == PERF_RECORD_COMM || |
| 1217 | type == PERF_RECORD_MMAP || |
| 1218 | type == PERF_RECORD_FORK || |
| 1219 | type == PERF_RECORD_EXIT) && |
| 1220 | (pid_t)event->comm.pid != evlist->workload.pid) { |
| 1221 | pr_debug("%s with unexpected pid/tid\n", name); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1222 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | if ((type == PERF_RECORD_COMM || |
| 1226 | type == PERF_RECORD_MMAP) && |
| 1227 | event->comm.pid != event->comm.tid) { |
| 1228 | pr_debug("%s with different pid/tid!\n", name); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1229 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | switch (type) { |
| 1233 | case PERF_RECORD_COMM: |
| 1234 | if (strcmp(event->comm.comm, cmd)) { |
| 1235 | pr_debug("%s with unexpected comm!\n", name); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1236 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1237 | } |
| 1238 | break; |
| 1239 | case PERF_RECORD_EXIT: |
| 1240 | goto found_exit; |
| 1241 | case PERF_RECORD_MMAP: |
| 1242 | bname = strrchr(event->mmap.filename, '/'); |
| 1243 | if (bname != NULL) { |
| 1244 | if (!found_cmd_mmap) |
| 1245 | found_cmd_mmap = !strcmp(bname + 1, cmd); |
| 1246 | if (!found_libc_mmap) |
| 1247 | found_libc_mmap = !strncmp(bname + 1, "libc", 4); |
| 1248 | if (!found_ld_mmap) |
| 1249 | found_ld_mmap = !strncmp(bname + 1, "ld", 2); |
| 1250 | } else if (!found_vdso_mmap) |
| 1251 | found_vdso_mmap = !strcmp(event->mmap.filename, "[vdso]"); |
| 1252 | break; |
| 1253 | |
| 1254 | case PERF_RECORD_SAMPLE: |
| 1255 | /* Just ignore samples for now */ |
| 1256 | break; |
| 1257 | default: |
| 1258 | pr_debug("Unexpected perf_event->header.type %d!\n", |
| 1259 | type); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1260 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
| 1265 | /* |
| 1266 | * We don't use poll here because at least at 3.1 times the |
| 1267 | * PERF_RECORD_{!SAMPLE} events don't honour |
| 1268 | * perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does. |
| 1269 | */ |
| 1270 | if (total_events == before && false) |
| 1271 | poll(evlist->pollfd, evlist->nr_fds, -1); |
| 1272 | |
| 1273 | sleep(1); |
| 1274 | if (++wakeups > 5) { |
| 1275 | pr_debug("No PERF_RECORD_EXIT event!\n"); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1276 | break; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | found_exit: |
| 1281 | if (nr_events[PERF_RECORD_COMM] > 1) { |
| 1282 | pr_debug("Excessive number of PERF_RECORD_COMM events!\n"); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1283 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | if (nr_events[PERF_RECORD_COMM] == 0) { |
| 1287 | pr_debug("Missing PERF_RECORD_COMM for %s!\n", cmd); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1288 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | if (!found_cmd_mmap) { |
| 1292 | pr_debug("PERF_RECORD_MMAP for %s missing!\n", cmd); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1293 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (!found_libc_mmap) { |
| 1297 | pr_debug("PERF_RECORD_MMAP for %s missing!\n", "libc"); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1298 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | if (!found_ld_mmap) { |
| 1302 | pr_debug("PERF_RECORD_MMAP for %s missing!\n", "ld"); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1303 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | if (!found_vdso_mmap) { |
| 1307 | pr_debug("PERF_RECORD_MMAP for %s missing!\n", "[vdso]"); |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1308 | ++errs; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1309 | } |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1310 | out_err: |
| 1311 | perf_evlist__munmap(evlist); |
| 1312 | out_free_cpu_mask: |
| 1313 | CPU_FREE(cpu_mask); |
| 1314 | out_delete_evlist: |
| 1315 | perf_evlist__delete(evlist); |
| 1316 | out: |
Arnaldo Carvalho de Melo | f71c49e | 2011-12-02 13:53:04 -0200 | [diff] [blame] | 1317 | return (err < 0 || errs > 0) ? -1 : 0; |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1318 | } |
| 1319 | |
Peter Zijlstra | 08aa0d1 | 2011-11-21 14:42:47 +0100 | [diff] [blame] | 1320 | |
| 1321 | #if defined(__x86_64__) || defined(__i386__) |
| 1322 | |
| 1323 | #define barrier() asm volatile("" ::: "memory") |
| 1324 | |
| 1325 | static u64 rdpmc(unsigned int counter) |
| 1326 | { |
| 1327 | unsigned int low, high; |
| 1328 | |
| 1329 | asm volatile("rdpmc" : "=a" (low), "=d" (high) : "c" (counter)); |
| 1330 | |
| 1331 | return low | ((u64)high) << 32; |
| 1332 | } |
| 1333 | |
| 1334 | static u64 rdtsc(void) |
| 1335 | { |
| 1336 | unsigned int low, high; |
| 1337 | |
| 1338 | asm volatile("rdtsc" : "=a" (low), "=d" (high)); |
| 1339 | |
| 1340 | return low | ((u64)high) << 32; |
| 1341 | } |
| 1342 | |
| 1343 | static u64 mmap_read_self(void *addr) |
| 1344 | { |
| 1345 | struct perf_event_mmap_page *pc = addr; |
| 1346 | u32 seq, idx, time_mult = 0, time_shift = 0; |
| 1347 | u64 count, cyc = 0, time_offset = 0, enabled, running, delta; |
| 1348 | |
| 1349 | do { |
| 1350 | seq = pc->lock; |
| 1351 | barrier(); |
| 1352 | |
| 1353 | enabled = pc->time_enabled; |
| 1354 | running = pc->time_running; |
| 1355 | |
| 1356 | if (enabled != running) { |
| 1357 | cyc = rdtsc(); |
| 1358 | time_mult = pc->time_mult; |
| 1359 | time_shift = pc->time_shift; |
| 1360 | time_offset = pc->time_offset; |
| 1361 | } |
| 1362 | |
| 1363 | idx = pc->index; |
| 1364 | count = pc->offset; |
| 1365 | if (idx) |
| 1366 | count += rdpmc(idx - 1); |
| 1367 | |
| 1368 | barrier(); |
| 1369 | } while (pc->lock != seq); |
| 1370 | |
| 1371 | if (enabled != running) { |
| 1372 | u64 quot, rem; |
| 1373 | |
| 1374 | quot = (cyc >> time_shift); |
| 1375 | rem = cyc & ((1 << time_shift) - 1); |
| 1376 | delta = time_offset + quot * time_mult + |
| 1377 | ((rem * time_mult) >> time_shift); |
| 1378 | |
| 1379 | enabled += delta; |
| 1380 | if (idx) |
| 1381 | running += delta; |
| 1382 | |
| 1383 | quot = count / running; |
| 1384 | rem = count % running; |
| 1385 | count = quot * enabled + (rem * enabled) / running; |
| 1386 | } |
| 1387 | |
| 1388 | return count; |
| 1389 | } |
| 1390 | |
| 1391 | /* |
| 1392 | * If the RDPMC instruction faults then signal this back to the test parent task: |
| 1393 | */ |
| 1394 | static void segfault_handler(int sig __used, siginfo_t *info __used, void *uc __used) |
| 1395 | { |
| 1396 | exit(-1); |
| 1397 | } |
| 1398 | |
| 1399 | static int __test__rdpmc(void) |
| 1400 | { |
| 1401 | long page_size = sysconf(_SC_PAGE_SIZE); |
| 1402 | volatile int tmp = 0; |
| 1403 | u64 i, loops = 1000; |
| 1404 | int n; |
| 1405 | int fd; |
| 1406 | void *addr; |
| 1407 | struct perf_event_attr attr = { |
| 1408 | .type = PERF_TYPE_HARDWARE, |
| 1409 | .config = PERF_COUNT_HW_INSTRUCTIONS, |
| 1410 | .exclude_kernel = 1, |
| 1411 | }; |
| 1412 | u64 delta_sum = 0; |
| 1413 | struct sigaction sa; |
| 1414 | |
| 1415 | sigfillset(&sa.sa_mask); |
| 1416 | sa.sa_sigaction = segfault_handler; |
| 1417 | sigaction(SIGSEGV, &sa, NULL); |
| 1418 | |
| 1419 | fprintf(stderr, "\n\n"); |
| 1420 | |
| 1421 | fd = sys_perf_event_open(&attr, 0, -1, -1, 0); |
| 1422 | if (fd < 0) { |
| 1423 | die("Error: sys_perf_event_open() syscall returned " |
| 1424 | "with %d (%s)\n", fd, strerror(errno)); |
| 1425 | } |
| 1426 | |
| 1427 | addr = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); |
| 1428 | if (addr == (void *)(-1)) { |
| 1429 | die("Error: mmap() syscall returned " |
| 1430 | "with (%s)\n", strerror(errno)); |
| 1431 | } |
| 1432 | |
| 1433 | for (n = 0; n < 6; n++) { |
| 1434 | u64 stamp, now, delta; |
| 1435 | |
| 1436 | stamp = mmap_read_self(addr); |
| 1437 | |
| 1438 | for (i = 0; i < loops; i++) |
| 1439 | tmp++; |
| 1440 | |
| 1441 | now = mmap_read_self(addr); |
| 1442 | loops *= 10; |
| 1443 | |
| 1444 | delta = now - stamp; |
| 1445 | fprintf(stderr, "%14d: %14Lu\n", n, (long long)delta); |
| 1446 | |
| 1447 | delta_sum += delta; |
| 1448 | } |
| 1449 | |
| 1450 | munmap(addr, page_size); |
| 1451 | close(fd); |
| 1452 | |
| 1453 | fprintf(stderr, " "); |
| 1454 | |
| 1455 | if (!delta_sum) |
| 1456 | return -1; |
| 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
| 1461 | static int test__rdpmc(void) |
| 1462 | { |
| 1463 | int status = 0; |
| 1464 | int wret = 0; |
| 1465 | int ret; |
| 1466 | int pid; |
| 1467 | |
| 1468 | pid = fork(); |
| 1469 | if (pid < 0) |
| 1470 | return -1; |
| 1471 | |
| 1472 | if (!pid) { |
| 1473 | ret = __test__rdpmc(); |
| 1474 | |
| 1475 | exit(ret); |
| 1476 | } |
| 1477 | |
| 1478 | wret = waitpid(pid, &status, 0); |
| 1479 | if (wret < 0 || status) |
| 1480 | return -1; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | #endif |
| 1486 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1487 | static struct test { |
| 1488 | const char *desc; |
| 1489 | int (*func)(void); |
| 1490 | } tests[] = { |
| 1491 | { |
| 1492 | .desc = "vmlinux symtab matches kallsyms", |
| 1493 | .func = test__vmlinux_matches_kallsyms, |
| 1494 | }, |
| 1495 | { |
Arnaldo Carvalho de Melo | d854861 | 2011-01-04 00:16:20 -0200 | [diff] [blame] | 1496 | .desc = "detect open syscall event", |
| 1497 | .func = test__open_syscall_event, |
| 1498 | }, |
| 1499 | { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1500 | .desc = "detect open syscall event on all cpus", |
| 1501 | .func = test__open_syscall_event_on_all_cpus, |
| 1502 | }, |
| 1503 | { |
Arnaldo Carvalho de Melo | de5fa3a | 2011-01-15 10:42:46 -0200 | [diff] [blame] | 1504 | .desc = "read samples using the mmap interface", |
| 1505 | .func = test__basic_mmap, |
| 1506 | }, |
| 1507 | { |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 1508 | .desc = "parse events tests", |
| 1509 | .func = test__parse_events, |
| 1510 | }, |
Peter Zijlstra | 08aa0d1 | 2011-11-21 14:42:47 +0100 | [diff] [blame] | 1511 | #if defined(__x86_64__) || defined(__i386__) |
| 1512 | { |
| 1513 | .desc = "x86 rdpmc test", |
| 1514 | .func = test__rdpmc, |
| 1515 | }, |
| 1516 | #endif |
Jiri Olsa | 13b6256 | 2011-07-14 11:25:33 +0200 | [diff] [blame] | 1517 | { |
Arnaldo Carvalho de Melo | 3e7c439 | 2011-12-02 11:13:50 -0200 | [diff] [blame] | 1518 | .desc = "Validate PERF_RECORD_* events & perf_sample fields", |
| 1519 | .func = test__PERF_RECORD, |
| 1520 | }, |
| 1521 | { |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1522 | .func = NULL, |
| 1523 | }, |
| 1524 | }; |
| 1525 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1526 | static bool perf_test__matches(int curr, int argc, const char *argv[]) |
| 1527 | { |
| 1528 | int i; |
| 1529 | |
| 1530 | if (argc == 0) |
| 1531 | return true; |
| 1532 | |
| 1533 | for (i = 0; i < argc; ++i) { |
| 1534 | char *end; |
| 1535 | long nr = strtoul(argv[i], &end, 10); |
| 1536 | |
| 1537 | if (*end == '\0') { |
| 1538 | if (nr == curr + 1) |
| 1539 | return true; |
| 1540 | continue; |
| 1541 | } |
| 1542 | |
| 1543 | if (strstr(tests[curr].desc, argv[i])) |
| 1544 | return true; |
| 1545 | } |
| 1546 | |
| 1547 | return false; |
| 1548 | } |
| 1549 | |
| 1550 | static int __cmd_test(int argc, const char *argv[]) |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1551 | { |
| 1552 | int i = 0; |
| 1553 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1554 | while (tests[i].func) { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1555 | int curr = i++, err; |
| 1556 | |
| 1557 | if (!perf_test__matches(curr, argc, argv)) |
| 1558 | continue; |
| 1559 | |
| 1560 | pr_info("%2d: %s:", i, tests[curr].desc); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1561 | pr_debug("\n--- start ---\n"); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1562 | err = tests[curr].func(); |
| 1563 | pr_debug("---- end ----\n%s:", tests[curr].desc); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1564 | pr_info(" %s\n", err ? "FAILED!\n" : "Ok"); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1570 | static int perf_test__list(int argc, const char **argv) |
| 1571 | { |
| 1572 | int i = 0; |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1573 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1574 | while (tests[i].func) { |
| 1575 | int curr = i++; |
| 1576 | |
| 1577 | if (argc > 1 && !strstr(tests[curr].desc, argv[1])) |
| 1578 | continue; |
| 1579 | |
| 1580 | pr_info("%2d: %s\n", i, tests[curr].desc); |
| 1581 | } |
| 1582 | |
| 1583 | return 0; |
| 1584 | } |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1585 | |
| 1586 | int cmd_test(int argc, const char **argv, const char *prefix __used) |
| 1587 | { |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1588 | const char * const test_usage[] = { |
| 1589 | "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", |
| 1590 | NULL, |
| 1591 | }; |
| 1592 | const struct option test_options[] = { |
Namhyung Kim | c30ab8a | 2012-01-08 02:25:26 +0900 | [diff] [blame] | 1593 | OPT_INCR('v', "verbose", &verbose, |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1594 | "be more verbose (show symbol address, etc)"), |
| 1595 | OPT_END() |
| 1596 | }; |
| 1597 | |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1598 | argc = parse_options(argc, argv, test_options, test_usage, 0); |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1599 | if (argc >= 1 && !strcmp(argv[0], "list")) |
| 1600 | return perf_test__list(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1601 | |
| 1602 | symbol_conf.priv_size = sizeof(int); |
| 1603 | symbol_conf.sort_by_name = true; |
| 1604 | symbol_conf.try_vmlinux_path = true; |
| 1605 | |
| 1606 | if (symbol__init() < 0) |
| 1607 | return -1; |
| 1608 | |
Arnaldo Carvalho de Melo | e60770a | 2011-11-29 12:52:07 -0200 | [diff] [blame] | 1609 | return __cmd_test(argc, argv); |
Arnaldo Carvalho de Melo | 1c6a800 | 2010-04-29 18:58:32 -0300 | [diff] [blame] | 1610 | } |