]> www.infradead.org Git - users/hch/dma-mapping.git/commitdiff
selftests/bpf: Do not update vmlinux.h unnecessarily
authorIhor Solodrai <ihor.solodrai@pm.me>
Wed, 28 Aug 2024 17:46:23 +0000 (17:46 +0000)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 30 Aug 2024 18:54:14 +0000 (11:54 -0700)
%.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.

When generating vmlinux.h, compare it to a previous version and update
it only if there are changes.

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

Notice that %.bpf.o gen step is skipped if vmlinux.h hasn't changed.

Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/CAEf4BzY1z5cC7BKye8=A8aTVxpsCzD=p1jdTfKC7i0XVuYoHUQ@mail.gmail.com
Link: https://lore.kernel.org/bpf/20240828174608.377204-2-ihor.solodrai@pm.me
tools/testing/selftests/bpf/Makefile

index 53cc13b92ee266f1c5f5c6aaa59e301f21476071..7660d19b66c2afde49275f5baec441085c0cb8fe 100644 (file)
@@ -399,10 +399,14 @@ $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile)                  \
                    DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
 endif
 
+# vmlinux.h is first dumped to a temprorary file and then compared to
+# the previous version. This helps to avoid unnecessary re-builds of
+# $(TRUNNER_BPF_OBJS)
 $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
 ifeq ($(VMLINUX_H),)
        $(call msg,GEN,,$@)
-       $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
+       $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $(INCLUDE_DIR)/.vmlinux.h.tmp
+       $(Q)cmp -s $(INCLUDE_DIR)/.vmlinux.h.tmp $@ || mv $(INCLUDE_DIR)/.vmlinux.h.tmp $@
 else
        $(call msg,CP,,$@)
        $(Q)cp "$(VMLINUX_H)" $@