Skip to contentSkip to conversation

perf: enable libtraceevent dynamic linking

PATCH In review Michael Petlan 3 participants 5 messages Apr 28, 2021 – Apr 30, 2021 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: enable libtraceevent dynamic linking

Currently we support only static linking with kernel's libtraceevent (tools/lib/traceevent). This patch adds libtraceevent package detection and support to link perf with it dynamically.

The libtraceevent package status is displayed with:

$ make VF=1 LIBTRACEEVENT_DYNAMIC=1
...
...                 libtraceevent: [ on  ]

Default behavior remains the same (static linking).

---
 tools/build/Makefile.feature             |  1 +
 tools/build/feature/Makefile             |  4 ++++
 tools/build/feature/test-libtraceevent.c | 12 ++++++++++++
 tools/perf/Makefile.config               |  9 +++++++++
 tools/perf/Makefile.perf                 |  8 ++++++--
 5 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 tools/build/feature/test-libtraceevent.c
tools/build/Makefile.feature +1 -0
index 74e255d58d8d..b3221a43fa65 100644
@@ -52,6 +52,7 @@ FEATURE_TESTS_BASIC :=                  \
         libpython-version               \
         libslang                        \
         libslang-include-subdir         \
+        libtraceevent                   \
         libcrypto                       \
         libunwind                       \
         pthread-attr-setaffinity-np     \
tools/build/feature/Makefile +4 -0
index 3e55edb3ea54..ec203e28407f 100644
@@ -36,6 +36,7 @@ FILES=                                          \
          test-libpython-version.bin             \
          test-libslang.bin                      \
          test-libslang-include-subdir.bin       \
+         test-libtraceevent.bin                 \
          test-libcrypto.bin                     \
          test-libunwind.bin                     \
          test-libunwind-debug-frame.bin         \
@@ -196,6 +197,9 @@ $(OUTPUT)test-libslang.bin:
 $(OUTPUT)test-libslang-include-subdir.bin:
 	$(BUILD) -lslang
 
+$(OUTPUT)test-libtraceevent.bin:
+	$(BUILD) -ltraceevent
+
 $(OUTPUT)test-libcrypto.bin:
 	$(BUILD) -lcrypto
 
tools/build/feature/test-libtraceevent.c new file +12 -0
new file mode 100644
index 000000000000..416b11ffd4b4
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <traceevent/trace-seq.h>
+
+int main(void)
+{
+	int rv = 0;
+	struct trace_seq s;
+	trace_seq_init(&s);
+	rv += !(s.state == TRACE_SEQ__GOOD);
+	trace_seq_destroy(&s);
+	return rv;
+}
tools/perf/Makefile.config +9 -0
index 3514fe956ed1..99c73a7b6a26 100644
@@ -1079,6 +1079,15 @@ ifdef LIBPFM4
   endif
 endif
 
+ifdef LIBTRACEEVENT_DYNAMIC
+  $(call feature_check,libtraceevent)
+  ifeq ($(feature-libtraceevent), 1)
+    EXTLIBS += -ltraceevent
+  else
+    dummy := $(error Error: No libtraceevent devel library found, please install libtraceevent-devel);
+  endif
+endif
+
 # Among the variables below, these:
 #   perfexecdir
 #   perf_include_dir
tools/perf/Makefile.perf +6 -2
index 090fb9d62665..fde8ca22d117 100644
@@ -128,6 +128,8 @@ include ../scripts/utilities.mak
 #
 # Define BUILD_BPF_SKEL to enable BPF skeletons
 #
+# Define LIBTRACEEVENT_DYNAMIC to enable libtraceevent dynamic linking
+#
 
 # As per kernel Makefile, avoid funny character set dependencies
 unexport LC_ALL
@@ -309,7 +311,6 @@ endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
-
 LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 
 #
@@ -374,12 +375,15 @@ endif
 
 export PERL_PATH
 
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
   endif
 endif
+ifndef LIBTRACEEVENT_DYNAMIC
+  PERFLIBS += $(LIBTRACEEVENT)
+endif
 
 # We choose to avoid "if .. else if .. else .. endif endif"
 # because maintaining the nesting to match is a pain.  If
Signature · 1 line
2.18.4
#1 lore raw

On Wed, Apr 28, 2021 at 11:20:23AM +0200, Michael Petlan wrote:

SNIP

Quoted 13 lines

unexport LC_ALL

tools/perf/Makefile.perf +0 -1
@@ -309,7 +311,6 @@ endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
-
 LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 
 #
@@ -374,12 +375,15 @@ endif
 
 export PERL_PATH
 

tools/perf/Makefile.perf endif · line 386

Quoted 10 lines
tools/perf/Makefile.perf +4 -1
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
   endif
 endif
