diff mbox series

[bpf-next,3/3] bpf: iterators: build and use lightweight bootstrap version of bpftool

Message ID 20220712030813.865410-4-pulehui@huawei.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Use lightweigt version of bpftool | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: haoluo@google.com song@kernel.org martin.lau@linux.dev jolsa@kernel.org sdf@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc

Commit Message

Pu Lehui July 12, 2022, 3:08 a.m. UTC
kernel/bpf/preload/iterators use bpftool for vmlinux.h, skeleton, and
static linking only. So we can use lightweight bootstrap version of
bpftool to handle these, and it will be faster.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
Suggested-by: Andrii Nakryiko <andrii@kernel.org>
---
 kernel/bpf/preload/iterators/Makefile | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Comments

Andrii Nakryiko July 13, 2022, 6:55 p.m. UTC | #1
On Mon, Jul 11, 2022 at 7:37 PM Pu Lehui <pulehui@huawei.com> wrote:
>
> kernel/bpf/preload/iterators use bpftool for vmlinux.h, skeleton, and
> static linking only. So we can use lightweight bootstrap version of
> bpftool to handle these, and it will be faster.
>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
> ---
>  kernel/bpf/preload/iterators/Makefile | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/bpf/preload/iterators/Makefile b/kernel/bpf/preload/iterators/Makefile
> index bfe24f8c5a20..cf5f39f95fed 100644
> --- a/kernel/bpf/preload/iterators/Makefile
> +++ b/kernel/bpf/preload/iterators/Makefile
> @@ -9,7 +9,7 @@ LLVM_STRIP ?= llvm-strip
>  TOOLS_PATH := $(abspath ../../../../tools)
>  BPFTOOL_SRC := $(TOOLS_PATH)/bpf/bpftool
>  BPFTOOL_OUTPUT := $(abs_out)/bpftool
> -DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
> +DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)/bootstrap/bpftool
>  BPFTOOL ?= $(DEFAULT_BPFTOOL)
>
>  LIBBPF_SRC := $(TOOLS_PATH)/lib/bpf
> @@ -61,9 +61,14 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>                     OUTPUT=$(abspath $(dir $@))/ prefix=                       \
>                     DESTDIR=$(LIBBPF_DESTDIR) $(abspath $@) install_headers
>
> +ifeq ($(CROSS_COMPILE),)
>  $(DEFAULT_BPFTOOL): $(BPFOBJ) | $(BPFTOOL_OUTPUT)
>         $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)                        \
>                     OUTPUT=$(BPFTOOL_OUTPUT)/                                  \
> -                   LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/                            \
> -                   LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/                          \
> -                   prefix= DESTDIR=$(abs_out)/ install-bin
> +                   LIBBPF_BOOTSTRAP_OUTPUT=$(LIBBPF_OUTPUT)/                  \
> +                   LIBBPF_BOOTSTRAP_DESTDIR=$(LIBBPF_DESTDIR)/ bootstrap
> +else
> +$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
> +       $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)                        \
> +                   OUTPUT=$(BPFTOOL_OUTPUT)/ bootstrap
> +endif

another idea (related to my two previous comments for this patch set),
maybe we can teach bpftool's Makefile to reuse LIBBPF_OUTPUT as
LIBBPF_BOOTSTRAP_OUTPUT, if there is no CROSS_COMPILE? Then we can
keep iterators/Makefile, samples/bpf/Makefile and runqslower/Makefile
simpler and ignorant of CROSS_COMPILE, but still get the benefit of
not rebuilding libbpf unnecessarily in non-cross-compile mode?

