3 #include "thread_map.h"
7 int test__open_syscall_event_on_all_cpus(void)
10 struct thread_map *threads;
12 struct perf_evsel *evsel;
13 struct perf_event_attr attr;
14 unsigned int nr_open_calls = 111, i;
16 int id = trace_event__id("sys_enter_open");
19 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
23 threads = thread_map__new(-1, getpid(), UINT_MAX);
24 if (threads == NULL) {
25 pr_debug("thread_map__new\n");
29 cpus = cpu_map__new(NULL);
31 pr_debug("cpu_map__new\n");
32 goto out_thread_map_delete;
38 memset(&attr, 0, sizeof(attr));
39 attr.type = PERF_TYPE_TRACEPOINT;
41 evsel = perf_evsel__new(&attr, 0);
43 pr_debug("perf_evsel__new\n");
44 goto out_thread_map_delete;
47 if (perf_evsel__open(evsel, cpus, threads) < 0) {
48 pr_debug("failed to open counter: %s, "
49 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
51 goto out_evsel_delete;
54 for (cpu = 0; cpu < cpus->nr; ++cpu) {
55 unsigned int ncalls = nr_open_calls + cpu;
57 * XXX eventually lift this restriction in a way that
58 * keeps perf building on older glibc installations
59 * without CPU_ALLOC. 1024 cpus in 2010 still seems
60 * a reasonable upper limit tho :-)
62 if (cpus->map[cpu] >= CPU_SETSIZE) {
63 pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
67 CPU_SET(cpus->map[cpu], &cpu_set);
68 if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
69 pr_debug("sched_setaffinity() failed on CPU %d: %s ",
74 for (i = 0; i < ncalls; ++i) {
75 fd = open("/etc/passwd", O_RDONLY);
78 CPU_CLR(cpus->map[cpu], &cpu_set);
82 * Here we need to explicitely preallocate the counts, as if
83 * we use the auto allocation it will allocate just for 1 cpu,
84 * as we start by cpu 0.
86 if (perf_evsel__alloc_counts(evsel, cpus->nr) < 0) {
87 pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus->nr);
93 for (cpu = 0; cpu < cpus->nr; ++cpu) {
94 unsigned int expected;
96 if (cpus->map[cpu] >= CPU_SETSIZE)
99 if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) {
100 pr_debug("perf_evsel__read_on_cpu\n");
105 expected = nr_open_calls + cpu;
106 if (evsel->counts->cpu[cpu].val != expected) {
107 pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
108 expected, cpus->map[cpu], evsel->counts->cpu[cpu].val);
114 perf_evsel__close_fd(evsel, 1, threads->nr);
116 perf_evsel__delete(evsel);
117 out_thread_map_delete:
118 thread_map__delete(threads);