Skip to contentSkip to conversation

tools/tracing: Use tools/build makefiles like perf

PATCH Superseded Daniel Bristot de Oliveira 2 participants 7 messages Mar 15, 2024

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover tools/tracing: Use tools/build makefiles like perf

tools/tracing and tools/verification/rv are using standalone Makefiles and this approach has some drawbacks. For example, code duplication and lack of proper dependency handling, making things harder for users.

Linus suggested using perf's build system, and it is indeed the best way to go.

This series replaces tools/tracing and tools/verification/rv makefiles with makefiles inspired by perf and objtool that use tools/build/ infrastructure.

Thanks, Arnaldo, for the pointers via chat.

Changes from V1:
- Link: https://lore.kernel.org/lkml/[email protected]/
- Proper handle O= and OUTPUT= flags fixing "make tools/tracing"
- Cleanups

Daniel Bristot de Oliveira (3):
tools/tracing: Use tools/build makefiles on latency-collector tools/rtla: Use tools/build makefiles to build rtla tools/verification: Use tools/build makefiles on rv

 tools/tracing/latency/.gitignore       |   5 +-
 tools/tracing/latency/Build            |   1 +
 tools/tracing/latency/Makefile         | 105 ++++++++++--
 tools/tracing/latency/Makefile.config  |  30 ++++
 tools/tracing/rtla/.gitignore          |   7 +-
 tools/tracing/rtla/Build               |   1 +
 tools/tracing/rtla/Makefile            | 217 +++++++++----------------
 tools/tracing/rtla/Makefile.config     |  47 ++++++
 tools/tracing/rtla/Makefile.rtla       |  80 +++++++++
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build           |  11 ++
 tools/verification/rv/.gitignore       |   6 +
 tools/verification/rv/Build            |   1 +
 tools/verification/rv/Makefile         | 207 +++++++++--------------
 tools/verification/rv/Makefile.config  |  47 ++++++
 tools/verification/rv/Makefile.rv      |  51 ++++++
 tools/verification/rv/src/Build        |   4 +
 17 files changed, 549 insertions(+), 297 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build
Signature · 1 line
2.44.0
#1 lore raw

PATCH v2 1/3 tools/tracing: Use tools/build makefiles on latency-collector

Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example: Before this patch, a missing tracefs/traceevents headers will result in fail like this:

-------------------------------- %< ------------------------------- ~/linux/tools/tracing/latency $ make
cc -Wall -Wextra -g -O2 -o latency-collector latency-collector.c -lpthread latency-collector.c:26:10: fatal error: tracefs.h: No such file or directory
26 | #include <tracefs.h>

      |          ^~~~~~~~~~~

compilation terminated.
make: *** [Makefile:14: latency-collector] Error 1 -------------------------------- %< -------------------------------

Which is not that helpful. After this change it reports:

-------------------------------- %< ------------------------------- ~/linux/tools/tracing/latency# make

Auto-detecting system features:
... libtraceevent: [ OFF ]
... libtracefs: [ OFF ]

libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel libtracefs is missing. Please install libtracefs-dev/libtracefs-devel Makefile.config:29: *** Please, check the errors above.. Stop. -------------------------------- %< -------------------------------

This type of output is common across other tools in tools/ like perf and objtool.

---
 tools/tracing/latency/.gitignore      |   5 +-
 tools/tracing/latency/Build           |   1 +
 tools/tracing/latency/Makefile        | 105 +++++++++++++++++++++-----
 tools/tracing/latency/Makefile.config |  30 ++++++++
 4 files changed, 122 insertions(+), 19 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
tools/tracing/latency/.gitignore +4 -1
index 0863960761e7..2bb8e60f7fdd 100644
@@ -1,2 +1,5 @@
-# SPDX-License-Identifier: GPL-2.0
+# SPDX-License-Identifier: GPL-2.0-only
 latency-collector
+fixdep
+feature
+FEATURE-DUMP
tools/tracing/latency/Build new file +1 -0
new file mode 100644
index 000000000000..0ce65ea72bf9
@@ -0,0 +1 @@
+latency-collector-y += latency-collector.o
tools/tracing/latency/Makefile +87 -18

