Skip to content

Commit f2d713f

Browse files
tytsogitster
authored andcommitted
Fix build problems related to profile-directed optimization
There was a number of problems I ran into when trying the profile-directed optimizations added by Andi Kleen in git commit 7ddc271. (This was using gcc 4.4 found on many enterprise distros.) 1) The -fprofile-generate and -fprofile-use commands are incompatible with ccache; the code ends up looking in the wrong place for the gcda files based on the ccache object names. 2) If the makefile notices that CFLAGS are different, it will rebuild all of the binaries. Hence the recipe originally specified by the INSTALL file ("make profile-all" followed by "make install") doesn't work. It will appear to work, but the binaries will end up getting built with no optimization. This patch fixes this by using an explicit set of options passed via the PROFILE variable then using this to directly manipulate CFLAGS and EXTLIBS. The developer can run "make PROFILE=BUILD all ; sudo make PROFILE=BUILD install" automatically run a two-pass build with the test suite run in between as the sample workload for the purpose of recording profiling information to do the profile-directed optimization. Alternatively, the profiling version of binaries can be built using: make PROFILE=GEN PROFILE_DIR=/var/cache/profile all make PROFILE=GEN install and then after git has been used for a while, the optimized version of the binary can be built as follows: make PROFILE=USE PROFILE_DIR=/var/cache/profile all make PROFILE=USE install Signed-off-by: "Theodore Ts'o" <[email protected]> Cc: Andi Kleen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 828ea97 commit f2d713f

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

INSTALL

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,25 @@ set up install paths (via config.mak.autogen), so you can write instead
2828
If you're willing to trade off (much) longer build time for a later
2929
faster git you can also do a profile feedback build with
3030

31-
$ make profile-all
32-
# make prefix=... install
31+
$ make prefix=/usr PROFILE=BUILD all
32+
# make prefix=/usr PROFILE=BUILD install
3333

3434
This will run the complete test suite as training workload and then
3535
rebuild git with the generated profile feedback. This results in a git
3636
which is a few percent faster on CPU intensive workloads. This
3737
may be a good tradeoff for distribution packagers.
3838

39-
Note that the profile feedback build stage currently generates
40-
a lot of additional compiler warnings.
39+
Or if you just want to install a profile-optimized version of git into
40+
your home directory, you could run:
41+
42+
$ make PROFILE=BUILD install
43+
44+
As a caveat: a profile-optimized build takes a *lot* longer since the
45+
git tree must be built twice, and in order for the profiling
46+
measurements to work properly, ccache must be disabled and the test
47+
suite has to be run using only a single CPU. In addition, the profile
48+
feedback build stage currently generates a lot of additional compiler
49+
warnings.
4150

4251
Issues of note:
4352

Makefile

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,24 @@ ifdef ASCIIDOC7
17681768
export ASCIIDOC7
17691769
endif
17701770

1771+
### profile feedback build
1772+
#
1773+
1774+
# Can adjust this to be a global directory if you want to do extended
1775+
# data gathering
1776+
PROFILE_DIR := $(CURDIR)
1777+
1778+
ifeq "$(PROFILE)" "GEN"
1779+
CFLAGS += -fprofile-generate=$(PROFILE_DIR) -DNO_NORETURN=1
1780+
EXTLIBS += -lgcov
1781+
export CCACHE_DISABLE=t
1782+
V=1
1783+
else ifneq "$(PROFILE)" ""
1784+
CFLAGS += -fprofile-use=$(PROFILE_DIR) -fprofile-correction -DNO_NORETURN=1
1785+
export CCACHE_DISABLE=t
1786+
V=1
1787+
endif
1788+
17711789
# Shell quote (do not use $(call) to accommodate ancient setups);
17721790

17731791
SHA1_HEADER_SQ = $(subst ','\'',$(SHA1_HEADER))
@@ -1824,7 +1842,17 @@ export DIFF TAR INSTALL DESTDIR SHELL_PATH
18241842

18251843
SHELL = $(SHELL_PATH)
18261844

1827-
all:: shell_compatibility_test $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
1845+
all:: shell_compatibility_test
1846+
1847+
ifeq "$(PROFILE)" "BUILD"
1848+
ifeq ($(filter all,$(MAKECMDGOALS)),all)
1849+
all:: profile-clean
1850+
$(MAKE) PROFILE=GEN all
1851+
$(MAKE) PROFILE=GEN -j1 test
1852+
endif
1853+
endif
1854+
1855+
all:: $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
18281856
ifneq (,$X)
18291857
$(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';)
18301858
endif
@@ -2552,7 +2580,11 @@ distclean: clean
25522580
$(RM) configure
25532581
$(RM) po/git.pot
25542582

2555-
clean:
2583+
profile-clean:
2584+
$(RM) $(addsuffix *.gcda,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
2585+
$(RM) $(addsuffix *.gcno,$(addprefix $(PROFILE_DIR)/, $(object_dirs)))
2586+
2587+
clean: profile-clean
25562588
$(RM) *.o block-sha1/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o vcs-svn/*.o \
25572589
builtin/*.o $(LIB_FILE) $(XDIFF_LIB) $(VCSSVN_LIB)
25582590
$(RM) $(ALL_PROGRAMS) $(SCRIPT_LIB) $(BUILT_INS) git$X
@@ -2582,7 +2614,7 @@ ifndef NO_TCLTK
25822614
endif
25832615
$(RM) GIT-VERSION-FILE GIT-CFLAGS GIT-LDFLAGS GIT-GUI-VARS GIT-BUILD-OPTIONS
25842616

2585-
.PHONY: all install clean strip
2617+
.PHONY: all install profile-clean clean strip
25862618
.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
25872619
.PHONY: FORCE cscope
25882620

@@ -2692,18 +2724,3 @@ cover_db: coverage-report
26922724
cover_db_html: cover_db
26932725
cover -report html -outputdir cover_db_html cover_db
26942726

2695-
### profile feedback build
2696-
#
2697-
.PHONY: profile-all profile-clean
2698-
2699-
PROFILE_GEN_CFLAGS := $(CFLAGS) -fprofile-generate -DNO_NORETURN=1
2700-
PROFILE_USE_CFLAGS := $(CFLAGS) -fprofile-use -fprofile-correction -DNO_NORETURN=1
2701-
2702-
profile-clean:
2703-
$(RM) $(addsuffix *.gcda,$(object_dirs))
2704-
$(RM) $(addsuffix *.gcno,$(object_dirs))
2705-
2706-
profile-all: profile-clean
2707-
$(MAKE) CFLAGS="$(PROFILE_GEN_CFLAGS)" all
2708-
$(MAKE) CFLAGS="$(PROFILE_GEN_CFLAGS)" -j1 test
2709-
$(MAKE) CFLAGS="$(PROFILE_USE_CFLAGS)" all

0 commit comments

Comments
 (0)