From 24f73b85f887122df8343346a106be144e6d814a Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Tue, 24 Oct 2023 16:42:55 +0200 Subject: [PATCH] package/linux-tools: add rtla The RealTime Linux Analysis tool includes a set of commands that relies on the osnoise and timerlat tracers from the ftrace kernel subsystem, allowing to analyze the lantency sources coming from the hardware and the kernel itself. This tool was introduced in v5.17 but until v5.19 it relied on libprocps that has been deprecated soon. So let's make it available for v5.19+. Rtla relies on libtracefs and libtraceevent, although libtraceevent itself is already a dependency for libtracefs. Signed-off-by: Maxime Chevallier [Giulio: fix install on recent Linux versions] Signed-off-by: Giulio Benetti [Andreas: deal with Linux Fixups, musl, SSP] Signed-off-by: Andreas Ziegler [yann.morin.1998@free.fr: reword and extend help text] Signed-off-by: Yann E. MORIN --- DEVELOPERS | 2 + package/linux-tools/Config.in | 21 +++++++++ package/linux-tools/linux-tool-rtla.mk.in | 52 +++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 package/linux-tools/linux-tool-rtla.mk.in diff --git a/DEVELOPERS b/DEVELOPERS index 86588b1adb..d7543247f2 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1237,6 +1237,7 @@ F: package/libnss/ F: package/libnvme/ F: package/libtraceevent/ F: package/libtracefs +F: package/linux-tools/linux-tool-rtla.mk.in F: package/mali-driver/ F: package/minicom/ F: package/mongoose/ @@ -2136,6 +2137,7 @@ F: package/timescaledb/ N: Maxime Chevallier F: package/libtraceevent/ F: package/libtracefs +F: package/linux-tools/linux-tool-rtla.mk.in N: Michael Durrant F: board/arcturus/ diff --git a/package/linux-tools/Config.in b/package/linux-tools/Config.in index 451b0eeff5..adfca4dbe3 100644 --- a/package/linux-tools/Config.in +++ b/package/linux-tools/Config.in @@ -102,6 +102,27 @@ config BR2_PACKAGE_LINUX_TOOLS_PERF_NEEDS_HOST_PYTHON3 endif +config BR2_PACKAGE_LINUX_TOOLS_RTLA + bool "rtla" + select BR2_PACKAGE_LINUX_TOOLS + select BR2_PACKAGE_LIBTRACEFS + help + These tracers allow performing latency analysis, for which the + rtla tool provides wrapper commands to visualize and extract + latency traces and reports. + + rtla includes three tracers, which have been introduced in + different kernel versions: + - Linux 5.19 introduced the osnoise and timerlat tracers, + - Linux 6.3 introduced the hwnoise tracer + + osnoise and timerlat are always installed, while hwnoise is + installed if your kernel is recent enough. + + Note: rtla in kernels before 5.19 had additional dependencies, + not available in Buildroot, so only rtla in kernels 5.19 + onwards is actually supported in Buildroot. + config BR2_PACKAGE_LINUX_TOOLS_SELFTESTS bool"selftests" depends on BR2_PACKAGE_BUSYBOX_SHOW_OTHERS # bash diff --git a/package/linux-tools/linux-tool-rtla.mk.in b/package/linux-tools/linux-tool-rtla.mk.in new file mode 100644 index 0000000000..449371ddfe --- /dev/null +++ b/package/linux-tools/linux-tool-rtla.mk.in @@ -0,0 +1,52 @@ +################################################################################ +# +# rtla +# +################################################################################ + +LINUX_TOOLS += rtla + +RTLA_DEPENDENCIES = host-pkgconf libtracefs +RTLA_MAKE_OPTS = $(LINUX_MAKE_FLAGS) \ + CC=$(TARGET_CC) \ + EXTRA_CFLAGS="-D_GNU_SOURCE" \ + LDFLAGS="$(TARGET_LDFLAGS)" \ + PKG_CONFIG_PATH=$(STAGING_DIR)/usr/lib/pkgconfig + +ifeq ($(BR2_TOOLCHAIN_HAS_SSP),) +define RTLA_DISABLE_STACK_PROTECTOR + $(SED) 's/-fstack-protector.* //' $(LINUX_DIR)/tools/tracing/rtla/Makefile +endef +endif + +define RTLA_LINUX_CONFIG_FIXUPS + $(call KCONFIG_ENABLE_OPT,CONFIG_FTRACE) + $(call KCONFIG_ENABLE_OPT,CONFIG_TIMERLAT_TRACER) + $(call KCONFIG_ENABLE_OPT,CONFIG_HIST_TRIGGERS) +endef + +define RTLA_BUILD_CMDS + $(Q)if ! grep install $(LINUX_DIR)/tools/tracing/rtla/Makefile >/dev/null 2>&1 ; then \ + echo "Your kernel version is too old and does not implement the rtla tool." ; \ + echo "At least kernel 5.19 must be used." ; \ + exit 1 ; \ + fi + $(RTLA_DISABLE_STACK_PROTECTOR) + $(TARGET_MAKE_ENV) $(MAKE) $(RTLA_MAKE_OPTS) \ + -C $(LINUX_DIR)/tools/tracing rtla +endef + +# make rtla_install build and install by default documentation using rst2man +# but it's not available in Buildroot and we don't want manual files in target +# folder so let's simply install the resulting rtla binary and create symlinks +# like Linux does in its tools/tracing/rtla/Makefile +define RTLA_INSTALL_TARGET_CMDS + $(INSTALL) -m 0755 -D $(LINUX_DIR)/tools/tracing/rtla/rtla $(TARGET_DIR)/usr/bin + ln -sf rtla $(TARGET_DIR)/usr/bin/osnoise + ln -sf rtla $(TARGET_DIR)/usr/bin/timerlat + + # Check if hwnoise is provided or not + if grep -q hwnoise $(LINUX_DIR)/tools/tracing/rtla/Makefile; then \ + ln -sf rtla $(TARGET_DIR)/usr/bin/hwnoise ; \ + fi +endef