Skip to contentSkip to conversation

kconfig: redo fake deps at include/config/*.h

PATCH Superseded Alexey Dobriyan 2 participants 4 messages Apr 14, 2021 – Apr 16, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig: redo fake deps at include/config/*.h

Make include/config/foo/bar.h fake deps files generation simpler.

* delete .h suffix
those aren't header files, shorten filenames,

* delete tolower()
Linux filesystems can deal with both upper and lowercase filenames very well,

* put everything in 1 directory

	Presumably 'mkdir -p' split is from dark times when filesystems
	handled huge directories badly, disks were round adding to
	seek times.

	x86_64 allmodconfig lists 12364 files in include/config.

	../obj/include/config/
	├── 104_QUAD_8
	├── 60XX_WDT
	├── 64BIT
	├── 6LOWPAN
	├── 6LOWPAN_DEBUGFS
	├── 6LOWPAN_GHC_EXT_HDR_DEST
	├── 6LOWPAN_GHC_EXT_HDR_FRAG
	├── 6LOWPAN_GHC_EXT_HDR_HOP
	├── 6LOWPAN_GHC_EXT_HDR_ROUTE

		...
	├── ZSTD_COMPRESS
	├── ZSTD_DECOMPRESS
	├── ZSWAP
	├── ZSWAP_COMPRESSOR_DEFAULT
	├── ZSWAP_COMPRESSOR_DEFAULT_LZO
	├── ZSWAP_DEFAULT_ON
	├── ZSWAP_ZPOOL_DEFAULT
	└── ZSWAP_ZPOOL_DEFAULT_ZBUD

	0 directories, 12364 files

---

 include/linux/compiler-version.h |    2 +-
 init/Kconfig                     |    2 +-
 scripts/Makefile.build           |    4 ++--
 scripts/basic/fixdep.c           |   30 +++---------------------------
 scripts/kconfig/confdata.c       |   11 +++--------
 5 files changed, 10 insertions(+), 39 deletions(-)
include/linux/compiler-version.h +1 -1
@@ -9,6 +9,6 @@
  * This header exists to force full rebuild when the compiler is upgraded.
  *
  * When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
- * and add dependency on include/config/cc/version/text.h, which is touched
+ * and add dependency on include/config/CC_VERSION_TEXT, which is touched
  * by Kconfig when the version string from the compiler changes.
  */
init/Kconfig +1 -1
@@ -21,7 +21,7 @@ config CC_VERSION_TEXT
 
 	  - Ensure full rebuild when the compiler is updated
 	    include/linux/compiler-version.h contains this option in the comment
-	    line so fixdep adds include/config/cc/version/text.h into the
+	    line so fixdep adds include/config/CC_VERSION_TEXT into the
 	    auto-generated dependency. When the compiler is updated, syncconfig
 	    will touch it and then every file will be rebuilt.
 
scripts/Makefile.build +2 -2
@@ -238,8 +238,8 @@ endif # CONFIG_STACK_VALIDATION
 
 # Rebuild all objects when objtool changes, or is enabled/disabled.
 objtool_dep = $(objtool_obj)					\
-	      $(wildcard include/config/orc/unwinder.h		\
-			 include/config/stack/validation.h)
+	      $(wildcard include/config/ORC_UNWINDER		\
+			 include/config/STACK_VALIDATION)
 
 ifdef CONFIG_TRIM_UNUSED_KSYMS
 cmd_gen_ksymdeps = \
scripts/basic/fixdep.c +3 -27
@@ -34,7 +34,7 @@
  * the config symbols are rebuilt.
  *
  * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
- * which depend on "include/config/his/driver.h" will be rebuilt,
+ * which depend on "include/config/HIS_DRIVER" will be rebuilt,
  * so most likely only his driver ;-)
  *
  * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
@@ -74,7 +74,7 @@
  *
  * and then basically copies the .<target>.d file to stdout, in the
  * process filtering out the dependency on autoconf.h and adding
- * dependencies on include/config/my/option.h for every
+ * dependencies on include/config/MY_OPTION for every
  * CONFIG_MY_OPTION encountered in any of the prerequisites.
  *
  * We don't even try to really parse the header files, but
@@ -124,36 +124,12 @@ static void xprintf(const char *format, ...)
 	va_end(ap);
 }
 
