All of lore.kernel.org
 help / color / mirror / Atom feed
From: Doug Anderson <dianders@chromium.org>
To: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH 1/4] kbuild: create directory for make cache only when necessary
Date: Thu, 9 Nov 2017 09:59:08 -0800	[thread overview]
Message-ID: <CAD=FV=VQ2YoWd0ARSk6z03zFzKmem6VbJ4r5T0aoGh7kGhwaDw@mail.gmail.com> (raw)
In-Reply-To: <1510242077-8122-2-git-send-email-yamada.masahiro@socionext.com>

Hi,

On Thu, Nov 9, 2017 at 7:41 AM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> Currently, the existence of $(dir $(make-cache)) is always checked,
> and created if it is missing.
>
> We can avoid unnecessary system calls by some tricks.
>
> [1] If KBUILD_SRC is unset, we are building in the source tree.
>     The output directory checks can be entirely skipped.
> [2] If at least one cache data is found, it means the cache file
>     was included.  Obiously its directory exists.  Skip "mkdir -p".
> [3] If Makefile does not contain any call of __run-and-store, it will
>     not create a cache file.  No need to create its directory.
> [4] The "mkdir -p" should be only invoked by the first call of
>     __run-and-store
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
>
>  scripts/Kbuild.include | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
> index be1c9d6..4fb1be1 100644
> --- a/scripts/Kbuild.include
> +++ b/scripts/Kbuild.include
> @@ -99,18 +99,19 @@ cc-cross-prefix =  \
>
>  # Include values from last time
>  make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk
> -ifeq ($(wildcard $(dir $(make-cache))),)
> -$(shell mkdir -p '$(dir $(make-cache))')
> -endif
>  $(make-cache): ;
>  -include $(make-cache)
>
> +cached-data := $(filter __cached_%, $(.VARIABLES))
> +
>  # If cache exceeds 1000 lines, shrink it down to 500.
> -ifneq ($(word 1000,$(filter __cached_%, $(.VARIABLES))),)
> +ifneq ($(word 1000,$(cached-data)),)
>  $(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \
>         mv $(make-cache).tmp $(make-cache))
>  endif
>
> +cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,$(dir $(make-cache))))

It wouldn't hurt to add a comment that cache-dir will be blank if we
don't need to make the cache dir and will contain a directory path
only if the dir doesn't exist.  Without a comment it could take
someone quite a while to realize that...

> +
>  # Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios)
>  #
>  # Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'
> @@ -136,6 +137,10 @@ __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$
>  define __run-and-store
>  ifeq ($(origin $(1)),undefined)
>    $$(eval $(1) := $$(shell $$(2)))
> +ifneq ($(cache-dir),)
> +  $$(shell mkdir -p $(cache-dir))

I _think_ you want some single quotes in there.  AKA:

$$(shell mkdir -p '$(cache-dir)')

That at least matches what the "old" code used to do.  Specifically if
'cache-dir' happens to have a space in it then it won't work right
without the single quotes.  There may be other symbols that your shell
might interpret in interesting ways, too.

NOTE: I have no idea if the kernel Makefiles work if paths like
KBUILD_SRC have spaces in them to begin with, but it seems wise to add
the quotes here anyway.

ALSO NOTE: I think you could still confuse the kernel Makefiles if
somehow you had a single quote in your path somehow.  I assume we
don't care?


> +  $$(eval cache-dir :=)
> +endif
>    $$(shell echo '$(1) := $$($(1))' >> $(make-cache))
>  endif
>  endef

Other than the single quote problem and the suggested comment, this
seems like a sane optimization to me.  Feel free to add my Reviewed-by
once those fixes are in place.

-Doug

  reply	other threads:[~2017-11-09 17:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-09 15:41 [PATCH 0/4] kbuild: optimize output directory creation Masahiro Yamada
2017-11-09 15:41 ` [PATCH 1/4] kbuild: create directory for make cache only when necessary Masahiro Yamada
2017-11-09 17:59   ` Doug Anderson [this message]
2017-11-10  4:12     ` Masahiro Yamada
2017-11-10 17:34       ` Doug Anderson
2017-11-09 15:41 ` [PATCH 2/4] kbuild: remove redundant $(wildcard ...) for cmd_files calculation Masahiro Yamada
2017-11-10  4:53   ` Doug Anderson
2017-11-10  4:55     ` Masahiro Yamada
2017-11-09 15:41 ` [PATCH 3/4] kbuild: create object directories simpler and faster Masahiro Yamada
2017-11-10  6:26   ` Ingo Molnar
2017-11-10  8:45   ` Cao jin
2017-11-10  8:45     ` Cao jin
2017-11-10  9:21     ` Masahiro Yamada
2017-11-13  8:48       ` Masahiro Yamada
2017-11-10 18:46   ` Doug Anderson
2017-11-09 15:41 ` [PATCH 4/4] kbuild: optimize object directory creation for incremental build Masahiro Yamada
2017-11-10 10:58   ` Cao jin
2017-11-10 10:58     ` Cao jin
2017-11-13  7:24     ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD=FV=VQ2YoWd0ARSk6z03zFzKmem6VbJ4r5T0aoGh7kGhwaDw@mail.gmail.com' \
    --to=dianders@chromium.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=sam@ravnborg.org \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.