Skip to content

Commit

Permalink
perf tools: Make find_vdso_map() more modular
Browse files Browse the repository at this point in the history
In preparation for checking that the vectors page on the ARM
architecture, refactor the find_vdso_map() function to accept finding an
arbitrary string and create a dedicated helper function for that under
util/find-map.c and update the filename to find-map.c and all references
to it: perf-read-vdso.c and util/vdso.c.

Signed-off-by: Florian Fainelli <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Chris Healy <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Kim Phillips <[email protected]>
Cc: Lucas Stach <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Ravi Bangoria <[email protected]>
Cc: Russell King <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Thomas Richter <[email protected]>
Link: http:https://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ffainelli authored and acmel committed Jan 8, 2019
1 parent ac6e022 commit 0115323
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,12 @@ $(OUTPUT)perf-%: %.o $(PERFLIBS)
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)

ifndef NO_PERF_READ_VDSO32
$(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-vdso-map.c
$(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-map.c
$(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
endif

ifndef NO_PERF_READ_VDSOX32
$(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c
$(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c
$(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
endif

Expand Down
6 changes: 3 additions & 3 deletions tools/perf/perf-read-vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#define VDSO__MAP_NAME "[vdso]"

/*
* Include definition of find_vdso_map() also used in util/vdso.c for
* Include definition of find_map() also used in util/vdso.c for
* building perf.
*/
#include "util/find-vdso-map.c"
#include "util/find-map.c"

int main(void)
{
void *start, *end;
size_t size, written;

if (find_vdso_map(&start, &end))
if (find_map(&start, &end, VDSO__MAP_NAME))
return 1;

size = end - start;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: GPL-2.0
static int find_vdso_map(void **start, void **end)
static int find_map(void **start, void **end, const char *name)
{
FILE *maps;
char line[128];
int found = 0;

maps = fopen("/proc/self/maps", "r");
if (!maps) {
fprintf(stderr, "vdso: cannot open maps\n");
fprintf(stderr, "cannot open maps\n");
return -1;
}

Expand All @@ -21,8 +21,7 @@ static int find_vdso_map(void **start, void **end)
if (m < 0)
continue;

if (!strncmp(&line[m], VDSO__MAP_NAME,
sizeof(VDSO__MAP_NAME) - 1))
if (!strncmp(&line[m], name, strlen(name)))
found = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions tools/perf/util/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "debug.h"

/*
* Include definition of find_vdso_map() also used in perf-read-vdso.c for
* Include definition of find_map() also used in perf-read-vdso.c for
* building perf-read-vdso32 and perf-read-vdsox32.
*/
#include "find-vdso-map.c"
#include "find-map.c"

#define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX"

Expand Down Expand Up @@ -76,7 +76,7 @@ static char *get_file(struct vdso_file *vdso_file)
if (vdso_file->found)
return vdso_file->temp_file_name;

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

size = end - start;
Expand Down

0 comments on commit 0115323

Please sign in to comment.