Skip to content

Commit 2ad6d23

Browse files
theihoranakryiko
authored andcommitted
selftests/bpf: Do not update vmlinux.h unnecessarily
%.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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/CAEf4BzY1z5cC7BKye8=A8aTVxpsCzD=p1jdTfKC7i0XVuYoHUQ@mail.gmail.com Link: https://lore.kernel.org/bpf/[email protected]
1 parent 38960ac commit 2ad6d23

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,14 @@ $(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
399399
DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
400400
endif
401401

402+
# vmlinux.h is first dumped to a temprorary file and then compared to
403+
# the previous version. This helps to avoid unnecessary re-builds of
404+
# $(TRUNNER_BPF_OBJS)
402405
$(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
403406
ifeq ($(VMLINUX_H),)
404407
$(call msg,GEN,,$@)
405-
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
408+
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $(INCLUDE_DIR)/.vmlinux.h.tmp
409+
$(Q)cmp -s $(INCLUDE_DIR)/.vmlinux.h.tmp $@ || mv $(INCLUDE_DIR)/.vmlinux.h.tmp $@
406410
else
407411
$(call msg,CP,,$@)
408412
$(Q)cp "$(VMLINUX_H)" $@

0 commit comments

Comments
 (0)