* [RFC] perf build: Use self-contained headers from kernel source when compiling
@ 2025-11-24 7:23 hupu
2025-11-24 7:51 ` hupu
2025-11-25 16:39 ` Leo Yan
0 siblings, 2 replies; 7+ messages in thread
From: hupu @ 2025-11-24 7:23 UTC (permalink / raw)
To: namhyung, leo.yan
Cc: acme, adrian.hunter, alexander.shishkin, hupu.gm, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
When building perf, switch to using the self-contained headers provided
in the kernel source tree to avoid build failures caused by missing
architecture-specific headers. For example, the build may fail with
errors like:
/usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not
found
5 | #include <asm/ioctl.h>
| ^~~~~~~~~~~~~
This issue may occur because system-installed headers are incomplete,
incompatible with the kernel version being built, or the corresponding
architecture-specific headers are not installed at all. Using the
self-contained headers from the kernel source ensures a consistent and
compatible build environment.
Signed-off-by: hupu <hupu.gm@gmail.com>
---
tools/perf/Makefile.perf | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 47c906b807ef..eaccaae87e3c 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1202,7 +1202,9 @@ endif
CLANG_OPTIONS = -Wall
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
-BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
+KHDR_INCLUDES := $(abspath $(OUTPUT)/../../usr/include)
+BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) \
+ -I$(KHDR_INCLUDES) $(CLANG_SYS_INCLUDES)
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
ifneq ($(WERROR),0)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-11-24 7:23 [RFC] perf build: Use self-contained headers from kernel source when compiling hupu
@ 2025-11-24 7:51 ` hupu
2025-11-25 13:12 ` hupu
2025-11-25 16:39 ` Leo Yan
1 sibling, 1 reply; 7+ messages in thread
From: hupu @ 2025-11-24 7:51 UTC (permalink / raw)
To: namhyung, leo.yan
Cc: acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
Hi All Maintainers:
The background of this PATCH is explained in the email linked below.
To avoid potential disagreement from submitting multiple PATCHes in a
single email, this email focuses solely on discussing whether to use
self-contained headers from the kernel source when building perf.
https://lore.kernel.org/all/20251013080609.2070555-1-hupu.gm@gmail.com/
Thanks,
hupu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-11-24 7:51 ` hupu
@ 2025-11-25 13:12 ` hupu
0 siblings, 0 replies; 7+ messages in thread
From: hupu @ 2025-11-25 13:12 UTC (permalink / raw)
To: namhyung, leo.yan
Cc: acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
RESEND for attention.
On Mon, Nov 24, 2025 at 3:51 PM hupu <hupu.gm@gmail.com> wrote:
>
> Hi All Maintainers:
>
> The background of this PATCH is explained in the email linked below.
> To avoid potential disagreement from submitting multiple PATCHes in a
> single email, this email focuses solely on discussing whether to use
> self-contained headers from the kernel source when building perf.
>
> https://lore.kernel.org/all/20251013080609.2070555-1-hupu.gm@gmail.com/
>
> Thanks,
> hupu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-11-24 7:23 [RFC] perf build: Use self-contained headers from kernel source when compiling hupu
2025-11-24 7:51 ` hupu
@ 2025-11-25 16:39 ` Leo Yan
2025-12-05 6:29 ` hupu
1 sibling, 1 reply; 7+ messages in thread
From: Leo Yan @ 2025-11-25 16:39 UTC (permalink / raw)
To: hupu
Cc: namhyung, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
On Mon, Nov 24, 2025 at 03:23:10PM +0800, hupu wrote:
> When building perf, switch to using the self-contained headers provided
> in the kernel source tree to avoid build failures caused by missing
> architecture-specific headers. For example, the build may fail with
> errors like:
>
> /usr/include/linux/ioctl.h:5:10: fatal error: 'asm/ioctl.h' file not
> found
> 5 | #include <asm/ioctl.h>
> | ^~~~~~~~~~~~~
>
> This issue may occur because system-installed headers are incomplete,
> incompatible with the kernel version being built, or the corresponding
> architecture-specific headers are not installed at all. Using the
> self-contained headers from the kernel source ensures a consistent and
> compatible build environment.
>
> Signed-off-by: hupu <hupu.gm@gmail.com>
> ---
> tools/perf/Makefile.perf | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index 47c906b807ef..eaccaae87e3c 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -1202,7 +1202,9 @@ endif
>
> CLANG_OPTIONS = -Wall
> CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
> -BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
> +KHDR_INCLUDES := $(abspath $(OUTPUT)/../../usr/include)
This doesn't work if use the commands:
make -j `nproc` Image O=$OUT
make headers_install O=$OUT
make O=$OUT -C tools/perf VF=1 CORESIGHT=1 DEBUG=1
Maybe it is good to search possible paths:
$(abspath ../../usr/include) => Build in local folder
$(abspath $(OUTPUT)usr/include) => Build in a specified folder
> +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) \
> + -I$(KHDR_INCLUDES) $(CLANG_SYS_INCLUDES)
Why the issue only happens for eBPF skel build but not for perf binary
build? As I said in another reply, I'd consolidate options for both
cases.
Thanks,
Leo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-11-25 16:39 ` Leo Yan
@ 2025-12-05 6:29 ` hupu
2025-12-08 9:04 ` hupu
0 siblings, 1 reply; 7+ messages in thread
From: hupu @ 2025-12-05 6:29 UTC (permalink / raw)
To: Leo Yan
Cc: namhyung, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
Hi Leo,
Thank you for your reply.
On Wed, Nov 26, 2025 at 12:39 AM Leo Yan <leo.yan@arm.com> wrote:
>
[...]
>
> This doesn't work if use the commands:
>
> make -j `nproc` Image O=$OUT
> make headers_install O=$OUT
> make O=$OUT -C tools/perf VF=1 CORESIGHT=1 DEBUG=1
>
Oh, yes, I followed the steps you provided and was able to reproduce
the issue exactly as described. Thank you very much for pointing it
out.
> Maybe it is good to search possible paths:
>
> $(abspath ../../usr/include) => Build in local folder
> $(abspath $(OUTPUT)usr/include) => Build in a specified folder
>
> > +BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) \
> > + -I$(KHDR_INCLUDES) $(CLANG_SYS_INCLUDES)
>
I agree with your suggestion, but I think the following search path
order might be more suitable.
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 47c906b807ef..0f1113b8552c 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -1202,7 +1202,13 @@ endif
CLANG_OPTIONS = -Wall
CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
-BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) $(CLANG_SYS_INCLUDES)
+
+KHDR_INCLUDES := -I$(abspath $(OUTPUT)../../usr/include) \
+-I$(abspath $(OUTPUT)../../arch/$(SRCARCH)/include/generated/uapi) \
+-I$(abspath $(OUTPUT)../../arch/$(SRCARCH)/include/uapi)
+
+BPF_INCLUDE := -I$(SKEL_TMP_OUT)/.. -I$(LIBBPF_INCLUDE) \
+ $(KHDR_INCLUDES) $(CLANG_SYS_INCLUDES)
TOOLS_UAPI_INCLUDE := -I$(srctree)/tools/include/uapi
ifneq ($(WERROR),0)
It’s worth noting that if the 'O=XXX' parameter is not specified
during the build, the OUTPUT variable will be empty. In this case, the
header files will be searched under the kernel source tree, which
corresponds to the 'local folder' scenario you mentioned above.
I have tested the patch in both scenarios below, and it works
correctly in each case:
Case 1: Build with 'O=$BUILD_DIR' specified
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE Image O=$BUILD_DIR -j$JOBS
make headers_install O=$BUILD_DIR
make perf ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE O=$BUILD_DIR -j$JOBS
Case 2: Build without O=$BUILD_DIR specified
make ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE Image -j$JOBS
make headers_install
make perf ARCH=$ARCH CROSS_COMPILE=$CROSS_COMPILE -j$JOBS
> Why the issue only happens for eBPF skel build but not for perf binary
> build? As I said in another reply, I'd consolidate options for both
> cases.
>
Regarding your question — “Why does the issue only occur for eBPF skel
build, but not for perf binary build?” — here is my personal opinion:
As I mentioned in my previous reply (link below), eBPF skel and perf
binary are built using different toolchains — clang for the former,
and gcc or a cross-compilation toolchain for the latter. Without
deliberate unification, they will naturally use different compiler
options during the build process.
https://lore.kernel.org/all/CADHxFxQ2kb2pRhn0-_PJwmo9pykHzDMJDPQay5GaqmmZF1nwSw@mail.gmail.com/#t
Thanks,
hupu
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-12-05 6:29 ` hupu
@ 2025-12-08 9:04 ` hupu
2025-12-10 10:24 ` hupu
0 siblings, 1 reply; 7+ messages in thread
From: hupu @ 2025-12-08 9:04 UTC (permalink / raw)
To: Leo Yan
Cc: namhyung, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
RESEND for your attention.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC] perf build: Use self-contained headers from kernel source when compiling
2025-12-08 9:04 ` hupu
@ 2025-12-10 10:24 ` hupu
0 siblings, 0 replies; 7+ messages in thread
From: hupu @ 2025-12-10 10:24 UTC (permalink / raw)
To: Leo Yan
Cc: namhyung, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
justinstitt, linux-kernel, linux-perf-users, mark.rutland, mingo,
morbo, nathan, nick.desaulniers+lkml, peterz
RESEND AGAIN
On Mon, Dec 8, 2025 at 5:04 PM hupu <hupu.gm@gmail.com> wrote:
>
> RESEND for your attention.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-10 10:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24 7:23 [RFC] perf build: Use self-contained headers from kernel source when compiling hupu
2025-11-24 7:51 ` hupu
2025-11-25 13:12 ` hupu
2025-11-25 16:39 ` Leo Yan
2025-12-05 6:29 ` hupu
2025-12-08 9:04 ` hupu
2025-12-10 10:24 ` hupu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).