[PATCH v3 0/2] linux-custom: add linux-perf package

1 view
Skip to first unread message

Isaac True

unread,
Nov 27, 2025, 6:31:12 AM (8 days ago) Nov 27
to isar-...@googlegroups.com, Isaac True
Modify the linux-custom recipe to additionally generate a linux-perf
package, build the perf binary, and add this binary to the new package.
This is useful for profiling application and kernel performance on
targets.

Changes since v2:

- Bring the packaging more in-line with the Debian kernel packages and
rename linux-tools to linux-perf and use the package description from
the linux-perf Debian package.
- Rename the build profile from "tools" to "notools" and invert the
logic used to determine whether to build perf. This brings it more
in-line with how the Debian kernel packaging works. The accompanying
variable has been renamed from `KERNEL_BUILD_TOOLS` to
`KERNEL_BUILD_NOTOOLS`.

Changes since v1:

- Make generation of the linux-tools package configurable. If the
`KERNEL_BUILD_TOOLS` variable is set to `"1"`, perf will be built
and the package will be generated.

Isaac True (2):
linux-custom: build perf and add it to the linux-perf package
doc: custom_kernel: add information on linux-perf

doc/custom_kernel.md | 9 +++++----
meta/recipes-kernel/linux/files/debian/control.tmpl | 9 +++++++++
meta/recipes-kernel/linux/files/debian/isar/build.tmpl | 3 +++
.../recipes-kernel/linux/files/debian/isar/common.tmpl | 2 ++
.../linux/files/debian/isar/install.tmpl | 7 +++++++
meta/recipes-kernel/linux/files/debian/rules.tmpl | 2 +-
meta/recipes-kernel/linux/linux-custom.inc | 10 ++++++++++
7 files changed, 37 insertions(+), 5 deletions(-)

Isaac True

unread,
Nov 27, 2025, 6:31:18 AM (8 days ago) Nov 27
to isar-...@googlegroups.com, Isaac True
Add an additional package to the linux-custom recipe containing the perf
tool, which is built as part of the kernel build process. This package
is only created and perf is only built if the "notools" profile is not
active, which is controlled by the new variable "KERNEL_BUILD_NOTOOLS"
and enabled by default.

Signed-off-by: Isaac True <it...@emlix.com>
---
meta/recipes-kernel/linux/files/debian/control.tmpl | 9 +++++++++
meta/recipes-kernel/linux/files/debian/isar/build.tmpl | 3 +++
.../recipes-kernel/linux/files/debian/isar/common.tmpl | 2 ++
.../linux/files/debian/isar/install.tmpl | 7 +++++++
meta/recipes-kernel/linux/files/debian/rules.tmpl | 2 +-
meta/recipes-kernel/linux/linux-custom.inc | 10 ++++++++++
6 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/meta/recipes-kernel/linux/files/debian/control.tmpl b/meta/recipes-kernel/linux/files/debian/control.tmpl
index ee87cf92..155c2808 100644
--- a/meta/recipes-kernel/linux/files/debian/control.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/control.tmpl
@@ -69,3 +69,12 @@ Conflicts: linux-kbuild-${KERNEL_NAME_PROVIDED}
Description: ${KERNEL_NAME_PROVIDED} Linux kbuild scripts and tools for @KR@
This package provides kernel kbuild scripts and tools for @KR@
This is useful for people who need to build external modules
+
+Package: linux-perf-${KERNEL_NAME_PROVIDED}
+Build-Profiles: <pkg.${BPN}.kernel !pkg.${BPN}.notools>
+Section: devel
+Architecture: any
+Multi-Arch: foreign
+Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends}, ${python3:Depends}
+Description: ${KERNEL_NAME_PROVIDED} performance analysis tools for @KR@
+ This package contains the 'perf' performance analysis tools for @KR@.
diff --git a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
index b4c105c1..f518ce34 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/build.tmpl
@@ -23,6 +23,9 @@ do_build() {

if echo "${DEB_BUILD_PROFILES}" | grep -q "kernel"; then # Build kernel scripts and tools
${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}"
+ if ! echo "${DEB_BUILD_PROFILES}" | grep -q "notools"; then # Build kernel tools
+ ${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" -C tools/perf
+ fi
elif echo "${DEB_BUILD_PROFILES}" | grep -q "kbuild"; then # Build kernel scripts and tools
${MAKE} O=${KERNEL_BUILD_DIR} ${PARALLEL_MAKE} ${KERNEL_EXTRA_BUILDARGS} KCFLAGS="${KCFLAGS}" KAFLAGS="${KAFLAGS}" scripts
if grep -q -E "CONFIG_STACK_VALIDATION=y|CONFIG_HAVE_OBJTOOL=y" ${KERNEL_BUILD_DIR}/.config && [ -d "tools/objtool" ]; then
diff --git a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
index f9cc2f02..07283dcd 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/common.tmpl
@@ -12,6 +12,7 @@ KERNEL_PKG_LIBC_HEADERS=linux-libc-dev
KERNEL_PKG_LIBC_HEADERS_CROSS=linux-libc-dev-${DISTRO_ARCH}-cross
KERNEL_PKG_KERN_KBUILD=linux-kbuild-${KERNEL_NAME_PROVIDED}
KERNEL_PKG_KERN_KBUILD_CROSS=${KERNEL_PKG_KERN_KBUILD}-${DISTRO_ARCH}-cross
+KERNEL_PKG_PERF=linux-perf-${KERNEL_NAME_PROVIDED}

# Force creating debian package with valid host arch for -native build
# Use a cross build to comply with arch specific kernel defconfigs
@@ -38,6 +39,7 @@ deb_libc_hdr_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS}
deb_libc_hdr_cross_dir=${deb_top_dir}/${KERNEL_PKG_LIBC_HEADERS_CROSS}
deb_kern_kbuild_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD}
deb_kern_kbuild_cross_dir=${deb_top_dir}/${KERNEL_PKG_KERN_KBUILD_CROSS}
+deb_perf_dir=${deb_top_dir}/${KERNEL_PKG_PERF}

