.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
| 2 | +#include "debug.h" |
---|
2 | 3 | #include "evlist.h" |
---|
3 | 4 | #include "evsel.h" |
---|
| 5 | +#include "target.h" |
---|
4 | 6 | #include "thread_map.h" |
---|
5 | | -#include "cpumap.h" |
---|
6 | 7 | #include "tests.h" |
---|
| 8 | +#include "util/mmap.h" |
---|
7 | 9 | |
---|
8 | 10 | #include <errno.h> |
---|
9 | 11 | #include <signal.h> |
---|
| 12 | +#include <linux/string.h> |
---|
| 13 | +#include <perf/cpumap.h> |
---|
| 14 | +#include <perf/evlist.h> |
---|
| 15 | +#include <perf/mmap.h> |
---|
10 | 16 | |
---|
11 | 17 | static int exited; |
---|
12 | 18 | static int nr_exit; |
---|
.. | .. |
---|
37 | 43 | { |
---|
38 | 44 | int err = -1; |
---|
39 | 45 | union perf_event *event; |
---|
40 | | - struct perf_evsel *evsel; |
---|
41 | | - struct perf_evlist *evlist; |
---|
| 46 | + struct evsel *evsel; |
---|
| 47 | + struct evlist *evlist; |
---|
42 | 48 | struct target target = { |
---|
43 | 49 | .uid = UINT_MAX, |
---|
44 | 50 | .uses_mmap = true, |
---|
45 | 51 | }; |
---|
46 | 52 | const char *argv[] = { "true", NULL }; |
---|
47 | 53 | char sbuf[STRERR_BUFSIZE]; |
---|
48 | | - struct cpu_map *cpus; |
---|
49 | | - struct thread_map *threads; |
---|
50 | | - struct perf_mmap *md; |
---|
| 54 | + struct perf_cpu_map *cpus; |
---|
| 55 | + struct perf_thread_map *threads; |
---|
| 56 | + struct mmap *md; |
---|
| 57 | + int retry_count = 0; |
---|
51 | 58 | |
---|
52 | 59 | signal(SIGCHLD, sig_handler); |
---|
53 | 60 | |
---|
.. | .. |
---|
63 | 70 | * perf_evlist__prepare_workload we'll fill in the only thread |
---|
64 | 71 | * we're monitoring, the one forked there. |
---|
65 | 72 | */ |
---|
66 | | - cpus = cpu_map__dummy_new(); |
---|
| 73 | + cpus = perf_cpu_map__dummy_new(); |
---|
67 | 74 | threads = thread_map__new_by_tid(-1); |
---|
68 | 75 | if (!cpus || !threads) { |
---|
69 | 76 | err = -ENOMEM; |
---|
.. | .. |
---|
71 | 78 | goto out_free_maps; |
---|
72 | 79 | } |
---|
73 | 80 | |
---|
74 | | - perf_evlist__set_maps(evlist, cpus, threads); |
---|
| 81 | + perf_evlist__set_maps(&evlist->core, cpus, threads); |
---|
75 | 82 | |
---|
76 | 83 | cpus = NULL; |
---|
77 | 84 | threads = NULL; |
---|
.. | .. |
---|
83 | 90 | goto out_delete_evlist; |
---|
84 | 91 | } |
---|
85 | 92 | |
---|
86 | | - evsel = perf_evlist__first(evlist); |
---|
87 | | - evsel->attr.task = 1; |
---|
| 93 | + evsel = evlist__first(evlist); |
---|
| 94 | + evsel->core.attr.task = 1; |
---|
88 | 95 | #ifdef __s390x__ |
---|
89 | | - evsel->attr.sample_freq = 1000000; |
---|
| 96 | + evsel->core.attr.sample_freq = 1000000; |
---|
90 | 97 | #else |
---|
91 | | - evsel->attr.sample_freq = 1; |
---|
| 98 | + evsel->core.attr.sample_freq = 1; |
---|
92 | 99 | #endif |
---|
93 | | - evsel->attr.inherit = 0; |
---|
94 | | - evsel->attr.watermark = 0; |
---|
95 | | - evsel->attr.wakeup_events = 1; |
---|
96 | | - evsel->attr.exclude_kernel = 1; |
---|
| 100 | + evsel->core.attr.inherit = 0; |
---|
| 101 | + evsel->core.attr.watermark = 0; |
---|
| 102 | + evsel->core.attr.wakeup_events = 1; |
---|
| 103 | + evsel->core.attr.exclude_kernel = 1; |
---|
97 | 104 | |
---|
98 | | - err = perf_evlist__open(evlist); |
---|
| 105 | + err = evlist__open(evlist); |
---|
99 | 106 | if (err < 0) { |
---|
100 | 107 | pr_debug("Couldn't open the evlist: %s\n", |
---|
101 | 108 | str_error_r(-err, sbuf, sizeof(sbuf))); |
---|
102 | 109 | goto out_delete_evlist; |
---|
103 | 110 | } |
---|
104 | 111 | |
---|
105 | | - if (perf_evlist__mmap(evlist, 128) < 0) { |
---|
| 112 | + if (evlist__mmap(evlist, 128) < 0) { |
---|
106 | 113 | pr_debug("failed to mmap events: %d (%s)\n", errno, |
---|
107 | 114 | str_error_r(errno, sbuf, sizeof(sbuf))); |
---|
108 | 115 | err = -1; |
---|
.. | .. |
---|
113 | 120 | |
---|
114 | 121 | retry: |
---|
115 | 122 | md = &evlist->mmap[0]; |
---|
116 | | - if (perf_mmap__read_init(md) < 0) |
---|
| 123 | + if (perf_mmap__read_init(&md->core) < 0) |
---|
117 | 124 | goto out_init; |
---|
118 | 125 | |
---|
119 | | - while ((event = perf_mmap__read_event(md)) != NULL) { |
---|
| 126 | + while ((event = perf_mmap__read_event(&md->core)) != NULL) { |
---|
120 | 127 | if (event->header.type == PERF_RECORD_EXIT) |
---|
121 | 128 | nr_exit++; |
---|
122 | 129 | |
---|
123 | | - perf_mmap__consume(md); |
---|
| 130 | + perf_mmap__consume(&md->core); |
---|
124 | 131 | } |
---|
125 | | - perf_mmap__read_done(md); |
---|
| 132 | + perf_mmap__read_done(&md->core); |
---|
126 | 133 | |
---|
127 | 134 | out_init: |
---|
128 | 135 | if (!exited || !nr_exit) { |
---|
129 | | - perf_evlist__poll(evlist, -1); |
---|
| 136 | + evlist__poll(evlist, -1); |
---|
| 137 | + |
---|
| 138 | + if (retry_count++ > 1000) { |
---|
| 139 | + pr_debug("Failed after retrying 1000 times\n"); |
---|
| 140 | + err = -1; |
---|
| 141 | + goto out_free_maps; |
---|
| 142 | + } |
---|
| 143 | + |
---|
130 | 144 | goto retry; |
---|
131 | 145 | } |
---|
132 | 146 | |
---|
.. | .. |
---|
136 | 150 | } |
---|
137 | 151 | |
---|
138 | 152 | out_free_maps: |
---|
139 | | - cpu_map__put(cpus); |
---|
140 | | - thread_map__put(threads); |
---|
| 153 | + perf_cpu_map__put(cpus); |
---|
| 154 | + perf_thread_map__put(threads); |
---|
141 | 155 | out_delete_evlist: |
---|
142 | | - perf_evlist__delete(evlist); |
---|
| 156 | + evlist__delete(evlist); |
---|
143 | 157 | return err; |
---|
144 | 158 | } |
---|