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

tools/rtla: Use tools/build makefiles to build rtla

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.

Link: https://lkml.kernel.org/r/57563abf2715d22515c0c54a87cff3849eca5d52.1710519524.git.bristot@kernel.org

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: John Kacur <jkacur@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>

+233 -134
+6 -1
tools/tracing/rtla/.gitignore
··· 1 - /rtla 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + rtla 3 + rtla-static 4 + fixdep 5 + feature 6 + FEATURE-DUMP
+1
tools/tracing/rtla/Build
··· 1 + rtla-y += src/
+62 -133
tools/tracing/rtla/Makefile
··· 1 - NAME := rtla 2 - # Follow the kernel version 3 - VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. kernelversion | grep -v make) 1 + # SPDX-License-Identifier: GPL-2.0-only 4 2 5 - # From libtracefs: 6 - # Makefiles suck: This macro sets a default value of $(2) for the 7 - # variable named by $(1), unless the variable has been set by 8 - # environment or command line. This is necessary for CC and AR 9 - # because make sets default values, so the simpler ?= approach 10 - # won't work as expected. 11 - define allow-override 12 - $(if $(or $(findstring environment,$(origin $(1))),\ 13 - $(findstring command line,$(origin $(1)))),,\ 14 - $(eval $(1) = $(2))) 15 - endef 16 - 17 - # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 18 - $(call allow-override,CC,$(CROSS_COMPILE)gcc) 19 - $(call allow-override,AR,$(CROSS_COMPILE)ar) 20 - $(call allow-override,STRIP,$(CROSS_COMPILE)strip) 21 - $(call allow-override,PKG_CONFIG,pkg-config) 22 - $(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/) 23 - $(call allow-override,LDCONFIG,ldconfig) 24 - 25 - INSTALL = install 26 - MKDIR = mkdir 27 - FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ 28 - -fasynchronous-unwind-tables -fstack-clash-protection 29 - WOPTS := -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized 30 - 31 - ifeq ($(CC),clang) 32 - FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS)) 33 - WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS)) 3 + ifeq ($(srctree),) 4 + srctree := $(patsubst %/,%,$(dir $(CURDIR))) 5 + srctree := $(patsubst %/,%,$(dir $(srctree))) 6 + srctree := $(patsubst %/,%,$(dir $(srctree))) 34 7 endif 35 8 36 - TRACEFS_HEADERS := $$($(PKG_CONFIG) --cflags libtracefs) 9 + include $(srctree)/tools/scripts/Makefile.include 37 10 38 - CFLAGS := -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS) 39 - LDFLAGS := -flto=auto -ggdb $(EXTRA_LDFLAGS) 40 - LIBS := $$($(PKG_CONFIG) --libs libtracefs) 11 + # O is an alias for OUTPUT 12 + OUTPUT := $(O) 41 13 42 - SRC := $(wildcard src/*.c) 43 - HDR := $(wildcard src/*.h) 44 - OBJ := $(SRC:.c=.o) 45 - DIRS := src 46 - FILES := Makefile README.txt 47 - CEXT := bz2 48 - TARBALL := $(NAME)-$(VERSION).tar.$(CEXT) 49 - TAROPTS := -cvjf $(TARBALL) 50 - BINDIR := /usr/bin 51 - DATADIR := /usr/share 52 - DOCDIR := $(DATADIR)/doc 53 - MANDIR := $(DATADIR)/man 54 - LICDIR := $(DATADIR)/licenses 55 - SRCTREE := $(or $(BUILD_SRC),$(CURDIR)) 56 - 57 - # If running from the tarball, man pages are stored in the Documentation 58 - # dir. If running from the kernel source, man pages are stored in 59 - # Documentation/tools/rtla/. 60 - ifneq ($(wildcard Documentation/.*),) 61 - DOCSRC = Documentation/ 14 + ifeq ($(OUTPUT),) 15 + OUTPUT := $(CURDIR) 62 16 else 63 - DOCSRC = $(SRCTREE)/../../../Documentation/tools/rtla/ 17 + # subdir is used by the ../Makefile in $(call descend,) 18 + ifneq ($(subdir),) 19 + OUTPUT := $(OUTPUT)/$(subdir) 20 + endif 64 21 endif 65 22 66 - LIBTRACEEVENT_MIN_VERSION = 1.5 67 - LIBTRACEFS_MIN_VERSION = 1.3 68 - 69 - .PHONY: all warnings show_warnings 70 - all: warnings rtla 71 - 72 - TEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n") 73 - ifeq ("$(TEST_LIBTRACEEVENT)", "n") 74 - WARNINGS = show_warnings 75 - MISSING_LIBS += echo "** libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) or higher"; 76 - MISSING_PACKAGES += "libtraceevent-devel" 77 - MISSING_SOURCE += echo "** https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ "; 23 + ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),) 24 + OUTPUT := $(OUTPUT)/ 78 25 endif 79 26 80 - TEST_LIBTRACEFS = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 || echo n") 81 - ifeq ("$(TEST_LIBTRACEFS)", "n") 82 - WARNINGS = show_warnings 83 - MISSING_LIBS += echo "** libtracefs version $(LIBTRACEFS_MIN_VERSION) or higher"; 84 - MISSING_PACKAGES += "libtracefs-devel" 85 - MISSING_SOURCE += echo "** https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ "; 27 + RTLA := $(OUTPUT)rtla 28 + RTLA_IN := $(RTLA)-in.o 29 + 30 + VERSION := $(shell sh -c "make -sC ../../.. kernelversion | grep -v make") 31 + DOCSRC := ../../../Documentation/tools/rtla/ 32 + 33 + FEATURE_TESTS := libtraceevent 34 + FEATURE_TESTS += libtracefs 35 + FEATURE_DISPLAY := libtraceevent 36 + FEATURE_DISPLAY += libtracefs 37 + 38 + ifeq ($(V),1) 39 + Q = 40 + else 41 + Q = @ 86 42 endif 87 43 88 - define show_dependencies 89 - @echo "********************************************"; \ 90 - echo "** NOTICE: Failed build dependencies"; \ 91 - echo "**"; \ 92 - echo "** Required Libraries:"; \ 93 - $(MISSING_LIBS) \ 94 - echo "**"; \ 95 - echo "** Consider installing the latest libtracefs from your"; \ 96 - echo "** distribution, e.g., 'dnf install $(MISSING_PACKAGES)' on Fedora,"; \ 97 - echo "** or from source:"; \ 98 - echo "**"; \ 99 - $(MISSING_SOURCE) \ 100 - echo "**"; \ 101 - echo "********************************************" 102 - endef 44 + all: $(RTLA) 103 45 104 - show_warnings: 105 - $(call show_dependencies); 46 + include $(srctree)/tools/build/Makefile.include 47 + include Makefile.rtla 106 48 107 - ifneq ("$(WARNINGS)", "") 108 - ERROR_OUT = $(error Please add the necessary dependencies) 49 + # check for dependencies only on required targets 50 + NON_CONFIG_TARGETS := clean install tarball doc doc_clean doc_install 109 51 110 - warnings: $(WARNINGS) 111 - $(ERROR_OUT) 52 + config := 1 53 + ifdef MAKECMDGOALS 54 + ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),) 55 + config := 0 56 + endif 112 57 endif 113 58 114 - rtla: $(OBJ) 115 - $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) 59 + ifeq ($(config),1) 60 + include $(srctree)/tools/build/Makefile.feature 61 + include Makefile.config 62 + endif 116 63 117 - static: $(OBJ) 118 - $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl 64 + CFLAGS += $(INCLUDES) $(LIB_INCLUDES) 119 65 120 - .PHONY: install 121 - install: doc_install 122 - $(MKDIR) -p $(DESTDIR)$(BINDIR) 123 - $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR) 124 - $(STRIP) $(DESTDIR)$(BINDIR)/rtla 125 - @test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise 126 - ln -s rtla $(DESTDIR)$(BINDIR)/osnoise 127 - @test ! -f $(DESTDIR)$(BINDIR)/hwnoise || rm $(DESTDIR)$(BINDIR)/hwnoise 128 - ln -s rtla $(DESTDIR)$(BINDIR)/hwnoise 129 - @test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat 130 - ln -s rtla $(DESTDIR)$(BINDIR)/timerlat 66 + export CFLAGS OUTPUT srctree 131 67 132 - .PHONY: clean tarball 133 - clean: doc_clean 134 - @test ! -f rtla || rm rtla 135 - @test ! -f rtla-static || rm rtla-static 136 - @test ! -f src/rtla.o || rm src/rtla.o 137 - @test ! -f $(TARBALL) || rm -f $(TARBALL) 138 - @rm -rf *~ $(OBJ) *.tar.$(CEXT) 68 + $(RTLA): $(RTLA_IN) 69 + $(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS) 139 70 140 - tarball: clean 141 - rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION) 142 - echo $(VERSION) > $(NAME)-$(VERSION)/VERSION 143 - cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION) 144 - mkdir $(NAME)-$(VERSION)/Documentation/ 145 - cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/ 146 - tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION) 147 - rm -rf $(NAME)-$(VERSION) 71 + static: $(RTLA_IN) 72 + $(eval LDFLAGS += -static) 73 + $(QUIET_LINK)$(CC) -static $(LDFLAGS) -o $(RTLA)-static $(RTLA_IN) $(EXTLIBS) 148 74 149 - .PHONY: doc doc_clean doc_install 150 - doc: 151 - $(MAKE) -C $(DOCSRC) 75 + rtla.%: fixdep FORCE 76 + make -f $(srctree)/tools/build/Makefile.build dir=. $@ 152 77 153 - doc_clean: 154 - $(MAKE) -C $(DOCSRC) clean 78 + $(RTLA_IN): fixdep FORCE 79 + make $(build)=rtla 155 80 156 - doc_install: 157 - $(MAKE) -C $(DOCSRC) install 81 + clean: doc_clean fixdep-clean 82 + $(call QUIET_CLEAN, rtla) 83 + $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete 84 + $(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-* 85 + $(Q)rm -rf feature 86 + .PHONY: FORCE clean
+47
tools/tracing/rtla/Makefile.config
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + STOP_ERROR := 4 + 5 + LIBTRACEEVENT_MIN_VERSION = 1.5 6 + LIBTRACEFS_MIN_VERSION = 1.3 7 + 8 + define lib_setup 9 + $(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)")) 10 + $(eval EXTLIBS += -l$(1)) 11 + endef 12 + 13 + $(call feature_check,libtraceevent) 14 + ifeq ($(feature-libtraceevent), 1) 15 + $(call detected,CONFIG_LIBTRACEEVENT) 16 + 17 + TEST = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 && echo y || echo n") 18 + ifeq ($(TEST),n) 19 + $(info libtraceevent version is too low, it must be at least $(LIBTRACEEVENT_MIN_VERSION)) 20 + STOP_ERROR := 1 21 + endif 22 + 23 + $(call lib_setup,traceevent) 24 + else 25 + STOP_ERROR := 1 26 + $(info libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel) 27 + endif 28 + 29 + $(call feature_check,libtracefs) 30 + ifeq ($(feature-libtracefs), 1) 31 + $(call detected,CONFIG_LIBTRACEFS) 32 + 33 + TEST = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 && echo y || echo n") 34 + ifeq ($(TEST),n) 35 + $(info libtracefs version is too low, it must be at least $(LIBTRACEFS_MIN_VERSION)) 36 + STOP_ERROR := 1 37 + endif 38 + 39 + $(call lib_setup,tracefs) 40 + else 41 + STOP_ERROR := 1 42 + $(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel) 43 + endif 44 + 45 + ifeq ($(STOP_ERROR),1) 46 + $(error Please, check the errors above.) 47 + endif
+80
tools/tracing/rtla/Makefile.rtla
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + define allow-override 4 + $(if $(or $(findstring environment,$(origin $(1))),\ 5 + $(findstring command line,$(origin $(1)))),,\ 6 + $(eval $(1) = $(2))) 7 + endef 8 + 9 + # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 10 + $(call allow-override,CC,$(CROSS_COMPILE)gcc) 11 + $(call allow-override,AR,$(CROSS_COMPILE)ar) 12 + $(call allow-override,STRIP,$(CROSS_COMPILE)strip) 13 + $(call allow-override,PKG_CONFIG,pkg-config) 14 + $(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/) 15 + $(call allow-override,LDCONFIG,ldconfig) 16 + export CC AR STRIP PKG_CONFIG LD_SO_CONF_PATH LDCONFIG 17 + 18 + FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ 19 + -fasynchronous-unwind-tables -fstack-clash-protection 20 + WOPTS := -O -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 \ 21 + -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized 22 + 23 + ifeq ($(CC),clang) 24 + FOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(FOPTS)) 25 + WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS)) 26 + endif 27 + 28 + CFLAGS := -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(WOPTS) $(CFLAGS) 29 + LDFLAGS := -ggdb $(LDFLAGS) 30 + 31 + RM := rm -rf 32 + LN := ln -s 33 + INSTALL := install 34 + MKDIR := mkdir 35 + STRIP := strip 36 + BINDIR := /usr/bin 37 + 38 + .PHONY: install 39 + install: doc_install 40 + @$(MKDIR) -p $(DESTDIR)$(BINDIR) 41 + $(call QUIET_INSTALL,rtla)$(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR) 42 + @$(STRIP) $(DESTDIR)$(BINDIR)/rtla 43 + @test ! -f $(DESTDIR)$(BINDIR)/osnoise || $(RM) $(DESTDIR)$(BINDIR)/osnoise 44 + @$(LN) rtla $(DESTDIR)$(BINDIR)/osnoise 45 + @test ! -f $(DESTDIR)$(BINDIR)/hwnoise || $(RM) $(DESTDIR)$(BINDIR)/hwnoise 46 + @$(LN) -s rtla $(DESTDIR)$(BINDIR)/hwnoise 47 + @test ! -f $(DESTDIR)$(BINDIR)/timerlat || $(RM) $(DESTDIR)$(BINDIR)/timerlat 48 + @$(LN) -s rtla $(DESTDIR)$(BINDIR)/timerlat 49 + 50 + .PHONY: doc doc_clean doc_install 51 + doc: 52 + $(MAKE) -C $(DOCSRC) 53 + 54 + doc_clean: 55 + $(MAKE) -C $(DOCSRC) clean 56 + 57 + doc_install: 58 + $(MAKE) -C $(DOCSRC) install 59 + 60 + # This section is neesary for the tarball, when the tarball 61 + # support is removed, we can delete these entries. 62 + NAME := rtla 63 + DIRS := src 64 + FILES := Makefile README.txt 65 + CEXT := bz2 66 + TARBALL := $(NAME)-$(VERSION).tar.$(CEXT) 67 + TAROPTS := -cvjf $(TARBALL) 68 + SRCTREE := $(or $(BUILD_SRC),$(CURDIR)) 69 + 70 + tarball: clean 71 + $(RM) $(NAME)-$(VERSION) && $(MKDIR) $(NAME)-$(VERSION) 72 + echo $(VERSION) > $(NAME)-$(VERSION)/VERSION 73 + cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION) 74 + $(MKDIR) $(NAME)-$(VERSION)/Documentation/ 75 + cp -rp $(SRCTREE)/../../../Documentation/tools/$(NAME)/* $(NAME)-$(VERSION)/Documentation/ 76 + cp Makefile.standalone $(NAME)-$(VERSION)/Makefile 77 + cp Makefile.$(NAME) $(NAME)-$(VERSION)/ 78 + tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION) 79 + $(RM) $(NAME)-$(VERSION) 80 + .PHONY: tarball
+26
tools/tracing/rtla/Makefile.standalone
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + 3 + VERSION := $(shell cat VERSION) 4 + CFLAGS += $$($(PKG_CONFIG) --cflags libtracefs) 5 + EXTLIBS += $$($(PKG_CONFIG) --libs libtracefs) 6 + 7 + rtla: 8 + 9 + include Makefile.rtla 10 + 11 + SRC := $(wildcard src/*.c) 12 + HDR := $(wildcard src/*.h) 13 + OBJ := $(SRC:.c=.o) 14 + DOCSRC := Documentation/ 15 + 16 + rtla: $(OBJ) 17 + $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) $(EXTLIBS) 18 + $(info This is a deprecated method to compile RTLA, please compile from Linux kernel source) 19 + 20 + .PHONY: clean tarball 21 + clean: doc_clean 22 + @test ! -f rtla || rm rtla 23 + @test ! -f rtla-static || rm rtla-static 24 + @test ! -f src/rtla.o || rm src/rtla.o 25 + @test ! -f $(TARBALL) || rm -f $(TARBALL) 26 + @rm -rf *~ $(OBJ) *.tar.$(CEXT)
+11
tools/tracing/rtla/src/Build
··· 1 + rtla-y += trace.o 2 + rtla-y += utils.o 3 + rtla-y += osnoise.o 4 + rtla-y += osnoise_top.o 5 + rtla-y += osnoise_hist.o 6 + rtla-y += timerlat.o 7 + rtla-y += timerlat_top.o 8 + rtla-y += timerlat_hist.o 9 + rtla-y += timerlat_u.o 10 + rtla-y += timerlat_aa.o 11 + rtla-y += rtla.o