# Array of packages to be generated
declare -A kern_pkgs
diff --git a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
index 6fa94508..e6badb2f 100644
--- a/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/isar/install.tmpl
@@ -68,6 +68,9 @@ do_install() {
install_dtbs
install_kmods
install_headers
+ if ! echo "${DEB_BUILD_PROFILES}" | grep -q "notools"; then
+ install_tools
+ fi
fi

# Stop tracing
@@ -137,6 +140,10 @@ install_dtbs() {
${MAKE} O=${O} INSTALL_DTBS_PATH=${deb_img_dir}/usr/lib/linux-image-${krel} dtbs_install
}

+install_tools() {
+ install -Dm0755 ${O}/perf ${deb_perf_dir}/usr/bin/perf
+}
+
install_kmods() {
[ -n "${CONFIG_MODULES}" ] || return 0
${MAKE} O=${O} modules_install \
diff --git a/meta/recipes-kernel/linux/files/debian/rules.tmpl b/meta/recipes-kernel/linux/files/debian/rules.tmpl
index 598ae93f..a3b25396 100755
--- a/meta/recipes-kernel/linux/files/debian/rules.tmpl
+++ b/meta/recipes-kernel/linux/files/debian/rules.tmpl
@@ -45,4 +45,4 @@ override_dh_strip_nondeterminism:
true

override_dh_strip:
- unset DEB_HOST_GNU_TYPE && dh_strip -Xvmlinu --no-automatic-dbgsym
+ unset DEB_HOST_GNU_TYPE && dh_strip -Xvmlinu -Xperf --no-automatic-dbgsym
diff --git a/meta/recipes-kernel/linux/linux-custom.inc b/meta/recipes-kernel/linux/linux-custom.inc
index ccbea976..8d9846cd 100644
--- a/meta/recipes-kernel/linux/linux-custom.inc
+++ b/meta/recipes-kernel/linux/linux-custom.inc
@@ -169,6 +169,14 @@ RECIPE_PROVIDES:append:libcdev = " \
linux-libc-dev-${DISTRO_ARCH}-cross \
"

+# Set to "0" to disable the notools build profile and build the linux-perf package
+KERNEL_BUILD_NOTOOLS ??= "1"
+
+# Provide the linux-perf package if the notools build profile has not been enabled
+RECIPE_PROVIDES:append = " \
+ ${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.notools'.format(d.getVar('BPN')), '', 'linux-perf-{}'.format(d.getVar('KERNEL_NAME_PROVIDED')), d)} \
+"
+
# When cross-profile is active:
# kbuild package is provided by -native or -kbuildtarget variant. Also headers
# provisioning moves over to ensure those variants are pulled, although the
@@ -231,6 +239,8 @@ def get_additional_build_profiles(d):
profiles += ' pkg.{}.nolibcdev'.format(d.getVar('BPN'))
elif bb.utils.to_boolean(d.getVar('KERNEL_LIBC_DEV_ARCH_ALL')):
profiles += ' pkg.{}.libcdev-arch-all'.format(d.getVar('BPN'))
+ if bb.utils.to_boolean(d.getVar('KERNEL_BUILD_NOTOOLS')):
+ profiles += ' pkg.{}.notools'.format(d.getVar('BPN'))
return profiles

KERNEL_LIBC_DEV_ARCH = "${@ bb.utils.contains('DEB_BUILD_PROFILES', 'pkg.{}.libcdev-arch-all'.format(d.getVar('BPN')), 'all\nMulti-Arch: foreign', 'any', d) }"

Isaac True

unread,
Nov 27, 2025, 6:31:23 AM (8 days ago) Nov 27
to isar-...@googlegroups.com, Isaac True
Remove the "Package perf" from the future ideas list and add it to the
"Features" list with the new linux-perf package.

Signed-off-by: Isaac True <it...@emlix.com>
---
doc/custom_kernel.md | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/doc/custom_kernel.md b/doc/custom_kernel.md
index ce5f1bf7..87eacfe4 100644
--- a/doc/custom_kernel.md
+++ b/doc/custom_kernel.md
@@ -68,15 +68,16 @@ The linux-custom recipe provides support for:

14. Support `devshell` (kernel configuration shall be applied)

+ 15. Produce a `linux-perf` package which includes the `perf` binary if building
+ kernel tools has not been disabled (`KERNEL_BUILD_NOTOOLS` equals to `"0"`)
+
## Future

In the future, the recipe may be extended to:

- 1. Package perf
+ 1. Support inclusion/build of dts files listed in `SRC_URI`

- 2. Support inclusion/build of dts files listed in `SRC_URI`
-
- 3. Be compatible with Ubuntu
+ 2. Be compatible with Ubuntu

## Examples

Jan Kiszka

unread,
Nov 27, 2025, 6:39:34 AM (8 days ago) Nov 27
to Isaac True, isar-...@googlegroups.com
That's like linux-libc-dev vs. linux-libc-dev-${KERNEL_NAME_PROVIDED} -
we had to roll back the latter recently, see git.

Why not "linux-perf"?

Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
Reply all
Reply to author
Forward
0 new messages