1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Facebook
6 #include <test_progs.h>
7 #include "perf_event_stackmap.skel.h"
10 #define noinline __attribute__((noinline))
13 noinline
int func_1(void)
23 noinline
int func_2(void)
28 noinline
int func_3(void)
33 noinline
int func_4(void)
38 noinline
int func_5(void)
43 noinline
int func_6(void)
47 for (i
= 0; i
< 100; i
++)
53 void test_perf_event_stackmap(void)
55 struct perf_event_attr attr
= {
56 /* .type = PERF_TYPE_SOFTWARE, */
57 .type
= PERF_TYPE_HARDWARE
,
58 .config
= PERF_COUNT_HW_CPU_CYCLES
,
60 .sample_type
= PERF_SAMPLE_IP
| PERF_SAMPLE_BRANCH_STACK
|
61 PERF_SAMPLE_CALLCHAIN
,
62 .branch_sample_type
= PERF_SAMPLE_BRANCH_USER
|
63 PERF_SAMPLE_BRANCH_NO_FLAGS
|
64 PERF_SAMPLE_BRANCH_NO_CYCLES
|
65 PERF_SAMPLE_BRANCH_CALL_STACK
,
66 .sample_period
= 5000,
67 .size
= sizeof(struct perf_event_attr
),
69 struct perf_event_stackmap
*skel
;
74 skel
= perf_event_stackmap__open();
76 if (CHECK(!skel
, "skel_open", "skeleton open failed\n"))
79 err
= perf_event_stackmap__load(skel
);
80 if (CHECK(err
, "skel_load", "skeleton load failed: %d\n", err
))
85 err
= pthread_setaffinity_np(pthread_self(), sizeof(cpu_set
), &cpu_set
);
86 if (CHECK(err
, "set_affinity", "err %d, errno %d\n", err
, errno
))
89 pmu_fd
= syscall(__NR_perf_event_open
, &attr
, -1 /* pid */,
90 0 /* cpu 0 */, -1 /* group id */,
93 printf("%s:SKIP:cpu doesn't support the event\n", __func__
);
98 skel
->links
.oncpu
= bpf_program__attach_perf_event(skel
->progs
.oncpu
,
100 if (CHECK(IS_ERR(skel
->links
.oncpu
), "attach_perf_event",
101 "err %ld\n", PTR_ERR(skel
->links
.oncpu
))) {
106 /* create kernel and user stack traces for testing */
109 CHECK(skel
->data
->stackid_kernel
!= 2, "get_stackid_kernel", "failed\n");
110 CHECK(skel
->data
->stackid_user
!= 2, "get_stackid_user", "failed\n");
111 CHECK(skel
->data
->stack_kernel
!= 2, "get_stack_kernel", "failed\n");
112 CHECK(skel
->data
->stack_user
!= 2, "get_stack_user", "failed\n");
115 perf_event_stackmap__destroy(skel
);