diff mbox

[U-Boot] config.mk: use memoization in cc-option macro to speed up compilation

Message ID 1320259591-8760-1-git-send-email-daniel.schwierzeck@googlemail.com
State Superseded
Headers show

Commit Message

Daniel Schwierzeck Nov. 2, 2011, 6:46 p.m. UTC
Apply memoization to cc-option macro by caching the results of the
gcc calls. This macro is called very often so using cached results
leads to faster compilation times.

This feature can be enabled by setting CACHE_CC_OPTIONS=y in the
environment.

Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
---

Some MAKEALL runs for ARM and MIPS (on Core 2 Duo E6600 at 2.4GHz):

time CROSS_COMPILE=/opt/codesourcery/arm-2011.03/bin/arm-none-linux-gnueabi-
MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL -s omap3 -v ti

real	3m0.380s
user	9m30.570s
sys	1m34.550s


time CACHE_CC_OPTIONS=y CROSS_COMPILE=/opt/codesourcery/arm-2011.03/bin/arm-none-linux-gnueabi-
MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL -s omap3 -v ti

real	1m15.661s
user	4m21.510s
sys	0m33.190s


time CROSS_COMPILE=/opt/codesourcery/mips-2011.03/bin/mips-linux-gnu-
MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL mips4kc

real	2m49.883s
user	6m25.840s
sys	0m58.200s


time CACHE_CC_OPTIONS=y CROSS_COMPILE=/opt/codesourcery/mips-2011.03/bin/mips-linux-gnu-
MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL mips4kc

real	2m18.205s
user	4m59.740s
sys	0m39.530s

 config.mk |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

Comments

Simon Glass Nov. 2, 2011, 8:39 p.m. UTC | #1
Hi Daniel,

On Wed, Nov 2, 2011 at 11:46 AM, Daniel Schwierzeck
<daniel.schwierzeck@googlemail.com> wrote:
> Apply memoization to cc-option macro by caching the results of the
> gcc calls. This macro is called very often so using cached results
> leads to faster compilation times.
>
> This feature can be enabled by setting CACHE_CC_OPTIONS=y in the
> environment.
>
> Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@googlemail.com>
> ---
>
> Some MAKEALL runs for ARM and MIPS (on Core 2 Duo E6600 at 2.4GHz):
>
> time CROSS_COMPILE=/opt/codesourcery/arm-2011.03/bin/arm-none-linux-gnueabi-
> MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL -s omap3 -v ti
>
> real    3m0.380s
> user    9m30.570s
> sys     1m34.550s
>
>
> time CACHE_CC_OPTIONS=y CROSS_COMPILE=/opt/codesourcery/arm-2011.03/bin/arm-none-linux-gnueabi-
> MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL -s omap3 -v ti
>
> real    1m15.661s
> user    4m21.510s
> sys     0m33.190s
>
>
> time CROSS_COMPILE=/opt/codesourcery/mips-2011.03/bin/mips-linux-gnu-
> MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL mips4kc
>
> real    2m49.883s
> user    6m25.840s
> sys     0m58.200s
>
>
> time CACHE_CC_OPTIONS=y CROSS_COMPILE=/opt/codesourcery/mips-2011.03/bin/mips-linux-gnu-
> MAKEALL_LOGDIR=../logs/ BUILD_DIR=../test/ ./MAKEALL mips4kc
>
> real    2m18.205s
> user    4m59.740s
> sys     0m39.530s
>
>  config.mk |   14 ++++++++++++++
>  1 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/config.mk b/config.mk
> index 11b67e5..27c366f 100644
> --- a/config.mk
> +++ b/config.mk
> @@ -107,8 +107,22 @@ HOSTCFLAGS += -pedantic
>  # Option checker (courtesy linux kernel) to ensure
>  # only supported compiler options are used
>  #
> +ifeq ($(CACHE_CC_OPTIONS),y)
> +sinclude $(OBJTREE)/include/cc-options.mk

It would be better to put this into include/generated - it will also
make git ignore it and it will be also be removed on clobber which I
think you need.

> +
> +cc-option-cached = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> +               > /dev/null 2>&1; then \
> +               echo 'CC_OPTIONS += $(strip $1)' \
> +                       >> $(OBJTREE)/include/cc-options.mk; \
> +               echo "$(1)"; else echo "$(2)"; fi ;)
> +
> +cc-option = $(if $(filter $1,$(CC_OPTIONS)),\
> +               $(filter $1,$(CC_OPTIONS)),\
> +               $(call cc-option-cached,$1,$2))
> +else
>  cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
>                > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
> +endif
>

Tested-by: Simon Glass <sjg@chromium.org>

With this patch and Wolfgang's I get 1.122s for an incremental build
now. Now I just need faster SPI flash and a faster car to get to work
sooner.

Is there any reason not to enable this option by default?

Regards,
Simon


>  #
>  # Include the make variables (CC, etc...)
> --
> 1.7.7.1
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
>
Daniel Schwierzeck Nov. 2, 2011, 9:36 p.m. UTC | #2
Hi Simon,

On 02.11.2011 21:39, Simon Glass wrote:
...
>>
>> diff --git a/config.mk b/config.mk
>> index 11b67e5..27c366f 100644
>> --- a/config.mk
>> +++ b/config.mk
>> @@ -107,8 +107,22 @@ HOSTCFLAGS += -pedantic
>>   # Option checker (courtesy linux kernel) to ensure
>>   # only supported compiler options are used
>>   #
>> +ifeq ($(CACHE_CC_OPTIONS),y)
>> +sinclude $(OBJTREE)/include/cc-options.mk
>
> It would be better to put this into include/generated - it will also
> make git ignore it and it will be also be removed on clobber which I
> think you need.

