Skip to content

Commit

Permalink
perf tools: Group VDSO global variables into a structure
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Adrian Hunter authored and Arnaldo Carvalho de Melo committed Jul 23, 2014
1 parent d5652d8 commit 30f4f81
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions tools/perf/util/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,27 @@
#include "linux/string.h"
#include "debug.h"

static bool vdso_found;
static char vdso_file[] = "/tmp/perf-vdso.so-XXXXXX";
#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX"

struct vdso_file {
bool found;
bool error;
char temp_file_name[sizeof(VDSO__TEMP_FILE_NAME)];
const char *dso_name;
};

struct vdso_info {
struct vdso_file vdso;
};

static struct vdso_info vdso_info_ = {
.vdso = {
.temp_file_name = VDSO__TEMP_FILE_NAME,
.dso_name = VDSO__MAP_NAME,
},
};

static struct vdso_info *vdso_info = &vdso_info_;

static int find_vdso_map(void **start, void **end)
{
Expand Down Expand Up @@ -49,18 +68,18 @@ static int find_vdso_map(void **start, void **end)
return !found;
}

static char *get_file(void)
static char *get_file(struct vdso_file *vdso_file)
{
char *vdso = NULL;
char *buf = NULL;
void *start, *end;
size_t size;
int fd;

if (vdso_found)
return vdso_file;
if (vdso_file->found)
return vdso_file->temp_file_name;

if (find_vdso_map(&start, &end))
if (vdso_file->error || find_vdso_map(&start, &end))
return NULL;

size = end - start;
Expand All @@ -69,26 +88,27 @@ static char *get_file(void)
if (!buf)
return NULL;

fd = mkstemp(vdso_file);
fd = mkstemp(vdso_file->temp_file_name);
if (fd < 0)
goto out;

if (size == (size_t) write(fd, buf, size))
vdso = vdso_file;
vdso = vdso_file->temp_file_name;

close(fd);

out:
free(buf);

vdso_found = (vdso != NULL);
vdso_file->found = (vdso != NULL);
vdso_file->error = !vdso_file->found;
return vdso;
}

void vdso__exit(void)
{
if (vdso_found)
unlink(vdso_file);
if (vdso_info->vdso.found)
unlink(vdso_info->vdso.temp_file_name);
}

struct dso *vdso__dso_findnew(struct machine *machine)
Expand All @@ -98,7 +118,7 @@ struct dso *vdso__dso_findnew(struct machine *machine)
if (!dso) {
char *file;

file = get_file();
file = get_file(&vdso_info->vdso);
if (!file)
return NULL;

Expand Down

0 comments on commit 30f4f81

Please sign in to comment.