All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jugurtha BELKALEM <jugurtha.belkalem@smile.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 2/2] package/bcc: new package
Date: Thu, 13 Aug 2020 15:02:20 +0200	[thread overview]
Message-ID: <1597323740-20153-3-git-send-email-jugurtha.belkalem@smile.fr> (raw)
In-Reply-To: <1597323740-20153-1-git-send-email-jugurtha.belkalem@smile.fr>

bcc is a front-end tool for eBPF :
https://github.com/iovisor/bcc/blob/master/README.md.
eBPF is the most powerful Linux tracer, and bcc
allows to write eBPF scripts in C and PYTHON3.

bcc can help to troubleshoot issues quickly on
embedded systems (as long as Linux kernel
version >= 4.1).

bcc can also make it easy to create observabilty tools,
SDN configuration, ddos mitigation, intrusion detection
and secure containers. More information is available at:
http://www.brendangregg.com/ebpf.html.

BCC can be tested on the target :
$ mount -t debugfs none /sys/kernel/debug
$ mkdir -p /lib/modules/KERNEL_VERSION/build
$ cd /lib/modules/KERNEL_VERSION//build
$ cp /sys/kernel/kheaders.tar.xz .
$ unxz kheaders.tar.xz
$ tar xf kheaders.tar
$ cd /usr/share/bcc/examples/tracing
$ ./disksnoop.py

Signed-off-by: Jugurtha BELKALEM <jugurtha.belkalem@smile.fr>
---
 DEVELOPERS                                       |  1 +
 package/Config.in                                |  1 +
 package/bcc/0001-fix-aarch64-cross-compile.patch | 65 ++++++++++++++++++++++++
 package/bcc/Config.in                            | 49 ++++++++++++++++++
 package/bcc/bcc.hash                             |  3 ++
 package/bcc/bcc.mk                               | 63 +++++++++++++++++++++++
 6 files changed, 182 insertions(+)
 create mode 100644 package/bcc/0001-fix-aarch64-cross-compile.patch
 create mode 100644 package/bcc/Config.in
 create mode 100644 package/bcc/bcc.hash
 create mode 100644 package/bcc/bcc.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index 42fa5a4..bd836a6 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1396,6 +1396,7 @@ N:	Joshua Henderson <joshua.henderson@microchip.com>
 F:	package/qt5/qt5wayland/
 
 N:	Jugurtha BELKALEM <jugurtha.belkalem@smile.fr>
+F:	package/bcc/
 F:	package/python-cycler/
 F:	package/python-matplotlib/
 
diff --git a/package/Config.in b/package/Config.in
index d7e79f4..8ec3932 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -83,6 +83,7 @@ menu "Compressors and decompressors"
 endmenu
 
 menu "Debugging, profiling and benchmark"
+	source "package/bcc/Config.in"
 	source "package/blktrace/Config.in"
 	source "package/bonnie/Config.in"
 	source "package/cache-calibrator/Config.in"