-static void xputchar(int c)
-{
-	int ret;
-
-	ret = putchar(c);
-	if (ret == EOF) {
-		perror("fixdep");
-		exit(1);
-	}
-}
-
 /*
  * Print out a dependency path from a symbol name
  */
 static void print_dep(const char *m, int slen, const char *dir)
 {
-	int c, prev_c = '/', i;
-
-	xprintf("    $(wildcard %s/", dir);
-	for (i = 0; i < slen; i++) {
-		c = m[i];
-		if (c == '_')
-			c = '/';
-		else
-			c = tolower(c);
-		if (c != '/' || prev_c != '/')
-			xputchar(c);
-		prev_c = c;
-	}
-	xprintf(".h) \\\n");
+	xprintf("    $(wildcard %s/%.*s) \\\n", dir, slen, m);
 }
 
 struct item {
scripts/kconfig/confdata.c +3 -8
@@ -130,19 +130,14 @@ static size_t depfile_prefix_len;
 static int conf_touch_dep(const char *name)
 {
 	int fd, ret;
-	const char *s;
-	char *d, c;
+	char *d;
 
 	/* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
 	if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
 		return -1;
 
 	d = depfile_path + depfile_prefix_len;
-	s = name;
-
-	while ((c = *s++))
-		*d++ = (c == '_') ? '/' : tolower(c);
-	strcpy(d, ".h");
+	strcpy(d, name);
 
 	/* Assume directory path already exists. */
 	fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -465,7 +460,7 @@ int conf_read_simple(const char *name, int def)
 					 * Reading from include/config/auto.conf
 					 * If CONFIG_FOO previously existed in
 					 * auto.conf but it is missing now,
-					 * include/config/foo.h must be touched.
+					 * include/config/FOO must be touched.
 					 */
 					conf_touch_dep(line + strlen(CONFIG_));
 				else
#1 lore raw
Quoted 6 lines · Alexey Dobriyan

Make include/config/foo/bar.h fake deps files generation simpler.

* delete .h suffix
those aren't header files, shorten filenames,

Quoted 8 lines

* delete tolower()
Linux filesystems can deal with both upper and lowercase filenames very well,

* put everything in 1 directory
Presumably 'mkdir -p' split is from dark times when filesystems handled huge directories badly, disks were round adding to seek times.

I am not sure about the impact of this change given various file systems in the wild, but this simplification is attractive.

With a quick search, I found a comment 'performance issues past 10,000' on ext2 [1] but that may not be what we care about much...

[1]: https://webmasters.stackexchange.com/questions/99539/what-is-a-recommended-maximum-number-of-files-in-a-directory-on-your-webserver

Quoted 25 lines
scripts/basic/fixdep.c +0 -16
@@ -124,36 +124,12 @@ static void xprintf(const char *format, ...)
        va_end(ap);
 }
 
-static void xputchar(int c)
-{
-       int ret;
-
-       ret = putchar(c);
-       if (ret == EOF) {
-               perror("fixdep");
-               exit(1);
-       }
-}
-
 /*
  * Print out a dependency path from a symbol name
  */
 static void print_dep(const char *m, int slen, const char *dir)
 {
-       int c, prev_c = '/', i;
-
-       xprintf("    $(wildcard %s/", dir);
-       for (i = 0; i < slen; i++) {
-               c = m[i];

scripts/basic/fixdep.c static void xprintf(const char *format, ...) · line 132

Quoted 10 lines
scripts/basic/fixdep.c +1 -9
-               if (c == '_')
-                       c = '/';
-               else
-                       c = tolower(c);
-               if (c != '/' || prev_c != '/')
-                       xputchar(c);
-               prev_c = c;
-       }
-       xprintf(".h) \\\n");
+       xprintf("    $(wildcard %s/%.*s) \\\n", dir, slen, m);

Since this function now contains just one line, can you hard-code

    xprintf("    $(wildcard include/config/%.*s) \\\n", slen, m);

in use_config() ?

Quoted 6 lines
scripts/basic/fixdep.c +0 -0
 }
 
 struct item {

scripts/kconfig/confdata.c static size_t depfile_prefix_len; · line 136

Quoted 9 lines
scripts/kconfig/confdata.c +1 -2
@@ -130,19 +130,14 @@ static size_t depfile_prefix_len;
 static int conf_touch_dep(const char *name)
 {
        int fd, ret;
-       const char *s;
-       char *d, c;
+       char *d;
 
        /* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
        if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))

Since you dropped the ".h" suffix, please fix up this line.

Also, you can fix

# changed, Kconfig touches the corresponding timestamp file
include/config/*.h.

in kernel/gen_kheaders.sh

Quoted 13 lines
scripts/kconfig/confdata.c +1 -5
                return -1;
 
        d = depfile_path + depfile_prefix_len;
-       s = name;
-
-       while ((c = *s++))
-               *d++ = (c == '_') ? '/' : tolower(c);
-       strcpy(d, ".h");
+       strcpy(d, name);
 
        /* Assume directory path already exists. */
        fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);

scripts/kconfig/confdata.c int conf_read_simple(const char *name, int def) · line 466

Quoted 8 lines
scripts/kconfig/confdata.c +1 -1
@@ -465,7 +460,7 @@ int conf_read_simple(const char *name, int def)
                                         * Reading from include/config/auto.conf
                                         * If CONFIG_FOO previously existed in
                                         * auto.conf but it is missing now,
-                                        * include/config/foo.h must be touched.
+                                        * include/config/FOO must be touched.
                                         */
                                        conf_touch_dep(line + strlen(CONFIG_));
                                else

--
Best Regards
Masahiro Yamada

#2 lore raw

PATCH v2 1/1 kconfig: redo fake deps at include/config/*.h

Make include/config/foo/bar.h fake deps files generation simpler.

* delete .h suffix
those aren't header files, shorten filenames,

* delete tolower()
Linux filesystems can deal with both upper and lowercase filenames very well,

* put everything in 1 directory

	Presumably 'mkdir -p' split is from dark times when filesystems
	handled huge directories badly, disks were round adding to
	seek times.

	x86_64 allmodconfig lists 12364 files in include/config.

	../obj/include/config/
	├── 104_QUAD_8
	├── 60XX_WDT
	├── 64BIT
		...
	├── ZSWAP_DEFAULT_ON
	├── ZSWAP_ZPOOL_DEFAULT
	└── ZSWAP_ZPOOL_DEFAULT_ZBUD

	0 directories, 12364 files

---

 include/linux/compiler-version.h |    2 +-
 init/Kconfig                     |    2 +-
 kernel/gen_kheaders.sh           |    2 +-
 scripts/Makefile.build           |    4 ++--
 scripts/basic/fixdep.c           |   39 ++++-----------------------------------
 scripts/kconfig/confdata.c       |   15 +++++----------
 6 files changed, 14 insertions(+), 50 deletions(-)
include/linux/compiler-version.h +1 -1
@@ -9,6 +9,6 @@
  * This header exists to force full rebuild when the compiler is upgraded.
  *
  * When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
- * and add dependency on include/config/cc/version/text.h, which is touched
+ * and add dependency on include/config/CC_VERSION_TEXT, which is touched
  * by Kconfig when the version string from the compiler changes.
  */
init/Kconfig +1 -1
@@ -21,7 +21,7 @@ config CC_VERSION_TEXT
 
 	  - Ensure full rebuild when the compiler is updated
 	    include/linux/compiler-version.h contains this option in the comment
-	    line so fixdep adds include/config/cc/version/text.h into the
+	    line so fixdep adds include/config/CC_VERSION_TEXT into the
 	    auto-generated dependency. When the compiler is updated, syncconfig
 	    will touch it and then every file will be rebuilt.
 
kernel/gen_kheaders.sh +1 -1
@@ -36,7 +36,7 @@ all_dirs="$all_dirs $dir_list"
 #
 # When Kconfig regenerates include/generated/autoconf.h, its timestamp is
 # updated, but the contents might be still the same. When any CONFIG option is
-# changed, Kconfig touches the corresponding timestamp file include/config/*.h.
+# changed, Kconfig touches the corresponding timestamp file include/config/*.
 # Hence, the md5sum detects the configuration change anyway. We do not need to
 # check include/generated/autoconf.h explicitly.
 #
scripts/Makefile.build +2 -2
@@ -238,8 +238,8 @@ endif # CONFIG_STACK_VALIDATION
 
 # Rebuild all objects when objtool changes, or is enabled/disabled.
 objtool_dep = $(objtool_obj)					\
-	      $(wildcard include/config/orc/unwinder.h		\
-			 include/config/stack/validation.h)
+	      $(wildcard include/config/ORC_UNWINDER		\
+			 include/config/STACK_VALIDATION)
 
 ifdef CONFIG_TRIM_UNUSED_KSYMS
 cmd_gen_ksymdeps = \
scripts/basic/fixdep.c +4 -35
@@ -34,7 +34,7 @@
  * the config symbols are rebuilt.
  *
  * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
- * which depend on "include/config/his/driver.h" will be rebuilt,
+ * which depend on "include/config/HIS_DRIVER" will be rebuilt,
  * so most likely only his driver ;-)
  *
  * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
@@ -74,7 +74,7 @@
  *
  * and then basically copies the .<target>.d file to stdout, in the
  * process filtering out the dependency on autoconf.h and adding
- * dependencies on include/config/my/option.h for every
+ * dependencies on include/config/MY_OPTION for every
  * CONFIG_MY_OPTION encountered in any of the prerequisites.
  *
  * We don't even try to really parse the header files, but
@@ -124,38 +124,6 @@ static void xprintf(const char *format, ...)
 	va_end(ap);
 }
 
