diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2014-10-23 06:45:23 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-10-29 08:32:48 -0400 |
commit | f6832e1720f5cc283703cfe9ccbfb46a3fb6f548 (patch) | |
tree | 16f0d4b4efc87d30035dd4a5340d5536d9452fa2 | |
parent | e477f3f01a89a8fd44031e7f2ba6ffcab037336c (diff) |
perf tools: Add support for 32-bit compatibility VDSOs
'perf record' post-processes the event stream to create a list of
build-ids for object files for which sample events have been recorded.
That results in those object files being recorded in the build-id cache.
In the case of VDSO, perf tools reads it from memory and copies it into
a temporary file, which as decribed above, gets added to the build-id
cache.
Then when the perf.data file is processed by other tools, the build-id
of VDSO is listed in the perf.data file and the VDSO can be read from
the build-id cache. In that case the name of the map, the short name of
the DSO, and the entry in the build-id cache are all "[vdso]".
However, in the 64-bit case, there also can be 32-bit compatibility
VDSOs.
A previous patch added programs "perf-read-vdso32" and "perf
read-vdsox32".
This patch uses those programs to read the correct VDSO for a thread and
create a temporary file just as for the 64-bit VDSO.
The map name and the entry in the build-id cache are still "[vdso]" but
the DSO short name becomes "[vdso32]" and "[vdsox32]" respectively.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1414061124-26830-16-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/vdso.c | 170 | ||||
-rw-r--r-- | tools/perf/util/vdso.h | 4 |
2 files changed, 172 insertions, 2 deletions
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index f51390a1ed51..69daef6a17d5 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "util.h" | 12 | #include "util.h" |
13 | #include "symbol.h" | 13 | #include "symbol.h" |
14 | #include "machine.h" | 14 | #include "machine.h" |
15 | #include "thread.h" | ||
15 | #include "linux/string.h" | 16 | #include "linux/string.h" |
16 | #include "debug.h" | 17 | #include "debug.h" |
17 | 18 | ||
@@ -28,10 +29,15 @@ struct vdso_file { | |||
28 | bool error; | 29 | bool error; |
29 | char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)]; | 30 | char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)]; |
30 | const char *dso_name; | 31 | const char *dso_name; |
32 | const char *read_prog; | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | struct vdso_info { | 35 | struct vdso_info { |
34 | struct vdso_file vdso; | 36 | struct vdso_file vdso; |
37 | #if BITS_PER_LONG == 64 | ||
38 | struct vdso_file vdso32; | ||
39 | struct vdso_file vdsox32; | ||
40 | #endif | ||
35 | }; | 41 | }; |
36 | 42 | ||
37 | static struct vdso_info *vdso_info__new(void) | 43 | static struct vdso_info *vdso_info__new(void) |
@@ -41,6 +47,18 @@ static struct vdso_info *vdso_info__new(void) | |||
41 | .temp_file_name = VDSO__TEMP_FILE_NAME, | 47 | .temp_file_name = VDSO__TEMP_FILE_NAME, |
42 | .dso_name = DSO__NAME_VDSO, | 48 | .dso_name = DSO__NAME_VDSO, |
43 | }, | 49 | }, |
50 | #if BITS_PER_LONG == 64 | ||
51 | .vdso32 = { | ||
52 | .temp_file_name = VDSO__TEMP_FILE_NAME, | ||
53 | .dso_name = DSO__NAME_VDSO32, | ||
54 | .read_prog = "perf-read-vdso32", | ||
55 | }, | ||
56 | .vdsox32 = { | ||
57 | .temp_file_name = VDSO__TEMP_FILE_NAME, | ||
58 | .dso_name = DSO__NAME_VDSOX32, | ||
59 | .read_prog = "perf-read-vdsox32", | ||
60 | }, | ||
61 | #endif | ||
44 | }; | 62 | }; |
45 | 63 | ||
46 | return memdup(&vdso_info_init, sizeof(vdso_info_init)); | 64 | return memdup(&vdso_info_init, sizeof(vdso_info_init)); |
@@ -92,6 +110,12 @@ void vdso__exit(struct machine *machine) | |||
92 | 110 | ||
93 | if (vdso_info->vdso.found) | 111 | if (vdso_info->vdso.found) |
94 | unlink(vdso_info->vdso.temp_file_name); | 112 | unlink(vdso_info->vdso.temp_file_name); |
113 | #if BITS_PER_LONG == 64 | ||
114 | if (vdso_info->vdso32.found) | ||
115 | unlink(vdso_info->vdso32.temp_file_name); | ||
116 | if (vdso_info->vdsox32.found) | ||
117 | unlink(vdso_info->vdsox32.temp_file_name); | ||
118 | #endif | ||
95 | 119 | ||
96 | zfree(&machine->vdso_info); | 120 | zfree(&machine->vdso_info); |
97 | } | 121 | } |
@@ -110,6 +134,143 @@ static struct dso *vdso__new(struct machine *machine, const char *short_name, | |||
110 | return dso; | 134 | return dso; |
111 | } | 135 | } |
112 | 136 | ||
137 | #if BITS_PER_LONG == 64 | ||
138 | |||
139 | static enum dso_type machine__thread_dso_type(struct machine *machine, | ||
140 | struct thread *thread) | ||
141 | { | ||
142 | enum dso_type dso_type = DSO__TYPE_UNKNOWN; | ||
143 | struct map *map; | ||
144 | struct dso *dso; | ||
145 | |||
146 | map = map_groups__first(thread->mg, MAP__FUNCTION); | ||
147 | for (; map ; map = map_groups__next(map)) { | ||
148 | dso = map->dso; | ||
149 | if (!dso || dso->long_name[0] != '/') | ||
150 | continue; | ||
151 | dso_type = dso__type(dso, machine); | ||
152 | if (dso_type != DSO__TYPE_UNKNOWN) | ||
153 | break; | ||
154 | } | ||
155 | |||
156 | return dso_type; | ||
157 | } | ||
158 | |||
159 | static int vdso__do_copy_compat(FILE *f, int fd) | ||
160 | { | ||
161 | char buf[4096]; | ||
162 | size_t count; | ||
163 | |||
164 | while (1) { | ||
165 | count = fread(buf, 1, sizeof(buf), f); | ||
166 | if (ferror(f)) | ||
167 | return -errno; | ||
168 | if (feof(f)) | ||
169 | break; | ||
170 | if (count && writen(fd, buf, count) != (ssize_t)count) | ||
171 | return -errno; | ||
172 | } | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | static int vdso__copy_compat(const char *prog, int fd) | ||
178 | { | ||
179 | FILE *f; | ||
180 | int err; | ||
181 | |||
182 | f = popen(prog, "r"); | ||
183 | if (!f) | ||
184 | return -errno; | ||
185 | |||
186 | err = vdso__do_copy_compat(f, fd); | ||
187 | |||
188 | if (pclose(f) == -1) | ||
189 | return -errno; | ||
190 | |||
191 | return err; | ||
192 | } | ||
193 | |||
194 | static int vdso__create_compat_file(const char *prog, char *temp_name) | ||
195 | { | ||
196 | int fd, err; | ||
197 | |||
198 | fd = mkstemp(temp_name); | ||
199 | if (fd < 0) | ||
200 | return -errno; | ||
201 | |||
202 | err = vdso__copy_compat(prog, fd); | ||
203 | |||
204 | if (close(fd) == -1) | ||
205 | return -errno; | ||
206 | |||
207 | return err; | ||
208 | } | ||
209 | |||
210 | static const char *vdso__get_compat_file(struct vdso_file *vdso_file) | ||
211 | { | ||
212 | int err; | ||
213 | |||
214 | if (vdso_file->found) | ||
215 | return vdso_file->temp_file_name; | ||
216 | |||
217 | if (vdso_file->error) | ||
218 | return NULL; | ||
219 | |||
220 | err = vdso__create_compat_file(vdso_file->read_prog, | ||
221 | vdso_file->temp_file_name); | ||
222 | if (err) { | ||
223 | pr_err("%s failed, error %d\n", vdso_file->read_prog, err); | ||
224 | vdso_file->error = true; | ||
225 | return NULL; | ||
226 | } | ||
227 | |||
228 | vdso_file->found = true; | ||
229 | |||
230 | return vdso_file->temp_file_name; | ||
231 | } | ||
232 | |||
233 | static struct dso *vdso__findnew_compat(struct machine *machine, | ||
234 | struct vdso_file *vdso_file) | ||
235 | { | ||
236 | const char *file_name; | ||
237 | struct dso *dso; | ||
238 | |||
239 | dso = dsos__find(&machine->user_dsos, vdso_file->dso_name, true); | ||
240 | if (dso) | ||
241 | return dso; | ||
242 | |||
243 | file_name = vdso__get_compat_file(vdso_file); | ||
244 | if (!file_name) | ||
245 | return NULL; | ||
246 | |||
247 | return vdso__new(machine, vdso_file->dso_name, file_name); | ||
248 | } | ||
249 | |||
250 | static int vdso__dso_findnew_compat(struct machine *machine, | ||
251 | struct thread *thread, | ||
252 | struct vdso_info *vdso_info, | ||
253 | struct dso **dso) | ||
254 | { | ||
255 | enum dso_type dso_type; | ||
256 | |||
257 | dso_type = machine__thread_dso_type(machine, thread); | ||
258 | switch (dso_type) { | ||
259 | case DSO__TYPE_32BIT: | ||
260 | *dso = vdso__findnew_compat(machine, &vdso_info->vdso32); | ||
261 | return 1; | ||
262 | case DSO__TYPE_X32BIT: | ||
263 | *dso = vdso__findnew_compat(machine, &vdso_info->vdsox32); | ||
264 | return 1; | ||
265 | case DSO__TYPE_UNKNOWN: | ||
266 | case DSO__TYPE_64BIT: | ||
267 | default: | ||
268 | return 0; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | #endif | ||
273 | |||
113 | struct dso *vdso__dso_findnew(struct machine *machine, | 274 | struct dso *vdso__dso_findnew(struct machine *machine, |
114 | struct thread *thread __maybe_unused) | 275 | struct thread *thread __maybe_unused) |
115 | { | 276 | { |
@@ -123,6 +284,11 @@ struct dso *vdso__dso_findnew(struct machine *machine, | |||
123 | if (!vdso_info) | 284 | if (!vdso_info) |
124 | return NULL; | 285 | return NULL; |
125 | 286 | ||
287 | #if BITS_PER_LONG == 64 | ||
288 | if (vdso__dso_findnew_compat(machine, thread, vdso_info, &dso)) | ||
289 | return dso; | ||
290 | #endif | ||
291 | |||
126 | dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true); | 292 | dso = dsos__find(&machine->user_dsos, DSO__NAME_VDSO, true); |
127 | if (!dso) { | 293 | if (!dso) { |
128 | char *file; | 294 | char *file; |
@@ -139,5 +305,7 @@ struct dso *vdso__dso_findnew(struct machine *machine, | |||
139 | 305 | ||
140 | bool dso__is_vdso(struct dso *dso) | 306 | bool dso__is_vdso(struct dso *dso) |
141 | { | 307 | { |
142 | return !strcmp(dso->short_name, DSO__NAME_VDSO); | 308 | return !strcmp(dso->short_name, DSO__NAME_VDSO) || |
309 | !strcmp(dso->short_name, DSO__NAME_VDSO32) || | ||
310 | !strcmp(dso->short_name, DSO__NAME_VDSOX32); | ||
143 | } | 311 | } |
diff --git a/tools/perf/util/vdso.h b/tools/perf/util/vdso.h index af9d6929a215..d97da1616f0c 100644 --- a/tools/perf/util/vdso.h +++ b/tools/perf/util/vdso.h | |||
@@ -7,7 +7,9 @@ | |||
7 | 7 | ||
8 | #define VDSO__MAP_NAME "[vdso]" | 8 | #define VDSO__MAP_NAME "[vdso]" |
9 | 9 | ||
10 | #define DSO__NAME_VDSO "[vdso]" | 10 | #define DSO__NAME_VDSO "[vdso]" |
11 | #define DSO__NAME_VDSO32 "[vdso32]" | ||
12 | #define DSO__NAME_VDSOX32 "[vdsox32]" | ||
11 | 13 | ||
12 | static inline bool is_vdso_map(const char *filename) | 14 | static inline bool is_vdso_map(const char *filename) |
13 | { | 15 | { |