5 #include "thread_map.h"
10 int test__openat_syscall_event_on_all_cpus(int subtest __maybe_unused
)
12 int err
= -1, fd
, cpu
;
14 struct perf_evsel
*evsel
;
15 unsigned int nr_openat_calls
= 111, i
;
17 struct thread_map
*threads
= thread_map__new(-1, getpid(), UINT_MAX
);
18 char sbuf
[STRERR_BUFSIZE
];
21 if (threads
== NULL
) {
22 pr_debug("thread_map__new\n");
26 cpus
= cpu_map__new(NULL
);
28 pr_debug("cpu_map__new\n");
29 goto out_thread_map_delete
;
34 evsel
= perf_evsel__newtp("syscalls", "sys_enter_openat");
36 tracing_path__strerror_open_tp(errno
, errbuf
, sizeof(errbuf
), "syscalls", "sys_enter_openat");
37 pr_debug("%s\n", errbuf
);
38 goto out_thread_map_delete
;
41 if (perf_evsel__open(evsel
, cpus
, threads
) < 0) {
42 pr_debug("failed to open counter: %s, "
43 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
44 strerror_r(errno
, sbuf
, sizeof(sbuf
)));
45 goto out_evsel_delete
;
48 for (cpu
= 0; cpu
< cpus
->nr
; ++cpu
) {
49 unsigned int ncalls
= nr_openat_calls
+ cpu
;
51 * XXX eventually lift this restriction in a way that
52 * keeps perf building on older glibc installations
53 * without CPU_ALLOC. 1024 cpus in 2010 still seems
54 * a reasonable upper limit tho :-)
56 if (cpus
->map
[cpu
] >= CPU_SETSIZE
) {
57 pr_debug("Ignoring CPU %d\n", cpus
->map
[cpu
]);
61 CPU_SET(cpus
->map
[cpu
], &cpu_set
);
62 if (sched_setaffinity(0, sizeof(cpu_set
), &cpu_set
) < 0) {
63 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
65 strerror_r(errno
, sbuf
, sizeof(sbuf
)));
68 for (i
= 0; i
< ncalls
; ++i
) {
69 fd
= openat(0, "/etc/passwd", O_RDONLY
);
72 CPU_CLR(cpus
->map
[cpu
], &cpu_set
);
76 * Here we need to explicitely preallocate the counts, as if
77 * we use the auto allocation it will allocate just for 1 cpu,
78 * as we start by cpu 0.
80 if (perf_evsel__alloc_counts(evsel
, cpus
->nr
, 1) < 0) {
81 pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus
->nr
);
87 for (cpu
= 0; cpu
< cpus
->nr
; ++cpu
) {
88 unsigned int expected
;
90 if (cpus
->map
[cpu
] >= CPU_SETSIZE
)
93 if (perf_evsel__read_on_cpu(evsel
, cpu
, 0) < 0) {
94 pr_debug("perf_evsel__read_on_cpu\n");
99 expected
= nr_openat_calls
+ cpu
;
100 if (perf_counts(evsel
->counts
, cpu
, 0)->val
!= expected
) {
101 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64
"\n",
102 expected
, cpus
->map
[cpu
], perf_counts(evsel
->counts
, cpu
, 0)->val
);
107 perf_evsel__free_counts(evsel
);
109 perf_evsel__close_fd(evsel
, 1, threads
->nr
);
111 perf_evsel__delete(evsel
);
112 out_thread_map_delete
:
113 thread_map__put(threads
);