Skip to contentSkip to conversation

libtracefs: avoid pointless extra DEP stage

PATCH Superseded Jan Engelhardt 2 participants 5 messages Jun 20, 2022 – Jul 14, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: avoid pointless extra DEP stage

Call the compiler only once per source file. Reduces build time from 0.85 to 0.75 seconds for me.

---
 scripts/utils.mk |  4 ++--
 src/Makefile     | 14 ++------------
 2 files changed, 4 insertions(+), 14 deletions(-)
scripts/utils.mk +2 -2
index 5f43de1..b8a32a3 100644
@@ -53,12 +53,12 @@ endif
 
 do_fpic_compile =					\
 	($(print_fpic_compile)				\
-	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(EXT) -fPIC $< -o $@)
+	$(CC) -MMD -MP -c $(CPPFLAGS) $(CFLAGS) $(EXT) -fPIC $< -o $@)
 
 do_compile =							\
 	($(if $(GENERATE_PIC), $(do_fpic_compile),		\
 	 $(print_compile)					\
-	 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(EXT) $< -o $@))
+	 $(CC) -MMD -MP -c $(CPPFLAGS) $(CFLAGS) $(EXT) $< -o $@))
 
 do_app_build =						\
 	($(print_app_build)				\
src/Makefile +2 -12
index 645d518..3cd4263 100644
@@ -48,24 +48,14 @@ sqlhist-lex.c: sqlhist.l sqlhist.tab.c
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
-$(DEPS): $(bdir)/.%.d: %.c
-	$(Q)$(CC) -M -MT $(bdir)/$*.o $(CPPFLAGS) $(CFLAGS) $< > $@
-
-$(OBJS): $(bdir)/%.o : $(bdir)/.%.d
-
 tracefs-sqlhist.o: sqlhist.tab.h
 
 $(OBJS): | $(bdir)
-$(DEPS): | $(bdir)
 
 clean:
-	$(Q)$(call do_clean,$(OBJS) .*.d)
+	$(Q)$(call do_clean,$(OBJS) *.d)
 
-dep_includes := $(wildcard $(DEPS))
-
-ifneq ($(dep_includes),)
-  include $(dep_includes)
-endif
+-include *.d
 
 $(bdir)/tracefs-sqlhist.o tracefs-sqlhist.o: sqlhist.tab.h
 
Signature · 1 line
2.36.1
#1 lore raw

src/Makefile sqlhist-lex.c: sqlhist.l sqlhist.tab.c · line 58

Quoted 11 lines · On Mon, 20 Jun 2022 17:03:16 +0200 Jan Engelhardt <[email protected]> wrote:

clean:

src/Makefile +2 -6
-	$(Q)$(call do_clean,$(OBJS) .*.d)
+	$(Q)$(call do_clean,$(OBJS) *.d)
 
-dep_includes := $(wildcard $(DEPS))
-
-ifneq ($(dep_includes),)
-  include $(dep_includes)
-endif
+-include *.d

After this change, the .d files are visible. Is there a way to keep them hidden? That is, keep the . in front?

-- Steve

#2 lore raw
Quoted 7 lines · Steven Rostedt
Quoted 4 lines · On Mon, 20 Jun 2022 17:03:16 +0200 Jan Engelhardt <[email protected]> wrote:

clean:

src/Makefile +1 -1
-	$(Q)$(call do_clean,$(OBJS) .*.d)
+	$(Q)$(call do_clean,$(OBJS) *.d)
Quoted 10 lines

src/Makefile sqlhist-lex.c: sqlhist.l sqlhist.tab.c · line 58

Quoted 7 lines
src/Makefile +1 -5
-dep_includes := $(wildcard $(DEPS))
-
-ifneq ($(dep_includes),)
-  include $(dep_includes)
-endif
+-include *.d

After this change, the .d files are visible. Is there a way to keep them hidden? That is, keep the . in front?

Generally there is. Let me see how to stick
that into the $(CC) line.

#3 lore raw

PATCH v2 1/1 libtracefs: avoid pointless extra DEP stage

Call the compiler only once per source file. Reduces build time from 0.85 to 0.75 seconds for me.

---
 .gitignore       |  2 +-
 Makefile         |  1 -
 scripts/utils.mk |  4 ++--
 src/Makefile     | 13 +------------
 utest/Makefile   | 10 +---------
 5 files changed, 5 insertions(+), 25 deletions(-)
.gitignore +1 -1
index 88c9b42..3e72a58 100644
@@ -11,5 +11,5 @@ build_prefix
 build_uninstall
 tfs_version.h
 *.o
-*.d
+.*.d
 sqlhist
Makefile +0 -1
index 0044656..941ffff 100644
@@ -330,7 +330,6 @@ OBJS += tracefs-instance.o
 OBJS += tracefs-events.o
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
-DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
 
 all: $(DEFAULT_TARGET)
 
scripts/utils.mk +2 -2
index 5f43de1..b432e67 100644
@@ -53,12 +53,12 @@ endif
 
 do_fpic_compile =					\
 	($(print_fpic_compile)				\
-	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(EXT) -fPIC $< -o $@)
+	$(CC) -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ -MP -c $(CPPFLAGS) $(CFLAGS) $(EXT) -fPIC $< -o $@)
 
 do_compile =							\
 	($(if $(GENERATE_PIC), $(do_fpic_compile),		\
 	 $(print_compile)					\
-	 $(CC) -c $(CPPFLAGS) $(CFLAGS) $(EXT) $< -o $@))
+	 $(CC) -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ -MP -c $(CPPFLAGS) $(CFLAGS) $(EXT) $< -o $@))
 
 do_app_build =						\
 	($(print_app_build)				\
src/Makefile +1 -12
index 645d518..d28b8f4 100644
@@ -21,7 +21,6 @@ OBJS += sqlhist.tab.o
 OBJS += tracefs-sqlhist.o
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
-DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
 
 $(LIBTRACEFS_STATIC): $(OBJS)
 	$(Q)$(call do_build_static_lib)
@@ -48,24 +47,14 @@ sqlhist-lex.c: sqlhist.l sqlhist.tab.c
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
-$(DEPS): $(bdir)/.%.d: %.c
-	$(Q)$(CC) -M -MT $(bdir)/$*.o $(CPPFLAGS) $(CFLAGS) $< > $@
-
-$(OBJS): $(bdir)/%.o : $(bdir)/.%.d
-
 tracefs-sqlhist.o: sqlhist.tab.h
 
 $(OBJS): | $(bdir)
-$(DEPS): | $(bdir)
 
 clean:
 	$(Q)$(call do_clean,$(OBJS) .*.d)
 
-dep_includes := $(wildcard $(DEPS))
-
-ifneq ($(dep_includes),)
-  include $(dep_includes)
-endif
+-include .*.d
 
 $(bdir)/tracefs-sqlhist.o tracefs-sqlhist.o: sqlhist.tab.h
 
utest/Makefile +1 -9
index 74bf7e6..ee0020a 100644
@@ -15,13 +15,11 @@ LIBS += -lcunit				\
 	$(obj)/lib/libtracefs.a
 
 OBJS := $(OBJS:%.o=$(bdir)/%.o)
-DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
 
 $(bdir):
 	@mkdir -p $(bdir)
 
 $(OBJS): | $(bdir)
-$(DEPS): | $(bdir)
 
 $(bdir)/trace-utest: $(OBJS)
 	$(Q)$(do_app_build)
@@ -29,13 +27,7 @@ $(bdir)/trace-utest: $(OBJS)
 $(bdir)/%.o: %.c
 	$(Q)$(call do_fpic_compile)
 
-$(DEPS): $(bdir)/.%.d: %.c
-	$(Q)$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@
-	$(Q)$(CC) -M -MT $(bdir)/$*.o $(CPPFLAGS) $(CFLAGS) $< > $@
-
-$(OBJS): $(bdir)/%.o : $(bdir)/.%.d
-
-dep_includes := $(wildcard $(DEPS))
+-include .*.d
 
 test: $(TARGETS)
 
Signature · 1 line
2.36.1