+ifndef LIBTRACEEVENT_DYNAMIC
+  PERFLIBS += $(LIBTRACEEVENT)
+endif

there's also install-traceevent-plugins target called during install, which should be skipped for LIBTRACEEVENT_DYNAMIC

jirka

Quoted 6 lines
tools/perf/Makefile.perf +0 -0
 # We choose to avoid "if .. else if .. else .. endif endif"
 # because maintaining the nesting to match is a pain.  If
Signature · 1 line
2.18.4
#2 lore raw
Quoted 17 lines · Jiri Olsa

On Wed, Apr 28, 2021 at 11:20:23AM +0200, Michael Petlan wrote:

SNIP

Quoted 13 lines

unexport LC_ALL

tools/perf/Makefile.perf +0 -1
@@ -309,7 +311,6 @@ endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
-
 LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 
 #
@@ -374,12 +375,15 @@ endif
 
 export PERL_PATH
 
Quoted 13 lines

tools/perf/Makefile.perf endif · line 386

Quoted 10 lines
tools/perf/Makefile.perf +4 -1
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
   endif
 endif
+ifndef LIBTRACEEVENT_DYNAMIC
+  PERFLIBS += $(LIBTRACEEVENT)
+endif

there's also install-traceevent-plugins target called during install, which should be skipped for LIBTRACEEVENT_DYNAMIC

Oh, didn't notice that. Thanks.

However, it seems that's not all what we miss in the patch. Seems that libtraceevent-dynamic-list should be also taken from external libtraceevent, when linked dynamically, shouldn't it.

Quoted 10 lines

jirka

Quoted 6 lines
tools/perf/Makefile.perf +0 -0
 # We choose to avoid "if .. else if .. else .. endif endif"
 # because maintaining the nesting to match is a pain.  If
Signature · 1 line
2.18.4
#3 lore raw

Em Fri, Apr 30, 2021 at 02:59:00PM +0200, Michael Petlan escreveu:

Quoted 32 lines · Jiri Olsa
Quoted 17 lines · Michael Petlan

SNIP

Quoted 13 lines

unexport LC_ALL

tools/perf/Makefile.perf +0 -1
@@ -309,7 +311,6 @@ endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
-
 LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 
 #
@@ -374,12 +375,15 @@ endif
 
 export PERL_PATH
 
Quoted 13 lines

tools/perf/Makefile.perf endif · line 386

Quoted 10 lines
tools/perf/Makefile.perf +4 -1
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
   endif
 endif
+ifndef LIBTRACEEVENT_DYNAMIC
+  PERFLIBS += $(LIBTRACEEVENT)
+endif

there's also install-traceevent-plugins target called during install, which should be skipped for LIBTRACEEVENT_DYNAMIC

Quoted 6 lines

Oh, didn't notice that. Thanks.

However, it seems that's not all what we miss in the patch. Seems that libtraceevent-dynamic-list should be also taken from external libtraceevent, when linked dynamically, shouldn't it.

Please send patches on top of what you already sent, that I have already merged and sent upstream, since it is opt-in.

- Arnaldo

#4 lore raw
Quoted 35 lines · Arnaldo Carvalho de Melo

Em Fri, Apr 30, 2021 at 02:59:00PM +0200, Michael Petlan escreveu:

Quoted 34 lines · Jiri Olsa
Quoted 17 lines · Michael Petlan

SNIP

Quoted 13 lines

unexport LC_ALL

tools/perf/Makefile.perf +0 -1
@@ -309,7 +311,6 @@ endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
 export LIBTRACEEVENT
-
 LIBTRACEEVENT_DYNAMIC_LIST = $(PLUGINS_PATH)libtraceevent-dynamic-list
 
 #
@@ -374,12 +375,15 @@ endif
 
 export PERL_PATH
 
Quoted 13 lines

tools/perf/Makefile.perf endif · line 386

Quoted 10 lines
tools/perf/Makefile.perf +4 -1
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
+PERFLIBS = $(LIBAPI) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   ifndef LIBBPF_DYNAMIC
     PERFLIBS += $(LIBBPF)
   endif
 endif
+ifndef LIBTRACEEVENT_DYNAMIC
+  PERFLIBS += $(LIBTRACEEVENT)
+endif

there's also install-traceevent-plugins target called during install, which should be skipped for LIBTRACEEVENT_DYNAMIC

Oh, didn't notice that. Thanks.

Quoted 7 lines
Quoted 4 lines

However, it seems that's not all what we miss in the patch. Seems that libtraceevent-dynamic-list should be also taken from external libtraceevent, when linked dynamically, shouldn't it.

Please send patches on top of what you already sent, that I have already merged and sent upstream, since it is opt-in.

OK, this is great. I can already use the patch downstream, and polish it later.
Thank you!

Quoted 4 lines

- Arnaldo