diff --git a/package/bcc/0001-fix-aarch64-cross-compile.patch b/package/bcc/0001-fix-aarch64-cross-compile.patch
new file mode 100644
index 0000000..6b42797
--- /dev/null
+++ b/package/bcc/0001-fix-aarch64-cross-compile.patch
@@ -0,0 +1,65 @@
+From 5a5b0f04484e00c88e7be902101367d6d591fb96 Mon Sep 17 00:00:00 2001
+From: Jugurtha BELKALEM <jugurtha.belkalem@smile.fr>
+Date: Thu, 2 May 2019 11:06:23 +0200
+Subject: [PATCH] cmake/luajit: Provide the target architecture to luaJIT while
+ cross-compiling
+
+Unlike CMAKE_SYSTEM_PROCESSOR which identifies aarch64
+as a valid architecture, luajit does not recognize it.
+luajit defines aarch64 as arm64.
+
+LuaJIT doesn't use usual arch naming, so we have to convert
+between CMake and Luajit for each architectures while
+cross-compiling.
+
+Signed-off-by: Jugurtha BELKALEM <jugurtha.belkalem@smile.fr>
+Signed-off-by: Romain Naour <romain.naour@smile.fr>
+---
+v2: Do the same for other architecture supported by LuaJIT.
+https://github.com/iovisor/bcc/pull/2480
+---
+ src/lua/CMakeLists.txt | 29 ++++++++++++++++++++++++++++-
+ 1 file changed, 28 insertions(+), 1 deletion(-)
+
+diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt
+index 7541d48df..226e1b1d2 100644
+--- a/src/lua/CMakeLists.txt
++++ b/src/lua/CMakeLists.txt
+@@ -13,9 +13,36 @@ if (LUAJIT_LIBRARIES AND LUAJIT)
+ 		DEPENDS ${SRC_LUA} ${CMAKE_CURRENT_SOURCE_DIR}/squishy
+ 	)
+ 
++	# LuaJIT doesn't use usual arch naming, so we have to convert
++	# between CMake and Luajit while cross-compiling.
++	if (CMAKE_CROSSCOMPILING)
++		SET (LUAJIT_TARGET_ARCH "-a")
++		# https://github.com/LuaJIT/LuaJIT/blob/f0e865dd4861520258299d0f2a56491bd9d602e1/src/jit/bcsave.lua#L30
++		# https://github.com/LuaJIT/LuaJIT/blob/f0e865dd4861520258299d0f2a56491bd9d602e1/src/jit/bcsave.lua#L65
++		if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "arm64")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64_be")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "arm64be")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "arm")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86)$")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "x86")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "mips")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "mipsel")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "mipsel")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "ppc")
++		elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
++			SET (LUAJIT_TARGET_ARCH ${LUAJIT_TARGET_ARCH} "x64")
++		else()
++			MESSAGE(FATAL_ERROR "${CMAKE_SYSTEM_PROCESSOR} is not supported by LuaJIT")
++		endif()
++	endif()
++
+ 	ADD_CUSTOM_COMMAND(
+ 		OUTPUT bcc.o
+-		COMMAND ${LUAJIT} -bg bcc.lua bcc.o
++		COMMAND ${LUAJIT} -bg bcc.lua ${LUAJIT_TARGET_ARCH} bcc.o
+ 		DEPENDS bcc.lua
+ 	)
+ 
diff --git a/package/bcc/Config.in b/package/bcc/Config.in
new file mode 100644
index 0000000..a3cc402
--- /dev/null
+++ b/package/bcc/Config.in
@@ -0,0 +1,49 @@
+config BR2_PACKAGE_BCC
+	bool "bcc"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_LUAJIT_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_USES_GLIBC # hardcode GNU tuple (x86_64-unknown-linux-gnu)
+	depends on BR2_LINUX_KERNEL # needs kernel sources on the target
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 # clang
+	depends on BR2_TOOLCHAIN_HAS_THREADS # clang
+	depends on BR2_INSTALL_LIBSTDCPP # clang
+	select BR2_PACKAGE_AUDIT # runtime
+	select BR2_PACKAGE_CLANG
+	select BR2_PACKAGE_ELFUTILS
+	select BR2_PACKAGE_FLEX # needs FlexLexer.h
+	select BR2_PACKAGE_IPERF3 # runtime
+	select BR2_PACKAGE_LLVM_BPF
+	select BR2_PACKAGE_LUAJIT
+	select BR2_PACKAGE_NETPERF # runtime
+	select BR2_PACKAGE_PYTHON3
+	select BR2_PACKAGE_XZ # Decompress kernel headers required by BCC
+	help
+	  BPF Compiler Collection (BCC)
+
+	  BCC is a toolkit for creating efficient kernel tracing and
+	  manipulation programs, and includes several useful tools and
+	  examples. It makes use of extended BPF (Berkeley Packet
+	  Filters), formally known as eBPF, a new feature that was
+	  first added to Linux 3.15. Much of what BCC uses requires
+	  Linux 4.1 and above.
+
+	  Note: Before using bcc, you need either :
+	  - Copy the kernel source code to target folder
+	  /lib/module/<kernel version>/build.
+	  - Compile kernel with CONFIG_IKHEADERS (kernel_ver > 5.2)
+	  and use generated headers to populate
+	  /lib/module/<kernel version>/build.
+
+	  That's because the clang frontend build eBPF code at runtime.
+
+	  https://github.com/iovisor/bcc
+
+comment "bcc needs a Linux kernel to be built"
+	depends on !BR2_LINUX_KERNEL
+
+comment "bcc needs a glibc toolchain w/ wchar, threads, C++, gcc >= 4.8, host gcc >= 4.8"
+	depends on BR2_PACKAGE_LLVM_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_LUAJIT_ARCH_SUPPORTS
+	depends on BR2_LINUX_KERNEL
+	depends on !BR2_TOOLCHAIN_USES_GLIBC || !BR2_TOOLCHAIN_HAS_THREADS \
+		|| !BR2_INSTALL_LIBSTDCPP
diff --git a/package/bcc/bcc.hash b/package/bcc/bcc.hash
new file mode 100644
index 0000000..e01a2e8
--- /dev/null
+++ b/package/bcc/bcc.hash
@@ -0,0 +1,3 @@
+# locally calculated
+sha256 518f2ee52139dcc69c589be7a6171928dc2c1cf2cdb7d0c1468134166aa84ca1  bcc-v0.15.0.tar.gz
+sha256 b40930bbcf80744c86c46a12bc9da056641d722716c378f5659b9e555ef833e1  LICENSE.txt
diff --git a/package/bcc/bcc.mk b/package/bcc/bcc.mk
new file mode 100644
index 0000000..f6a2e12
--- /dev/null
+++ b/package/bcc/bcc.mk
@@ -0,0 +1,63 @@
+################################################################################
+#
+# bcc
+#
+################################################################################
+
+BCC_VERSION = v0.15.0
+BCC_SITE = https://github.com/iovisor/bcc.git
+BCC_SITE_METHOD = git
+BCC_GIT_SUBMODULES = YES
+BCC_LICENSE = Apache-2.0
+BCC_LICENSE_FILES = LICENSE.txt
+# libbcc.so and libbpf.so
+BCC_INSTALL_STAGING = YES
+BCC_DEPENDENCIES = host-bison host-flex host-luajit clang elfutils flex llvm \
+		   luajit
+
+# ENABLE_LLVM_SHARED=ON to use llvm.so.
+# Force REVISION otherwise bcc will use git describe to generate a version number.
+BCC_CONF_OPTS = -DENABLE_LLVM_SHARED=ON \
+	-DREVISION=$(BCC_VERSION) \
+	-DENABLE_CLANG_JIT=ON \
+	-DENABLE_MAN=OFF
+
+# BCC compiles src/python/setup.py.in into /src/python.
+# The generated compiled folder (/src/python/bcc-python/bcc) should
+# be copied to target python's site-packages directory.
+define BCC_INSTALL_PYTHON_BCC
+       cp -r $(BUILD_DIR)/bcc-$(BCC_VERSION)/src/python/bcc-python/bcc \
+               $(TARGET_DIR)/usr/lib/python3.*/site-packages/
+endef
+BCC_POST_INSTALL_TARGET_HOOKS += BCC_INSTALL_PYTHON_BCC
+
+define BCC_LINUX_CONFIG_FIXUPS
+       # Enable kernel support for eBPF
+       $(call KCONFIG_ENABLE_OPT,CONFIG_BPF)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_BPF_SYSCALL)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_CLS_BPF)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_ACT_BPF)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_BPF_JIT)
+       # [for Linux kernel versions 4.1 through 4.6]
+       $(call KCONFIG_ENABLE_OPT,CONFIG_HAVE_BPF_JIT)
+       # [for Linux kernel versions 4.7 and later]
+       $(call KCONFIG_ENABLE_OPT,CONFIG_HAVE_EBPF_JIT)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_BPF_EVENTS)
+       # [for Linux kernel versions 5.3 and later]
+       $(call KCONFIG_ENABLE_OPT,CONFIG_IKHEADERS)
+       # For running bcc networking examples on vanilla kernel
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_SCH_SFQ)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_ACT_POLICE)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_ACT_GACT)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_DUMMY)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_VXLAN)
+       # Testing
+       $(call KCONFIG_ENABLE_OPT,CONFIG_KPROBES)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_FTRACE)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_BPFILTER)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_CGROUP_BPF)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_CLS_ACT)
+       $(call KCONFIG_ENABLE_OPT,CONFIG_NET_ACT_BPF)
+endef
+
+$(eval $(cmake-package))
-- 
2.7.4

  parent reply	other threads:[~2020-08-13 13:02 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-13 13:02 [Buildroot] [PATCH 0/2] bcc front end tool for eBPF Jugurtha BELKALEM
2020-08-13 13:02 ` [Buildroot] [PATCH 1/2] package/llvm: add BPF backend Jugurtha BELKALEM
2020-08-13 13:02 ` Jugurtha BELKALEM [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-08-24 18:17 Jugurtha BELKALEM
2020-08-24 18:17 ` [Buildroot] [PATCH 2/2] package/bcc: new package Jugurtha BELKALEM
2020-10-04 18:12   ` Qais Yousef
2020-10-08 22:48     ` Qais Yousef
2020-11-03 22:34     ` Romain Naour
2020-11-24 16:41       ` Qais Yousef
2020-08-13 13:05 [Buildroot] [PATCH 0/2] bcc front end tool for eBPF Jugurtha BELKALEM
2020-08-13 13:05 ` [Buildroot] [PATCH 2/2] package/bcc: new package Jugurtha BELKALEM
2019-01-13 21:21 [Buildroot] [PATCH 1/2] package/llvm: add BPF backend Romain Naour
2019-01-13 21:21 ` [Buildroot] [PATCH 2/2] package/bcc: new package Romain Naour
2019-01-14 19:40   ` Romain Naour
2019-01-14 20:43   ` Matthew Weber
2019-01-14 21:00     ` Romain Naour
2019-03-14 17:15       ` Romain Naour

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1597323740-20153-3-git-send-email-jugurtha.belkalem@smile.fr \
    --to=jugurtha.belkalem@smile.fr \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.