> --
> 2.25.1
>
Quentin Monnet July 13, 2022, 7:03 p.m. UTC | #2
On 13/07/2022 19:55, Andrii Nakryiko wrote:
> On Mon, Jul 11, 2022 at 7:37 PM Pu Lehui <pulehui@huawei.com> wrote:
>>
>> kernel/bpf/preload/iterators use bpftool for vmlinux.h, skeleton, and
>> static linking only. So we can use lightweight bootstrap version of
>> bpftool to handle these, and it will be faster.
>>
>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>> Suggested-by: Andrii Nakryiko <andrii@kernel.org>
>> ---
>>  kernel/bpf/preload/iterators/Makefile | 13 +++++++++----
>>  1 file changed, 9 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/bpf/preload/iterators/Makefile b/kernel/bpf/preload/iterators/Makefile
>> index bfe24f8c5a20..cf5f39f95fed 100644
>> --- a/kernel/bpf/preload/iterators/Makefile
>> +++ b/kernel/bpf/preload/iterators/Makefile
>> @@ -9,7 +9,7 @@ LLVM_STRIP ?= llvm-strip
>>  TOOLS_PATH := $(abspath ../../../../tools)
>>  BPFTOOL_SRC := $(TOOLS_PATH)/bpf/bpftool
>>  BPFTOOL_OUTPUT := $(abs_out)/bpftool
>> -DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
>> +DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)/bootstrap/bpftool
>>  BPFTOOL ?= $(DEFAULT_BPFTOOL)
>>
>>  LIBBPF_SRC := $(TOOLS_PATH)/lib/bpf
>> @@ -61,9 +61,14 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>>                     OUTPUT=$(abspath $(dir $@))/ prefix=                       \
>>                     DESTDIR=$(LIBBPF_DESTDIR) $(abspath $@) install_headers
>>
>> +ifeq ($(CROSS_COMPILE),)
>>  $(DEFAULT_BPFTOOL): $(BPFOBJ) | $(BPFTOOL_OUTPUT)
>>         $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)                        \
>>                     OUTPUT=$(BPFTOOL_OUTPUT)/                                  \
>> -                   LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/                            \
>> -                   LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/                          \
>> -                   prefix= DESTDIR=$(abs_out)/ install-bin
>> +                   LIBBPF_BOOTSTRAP_OUTPUT=$(LIBBPF_OUTPUT)/                  \
>> +                   LIBBPF_BOOTSTRAP_DESTDIR=$(LIBBPF_DESTDIR)/ bootstrap
>> +else
>> +$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
>> +       $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)                        \
>> +                   OUTPUT=$(BPFTOOL_OUTPUT)/ bootstrap
>> +endif
> 
> another idea (related to my two previous comments for this patch set),
> maybe we can teach bpftool's Makefile to reuse LIBBPF_OUTPUT as
> LIBBPF_BOOTSTRAP_OUTPUT, if there is no CROSS_COMPILE? Then we can
> keep iterators/Makefile, samples/bpf/Makefile and runqslower/Makefile
> simpler and ignorant of CROSS_COMPILE, but still get the benefit of
> not rebuilding libbpf unnecessarily in non-cross-compile mode?

Could be a good idea. Seeing how the HID BPF patches add BTF/skeletons
generation at new locations, I'm also starting to wonder if it would be
worth having a Makefile.bpftool.include of some sort to harmonise the
way we compile the bootstrap bpftool as a dependency, and make it easier
to maintain. I haven't looked at how feasible that would be, yet.
diff mbox series

Patch

diff --git a/kernel/bpf/preload/iterators/Makefile b/kernel/bpf/preload/iterators/Makefile
index bfe24f8c5a20..cf5f39f95fed 100644
--- a/kernel/bpf/preload/iterators/Makefile
+++ b/kernel/bpf/preload/iterators/Makefile
@@ -9,7 +9,7 @@  LLVM_STRIP ?= llvm-strip
 TOOLS_PATH := $(abspath ../../../../tools)
 BPFTOOL_SRC := $(TOOLS_PATH)/bpf/bpftool
 BPFTOOL_OUTPUT := $(abs_out)/bpftool
-DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
+DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)/bootstrap/bpftool
 BPFTOOL ?= $(DEFAULT_BPFTOOL)
 
 LIBBPF_SRC := $(TOOLS_PATH)/lib/bpf
@@ -61,9 +61,14 @@  $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
 		    OUTPUT=$(abspath $(dir $@))/ prefix=		       \
 		    DESTDIR=$(LIBBPF_DESTDIR) $(abspath $@) install_headers
 
+ifeq ($(CROSS_COMPILE),)
 $(DEFAULT_BPFTOOL): $(BPFOBJ) | $(BPFTOOL_OUTPUT)
 	$(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)			       \
 		    OUTPUT=$(BPFTOOL_OUTPUT)/				       \
-		    LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/			       \
-		    LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/			       \
-		    prefix= DESTDIR=$(abs_out)/ install-bin
+		    LIBBPF_BOOTSTRAP_OUTPUT=$(LIBBPF_OUTPUT)/		       \
+		    LIBBPF_BOOTSTRAP_DESTDIR=$(LIBBPF_DESTDIR)/ bootstrap
+else
+$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
+	$(Q)$(MAKE) $(submake_extras) -C $(BPFTOOL_SRC)			       \
+		    OUTPUT=$(BPFTOOL_OUTPUT)/ bootstrap
+endif