Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Make find_vdso_map() more modular

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 <f.fainelli@gmail.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Kim Phillips <kim.phillips@arm.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: http://lkml.kernel.org/r/20181221034337.26663-2-f.fainelli@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Florian Fainelli and committed by
Arnaldo Carvalho de Melo
01153237 ac6e022c

+11 -12
+2 -2
tools/perf/Makefile.perf
··· 662 662 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS) 663 663 664 664 ifndef NO_PERF_READ_VDSO32 665 - $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-vdso-map.c 665 + $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-map.c 666 666 $(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c 667 667 endif 668 668 669 669 ifndef NO_PERF_READ_VDSOX32 670 - $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c 670 + $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-map.c 671 671 $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c 672 672 endif 673 673
+3 -3
tools/perf/perf-read-vdso.c
··· 5 5 #define VDSO__MAP_NAME "[vdso]" 6 6 7 7 /* 8 - * Include definition of find_vdso_map() also used in util/vdso.c for 8 + * Include definition of find_map() also used in util/vdso.c for 9 9 * building perf. 10 10 */ 11 - #include "util/find-vdso-map.c" 11 + #include "util/find-map.c" 12 12 13 13 int main(void) 14 14 { 15 15 void *start, *end; 16 16 size_t size, written; 17 17 18 - if (find_vdso_map(&start, &end)) 18 + if (find_map(&start, &end, VDSO__MAP_NAME)) 19 19 return 1; 20 20 21 21 size = end - start;
+3 -4
tools/perf/util/find-vdso-map.c tools/perf/util/find-map.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - static int find_vdso_map(void **start, void **end) 2 + static int find_map(void **start, void **end, const char *name) 3 3 { 4 4 FILE *maps; 5 5 char line[128]; ··· 7 7 8 8 maps = fopen("/proc/self/maps", "r"); 9 9 if (!maps) { 10 - fprintf(stderr, "vdso: cannot open maps\n"); 10 + fprintf(stderr, "cannot open maps\n"); 11 11 return -1; 12 12 } 13 13 ··· 21 21 if (m < 0) 22 22 continue; 23 23 24 - if (!strncmp(&line[m], VDSO__MAP_NAME, 25 - sizeof(VDSO__MAP_NAME) - 1)) 24 + if (!strncmp(&line[m], name, strlen(name))) 26 25 found = 1; 27 26 } 28 27
+3 -3
tools/perf/util/vdso.c
··· 18 18 #include "debug.h" 19 19 20 20 /* 21 - * Include definition of find_vdso_map() also used in perf-read-vdso.c for 21 + * Include definition of find_map() also used in perf-read-vdso.c for 22 22 * building perf-read-vdso32 and perf-read-vdsox32. 23 23 */ 24 - #include "find-vdso-map.c" 24 + #include "find-map.c" 25 25 26 26 #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" 27 27 ··· 76 76 if (vdso_file->found) 77 77 return vdso_file->temp_file_name; 78 78 79 - if (vdso_file->error || find_vdso_map(&start, &end)) 79 + if (vdso_file->error || find_map(&start, &end, VDSO__MAP_NAME)) 80 80 return NULL; 81 81 82 82 size = end - start;