aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kernel/events/core.c2
-rw-r--r--tools/build/Build.include81
-rw-r--r--tools/build/Documentation/Build.txt139
-rw-r--r--tools/build/Makefile.build130
-rw-r--r--tools/build/tests/ex/Build8
-rw-r--r--tools/build/tests/ex/Makefile23
-rw-r--r--tools/build/tests/ex/a.c5
-rw-r--r--tools/build/tests/ex/arch/Build2
-rw-r--r--tools/build/tests/ex/arch/e.c5
-rw-r--r--tools/build/tests/ex/arch/f.c5
-rw-r--r--tools/build/tests/ex/b.c5
-rw-r--r--tools/build/tests/ex/c.c5
-rw-r--r--tools/build/tests/ex/d.c5
-rw-r--r--tools/build/tests/ex/empty/Build0
-rw-r--r--tools/build/tests/ex/ex.c19
-rwxr-xr-xtools/build/tests/run.sh42
-rw-r--r--tools/lib/api/Build2
-rw-r--r--tools/lib/api/Makefile58
-rw-r--r--tools/lib/api/fd/Build1
-rw-r--r--tools/lib/api/fs/Build4
-rw-r--r--tools/lib/api/fs/debugfs.c69
-rw-r--r--tools/lib/api/fs/debugfs.h13
-rw-r--r--tools/lib/api/fs/findfs.c63
-rw-r--r--tools/lib/api/fs/findfs.h23
-rw-r--r--tools/lib/api/fs/tracefs.c78
-rw-r--r--tools/lib/api/fs/tracefs.h21
-rw-r--r--tools/lib/lockdep/Build1
-rw-r--r--tools/lib/lockdep/Makefile132
-rw-r--r--tools/lib/traceevent/Build17
-rw-r--r--tools/lib/traceevent/Makefile169
-rw-r--r--tools/lib/traceevent/event-parse.h2
-rw-r--r--tools/lib/traceevent/trace-seq.c13
-rw-r--r--tools/perf/Build43
-rw-r--r--tools/perf/Documentation/Build.txt49
-rw-r--r--tools/perf/Documentation/perf-probe.txt16
-rw-r--r--tools/perf/MANIFEST1
-rw-r--r--tools/perf/Makefile.perf616
-rw-r--r--tools/perf/arch/Build2
-rw-r--r--tools/perf/arch/arm/Build2
-rw-r--r--tools/perf/arch/arm/Makefile11
-rw-r--r--tools/perf/arch/arm/tests/Build2
-rw-r--r--tools/perf/arch/arm/util/Build4
-rw-r--r--tools/perf/arch/arm64/Build1
-rw-r--r--tools/perf/arch/arm64/Makefile4
-rw-r--r--tools/perf/arch/arm64/util/Build2
-rw-r--r--tools/perf/arch/powerpc/Build1
-rw-r--r--tools/perf/arch/powerpc/Makefile3
-rw-r--r--tools/perf/arch/powerpc/util/Build4
-rw-r--r--tools/perf/arch/s390/Build1
-rw-r--r--tools/perf/arch/s390/Makefile3
-rw-r--r--tools/perf/arch/s390/util/Build4
-rw-r--r--tools/perf/arch/sh/Build1
-rw-r--r--tools/perf/arch/sh/Makefile1
-rw-r--r--tools/perf/arch/sh/util/Build1
-rw-r--r--tools/perf/arch/sparc/Build1
-rw-r--r--tools/perf/arch/sparc/Makefile1
-rw-r--r--tools/perf/arch/sparc/util/Build1
-rw-r--r--tools/perf/arch/x86/Build2
-rw-r--r--tools/perf/arch/x86/Makefile15
-rw-r--r--tools/perf/arch/x86/tests/Build2
-rw-r--r--tools/perf/arch/x86/util/Build8
-rw-r--r--tools/perf/bench/Build11
-rw-r--r--tools/perf/builtin-buildid-cache.c37
-rw-r--r--tools/perf/builtin-list.c3
-rw-r--r--tools/perf/builtin-trace.c90
-rw-r--r--tools/perf/config/Makefile41
-rw-r--r--tools/perf/config/feature-checks/Makefile2
-rw-r--r--tools/perf/scripts/Build2
-rw-r--r--tools/perf/scripts/perl/Perf-Trace-Util/Build3
-rw-r--r--tools/perf/scripts/python/Perf-Trace-Util/Build3
-rw-r--r--tools/perf/tests/Build42
-rw-r--r--tools/perf/tests/dso-data.c22
-rw-r--r--tools/perf/tests/open-syscall-all-cpus.c7
-rw-r--r--tools/perf/tests/open-syscall.c7
-rw-r--r--tools/perf/tests/parse-events.c13
-rw-r--r--tools/perf/ui/Build14
-rw-r--r--tools/perf/ui/browsers/Build10
-rw-r--r--tools/perf/ui/gtk/Build9
-rw-r--r--tools/perf/ui/tui/Build4
-rw-r--r--tools/perf/util/Build142
-rw-r--r--tools/perf/util/build-id.c96
-rw-r--r--tools/perf/util/build-id.h4
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/dso.c8
-rw-r--r--tools/perf/util/dwarf-aux.c15
-rw-r--r--tools/perf/util/dwarf-aux.h3
-rw-r--r--tools/perf/util/evlist.c3
-rw-r--r--tools/perf/util/parse-events.c24
-rw-r--r--tools/perf/util/parse-events.h2
-rw-r--r--tools/perf/util/parse-options.c6
-rw-r--r--tools/perf/util/probe-event.c24
-rw-r--r--tools/perf/util/probe-finder.c12
-rw-r--r--tools/perf/util/python-ext-sources1
-rw-r--r--tools/perf/util/scripting-engines/Build6
-rw-r--r--tools/perf/util/setup.py2
-rw-r--r--tools/perf/util/symbol-elf.c11
-rw-r--r--tools/perf/util/trace-event-parse.c12
-rw-r--r--tools/perf/util/trace-event.h3
-rw-r--r--tools/perf/util/util.c60
-rw-r--r--tools/perf/util/util.h1
100 files changed, 1641 insertions, 1059 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 257eccf9afd4..20cece0a7aea 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4446,7 +4446,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
4446 * If we have rb pages ensure they're a power-of-two number, so we 4446 * If we have rb pages ensure they're a power-of-two number, so we
4447 * can do bitmasks instead of modulo. 4447 * can do bitmasks instead of modulo.
4448 */ 4448 */
4449 if (nr_pages != 0 && !is_power_of_2(nr_pages)) 4449 if (!is_power_of_2(nr_pages))
4450 return -EINVAL; 4450 return -EINVAL;
4451 4451
4452 if (vma_size != PAGE_SIZE * (1 + nr_pages)) 4452 if (vma_size != PAGE_SIZE * (1 + nr_pages))
diff --git a/tools/build/Build.include b/tools/build/Build.include
new file mode 100644
index 000000000000..4c8daaccb82a
--- /dev/null
+++ b/tools/build/Build.include
@@ -0,0 +1,81 @@
1###
2# build: Generic definitions
3#
4# Lots of this code have been borrowed or heavily inspired from parts
5# of kbuild code, which is not credited, but mostly developed by:
6#
7# Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015
8# Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015
9#
10
11###
12# Convenient variables
13comma := ,
14squote := '
15
16###
17# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
18dot-target = $(dir $@).$(notdir $@)
19
20###
21# filename of target with directory and extension stripped
22basetarget = $(basename $(notdir $@))
23
24###
25# The temporary file to save gcc -MD generated dependencies must not
26# contain a comma
27depfile = $(subst $(comma),_,$(dot-target).d)
28
29###
30# Check if both arguments has same arguments. Result is empty string if equal.
31arg-check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
32 $(filter-out $(cmd_$@), $(cmd_$(1))) )
33
34###
35# Escape single quote for use in echo statements
36escsq = $(subst $(squote),'\$(squote)',$1)
37
38# Echo command
39# Short version is used, if $(quiet) equals `quiet_', otherwise full one.
40echo-cmd = $(if $($(quiet)cmd_$(1)),\
41 echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
42
43###
44# Replace >$< with >$$< to preserve $ when reloading the .cmd file
45# (needed for make)
46# Replace >#< with >\#< to avoid starting a comment in the .cmd file
47# (needed for make)
48# Replace >'< with >'\''< to be able to enclose the whole string in '...'
49# (needed for the shell)
50make-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1)))))
51
52###
53# Find any prerequisites that is newer than target or that does not exist.
54# PHONY targets skipped in both cases.
55any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
56
57###
58# if_changed_dep - execute command if any prerequisite is newer than
59# target, or command line has changed and update
60# dependencies in the cmd file
61if_changed_dep = $(if $(strip $(any-prereq) $(arg-check)), \
62 @set -e; \
63 $(echo-cmd) $(cmd_$(1)); \
64 cat $(depfile) > $(dot-target).cmd; \
65 printf '%s\n' 'cmd_$@ := $(make-cmd)' >> $(dot-target).cmd)
66
67# if_changed - execute command if any prerequisite is newer than
68# target, or command line has changed
69if_changed = $(if $(strip $(any-prereq) $(arg-check)), \
70 @set -e; \
71 $(echo-cmd) $(cmd_$(1)); \
72 printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd)
73
74###
75# C flags to be used in rule definitions, includes:
76# - depfile generation
77# - global $(CFLAGS)
78# - per target C flags
79# - per object C flags
80# - BUILD_STR macro to allow '-D"$(variable)"' constructs
81c_flags = -Wp,-MD,$(depfile),-MT,$@ $(CFLAGS) -D"BUILD_STR(s)=\#s" $(CFLAGS_$(basetarget).o) $(CFLAGS_$(obj))
diff --git a/tools/build/Documentation/Build.txt b/tools/build/Documentation/Build.txt
new file mode 100644
index 000000000000..00ad2d608727
--- /dev/null
+++ b/tools/build/Documentation/Build.txt
@@ -0,0 +1,139 @@
1Build Framework
2===============
3
4The perf build framework was adopted from the kernel build system, hence the
5idea and the way how objects are built is the same.
6
7Basically the user provides set of 'Build' files that list objects and
8directories to nest for specific target to be build.
9
10Unlike the kernel we don't have a single build object 'obj-y' list that where
11we setup source objects, but we support more. This allows one 'Build' file to
12carry a sources list for multiple build objects.
13
14a) Build framework makefiles
15----------------------------
16
17The build framework consists of 2 Makefiles:
18
19 Build.include
20 Makefile.build
21
22While the 'Build.include' file contains just some generic definitions, the
23'Makefile.build' file is the makefile used from the outside. It's
24interface/usage is following:
25
26 $ make -f tools/build/Makefile srctree=$(KSRC) dir=$(DIR) obj=$(OBJECT)
27
28where:
29
30 KSRC - is the path to kernel sources
31 DIR - is the path to the project to be built
32 OBJECT - is the name of the build object
33
34When succefully finished the $(DIR) directory contains the final object file
35called $(OBJECT)-in.o:
36
37 $ ls $(DIR)/$(OBJECT)-in.o
38
39which includes all compiled sources described in 'Build' makefiles.
40
41a) Build makefiles
42------------------
43
44The user supplies 'Build' makefiles that contains a objects list, and connects
45the build to nested directories.
46
47Assume we have the following project structure:
48
49 ex/a.c
50 /b.c
51 /c.c
52 /d.c
53 /arch/e.c
54 /arch/f.c
55
56Out of which you build the 'ex' binary ' and the 'libex.a' library:
57
58 'ex' - consists of 'a.o', 'b.o' and libex.a
59 'libex.a' - consists of 'c.o', 'd.o', 'e.o' and 'f.o'
60
61The build framework does not create the 'ex' and 'libex.a' binaries for you, it
62only prepares proper objects to be compiled and grouped together.
63
64To follow the above example, the user provides following 'Build' files:
65
66 ex/Build:
67 ex-y += a.o
68 ex-y += b.o
69
70 libex-y += c.o
71 libex-y += d.o
72 libex-y += arch/
73
74 ex/arch/Build:
75 libex-y += e.o
76 libex-y += f.o
77
78and runs:
79
80 $ make -f tools/build/Makefile.build dir=. obj=ex
81 $ make -f tools/build/Makefile.build dir=. obj=libex
82
83which creates the following objects:
84
85 ex/ex-in.o
86 ex/libex-in.o
87
88that contain request objects names in Build files.
89
90It's only a matter of 2 single commands to create the final binaries:
91
92 $ ar rcs libex.a libex-in.o
93 $ gcc -o ex ex-in.o libex.a
94
95You can check the 'ex' example in 'tools/build/tests/ex' for more details.
96
97b) Rules
98--------
99
100The build framework provides standard compilation rules to handle .S and .c
101compilation.
102
103It's possible to include special rule if needed (like we do for flex or bison
104code generation).
105
106c) CFLAGS
107---------
108
109It's possible to alter the standard object C flags in the following way:
110
111 CFLAGS_perf.o += '...' - alters CFLAGS for perf.o object
112 CFLAGS_gtk += '...' - alters CFLAGS for gtk build object
113
114This C flags changes has the scope of the Build makefile they are defined in.
115
116
117d) Dependencies
118---------------
119
120For each built object file 'a.o' the '.a.cmd' is created and holds:
121
122 - Command line used to built that object
123 (for each object)
124
125 - Dependency rules generated by 'gcc -Wp,-MD,...'
126 (for compiled object)
127
128All existing '.cmd' files are included in the Build process to follow properly
129the dependencies and trigger a rebuild when necessary.
130
131
132e) Single rules
133---------------
134
135It's possible to build single object file by choice, like:
136
137 $ make util/map.o # objects
138 $ make util/map.i # preprocessor
139 $ make util/map.s # assembly
diff --git a/tools/build/Makefile.build b/tools/build/Makefile.build
new file mode 100644
index 000000000000..10df57237a66
--- /dev/null
+++ b/tools/build/Makefile.build
@@ -0,0 +1,130 @@
1###
2# Main build makefile.
3#
4# Lots of this code have been borrowed or heavily inspired from parts
5# of kbuild code, which is not credited, but mostly developed by:
6#
7# Copyright (C) Sam Ravnborg <sam@mars.ravnborg.org>, 2015
8# Copyright (C) Linus Torvalds <torvalds@linux-foundation.org>, 2015
9#
10
11PHONY := __build
12__build:
13
14ifeq ($(V),1)
15 quiet =
16 Q =
17else
18 quiet=quiet_
19 Q=@
20endif
21
22build-dir := $(srctree)/tools/build
23
24# Generic definitions
25include $(build-dir)/Build.include
26
27# do not force detected configuration
28-include .config-detected
29
30# Init all relevant variables used in build files so
31# 1) they have correct type
32# 2) they do not inherit any value from the environment
33subdir-y :=
34obj-y :=
35subdir-y :=
36subdir-obj-y :=
37
38# Build definitions
39build-file := $(dir)/Build
40include $(build-file)
41
42quiet_cmd_flex = FLEX $@
43quiet_cmd_bison = BISON $@
44
45# Create directory unless it exists
46quiet_cmd_mkdir = MKDIR $(dir $@)
47 cmd_mkdir = mkdir -p $(dir $@)
48 rule_mkdir = $(if $(wildcard $(dir $@)),,@$(call echo-cmd,mkdir) $(cmd_mkdir))
49
50# Compile command
51quiet_cmd_cc_o_c = CC $@
52 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
53
54quiet_cmd_cc_i_c = CPP $@
55 cmd_cc_i_c = $(CC) $(c_flags) -E -o $@ $<
56
57quiet_cmd_cc_s_c = AS $@
58 cmd_cc_s_c = $(CC) $(c_flags) -S -o $@ $<
59
60# Link agregate command
61# If there's nothing to link, create empty $@ object.
62quiet_cmd_ld_multi = LD $@
63 cmd_ld_multi = $(if $(strip $(obj-y)),\
64 $(LD) -r -o $@ $(obj-y),rm -f $@; $(AR) rcs $@)
65
66# Build rules
67$(OUTPUT)%.o: %.c FORCE
68 $(call rule_mkdir)
69 $(call if_changed_dep,cc_o_c)
70
71$(OUTPUT)%.o: %.S FORCE
72 $(call rule_mkdir)
73 $(call if_changed_dep,cc_o_c)
74
75$(OUTPUT)%.i: %.c FORCE
76 $(call rule_mkdir)
77 $(call if_changed_dep,cc_i_c)
78
79$(OUTPUT)%.i: %.S FORCE
80 $(call rule_mkdir)
81 $(call if_changed_dep,cc_i_c)
82
83$(OUTPUT)%.s: %.c FORCE
84 $(call rule_mkdir)
85 $(call if_changed_dep,cc_s_c)
86
87# Gather build data:
88# obj-y - list of build objects
89# subdir-y - list of directories to nest
90# subdir-obj-y - list of directories objects 'dir/$(obj)-in.o'
91obj-y := $($(obj)-y)
92subdir-y := $(patsubst %/,%,$(filter %/, $(obj-y)))
93obj-y := $(patsubst %/, %/$(obj)-in.o, $(obj-y))
94subdir-obj-y := $(filter %/$(obj)-in.o, $(obj-y))
95
96# '$(OUTPUT)/dir' prefix to all objects
97prefix := $(subst ./,,$(OUTPUT)$(dir)/)
98obj-y := $(addprefix $(prefix),$(obj-y))
99subdir-obj-y := $(addprefix $(prefix),$(subdir-obj-y))
100
101# Final '$(obj)-in.o' object
102in-target := $(prefix)$(obj)-in.o
103
104PHONY += $(subdir-y)
105
106$(subdir-y):
107 $(Q)$(MAKE) -f $(build-dir)/Makefile.build dir=$(dir)/$@ obj=$(obj)
108
109$(sort $(subdir-obj-y)): $(subdir-y) ;
110
111$(in-target): $(obj-y) FORCE
112 $(call rule_mkdir)
113 $(call if_changed,ld_multi)
114
115__build: $(in-target)
116 @:
117
118PHONY += FORCE
119FORCE:
120
121# Include all cmd files to get all the dependency rules
122# for all objects included
123targets := $(wildcard $(sort $(obj-y) $(in-target) $(MAKECMDGOALS)))
124cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
125
126ifneq ($(cmd_files),)
127 include $(cmd_files)
128endif
129
130.PHONY: $(PHONY)
diff --git a/tools/build/tests/ex/Build b/tools/build/tests/ex/Build
new file mode 100644
index 000000000000..0e6c3e6767e6
--- /dev/null
+++ b/tools/build/tests/ex/Build
@@ -0,0 +1,8 @@
1ex-y += ex.o
2ex-y += a.o
3ex-y += b.o
4ex-y += empty/
5
6libex-y += c.o
7libex-y += d.o
8libex-y += arch/
diff --git a/tools/build/tests/ex/Makefile b/tools/build/tests/ex/Makefile
new file mode 100644
index 000000000000..52d2476073a3
--- /dev/null
+++ b/tools/build/tests/ex/Makefile
@@ -0,0 +1,23 @@
1export srctree := ../../../..
2export CC := gcc
3export LD := ld
4export AR := ar
5
6build := -f $(srctree)/tools/build/Makefile.build dir=. obj
7ex: ex-in.o libex-in.o
8 gcc -o $@ $^
9
10ex.%: FORCE
11 make -f $(srctree)/tools/build/Makefile.build dir=. $@
12
13ex-in.o: FORCE
14 make $(build)=ex
15
16libex-in.o: FORCE
17 make $(build)=libex
18
19clean:
20 find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
21 rm -f ex ex.i ex.s
22
23.PHONY: FORCE
diff --git a/tools/build/tests/ex/a.c b/tools/build/tests/ex/a.c
new file mode 100644
index 000000000000..851762798c83
--- /dev/null
+++ b/tools/build/tests/ex/a.c
@@ -0,0 +1,5 @@
1
2int a(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/arch/Build b/tools/build/tests/ex/arch/Build
new file mode 100644
index 000000000000..55506189efae
--- /dev/null
+++ b/tools/build/tests/ex/arch/Build
@@ -0,0 +1,2 @@
1libex-y += e.o
2libex-y += f.o
diff --git a/tools/build/tests/ex/arch/e.c b/tools/build/tests/ex/arch/e.c
new file mode 100644
index 000000000000..beaa4a1d7ba8
--- /dev/null
+++ b/tools/build/tests/ex/arch/e.c
@@ -0,0 +1,5 @@
1
2int e(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/arch/f.c b/tools/build/tests/ex/arch/f.c
new file mode 100644
index 000000000000..7c3e9e9da5b7
--- /dev/null
+++ b/tools/build/tests/ex/arch/f.c
@@ -0,0 +1,5 @@
1
2int f(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/b.c b/tools/build/tests/ex/b.c
new file mode 100644
index 000000000000..c24ff9ca9a97
--- /dev/null
+++ b/tools/build/tests/ex/b.c
@@ -0,0 +1,5 @@
1
2int b(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/c.c b/tools/build/tests/ex/c.c
new file mode 100644
index 000000000000..e216d0217499
--- /dev/null
+++ b/tools/build/tests/ex/c.c
@@ -0,0 +1,5 @@
1
2int c(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/d.c b/tools/build/tests/ex/d.c
new file mode 100644
index 000000000000..80dc0f06151b
--- /dev/null
+++ b/tools/build/tests/ex/d.c
@@ -0,0 +1,5 @@
1
2int d(void)
3{
4 return 0;
5}
diff --git a/tools/build/tests/ex/empty/Build b/tools/build/tests/ex/empty/Build
new file mode 100644
index 000000000000..e69de29bb2d1
--- /dev/null
+++ b/tools/build/tests/ex/empty/Build
diff --git a/tools/build/tests/ex/ex.c b/tools/build/tests/ex/ex.c
new file mode 100644
index 000000000000..dc42eb2e1a67
--- /dev/null
+++ b/tools/build/tests/ex/ex.c
@@ -0,0 +1,19 @@
1
2int a(void);
3int b(void);
4int c(void);
5int d(void);
6int e(void);
7int f(void);
8
9int main(void)
10{
11 a();
12 b();
13 c();
14 d();
15 e();
16 f();
17
18 return 0;
19}
diff --git a/tools/build/tests/run.sh b/tools/build/tests/run.sh
new file mode 100755
index 000000000000..5494f8ea7567
--- /dev/null
+++ b/tools/build/tests/run.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2
3function test_ex {
4 make -C ex V=1 clean > ex.out 2>&1
5 make -C ex V=1 >> ex.out 2>&1
6
7 if [ ! -x ./ex/ex ]; then
8 echo FAILED
9 exit -1
10 fi
11
12 make -C ex V=1 clean > /dev/null 2>&1
13 rm -f ex.out
14}
15
16function test_ex_suffix {
17 make -C ex V=1 clean > ex.out 2>&1
18
19 # use -rR to disable make's builtin rules
20 make -rR -C ex V=1 ex.o >> ex.out 2>&1
21 make -rR -C ex V=1 ex.i >> ex.out 2>&1
22 make -rR -C ex V=1 ex.s >> ex.out 2>&1
23
24 if [ -x ./ex/ex ]; then
25 echo FAILED
26 exit -1
27 fi
28
29 if [ ! -f ./ex/ex.o -o ! -f ./ex/ex.i -o ! -f ./ex/ex.s ]; then
30 echo FAILED
31 exit -1
32 fi
33
34 make -C ex V=1 clean > /dev/null 2>&1
35 rm -f ex.out
36}
37echo -n Testing..
38
39test_ex
40test_ex_suffix
41
42echo OK
diff --git a/tools/lib/api/Build b/tools/lib/api/Build
new file mode 100644
index 000000000000..3653965cf481
--- /dev/null
+++ b/tools/lib/api/Build
@@ -0,0 +1,2 @@
1libapi-y += fd/
2libapi-y += fs/
diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
index 36c08b1f4afb..d8fe29fc19a4 100644
--- a/tools/lib/api/Makefile
+++ b/tools/lib/api/Makefile
@@ -1,49 +1,43 @@
1include ../../scripts/Makefile.include 1include ../../scripts/Makefile.include
2include ../../perf/config/utilities.mak # QUIET_CLEAN 2include ../../perf/config/utilities.mak # QUIET_CLEAN
3 3
4ifeq ($(srctree),)
5srctree := $(patsubst %/,%,$(dir $(shell pwd)))
6srctree := $(patsubst %/,%,$(dir $(srctree)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8#$(info Determined 'srctree' to be $(srctree))
9endif
10
4CC = $(CROSS_COMPILE)gcc 11CC = $(CROSS_COMPILE)gcc
5AR = $(CROSS_COMPILE)ar 12AR = $(CROSS_COMPILE)ar
6 13
7# guard against environment variables 14MAKEFLAGS += --no-print-directory
8LIB_H=
9LIB_OBJS=
10
11LIB_H += fs/debugfs.h
12LIB_H += fs/fs.h
13# See comment below about piggybacking...
14LIB_H += fd/array.h
15
16LIB_OBJS += $(OUTPUT)fs/debugfs.o
17LIB_OBJS += $(OUTPUT)fs/fs.o
18# XXX piggybacking here, need to introduce libapikfd, or rename this
19# to plain libapik.a and make it have it all api goodies
20LIB_OBJS += $(OUTPUT)fd/array.o
21 15
22LIBFILE = libapikfs.a 16LIBFILE = $(OUTPUT)libapi.a
23 17
24CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC 18CFLAGS := $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
25EXTLIBS = -lelf -lpthread -lrt -lm 19CFLAGS += -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 -fPIC
26ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 20CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
27ALL_LDFLAGS = $(LDFLAGS)
28 21
29RM = rm -f 22RM = rm -f
30 23
31$(LIBFILE): $(LIB_OBJS) 24build := -f $(srctree)/tools/build/Makefile.build dir=. obj
32 $(QUIET_AR)$(RM) $@ && $(AR) rcs $(OUTPUT)$@ $(LIB_OBJS) 25API_IN := $(OUTPUT)libapi-in.o
33 26
34$(LIB_OBJS): $(LIB_H) 27export srctree OUTPUT CC LD CFLAGS V
35 28
36libapi_dirs: 29all: $(LIBFILE)
37 $(QUIET_MKDIR)mkdir -p $(OUTPUT)fd $(OUTPUT)fs
38 30
39$(OUTPUT)%.o: %.c libapi_dirs 31$(API_IN): FORCE
40 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< 32 @$(MAKE) $(build)=libapi
41$(OUTPUT)%.s: %.c libapi_dirs 33
42 $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< 34$(LIBFILE): $(API_IN)
43$(OUTPUT)%.o: %.S libapi_dirs 35 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(API_IN)
44 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
45 36
46clean: 37clean:
47 $(call QUIET_CLEAN, libapi) $(RM) $(LIB_OBJS) $(LIBFILE) 38 $(call QUIET_CLEAN, libapi) $(RM) $(LIBFILE); \
39 find $(if $(OUTPUT),$(OUTPUT),.) -name \*.o | xargs $(RM)
40
41FORCE:
48 42
49.PHONY: clean 43.PHONY: clean FORCE
diff --git a/tools/lib/api/fd/Build b/tools/lib/api/fd/Build
new file mode 100644
index 000000000000..605d99f6d71a
--- /dev/null
+++ b/tools/lib/api/fd/Build
@@ -0,0 +1 @@
libapi-y += array.o
diff --git a/tools/lib/api/fs/Build b/tools/lib/api/fs/Build
new file mode 100644
index 000000000000..6de5a4f0b501
--- /dev/null
+++ b/tools/lib/api/fs/Build
@@ -0,0 +1,4 @@
1libapi-y += fs.o
2libapi-y += debugfs.o
3libapi-y += findfs.o
4libapi-y += tracefs.o
diff --git a/tools/lib/api/fs/debugfs.c b/tools/lib/api/fs/debugfs.c
index d2b18e887071..8305b3e9d48e 100644
--- a/tools/lib/api/fs/debugfs.c
+++ b/tools/lib/api/fs/debugfs.c
@@ -3,75 +3,50 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h> 5#include <string.h>
6#include <unistd.h>
6#include <stdbool.h> 7#include <stdbool.h>
7#include <sys/vfs.h> 8#include <sys/vfs.h>
9#include <sys/types.h>
10#include <sys/stat.h>
8#include <sys/mount.h> 11#include <sys/mount.h>
9#include <linux/kernel.h> 12#include <linux/kernel.h>
10 13
11#include "debugfs.h" 14#include "debugfs.h"
12 15
13char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; 16#ifndef DEBUGFS_DEFAULT_PATH
17#define DEBUGFS_DEFAULT_PATH "/sys/kernel/debug"
18#endif
19
20char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
14 21
15static const char * const debugfs_known_mountpoints[] = { 22static const char * const debugfs_known_mountpoints[] = {
16 "/sys/kernel/debug", 23 DEBUGFS_DEFAULT_PATH,
17 "/debug", 24 "/debug",
18 0, 25 0,
19}; 26};
20 27
21static bool debugfs_found; 28static bool debugfs_found;
22 29
30bool debugfs_configured(void)
31{
32 return debugfs_find_mountpoint() != NULL;
33}
34
23/* find the path to the mounted debugfs */ 35/* find the path to the mounted debugfs */
24const char *debugfs_find_mountpoint(void) 36const char *debugfs_find_mountpoint(void)
25{ 37{
26 const char * const *ptr; 38 const char *ret;
27 char type[100];
28 FILE *fp;
29 39
30 if (debugfs_found) 40 if (debugfs_found)
31 return (const char *)debugfs_mountpoint; 41 return (const char *)debugfs_mountpoint;
32 42
33 ptr = debugfs_known_mountpoints; 43 ret = find_mountpoint("debugfs", (long) DEBUGFS_MAGIC,
34 while (*ptr) { 44 debugfs_mountpoint, PATH_MAX + 1,
35 if (debugfs_valid_mountpoint(*ptr) == 0) { 45 debugfs_known_mountpoints);
36 debugfs_found = true; 46 if (ret)
37 strcpy(debugfs_mountpoint, *ptr); 47 debugfs_found = true;
38 return debugfs_mountpoint;
39 }
40 ptr++;
41 }
42
43 /* give up and parse /proc/mounts */
44 fp = fopen("/proc/mounts", "r");
45 if (fp == NULL)
46 return NULL;
47
48 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
49 debugfs_mountpoint, type) == 2) {
50 if (strcmp(type, "debugfs") == 0)
51 break;
52 }
53 fclose(fp);
54 48
55 if (strcmp(type, "debugfs") != 0) 49 return ret;
56 return NULL;
57
58 debugfs_found = true;
59
60 return debugfs_mountpoint;
61}
62
63/* verify that a mountpoint is actually a debugfs instance */
64
65int debugfs_valid_mountpoint(const char *debugfs)
66{
67 struct statfs st_fs;
68
69 if (statfs(debugfs, &st_fs) < 0)
70 return -ENOENT;
71 else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
72 return -ENOENT;
73
74 return 0;
75} 50}
76 51
77/* mount the debugfs somewhere if it's not mounted */ 52/* mount the debugfs somewhere if it's not mounted */
@@ -87,7 +62,7 @@ char *debugfs_mount(const char *mountpoint)
87 mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT); 62 mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
88 /* if no environment variable, use default */ 63 /* if no environment variable, use default */
89 if (mountpoint == NULL) 64 if (mountpoint == NULL)
90 mountpoint = "/sys/kernel/debug"; 65 mountpoint = DEBUGFS_DEFAULT_PATH;
91 } 66 }
92 67
93 if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) 68 if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
diff --git a/tools/lib/api/fs/debugfs.h b/tools/lib/api/fs/debugfs.h
index 0739881a9897..455023698d2b 100644
--- a/tools/lib/api/fs/debugfs.h
+++ b/tools/lib/api/fs/debugfs.h
@@ -1,16 +1,7 @@
1#ifndef __API_DEBUGFS_H__ 1#ifndef __API_DEBUGFS_H__
2#define __API_DEBUGFS_H__ 2#define __API_DEBUGFS_H__
3 3
4#define _STR(x) #x 4#include "findfs.h"
5#define STR(x) _STR(x)
6
7/*
8 * On most systems <limits.h> would have given us this, but not on some systems
9 * (e.g. GNU/Hurd).
10 */
11#ifndef PATH_MAX
12#define PATH_MAX 4096
13#endif
14 5
15#ifndef DEBUGFS_MAGIC 6#ifndef DEBUGFS_MAGIC
16#define DEBUGFS_MAGIC 0x64626720 7#define DEBUGFS_MAGIC 0x64626720
@@ -20,8 +11,8 @@
20#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" 11#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
21#endif 12#endif
22 13
14bool debugfs_configured(void);
23const char *debugfs_find_mountpoint(void); 15const char *debugfs_find_mountpoint(void);
24int debugfs_valid_mountpoint(const char *debugfs);
25char *debugfs_mount(const char *mountpoint); 16char *debugfs_mount(const char *mountpoint);
26 17
27extern char debugfs_mountpoint[]; 18extern char debugfs_mountpoint[];
diff --git a/tools/lib/api/fs/findfs.c b/tools/lib/api/fs/findfs.c
new file mode 100644
index 000000000000..49946cb6d7af
--- /dev/null
+++ b/tools/lib/api/fs/findfs.c
@@ -0,0 +1,63 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <stdbool.h>
6#include <sys/vfs.h>
7
8#include "findfs.h"
9
10/* verify that a mountpoint is actually the type we want */
11
12int valid_mountpoint(const char *mount, long magic)
13{
14 struct statfs st_fs;
15
16 if (statfs(mount, &st_fs) < 0)
17 return -ENOENT;
18 else if ((long)st_fs.f_type != magic)
19 return -ENOENT;
20
21 return 0;
22}
23
24/* find the path to a mounted file system */
25const char *find_mountpoint(const char *fstype, long magic,
26 char *mountpoint, int len,
27 const char * const *known_mountpoints)
28{
29 const char * const *ptr;
30 char format[128];
31 char type[100];
32 FILE *fp;
33
34 if (known_mountpoints) {
35 ptr = known_mountpoints;
36 while (*ptr) {
37 if (valid_mountpoint(*ptr, magic) == 0) {
38 strncpy(mountpoint, *ptr, len - 1);
39 mountpoint[len-1] = 0;
40 return mountpoint;
41 }
42 ptr++;
43 }
44 }
45
46 /* give up and parse /proc/mounts */
47 fp = fopen("/proc/mounts", "r");
48 if (fp == NULL)
49 return NULL;
50
51 snprintf(format, 128, "%%*s %%%ds %%99s %%*s %%*d %%*d\n", len);
52
53 while (fscanf(fp, format, mountpoint, type) == 2) {
54 if (strcmp(type, fstype) == 0)
55 break;
56 }
57 fclose(fp);
58
59 if (strcmp(type, fstype) != 0)
60 return NULL;
61
62 return mountpoint;
63}
diff --git a/tools/lib/api/fs/findfs.h b/tools/lib/api/fs/findfs.h
new file mode 100644
index 000000000000..b6f5d05acc42
--- /dev/null
+++ b/tools/lib/api/fs/findfs.h
@@ -0,0 +1,23 @@
1#ifndef __API_FINDFS_H__
2#define __API_FINDFS_H__
3
4#include <stdbool.h>
5
6#define _STR(x) #x
7#define STR(x) _STR(x)
8
9/*
10 * On most systems <limits.h> would have given us this, but not on some systems
11 * (e.g. GNU/Hurd).
12 */
13#ifndef PATH_MAX
14#define PATH_MAX 4096
15#endif
16
17const char *find_mountpoint(const char *fstype, long magic,
18 char *mountpoint, int len,
19 const char * const *known_mountpoints);
20
21int valid_mountpoint(const char *mount, long magic);
22
23#endif /* __API_FINDFS_H__ */
diff --git a/tools/lib/api/fs/tracefs.c b/tools/lib/api/fs/tracefs.c
new file mode 100644
index 000000000000..e4aa9688b71e
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.c
@@ -0,0 +1,78 @@
1#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include <stdbool.h>
7#include <sys/vfs.h>
8#include <sys/types.h>
9#include <sys/stat.h>
10#include <sys/mount.h>
11#include <linux/kernel.h>
12
13#include "tracefs.h"
14
15#ifndef TRACEFS_DEFAULT_PATH
16#define TRACEFS_DEFAULT_PATH "/sys/kernel/tracing"
17#endif
18
19char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
20
21static const char * const tracefs_known_mountpoints[] = {
22 TRACEFS_DEFAULT_PATH,
23 "/sys/kernel/debug/tracing",
24 "/tracing",
25 "/trace",
26 0,
27};
28
29static bool tracefs_found;
30
31bool tracefs_configured(void)
32{
33 return tracefs_find_mountpoint() != NULL;
34}
35
36/* find the path to the mounted tracefs */
37const char *tracefs_find_mountpoint(void)
38{
39 const char *ret;
40
41 if (tracefs_found)
42 return (const char *)tracefs_mountpoint;
43
44 ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
45 tracefs_mountpoint, PATH_MAX + 1,
46 tracefs_known_mountpoints);
47
48 if (ret)
49 tracefs_found = true;
50
51 return ret;
52}
53
54/* mount the tracefs somewhere if it's not mounted */
55char *tracefs_mount(const char *mountpoint)
56{
57 /* see if it's already mounted */
58 if (tracefs_find_mountpoint())
59 goto out;
60
61 /* if not mounted and no argument */
62 if (mountpoint == NULL) {
63 /* see if environment variable set */
64 mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
65 /* if no environment variable, use default */
66 if (mountpoint == NULL)
67 mountpoint = TRACEFS_DEFAULT_PATH;
68 }
69
70 if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
71 return NULL;
72
73 /* save the mountpoint */
74 tracefs_found = true;
75 strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
76out:
77 return tracefs_mountpoint;
78}
diff --git a/tools/lib/api/fs/tracefs.h b/tools/lib/api/fs/tracefs.h
new file mode 100644
index 000000000000..da780ac49acb
--- /dev/null
+++ b/tools/lib/api/fs/tracefs.h
@@ -0,0 +1,21 @@
1#ifndef __API_TRACEFS_H__
2#define __API_TRACEFS_H__
3
4#include "findfs.h"
5
6#ifndef TRACEFS_MAGIC
7#define TRACEFS_MAGIC 0x74726163
8#endif
9
10#ifndef PERF_TRACEFS_ENVIRONMENT
11#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
12#endif
13
14bool tracefs_configured(void);
15const char *tracefs_find_mountpoint(void);
16int tracefs_valid_mountpoint(const char *debugfs);
17char *tracefs_mount(const char *mountpoint);
18
19extern char tracefs_mountpoint[];
20
21#endif /* __API_DEBUGFS_H__ */
diff --git a/tools/lib/lockdep/Build b/tools/lib/lockdep/Build
new file mode 100644
index 000000000000..6f667355b068
--- /dev/null
+++ b/tools/lib/lockdep/Build
@@ -0,0 +1 @@
liblockdep-y += common.o lockdep.o preload.o rbtree.o
diff --git a/tools/lib/lockdep/Makefile b/tools/lib/lockdep/Makefile
index 52f9279c6c13..8c3340a4b9f8 100644
--- a/tools/lib/lockdep/Makefile
+++ b/tools/lib/lockdep/Makefile
@@ -35,6 +35,10 @@ bindir = $(prefix)/$(bindir_relative)
35 35
36export DESTDIR DESTDIR_SQ INSTALL 36export DESTDIR DESTDIR_SQ INSTALL
37 37
38MAKEFLAGS += --no-print-directory
39
40include ../../scripts/Makefile.include
41
38# copy a bit from Linux kbuild 42# copy a bit from Linux kbuild
39 43
40ifeq ("$(origin V)", "command line") 44ifeq ("$(origin V)", "command line")
@@ -44,56 +48,21 @@ ifndef VERBOSE
44 VERBOSE = 0 48 VERBOSE = 0
45endif 49endif
46 50
47ifeq ("$(origin O)", "command line") 51ifeq ($(srctree),)
48 BUILD_OUTPUT := $(O) 52srctree := $(patsubst %/,%,$(dir $(shell pwd)))
53srctree := $(patsubst %/,%,$(dir $(srctree)))
54srctree := $(patsubst %/,%,$(dir $(srctree)))
55#$(info Determined 'srctree' to be $(srctree))
49endif 56endif
50 57
51ifeq ($(BUILD_SRC),)
52ifneq ($(BUILD_OUTPUT),)
53
54define build_output
55 $(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) \
56 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
57endef
58
59saved-output := $(BUILD_OUTPUT)
60BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
61$(if $(BUILD_OUTPUT),, \
62 $(error output directory "$(saved-output)" does not exist))
63
64all: sub-make
65
66gui: force
67 $(call build_output, all_cmd)
68
69$(filter-out gui,$(MAKECMDGOALS)): sub-make
70
71sub-make: force
72 $(call build_output, $(MAKECMDGOALS))
73
74
75# Leave processing to above invocation of make
76skip-makefile := 1
77
78endif # BUILD_OUTPUT
79endif # BUILD_SRC
80
81# We process the rest of the Makefile if this is the final invocation of make
82ifeq ($(skip-makefile),)
83
84srctree := $(realpath $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR)))
85objtree := $(realpath $(CURDIR))
86src := $(srctree)
87obj := $(objtree)
88
89export prefix libdir bindir src obj
90
91# Shell quotes 58# Shell quotes
92libdir_SQ = $(subst ','\'',$(libdir)) 59libdir_SQ = $(subst ','\'',$(libdir))
93bindir_SQ = $(subst ','\'',$(bindir)) 60bindir_SQ = $(subst ','\'',$(bindir))
94 61
95LIB_FILE = liblockdep.a liblockdep.so.$(LIBLOCKDEP_VERSION) 62LIB_IN := $(OUTPUT)liblockdep-in.o
63
96BIN_FILE = lockdep 64BIN_FILE = lockdep
65LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
97 66
98CONFIG_INCLUDES = 67CONFIG_INCLUDES =
99CONFIG_LIBS = 68CONFIG_LIBS =
@@ -108,33 +77,23 @@ INCLUDES = -I. -I/usr/local/include -I./uinclude -I./include -I../../include $(C
108 77
109# Set compile option CFLAGS if not set elsewhere 78# Set compile option CFLAGS if not set elsewhere
110CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g 79CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
80CFLAGS += -fPIC
111 81
112override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 82override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
113 83
114ifeq ($(VERBOSE),1) 84ifeq ($(VERBOSE),1)
115 Q = 85 Q =
116 print_compile =
117 print_app_build =
118 print_fpic_compile =
119 print_shared_lib_compile = 86 print_shared_lib_compile =
120 print_install = 87 print_install =
121else 88else
122 Q = @ 89 Q = @
123 print_compile = echo ' CC '$(OBJ); 90 print_shared_lib_compile = echo ' LD '$(OBJ);
124 print_app_build = echo ' BUILD '$(OBJ); 91 print_static_lib_build = echo ' LD '$(OBJ);
125 print_fpic_compile = echo ' CC FPIC '$(OBJ); 92 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
126 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
127 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
128 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
129endif 93endif
130 94
131do_fpic_compile = \ 95export srctree OUTPUT CC LD CFLAGS V
132 ($(print_fpic_compile) \ 96build := -f $(srctree)/tools/build/Makefile.build dir=. obj
133 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
134
135do_app_build = \
136 ($(print_app_build) \
137 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
138 97
139do_compile_shared_library = \ 98do_compile_shared_library = \
140 ($(print_shared_lib_compile) \ 99 ($(print_shared_lib_compile) \
@@ -144,22 +103,6 @@ do_build_static_lib = \
144 ($(print_static_lib_build) \ 103 ($(print_static_lib_build) \
145 $(RM) $@; $(AR) rcs $@ $^) 104 $(RM) $@; $(AR) rcs $@ $^)
146 105
147
148define do_compile
149 $(print_compile) \
150 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
151endef
152
153$(obj)/%.o: $(src)/%.c
154 $(Q)$(call do_compile)
155
156%.o: $(src)/%.c
157 $(Q)$(call do_compile)
158
159PEVENT_LIB_OBJS = common.o lockdep.o preload.o rbtree.o
160
161ALL_OBJS = $(PEVENT_LIB_OBJS)
162
163CMD_TARGETS = $(LIB_FILE) 106CMD_TARGETS = $(LIB_FILE)
164 107
165TARGETS = $(CMD_TARGETS) 108TARGETS = $(CMD_TARGETS)
@@ -169,42 +112,15 @@ all: all_cmd
169 112
170all_cmd: $(CMD_TARGETS) 113all_cmd: $(CMD_TARGETS)
171 114
172liblockdep.so.$(LIBLOCKDEP_VERSION): $(PEVENT_LIB_OBJS) 115$(LIB_IN): force
116 $(Q)$(MAKE) $(build)=liblockdep
117
118liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
173 $(Q)$(do_compile_shared_library) 119 $(Q)$(do_compile_shared_library)
174 120
175liblockdep.a: $(PEVENT_LIB_OBJS) 121liblockdep.a: $(LIB_IN)
176 $(Q)$(do_build_static_lib) 122 $(Q)$(do_build_static_lib)
177 123
178$(PEVENT_LIB_OBJS): %.o: $(src)/%.c
179 $(Q)$(do_fpic_compile)
180
181## make deps
182
183all_objs := $(sort $(ALL_OBJS))
184all_deps := $(all_objs:%.o=.%.d)
185
186# let .d file also depends on the source and header files
187define check_deps
188 @set -e; $(RM) $@; \
189 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
190 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
191 $(RM) $@.$$$$
192endef
193
194$(all_deps): .%.d: $(src)/%.c
195 $(Q)$(call check_deps)
196
197$(all_objs) : %.o : .%.d
198
199dep_includes := $(wildcard $(all_deps))
200
201ifneq ($(dep_includes),)
202 include $(dep_includes)
203endif
204
205### Detect environment changes
206TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
207
208tags: force 124tags: force
209 $(RM) tags 125 $(RM) tags
210 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 126 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
@@ -233,8 +149,6 @@ clean:
233 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d 149 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d
234 $(RM) tags TAGS 150 $(RM) tags TAGS
235 151
236endif # skip-makefile
237
238PHONY += force 152PHONY += force
239force: 153force:
240 154
diff --git a/tools/lib/traceevent/Build b/tools/lib/traceevent/Build
new file mode 100644
index 000000000000..c681d0575d16
--- /dev/null
+++ b/tools/lib/traceevent/Build
@@ -0,0 +1,17 @@
1libtraceevent-y += event-parse.o
2libtraceevent-y += event-plugin.o
3libtraceevent-y += trace-seq.o
4libtraceevent-y += parse-filter.o
5libtraceevent-y += parse-utils.o
6libtraceevent-y += kbuffer-parse.o
7
8plugin_jbd2-y += plugin_jbd2.o
9plugin_hrtimer-y += plugin_hrtimer.o
10plugin_kmem-y += plugin_kmem.o
11plugin_kvm-y += plugin_kvm.o
12plugin_mac80211-y += plugin_mac80211.o
13plugin_sched_switch-y += plugin_sched_switch.o
14plugin_function-y += plugin_function.o
15plugin_xen-y += plugin_xen.o
16plugin_scsi-y += plugin_scsi.o
17plugin_cfg80211-y += plugin_cfg80211.o
diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
index 005c9cc06935..d410da335e3d 100644
--- a/tools/lib/traceevent/Makefile
+++ b/tools/lib/traceevent/Makefile
@@ -67,7 +67,7 @@ PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
67PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' 67PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68endif 68endif
69 69
70include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include 70include ../../scripts/Makefile.include
71 71
72# copy a bit from Linux kbuild 72# copy a bit from Linux kbuild
73 73
@@ -78,40 +78,13 @@ ifndef VERBOSE
78 VERBOSE = 0 78 VERBOSE = 0
79endif 79endif
80 80
81ifeq ("$(origin O)", "command line") 81ifeq ($(srctree),)
82 BUILD_OUTPUT := $(O) 82srctree := $(patsubst %/,%,$(dir $(shell pwd)))
83srctree := $(patsubst %/,%,$(dir $(srctree)))
84srctree := $(patsubst %/,%,$(dir $(srctree)))
85#$(info Determined 'srctree' to be $(srctree))
83endif 86endif
84 87
85ifeq ($(BUILD_SRC),)
86ifneq ($(OUTPUT),)
87
88define build_output
89 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(OUTPUT) \
90 BUILD_SRC=$(CURDIR)/ -f $(CURDIR)/Makefile $1
91endef
92
93all: sub-make
94
95$(MAKECMDGOALS): sub-make
96
97sub-make: force
98 $(call build_output, $(MAKECMDGOALS))
99
100
101# Leave processing to above invocation of make
102skip-makefile := 1
103
104endif # OUTPUT
105endif # BUILD_SRC
106
107# We process the rest of the Makefile if this is the final invocation of make
108ifeq ($(skip-makefile),)
109
110srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
111objtree := $(CURDIR)
112src := $(srctree)
113obj := $(objtree)
114
115export prefix bindir src obj 88export prefix bindir src obj
116 89
117# Shell quotes 90# Shell quotes
@@ -132,16 +105,19 @@ EXTRAVERSION = $(EP_EXTRAVERSION)
132OBJ = $@ 105OBJ = $@
133N = 106N =
134 107
135export Q VERBOSE
136
137EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) 108EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
138 109
139INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES) 110INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
140 111
141# Set compile option CFLAGS if not set elsewhere 112# Set compile option CFLAGS
142CFLAGS ?= -g -Wall 113ifdef EXTRA_CFLAGS
114 CFLAGS := $(EXTRA_CFLAGS)
115else
116 CFLAGS := -g -Wall
117endif
143 118
144# Append required CFLAGS 119# Append required CFLAGS
120override CFLAGS += -fPIC
145override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 121override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
146override CFLAGS += $(udis86-flags) -D_GNU_SOURCE 122override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
147 123
@@ -151,74 +127,58 @@ else
151 Q = @ 127 Q = @
152endif 128endif
153 129
154do_compile_shared_library = \ 130# Disable command line variables (CFLAGS) overide from top
155 ($(print_shared_lib_compile) \ 131# level Makefile (perf), otherwise build Makefile will get
156 $(CC) --shared $^ -o $@) 132# the same command line setup.
157 133MAKEOVERRIDES=
158do_plugin_build = \
159 ($(print_plugin_build) \
160 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
161
162do_build_static_lib = \
163 ($(print_static_lib_build) \
164 $(RM) $@; $(AR) rcs $@ $^)
165
166
167do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
168 134
169$(obj)/%.o: $(src)/%.c 135export srctree OUTPUT CC LD CFLAGS V
170 $(call do_compile) 136build := -f $(srctree)/tools/build/Makefile.build dir=. obj
171 137
172%.o: $(src)/%.c 138PLUGINS = plugin_jbd2.so
173 $(call do_compile) 139PLUGINS += plugin_hrtimer.so
140PLUGINS += plugin_kmem.so
141PLUGINS += plugin_kvm.so
142PLUGINS += plugin_mac80211.so
143PLUGINS += plugin_sched_switch.so
144PLUGINS += plugin_function.so
145PLUGINS += plugin_xen.so
146PLUGINS += plugin_scsi.so
147PLUGINS += plugin_cfg80211.so
174 148
175PEVENT_LIB_OBJS = event-parse.o 149PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
176PEVENT_LIB_OBJS += event-plugin.o 150PLUGINS_IN := $(PLUGINS:.so=-in.o)
177PEVENT_LIB_OBJS += trace-seq.o
178PEVENT_LIB_OBJS += parse-filter.o
179PEVENT_LIB_OBJS += parse-utils.o
180PEVENT_LIB_OBJS += kbuffer-parse.o
181 151
182PLUGIN_OBJS = plugin_jbd2.o 152TE_IN := $(OUTPUT)libtraceevent-in.o
183PLUGIN_OBJS += plugin_hrtimer.o 153LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
184PLUGIN_OBJS += plugin_kmem.o
185PLUGIN_OBJS += plugin_kvm.o
186PLUGIN_OBJS += plugin_mac80211.o
187PLUGIN_OBJS += plugin_sched_switch.o
188PLUGIN_OBJS += plugin_function.o
189PLUGIN_OBJS += plugin_xen.o
190PLUGIN_OBJS += plugin_scsi.o
191PLUGIN_OBJS += plugin_cfg80211.o
192
193PLUGINS := $(PLUGIN_OBJS:.o=.so)
194
195ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
196 154
197CMD_TARGETS = $(LIB_FILE) $(PLUGINS) 155CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
198 156
199TARGETS = $(CMD_TARGETS) 157TARGETS = $(CMD_TARGETS)
200 158
201
202all: all_cmd 159all: all_cmd
203 160
204all_cmd: $(CMD_TARGETS) 161all_cmd: $(CMD_TARGETS)
205 162
206libtraceevent.so: $(PEVENT_LIB_OBJS) 163$(TE_IN): force
164 $(Q)$(MAKE) $(build)=libtraceevent
165
166$(OUTPUT)libtraceevent.so: $(TE_IN)
207 $(QUIET_LINK)$(CC) --shared $^ -o $@ 167 $(QUIET_LINK)$(CC) --shared $^ -o $@
208 168
209libtraceevent.a: $(PEVENT_LIB_OBJS) 169$(OUTPUT)libtraceevent.a: $(TE_IN)
210 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ 170 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
211 171
212plugins: $(PLUGINS) 172plugins: $(PLUGINS)
213 173
214$(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS 174__plugin_obj = $(notdir $@)
215 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@ 175 plugin_obj = $(__plugin_obj:-in.o=)
216 176
217$(PLUGIN_OBJS): %.o : $(src)/%.c 177$(PLUGINS_IN): force
218 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) -fPIC -o $@ $< 178 $(Q)$(MAKE) $(build)=$(plugin_obj)
219 179
220$(PLUGINS): %.so: %.o 180$(OUTPUT)%.so: $(OUTPUT)%-in.o
221 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $< 181 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
222 182
223define make_version.h 183define make_version.h
224 (echo '/* This file is automatically generated. Do not modify. */'; \ 184 (echo '/* This file is automatically generated. Do not modify. */'; \
@@ -255,40 +215,6 @@ define update_dir
255 fi); 215 fi);
256endef 216endef
257 217
258## make deps
259
260all_objs := $(sort $(ALL_OBJS))
261all_deps := $(all_objs:%.o=.%.d)
262
263# let .d file also depends on the source and header files
264define check_deps
265 @set -e; $(RM) $@; \
266 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
267 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
268 $(RM) $@.$$$$
269endef
270
271$(all_deps): .%.d: $(src)/%.c
272 $(Q)$(call check_deps)
273
274$(all_objs) : %.o : .%.d
275
276dep_includes := $(wildcard $(all_deps))
277
278ifneq ($(dep_includes),)
279 include $(dep_includes)
280endif
281
282### Detect environment changes
283TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
284
285TRACEEVENT-CFLAGS: force
286 @FLAGS='$(TRACK_CFLAGS)'; \
287 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
288 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
289 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
290 fi
291
292tags: force 218tags: force
293 $(RM) tags 219 $(RM) tags
294 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 220 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
@@ -327,14 +253,9 @@ clean:
327 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \ 253 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
328 $(RM) TRACEEVENT-CFLAGS tags TAGS 254 $(RM) TRACEEVENT-CFLAGS tags TAGS
329 255
330endif # skip-makefile
331
332PHONY += force plugins 256PHONY += force plugins
333force: 257force:
334 258
335plugins:
336 @echo > /dev/null
337
338# Declare the contents of the .PHONY variable as phony. We keep that 259# Declare the contents of the .PHONY variable as phony. We keep that
339# information in a variable so we can use it in if_changed and friends. 260# information in a variable so we can use it in if_changed and friends.
340.PHONY: $(PHONY) 261.PHONY: $(PHONY)
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 7a3873ff9a4f..5b4efc062320 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -22,6 +22,7 @@
22 22
23#include <stdbool.h> 23#include <stdbool.h>
24#include <stdarg.h> 24#include <stdarg.h>
25#include <stdio.h>
25#include <regex.h> 26#include <regex.h>
26#include <string.h> 27#include <string.h>
27 28
@@ -91,6 +92,7 @@ extern int trace_seq_putc(struct trace_seq *s, unsigned char c);
91 92
92extern void trace_seq_terminate(struct trace_seq *s); 93extern void trace_seq_terminate(struct trace_seq *s);
93 94
95extern int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp);
94extern int trace_seq_do_printf(struct trace_seq *s); 96extern int trace_seq_do_printf(struct trace_seq *s);
95 97
96 98
diff --git a/tools/lib/traceevent/trace-seq.c b/tools/lib/traceevent/trace-seq.c
index ec3bd16a5488..292dc9f1d233 100644
--- a/tools/lib/traceevent/trace-seq.c
+++ b/tools/lib/traceevent/trace-seq.c
@@ -231,19 +231,24 @@ void trace_seq_terminate(struct trace_seq *s)
231 s->buffer[s->len] = 0; 231 s->buffer[s->len] = 0;
232} 232}
233 233
234int trace_seq_do_printf(struct trace_seq *s) 234int trace_seq_do_fprintf(struct trace_seq *s, FILE *fp)
235{ 235{
236 TRACE_SEQ_CHECK(s); 236 TRACE_SEQ_CHECK(s);
237 237
238 switch (s->state) { 238 switch (s->state) {
239 case TRACE_SEQ__GOOD: 239 case TRACE_SEQ__GOOD:
240 return printf("%.*s", s->len, s->buffer); 240 return fprintf(fp, "%.*s", s->len, s->buffer);
241 case TRACE_SEQ__BUFFER_POISONED: 241 case TRACE_SEQ__BUFFER_POISONED:
242 puts("Usage of trace_seq after it was destroyed"); 242 fprintf(fp, "%s\n", "Usage of trace_seq after it was destroyed");
243 break; 243 break;
244 case TRACE_SEQ__MEM_ALLOC_FAILED: 244 case TRACE_SEQ__MEM_ALLOC_FAILED:
245 puts("Can't allocate trace_seq buffer memory"); 245 fprintf(fp, "%s\n", "Can't allocate trace_seq buffer memory");
246 break; 246 break;
247 } 247 }
248 return -1; 248 return -1;
249} 249}
250
251int trace_seq_do_printf(struct trace_seq *s)
252{
253 return trace_seq_do_fprintf(s, stdout);
254}
diff --git a/tools/perf/Build b/tools/perf/Build
new file mode 100644
index 000000000000..976e03849f6d
--- /dev/null
+++ b/tools/perf/Build
@@ -0,0 +1,43 @@
1perf-y += builtin-bench.o
2perf-y += builtin-annotate.o
3perf-y += builtin-diff.o
4perf-y += builtin-evlist.o
5perf-y += builtin-help.o
6perf-y += builtin-sched.o
7perf-y += builtin-buildid-list.o
8perf-y += builtin-buildid-cache.o
9perf-y += builtin-list.o
10perf-y += builtin-record.o
11perf-y += builtin-report.o
12perf-y += builtin-stat.o
13perf-y += builtin-timechart.o
14perf-y += builtin-top.o
15perf-y += builtin-script.o
16perf-y += builtin-kmem.o
17perf-y += builtin-lock.o
18perf-y += builtin-kvm.o
19perf-y += builtin-inject.o
20perf-y += builtin-mem.o
21
22perf-$(CONFIG_AUDIT) += builtin-trace.o
23perf-$(CONFIG_LIBELF) += builtin-probe.o
24
25perf-y += bench/
26perf-y += tests/
27
28perf-y += perf.o
29
30paths += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))"
31paths += -DPERF_INFO_PATH="BUILD_STR($(infodir_SQ))"
32paths += -DPERF_MAN_PATH="BUILD_STR($(mandir_SQ))"
33
34CFLAGS_builtin-help.o += $(paths)
35CFLAGS_builtin-timechart.o += $(paths)
36CFLAGS_perf.o += -DPERF_HTML_PATH="BUILD_STR($(htmldir_SQ))" -include $(OUTPUT)PERF-VERSION-FILE
37
38libperf-y += util/
39libperf-y += arch/
40libperf-y += ui/
41libperf-y += scripts/
42
43gtk-y += ui/gtk/
diff --git a/tools/perf/Documentation/Build.txt b/tools/perf/Documentation/Build.txt
new file mode 100644
index 000000000000..f6fc6507ba55
--- /dev/null
+++ b/tools/perf/Documentation/Build.txt
@@ -0,0 +1,49 @@
1
21) perf build
3=============
4The perf build process consists of several separated building blocks,
5which are linked together to form the perf binary:
6 - libperf library (static)
7 - perf builtin commands
8 - traceevent library (static)
9 - GTK ui library
10
11Several makefiles govern the perf build:
12
13 - Makefile
14 top level Makefile working as a wrapper that calls the main
15 Makefile.perf with a -j option to do parallel builds.
16
17 - Makefile.perf
18 main makefile that triggers build of all perf objects including
19 installation and documentation processing.
20
21 - tools/build/Makefile.build
22 main makefile of the build framework
23
24 - tools/build/Build.include
25 build framework generic definitions
26
27 - Build makefiles
28 makefiles that defines build objects
29
30Please refer to tools/build/Documentation/Build.txt for more
31information about build framework.
32
33
342) perf build
35=============
36The Makefile.perf triggers the build framework for build objects:
37 perf, libperf, gtk
38
39resulting in following objects:
40 $ ls *-in.o
41 gtk-in.o libperf-in.o perf-in.o
42
43Those objects are then used in final linking:
44 libperf-gtk.so <- gtk-in.o libperf-in.o
45 perf <- perf-in.o libperf-in.o
46
47
48NOTE this description is omitting other libraries involved, only
49 focusing on build framework outcomes
diff --git a/tools/perf/Documentation/perf-probe.txt b/tools/perf/Documentation/perf-probe.txt
index aaa869be3dc1..239609c09f83 100644
--- a/tools/perf/Documentation/perf-probe.txt
+++ b/tools/perf/Documentation/perf-probe.txt
@@ -47,6 +47,12 @@ OPTIONS
47-v:: 47-v::
48--verbose:: 48--verbose::
49 Be more verbose (show parsed arguments, etc). 49 Be more verbose (show parsed arguments, etc).
50 Can not use with -q.
51
52-q::
53--quiet::
54 Be quiet (do not show any messages including errors).
55 Can not use with -v.
50 56
51-a:: 57-a::
52--add=:: 58--add=::
@@ -96,7 +102,7 @@ OPTIONS
96 Dry run. With this option, --add and --del doesn't execute actual 102 Dry run. With this option, --add and --del doesn't execute actual
97 adding and removal operations. 103 adding and removal operations.
98 104
99--max-probes:: 105--max-probes=NUM::
100 Set the maximum number of probe points for an event. Default is 128. 106 Set the maximum number of probe points for an event. Default is 128.
101 107
102-x:: 108-x::
@@ -104,8 +110,13 @@ OPTIONS
104 Specify path to the executable or shared library file for user 110 Specify path to the executable or shared library file for user
105 space tracing. Can also be used with --funcs option. 111 space tracing. Can also be used with --funcs option.
106 112
113--demangle::
114 Demangle application symbols. --no-demangle is also available
115 for disabling demangling.
116
107--demangle-kernel:: 117--demangle-kernel::
108 Demangle kernel symbols. 118 Demangle kernel symbols. --no-demangle-kernel is also available
119 for disabling kernel demangling.
109 120
110In absence of -m/-x options, perf probe checks if the first argument after 121In absence of -m/-x options, perf probe checks if the first argument after
111the options is an absolute path name. If its an absolute path, perf probe 122the options is an absolute path name. If its an absolute path, perf probe
@@ -137,6 +148,7 @@ Each probe argument follows below syntax.
137 [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE] 148 [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE]
138 149
139'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.) 150'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), local array with fixed index (e.g. array[1], var->array[0], var->pointer[2]), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
151'$vars' special argument is also available for NAME, it is expanded to the local variables which can access at given probe point.
140'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type. 152'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo. You can specify 'string' type only for the local variable or structure member which is an array of or a pointer to 'char' or 'unsigned char' type.
141 153
142On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid. 154On x86 systems %REG is always the short form of the register: for example %AX. %RAX or %EAX is not valid.
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index fbbfdc39271d..11ccbb22ea2b 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -1,5 +1,6 @@
1tools/perf 1tools/perf
2tools/scripts 2tools/scripts
3tools/build
3tools/lib/traceevent 4tools/lib/traceevent
4tools/lib/api 5tools/lib/api
5tools/lib/symbol/kallsyms.c 6tools/lib/symbol/kallsyms.c
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index aa6a50447c32..efc5158738f4 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -82,13 +82,29 @@ endif
82 82
83ifneq ($(OUTPUT),) 83ifneq ($(OUTPUT),)
84#$(info Determined 'OUTPUT' to be $(OUTPUT)) 84#$(info Determined 'OUTPUT' to be $(OUTPUT))
85# Adding $(OUTPUT) as a directory to look for source files,
86# because use generated output files as sources dependency
87# for flex/bison parsers.
88VPATH += $(OUTPUT)
89export VPATH
85endif 90endif
86 91
92ifeq ($(V),1)
93 Q =
94else
95 Q = @
96endif
97
98# Do not use make's built-in rules
99# (this improves performance and avoids hard-to-debug behaviour);
100MAKEFLAGS += -r
101
87$(OUTPUT)PERF-VERSION-FILE: ../../.git/HEAD 102$(OUTPUT)PERF-VERSION-FILE: ../../.git/HEAD
88 @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) 103 $(Q)$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
89 @touch $(OUTPUT)PERF-VERSION-FILE 104 $(Q)touch $(OUTPUT)PERF-VERSION-FILE
90 105
91CC = $(CROSS_COMPILE)gcc 106CC = $(CROSS_COMPILE)gcc
107LD = $(CROSS_COMPILE)ld
92AR = $(CROSS_COMPILE)ar 108AR = $(CROSS_COMPILE)ar
93PKG_CONFIG = $(CROSS_COMPILE)pkg-config 109PKG_CONFIG = $(CROSS_COMPILE)pkg-config
94 110
@@ -127,10 +143,6 @@ export prefix bindir sharedir sysconfdir DESTDIR
127SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ 143SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
128 144
129# Guard against environment variables 145# Guard against environment variables
130BUILTIN_OBJS =
131LIB_H =
132LIB_OBJS =
133GTK_OBJS =
134PYRF_OBJS = 146PYRF_OBJS =
135SCRIPT_SH = 147SCRIPT_SH =
136 148
@@ -155,8 +167,8 @@ endif
155LIBTRACEEVENT = $(TE_PATH)libtraceevent.a 167LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
156export LIBTRACEEVENT 168export LIBTRACEEVENT
157 169
158LIBAPIKFS = $(LIB_PATH)libapikfs.a 170LIBAPI = $(LIB_PATH)libapi.a
159export LIBAPIKFS 171export LIBAPI
160 172
161# python extension build directories 173# python extension build directories
162PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ 174PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
@@ -167,7 +179,7 @@ export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP
167python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so 179python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf.so
168 180
169PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources) 181PYTHON_EXT_SRCS := $(shell grep -v ^\# util/python-ext-sources)
170PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) $(LIBAPIKFS) 182PYTHON_EXT_DEPS := util/python-ext-sources util/setup.py $(LIBTRACEEVENT) $(LIBAPI)
171 183
172$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS) 184$(OUTPUT)python/perf.so: $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
173 $(QUIET_GEN)CFLAGS='$(CFLAGS)' $(PYTHON_WORD) util/setup.py \ 185 $(QUIET_GEN)CFLAGS='$(CFLAGS)' $(PYTHON_WORD) util/setup.py \
@@ -206,297 +218,9 @@ endif
206 218
207export PERL_PATH 219export PERL_PATH
208 220
209$(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
210 $(QUIET_FLEX)$(FLEX) -o $@ --header-file=$(OUTPUT)util/parse-events-flex.h $(PARSER_DEBUG_FLEX) util/parse-events.l
211
212$(OUTPUT)util/parse-events-bison.c: util/parse-events.y
213 $(QUIET_BISON)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $(OUTPUT)util/parse-events-bison.c -p parse_events_
214
215$(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c
216 $(QUIET_FLEX)$(FLEX) -o $@ --header-file=$(OUTPUT)util/pmu-flex.h util/pmu.l
217
218$(OUTPUT)util/pmu-bison.c: util/pmu.y
219 $(QUIET_BISON)$(BISON) -v util/pmu.y -d -o $(OUTPUT)util/pmu-bison.c -p perf_pmu_
220
221$(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c
222$(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
223
224LIB_FILE=$(OUTPUT)libperf.a 221LIB_FILE=$(OUTPUT)libperf.a
225 222
226LIB_H += ../lib/symbol/kallsyms.h 223PERFLIBS = $(LIB_FILE) $(LIBAPI) $(LIBTRACEEVENT)
227LIB_H += ../../include/uapi/linux/perf_event.h
228LIB_H += ../../include/linux/rbtree.h
229LIB_H += ../../include/linux/list.h
230LIB_H += ../../include/uapi/linux/const.h
231LIB_H += ../include/linux/hash.h
232LIB_H += ../../include/linux/stringify.h
233LIB_H += util/include/linux/bitmap.h
234LIB_H += ../include/linux/bitops.h
235LIB_H += ../include/asm-generic/bitops/arch_hweight.h
236LIB_H += ../include/asm-generic/bitops/atomic.h
237LIB_H += ../include/asm-generic/bitops/const_hweight.h
238LIB_H += ../include/asm-generic/bitops/find.h
239LIB_H += ../include/asm-generic/bitops/fls64.h
240LIB_H += ../include/asm-generic/bitops/fls.h
241LIB_H += ../include/asm-generic/bitops/__ffs.h
242LIB_H += ../include/asm-generic/bitops/__fls.h
243LIB_H += ../include/asm-generic/bitops/hweight.h
244LIB_H += ../include/asm-generic/bitops.h
245LIB_H += ../include/linux/compiler.h
246LIB_H += ../include/linux/log2.h
247LIB_H += util/include/linux/const.h
248LIB_H += util/include/linux/ctype.h
249LIB_H += util/include/linux/kernel.h
250LIB_H += util/include/linux/list.h
251LIB_H += ../include/linux/export.h
252LIB_H += util/include/linux/poison.h
253LIB_H += util/include/linux/rbtree.h
254LIB_H += util/include/linux/rbtree_augmented.h
255LIB_H += util/include/linux/string.h
256LIB_H += ../include/linux/types.h
257LIB_H += util/include/linux/linkage.h
258LIB_H += util/include/asm/asm-offsets.h
259LIB_H += ../include/asm/bug.h
260LIB_H += util/include/asm/byteorder.h
261LIB_H += util/include/asm/swab.h
262LIB_H += util/include/asm/system.h
263LIB_H += util/include/asm/uaccess.h
264LIB_H += util/include/dwarf-regs.h
265LIB_H += util/include/asm/dwarf2.h
266LIB_H += util/include/asm/cpufeature.h
267LIB_H += util/include/asm/unistd_32.h
268LIB_H += util/include/asm/unistd_64.h
269LIB_H += perf.h
270LIB_H += util/annotate.h
271LIB_H += util/cache.h
272LIB_H += util/callchain.h
273LIB_H += util/build-id.h
274LIB_H += util/db-export.h
275LIB_H += util/debug.h
276LIB_H += util/pmu.h
277LIB_H += util/event.h
278LIB_H += util/evsel.h
279LIB_H += util/evlist.h
280LIB_H += util/exec_cmd.h
281LIB_H += util/find-vdso-map.c
282LIB_H += util/levenshtein.h
283LIB_H += util/machine.h
284LIB_H += util/map.h
285LIB_H += util/parse-options.h
286LIB_H += util/parse-events.h
287LIB_H += util/quote.h
288LIB_H += util/util.h
289LIB_H += util/xyarray.h
290LIB_H += util/header.h
291LIB_H += util/help.h
292LIB_H += util/session.h
293LIB_H += util/ordered-events.h
294LIB_H += util/strbuf.h
295LIB_H += util/strlist.h
296LIB_H += util/strfilter.h
297LIB_H += util/svghelper.h
298LIB_H += util/tool.h
299LIB_H += util/run-command.h
300LIB_H += util/sigchain.h
301LIB_H += util/dso.h
302LIB_H += util/symbol.h
303LIB_H += util/color.h
304LIB_H += util/values.h
305LIB_H += util/sort.h
306LIB_H += util/hist.h
307LIB_H += util/comm.h
308LIB_H += util/thread.h
309LIB_H += util/thread_map.h
310LIB_H += util/trace-event.h
311LIB_H += util/probe-finder.h
312LIB_H += util/dwarf-aux.h
313LIB_H += util/probe-event.h
314LIB_H += util/pstack.h
315LIB_H += util/cpumap.h
316LIB_H += util/top.h
317LIB_H += $(ARCH_INCLUDE)
318LIB_H += util/cgroup.h
319LIB_H += $(LIB_INCLUDE)traceevent/event-parse.h
320LIB_H += util/target.h
321LIB_H += util/rblist.h
322LIB_H += util/intlist.h
323LIB_H += util/perf_regs.h
324LIB_H += util/unwind.h
325LIB_H += util/vdso.h
326LIB_H += util/tsc.h
327LIB_H += ui/helpline.h
328LIB_H += ui/progress.h
329LIB_H += ui/util.h
330LIB_H += ui/ui.h
331LIB_H += util/data.h
332LIB_H += util/kvm-stat.h
333LIB_H += util/thread-stack.h
334
335LIB_OBJS += $(OUTPUT)util/abspath.o
336LIB_OBJS += $(OUTPUT)util/alias.o
337LIB_OBJS += $(OUTPUT)util/annotate.o
338LIB_OBJS += $(OUTPUT)util/build-id.o
339LIB_OBJS += $(OUTPUT)util/config.o
340LIB_OBJS += $(OUTPUT)util/ctype.o
341LIB_OBJS += $(OUTPUT)util/db-export.o
342LIB_OBJS += $(OUTPUT)util/pmu.o
343LIB_OBJS += $(OUTPUT)util/environment.o
344LIB_OBJS += $(OUTPUT)util/event.o
345LIB_OBJS += $(OUTPUT)util/evlist.o
346LIB_OBJS += $(OUTPUT)util/evsel.o
347LIB_OBJS += $(OUTPUT)util/exec_cmd.o
348LIB_OBJS += $(OUTPUT)util/find_next_bit.o
349LIB_OBJS += $(OUTPUT)util/help.o
350LIB_OBJS += $(OUTPUT)util/kallsyms.o
351LIB_OBJS += $(OUTPUT)util/levenshtein.o
352LIB_OBJS += $(OUTPUT)util/parse-options.o
353LIB_OBJS += $(OUTPUT)util/parse-events.o
354LIB_OBJS += $(OUTPUT)util/path.o
355LIB_OBJS += $(OUTPUT)util/rbtree.o
356LIB_OBJS += $(OUTPUT)util/bitmap.o
357LIB_OBJS += $(OUTPUT)util/hweight.o
358LIB_OBJS += $(OUTPUT)util/run-command.o
359LIB_OBJS += $(OUTPUT)util/quote.o
360LIB_OBJS += $(OUTPUT)util/strbuf.o
361LIB_OBJS += $(OUTPUT)util/string.o
362LIB_OBJS += $(OUTPUT)util/strlist.o
363LIB_OBJS += $(OUTPUT)util/strfilter.o
364LIB_OBJS += $(OUTPUT)util/top.o
365LIB_OBJS += $(OUTPUT)util/usage.o
366LIB_OBJS += $(OUTPUT)util/wrapper.o
367LIB_OBJS += $(OUTPUT)util/sigchain.o
368LIB_OBJS += $(OUTPUT)util/dso.o
369LIB_OBJS += $(OUTPUT)util/symbol.o
370LIB_OBJS += $(OUTPUT)util/symbol-elf.o
371LIB_OBJS += $(OUTPUT)util/color.o
372LIB_OBJS += $(OUTPUT)util/pager.o
373LIB_OBJS += $(OUTPUT)util/header.o
374LIB_OBJS += $(OUTPUT)util/callchain.o
375LIB_OBJS += $(OUTPUT)util/values.o
376LIB_OBJS += $(OUTPUT)util/debug.o
377LIB_OBJS += $(OUTPUT)util/machine.o
378LIB_OBJS += $(OUTPUT)util/map.o
379LIB_OBJS += $(OUTPUT)util/pstack.o
380LIB_OBJS += $(OUTPUT)util/session.o
381LIB_OBJS += $(OUTPUT)util/ordered-events.o
382LIB_OBJS += $(OUTPUT)util/comm.o
383LIB_OBJS += $(OUTPUT)util/thread.o
384LIB_OBJS += $(OUTPUT)util/thread_map.o
385LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
386LIB_OBJS += $(OUTPUT)util/parse-events-flex.o
387LIB_OBJS += $(OUTPUT)util/parse-events-bison.o
388LIB_OBJS += $(OUTPUT)util/pmu-flex.o
389LIB_OBJS += $(OUTPUT)util/pmu-bison.o
390LIB_OBJS += $(OUTPUT)util/trace-event-read.o
391LIB_OBJS += $(OUTPUT)util/trace-event-info.o
392LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
393LIB_OBJS += $(OUTPUT)util/trace-event.o
394LIB_OBJS += $(OUTPUT)util/svghelper.o
395LIB_OBJS += $(OUTPUT)util/sort.o
396LIB_OBJS += $(OUTPUT)util/hist.o
397LIB_OBJS += $(OUTPUT)util/probe-event.o
398LIB_OBJS += $(OUTPUT)util/util.o
399LIB_OBJS += $(OUTPUT)util/xyarray.o
400LIB_OBJS += $(OUTPUT)util/cpumap.o
401LIB_OBJS += $(OUTPUT)util/cgroup.o
402LIB_OBJS += $(OUTPUT)util/target.o
403LIB_OBJS += $(OUTPUT)util/rblist.o
404LIB_OBJS += $(OUTPUT)util/intlist.o
405LIB_OBJS += $(OUTPUT)util/vdso.o
406LIB_OBJS += $(OUTPUT)util/stat.o
407LIB_OBJS += $(OUTPUT)util/record.o
408LIB_OBJS += $(OUTPUT)util/srcline.o
409LIB_OBJS += $(OUTPUT)util/data.o
410LIB_OBJS += $(OUTPUT)util/tsc.o
411LIB_OBJS += $(OUTPUT)util/cloexec.o
412LIB_OBJS += $(OUTPUT)util/thread-stack.o
413
414LIB_OBJS += $(OUTPUT)ui/setup.o
415LIB_OBJS += $(OUTPUT)ui/helpline.o
416LIB_OBJS += $(OUTPUT)ui/progress.o
417LIB_OBJS += $(OUTPUT)ui/util.o
418LIB_OBJS += $(OUTPUT)ui/hist.o
419LIB_OBJS += $(OUTPUT)ui/stdio/hist.o
420
421LIB_OBJS += $(OUTPUT)arch/common.o
422
423LIB_OBJS += $(OUTPUT)tests/parse-events.o
424LIB_OBJS += $(OUTPUT)tests/dso-data.o
425LIB_OBJS += $(OUTPUT)tests/attr.o
426LIB_OBJS += $(OUTPUT)tests/vmlinux-kallsyms.o
427LIB_OBJS += $(OUTPUT)tests/open-syscall.o
428LIB_OBJS += $(OUTPUT)tests/open-syscall-all-cpus.o
429LIB_OBJS += $(OUTPUT)tests/open-syscall-tp-fields.o
430LIB_OBJS += $(OUTPUT)tests/mmap-basic.o
431LIB_OBJS += $(OUTPUT)tests/perf-record.o
432LIB_OBJS += $(OUTPUT)tests/rdpmc.o
433LIB_OBJS += $(OUTPUT)tests/evsel-roundtrip-name.o
434LIB_OBJS += $(OUTPUT)tests/evsel-tp-sched.o
435LIB_OBJS += $(OUTPUT)tests/fdarray.o
436LIB_OBJS += $(OUTPUT)tests/pmu.o
437LIB_OBJS += $(OUTPUT)tests/hists_common.o
438LIB_OBJS += $(OUTPUT)tests/hists_link.o
439LIB_OBJS += $(OUTPUT)tests/hists_filter.o
440LIB_OBJS += $(OUTPUT)tests/hists_output.o
441LIB_OBJS += $(OUTPUT)tests/hists_cumulate.o
442LIB_OBJS += $(OUTPUT)tests/python-use.o
443LIB_OBJS += $(OUTPUT)tests/bp_signal.o
444LIB_OBJS += $(OUTPUT)tests/bp_signal_overflow.o
445LIB_OBJS += $(OUTPUT)tests/task-exit.o
446LIB_OBJS += $(OUTPUT)tests/sw-clock.o
447ifeq ($(ARCH),x86)
448LIB_OBJS += $(OUTPUT)tests/perf-time-to-tsc.o
449endif
450LIB_OBJS += $(OUTPUT)tests/code-reading.o
451LIB_OBJS += $(OUTPUT)tests/sample-parsing.o
452LIB_OBJS += $(OUTPUT)tests/parse-no-sample-id-all.o
453ifndef NO_DWARF_UNWIND
454ifeq ($(ARCH),$(filter $(ARCH),x86 arm))
455LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
456endif
457endif
458LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o
459LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o
460LIB_OBJS += $(OUTPUT)tests/switch-tracking.o
461
462BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
463BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
464# Benchmark modules
465BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o
466BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o
467ifeq ($(ARCH), x86)
468ifeq ($(IS_64_BIT), 1)
469BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy-x86-64-asm.o
470BUILTIN_OBJS += $(OUTPUT)bench/mem-memset-x86-64-asm.o
471endif
472endif
473BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
474BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
475BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
476BUILTIN_OBJS += $(OUTPUT)bench/futex-requeue.o
477
478BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
479BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
480BUILTIN_OBJS += $(OUTPUT)builtin-help.o
481BUILTIN_OBJS += $(OUTPUT)builtin-sched.o
482BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o
483BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o
484BUILTIN_OBJS += $(OUTPUT)builtin-list.o
485BUILTIN_OBJS += $(OUTPUT)builtin-record.o
486BUILTIN_OBJS += $(OUTPUT)builtin-report.o
487BUILTIN_OBJS += $(OUTPUT)builtin-stat.o
488BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o
489BUILTIN_OBJS += $(OUTPUT)builtin-top.o
490BUILTIN_OBJS += $(OUTPUT)builtin-script.o
491BUILTIN_OBJS += $(OUTPUT)builtin-probe.o
492BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
493BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
494BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
495BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
496BUILTIN_OBJS += $(OUTPUT)tests/builtin-test.o
497BUILTIN_OBJS += $(OUTPUT)builtin-mem.o
498
499PERFLIBS = $(LIB_FILE) $(LIBAPIKFS) $(LIBTRACEEVENT)
500 224
501# We choose to avoid "if .. else if .. else .. endif endif" 225# We choose to avoid "if .. else if .. else .. endif endif"
502# because maintaining the nesting to match is a pain. If 226# because maintaining the nesting to match is a pain. If
@@ -508,67 +232,9 @@ ifneq ($(OUTPUT),)
508 CFLAGS += -I$(OUTPUT) 232 CFLAGS += -I$(OUTPUT)
509endif 233endif
510 234
511ifdef NO_LIBELF
512# Remove ELF/DWARF dependent codes
513LIB_OBJS := $(filter-out $(OUTPUT)util/symbol-elf.o,$(LIB_OBJS))
514LIB_OBJS := $(filter-out $(OUTPUT)util/dwarf-aux.o,$(LIB_OBJS))
515LIB_OBJS := $(filter-out $(OUTPUT)util/probe-event.o,$(LIB_OBJS))
516LIB_OBJS := $(filter-out $(OUTPUT)util/probe-finder.o,$(LIB_OBJS))
517
518BUILTIN_OBJS := $(filter-out $(OUTPUT)builtin-probe.o,$(BUILTIN_OBJS))
519
520# Use minimal symbol handling
521LIB_OBJS += $(OUTPUT)util/symbol-minimal.o
522
523else # NO_LIBELF
524ifndef NO_DWARF
525 LIB_OBJS += $(OUTPUT)util/probe-finder.o
526 LIB_OBJS += $(OUTPUT)util/dwarf-aux.o
527endif # NO_DWARF
528endif # NO_LIBELF
529
530ifndef NO_LIBDW_DWARF_UNWIND
531 LIB_OBJS += $(OUTPUT)util/unwind-libdw.o
532 LIB_H += util/unwind-libdw.h
533endif
534
535ifndef NO_LIBUNWIND
536 LIB_OBJS += $(OUTPUT)util/unwind-libunwind.o
537endif
538LIB_OBJS += $(OUTPUT)tests/keep-tracking.o
539
540ifndef NO_LIBAUDIT
541 BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
542endif
543
544ifndef NO_SLANG
545 LIB_OBJS += $(OUTPUT)ui/browser.o
546 LIB_OBJS += $(OUTPUT)ui/browsers/annotate.o
547 LIB_OBJS += $(OUTPUT)ui/browsers/hists.o
548 LIB_OBJS += $(OUTPUT)ui/browsers/map.o
549 LIB_OBJS += $(OUTPUT)ui/browsers/scripts.o
550 LIB_OBJS += $(OUTPUT)ui/browsers/header.o
551 LIB_OBJS += $(OUTPUT)ui/tui/setup.o
552 LIB_OBJS += $(OUTPUT)ui/tui/util.o
553 LIB_OBJS += $(OUTPUT)ui/tui/helpline.o
554 LIB_OBJS += $(OUTPUT)ui/tui/progress.o
555 LIB_H += ui/tui/tui.h
556 LIB_H += ui/browser.h
557 LIB_H += ui/browsers/map.h
558 LIB_H += ui/keysyms.h
559 LIB_H += ui/libslang.h
560endif
561
562ifndef NO_GTK2 235ifndef NO_GTK2
563 ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so 236 ALL_PROGRAMS += $(OUTPUT)libperf-gtk.so
564 237 GTK_IN := $(OUTPUT)gtk-in.o
565 GTK_OBJS += $(OUTPUT)ui/gtk/browser.o
566 GTK_OBJS += $(OUTPUT)ui/gtk/hists.o
567 GTK_OBJS += $(OUTPUT)ui/gtk/setup.o
568 GTK_OBJS += $(OUTPUT)ui/gtk/util.o
569 GTK_OBJS += $(OUTPUT)ui/gtk/helpline.o
570 GTK_OBJS += $(OUTPUT)ui/gtk/progress.o
571 GTK_OBJS += $(OUTPUT)ui/gtk/annotate.o
572 238
573install-gtk: $(OUTPUT)libperf-gtk.so 239install-gtk: $(OUTPUT)libperf-gtk.so
574 $(call QUIET_INSTALL, 'GTK UI') \ 240 $(call QUIET_INSTALL, 'GTK UI') \
@@ -576,31 +242,6 @@ install-gtk: $(OUTPUT)libperf-gtk.so
576 $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)' 242 $(INSTALL) $(OUTPUT)libperf-gtk.so '$(DESTDIR_SQ)$(libdir_SQ)'
577endif 243endif
578 244
579ifndef NO_LIBPERL
580 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
581 LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
582endif
583
584ifndef NO_LIBPYTHON
585 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
586 LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
587endif
588
589ifeq ($(NO_PERF_REGS),0)
590 ifeq ($(ARCH),x86)
591 LIB_H += arch/x86/include/perf_regs.h
592 endif
593 LIB_OBJS += $(OUTPUT)util/perf_regs.o
594endif
595
596ifndef NO_LIBNUMA
597 BUILTIN_OBJS += $(OUTPUT)bench/numa.o
598endif
599
600ifndef NO_ZLIB
601 LIB_OBJS += $(OUTPUT)util/zlib.o
602endif
603
604ifdef ASCIIDOC8 245ifdef ASCIIDOC8
605 export ASCIIDOC8 246 export ASCIIDOC8
606endif 247endif
@@ -616,39 +257,29 @@ SHELL = $(SHELL_PATH)
616all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) 257all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
617 258
618please_set_SHELL_PATH_to_a_more_modern_shell: 259please_set_SHELL_PATH_to_a_more_modern_shell:
619 @$$(:) 260 $(Q)$$(:)
620 261
621shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell 262shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
622 263
623strip: $(PROGRAMS) $(OUTPUT)perf 264strip: $(PROGRAMS) $(OUTPUT)perf
624 $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf 265 $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf
625 266
626$(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 267PERF_IN := $(OUTPUT)perf-in.o
627 $(QUIET_CC)$(CC) -include $(OUTPUT)PERF-VERSION-FILE \
628 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
629 $(CFLAGS) -c $(filter %.c,$^) -o $@
630 268
631$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) 269export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX
632 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(OUTPUT)perf.o \ 270build := -f $(srctree)/tools/build/Makefile.build dir=. obj
633 $(BUILTIN_OBJS) $(LIBS) -o $@
634 271
635$(GTK_OBJS): $(OUTPUT)%.o: %.c $(LIB_H) 272$(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE
636 $(QUIET_CC)$(CC) -o $@ -c -fPIC $(CFLAGS) $(GTK_CFLAGS) $< 273 $(Q)$(MAKE) $(build)=perf
637 274
638$(OUTPUT)libperf-gtk.so: $(GTK_OBJS) $(PERFLIBS) 275$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN)
639 $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS) 276 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(LIBS) -o $@
640 277
641$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 278$(GTK_IN): FORCE
642 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \ 279 $(Q)$(MAKE) $(build)=gtk
643 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
644 '-DPERF_MAN_PATH="$(mandir_SQ)"' \
645 '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
646 280
647$(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 281$(OUTPUT)libperf-gtk.so: $(GTK_IN) $(PERFLIBS)
648 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \ 282 $(QUIET_LINK)$(CC) -o $@ -shared $(LDFLAGS) $(filter %.o,$^) $(GTK_LIBS)
649 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
650 '-DPERF_MAN_PATH="$(mandir_SQ)"' \
651 '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
652 283
653$(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt 284$(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
654 285
@@ -659,8 +290,7 @@ $(SCRIPTS) : % : %.sh
659 $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@' 290 $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@'
660 291
661# These can record PERF_VERSION 292# These can record PERF_VERSION
662$(OUTPUT)perf.o perf.spec \ 293perf.spec $(SCRIPTS) \
663 $(SCRIPTS) \
664 : $(OUTPUT)PERF-VERSION-FILE 294 : $(OUTPUT)PERF-VERSION-FILE
665 295
666.SUFFIXES: 296.SUFFIXES:
@@ -683,90 +313,33 @@ endif
683# These two need to be here so that when O= is not used they take precedence 313# These two need to be here so that when O= is not used they take precedence
684# over the general rule for .o 314# over the general rule for .o
685 315
686$(OUTPUT)util/%-flex.o: $(OUTPUT)util/%-flex.c $(OUTPUT)PERF-CFLAGS 316# get relative building directory (to $(OUTPUT))
687 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(CFLAGS) -w $< 317# and '.' if it's $(OUTPUT) itself
688 318__build-dir = $(subst $(OUTPUT),,$(dir $@))
689$(OUTPUT)util/%-bison.o: $(OUTPUT)util/%-bison.c $(OUTPUT)PERF-CFLAGS 319build-dir = $(if $(__build-dir),$(__build-dir),.)
690 $(QUIET_CC)$(CC) -o $@ -c -Iutil/ $(CFLAGS) -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w $<
691
692$(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
693 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
694$(OUTPUT)%.i: %.c $(OUTPUT)PERF-CFLAGS
695 $(QUIET_CC)$(CC) -o $@ -E $(CFLAGS) $<
696$(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
697 $(QUIET_CC)$(CC) -o $@ -S $(CFLAGS) $<
698$(OUTPUT)%.o: %.S
699 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
700$(OUTPUT)%.s: %.S
701 $(QUIET_CC)$(CC) -o $@ -E $(CFLAGS) $<
702
703$(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
704 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
705 '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \
706 '-DPREFIX="$(prefix_SQ)"' \
707 $<
708
709$(OUTPUT)tests/attr.o: tests/attr.c $(OUTPUT)PERF-CFLAGS
710 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
711 '-DBINDIR="$(bindir_SQ)"' -DPYTHON='"$(PYTHON_WORD)"' \
712 $<
713
714$(OUTPUT)tests/python-use.o: tests/python-use.c $(OUTPUT)PERF-CFLAGS
715 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) \
716 -DPYTHONPATH='"$(OUTPUT)python"' \
717 -DPYTHON='"$(PYTHON_WORD)"' \
718 $<
719
720$(OUTPUT)tests/dwarf-unwind.o: tests/dwarf-unwind.c
721 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -fno-optimize-sibling-calls $<
722
723$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
724 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
725 320
726$(OUTPUT)ui/setup.o: ui/setup.c $(OUTPUT)PERF-CFLAGS 321single_dep: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
727 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DLIBDIR='"$(libdir_SQ)"' $<
728 322
729$(OUTPUT)ui/browser.o: ui/browser.c $(OUTPUT)PERF-CFLAGS 323$(OUTPUT)%.o: %.c single_dep FORCE
730 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $< 324 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
731 325
732$(OUTPUT)ui/browsers/annotate.o: ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS 326$(OUTPUT)%.i: %.c single_dep FORCE
733 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $< 327 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
734 328
735$(OUTPUT)ui/browsers/hists.o: ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS 329$(OUTPUT)%.s: %.c single_dep FORCE
736 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $< 330 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
737 331
738$(OUTPUT)ui/browsers/map.o: ui/browsers/map.c $(OUTPUT)PERF-CFLAGS 332$(OUTPUT)%-bison.o: %.c single_dep FORCE
739 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $< 333 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
740 334
741$(OUTPUT)ui/browsers/scripts.o: ui/browsers/scripts.c $(OUTPUT)PERF-CFLAGS 335$(OUTPUT)%-flex.o: %.c single_dep FORCE
742 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -DENABLE_SLFUTURE_CONST $< 336 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
743 337
744$(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c $(OUTPUT)PERF-CFLAGS 338$(OUTPUT)%.o: %.S single_dep FORCE
745 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $< 339 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
746 340
747$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS 341$(OUTPUT)%.i: %.S single_dep FORCE
748 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 342 $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
749
750$(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS
751 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
752
753$(OUTPUT)util/find_next_bit.o: ../lib/util/find_next_bit.c $(OUTPUT)PERF-CFLAGS
754 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-unused-parameter -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
755
756$(OUTPUT)util/parse-events.o: util/parse-events.c $(OUTPUT)PERF-CFLAGS
757 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) -Wno-redundant-decls $<
758
759$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
760 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-undef -Wno-switch-default $<
761
762$(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
763 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-undef -Wno-switch-default $<
764
765$(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS
766 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
767
768$(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
769 $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
770 343
771$(OUTPUT)perf-%: %.o $(PERFLIBS) 344$(OUTPUT)perf-%: %.o $(PERFLIBS)
772 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS) 345 $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $(LDFLAGS) $(filter %.o,$^) $(LIBS)
@@ -781,58 +354,34 @@ $(OUTPUT)perf-read-vdsox32: perf-read-vdso.c util/find-vdso-map.c
781 $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c 354 $(QUIET_CC)$(CC) -mx32 $(filter -static,$(LDFLAGS)) -Wall -Werror -o $@ perf-read-vdso.c
782endif 355endif
783 356
784$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) 357$(patsubst perf-%,%.o,$(PROGRAMS)): $(wildcard */*.h)
785$(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
786
787# we compile into subdirectories. if the target directory is not the source directory, they might not exists. So
788# we depend the various files onto their directories.
789DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(GTK_OBJS)
790DIRECTORY_DEPS += $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h
791# no need to add flex objects, because they depend on bison ones
792DIRECTORY_DEPS += $(OUTPUT)util/parse-events-bison.c
793DIRECTORY_DEPS += $(OUTPUT)util/pmu-bison.c
794 358
795OUTPUT_DIRECTORIES := $(sort $(dir $(DIRECTORY_DEPS))) 359LIBPERF_IN := $(OUTPUT)libperf-in.o
796 360
797$(DIRECTORY_DEPS): | $(OUTPUT_DIRECTORIES) 361$(LIBPERF_IN): FORCE
798# In the second step, we make a rule to actually create these directories 362 $(Q)$(MAKE) $(build)=libperf
799$(OUTPUT_DIRECTORIES):
800 $(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null
801 363
802$(LIB_FILE): $(LIB_OBJS) 364$(LIB_FILE): $(LIBPERF_IN)
803 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) 365 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) $(LIB_OBJS)
804 366
805# libtraceevent.a
806TE_SOURCES = $(wildcard $(TRACE_EVENT_DIR)*.[ch])
807
808LIBTRACEEVENT_FLAGS = $(QUIET_SUBDIR1) O=$(OUTPUT)
809LIBTRACEEVENT_FLAGS += CFLAGS="-g -Wall $(EXTRA_CFLAGS)"
810LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ) 367LIBTRACEEVENT_FLAGS += plugin_dir=$(plugindir_SQ)
811 368
812$(LIBTRACEEVENT): $(TE_SOURCES) $(OUTPUT)PERF-CFLAGS 369$(LIBTRACEEVENT): FORCE
813 $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) libtraceevent.a plugins 370 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) $(OUTPUT)libtraceevent.a plugins
814 371
815$(LIBTRACEEVENT)-clean: 372$(LIBTRACEEVENT)-clean:
816 $(call QUIET_CLEAN, libtraceevent) 373 $(call QUIET_CLEAN, libtraceevent)
817 @$(MAKE) -C $(TRACE_EVENT_DIR) O=$(OUTPUT) clean >/dev/null 374 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) O=$(OUTPUT) clean >/dev/null
818 375
819install-traceevent-plugins: $(LIBTRACEEVENT) 376install-traceevent-plugins: $(LIBTRACEEVENT)
820 $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) install_plugins 377 $(Q)$(MAKE) -C $(TRACE_EVENT_DIR) $(LIBTRACEEVENT_FLAGS) O=$(OUTPUT) install_plugins
821
822LIBAPIKFS_SOURCES = $(wildcard $(LIB_PATH)fs/*.[ch] $(LIB_PATH)fd/*.[ch])
823 378
824# if subdir is set, we've been called from above so target has been built 379$(LIBAPI): FORCE
825# already 380 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
826$(LIBAPIKFS): $(LIBAPIKFS_SOURCES)
827ifeq ($(subdir),)
828 $(QUIET_SUBDIR0)$(LIB_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libapikfs.a
829endif
830 381
831$(LIBAPIKFS)-clean: 382$(LIBAPI)-clean:
832ifeq ($(subdir),) 383 $(call QUIET_CLEAN, libapi)
833 $(call QUIET_CLEAN, libapikfs) 384 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
834 @$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
835endif
836 385
837help: 386help:
838 @echo 'Perf make targets:' 387 @echo 'Perf make targets:'
@@ -888,17 +437,6 @@ cscope:
888 $(QUIET_GEN)$(RM) cscope*; \ 437 $(QUIET_GEN)$(RM) cscope*; \
889 $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs cscope -b $(TAG_FILES) 438 $(FIND) $(TAG_FOLDERS) -name '*.[hcS]' -print | xargs cscope -b $(TAG_FILES)
890 439
891### Detect prefix changes
892TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):\
893 $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ):$(plugindir_SQ)
894
895$(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS
896 @FLAGS='$(TRACK_CFLAGS)'; \
897 if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \
898 echo 1>&2 " FLAGS: * new build flags or prefix"; \
899 echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \
900 fi
901
902### Testing rules 440### Testing rules
903 441
904# GNU make supports exporting all variables by "export" without parameters. 442# GNU make supports exporting all variables by "export" without parameters.
@@ -981,12 +519,14 @@ $(INSTALL_DOC_TARGETS):
981# 519#
982config-clean: 520config-clean:
983 $(call QUIET_CLEAN, config) 521 $(call QUIET_CLEAN, config)
984 @$(MAKE) -C config/feature-checks clean >/dev/null 522 $(Q)$(MAKE) -C config/feature-checks clean >/dev/null
985 523
986clean: $(LIBTRACEEVENT)-clean $(LIBAPIKFS)-clean config-clean 524clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean
987 $(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) 525 $(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
526 $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
527 $(Q)$(RM) .config-detected
988 $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 528 $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
989 $(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* 529 $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-FEATURES $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
990 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean 530 $(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
991 $(python-clean) 531 $(python-clean)
992 532
@@ -1000,7 +540,9 @@ else
1000 GIT-HEAD-PHONY = 540 GIT-HEAD-PHONY =
1001endif 541endif
1002 542
543FORCE:
544
1003.PHONY: all install clean config-clean strip install-gtk 545.PHONY: all install clean config-clean strip install-gtk
1004.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell 546.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
1005.PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope .FORCE-PERF-CFLAGS 547.PHONY: $(GIT-HEAD-PHONY) TAGS tags cscope FORCE single_dep
1006 548
diff --git a/tools/perf/arch/Build b/tools/perf/arch/Build
new file mode 100644
index 000000000000..109eb75cf7de
--- /dev/null
+++ b/tools/perf/arch/Build
@@ -0,0 +1,2 @@
1libperf-y += common.o
2libperf-y += $(ARCH)/
diff --git a/tools/perf/arch/arm/Build b/tools/perf/arch/arm/Build
new file mode 100644
index 000000000000..41bf61da476a
--- /dev/null
+++ b/tools/perf/arch/arm/Build
@@ -0,0 +1,2 @@
1libperf-y += util/
2libperf-$(CONFIG_DWARF_UNWIND) += tests/
diff --git a/tools/perf/arch/arm/Makefile b/tools/perf/arch/arm/Makefile
index 09d62153d384..7fbca175099e 100644
--- a/tools/perf/arch/arm/Makefile
+++ b/tools/perf/arch/arm/Makefile
@@ -1,14 +1,3 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif
5ifndef NO_LIBUNWIND
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
7endif
8ifndef NO_LIBDW_DWARF_UNWIND
9LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libdw.o
10endif
11ifndef NO_DWARF_UNWIND
12LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/regs_load.o
13LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o
14endif 3endif
diff --git a/tools/perf/arch/arm/tests/Build b/tools/perf/arch/arm/tests/Build
new file mode 100644
index 000000000000..b30eff9bcc83
--- /dev/null
+++ b/tools/perf/arch/arm/tests/Build
@@ -0,0 +1,2 @@
1libperf-y += regs_load.o
2libperf-y += dwarf-unwind.o
diff --git a/tools/perf/arch/arm/util/Build b/tools/perf/arch/arm/util/Build
new file mode 100644
index 000000000000..d22e3d07de3d
--- /dev/null
+++ b/tools/perf/arch/arm/util/Build
@@ -0,0 +1,4 @@
1libperf-$(CONFIG_DWARF) += dwarf-regs.o
2
3libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
4libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/arch/arm64/Build b/tools/perf/arch/arm64/Build
new file mode 100644
index 000000000000..54afe4a467e7
--- /dev/null
+++ b/tools/perf/arch/arm64/Build
@@ -0,0 +1 @@
libperf-y += util/
diff --git a/tools/perf/arch/arm64/Makefile b/tools/perf/arch/arm64/Makefile
index 67e9b3d38e89..7fbca175099e 100644
--- a/tools/perf/arch/arm64/Makefile
+++ b/tools/perf/arch/arm64/Makefile
@@ -1,7 +1,3 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif
5ifndef NO_LIBUNWIND
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
7endif 3endif
diff --git a/tools/perf/arch/arm64/util/Build b/tools/perf/arch/arm64/util/Build
new file mode 100644
index 000000000000..e58123a8912b
--- /dev/null
+++ b/tools/perf/arch/arm64/util/Build
@@ -0,0 +1,2 @@
1libperf-$(CONFIG_DWARF) += dwarf-regs.o
2libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
diff --git a/tools/perf/arch/powerpc/Build b/tools/perf/arch/powerpc/Build
new file mode 100644
index 000000000000..54afe4a467e7
--- /dev/null
+++ b/tools/perf/arch/powerpc/Build
@@ -0,0 +1 @@
libperf-y += util/
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile
index 6f7782bea5dd..7fbca175099e 100644
--- a/tools/perf/arch/powerpc/Makefile
+++ b/tools/perf/arch/powerpc/Makefile
@@ -1,6 +1,3 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/skip-callchain-idx.o
5endif 3endif
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
diff --git a/tools/perf/arch/powerpc/util/Build b/tools/perf/arch/powerpc/util/Build
new file mode 100644
index 000000000000..0af6e9b3f728
--- /dev/null
+++ b/tools/perf/arch/powerpc/util/Build
@@ -0,0 +1,4 @@
1libperf-y += header.o
2
3libperf-$(CONFIG_DWARF) += dwarf-regs.o
4libperf-$(CONFIG_DWARF) += skip-callchain-idx.o
diff --git a/tools/perf/arch/s390/Build b/tools/perf/arch/s390/Build
new file mode 100644
index 000000000000..54afe4a467e7
--- /dev/null
+++ b/tools/perf/arch/s390/Build
@@ -0,0 +1 @@
libperf-y += util/
diff --git a/tools/perf/arch/s390/Makefile b/tools/perf/arch/s390/Makefile
index 798ac7379c5f..21322e0385b8 100644
--- a/tools/perf/arch/s390/Makefile
+++ b/tools/perf/arch/s390/Makefile
@@ -1,7 +1,4 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 3endif
5LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
6HAVE_KVM_STAT_SUPPORT := 1 4HAVE_KVM_STAT_SUPPORT := 1
7LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/s390/util/Build b/tools/perf/arch/s390/util/Build
new file mode 100644
index 000000000000..8a61372bb47a
--- /dev/null
+++ b/tools/perf/arch/s390/util/Build
@@ -0,0 +1,4 @@
1libperf-y += header.o
2libperf-y += kvm-stat.o
3
4libperf-$(CONFIG_DWARF) += dwarf-regs.o
diff --git a/tools/perf/arch/sh/Build b/tools/perf/arch/sh/Build
new file mode 100644
index 000000000000..54afe4a467e7
--- /dev/null
+++ b/tools/perf/arch/sh/Build
@@ -0,0 +1 @@
libperf-y += util/
diff --git a/tools/perf/arch/sh/Makefile b/tools/perf/arch/sh/Makefile
index 15130b50dfe3..7fbca175099e 100644
--- a/tools/perf/arch/sh/Makefile
+++ b/tools/perf/arch/sh/Makefile
@@ -1,4 +1,3 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 3endif
diff --git a/tools/perf/arch/sh/util/Build b/tools/perf/arch/sh/util/Build
new file mode 100644
index 000000000000..954e287bbb89
--- /dev/null
+++ b/tools/perf/arch/sh/util/Build
@@ -0,0 +1 @@
libperf-$(CONFIG_DWARF) += dwarf-regs.o
diff --git a/tools/perf/arch/sparc/Build b/tools/perf/arch/sparc/Build
new file mode 100644
index 000000000000..54afe4a467e7
--- /dev/null
+++ b/tools/perf/arch/sparc/Build
@@ -0,0 +1 @@
libperf-y += util/
diff --git a/tools/perf/arch/sparc/Makefile b/tools/perf/arch/sparc/Makefile
index 15130b50dfe3..7fbca175099e 100644
--- a/tools/perf/arch/sparc/Makefile
+++ b/tools/perf/arch/sparc/Makefile
@@ -1,4 +1,3 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 3endif
diff --git a/tools/perf/arch/sparc/util/Build b/tools/perf/arch/sparc/util/Build
new file mode 100644
index 000000000000..954e287bbb89
--- /dev/null
+++ b/tools/perf/arch/sparc/util/Build
@@ -0,0 +1 @@
libperf-$(CONFIG_DWARF) += dwarf-regs.o
diff --git a/tools/perf/arch/x86/Build b/tools/perf/arch/x86/Build
new file mode 100644
index 000000000000..41bf61da476a
--- /dev/null
+++ b/tools/perf/arch/x86/Build
@@ -0,0 +1,2 @@
1libperf-y += util/
2libperf-$(CONFIG_DWARF_UNWIND) += tests/
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
index 9b21881db52f..21322e0385b8 100644
--- a/tools/perf/arch/x86/Makefile
+++ b/tools/perf/arch/x86/Makefile
@@ -1,19 +1,4 @@
1ifndef NO_DWARF 1ifndef NO_DWARF
2PERF_HAVE_DWARF_REGS := 1 2PERF_HAVE_DWARF_REGS := 1
3LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
4endif 3endif
5ifndef NO_LIBUNWIND
6LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libunwind.o
7endif
8ifndef NO_LIBDW_DWARF_UNWIND
9LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/unwind-libdw.o
10endif
11ifndef NO_DWARF_UNWIND
12LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/regs_load.o
13LIB_OBJS += $(OUTPUT)arch/$(ARCH)/tests/dwarf-unwind.o
14endif
15LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/header.o
16LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/tsc.o
17LIB_H += arch/$(ARCH)/util/tsc.h
18HAVE_KVM_STAT_SUPPORT := 1 4HAVE_KVM_STAT_SUPPORT := 1
19LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/kvm-stat.o
diff --git a/tools/perf/arch/x86/tests/Build b/tools/perf/arch/x86/tests/Build
new file mode 100644
index 000000000000..b30eff9bcc83
--- /dev/null
+++ b/tools/perf/arch/x86/tests/Build
@@ -0,0 +1,2 @@
1libperf-y += regs_load.o
2libperf-y += dwarf-unwind.o
diff --git a/tools/perf/arch/x86/util/Build b/tools/perf/arch/x86/util/Build
new file mode 100644
index 000000000000..cfbccc4e3187
--- /dev/null
+++ b/tools/perf/arch/x86/util/Build
@@ -0,0 +1,8 @@
1libperf-y += header.o
2libperf-y += tsc.o
3libperf-y += kvm-stat.o
4
5libperf-$(CONFIG_DWARF) += dwarf-regs.o
6
7libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
8libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
diff --git a/tools/perf/bench/Build b/tools/perf/bench/Build
new file mode 100644
index 000000000000..5ce98023d518
--- /dev/null
+++ b/tools/perf/bench/Build
@@ -0,0 +1,11 @@
1perf-y += sched-messaging.o
2perf-y += sched-pipe.o
3perf-y += mem-memcpy.o
4perf-y += futex-hash.o
5perf-y += futex-wake.o
6perf-y += futex-requeue.o
7
8perf-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o
9perf-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o
10
11perf-$(CONFIG_NUMA) += numa.o
diff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c
index 50e6b66aea1f..d929d9544664 100644
--- a/tools/perf/builtin-buildid-cache.c
+++ b/tools/perf/builtin-buildid-cache.c
@@ -125,8 +125,7 @@ static int build_id_cache__kcore_existing(const char *from_dir, char *to_dir,
125 return ret; 125 return ret;
126} 126}
127 127
128static int build_id_cache__add_kcore(const char *filename, const char *debugdir, 128static int build_id_cache__add_kcore(const char *filename, bool force)
129 bool force)
130{ 129{
131 char dir[32], sbuildid[BUILD_ID_SIZE * 2 + 1]; 130 char dir[32], sbuildid[BUILD_ID_SIZE * 2 + 1];
132 char from_dir[PATH_MAX], to_dir[PATH_MAX]; 131 char from_dir[PATH_MAX], to_dir[PATH_MAX];
@@ -143,7 +142,7 @@ static int build_id_cache__add_kcore(const char *filename, const char *debugdir,
143 return -1; 142 return -1;
144 143
145 scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s", 144 scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s",
146 debugdir, sbuildid); 145 buildid_dir, sbuildid);
147 146
148 if (!force && 147 if (!force &&
149 !build_id_cache__kcore_existing(from_dir, to_dir, sizeof(to_dir))) { 148 !build_id_cache__kcore_existing(from_dir, to_dir, sizeof(to_dir))) {
@@ -155,7 +154,7 @@ static int build_id_cache__add_kcore(const char *filename, const char *debugdir,
155 return -1; 154 return -1;
156 155
157 scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s/%s", 156 scnprintf(to_dir, sizeof(to_dir), "%s/[kernel.kcore]/%s/%s",
158 debugdir, sbuildid, dir); 157 buildid_dir, sbuildid, dir);
159 158
160 if (mkdir_p(to_dir, 0755)) 159 if (mkdir_p(to_dir, 0755))
161 return -1; 160 return -1;
@@ -183,7 +182,7 @@ static int build_id_cache__add_kcore(const char *filename, const char *debugdir,
183 return 0; 182 return 0;
184} 183}
185 184
186static int build_id_cache__add_file(const char *filename, const char *debugdir) 185static int build_id_cache__add_file(const char *filename)
187{ 186{
188 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 187 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
189 u8 build_id[BUILD_ID_SIZE]; 188 u8 build_id[BUILD_ID_SIZE];
@@ -195,7 +194,7 @@ static int build_id_cache__add_file(const char *filename, const char *debugdir)
195 } 194 }
196 195
197 build_id__sprintf(build_id, sizeof(build_id), sbuild_id); 196 build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
198 err = build_id_cache__add_s(sbuild_id, debugdir, filename, 197 err = build_id_cache__add_s(sbuild_id, filename,
199 false, false); 198 false, false);
200 if (verbose) 199 if (verbose)
201 pr_info("Adding %s %s: %s\n", sbuild_id, filename, 200 pr_info("Adding %s %s: %s\n", sbuild_id, filename,
@@ -203,8 +202,7 @@ static int build_id_cache__add_file(const char *filename, const char *debugdir)
203 return err; 202 return err;
204} 203}
205 204
206static int build_id_cache__remove_file(const char *filename, 205static int build_id_cache__remove_file(const char *filename)
207 const char *debugdir)
208{ 206{
209 u8 build_id[BUILD_ID_SIZE]; 207 u8 build_id[BUILD_ID_SIZE];
210 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 208 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -217,7 +215,7 @@ static int build_id_cache__remove_file(const char *filename,
217 } 215 }
218 216
219 build_id__sprintf(build_id, sizeof(build_id), sbuild_id); 217 build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
220 err = build_id_cache__remove_s(sbuild_id, debugdir); 218 err = build_id_cache__remove_s(sbuild_id);
221 if (verbose) 219 if (verbose)
222 pr_info("Removing %s %s: %s\n", sbuild_id, filename, 220 pr_info("Removing %s %s: %s\n", sbuild_id, filename,
223 err ? "FAIL" : "Ok"); 221 err ? "FAIL" : "Ok");
@@ -252,8 +250,7 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *f
252 return 0; 250 return 0;
253} 251}
254 252
255static int build_id_cache__update_file(const char *filename, 253static int build_id_cache__update_file(const char *filename)
256 const char *debugdir)
257{ 254{
258 u8 build_id[BUILD_ID_SIZE]; 255 u8 build_id[BUILD_ID_SIZE];
259 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 256 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
@@ -266,11 +263,10 @@ static int build_id_cache__update_file(const char *filename,
266 } 263 }
267 264
268 build_id__sprintf(build_id, sizeof(build_id), sbuild_id); 265 build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
269 err = build_id_cache__remove_s(sbuild_id, debugdir); 266 err = build_id_cache__remove_s(sbuild_id);
270 if (!err) { 267 if (!err)
271 err = build_id_cache__add_s(sbuild_id, debugdir, filename, 268 err = build_id_cache__add_s(sbuild_id, filename, false, false);
272 false, false); 269
273 }
274 if (verbose) 270 if (verbose)
275 pr_info("Updating %s %s: %s\n", sbuild_id, filename, 271 pr_info("Updating %s %s: %s\n", sbuild_id, filename,
276 err ? "FAIL" : "Ok"); 272 err ? "FAIL" : "Ok");
@@ -338,7 +334,7 @@ int cmd_buildid_cache(int argc, const char **argv,
338 list = strlist__new(true, add_name_list_str); 334 list = strlist__new(true, add_name_list_str);
339 if (list) { 335 if (list) {
340 strlist__for_each(pos, list) 336 strlist__for_each(pos, list)
341 if (build_id_cache__add_file(pos->s, buildid_dir)) { 337 if (build_id_cache__add_file(pos->s)) {
342 if (errno == EEXIST) { 338 if (errno == EEXIST) {
343 pr_debug("%s already in the cache\n", 339 pr_debug("%s already in the cache\n",
344 pos->s); 340 pos->s);
@@ -356,7 +352,7 @@ int cmd_buildid_cache(int argc, const char **argv,
356 list = strlist__new(true, remove_name_list_str); 352 list = strlist__new(true, remove_name_list_str);
357 if (list) { 353 if (list) {
358 strlist__for_each(pos, list) 354 strlist__for_each(pos, list)
359 if (build_id_cache__remove_file(pos->s, buildid_dir)) { 355 if (build_id_cache__remove_file(pos->s)) {
360 if (errno == ENOENT) { 356 if (errno == ENOENT) {
361 pr_debug("%s wasn't in the cache\n", 357 pr_debug("%s wasn't in the cache\n",
362 pos->s); 358 pos->s);
@@ -377,7 +373,7 @@ int cmd_buildid_cache(int argc, const char **argv,
377 list = strlist__new(true, update_name_list_str); 373 list = strlist__new(true, update_name_list_str);
378 if (list) { 374 if (list) {
379 strlist__for_each(pos, list) 375 strlist__for_each(pos, list)
380 if (build_id_cache__update_file(pos->s, buildid_dir)) { 376 if (build_id_cache__update_file(pos->s)) {
381 if (errno == ENOENT) { 377 if (errno == ENOENT) {
382 pr_debug("%s wasn't in the cache\n", 378 pr_debug("%s wasn't in the cache\n",
383 pos->s); 379 pos->s);
@@ -391,8 +387,7 @@ int cmd_buildid_cache(int argc, const char **argv,
391 } 387 }
392 } 388 }
393 389
394 if (kcore_filename && 390 if (kcore_filename && build_id_cache__add_kcore(kcore_filename, force))
395 build_id_cache__add_kcore(kcore_filename, buildid_dir, force))
396 pr_warning("Couldn't add %s\n", kcore_filename); 391 pr_warning("Couldn't add %s\n", kcore_filename);
397 392
398out: 393out:
diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
index 198f3c3aff95..ad8018e26aa0 100644
--- a/tools/perf/builtin-list.c
+++ b/tools/perf/builtin-list.c
@@ -41,6 +41,9 @@ int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
41 return 0; 41 return 0;
42 } 42 }
43 43
44 if (!raw_dump)
45 printf("\nList of pre-defined events (to be used in -e):\n\n");
46
44 if (argc == 0) { 47 if (argc == 0) {
45 print_events(NULL, false); 48 print_events(NULL, false);
46 return 0; 49 return 0;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 7e935f1083ec..b1c1df9bfb26 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -1219,7 +1219,9 @@ struct trace {
1219 struct syscall *table; 1219 struct syscall *table;
1220 } syscalls; 1220 } syscalls;
1221 struct record_opts opts; 1221 struct record_opts opts;
1222 struct perf_evlist *evlist;
1222 struct machine *host; 1223 struct machine *host;
1224 struct thread *current;
1223 u64 base_time; 1225 u64 base_time;
1224 FILE *output; 1226 FILE *output;
1225 unsigned long nr_events; 1227 unsigned long nr_events;
@@ -1642,6 +1644,29 @@ static void thread__update_stats(struct thread_trace *ttrace,
1642 update_stats(stats, duration); 1644 update_stats(stats, duration);
1643} 1645}
1644 1646
1647static int trace__printf_interrupted_entry(struct trace *trace, struct perf_sample *sample)
1648{
1649 struct thread_trace *ttrace;
1650 u64 duration;
1651 size_t printed;
1652
1653 if (trace->current == NULL)
1654 return 0;
1655
1656 ttrace = thread__priv(trace->current);
1657
1658 if (!ttrace->entry_pending)
1659 return 0;
1660
1661 duration = sample->time - ttrace->entry_time;
1662
1663 printed = trace__fprintf_entry_head(trace, trace->current, duration, sample->time, trace->output);
1664 printed += fprintf(trace->output, "%-70s) ...\n", ttrace->entry_str);
1665 ttrace->entry_pending = false;
1666
1667 return printed;
1668}
1669
1645static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel, 1670static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1646 union perf_event *event __maybe_unused, 1671 union perf_event *event __maybe_unused,
1647 struct perf_sample *sample) 1672 struct perf_sample *sample)
@@ -1673,6 +1698,8 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1673 return -1; 1698 return -1;
1674 } 1699 }
1675 1700
1701 printed += trace__printf_interrupted_entry(trace, sample);
1702
1676 ttrace->entry_time = sample->time; 1703 ttrace->entry_time = sample->time;
1677 msg = ttrace->entry_str; 1704 msg = ttrace->entry_str;
1678 printed += scnprintf(msg + printed, 1024 - printed, "%s(", sc->name); 1705 printed += scnprintf(msg + printed, 1024 - printed, "%s(", sc->name);
@@ -1688,6 +1715,8 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
1688 } else 1715 } else
1689 ttrace->entry_pending = true; 1716 ttrace->entry_pending = true;
1690 1717
1718 trace->current = thread;
1719
1691 return 0; 1720 return 0;
1692} 1721}
1693 1722
@@ -1805,6 +1834,24 @@ out_dump:
1805 return 0; 1834 return 0;
1806} 1835}
1807 1836
1837static int trace__event_handler(struct trace *trace, struct perf_evsel *evsel,
1838 union perf_event *event __maybe_unused,
1839 struct perf_sample *sample)
1840{
1841 trace__printf_interrupted_entry(trace, sample);
1842 trace__fprintf_tstamp(trace, sample->time, trace->output);
1843 fprintf(trace->output, "(%9.9s): %s:", " ", evsel->name);
1844
1845 if (evsel->tp_format) {
1846 event_format__fprintf(evsel->tp_format, sample->cpu,
1847 sample->raw_data, sample->raw_size,
1848 trace->output);
1849 }
1850
1851 fprintf(trace->output, ")\n");
1852 return 0;
1853}
1854
1808static void print_location(FILE *f, struct perf_sample *sample, 1855static void print_location(FILE *f, struct perf_sample *sample,
1809 struct addr_location *al, 1856 struct addr_location *al,
1810 bool print_dso, bool print_sym) 1857 bool print_dso, bool print_sym)
@@ -2039,7 +2086,7 @@ static int perf_evlist__add_pgfault(struct perf_evlist *evlist,
2039 2086
2040static int trace__run(struct trace *trace, int argc, const char **argv) 2087static int trace__run(struct trace *trace, int argc, const char **argv)
2041{ 2088{
2042 struct perf_evlist *evlist = perf_evlist__new(); 2089 struct perf_evlist *evlist = trace->evlist;
2043 struct perf_evsel *evsel; 2090 struct perf_evsel *evsel;
2044 int err = -1, i; 2091 int err = -1, i;
2045 unsigned long before; 2092 unsigned long before;
@@ -2048,11 +2095,6 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
2048 2095
2049 trace->live = true; 2096 trace->live = true;
2050 2097
2051 if (evlist == NULL) {
2052 fprintf(trace->output, "Not enough memory to run!\n");
2053 goto out;
2054 }
2055
2056 if (trace->trace_syscalls && 2098 if (trace->trace_syscalls &&
2057 perf_evlist__add_syscall_newtp(evlist, trace__sys_enter, 2099 perf_evlist__add_syscall_newtp(evlist, trace__sys_enter,
2058 trace__sys_exit)) 2100 trace__sys_exit))
@@ -2109,12 +2151,14 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
2109 if (err < 0) 2151 if (err < 0)
2110 goto out_error_mmap; 2152 goto out_error_mmap;
2111 2153
2112 perf_evlist__enable(evlist);
2113
2114 if (forks) 2154 if (forks)
2115 perf_evlist__start_workload(evlist); 2155 perf_evlist__start_workload(evlist);
2156 else
2157 perf_evlist__enable(evlist);
2116 2158
2117 trace->multiple_threads = evlist->threads->map[0] == -1 || evlist->threads->nr > 1; 2159 trace->multiple_threads = evlist->threads->map[0] == -1 ||
2160 evlist->threads->nr > 1 ||
2161 perf_evlist__first(evlist)->attr.inherit;
2118again: 2162again:
2119 before = trace->nr_events; 2163 before = trace->nr_events;
2120 2164
@@ -2197,7 +2241,7 @@ out_disable:
2197 2241
2198out_delete_evlist: 2242out_delete_evlist:
2199 perf_evlist__delete(evlist); 2243 perf_evlist__delete(evlist);
2200out: 2244 trace->evlist = NULL;
2201 trace->live = false; 2245 trace->live = false;
2202 return err; 2246 return err;
2203{ 2247{
@@ -2468,6 +2512,14 @@ static int parse_pagefaults(const struct option *opt, const char *str,
2468 return 0; 2512 return 0;
2469} 2513}
2470 2514
2515static void evlist__set_evsel_handler(struct perf_evlist *evlist, void *handler)
2516{
2517 struct perf_evsel *evsel;
2518
2519 evlist__for_each(evlist, evsel)
2520 evsel->handler = handler;
2521}
2522
2471int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) 2523int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2472{ 2524{
2473 const char * const trace_usage[] = { 2525 const char * const trace_usage[] = {
@@ -2502,6 +2554,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2502 const char *output_name = NULL; 2554 const char *output_name = NULL;
2503 const char *ev_qualifier_str = NULL; 2555 const char *ev_qualifier_str = NULL;
2504 const struct option trace_options[] = { 2556 const struct option trace_options[] = {
2557 OPT_CALLBACK(0, "event", &trace.evlist, "event",
2558 "event selector. use 'perf list' to list available events",
2559 parse_events_option),
2505 OPT_BOOLEAN(0, "comm", &trace.show_comm, 2560 OPT_BOOLEAN(0, "comm", &trace.show_comm,
2506 "show the thread COMM next to its id"), 2561 "show the thread COMM next to its id"),
2507 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"), 2562 OPT_BOOLEAN(0, "tool_stats", &trace.show_tool_stats, "show tool stats"),
@@ -2543,6 +2598,15 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2543 int err; 2598 int err;
2544 char bf[BUFSIZ]; 2599 char bf[BUFSIZ];
2545 2600
2601 trace.evlist = perf_evlist__new();
2602 if (trace.evlist == NULL)
2603 return -ENOMEM;
2604
2605 if (trace.evlist == NULL) {
2606 pr_err("Not enough memory to run!\n");
2607 goto out;
2608 }
2609
2546 argc = parse_options(argc, argv, trace_options, trace_usage, 2610 argc = parse_options(argc, argv, trace_options, trace_usage,
2547 PARSE_OPT_STOP_AT_NON_OPTION); 2611 PARSE_OPT_STOP_AT_NON_OPTION);
2548 2612
@@ -2551,6 +2615,9 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2551 trace.opts.sample_time = true; 2615 trace.opts.sample_time = true;
2552 } 2616 }
2553 2617
2618 if (trace.evlist->nr_entries > 0)
2619 evlist__set_evsel_handler(trace.evlist, trace__event_handler);
2620
2554 if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) 2621 if ((argc >= 1) && (strcmp(argv[0], "record") == 0))
2555 return trace__record(&trace, argc-1, &argv[1]); 2622 return trace__record(&trace, argc-1, &argv[1]);
2556 2623
@@ -2558,7 +2625,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused)
2558 if (trace.summary_only) 2625 if (trace.summary_only)
2559 trace.summary = trace.summary_only; 2626 trace.summary = trace.summary_only;
2560 2627
2561 if (!trace.trace_syscalls && !trace.trace_pgfaults) { 2628 if (!trace.trace_syscalls && !trace.trace_pgfaults &&
2629 trace.evlist->nr_entries == 0 /* Was --events used? */) {
2562 pr_err("Please specify something to trace.\n"); 2630 pr_err("Please specify something to trace.\n");
2563 return -1; 2631 return -1;
2564 } 2632 }
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index cc224080b525..b97a7b903a23 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -11,19 +11,27 @@ ifneq ($(obj-perf),)
11obj-perf := $(abspath $(obj-perf))/ 11obj-perf := $(abspath $(obj-perf))/
12endif 12endif
13 13
14$(shell echo -n > .config-detected)
15detected = $(shell echo "$(1)=y" >> .config-detected)
16detected_var = $(shell echo "$(1)=$($(1))" >> .config-detected)
17
14LIB_INCLUDE := $(srctree)/tools/lib/ 18LIB_INCLUDE := $(srctree)/tools/lib/
15CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) 19CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
16 20
17include $(src-perf)/config/Makefile.arch 21include $(src-perf)/config/Makefile.arch
18 22
23$(call detected_var,ARCH)
24
19NO_PERF_REGS := 1 25NO_PERF_REGS := 1
20 26
21# Additional ARCH settings for x86 27# Additional ARCH settings for x86
22ifeq ($(ARCH),x86) 28ifeq ($(ARCH),x86)
29 $(call detected,CONFIG_X86)
23 ifeq (${IS_64_BIT}, 1) 30 ifeq (${IS_64_BIT}, 1)
24 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT 31 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
25 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S 32 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
26 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64 33 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
34 $(call detected,CONFIG_X86_64)
27 else 35 else
28 LIBUNWIND_LIBS = -lunwind -lunwind-x86 36 LIBUNWIND_LIBS = -lunwind -lunwind-x86
29 endif 37 endif
@@ -40,6 +48,10 @@ ifeq ($(ARCH),arm64)
40 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64 48 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
41endif 49endif
42 50
51ifeq ($(NO_PERF_REGS),0)
52 $(call detected,CONFIG_PERF_REGS)
53endif
54
43# So far there's only x86 and arm libdw unwind support merged in perf. 55# So far there's only x86 and arm libdw unwind support merged in perf.
44# Disable it on all other architectures in case libdw unwind 56# Disable it on all other architectures in case libdw unwind
45# support is detected in system. Add supported architectures 57# support is detected in system. Add supported architectures
@@ -114,6 +126,8 @@ ifdef PARSER_DEBUG
114 PARSER_DEBUG_BISON := -t 126 PARSER_DEBUG_BISON := -t
115 PARSER_DEBUG_FLEX := -d 127 PARSER_DEBUG_FLEX := -d
116 CFLAGS += -DPARSER_DEBUG 128 CFLAGS += -DPARSER_DEBUG
129 $(call detected_var,PARSER_DEBUG_BISON)
130 $(call detected_var,PARSER_DEBUG_FLEX)
117endif 131endif
118 132
119ifndef NO_LIBPYTHON 133ifndef NO_LIBPYTHON
@@ -361,6 +375,7 @@ endif # NO_LIBELF
361ifndef NO_LIBELF 375ifndef NO_LIBELF
362 CFLAGS += -DHAVE_LIBELF_SUPPORT 376 CFLAGS += -DHAVE_LIBELF_SUPPORT
363 EXTLIBS += -lelf 377 EXTLIBS += -lelf
378 $(call detected,CONFIG_LIBELF)
364 379
365 ifeq ($(feature-libelf-mmap), 1) 380 ifeq ($(feature-libelf-mmap), 1)
366 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT 381 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
@@ -381,6 +396,7 @@ ifndef NO_LIBELF
381 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS) 396 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
382 LDFLAGS += $(LIBDW_LDFLAGS) 397 LDFLAGS += $(LIBDW_LDFLAGS)
383 EXTLIBS += -ldw 398 EXTLIBS += -ldw
399 $(call detected,CONFIG_DWARF)
384 endif # PERF_HAVE_DWARF_REGS 400 endif # PERF_HAVE_DWARF_REGS
385 endif # NO_DWARF 401 endif # NO_DWARF
386endif # NO_LIBELF 402endif # NO_LIBELF
@@ -408,9 +424,11 @@ ifdef NO_LIBUNWIND
408 dwarf-post-unwind := 0 424 dwarf-post-unwind := 0
409 else 425 else
410 dwarf-post-unwind-text := libdw 426 dwarf-post-unwind-text := libdw
427 $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
411 endif 428 endif
412else 429else
413 dwarf-post-unwind-text := libunwind 430 dwarf-post-unwind-text := libunwind
431 $(call detected,CONFIG_LIBUNWIND)
414 # Enable libunwind support by default. 432 # Enable libunwind support by default.
415 ifndef NO_LIBDW_DWARF_UNWIND 433 ifndef NO_LIBDW_DWARF_UNWIND
416 NO_LIBDW_DWARF_UNWIND := 1 434 NO_LIBDW_DWARF_UNWIND := 1
@@ -419,6 +437,7 @@ endif
419 437
420ifeq ($(dwarf-post-unwind),1) 438ifeq ($(dwarf-post-unwind),1)
421 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT 439 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
440 $(call detected,CONFIG_DWARF_UNWIND)
422else 441else
423 NO_DWARF_UNWIND := 1 442 NO_DWARF_UNWIND := 1
424endif 443endif
@@ -447,6 +466,7 @@ ifndef NO_LIBAUDIT
447 else 466 else
448 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT 467 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
449 EXTLIBS += -laudit 468 EXTLIBS += -laudit
469 $(call detected,CONFIG_AUDIT)
450 endif 470 endif
451endif 471endif
452 472
@@ -463,6 +483,7 @@ ifndef NO_SLANG
463 CFLAGS += -I/usr/include/slang 483 CFLAGS += -I/usr/include/slang
464 CFLAGS += -DHAVE_SLANG_SUPPORT 484 CFLAGS += -DHAVE_SLANG_SUPPORT
465 EXTLIBS += -lslang 485 EXTLIBS += -lslang
486 $(call detected,CONFIG_SLANG)
466 endif 487 endif
467endif 488endif
468 489
@@ -501,6 +522,7 @@ else
501 else 522 else
502 LDFLAGS += $(PERL_EMBED_LDFLAGS) 523 LDFLAGS += $(PERL_EMBED_LDFLAGS)
503 EXTLIBS += $(PERL_EMBED_LIBADD) 524 EXTLIBS += $(PERL_EMBED_LIBADD)
525 $(call detected,CONFIG_LIBPERL)
504 endif 526 endif
505endif 527endif
506 528
@@ -560,6 +582,7 @@ else
560 LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 582 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
561 EXTLIBS += $(PYTHON_EMBED_LIBADD) 583 EXTLIBS += $(PYTHON_EMBED_LIBADD)
562 LANG_BINDINGS += $(obj-perf)python/perf.so 584 LANG_BINDINGS += $(obj-perf)python/perf.so
585 $(call detected,CONFIG_LIBPYTHON)
563 endif 586 endif
564 endif 587 endif
565 endif 588 endif
@@ -617,6 +640,7 @@ ifndef NO_ZLIB
617 ifeq ($(feature-zlib), 1) 640 ifeq ($(feature-zlib), 1)
618 CFLAGS += -DHAVE_ZLIB_SUPPORT 641 CFLAGS += -DHAVE_ZLIB_SUPPORT
619 EXTLIBS += -lz 642 EXTLIBS += -lz
643 $(call detected,CONFIG_ZLIB)
620 else 644 else
621 NO_ZLIB := 1 645 NO_ZLIB := 1
622 endif 646 endif
@@ -635,6 +659,7 @@ ifndef NO_LIBNUMA
635 else 659 else
636 CFLAGS += -DHAVE_LIBNUMA_SUPPORT 660 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
637 EXTLIBS += -lnuma 661 EXTLIBS += -lnuma
662 $(call detected,CONFIG_NUMA)
638 endif 663 endif
639endif 664endif
640 665
@@ -815,3 +840,19 @@ endif
815ifeq ($(display_lib),1) 840ifeq ($(display_lib),1)
816 $(info ) 841 $(info )
817endif 842endif
843
844$(call detected_var,bindir_SQ)
845$(call detected_var,PYTHON_WORD)
846ifneq ($(OUTPUT),)
847$(call detected_var,OUTPUT)
848endif
849$(call detected_var,htmldir_SQ)
850$(call detected_var,infodir_SQ)
851$(call detected_var,mandir_SQ)
852$(call detected_var,ETC_PERFCONFIG_SQ)
853$(call detected_var,prefix_SQ)
854$(call detected_var,perfexecdir_SQ)
855$(call detected_var,LIBDIR)
856$(call detected_var,GTK_CFLAGS)
857$(call detected_var,PERL_EMBED_CCOPTS)
858$(call detected_var,PYTHON_EMBED_CCOPTS)
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile
index 42ac05aaf8ac..b32ff3372514 100644
--- a/tools/perf/config/feature-checks/Makefile
+++ b/tools/perf/config/feature-checks/Makefile
@@ -49,7 +49,7 @@ test-hello.bin:
49 $(BUILD) 49 $(BUILD)
50 50
51test-pthread-attr-setaffinity-np.bin: 51test-pthread-attr-setaffinity-np.bin:
52 $(BUILD) -Werror -lpthread 52 $(BUILD) -D_GNU_SOURCE -Werror -lpthread
53 53
54test-stackprotector-all.bin: 54test-stackprotector-all.bin:
55 $(BUILD) -Werror -fstack-protector-all 55 $(BUILD) -Werror -fstack-protector-all
diff --git a/tools/perf/scripts/Build b/tools/perf/scripts/Build
new file mode 100644
index 000000000000..41efd7e368b3
--- /dev/null
+++ b/tools/perf/scripts/Build
@@ -0,0 +1,2 @@
1libperf-$(CONFIG_LIBPERL) += perl/Perf-Trace-Util/
2libperf-$(CONFIG_LIBPYTHON) += python/Perf-Trace-Util/
diff --git a/tools/perf/scripts/perl/Perf-Trace-Util/Build b/tools/perf/scripts/perl/Perf-Trace-Util/Build
new file mode 100644
index 000000000000..928e110179cb
--- /dev/null
+++ b/tools/perf/scripts/perl/Perf-Trace-Util/Build
@@ -0,0 +1,3 @@
1libperf-y += Context.o
2
3CFLAGS_Context.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs -Wno-undef -Wno-switch-default
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Build b/tools/perf/scripts/python/Perf-Trace-Util/Build
new file mode 100644
index 000000000000..aefc15c9444a
--- /dev/null
+++ b/tools/perf/scripts/python/Perf-Trace-Util/Build
@@ -0,0 +1,3 @@
1libperf-y += Context.o
2
3CFLAGS_Context.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
new file mode 100644
index 000000000000..2de01a4b4084
--- /dev/null
+++ b/tools/perf/tests/Build
@@ -0,0 +1,42 @@
1perf-y += builtin-test.o
2perf-y += parse-events.o
3perf-y += dso-data.o
4perf-y += attr.o
5perf-y += vmlinux-kallsyms.o
6perf-y += open-syscall.o
7perf-y += open-syscall-all-cpus.o
8perf-y += open-syscall-tp-fields.o
9perf-y += mmap-basic.o
10perf-y += perf-record.o
11perf-y += rdpmc.o
12perf-y += evsel-roundtrip-name.o
13perf-y += evsel-tp-sched.o
14perf-y += fdarray.o
15perf-y += pmu.o
16perf-y += hists_common.o
17perf-y += hists_link.o
18perf-y += hists_filter.o
19perf-y += hists_output.o
20perf-y += hists_cumulate.o
21perf-y += python-use.o
22perf-y += bp_signal.o
23perf-y += bp_signal_overflow.o
24perf-y += task-exit.o
25perf-y += sw-clock.o
26perf-y += mmap-thread-lookup.o
27perf-y += thread-mg-share.o
28perf-y += switch-tracking.o
29perf-y += keep-tracking.o
30perf-y += code-reading.o
31perf-y += sample-parsing.o
32perf-y += parse-no-sample-id-all.o
33
34perf-$(CONFIG_X86) += perf-time-to-tsc.o
35
36ifeq ($(ARCH),$(filter $(ARCH),x86 arm))
37perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
38endif
39
40CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
41CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
42CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c
index caaf37f079b1..513e5febbe5a 100644
--- a/tools/perf/tests/dso-data.c
+++ b/tools/perf/tests/dso-data.c
@@ -112,6 +112,9 @@ int test__dso_data(void)
112 112
113 dso = dso__new((const char *)file); 113 dso = dso__new((const char *)file);
114 114
115 TEST_ASSERT_VAL("Failed to access to dso",
116 dso__data_fd(dso, &machine) >= 0);
117
115 /* Basic 10 bytes tests. */ 118 /* Basic 10 bytes tests. */
116 for (i = 0; i < ARRAY_SIZE(offsets); i++) { 119 for (i = 0; i < ARRAY_SIZE(offsets); i++) {
117 struct test_data_offset *data = &offsets[i]; 120 struct test_data_offset *data = &offsets[i];
@@ -243,8 +246,8 @@ int test__dso_data_cache(void)
243 limit = nr * 4; 246 limit = nr * 4;
244 TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit(limit)); 247 TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit(limit));
245 248
246 /* and this is now our dso open FDs limit + 1 extra */ 249 /* and this is now our dso open FDs limit */
247 dso_cnt = limit / 2 + 1; 250 dso_cnt = limit / 2;
248 TEST_ASSERT_VAL("failed to create dsos\n", 251 TEST_ASSERT_VAL("failed to create dsos\n",
249 !dsos__create(dso_cnt, TEST_FILE_SIZE)); 252 !dsos__create(dso_cnt, TEST_FILE_SIZE));
250 253
@@ -252,13 +255,13 @@ int test__dso_data_cache(void)
252 struct dso *dso = dsos[i]; 255 struct dso *dso = dsos[i];
253 256
254 /* 257 /*
255 * Open dsos via dso__data_fd or dso__data_read_offset. 258 * Open dsos via dso__data_fd(), it opens the data
256 * Both opens the data file and keep it open. 259 * file and keep it open (unless open file limit).
257 */ 260 */
261 fd = dso__data_fd(dso, &machine);
262 TEST_ASSERT_VAL("failed to get fd", fd > 0);
263
258 if (i % 2) { 264 if (i % 2) {
259 fd = dso__data_fd(dso, &machine);
260 TEST_ASSERT_VAL("failed to get fd", fd > 0);
261 } else {
262 #define BUFSIZE 10 265 #define BUFSIZE 10
263 u8 buf[BUFSIZE]; 266 u8 buf[BUFSIZE];
264 ssize_t n; 267 ssize_t n;
@@ -268,7 +271,10 @@ int test__dso_data_cache(void)
268 } 271 }
269 } 272 }
270 273
271 /* open +1 dso over the allowed limit */ 274 /* verify the first one is already open */
275 TEST_ASSERT_VAL("dsos[0] is not open", dsos[0]->data.fd != -1);
276
277 /* open +1 dso to reach the allowed limit */
272 fd = dso__data_fd(dsos[i], &machine); 278 fd = dso__data_fd(dsos[i], &machine);
273 TEST_ASSERT_VAL("failed to get fd", fd > 0); 279 TEST_ASSERT_VAL("failed to get fd", fd > 0);
274 280
diff --git a/tools/perf/tests/open-syscall-all-cpus.c b/tools/perf/tests/open-syscall-all-cpus.c
index 8fa82d1700c7..3ec885c48f8f 100644
--- a/tools/perf/tests/open-syscall-all-cpus.c
+++ b/tools/perf/tests/open-syscall-all-cpus.c
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
29 29
30 evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); 30 evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
31 if (evsel == NULL) { 31 if (evsel == NULL) {
32 pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 32 if (tracefs_configured())
33 pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
34 else if (debugfs_configured())
35 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
36 else
37 pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
33 goto out_thread_map_delete; 38 goto out_thread_map_delete;
34 } 39 }
35 40
diff --git a/tools/perf/tests/open-syscall.c b/tools/perf/tests/open-syscall.c
index a33b2daae40f..07aa319bf334 100644
--- a/tools/perf/tests/open-syscall.c
+++ b/tools/perf/tests/open-syscall.c
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
18 18
19 evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); 19 evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
20 if (evsel == NULL) { 20 if (evsel == NULL) {
21 pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 21 if (tracefs_configured())
22 pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
23 else if (debugfs_configured())
24 pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
25 else
26 pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
22 goto out_thread_map_delete; 27 goto out_thread_map_delete;
23 } 28 }
24 29
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 1cdab0ce00e2..ac243ebcb20a 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -3,6 +3,7 @@
3#include "evsel.h" 3#include "evsel.h"
4#include "evlist.h" 4#include "evlist.h"
5#include <api/fs/fs.h> 5#include <api/fs/fs.h>
6#include <api/fs/tracefs.h>
6#include <api/fs/debugfs.h> 7#include <api/fs/debugfs.h>
7#include "tests.h" 8#include "tests.h"
8#include "debug.h" 9#include "debug.h"
@@ -1192,11 +1193,19 @@ static int count_tracepoints(void)
1192{ 1193{
1193 char events_path[PATH_MAX]; 1194 char events_path[PATH_MAX];
1194 struct dirent *events_ent; 1195 struct dirent *events_ent;
1196 const char *mountpoint;
1195 DIR *events_dir; 1197 DIR *events_dir;
1196 int cnt = 0; 1198 int cnt = 0;
1197 1199
1198 scnprintf(events_path, PATH_MAX, "%s/tracing/events", 1200 mountpoint = tracefs_find_mountpoint();
1199 debugfs_find_mountpoint()); 1201 if (mountpoint) {
1202 scnprintf(events_path, PATH_MAX, "%s/events",
1203 mountpoint);
1204 } else {
1205 mountpoint = debugfs_find_mountpoint();
1206 scnprintf(events_path, PATH_MAX, "%s/tracing/events",
1207 mountpoint);
1208 }
1200 1209
1201 events_dir = opendir(events_path); 1210 events_dir = opendir(events_path);
1202 1211
diff --git a/tools/perf/ui/Build b/tools/perf/ui/Build
new file mode 100644
index 000000000000..0a73538c0441
--- /dev/null
+++ b/tools/perf/ui/Build
@@ -0,0 +1,14 @@
1libperf-y += setup.o
2libperf-y += helpline.o
3libperf-y += progress.o
4libperf-y += util.o
5libperf-y += hist.o
6libperf-y += stdio/hist.o
7
8CFLAGS_setup.o += -DLIBDIR="BUILD_STR($(LIBDIR))"
9
10libperf-$(CONFIG_SLANG) += browser.o
11libperf-$(CONFIG_SLANG) += browsers/
12libperf-$(CONFIG_SLANG) += tui/
13
14CFLAGS_browser.o += -DENABLE_SLFUTURE_CONST
diff --git a/tools/perf/ui/browsers/Build b/tools/perf/ui/browsers/Build
new file mode 100644
index 000000000000..de223f5bed58
--- /dev/null
+++ b/tools/perf/ui/browsers/Build
@@ -0,0 +1,10 @@
1libperf-y += annotate.o
2libperf-y += hists.o
3libperf-y += map.o
4libperf-y += scripts.o
5libperf-y += header.o
6
7CFLAGS_annotate.o += -DENABLE_SLFUTURE_CONST
8CFLAGS_hists.o += -DENABLE_SLFUTURE_CONST
9CFLAGS_map.o += -DENABLE_SLFUTURE_CONST
10CFLAGS_scripts.o += -DENABLE_SLFUTURE_CONST
diff --git a/tools/perf/ui/gtk/Build b/tools/perf/ui/gtk/Build
new file mode 100644
index 000000000000..ec22e899a224
--- /dev/null
+++ b/tools/perf/ui/gtk/Build
@@ -0,0 +1,9 @@
1CFLAGS_gtk += -fPIC $(GTK_CFLAGS)
2
3gtk-y += browser.o
4gtk-y += hists.o
5gtk-y += setup.o
6gtk-y += util.o
7gtk-y += helpline.o
8gtk-y += progress.o
9gtk-y += annotate.o
diff --git a/tools/perf/ui/tui/Build b/tools/perf/ui/tui/Build
new file mode 100644
index 000000000000..9e4c6ca41a9f
--- /dev/null
+++ b/tools/perf/ui/tui/Build
@@ -0,0 +1,4 @@
1libperf-y += setup.o
2libperf-y += util.o
3libperf-y += helpline.o
4libperf-y += progress.o
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
new file mode 100644
index 000000000000..32f9327b1a97
--- /dev/null
+++ b/tools/perf/util/Build
@@ -0,0 +1,142 @@
1libperf-y += abspath.o
2libperf-y += alias.o
3libperf-y += annotate.o
4libperf-y += build-id.o
5libperf-y += config.o
6libperf-y += ctype.o
7libperf-y += db-export.o
8libperf-y += environment.o
9libperf-y += event.o
10libperf-y += evlist.o
11libperf-y += evsel.o
12libperf-y += exec_cmd.o
13libperf-y += find_next_bit.o
14libperf-y += help.o
15libperf-y += kallsyms.o
16libperf-y += levenshtein.o
17libperf-y += parse-options.o
18libperf-y += parse-events.o
19libperf-y += path.o
20libperf-y += rbtree.o
21libperf-y += bitmap.o
22libperf-y += hweight.o
23libperf-y += run-command.o
24libperf-y += quote.o
25libperf-y += strbuf.o
26libperf-y += string.o
27libperf-y += strlist.o
28libperf-y += strfilter.o
29libperf-y += top.o
30libperf-y += usage.o
31libperf-y += wrapper.o
32libperf-y += sigchain.o
33libperf-y += dso.o
34libperf-y += symbol.o
35libperf-y += color.o
36libperf-y += pager.o
37libperf-y += header.o
38libperf-y += callchain.o
39libperf-y += values.o
40libperf-y += debug.o
41libperf-y += machine.o
42libperf-y += map.o
43libperf-y += pstack.o
44libperf-y += session.o
45libperf-y += ordered-events.o
46libperf-y += comm.o
47libperf-y += thread.o
48libperf-y += thread_map.o
49libperf-y += trace-event-parse.o
50libperf-y += parse-events-flex.o
51libperf-y += parse-events-bison.o
52libperf-y += pmu.o
53libperf-y += pmu-flex.o
54libperf-y += pmu-bison.o
55libperf-y += trace-event-read.o
56libperf-y += trace-event-info.o
57libperf-y += trace-event-scripting.o
58libperf-y += trace-event.o
59libperf-y += svghelper.o
60libperf-y += sort.o
61libperf-y += hist.o
62libperf-y += util.o
63libperf-y += xyarray.o
64libperf-y += cpumap.o
65libperf-y += cgroup.o
66libperf-y += target.o
67libperf-y += rblist.o
68libperf-y += intlist.o
69libperf-y += vdso.o
70libperf-y += stat.o
71libperf-y += record.o
72libperf-y += srcline.o
73libperf-y += data.o
74libperf-y += tsc.o
75libperf-y += cloexec.o
76libperf-y += thread-stack.o
77
78libperf-$(CONFIG_LIBELF) += symbol-elf.o
79libperf-$(CONFIG_LIBELF) += probe-event.o
80
81ifndef CONFIG_LIBELF
82libperf-y += symbol-minimal.o
83endif
84
85libperf-$(CONFIG_DWARF) += probe-finder.o
86libperf-$(CONFIG_DWARF) += dwarf-aux.o
87
88libperf-$(CONFIG_LIBDW_DWARF_UNWIND) += unwind-libdw.o
89libperf-$(CONFIG_LIBUNWIND) += unwind-libunwind.o
90
91libperf-y += scripting-engines/
92
93libperf-$(CONFIG_PERF_REGS) += perf_regs.o
94libperf-$(CONFIG_ZLIB) += zlib.o
95
96CFLAGS_config.o += -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
97CFLAGS_exec_cmd.o += -DPERF_EXEC_PATH="BUILD_STR($(perfexecdir_SQ))" -DPREFIX="BUILD_STR($(prefix_SQ))"
98
99$(OUTPUT)util/parse-events-flex.c: util/parse-events.l $(OUTPUT)util/parse-events-bison.c
100 $(call rule_mkdir)
101 @$(call echo-cmd,flex)$(FLEX) -o $@ --header-file=$(OUTPUT)util/parse-events-flex.h $(PARSER_DEBUG_FLEX) util/parse-events.l
102
103$(OUTPUT)util/parse-events-bison.c: util/parse-events.y
104 $(call rule_mkdir)
105 @$(call echo-cmd,bison)$(BISON) -v util/parse-events.y -d $(PARSER_DEBUG_BISON) -o $@ -p parse_events_
106
107$(OUTPUT)util/pmu-flex.c: util/pmu.l $(OUTPUT)util/pmu-bison.c
108 $(call rule_mkdir)
109 @$(call echo-cmd,flex)$(FLEX) -o $@ --header-file=$(OUTPUT)util/pmu-flex.h util/pmu.l
110
111$(OUTPUT)util/pmu-bison.c: util/pmu.y
112 $(call rule_mkdir)
113 @$(call echo-cmd,bison)$(BISON) -v util/pmu.y -d -o $@ -p perf_pmu_
114
115CFLAGS_parse-events-flex.o += -w
116CFLAGS_pmu-flex.o += -w
117CFLAGS_parse-events-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w
118CFLAGS_pmu-bison.o += -DYYENABLE_NLS=0 -DYYLTYPE_IS_TRIVIAL=0 -w
119
120$(OUTPUT)util/parse-events.o: $(OUTPUT)util/parse-events-flex.c $(OUTPUT)util/parse-events-bison.c
121$(OUTPUT)util/pmu.o: $(OUTPUT)util/pmu-flex.c $(OUTPUT)util/pmu-bison.c
122
123CFLAGS_find_next_bit.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
124CFLAGS_rbtree.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
125CFLAGS_hweight.o += -Wno-unused-parameter -DETC_PERFCONFIG="BUILD_STR($(ETC_PERFCONFIG_SQ))"
126CFLAGS_parse-events.o += -Wno-redundant-decls
127
128$(OUTPUT)util/kallsyms.o: ../lib/symbol/kallsyms.c FORCE
129 $(call rule_mkdir)
130 $(call if_changed_dep,cc_o_c)
131
132$(OUTPUT)util/find_next_bit.o: ../lib/util/find_next_bit.c FORCE
133 $(call rule_mkdir)
134 $(call if_changed_dep,cc_o_c)
135
136$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c FORCE
137 $(call rule_mkdir)
138 $(call if_changed_dep,cc_o_c)
139
140$(OUTPUT)util/hweight.o: ../../lib/hweight.c FORCE
141 $(call rule_mkdir)
142 $(call if_changed_dep,cc_o_c)
diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 0c72680a977f..adbc36028636 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -93,6 +93,35 @@ int build_id__sprintf(const u8 *build_id, int len, char *bf)
93 return raw - build_id; 93 return raw - build_id;
94} 94}
95 95
96/* asnprintf consolidates asprintf and snprintf */
97static int asnprintf(char **strp, size_t size, const char *fmt, ...)
98{
99 va_list ap;
100 int ret;
101
102 if (!strp)
103 return -EINVAL;
104
105 va_start(ap, fmt);
106 if (*strp)
107 ret = vsnprintf(*strp, size, fmt, ap);
108 else
109 ret = vasprintf(strp, fmt, ap);
110 va_end(ap);
111
112 return ret;
113}
114
115static char *build_id__filename(const char *sbuild_id, char *bf, size_t size)
116{
117 char *tmp = bf;
118 int ret = asnprintf(&bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
119 sbuild_id, sbuild_id + 2);
120 if (ret < 0 || (tmp && size < (unsigned int)ret))
121 return NULL;
122 return bf;
123}
124
96char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size) 125char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size)
97{ 126{
98 char build_id_hex[BUILD_ID_SIZE * 2 + 1]; 127 char build_id_hex[BUILD_ID_SIZE * 2 + 1];
@@ -101,14 +130,7 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size)
101 return NULL; 130 return NULL;
102 131
103 build_id__sprintf(dso->build_id, sizeof(dso->build_id), build_id_hex); 132 build_id__sprintf(dso->build_id, sizeof(dso->build_id), build_id_hex);
104 if (bf == NULL) { 133 return build_id__filename(build_id_hex, bf, size);
105 if (asprintf(&bf, "%s/.build-id/%.2s/%s", buildid_dir,
106 build_id_hex, build_id_hex + 2) < 0)
107 return NULL;
108 } else
109 snprintf(bf, size, "%s/.build-id/%.2s/%s", buildid_dir,
110 build_id_hex, build_id_hex + 2);
111 return bf;
112} 134}
113 135
114#define dsos__for_each_with_build_id(pos, head) \ 136#define dsos__for_each_with_build_id(pos, head) \
@@ -259,12 +281,12 @@ void disable_buildid_cache(void)
259 no_buildid_cache = true; 281 no_buildid_cache = true;
260} 282}
261 283
262int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, 284int build_id_cache__add_s(const char *sbuild_id, const char *name,
263 const char *name, bool is_kallsyms, bool is_vdso) 285 bool is_kallsyms, bool is_vdso)
264{ 286{
265 const size_t size = PATH_MAX; 287 const size_t size = PATH_MAX;
266 char *realname, *filename = zalloc(size), 288 char *realname, *filename = zalloc(size),
267 *linkname = zalloc(size), *targetname; 289 *linkname = zalloc(size), *targetname, *tmp;
268 int len, err = -1; 290 int len, err = -1;
269 bool slash = is_kallsyms || is_vdso; 291 bool slash = is_kallsyms || is_vdso;
270 292
@@ -282,7 +304,7 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
282 goto out_free; 304 goto out_free;
283 305
284 len = scnprintf(filename, size, "%s%s%s", 306 len = scnprintf(filename, size, "%s%s%s",
285 debugdir, slash ? "/" : "", 307 buildid_dir, slash ? "/" : "",
286 is_vdso ? DSO__NAME_VDSO : realname); 308 is_vdso ? DSO__NAME_VDSO : realname);
287 if (mkdir_p(filename, 0755)) 309 if (mkdir_p(filename, 0755))
288 goto out_free; 310 goto out_free;
@@ -297,14 +319,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
297 goto out_free; 319 goto out_free;
298 } 320 }
299 321
300 len = scnprintf(linkname, size, "%s/.build-id/%.2s", 322 if (!build_id__filename(sbuild_id, linkname, size))
301 debugdir, sbuild_id); 323 goto out_free;
324 tmp = strrchr(linkname, '/');
325 *tmp = '\0';
302 326
303 if (access(linkname, X_OK) && mkdir_p(linkname, 0755)) 327 if (access(linkname, X_OK) && mkdir_p(linkname, 0755))
304 goto out_free; 328 goto out_free;
305 329
306 snprintf(linkname + len, size - len, "/%s", sbuild_id + 2); 330 *tmp = '/';
307 targetname = filename + strlen(debugdir) - 5; 331 targetname = filename + strlen(buildid_dir) - 5;
308 memcpy(targetname, "../..", 5); 332 memcpy(targetname, "../..", 5);
309 333
310 if (symlink(targetname, linkname) == 0) 334 if (symlink(targetname, linkname) == 0)
@@ -318,29 +342,28 @@ out_free:
318} 342}
319 343
320static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size, 344static int build_id_cache__add_b(const u8 *build_id, size_t build_id_size,
321 const char *name, const char *debugdir, 345 const char *name, bool is_kallsyms,
322 bool is_kallsyms, bool is_vdso) 346 bool is_vdso)
323{ 347{
324 char sbuild_id[BUILD_ID_SIZE * 2 + 1]; 348 char sbuild_id[BUILD_ID_SIZE * 2 + 1];
325 349
326 build_id__sprintf(build_id, build_id_size, sbuild_id); 350 build_id__sprintf(build_id, build_id_size, sbuild_id);
327 351
328 return build_id_cache__add_s(sbuild_id, debugdir, name, 352 return build_id_cache__add_s(sbuild_id, name, is_kallsyms, is_vdso);
329 is_kallsyms, is_vdso);
330} 353}
331 354
332int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir) 355int build_id_cache__remove_s(const char *sbuild_id)
333{ 356{
334 const size_t size = PATH_MAX; 357 const size_t size = PATH_MAX;
335 char *filename = zalloc(size), 358 char *filename = zalloc(size),
336 *linkname = zalloc(size); 359 *linkname = zalloc(size), *tmp;
337 int err = -1; 360 int err = -1;
338 361
339 if (filename == NULL || linkname == NULL) 362 if (filename == NULL || linkname == NULL)
340 goto out_free; 363 goto out_free;
341 364
342 snprintf(linkname, size, "%s/.build-id/%.2s/%s", 365 if (!build_id__filename(sbuild_id, linkname, size))
343 debugdir, sbuild_id, sbuild_id + 2); 366 goto out_free;
344 367
345 if (access(linkname, F_OK)) 368 if (access(linkname, F_OK))
346 goto out_free; 369 goto out_free;
@@ -354,8 +377,8 @@ int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir)
354 /* 377 /*
355 * Since the link is relative, we must make it absolute: 378 * Since the link is relative, we must make it absolute:
356 */ 379 */
357 snprintf(linkname, size, "%s/.build-id/%.2s/%s", 380 tmp = strrchr(linkname, '/') + 1;
358 debugdir, sbuild_id, filename); 381 snprintf(tmp, size - (tmp - linkname), "%s", filename);
359 382
360 if (unlink(linkname)) 383 if (unlink(linkname))
361 goto out_free; 384 goto out_free;
@@ -367,8 +390,7 @@ out_free:
367 return err; 390 return err;
368} 391}
369 392
370static int dso__cache_build_id(struct dso *dso, struct machine *machine, 393static int dso__cache_build_id(struct dso *dso, struct machine *machine)
371 const char *debugdir)
372{ 394{
373 bool is_kallsyms = dso->kernel && dso->long_name[0] != '/'; 395 bool is_kallsyms = dso->kernel && dso->long_name[0] != '/';
374 bool is_vdso = dso__is_vdso(dso); 396 bool is_vdso = dso__is_vdso(dso);
@@ -381,28 +403,26 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine,
381 name = nm; 403 name = nm;
382 } 404 }
383 return build_id_cache__add_b(dso->build_id, sizeof(dso->build_id), name, 405 return build_id_cache__add_b(dso->build_id, sizeof(dso->build_id), name,
384 debugdir, is_kallsyms, is_vdso); 406 is_kallsyms, is_vdso);
385} 407}
386 408
387static int __dsos__cache_build_ids(struct list_head *head, 409static int __dsos__cache_build_ids(struct list_head *head,
388 struct machine *machine, const char *debugdir) 410 struct machine *machine)
389{ 411{
390 struct dso *pos; 412 struct dso *pos;
391 int err = 0; 413 int err = 0;
392 414
393 dsos__for_each_with_build_id(pos, head) 415 dsos__for_each_with_build_id(pos, head)
394 if (dso__cache_build_id(pos, machine, debugdir)) 416 if (dso__cache_build_id(pos, machine))
395 err = -1; 417 err = -1;
396 418
397 return err; 419 return err;
398} 420}
399 421
400static int machine__cache_build_ids(struct machine *machine, const char *debugdir) 422static int machine__cache_build_ids(struct machine *machine)
401{ 423{
402 int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine, 424 int ret = __dsos__cache_build_ids(&machine->kernel_dsos.head, machine);
403 debugdir); 425 ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine);
404 ret |= __dsos__cache_build_ids(&machine->user_dsos.head, machine,
405 debugdir);
406 return ret; 426 return ret;
407} 427}
408 428
@@ -417,11 +437,11 @@ int perf_session__cache_build_ids(struct perf_session *session)
417 if (mkdir(buildid_dir, 0755) != 0 && errno != EEXIST) 437 if (mkdir(buildid_dir, 0755) != 0 && errno != EEXIST)
418 return -1; 438 return -1;
419 439
420 ret = machine__cache_build_ids(&session->machines.host, buildid_dir); 440 ret = machine__cache_build_ids(&session->machines.host);
421 441
422 for (nd = rb_first(&session->machines.guests); nd; nd = rb_next(nd)) { 442 for (nd = rb_first(&session->machines.guests); nd; nd = rb_next(nd)) {
423 struct machine *pos = rb_entry(nd, struct machine, rb_node); 443 struct machine *pos = rb_entry(nd, struct machine, rb_node);
424 ret |= machine__cache_build_ids(pos, buildid_dir); 444 ret |= machine__cache_build_ids(pos);
425 } 445 }
426 return ret ? -1 : 0; 446 return ret ? -1 : 0;
427} 447}
diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h
index 8236319514d5..31b3c6332a1a 100644
--- a/tools/perf/util/build-id.h
+++ b/tools/perf/util/build-id.h
@@ -22,9 +22,9 @@ bool perf_session__read_build_ids(struct perf_session *session, bool with_hits);
22int perf_session__write_buildid_table(struct perf_session *session, int fd); 22int perf_session__write_buildid_table(struct perf_session *session, int fd);
23int perf_session__cache_build_ids(struct perf_session *session); 23int perf_session__cache_build_ids(struct perf_session *session);
24 24
25int build_id_cache__add_s(const char *sbuild_id, const char *debugdir, 25int build_id_cache__add_s(const char *sbuild_id,
26 const char *name, bool is_kallsyms, bool is_vdso); 26 const char *name, bool is_kallsyms, bool is_vdso);
27int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir); 27int build_id_cache__remove_s(const char *sbuild_id);
28void disable_buildid_cache(void); 28void disable_buildid_cache(void);
29 29
30#endif 30#endif
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index d04d770d90f6..fbcca21d66ab 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -17,6 +17,7 @@
17#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" 17#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
18#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" 18#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
19#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" 19#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
20#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
20 21
21typedef int (*config_fn_t)(const char *, const char *, void *); 22typedef int (*config_fn_t)(const char *, const char *, void *);
22extern int perf_default_config(const char *, const char *, void *); 23extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index c2f7d3b90966..814554d1b857 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -45,13 +45,13 @@ int dso__read_binary_type_filename(const struct dso *dso,
45 case DSO_BINARY_TYPE__DEBUGLINK: { 45 case DSO_BINARY_TYPE__DEBUGLINK: {
46 char *debuglink; 46 char *debuglink;
47 47
48 strncpy(filename, dso->long_name, size); 48 len = __symbol__join_symfs(filename, size, dso->long_name);
49 debuglink = filename + dso->long_name_len; 49 debuglink = filename + len;
50 while (debuglink != filename && *debuglink != '/') 50 while (debuglink != filename && *debuglink != '/')
51 debuglink--; 51 debuglink--;
52 if (*debuglink == '/') 52 if (*debuglink == '/')
53 debuglink++; 53 debuglink++;
54 ret = filename__read_debuglink(dso->long_name, debuglink, 54 ret = filename__read_debuglink(filename, debuglink,
55 size - (debuglink - filename)); 55 size - (debuglink - filename));
56 } 56 }
57 break; 57 break;
@@ -240,7 +240,7 @@ static int do_open(char *name)
240 if (fd >= 0) 240 if (fd >= 0)
241 return fd; 241 return fd;
242 242
243 pr_debug("dso open failed, mmap: %s\n", 243 pr_debug("dso open failed: %s\n",
244 strerror_r(errno, sbuf, sizeof(sbuf))); 244 strerror_r(errno, sbuf, sizeof(sbuf)));
245 if (!dso__data_open_cnt || errno != EMFILE) 245 if (!dso__data_open_cnt || errno != EMFILE)
246 break; 246 break;
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index cc66c4049e09..780b2bc11128 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -278,6 +278,21 @@ bool die_is_func_def(Dwarf_Die *dw_die)
278} 278}
279 279
280/** 280/**
281 * die_is_func_instance - Ensure that this DIE is an instance of a subprogram
282 * @dw_die: a DIE
283 *
284 * Ensure that this DIE is an instance (which has an entry address).
285 * This returns true if @dw_die is a function instance. If not, you need to
286 * call die_walk_instances() to find actual instances.
287 **/
288bool die_is_func_instance(Dwarf_Die *dw_die)
289{
290 Dwarf_Addr tmp;
291
292 /* Actually gcc optimizes non-inline as like as inlined */
293 return !dwarf_func_inline(dw_die) && dwarf_entrypc(dw_die, &tmp) == 0;
294}
295/**
281 * die_get_data_member_location - Get the data-member offset 296 * die_get_data_member_location - Get the data-member offset
282 * @mb_die: a DIE of a member of a data structure 297 * @mb_die: a DIE of a member of a data structure
283 * @offs: The offset of the member in the data structure 298 * @offs: The offset of the member in the data structure
diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h
index b4fe90c6cb2d..af7dbcd5f929 100644
--- a/tools/perf/util/dwarf-aux.h
+++ b/tools/perf/util/dwarf-aux.h
@@ -41,6 +41,9 @@ extern int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
41/* Ensure that this DIE is a subprogram and definition (not declaration) */ 41/* Ensure that this DIE is a subprogram and definition (not declaration) */
42extern bool die_is_func_def(Dwarf_Die *dw_die); 42extern bool die_is_func_def(Dwarf_Die *dw_die);
43 43
44/* Ensure that this DIE is an instance of a subprogram */
45extern bool die_is_func_instance(Dwarf_Die *dw_die);
46
44/* Compare diename and tname */ 47/* Compare diename and tname */
45extern bool die_compare_name(Dwarf_Die *dw_die, const char *tname); 48extern bool die_compare_name(Dwarf_Die *dw_die, const char *tname);
46 49
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 28b8ce86bf12..a8b2c5726aba 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,6 @@
7 * Released under the GPL v2. (and only v2, not any later version) 7 * Released under the GPL v2. (and only v2, not any later version)
8 */ 8 */
9#include "util.h" 9#include "util.h"
10#include <api/fs/debugfs.h>
11#include <api/fs/fs.h> 10#include <api/fs/fs.h>
12#include <poll.h> 11#include <poll.h>
13#include "cpumap.h" 12#include "cpumap.h"
@@ -1329,7 +1328,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, struct target *tar
1329 * writing exactly one byte, in workload.cork_fd, usually via 1328 * writing exactly one byte, in workload.cork_fd, usually via
1330 * perf_evlist__start_workload(). 1329 * perf_evlist__start_workload().
1331 * 1330 *
1332 * For cancelling the workload without actuallin running it, 1331 * For cancelling the workload without actually running it,
1333 * the parent will just close workload.cork_fd, without writing 1332 * the parent will just close workload.cork_fd, without writing
1334 * anything, i.e. read will return zero and we just exit() 1333 * anything, i.e. read will return zero and we just exit()
1335 * here. 1334 * here.
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 7f8ec6ce2823..109ba5c8c2e5 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -175,9 +175,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
175 char evt_path[MAXPATHLEN]; 175 char evt_path[MAXPATHLEN];
176 char dir_path[MAXPATHLEN]; 176 char dir_path[MAXPATHLEN];
177 177
178 if (debugfs_valid_mountpoint(tracing_events_path))
179 return NULL;
180
181 sys_dir = opendir(tracing_events_path); 178 sys_dir = opendir(tracing_events_path);
182 if (!sys_dir) 179 if (!sys_dir)
183 return NULL; 180 return NULL;
@@ -473,12 +470,6 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
473int parse_events_add_tracepoint(struct list_head *list, int *idx, 470int parse_events_add_tracepoint(struct list_head *list, int *idx,
474 char *sys, char *event) 471 char *sys, char *event)
475{ 472{
476 int ret;
477
478 ret = debugfs_valid_mountpoint(tracing_events_path);
479 if (ret)
480 return ret;
481
482 if (strpbrk(sys, "*?")) 473 if (strpbrk(sys, "*?"))
483 return add_tracepoint_multi_sys(list, idx, sys, event); 474 return add_tracepoint_multi_sys(list, idx, sys, event);
484 else 475 else
@@ -1109,13 +1100,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
1109 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent; 1100 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
1110 char evt_path[MAXPATHLEN]; 1101 char evt_path[MAXPATHLEN];
1111 char dir_path[MAXPATHLEN]; 1102 char dir_path[MAXPATHLEN];
1112 char sbuf[STRERR_BUFSIZE];
1113
1114 if (debugfs_valid_mountpoint(tracing_events_path)) {
1115 printf(" [ Tracepoints not available: %s ]\n",
1116 strerror_r(errno, sbuf, sizeof(sbuf)));
1117 return;
1118 }
1119 1103
1120 sys_dir = opendir(tracing_events_path); 1104 sys_dir = opendir(tracing_events_path);
1121 if (!sys_dir) 1105 if (!sys_dir)
@@ -1163,9 +1147,6 @@ int is_valid_tracepoint(const char *event_string)
1163 char evt_path[MAXPATHLEN]; 1147 char evt_path[MAXPATHLEN];
1164 char dir_path[MAXPATHLEN]; 1148 char dir_path[MAXPATHLEN];
1165 1149
1166 if (debugfs_valid_mountpoint(tracing_events_path))
1167 return 0;
1168
1169 sys_dir = opendir(tracing_events_path); 1150 sys_dir = opendir(tracing_events_path);
1170 if (!sys_dir) 1151 if (!sys_dir)
1171 return 0; 1152 return 0;
@@ -1338,11 +1319,6 @@ static void print_symbol_events(const char *event_glob, unsigned type,
1338 */ 1319 */
1339void print_events(const char *event_glob, bool name_only) 1320void print_events(const char *event_glob, bool name_only)
1340{ 1321{
1341 if (!name_only) {
1342 printf("\n");
1343 printf("List of pre-defined events (to be used in -e):\n");
1344 }
1345
1346 print_symbol_events(event_glob, PERF_TYPE_HARDWARE, 1322 print_symbol_events(event_glob, PERF_TYPE_HARDWARE,
1347 event_symbols_hw, PERF_COUNT_HW_MAX, name_only); 1323 event_symbols_hw, PERF_COUNT_HW_MAX, name_only);
1348 1324
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ff6e1fa4111e..39c3b57965d1 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
122int print_hwcache_events(const char *event_glob, bool name_only); 122int print_hwcache_events(const char *event_glob, bool name_only);
123extern int is_valid_tracepoint(const char *event_string); 123extern int is_valid_tracepoint(const char *event_string);
124 124
125extern int valid_debugfs_mount(const char *debugfs); 125int valid_event_mount(const char *eventfs);
126 126
127#endif /* __PERF_PARSE_EVENTS_H */ 127#endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
index 4a015f77e2b5..4ee9a86705ed 100644
--- a/tools/perf/util/parse-options.c
+++ b/tools/perf/util/parse-options.c
@@ -510,8 +510,10 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
510 } 510 }
511 exit(130); 511 exit(130);
512 case PARSE_OPT_LIST_SUBCMDS: 512 case PARSE_OPT_LIST_SUBCMDS:
513 for (int i = 0; subcommands[i]; i++) 513 if (subcommands) {
514 printf("%s ", subcommands[i]); 514 for (int i = 0; subcommands[i]; i++)
515 printf("%s ", subcommands[i]);
516 }
515 exit(130); 517 exit(130);
516 default: /* PARSE_OPT_UNKNOWN */ 518 default: /* PARSE_OPT_UNKNOWN */
517 if (ctx.argv[0][1] == '-') { 519 if (ctx.argv[0][1] == '-') {
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937eb0be2..9dfbed96bf39 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -41,6 +41,7 @@
41#include "symbol.h" 41#include "symbol.h"
42#include "thread.h" 42#include "thread.h"
43#include <api/fs/debugfs.h> 43#include <api/fs/debugfs.h>
44#include <api/fs/tracefs.h>
44#include "trace-event.h" /* For __maybe_unused */ 45#include "trace-event.h" /* For __maybe_unused */
45#include "probe-event.h" 46#include "probe-event.h"
46#include "probe-finder.h" 47#include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
1805 " - please rebuild kernel with %s.\n", 1806 " - please rebuild kernel with %s.\n",
1806 is_kprobe ? 'k' : 'u', config); 1807 is_kprobe ? 'k' : 'u', config);
1807 } else if (err == -ENOTSUP) 1808 } else if (err == -ENOTSUP)
1808 pr_warning("Debugfs is not mounted.\n"); 1809 pr_warning("Tracefs or debugfs is not mounted.\n");
1809 else 1810 else
1810 pr_warning("Failed to open %cprobe_events: %s\n", 1811 pr_warning("Failed to open %cprobe_events: %s\n",
1811 is_kprobe ? 'k' : 'u', 1812 is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
1816{ 1817{
1817 /* Both kprobes and uprobes are disabled, warn it. */ 1818 /* Both kprobes and uprobes are disabled, warn it. */
1818 if (kerr == -ENOTSUP && uerr == -ENOTSUP) 1819 if (kerr == -ENOTSUP && uerr == -ENOTSUP)
1819 pr_warning("Debugfs is not mounted.\n"); 1820 pr_warning("Tracefs or debugfs is not mounted.\n");
1820 else if (kerr == -ENOENT && uerr == -ENOENT) 1821 else if (kerr == -ENOENT && uerr == -ENOENT)
1821 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " 1822 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
1822 "or/and CONFIG_UPROBE_EVENTS.\n"); 1823 "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
1833{ 1834{
1834 char buf[PATH_MAX]; 1835 char buf[PATH_MAX];
1835 const char *__debugfs; 1836 const char *__debugfs;
1837 const char *tracing_dir = "";
1836 int ret; 1838 int ret;
1837 1839
1838 __debugfs = debugfs_find_mountpoint(); 1840 __debugfs = tracefs_find_mountpoint();
1839 if (__debugfs == NULL) 1841 if (__debugfs == NULL) {
1840 return -ENOTSUP; 1842 tracing_dir = "tracing/";
1841 1843
1842 ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file); 1844 __debugfs = debugfs_find_mountpoint();
1845 if (__debugfs == NULL)
1846 return -ENOTSUP;
1847 }
1848
1849 ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
1850 __debugfs, tracing_dir, trace_file);
1843 if (ret >= 0) { 1851 if (ret >= 0) {
1844 pr_debug("Opening %s write=%d\n", buf, readwrite); 1852 pr_debug("Opening %s write=%d\n", buf, readwrite);
1845 if (readwrite && !probe_event_dry_run) 1853 if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
1855 1863
1856static int open_kprobe_events(bool readwrite) 1864static int open_kprobe_events(bool readwrite)
1857{ 1865{
1858 return open_probe_events("tracing/kprobe_events", readwrite); 1866 return open_probe_events("kprobe_events", readwrite);
1859} 1867}
1860 1868
1861static int open_uprobe_events(bool readwrite) 1869static int open_uprobe_events(bool readwrite)
1862{ 1870{
1863 return open_probe_events("tracing/uprobe_events", readwrite); 1871 return open_probe_events("uprobe_events", readwrite);
1864} 1872}
1865 1873
1866/* Get raw string list of current kprobe_events or uprobe_events */ 1874/* Get raw string list of current kprobe_events or uprobe_events */
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index b5247d777f0e..d14193518e4d 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -915,17 +915,13 @@ static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
915 dwarf_decl_line(sp_die, &pf->lno); 915 dwarf_decl_line(sp_die, &pf->lno);
916 pf->lno += pp->line; 916 pf->lno += pp->line;
917 param->retval = find_probe_point_by_line(pf); 917 param->retval = find_probe_point_by_line(pf);
918 } else if (!dwarf_func_inline(sp_die)) { 918 } else if (die_is_func_instance(sp_die)) {
919 /* Instances always have the entry address */
920 dwarf_entrypc(sp_die, &pf->addr);
919 /* Real function */ 921 /* Real function */
920 if (pp->lazy_line) 922 if (pp->lazy_line)
921 param->retval = find_probe_point_lazy(sp_die, pf); 923 param->retval = find_probe_point_lazy(sp_die, pf);
922 else { 924 else {
923 if (dwarf_entrypc(sp_die, &pf->addr) != 0) {
924 pr_warning("Failed to get entry address of "
925 "%s.\n", dwarf_diename(sp_die));
926 param->retval = -ENOENT;
927 return DWARF_CB_ABORT;
928 }
929 pf->addr += pp->offset; 925 pf->addr += pp->offset;
930 /* TODO: Check the address in this function */ 926 /* TODO: Check the address in this function */
931 param->retval = call_probe_finder(sp_die, pf); 927 param->retval = call_probe_finder(sp_die, pf);
@@ -1536,7 +1532,7 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
1536 pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e); 1532 pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e);
1537 lr->start = lf->lno_s; 1533 lr->start = lf->lno_s;
1538 lr->end = lf->lno_e; 1534 lr->end = lf->lno_e;
1539 if (dwarf_func_inline(sp_die)) 1535 if (!die_is_func_instance(sp_die))
1540 param->retval = die_walk_instances(sp_die, 1536 param->retval = die_walk_instances(sp_die,
1541 line_range_inline_cb, lf); 1537 line_range_inline_cb, lf);
1542 else 1538 else
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 6c6a6953fa93..4d28624a1eca 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -17,6 +17,5 @@ util/xyarray.c
17util/cgroup.c 17util/cgroup.c
18util/rblist.c 18util/rblist.c
19util/strlist.c 19util/strlist.c
20../lib/api/fs/fs.c
21util/trace-event.c 20util/trace-event.c
22../../lib/rbtree.c 21../../lib/rbtree.c
diff --git a/tools/perf/util/scripting-engines/Build b/tools/perf/util/scripting-engines/Build
new file mode 100644
index 000000000000..6516e220c247
--- /dev/null
+++ b/tools/perf/util/scripting-engines/Build
@@ -0,0 +1,6 @@
1libperf-$(CONFIG_LIBPERL) += trace-event-perl.o
2libperf-$(CONFIG_LIBPYTHON) += trace-event-python.o
3
4CFLAGS_trace-event-perl.o += $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow -Wno-undef -Wno-switch-default
5
6CFLAGS_trace-event-python.o += $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index d0aee4b9dfd4..1833103768cb 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -25,7 +25,7 @@ cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter'
25build_lib = getenv('PYTHON_EXTBUILD_LIB') 25build_lib = getenv('PYTHON_EXTBUILD_LIB')
26build_tmp = getenv('PYTHON_EXTBUILD_TMP') 26build_tmp = getenv('PYTHON_EXTBUILD_TMP')
27libtraceevent = getenv('LIBTRACEEVENT') 27libtraceevent = getenv('LIBTRACEEVENT')
28libapikfs = getenv('LIBAPIKFS') 28libapikfs = getenv('LIBAPI')
29 29
30ext_sources = [f.strip() for f in file('util/python-ext-sources') 30ext_sources = [f.strip() for f in file('util/python-ext-sources')
31 if len(f.strip()) > 0 and f[0] != '#'] 31 if len(f.strip()) > 0 and f[0] != '#']
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
index b24f9d8727a8..b02731a19d1f 100644
--- a/tools/perf/util/symbol-elf.c
+++ b/tools/perf/util/symbol-elf.c
@@ -69,6 +69,10 @@ static inline uint8_t elf_sym__type(const GElf_Sym *sym)
69 return GELF_ST_TYPE(sym->st_info); 69 return GELF_ST_TYPE(sym->st_info);
70} 70}
71 71
72#ifndef STT_GNU_IFUNC
73#define STT_GNU_IFUNC 10
74#endif
75
72static inline int elf_sym__is_function(const GElf_Sym *sym) 76static inline int elf_sym__is_function(const GElf_Sym *sym)
73{ 77{
74 return (elf_sym__type(sym) == STT_FUNC || 78 return (elf_sym__type(sym) == STT_FUNC ||
@@ -859,10 +863,9 @@ int dso__load_sym(struct dso *dso, struct map *map,
859 /* Reject ARM ELF "mapping symbols": these aren't unique and 863 /* Reject ARM ELF "mapping symbols": these aren't unique and
860 * don't identify functions, so will confuse the profile 864 * don't identify functions, so will confuse the profile
861 * output: */ 865 * output: */
862 if (ehdr.e_machine == EM_ARM) { 866 if (ehdr.e_machine == EM_ARM || ehdr.e_machine == EM_AARCH64) {
863 if (!strcmp(elf_name, "$a") || 867 if (elf_name[0] == '$' && strchr("adtx", elf_name[1])
864 !strcmp(elf_name, "$d") || 868 && (elf_name[2] == '\0' || elf_name[2] == '.'))
865 !strcmp(elf_name, "$t"))
866 continue; 869 continue;
867 } 870 }
868 871
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
index c36636fd825b..25d6c737be3e 100644
--- a/tools/perf/util/trace-event-parse.c
+++ b/tools/perf/util/trace-event-parse.c
@@ -112,8 +112,8 @@ unsigned long long read_size(struct event_format *event, void *ptr, int size)
112 return pevent_read_number(event->pevent, ptr, size); 112 return pevent_read_number(event->pevent, ptr, size);
113} 113}
114 114
115void event_format__print(struct event_format *event, 115void event_format__fprintf(struct event_format *event,
116 int cpu, void *data, int size) 116 int cpu, void *data, int size, FILE *fp)
117{ 117{
118 struct pevent_record record; 118 struct pevent_record record;
119 struct trace_seq s; 119 struct trace_seq s;
@@ -125,10 +125,16 @@ void event_format__print(struct event_format *event,
125 125
126 trace_seq_init(&s); 126 trace_seq_init(&s);
127 pevent_event_info(&s, event, &record); 127 pevent_event_info(&s, event, &record);
128 trace_seq_do_printf(&s); 128 trace_seq_do_fprintf(&s, fp);
129 trace_seq_destroy(&s); 129 trace_seq_destroy(&s);
130} 130}
131 131
132void event_format__print(struct event_format *event,
133 int cpu, void *data, int size)
134{
135 return event_format__fprintf(event, cpu, data, size, stdout);
136}
137
132void parse_proc_kallsyms(struct pevent *pevent, 138void parse_proc_kallsyms(struct pevent *pevent,
133 char *file, unsigned int size __maybe_unused) 139 char *file, unsigned int size __maybe_unused)
134{ 140{
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index 52aaa19e1eb1..356629a30ca9 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -23,6 +23,9 @@ trace_event__tp_format(const char *sys, const char *name);
23 23
24int bigendian(void); 24int bigendian(void);
25 25
26void event_format__fprintf(struct event_format *event,
27 int cpu, void *data, int size, FILE *fp);
28
26void event_format__print(struct event_format *event, 29void event_format__print(struct event_format *event,
27 int cpu, void *data, int size); 30 int cpu, void *data, int size);
28 31
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b86744f29eef..92db3f156b63 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -303,13 +303,26 @@ void set_term_quiet_input(struct termios *old)
303 tcsetattr(0, TCSANOW, &tc); 303 tcsetattr(0, TCSANOW, &tc);
304} 304}
305 305
306static void set_tracing_events_path(const char *mountpoint) 306static void set_tracing_events_path(const char *tracing, const char *mountpoint)
307{ 307{
308 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s", 308 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
309 mountpoint, "tracing/events"); 309 mountpoint, tracing, "events");
310} 310}
311 311
312const char *perf_debugfs_mount(const char *mountpoint) 312static const char *__perf_tracefs_mount(const char *mountpoint)
313{
314 const char *mnt;
315
316 mnt = tracefs_mount(mountpoint);
317 if (!mnt)
318 return NULL;
319
320 set_tracing_events_path("", mnt);
321
322 return mnt;
323}
324
325static const char *__perf_debugfs_mount(const char *mountpoint)
313{ 326{
314 const char *mnt; 327 const char *mnt;
315 328
@@ -317,7 +330,20 @@ const char *perf_debugfs_mount(const char *mountpoint)
317 if (!mnt) 330 if (!mnt)
318 return NULL; 331 return NULL;
319 332
320 set_tracing_events_path(mnt); 333 set_tracing_events_path("tracing/", mnt);
334
335 return mnt;
336}
337
338const char *perf_debugfs_mount(const char *mountpoint)
339{
340 const char *mnt;
341
342 mnt = __perf_tracefs_mount(mountpoint);
343 if (mnt)
344 return mnt;
345
346 mnt = __perf_debugfs_mount(mountpoint);
321 347
322 return mnt; 348 return mnt;
323} 349}
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
325void perf_debugfs_set_path(const char *mntpt) 351void perf_debugfs_set_path(const char *mntpt)
326{ 352{
327 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt); 353 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
328 set_tracing_events_path(mntpt); 354 set_tracing_events_path("tracing/", mntpt);
355}
356
357static const char *find_tracefs(void)
358{
359 const char *path = __perf_tracefs_mount(NULL);
360
361 return path;
329} 362}
330 363
331static const char *find_debugfs(void) 364static const char *find_debugfs(void)
332{ 365{
333 const char *path = perf_debugfs_mount(NULL); 366 const char *path = __perf_debugfs_mount(NULL);
334 367
335 if (!path) 368 if (!path)
336 fprintf(stderr, "Your kernel does not support the debugfs filesystem"); 369 fprintf(stderr, "Your kernel does not support the debugfs filesystem");
@@ -344,6 +377,7 @@ static const char *find_debugfs(void)
344 */ 377 */
345const char *find_tracing_dir(void) 378const char *find_tracing_dir(void)
346{ 379{
380 const char *tracing_dir = "";
347 static char *tracing; 381 static char *tracing;
348 static int tracing_found; 382 static int tracing_found;
349 const char *debugfs; 383 const char *debugfs;
@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)
351 if (tracing_found) 385 if (tracing_found)
352 return tracing; 386 return tracing;
353 387
354 debugfs = find_debugfs(); 388 debugfs = find_tracefs();
355 if (!debugfs) 389 if (!debugfs) {
356 return NULL; 390 tracing_dir = "/tracing";
391 debugfs = find_debugfs();
392 if (!debugfs)
393 return NULL;
394 }
357 395
358 if (asprintf(&tracing, "%s/tracing", debugfs) < 0) 396 if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0)
359 return NULL; 397 return NULL;
360 398
361 tracing_found = 1; 399 tracing_found = 1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 027a5153495c..73c2f8e557ab 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -75,6 +75,7 @@
75#include <linux/types.h> 75#include <linux/types.h>
76#include <sys/ttydefaults.h> 76#include <sys/ttydefaults.h>
77#include <api/fs/debugfs.h> 77#include <api/fs/debugfs.h>
78#include <api/fs/tracefs.h>
78#include <termios.h> 79#include <termios.h>
79#include <linux/bitops.h> 80#include <linux/bitops.h>
80#include <termios.h> 81#include <termios.h>