3 #include "thread_map.h"
7 int test__open_syscall_event_on_all_cpus(void)
11 struct perf_evsel
*evsel
;
12 unsigned int nr_open_calls
= 111, i
;
14 struct thread_map
*threads
= thread_map__new(-1, getpid(), UINT_MAX
);
16 if (threads
== NULL
) {
17 pr_debug("thread_map__new\n");
21 cpus
= cpu_map__new(NULL
);
23 pr_debug("cpu_map__new\n");
24 goto out_thread_map_delete
;
29 evsel
= perf_evsel__newtp("syscalls", "sys_enter_open", 0);
31 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
32 goto out_thread_map_delete
;
35 if (perf_evsel__open(evsel
, cpus
, threads
) < 0) {
36 pr_debug("failed to open counter: %s, "
37 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
39 goto out_evsel_delete
;
42 for (cpu
= 0; cpu
< cpus
->nr
; ++cpu
) {
43 unsigned int ncalls
= nr_open_calls
+ cpu
;
45 * XXX eventually lift this restriction in a way that
46 * keeps perf building on older glibc installations
47 * without CPU_ALLOC. 1024 cpus in 2010 still seems
48 * a reasonable upper limit tho :-)
50 if (cpus
->map
[cpu
] >= CPU_SETSIZE
) {
51 pr_debug("Ignoring CPU %d\n", cpus
->map
[cpu
]);
55 CPU_SET(cpus
->map
[cpu
], &cpu_set
);
56 if (sched_setaffinity(0, sizeof(cpu_set
), &cpu_set
) < 0) {
57 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
62 for (i
= 0; i
< ncalls
; ++i
) {
63 fd
= open("/etc/passwd", O_RDONLY
);
66 CPU_CLR(cpus
->map
[cpu
], &cpu_set
);
70 * Here we need to explicitely preallocate the counts, as if
71 * we use the auto allocation it will allocate just for 1 cpu,
72 * as we start by cpu 0.
74 if (perf_evsel__alloc_counts(evsel
, cpus
->nr
) < 0) {
75 pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus
->nr
);
81 for (cpu
= 0; cpu
< cpus
->nr
; ++cpu
) {
82 unsigned int expected
;
84 if (cpus
->map
[cpu
] >= CPU_SETSIZE
)
87 if (perf_evsel__read_on_cpu(evsel
, cpu
, 0) < 0) {
88 pr_debug("perf_evsel__read_on_cpu\n");
93 expected
= nr_open_calls
+ cpu
;
94 if (evsel
->counts
->cpu
[cpu
].val
!= expected
) {
95 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64
"\n",
96 expected
, cpus
->map
[cpu
], evsel
->counts
->cpu
[cpu
].val
);
101 perf_evsel__free_counts(evsel
);
103 perf_evsel__close_fd(evsel
, 1, threads
->nr
);
105 perf_evsel__delete(evsel
);
106 out_thread_map_delete
:
107 thread_map__delete(threads
);