-static void xputchar(int c)
-{
-	int ret;
-
-	ret = putchar(c);
-	if (ret == EOF) {
-		perror("fixdep");
-		exit(1);
-	}
-}
-
-/*
- * Print out a dependency path from a symbol name
- */
-static void print_dep(const char *m, int slen, const char *dir)
-{
-	int c, prev_c = '/', i;
-
-	xprintf("    $(wildcard %s/", dir);
-	for (i = 0; i < slen; i++) {
-		c = m[i];
-		if (c == '_')
-			c = '/';
-		else
-			c = tolower(c);
-		if (c != '/' || prev_c != '/')
-			xputchar(c);
-		prev_c = c;
-	}
-	xprintf(".h) \\\n");
-}
-
 struct item {
 	struct item	*next;
 	unsigned int	len;
@@ -220,7 +188,8 @@ static void use_config(const char *m, int slen)
 	    return;
 
 	define_config(m, slen, hash);
-	print_dep(m, slen, "include/config");
+	/* Print out a dependency path from a symbol name. */
+	xprintf("    $(wildcard include/config/%.*s) \\\n", slen, m);
 }
 
 /* test if s ends in sub */
scripts/kconfig/confdata.c +5 -10
@@ -130,19 +130,14 @@ static size_t depfile_prefix_len;
 static int conf_touch_dep(const char *name)
 {
 	int fd, ret;
-	const char *s;
-	char *d, c;
+	char *d;
 
-	/* check overflow: prefix + name + ".h" + '\0' must fit in buffer. */
-	if (depfile_prefix_len + strlen(name) + 3 > sizeof(depfile_path))
+	/* check overflow: prefix + name + '\0' must fit in buffer. */
+	if (depfile_prefix_len + strlen(name) + 1 > sizeof(depfile_path))
 		return -1;
 
 	d = depfile_path + depfile_prefix_len;
-	s = name;
-
-	while ((c = *s++))
-		*d++ = (c == '_') ? '/' : tolower(c);
-	strcpy(d, ".h");
+	strcpy(d, name);
 
 	/* Assume directory path already exists. */
 	fd = open(depfile_path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@ -465,7 +460,7 @@ int conf_read_simple(const char *name, int def)
 					 * Reading from include/config/auto.conf
 					 * If CONFIG_FOO previously existed in
 					 * auto.conf but it is missing now,
-					 * include/config/foo.h must be touched.
+					 * include/config/FOO must be touched.
 					 */
 					conf_touch_dep(line + strlen(CONFIG_));
 				else
#3 lore raw
Quoted 109 lines · Alexey Dobriyan

Make include/config/foo/bar.h fake deps files generation simpler.

* delete .h suffix
those aren't header files, shorten filenames,

* delete tolower()
Linux filesystems can deal with both upper and lowercase filenames very well,

* put everything in 1 directory

        Presumably 'mkdir -p' split is from dark times when filesystems
        handled huge directories badly, disks were round adding to
        seek times.

        x86_64 allmodconfig lists 12364 files in include/config.

        ../obj/include/config/
        ├── 104_QUAD_8
        ├── 60XX_WDT
        ├── 64BIT
                ...
        ├── ZSWAP_DEFAULT_ON
        ├── ZSWAP_ZPOOL_DEFAULT
        └── ZSWAP_ZPOOL_DEFAULT_ZBUD

        0 directories, 12364 files

---

 include/linux/compiler-version.h |    2 +-
 init/Kconfig                     |    2 +-
 kernel/gen_kheaders.sh           |    2 +-
 scripts/Makefile.build           |    4 ++--
 scripts/basic/fixdep.c           |   39 ++++-----------------------------------
 scripts/kconfig/confdata.c       |   15 +++++----------
 6 files changed, 14 insertions(+), 50 deletions(-)
include/linux/compiler-version.h +1 -1
@@ -9,6 +9,6 @@
  * This header exists to force full rebuild when the compiler is upgraded.
  *
  * When fixdep scans this, it will find this string "CONFIG_CC_VERSION_TEXT"
- * and add dependency on include/config/cc/version/text.h, which is touched
+ * and add dependency on include/config/CC_VERSION_TEXT, which is touched
  * by Kconfig when the version string from the compiler changes.
  */
init/Kconfig +1 -1
@@ -21,7 +21,7 @@ config CC_VERSION_TEXT
 
          - Ensure full rebuild when the compiler is updated
            include/linux/compiler-version.h contains this option in the comment
-           line so fixdep adds include/config/cc/version/text.h into the
+           line so fixdep adds include/config/CC_VERSION_TEXT into the
            auto-generated dependency. When the compiler is updated, syncconfig
            will touch it and then every file will be rebuilt.
 
kernel/gen_kheaders.sh +1 -1
@@ -36,7 +36,7 @@ all_dirs="$all_dirs $dir_list"
 #
 # When Kconfig regenerates include/generated/autoconf.h, its timestamp is
 # updated, but the contents might be still the same. When any CONFIG option is
-# changed, Kconfig touches the corresponding timestamp file include/config/*.h.
+# changed, Kconfig touches the corresponding timestamp file include/config/*.
 # Hence, the md5sum detects the configuration change anyway. We do not need to
 # check include/generated/autoconf.h explicitly.
 #
scripts/Makefile.build +2 -2
@@ -238,8 +238,8 @@ endif # CONFIG_STACK_VALIDATION
 
 # Rebuild all objects when objtool changes, or is enabled/disabled.
 objtool_dep = $(objtool_obj)                                   \
-             $(wildcard include/config/orc/unwinder.h          \
-                        include/config/stack/validation.h)
+             $(wildcard include/config/ORC_UNWINDER            \
+                        include/config/STACK_VALIDATION)
 
 ifdef CONFIG_TRIM_UNUSED_KSYMS
 cmd_gen_ksymdeps = \
scripts/basic/fixdep.c +2 -3
@@ -34,7 +34,7 @@
  * the config symbols are rebuilt.
  *
  * So if the user changes his CONFIG_HIS_DRIVER option, only the objects
- * which depend on "include/config/his/driver.h" will be rebuilt,
+ * which depend on "include/config/HIS_DRIVER" will be rebuilt,
  * so most likely only his driver ;-)
  *
  * The idea above dates, by the way, back to Michael E Chastain, AFAIK.
@@ -74,7 +74,7 @@
  *
  * and then basically copies the .<target>.d file to stdout, in the
  * process filtering out the dependency on autoconf.h and adding
- * dependencies on include/config/my/option.h for every
+ * dependencies on include/config/MY_OPTION for every
  * CONFIG_MY_OPTION encountered in any of the prerequisites.
  *
  * We don't even try to really parse the header files, but
@@ -124,38 +124,6 @@ static void xprintf(const char *format, ...)
        va_end(ap);
 }
 
-static void xputchar(int c)

scripts/basic/fixdep.c static void xprintf(const char *format, ...) · line 137

Quoted 10 lines
scripts/basic/fixdep.c +0 -10
-{
-       int ret;
-
-       ret = putchar(c);
-       if (ret == EOF) {
-               perror("fixdep");
-               exit(1);
-       }
-}
-

Applied to linux-kbuild.

I just found one more minor thing to fix up.

fixdep no longer calls putchar(), so I squashed the following:

scripts/basic/fixdep.c +2 -2
index 5bee6a80992f..44e887cff49b 100644
@@ -107,8 +107,8 @@ static void usage(void)
 
 /*
  * In the intended usage of this program, the stdout is redirected to .*.cmd
- * files. The return value of printf() and putchar() must be checked to catch
- * any error, e.g. "No space left on device".
+ * files. The return value of printf() must be checked to catch any error,
+ * e.g. "No space left on device".
  */
 static void xprintf(const char *format, ...)
 {
Signature · 2 lines
Best Regards
Masahiro Yamada