[4/6] rtla: Add kernel recipe for rtla

Message ID 20240819074202.34144-5-patrick.barsanti@amarulasolutions.com
State New
Headers show
Series
  • Add support for rtla tool
Related show

Commit Message

Patrick Barsanti Aug. 19, 2024, 7:42 a.m. UTC
The rtla is a meta-tool that includes a set of commands that aims
to analyze the real-time properties of Linux.
Add support for it in poky.

Signed-off-by: Patrick Barsanti <patrick.barsanti@amarulasolutions.com>
---
 meta/recipes-kernel/rtla/rtla.bb | 137 +++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)
 create mode 100644 meta/recipes-kernel/rtla/rtla.bb

Patch

diff --git a/meta/recipes-kernel/rtla/rtla.bb b/meta/recipes-kernel/rtla/rtla.bb
new file mode 100644
index 0000000000..3eab857f92
--- /dev/null
+++ b/meta/recipes-kernel/rtla/rtla.bb
@@ -0,0 +1,137 @@ 
+SUMMARY = "RTLA (Real-Time Linux Analysis) tool"
+DESCRIPTION = "The rtla is a meta-tool that includes a set of commands that \
+    aims to analyze the real-time properties of Linux. But instead of testing \
+    Linux as a black box, rtla leverages kernel tracing capabilities to provide \
+    precise information about the properties and root causes of unexpected results."
+
+HOMEPAGE = "https://www.kernel.org/doc/html/latest/tools/rtla/rtla.html"
+
+LICENSE = "GPL-2.0-only"
+
+DEPENDS = "\
+    ${MLPREFIX}binutils \
+    ${MLPREFIX}elfutils \
+    bison-native \
+    flex-native \
+    libgcc \
+    libtraceevent \
+    libtracefs \
+    python3 \
+    python3-docutils-native \
+    python3-setuptools-native \
+    virtual/${MLPREFIX}libc \
+    xz \
+"
+
+do_configure[depends] += "virtual/kernel:do_shared_workdir"
+
+PROVIDES = "virtual/rtla"
+
+inherit linux-kernel-base kernel-arch manpages
+
+inherit_defer ${@bb.utils.contains('PACKAGECONFIG', 'python', 'python3targetconfig', '', d)}
+inherit python3-dir
+export PYTHON_SITEPACKAGES_DIR
+
+#kernel 3.1+ supports WERROR to disable warnings as errors
+export WERROR = "0"
+
+do_populate_lic[depends] += "virtual/kernel:do_shared_workdir"
+
+inherit kernelsrc
+
+S = "${WORKDIR}/${BP}"
+
+LDFLAGS = "-ldl -lutil"
+
+EXTRA_OEMAKE = '\
+    V=1 \
+    VF=1 \
+    -C ${S}/tools/tracing/rtla \
+    O=${B} \
+    CROSS_COMPILE=${TARGET_PREFIX} \
+    ARCH=${ARCH} \
+    CC="${CC}" \
+    CCLD="${CC}" \
+    LDSHARED="${CC} -shared" \
+    AR="${AR}" \
+    LD="${LD}" \
+    EXTRA_CFLAGS="-ldw -I${S}" \
+    YFLAGS='-y --file-prefix-map=${WORKDIR}=${TARGET_DBGSRC_DIR}' \
+    ${PACKAGECONFIG_CONFARGS} \
+    PKG_CONFIG=pkg-config \
+    TMPDIR="${B}" \
+    LIBUNWIND_DIR=${STAGING_EXECPREFIXDIR} \
+'
+
+EXTRA_OEMAKE += "\
+    'DESTDIR=${D}' \
+    'prefix=${prefix}' \
+    'bindir=${bindir}' \
+    'sharedir=${datadir}' \
+    'sysconfdir=${sysconfdir}' \
+    'sharedir=${@os.path.relpath(datadir, prefix)}' \
+    'mandir=${@os.path.relpath(mandir, prefix)}' \
+    'infodir=${@os.path.relpath(infodir, prefix)}' \
+    ${@bb.utils.contains('PACKAGECONFIG', 'python', 'PYTHON=python3 PYTHON_CONFIG=python3-config', '', d)} \
+"
+
+# During do_configure, we might run a 'make clean'. That often breaks
+# when done in parallel, so disable parallelism for do_configure.
+EXTRA_OEMAKE:append:task-configure = " JOBS=1"
+
+RTLA_SRC ?= "\
+    arch/${ARCH}/Makefile \
+    arch/arm64/tools \
+    Documentation/tools/rtla \
+    Makefile \
+    scripts/ \
+    tools/arch \
+    tools/build \
+    tools/include \
+    tools/lib \
+    tools/Makefile \
+    tools/scripts \
+    tools/tracing/Makefile \
+    tools/tracing/rtla \
+"
+
+do_compile() {
+    # Linux kernel build system is expected to do the right thing
+    unset CFLAGS
+    test -e ${S}/tools/lib/traceevent/plugins/Makefile && \
+        sed -i -e 's|\$(libdir)/traceevent/plugins|\$(libdir)/traceevent_${KERNEL_VERSION}/plugins|g' ${S}/tools/lib/traceevent/plugins/Makefile
+    test -e ${S}/tools/tracing/rtla/Makefile.config && \
+        sed -i -e 's|\$(libdir)/traceevent/plugins|\$(libdir)/traceevent_${KERNEL_VERSION}/plugins|g' ${S}/tools/tracing/rtla/Makefile.config
+    oe_runmake all
+}
+
+do_install() {
+    # Linux kernel build system is expected to do the right thing
+    unset CFLAGS
+    oe_runmake install
+}
+
+do_configure[prefuncs] += "copy_rtla_source_from_kernel"
+python copy_rtla_source_from_kernel() {
+    sources = (d.getVar("RTLA_SRC") or "").split()
+    src_dir = d.getVar("STAGING_KERNEL_DIR")
+    dest_dir = d.getVar("S")
+    bb.utils.mkdirhier(dest_dir)
+    bb.utils.prunedir(dest_dir)
+    for s in sources:
+        src = oe.path.join(src_dir, s)
+        dest = oe.path.join(dest_dir, s)
+        if not os.path.exists(src):
+            bb.warn("Path does not exist: %s. Maybe RTLA_SRC lists more files than what your kernel version provides and needs." % src)
+            continue
+        if os.path.isdir(src):
+            oe.path.copyhardlinktree(src, dest)
+        else:
+            src_path = os.path.dirname(s)
+            os.makedirs(os.path.join(dest_dir,src_path),exist_ok=True)
+            bb.utils.copyfile(src, dest)
+}
+
+# Skip the stripping QA check
+INSANE_SKIP:${PN} += "already-stripped"