111 lines not on this page · raw message

tools/tracing/latency/Makefile.config new file +30 -0
new file mode 100644
index 000000000000..b25e531a1f95
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+STOP_ERROR :=
+
+define lib_setup
+  $(eval EXTLIBS += -l$(1))
+  $(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)"))
+endef
+
+$(call feature_check,libtraceevent)
+ifeq ($(feature-libtraceevent), 1)
+  $(call detected,CONFIG_LIBTRACEEVENT)
+  $(call lib_setup,traceevent)
+else
+  STOP_ERROR := 1
+  $(info libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel)
+endif
+
+$(call feature_check,libtracefs)
+ifeq ($(feature-libtracefs), 1)
+  $(call detected,CONFIG_LIBTRACEFS)
+  $(call lib_setup,tracefs)
+else
+  STOP_ERROR := 1
+  $(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
+endif
+
+ifeq ($(STOP_ERROR),1)
+  $(error Please, check the errors above.)
+endif
Signature · 1 line
2.44.0
#2 lore raw

Re: [PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

Quoted 5 lines · Daniel Bristot de Oliveira

Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example: Before this patch, a missing tracefs/traceevents headers will result in fail like this:

-------------------------------- %< -------------------------------

Oops, b4 is interpreting these ------ as the '---' separator, and is truncating the message. I will fix this in a v3.

sorry.

-- Daniel

#3 lore raw

Re: [PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

Quoted 11 lines · Daniel Bristot de Oliveira
Quoted 5 lines · Daniel Bristot de Oliveira

Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example: Before this patch, a missing tracefs/traceevents headers will result in fail like this:

-------------------------------- %< -------------------------------

Oops, b4 is interpreting these ------ as the '---' separator, and is truncating the message. I will fix this in a v3.

sorry.

Yeah, that confuses scripts, that separator.

But overall I tested various versions of your patches and they look ok.

That tools/build/ was done for other tools to use and so far some tools/ living projects use it: tools/objtool, tools/lib/subcmd, etc.

I just did a:

git grep tools\/build

And there is quite a few more I didn't realize have been using bits and pieces, good.

- Arnaldo

#4 lore raw

Re: [PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · Daniel Bristot de Oliveira
Quoted 4 lines · Daniel Bristot de Oliveira

Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example: Before this patch, a missing tracefs/traceevents headers will result in fail like this:

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

-------------------------------- %< -------------------------------

Oops, b4 is interpreting these ------ as the '---' separator, and is truncating the message. I will fix this in a v3.

sorry.

Yeah, that confuses scripts, that separator.

checkpatch did not point that as an error, and git am works as well.... but it indeed confuses other scripts...

Thanks, Arnaldo.
-- Daniel

#5 lore raw

PATCH v2 2/3 tools/rtla: Use tools/build makefiles to build rtla

In reply to Daniel Bristot de Oliveira

Use tools/build/ makefiles to build rtla, inheriting the benefits of it. For example, having a proper way to handle dependencies.

rtla is built using perf infra-structure when building inside the kernel tree.

At this point, rtla diverges from perf in two points: Documentation and tarball generation/build.

At the documentation level, rtla is one step ahead, placing the documentation at Documentation/tools/rtla/, using the same build tools as kernel documentation. The idea is to move perf documentation to the same scheme and then share the same makefiles.

rtla has a tarball target that the (old) RHEL8 uses. The tarball was kept using a simple standalone makefile for compatibility. The standalone makefile shares most of the code, e.g., flags, with regular buildings.

The tarball method was set as deprecated. If necessary, we can make a rtla tarball like perf, which includes the entire tools/build. But this would also require changes in the user side (the directory structure changes, and probably the deps to build the package).

Inspired on perf and objtool.

---
 tools/tracing/rtla/.gitignore          |   7 +-
 tools/tracing/rtla/Build               |   1 +
 tools/tracing/rtla/Makefile            | 217 +++++++++----------------
 tools/tracing/rtla/Makefile.config     |  47 ++++++
 tools/tracing/rtla/Makefile.rtla       |  80 +++++++++
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build           |  11 ++
 7 files changed, 244 insertions(+), 145 deletions(-)
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build
tools/tracing/rtla/.gitignore +6 -1
index e9df32419b2b..293f0dbb0ca2 100644
@@ -1 +1,6 @@
-/rtla
+# SPDX-License-Identifier: GPL-2.0-only
+rtla
+rtla-static
+fixdep
+feature
+FEATURE-DUMP
tools/tracing/rtla/Build new file +1 -0
new file mode 100644
index 000000000000..6c9d5b36a315
@@ -0,0 +1 @@
+rtla-y += src/
tools/tracing/rtla/Makefile +73 -144

230 lines not on this page · raw message

tools/tracing/rtla/Makefile.config new file +47 -0

47 lines not on this page · raw message

tools/tracing/rtla/Makefile.rtla new file +80 -0

80 lines not on this page · raw message

tools/tracing/rtla/Makefile.standalone new file +26 -0
new file mode 100644
index 000000000000..86d07cb52fa5
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+VERSION		:= $(shell cat VERSION)
+CFLAGS		+= $$($(PKG_CONFIG) --cflags libtracefs)
+EXTLIBS		+= $$($(PKG_CONFIG) --libs libtracefs)
+
+rtla:
+
+include Makefile.rtla
+
+SRC		:= $(wildcard src/*.c)
+HDR		:= $(wildcard src/*.h)
+OBJ		:= $(SRC:.c=.o)
+DOCSRC		:= Documentation/
+
+rtla: $(OBJ)
+	$(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) $(EXTLIBS)
+	$(info This is a deprecated method to compile RTLA, please compile from Linux kernel source)
+
+.PHONY: clean tarball
+clean: doc_clean
+	@test ! -f rtla || rm rtla
+	@test ! -f rtla-static || rm rtla-static
+	@test ! -f src/rtla.o || rm src/rtla.o
+	@test ! -f $(TARBALL) || rm -f $(TARBALL)
+	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
tools/tracing/rtla/src/Build new file +11 -0
new file mode 100644
index 000000000000..dbed9e31829b
@@ -0,0 +1,11 @@
+rtla-y += trace.o
+rtla-y += utils.o
+rtla-y += osnoise.o
+rtla-y += osnoise_top.o
+rtla-y += osnoise_hist.o
+rtla-y += timerlat.o
+rtla-y += timerlat_top.o
+rtla-y += timerlat_hist.o
+rtla-y += timerlat_u.o
+rtla-y += timerlat_aa.o
+rtla-y += rtla.o
Signature · 1 line
2.44.0
#6 lore raw

PATCH v2 3/3 tools/verification: Use tools/build makefiles on rv

In reply to Daniel Bristot de Oliveira

Use tools/build/ makefiles to build rv, inheriting the benefits of it. For example, having a proper way to handle dependencies.

---
 tools/verification/rv/.gitignore      |   6 +
 tools/verification/rv/Build           |   1 +
 tools/verification/rv/Makefile        | 207 +++++++++-----------------
 tools/verification/rv/Makefile.config |  47 ++++++
 tools/verification/rv/Makefile.rv     |  51 +++++++
 tools/verification/rv/src/Build       |   4 +
 6 files changed, 183 insertions(+), 133 deletions(-)
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build
tools/verification/rv/.gitignore new file +6 -0
new file mode 100644
index 000000000000..34a486585a34
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+rv
+rv-static
+fixdep
+feature
+FEATURE-DUMP
tools/verification/rv/Build new file +1 -0
new file mode 100644
index 000000000000..a44c22349d4b
@@ -0,0 +1 @@
+rv-y += src/
tools/verification/rv/Makefile +74 -133

220 lines not on this page · raw message

tools/verification/rv/Makefile.config new file +47 -0

47 lines not on this page · raw message

tools/verification/rv/Makefile.rv new file +51 -0

51 lines not on this page · raw message

tools/verification/rv/src/Build new file +4 -0
new file mode 100644
index 000000000000..d781983c1a79
@@ -0,0 +1,4 @@
+rv-y += trace.o
+rv-y += utils.o
+rv-y += in_kernel.o
+rv-y += rv.o
Signature · 1 line
2.44.0