The patch is still experimental. But I will move that file to 
include/generated in the final version.

>
>> +
>> +cc-option-cached = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
>> +>  /dev/null 2>&1; then \
>> +               echo 'CC_OPTIONS += $(strip $1)' \
>> +>>  $(OBJTREE)/include/cc-options.mk; \
>> +               echo "$(1)"; else echo "$(2)"; fi ;)
>> +
>> +cc-option = $(if $(filter $1,$(CC_OPTIONS)),\
>> +               $(filter $1,$(CC_OPTIONS)),\
>> +               $(call cc-option-cached,$1,$2))
>> +else
>>   cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
>>                 >  /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
>> +endif
>>
>
> Tested-by: Simon Glass<sjg@chromium.org>
>
> With this patch and Wolfgang's I get 1.122s for an incremental build
> now. Now I just need faster SPI flash and a faster car to get to work
> sooner.
>
> Is there any reason not to enable this option by default?

To see the difference between compilation times with and without this 
optimization and to do not break existing code. In the final version I 
would remove the config switch and enable the optimization by default ;)

Best regards,
Daniel
Wolfgang Denk Nov. 3, 2011, 7:47 p.m. UTC | #3
Dear Daniel Schwierzeck,

In message <4EB1B7DD.40704@googlemail.com> you wrote:
> 
> The patch is still experimental. But I will move that file to 
> include/generated in the final version.

Indeed, please do.

> To see the difference between compilation times with and without this 
> optimization and to do not break existing code. In the final version I 
> would remove the config switch and enable the optimization by default ;)

Looking forward to seeing this final version soon :-)

Thanks!!

Best regards,

Wolfgang Denk
Aneesh V Nov. 5, 2011, 7:17 a.m. UTC | #4
On Friday 04 November 2011 06:15 PM, Daniel Schwierzeck wrote:
> Apply memoization to cc-option macro by caching the results of the
> gcc calls. This macro is called very often so using cached results
> leads to faster compilation times.

This one gives even better results compared to your
previous version.

Tested-by: Aneesh V <aneesh@ti.com>

br,
Aneesh


>
> Signed-off-by: Daniel Schwierzeck<daniel.schwierzeck@googlemail.com>
> ---
> Changes for v2:
>   - move cache file to $(obj)/include/generated
>   - reworked completely
>   - cache also non-working gcc options
>   - remove CACHE_CC_OPTIONS config switch and enable this optimization
>     by default
>
>   config.mk |   23 +++++++++++++++++++++--
>   1 files changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/config.mk b/config.mk
> index 918cffe..0da961a 100644
> --- a/config.mk
> +++ b/config.mk
> @@ -107,8 +107,27 @@ HOSTCFLAGS	+= -pedantic
>   # Option checker (courtesy linux kernel) to ensure
>   # only supported compiler options are used
>   #
> -cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> -		>  /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
> +CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk
> +
> +$(if $(wildcard $(CC_OPTIONS_CACHE_FILE)),,\
> +	$(shell mkdir -p $(dir $(CC_OPTIONS_CACHE_FILE))))
> +
> +sinclude $(CC_OPTIONS_CACHE_FILE)
> +
> +_ccopt_sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> +		>  /dev/null 2>&1; then \
> +		echo 'CC_OPTIONS += $(strip $1)'>>  $(CC_OPTIONS_CACHE_FILE); \
> +		echo "$(1)"; else \
> +		[ "x$(strip $2)" != "x" ]&&  \
> +			echo 'CC_OPTIONS_NOP += $(strip $2)'>>  $(CC_OPTIONS_CACHE_FILE); \
> +		echo "$(2)"; fi)
> +
> +_ccopt_cached = $(if $(filter $1,$(CC_OPTIONS)),$1,)
> +_ccopt_nop_cached = $(if $(filter $1,$(CC_OPTIONS_NOP)),$1,)
> +
> +cc-option = $(if $(call _ccopt_cached,$1),$1,\
> +		$(if $(call _ccopt_nop_cached,$2),$2,\
> +		$(call _ccopt_sys,$1,$2)))
>
>   #
>   # Include the make variables (CC, etc...)
diff mbox

Patch

diff --git a/config.mk b/config.mk
index 11b67e5..27c366f 100644
--- a/config.mk
+++ b/config.mk
@@ -107,8 +107,22 @@  HOSTCFLAGS	+= -pedantic
 # Option checker (courtesy linux kernel) to ensure
 # only supported compiler options are used
 #
+ifeq ($(CACHE_CC_OPTIONS),y)
+sinclude $(OBJTREE)/include/cc-options.mk
+
+cc-option-cached = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
+		> /dev/null 2>&1; then \
+		echo 'CC_OPTIONS += $(strip $1)' \
+			>> $(OBJTREE)/include/cc-options.mk; \
+		echo "$(1)"; else echo "$(2)"; fi ;)
+
+cc-option = $(if $(filter $1,$(CC_OPTIONS)),\
+		$(filter $1,$(CC_OPTIONS)),\
+		$(call cc-option-cached,$1,$2))
+else
 cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
 		> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
+endif
 
 #
 # Include the make variables (CC, etc...)