aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-07-22 09:17:54 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-07-23 16:11:26 -0400
commit30f4f815a45d0b148d17afb0d5a5575ae2ba4309 (patch)
treef0ce54ad9070b2bedfb26db41a64cea1f41c1234 /tools
parentd5652d865ea734a13a16cf563937291a84d4364d (diff)
perf tools: Group VDSO global variables into a structure
This is preparation for removing the global variables used in vdso.c and thereby fixing the lifetime of the VDSO temporary file. Also allowance is made for the later addition of support for compat VDSOs. Reviewed-by: Jiri Olsa <jolsa@redhat.com> 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/1406035081-14301-46-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/vdso.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c
index da5ba4da2bd2..75245f081b60 100644
--- a/tools/perf/util/vdso.c
+++ b/tools/perf/util/vdso.c
@@ -15,8 +15,27 @@
15#include "linux/string.h" 15#include "linux/string.h"
16#include "debug.h" 16#include "debug.h"
17 17
18static bool vdso_found; 18#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX"
19static char vdso_file[] = "/tmp/perf-vdso.so-XXXXXX"; 19
20struct vdso_file {
21 bool found;
22 bool error;
23 char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)];
24 const char *dso_name;
25};
26
27struct vdso_info {
28 struct vdso_file vdso;
29};
30
31static struct vdso_info vdso_info_ = {
32 .vdso = {
33 .temp_file_name = VDSO__TEMP_FILE_NAME,
34 .dso_name = VDSO__MAP_NAME,
35 },
36};
37
38static struct vdso_info *vdso_info = &vdso_info_;
20 39
21static int find_vdso_map(void **start, void **end) 40static int find_vdso_map(void **start, void **end)
22{ 41{
@@ -49,7 +68,7 @@ static int find_vdso_map(void **start, void **end)
49 return !found; 68 return !found;
50} 69}
51 70
52static char *get_file(void) 71static char *get_file(struct vdso_file *vdso_file)
53{ 72{
54 char *vdso = NULL; 73 char *vdso = NULL;
55 char *buf = NULL; 74 char *buf = NULL;
@@ -57,10 +76,10 @@ static char *get_file(void)
57 size_t size; 76 size_t size;
58 int fd; 77 int fd;
59 78
60 if (vdso_found) 79 if (vdso_file->found)
61 return vdso_file; 80 return vdso_file->temp_file_name;
62 81
63 if (find_vdso_map(&start, &end)) 82 if (vdso_file->error || find_vdso_map(&start, &end))
64 return NULL; 83 return NULL;
65 84
66 size = end - start; 85 size = end - start;
@@ -69,26 +88,27 @@ static char *get_file(void)
69 if (!buf) 88 if (!buf)
70 return NULL; 89 return NULL;
71 90
72 fd = mkstemp(vdso_file); 91 fd = mkstemp(vdso_file->temp_file_name);
73 if (fd < 0) 92 if (fd < 0)
74 goto out; 93 goto out;
75 94
76 if (size == (size_t) write(fd, buf, size)) 95 if (size == (size_t) write(fd, buf, size))
77 vdso = vdso_file; 96 vdso = vdso_file->temp_file_name;
78 97
79 close(fd); 98 close(fd);
80 99
81 out: 100 out:
82 free(buf); 101 free(buf);
83 102
84 vdso_found = (vdso != NULL); 103 vdso_file->found = (vdso != NULL);
104 vdso_file->error = !vdso_file->found;
85 return vdso; 105 return vdso;
86} 106}
87 107
88void vdso__exit(void) 108void vdso__exit(void)
89{ 109{
90 if (vdso_found) 110 if (vdso_info->vdso.found)
91 unlink(vdso_file); 111 unlink(vdso_info->vdso.temp_file_name);
92} 112}
93 113
94struct dso *vdso__dso_findnew(struct machine *machine) 114struct dso *vdso__dso_findnew(struct machine *machine)
@@ -98,7 +118,7 @@ struct dso *vdso__dso_findnew(struct machine *machine)
98 if (!dso) { 118 if (!dso) {
99 char *file; 119 char *file;
100 120
101 file = get_file(); 121 file = get_file(&vdso_info->vdso);
102 if (!file) 122 if (!file)
103 return NULL; 123 return NULL;
104 124