diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2014-10-23 17:16:03 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-10-29 08:32:48 -0400 |
commit | e477f3f01a89a8fd44031e7f2ba6ffcab037336c (patch) | |
tree | 36d6011cee4ae37dd5e0340cca5c1c0a125be42e /tools | |
parent | 42634bc7a02ead59cf2d50e60d8b8f825de8a3b0 (diff) |
perf tools: Build programs to copy 32-bit compatibility
perf tools copy VDSO out of memory. However, on 64-bit machines there
may be 32-bit compatibility VDOs also. To copy those requires separate
32-bit executables.
This patch adds to the build additional programs perf-read-vdso32 and
perf-read-vdsox32 for 32-bit and x32 respectively.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
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: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1414061124-26830-15-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/Makefile.perf | 38 | ||||
-rw-r--r-- | tools/perf/config/Makefile | 25 | ||||
-rw-r--r-- | tools/perf/config/Makefile.arch | 8 | ||||
-rw-r--r-- | tools/perf/config/feature-checks/Makefile | 10 | ||||
-rw-r--r-- | tools/perf/config/feature-checks/test-compile.c | 4 | ||||
-rw-r--r-- | tools/perf/perf-read-vdso.c | 34 | ||||
-rw-r--r-- | tools/perf/util/find-vdso-map.c | 30 | ||||
-rw-r--r-- | tools/perf/util/vdso.c | 37 |
8 files changed, 149 insertions, 37 deletions
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 262916f4a377..9c4ced0fc845 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf | |||
@@ -60,6 +60,12 @@ include config/utilities.mak | |||
60 | # | 60 | # |
61 | # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support | 61 | # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support |
62 | # for dwarf backtrace post unwind. | 62 | # for dwarf backtrace post unwind. |
63 | # | ||
64 | # Define NO_PERF_READ_VDSO32 if you do not want to build perf-read-vdso32 | ||
65 | # for reading the 32-bit compatibility VDSO in 64-bit mode | ||
66 | # | ||
67 | # Define NO_PERF_READ_VDSOX32 if you do not want to build perf-read-vdsox32 | ||
68 | # for reading the x32 mode 32-bit compatibility VDSO in 64-bit mode | ||
63 | 69 | ||
64 | ifeq ($(srctree),) | 70 | ifeq ($(srctree),) |
65 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) | 71 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) |
@@ -171,11 +177,16 @@ $(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) | |||
171 | 177 | ||
172 | SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) | 178 | SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) |
173 | 179 | ||
174 | # | ||
175 | # Single 'perf' binary right now: | ||
176 | # | ||
177 | PROGRAMS += $(OUTPUT)perf | 180 | PROGRAMS += $(OUTPUT)perf |
178 | 181 | ||
182 | ifndef NO_PERF_READ_VDSO32 | ||
183 | PROGRAMS += $(OUTPUT)perf-read-vdso32 | ||
184 | endif | ||
185 | |||
186 | ifndef NO_PERF_READ_VDSOX32 | ||
187 | PROGRAMS += $(OUTPUT)perf-read-vdsox32 | ||
188 | endif | ||
189 | |||
179 | # what 'all' will build and 'install' will install, in perfexecdir | 190 | # what 'all' will build and 'install' will install, in perfexecdir |
180 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) | 191 | ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) |
181 | 192 | ||
@@ -253,6 +264,7 @@ LIB_H += util/event.h | |||
253 | LIB_H += util/evsel.h | 264 | LIB_H += util/evsel.h |
254 | LIB_H += util/evlist.h | 265 | LIB_H += util/evlist.h |
255 | LIB_H += util/exec_cmd.h | 266 | LIB_H += util/exec_cmd.h |
267 | LIB_H += util/find-vdso-map.c | ||
256 | LIB_H += util/levenshtein.h | 268 | LIB_H += util/levenshtein.h |
257 | LIB_H += util/machine.h | 269 | LIB_H += util/machine.h |
258 | LIB_H += util/map.h | 270 | LIB_H += util/map.h |
@@ -732,6 +744,16 @@ $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Uti | |||
732 | $(OUTPUT)perf-%: %.o $(PERFLIBS) | 744 | $(OUTPUT)perf-%: %.o $(PERFLIBS) |
733 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS) | 745 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS) |
734 | 746 | ||
747 | ifndef NO_PERF_READ_VDSO32 | ||
748 | $(OUTPUT)perf-read-vdso32: perf-read-vdso.c util/find-vdso-map.c | ||
749 | $(QUIET_CC)$(CC) -m32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c | ||
750 | endif | ||
751 | |||
752 | ifndef NO_PERF_READ_VDSOX32 | ||
753 | $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c | ||
754 | $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c | ||
755 | endif | ||
756 | |||
735 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) | 757 | $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) |
736 | $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) | 758 | $(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) |
737 | 759 | ||
@@ -876,6 +898,14 @@ install-bin: all install-gtk | |||
876 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \ | 898 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \ |
877 | $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \ | 899 | $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \ |
878 | $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace' | 900 | $(LN) '$(DESTDIR_SQ)$(bindir_SQ)/perf' '$(DESTDIR_SQ)$(bindir_SQ)/trace' |
901 | ifndef NO_PERF_READ_VDSO32 | ||
902 | $(call QUIET_INSTALL, perf-read-vdso32) \ | ||
903 | $(INSTALL) $(OUTPUT)perf-read-vdso32 '$(DESTDIR_SQ)$(bindir_SQ)'; | ||
904 | endif | ||
905 | ifndef NO_PERF_READ_VDSOX32 | ||
906 | $(call QUIET_INSTALL, perf-read-vdsox32) \ | ||
907 | $(INSTALL) $(OUTPUT)perf-read-vdsox32 '$(DESTDIR_SQ)$(bindir_SQ)'; | ||
908 | endif | ||
879 | $(call QUIET_INSTALL, libexec) \ | 909 | $(call QUIET_INSTALL, libexec) \ |
880 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' | 910 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' |
881 | $(call QUIET_INSTALL, perf-archive) \ | 911 | $(call QUIET_INSTALL, perf-archive) \ |
@@ -928,7 +958,7 @@ config-clean: | |||
928 | 958 | ||
929 | clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean | 959 | clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean |
930 | $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS) | 960 | $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(OUTPUT)perf.o $(LANG_BINDINGS) $(GTK_OBJS) |
931 | $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf | 961 | $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 |
932 | $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* | 962 | $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* |
933 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean | 963 | $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean |
934 | $(python-clean) | 964 | $(python-clean) |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index 58f609198c6d..3ba2382a5236 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
@@ -230,7 +230,9 @@ VF_FEATURE_TESTS = \ | |||
230 | bionic \ | 230 | bionic \ |
231 | liberty \ | 231 | liberty \ |
232 | liberty-z \ | 232 | liberty-z \ |
233 | cplus-demangle | 233 | cplus-demangle \ |
234 | compile-32 \ | ||
235 | compile-x32 | ||
234 | 236 | ||
235 | # Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features. | 237 | # Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features. |
236 | # If in the future we need per-feature checks/flags for features not | 238 | # If in the future we need per-feature checks/flags for features not |
@@ -622,6 +624,27 @@ ifdef HAVE_KVM_STAT_SUPPORT | |||
622 | CFLAGS += -DHAVE_KVM_STAT_SUPPORT | 624 | CFLAGS += -DHAVE_KVM_STAT_SUPPORT |
623 | endif | 625 | endif |
624 | 626 | ||
627 | ifeq (${IS_64_BIT}, 1) | ||
628 | ifndef NO_PERF_READ_VDSO32 | ||
629 | $(call feature_check,compile-32) | ||
630 | ifneq ($(feature-compile-32), 1) | ||
631 | NO_PERF_READ_VDSO32 := 1 | ||
632 | endif | ||
633 | endif | ||
634 | ifneq (${IS_X86_64}, 1) | ||
635 | NO_PERF_READ_VDSOX32 := 1 | ||
636 | endif | ||
637 | ifndef NO_PERF_READ_VDSOX32 | ||
638 | $(call feature_check,compile-x32) | ||
639 | ifneq ($(feature-compile-x32), 1) | ||
640 | NO_PERF_READ_VDSOX32 := 1 | ||
641 | endif | ||
642 | endif | ||
643 | else | ||
644 | NO_PERF_READ_VDSO32 := 1 | ||
645 | NO_PERF_READ_VDSOX32 := 1 | ||
646 | endif | ||
647 | |||
625 | # Among the variables below, these: | 648 | # Among the variables below, these: |
626 | # perfexecdir | 649 | # perfexecdir |
627 | # template_dir | 650 | # template_dir |
diff --git a/tools/perf/config/Makefile.arch b/tools/perf/config/Makefile.arch index 4b06719ee984..851cd0172a76 100644 --- a/tools/perf/config/Makefile.arch +++ b/tools/perf/config/Makefile.arch | |||
@@ -21,3 +21,11 @@ ifeq ($(ARCH),x86_64) | |||
21 | RAW_ARCH := x86_64 | 21 | RAW_ARCH := x86_64 |
22 | endif | 22 | endif |
23 | endif | 23 | endif |
24 | |||
25 | ifeq (${IS_X86_64}, 1) | ||
26 | IS_64_BIT := 1 | ||
27 | else ifeq ($(ARCH),x86) | ||
28 | IS_64_BIT := 0 | ||
29 | else | ||
30 | IS_64_BIT := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) | ||
31 | endif | ||
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile index 72ab2984718e..7c68ec74a808 100644 --- a/tools/perf/config/feature-checks/Makefile +++ b/tools/perf/config/feature-checks/Makefile | |||
@@ -27,7 +27,9 @@ FILES= \ | |||
27 | test-libunwind-debug-frame.bin \ | 27 | test-libunwind-debug-frame.bin \ |
28 | test-stackprotector-all.bin \ | 28 | test-stackprotector-all.bin \ |
29 | test-timerfd.bin \ | 29 | test-timerfd.bin \ |
30 | test-libdw-dwarf-unwind.bin | 30 | test-libdw-dwarf-unwind.bin \ |
31 | test-compile-32.bin \ | ||
32 | test-compile-x32.bin | ||
31 | 33 | ||
32 | CC := $(CROSS_COMPILE)gcc -MD | 34 | CC := $(CROSS_COMPILE)gcc -MD |
33 | PKG_CONFIG := $(CROSS_COMPILE)pkg-config | 35 | PKG_CONFIG := $(CROSS_COMPILE)pkg-config |
@@ -131,6 +133,12 @@ test-libdw-dwarf-unwind.bin: | |||
131 | test-sync-compare-and-swap.bin: | 133 | test-sync-compare-and-swap.bin: |
132 | $(BUILD) -Werror | 134 | $(BUILD) -Werror |
133 | 135 | ||
136 | test-compile-32.bin: | ||
137 | $(CC) -m32 -o $(OUTPUT)$@ test-compile.c | ||
138 | |||
139 | test-compile-x32.bin: | ||
140 | $(CC) -mx32 -o $(OUTPUT)$@ test-compile.c | ||
141 | |||
134 | -include *.d | 142 | -include *.d |
135 | 143 | ||
136 | ############################### | 144 | ############################### |
diff --git a/tools/perf/config/feature-checks/test-compile.c b/tools/perf/config/feature-checks/test-compile.c new file mode 100644 index 000000000000..31dbf45bf99c --- /dev/null +++ b/tools/perf/config/feature-checks/test-compile.c | |||
@@ -0,0 +1,4 @@ | |||
1 | int main(void) | ||
2 | { | ||
3 | return 0; | ||
4 | } | ||
diff --git a/tools/perf/perf-read-vdso.c b/tools/perf/perf-read-vdso.c new file mode 100644 index 000000000000..764e2547c25a --- /dev/null +++ b/tools/perf/perf-read-vdso.c | |||
@@ -0,0 +1,34 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | |||
4 | #define VDSO__MAP_NAME "[vdso]" | ||
5 | |||
6 | /* | ||
7 | * Include definition of find_vdso_map() also used in util/vdso.c for | ||
8 | * building perf. | ||
9 | */ | ||
10 | #include "util/find-vdso-map.c" | ||
11 | |||
12 | int main(void) | ||
13 | { | ||
14 | void *start, *end; | ||
15 | size_t size, written; | ||
16 | |||
17 | if (find_vdso_map(&start, &end)) | ||
18 | return 1; | ||
19 | |||
20 | size = end - start; | ||
21 | |||
22 | while (size) { | ||
23 | written = fwrite(start, 1, size, stdout); | ||
24 | if (!written) | ||
25 | return 1; | ||
26 | start += written; | ||
27 | size -= written; | ||
28 | } | ||
29 | |||
30 | if (fflush(stdout)) | ||
31 | return 1; | ||
32 | |||
33 | return 0; | ||
34 | } | ||
diff --git a/tools/perf/util/find-vdso-map.c b/tools/perf/util/find-vdso-map.c new file mode 100644 index 000000000000..95ef1cffc056 --- /dev/null +++ b/tools/perf/util/find-vdso-map.c | |||
@@ -0,0 +1,30 @@ | |||
1 | static int find_vdso_map(void **start, void **end) | ||
2 | { | ||
3 | FILE *maps; | ||
4 | char line[128]; | ||
5 | int found = 0; | ||
6 | |||
7 | maps = fopen("/proc/self/maps", "r"); | ||
8 | if (!maps) { | ||
9 | fprintf(stderr, "vdso: cannot open maps\n"); | ||
10 | return -1; | ||
11 | } | ||
12 | |||
13 | while (!found && fgets(line, sizeof(line), maps)) { | ||
14 | int m = -1; | ||
15 | |||
16 | /* We care only about private r-x mappings. */ | ||
17 | if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n", | ||
18 | start, end, &m)) | ||
19 | continue; | ||
20 | if (m < 0) | ||
21 | continue; | ||
22 | |||
23 | if (!strncmp(&line[m], VDSO__MAP_NAME, | ||
24 | sizeof(VDSO__MAP_NAME) - 1)) | ||
25 | found = 1; | ||
26 | } | ||
27 | |||
28 | fclose(maps); | ||
29 | return !found; | ||
30 | } | ||
diff --git a/tools/perf/util/vdso.c b/tools/perf/util/vdso.c index adca69384fcc..f51390a1ed51 100644 --- a/tools/perf/util/vdso.c +++ b/tools/perf/util/vdso.c | |||
@@ -15,6 +15,12 @@ | |||
15 | #include "linux/string.h" | 15 | #include "linux/string.h" |
16 | #include "debug.h" | 16 | #include "debug.h" |
17 | 17 | ||
18 | /* | ||
19 | * Include definition of find_vdso_map() also used in perf-read-vdso.c for | ||
20 | * building perf-read-vdso32 and perf-read-vdsox32. | ||
21 | */ | ||
22 | #include "find-vdso-map.c" | ||
23 | |||
18 | #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" | 24 | #define VDSO__TEMP_FILE_NAME "/tmp/perf-vdso.so-XXXXXX" |
19 | 25 | ||
20 | struct vdso_file { | 26 | struct vdso_file { |
@@ -40,37 +46,6 @@ static struct vdso_info *vdso_info__new(void) | |||
40 | return memdup(&vdso_info_init, sizeof(vdso_info_init)); | 46 | return memdup(&vdso_info_init, sizeof(vdso_info_init)); |
41 | } | 47 | } |
42 | 48 | ||
43 | static int find_vdso_map(void **start, void **end) | ||
44 | { | ||
45 | FILE *maps; | ||
46 | char line[128]; | ||
47 | int found = 0; | ||
48 | |||
49 | maps = fopen("/proc/self/maps", "r"); | ||
50 | if (!maps) { | ||
51 | pr_err("vdso: cannot open maps\n"); | ||
52 | return -1; | ||
53 | } | ||
54 | |||
55 | while (!found && fgets(line, sizeof(line), maps)) { | ||
56 | int m = -1; | ||
57 | |||
58 | /* We care only about private r-x mappings. */ | ||
59 | if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n", | ||
60 | start, end, &m)) | ||
61 | continue; | ||
62 | if (m < 0) | ||
63 | continue; | ||
64 | |||
65 | if (!strncmp(&line[m], VDSO__MAP_NAME, | ||
66 | sizeof(VDSO__MAP_NAME) - 1)) | ||
67 | found = 1; | ||
68 | } | ||
69 | |||
70 | fclose(maps); | ||
71 | return !found; | ||
72 | } | ||
73 | |||
74 | static char *get_file(struct vdso_file *vdso_file) | 49 | static char *get_file(struct vdso_file *vdso_file) |
75 | { | 50 | { |
76 | char *vdso = NULL; | 51 | char *vdso = NULL; |