.. | .. |
---|
2 | 2 | #include <sys/time.h> |
---|
3 | 3 | #include <sys/prctl.h> |
---|
4 | 4 | #include <errno.h> |
---|
| 5 | +#include <limits.h> |
---|
5 | 6 | #include <time.h> |
---|
6 | 7 | #include <stdlib.h> |
---|
| 8 | +#include <linux/zalloc.h> |
---|
| 9 | +#include <perf/cpumap.h> |
---|
| 10 | +#include <perf/evlist.h> |
---|
| 11 | +#include <perf/mmap.h> |
---|
7 | 12 | |
---|
| 13 | +#include "debug.h" |
---|
8 | 14 | #include "parse-events.h" |
---|
9 | 15 | #include "evlist.h" |
---|
10 | 16 | #include "evsel.h" |
---|
11 | 17 | #include "thread_map.h" |
---|
12 | | -#include "cpumap.h" |
---|
| 18 | +#include "record.h" |
---|
13 | 19 | #include "tests.h" |
---|
| 20 | +#include "util/mmap.h" |
---|
14 | 21 | |
---|
15 | 22 | static int spin_sleep(void) |
---|
16 | 23 | { |
---|
.. | .. |
---|
51 | 58 | } |
---|
52 | 59 | |
---|
53 | 60 | struct switch_tracking { |
---|
54 | | - struct perf_evsel *switch_evsel; |
---|
55 | | - struct perf_evsel *cycles_evsel; |
---|
| 61 | + struct evsel *switch_evsel; |
---|
| 62 | + struct evsel *cycles_evsel; |
---|
56 | 63 | pid_t *tids; |
---|
57 | 64 | int nr_tids; |
---|
58 | 65 | int comm_seen[4]; |
---|
.. | .. |
---|
112 | 119 | return 0; |
---|
113 | 120 | } |
---|
114 | 121 | |
---|
115 | | -static int process_sample_event(struct perf_evlist *evlist, |
---|
| 122 | +static int process_sample_event(struct evlist *evlist, |
---|
116 | 123 | union perf_event *event, |
---|
117 | 124 | struct switch_tracking *switch_tracking) |
---|
118 | 125 | { |
---|
119 | 126 | struct perf_sample sample; |
---|
120 | | - struct perf_evsel *evsel; |
---|
| 127 | + struct evsel *evsel; |
---|
121 | 128 | pid_t next_tid, prev_tid; |
---|
122 | 129 | int cpu, err; |
---|
123 | 130 | |
---|
.. | .. |
---|
128 | 135 | |
---|
129 | 136 | evsel = perf_evlist__id2evsel(evlist, sample.id); |
---|
130 | 137 | if (evsel == switch_tracking->switch_evsel) { |
---|
131 | | - next_tid = perf_evsel__intval(evsel, &sample, "next_pid"); |
---|
132 | | - prev_tid = perf_evsel__intval(evsel, &sample, "prev_pid"); |
---|
| 138 | + next_tid = evsel__intval(evsel, &sample, "next_pid"); |
---|
| 139 | + prev_tid = evsel__intval(evsel, &sample, "prev_pid"); |
---|
133 | 140 | cpu = sample.cpu; |
---|
134 | 141 | pr_debug3("sched_switch: cpu: %d prev_tid %d next_tid %d\n", |
---|
135 | 142 | cpu, prev_tid, next_tid); |
---|
.. | .. |
---|
138 | 145 | return err; |
---|
139 | 146 | /* |
---|
140 | 147 | * Check for no missing sched_switch events i.e. that the |
---|
141 | | - * evsel->system_wide flag has worked. |
---|
| 148 | + * evsel->core.system_wide flag has worked. |
---|
142 | 149 | */ |
---|
143 | 150 | if (switch_tracking->tids[cpu] != -1 && |
---|
144 | 151 | switch_tracking->tids[cpu] != prev_tid) { |
---|
.. | .. |
---|
162 | 169 | return 0; |
---|
163 | 170 | } |
---|
164 | 171 | |
---|
165 | | -static int process_event(struct perf_evlist *evlist, union perf_event *event, |
---|
| 172 | +static int process_event(struct evlist *evlist, union perf_event *event, |
---|
166 | 173 | struct switch_tracking *switch_tracking) |
---|
167 | 174 | { |
---|
168 | 175 | if (event->header.type == PERF_RECORD_SAMPLE) |
---|
.. | .. |
---|
202 | 209 | u64 event_time; |
---|
203 | 210 | }; |
---|
204 | 211 | |
---|
205 | | -static int add_event(struct perf_evlist *evlist, struct list_head *events, |
---|
| 212 | +static int add_event(struct evlist *evlist, struct list_head *events, |
---|
206 | 213 | union perf_event *event) |
---|
207 | 214 | { |
---|
208 | 215 | struct perf_sample sample; |
---|
.. | .. |
---|
237 | 244 | |
---|
238 | 245 | while (!list_empty(events)) { |
---|
239 | 246 | node = list_entry(events->next, struct event_node, list); |
---|
240 | | - list_del(&node->list); |
---|
| 247 | + list_del_init(&node->list); |
---|
241 | 248 | free(node); |
---|
242 | 249 | } |
---|
243 | 250 | } |
---|
.. | .. |
---|
251 | 258 | return cmp; |
---|
252 | 259 | } |
---|
253 | 260 | |
---|
254 | | -static int process_events(struct perf_evlist *evlist, |
---|
| 261 | +static int process_events(struct evlist *evlist, |
---|
255 | 262 | struct switch_tracking *switch_tracking) |
---|
256 | 263 | { |
---|
257 | 264 | union perf_event *event; |
---|
258 | 265 | unsigned pos, cnt = 0; |
---|
259 | 266 | LIST_HEAD(events); |
---|
260 | 267 | struct event_node *events_array, *node; |
---|
261 | | - struct perf_mmap *md; |
---|
| 268 | + struct mmap *md; |
---|
262 | 269 | int i, ret; |
---|
263 | 270 | |
---|
264 | | - for (i = 0; i < evlist->nr_mmaps; i++) { |
---|
| 271 | + for (i = 0; i < evlist->core.nr_mmaps; i++) { |
---|
265 | 272 | md = &evlist->mmap[i]; |
---|
266 | | - if (perf_mmap__read_init(md) < 0) |
---|
| 273 | + if (perf_mmap__read_init(&md->core) < 0) |
---|
267 | 274 | continue; |
---|
268 | 275 | |
---|
269 | | - while ((event = perf_mmap__read_event(md)) != NULL) { |
---|
| 276 | + while ((event = perf_mmap__read_event(&md->core)) != NULL) { |
---|
270 | 277 | cnt += 1; |
---|
271 | 278 | ret = add_event(evlist, &events, event); |
---|
272 | | - perf_mmap__consume(md); |
---|
| 279 | + perf_mmap__consume(&md->core); |
---|
273 | 280 | if (ret < 0) |
---|
274 | 281 | goto out_free_nodes; |
---|
275 | 282 | } |
---|
276 | | - perf_mmap__read_done(md); |
---|
| 283 | + perf_mmap__read_done(&md->core); |
---|
277 | 284 | } |
---|
278 | 285 | |
---|
279 | 286 | events_array = calloc(cnt, sizeof(struct event_node)); |
---|
.. | .. |
---|
310 | 317 | * |
---|
311 | 318 | * This function implements a test that checks that sched_switch events and |
---|
312 | 319 | * tracking events can be recorded for a workload (current process) using the |
---|
313 | | - * evsel->system_wide and evsel->tracking flags (respectively) with other events |
---|
| 320 | + * evsel->core.system_wide and evsel->tracking flags (respectively) with other events |
---|
314 | 321 | * sometimes enabled or disabled. |
---|
315 | 322 | */ |
---|
316 | 323 | int test__switch_tracking(struct test *test __maybe_unused, int subtest __maybe_unused) |
---|
.. | .. |
---|
326 | 333 | .uses_mmap = true, |
---|
327 | 334 | }, |
---|
328 | 335 | }; |
---|
329 | | - struct thread_map *threads = NULL; |
---|
330 | | - struct cpu_map *cpus = NULL; |
---|
331 | | - struct perf_evlist *evlist = NULL; |
---|
332 | | - struct perf_evsel *evsel, *cpu_clocks_evsel, *cycles_evsel; |
---|
333 | | - struct perf_evsel *switch_evsel, *tracking_evsel; |
---|
| 336 | + struct perf_thread_map *threads = NULL; |
---|
| 337 | + struct perf_cpu_map *cpus = NULL; |
---|
| 338 | + struct evlist *evlist = NULL; |
---|
| 339 | + struct evsel *evsel, *cpu_clocks_evsel, *cycles_evsel; |
---|
| 340 | + struct evsel *switch_evsel, *tracking_evsel; |
---|
334 | 341 | const char *comm; |
---|
335 | 342 | int err = -1; |
---|
336 | 343 | |
---|
.. | .. |
---|
340 | 347 | goto out_err; |
---|
341 | 348 | } |
---|
342 | 349 | |
---|
343 | | - cpus = cpu_map__new(NULL); |
---|
| 350 | + cpus = perf_cpu_map__new(NULL); |
---|
344 | 351 | if (!cpus) { |
---|
345 | | - pr_debug("cpu_map__new failed!\n"); |
---|
| 352 | + pr_debug("perf_cpu_map__new failed!\n"); |
---|
346 | 353 | goto out_err; |
---|
347 | 354 | } |
---|
348 | 355 | |
---|
349 | | - evlist = perf_evlist__new(); |
---|
| 356 | + evlist = evlist__new(); |
---|
350 | 357 | if (!evlist) { |
---|
351 | | - pr_debug("perf_evlist__new failed!\n"); |
---|
| 358 | + pr_debug("evlist__new failed!\n"); |
---|
352 | 359 | goto out_err; |
---|
353 | 360 | } |
---|
354 | 361 | |
---|
355 | | - perf_evlist__set_maps(evlist, cpus, threads); |
---|
| 362 | + perf_evlist__set_maps(&evlist->core, cpus, threads); |
---|
356 | 363 | |
---|
357 | 364 | /* First event */ |
---|
358 | 365 | err = parse_events(evlist, "cpu-clock:u", NULL); |
---|
.. | .. |
---|
361 | 368 | goto out_err; |
---|
362 | 369 | } |
---|
363 | 370 | |
---|
364 | | - cpu_clocks_evsel = perf_evlist__last(evlist); |
---|
| 371 | + cpu_clocks_evsel = evlist__last(evlist); |
---|
365 | 372 | |
---|
366 | 373 | /* Second event */ |
---|
367 | 374 | err = parse_events(evlist, "cycles:u", NULL); |
---|
.. | .. |
---|
370 | 377 | goto out_err; |
---|
371 | 378 | } |
---|
372 | 379 | |
---|
373 | | - cycles_evsel = perf_evlist__last(evlist); |
---|
| 380 | + cycles_evsel = evlist__last(evlist); |
---|
374 | 381 | |
---|
375 | 382 | /* Third event */ |
---|
376 | 383 | if (!perf_evlist__can_select_event(evlist, sched_switch)) { |
---|
.. | .. |
---|
385 | 392 | goto out_err; |
---|
386 | 393 | } |
---|
387 | 394 | |
---|
388 | | - switch_evsel = perf_evlist__last(evlist); |
---|
| 395 | + switch_evsel = evlist__last(evlist); |
---|
389 | 396 | |
---|
390 | | - perf_evsel__set_sample_bit(switch_evsel, CPU); |
---|
391 | | - perf_evsel__set_sample_bit(switch_evsel, TIME); |
---|
| 397 | + evsel__set_sample_bit(switch_evsel, CPU); |
---|
| 398 | + evsel__set_sample_bit(switch_evsel, TIME); |
---|
392 | 399 | |
---|
393 | | - switch_evsel->system_wide = true; |
---|
| 400 | + switch_evsel->core.system_wide = true; |
---|
394 | 401 | switch_evsel->no_aux_samples = true; |
---|
395 | 402 | switch_evsel->immediate = true; |
---|
396 | 403 | |
---|
397 | 404 | /* Test moving an event to the front */ |
---|
398 | | - if (cycles_evsel == perf_evlist__first(evlist)) { |
---|
| 405 | + if (cycles_evsel == evlist__first(evlist)) { |
---|
399 | 406 | pr_debug("cycles event already at front"); |
---|
400 | 407 | goto out_err; |
---|
401 | 408 | } |
---|
402 | 409 | perf_evlist__to_front(evlist, cycles_evsel); |
---|
403 | | - if (cycles_evsel != perf_evlist__first(evlist)) { |
---|
| 410 | + if (cycles_evsel != evlist__first(evlist)) { |
---|
404 | 411 | pr_debug("Failed to move cycles event to front"); |
---|
405 | 412 | goto out_err; |
---|
406 | 413 | } |
---|
407 | 414 | |
---|
408 | | - perf_evsel__set_sample_bit(cycles_evsel, CPU); |
---|
409 | | - perf_evsel__set_sample_bit(cycles_evsel, TIME); |
---|
| 415 | + evsel__set_sample_bit(cycles_evsel, CPU); |
---|
| 416 | + evsel__set_sample_bit(cycles_evsel, TIME); |
---|
410 | 417 | |
---|
411 | 418 | /* Fourth event */ |
---|
412 | 419 | err = parse_events(evlist, "dummy:u", NULL); |
---|
.. | .. |
---|
415 | 422 | goto out_err; |
---|
416 | 423 | } |
---|
417 | 424 | |
---|
418 | | - tracking_evsel = perf_evlist__last(evlist); |
---|
| 425 | + tracking_evsel = evlist__last(evlist); |
---|
419 | 426 | |
---|
420 | 427 | perf_evlist__set_tracking_event(evlist, tracking_evsel); |
---|
421 | 428 | |
---|
422 | | - tracking_evsel->attr.freq = 0; |
---|
423 | | - tracking_evsel->attr.sample_period = 1; |
---|
| 429 | + tracking_evsel->core.attr.freq = 0; |
---|
| 430 | + tracking_evsel->core.attr.sample_period = 1; |
---|
424 | 431 | |
---|
425 | | - perf_evsel__set_sample_bit(tracking_evsel, TIME); |
---|
| 432 | + evsel__set_sample_bit(tracking_evsel, TIME); |
---|
426 | 433 | |
---|
427 | 434 | /* Config events */ |
---|
428 | 435 | perf_evlist__config(evlist, &opts, NULL); |
---|
429 | 436 | |
---|
430 | 437 | /* Check moved event is still at the front */ |
---|
431 | | - if (cycles_evsel != perf_evlist__first(evlist)) { |
---|
| 438 | + if (cycles_evsel != evlist__first(evlist)) { |
---|
432 | 439 | pr_debug("Front event no longer at front"); |
---|
433 | 440 | goto out_err; |
---|
434 | 441 | } |
---|
435 | 442 | |
---|
436 | 443 | /* Check tracking event is tracking */ |
---|
437 | | - if (!tracking_evsel->attr.mmap || !tracking_evsel->attr.comm) { |
---|
| 444 | + if (!tracking_evsel->core.attr.mmap || !tracking_evsel->core.attr.comm) { |
---|
438 | 445 | pr_debug("Tracking event not tracking\n"); |
---|
439 | 446 | goto out_err; |
---|
440 | 447 | } |
---|
.. | .. |
---|
442 | 449 | /* Check non-tracking events are not tracking */ |
---|
443 | 450 | evlist__for_each_entry(evlist, evsel) { |
---|
444 | 451 | if (evsel != tracking_evsel) { |
---|
445 | | - if (evsel->attr.mmap || evsel->attr.comm) { |
---|
| 452 | + if (evsel->core.attr.mmap || evsel->core.attr.comm) { |
---|
446 | 453 | pr_debug("Non-tracking event is tracking\n"); |
---|
447 | 454 | goto out_err; |
---|
448 | 455 | } |
---|
449 | 456 | } |
---|
450 | 457 | } |
---|
451 | 458 | |
---|
452 | | - if (perf_evlist__open(evlist) < 0) { |
---|
| 459 | + if (evlist__open(evlist) < 0) { |
---|
453 | 460 | pr_debug("Not supported\n"); |
---|
454 | 461 | err = 0; |
---|
455 | 462 | goto out; |
---|
456 | 463 | } |
---|
457 | 464 | |
---|
458 | | - err = perf_evlist__mmap(evlist, UINT_MAX); |
---|
| 465 | + err = evlist__mmap(evlist, UINT_MAX); |
---|
459 | 466 | if (err) { |
---|
460 | | - pr_debug("perf_evlist__mmap failed!\n"); |
---|
| 467 | + pr_debug("evlist__mmap failed!\n"); |
---|
461 | 468 | goto out_err; |
---|
462 | 469 | } |
---|
463 | 470 | |
---|
464 | | - perf_evlist__enable(evlist); |
---|
| 471 | + evlist__enable(evlist); |
---|
465 | 472 | |
---|
466 | | - err = perf_evsel__disable(cpu_clocks_evsel); |
---|
| 473 | + err = evsel__disable(cpu_clocks_evsel); |
---|
467 | 474 | if (err) { |
---|
468 | 475 | pr_debug("perf_evlist__disable_event failed!\n"); |
---|
469 | 476 | goto out_err; |
---|
.. | .. |
---|
482 | 489 | goto out_err; |
---|
483 | 490 | } |
---|
484 | 491 | |
---|
485 | | - err = perf_evsel__disable(cycles_evsel); |
---|
| 492 | + err = evsel__disable(cycles_evsel); |
---|
486 | 493 | if (err) { |
---|
487 | 494 | pr_debug("perf_evlist__disable_event failed!\n"); |
---|
488 | 495 | goto out_err; |
---|
.. | .. |
---|
508 | 515 | goto out_err; |
---|
509 | 516 | } |
---|
510 | 517 | |
---|
511 | | - err = perf_evsel__enable(cycles_evsel); |
---|
| 518 | + err = evsel__enable(cycles_evsel); |
---|
512 | 519 | if (err) { |
---|
513 | 520 | pr_debug("perf_evlist__disable_event failed!\n"); |
---|
514 | 521 | goto out_err; |
---|
.. | .. |
---|
527 | 534 | goto out_err; |
---|
528 | 535 | } |
---|
529 | 536 | |
---|
530 | | - perf_evlist__disable(evlist); |
---|
| 537 | + evlist__disable(evlist); |
---|
531 | 538 | |
---|
532 | 539 | switch_tracking.switch_evsel = switch_evsel; |
---|
533 | 540 | switch_tracking.cycles_evsel = cycles_evsel; |
---|
.. | .. |
---|
565 | 572 | } |
---|
566 | 573 | out: |
---|
567 | 574 | if (evlist) { |
---|
568 | | - perf_evlist__disable(evlist); |
---|
569 | | - perf_evlist__delete(evlist); |
---|
| 575 | + evlist__disable(evlist); |
---|
| 576 | + evlist__delete(evlist); |
---|
570 | 577 | } else { |
---|
571 | | - cpu_map__put(cpus); |
---|
572 | | - thread_map__put(threads); |
---|
| 578 | + perf_cpu_map__put(cpus); |
---|
| 579 | + perf_thread_map__put(threads); |
---|
573 | 580 | } |
---|
574 | 581 | |
---|
575 | 582 | return err; |
---|