Re: [PATCH bpf-next] selftests/bpf: compare vmlinux.h checksum when building %.bpf.o

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 23, 2024 at 4:06 PM Ihor Solodrai <ihor.solodrai@xxxxx> wrote:
>
> %.bpf.o objects depend on vmlinux.h, which makes them transitively
> dependent on unnecessary libbpf headers. However vmlinux.h doesn't
> actually change as often.
>
> Compute and save vmlinux.h checksum, and change $(TRUNNER_BPF_OBJS)
> dependencies so that they are rebuilt only if vmlinux.h contents was
> changed. Also explicitly list libbpf headers required for test progs.
>
> Example of build time improvement (after first clean build):
>   $ touch ../../../lib/bpf/bpf.h
>   $ time make -j8
> Before: real  1m37.592s
> After:  real  0m27.310s
>
> You may notice that the speed gain is caused by skipping %.bpf.o gen.
>
> Link: https://lore.kernel.org/bpf/CAEf4BzY1z5cC7BKye8=A8aTVxpsCzD=p1jdTfKC7i0XVuYoHUQ@xxxxxxxxxxxxxx
>
> Signed-off-by: Ihor Solodrai <ihor.solodrai@xxxxx>
> ---
>  tools/testing/selftests/bpf/Makefile | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
> index ec7d425c4022..4f23d9ddc8b8 100644
> --- a/tools/testing/selftests/bpf/Makefile
> +++ b/tools/testing/selftests/bpf/Makefile
> @@ -407,6 +407,14 @@ else
>         $(Q)cp "$(VMLINUX_H)" $@
>  endif
>
> +VMLINUX_H_CHECKSUM := $(INCLUDE_DIR)/vmlinux.h.md5
> +
> +$(VMLINUX_H_CHECKSUM): $(INCLUDE_DIR)/vmlinux.h
> +       $(shell md5sum $(INCLUDE_DIR)/vmlinux.h > .tmp.md5)
> +       $(shell md5sum -c .tmp.md5 $(VMLINUX_H_CHECKSUM) --status \
> +               || cp -f .tmp.md5 $(VMLINUX_H_CHECKSUM))
> +       $(shell rm .tmp.md5)

I'm not sure what md5sum buys us here, tbh... To compute checksum you
need to read entire contents anyways, so you are not really saving
anything performance-wise.

I was originally thinking that we'll extend existing rule for
$(INCLUDE_DIR)/vmlinux.h to do bpftool dump into temporary file, then
do `cmp --silent` over it and existing vmlinux.h (if it does exist, of
course), and if they are identical just exit and not modify anything.
If not, we just mv temp file over destination vmlinux.h.

In my head this would prevent make from triggering dependent targets
because vmlinux.h's modification time won't change.

Does the above not work?


> +
>  $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids   \
>                        $(TOOLSDIR)/bpf/resolve_btfids/main.c    \
>                        $(TOOLSDIR)/lib/rbtree.c                 \
> @@ -515,6 +523,12 @@ xdp_features.skel.h-deps := xdp_features.bpf.o
>  LINKED_BPF_OBJS := $(foreach skel,$(LINKED_SKELS),$($(skel)-deps))
>  LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.c,$(LINKED_BPF_OBJS))
>
> +HEADERS_FOR_BPF_OBJS := $(wildcard $(BPFDIR)/*.bpf.h)          \
> +                       $(addprefix $(BPFDIR)/, bpf_core_read.h \
> +                                               bpf_endian.h    \
> +                                               bpf_helpers.h   \
> +                                               bpf_tracing.h)
> +
>  # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
>  # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
>  # Parameters:
> @@ -564,9 +578,8 @@ $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
>  $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.bpf.o:                                \
>                      $(TRUNNER_BPF_PROGS_DIR)/%.c                       \
>                      $(TRUNNER_BPF_PROGS_DIR)/*.h                       \
> -                    $$(INCLUDE_DIR)/vmlinux.h                          \
> -                    $(wildcard $(BPFDIR)/bpf_*.h)                      \
> -                    $(wildcard $(BPFDIR)/*.bpf.h)                      \
> +                    $(VMLINUX_H_CHECKSUM)                              \
> +                    $(HEADERS_FOR_BPF_OBJS)                            \
>                      | $(TRUNNER_OUTPUT) $$(BPFOBJ)
>         $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@,                      \
>                                           $(TRUNNER_BPF_CFLAGS)         \
> --
> 2.34.1
>
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux