kconfig: save the KCONFIG_SEED value in the config file

Message ID 20230217065246.31641-1-rdunlap@infradead.org
State New
Headers
Series kconfig: save the KCONFIG_SEED value in the config file |

Commit Message

Randy Dunlap Feb. 17, 2023, 6:52 a.m. UTC
  Save (print) the randconfig seed value in the kernel .config file.
This enables someone to see easily that the .config file is a
randconfig file.

It also allows the randconfig file to be recreated by using the
KCONFIG_SEED environment variable, as long as KCONFIG_PROBABILITY
was not specified (the default probability values were used) and
as long as the file was not edited.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: linux-kbuild@vger.kernel.org
---
 scripts/kconfig/conf.c     |    3 +++
 scripts/kconfig/confdata.c |    2 ++
 scripts/kconfig/lkc.h      |    2 ++
 3 files changed, 7 insertions(+)
  

Comments

Masahiro Yamada Feb. 19, 2023, 10:14 a.m. UTC | #1
On Fri, Feb 17, 2023 at 3:52 PM Randy Dunlap <rdunlap@infradead.org> wrote:
>
> Save (print) the randconfig seed value in the kernel .config file.
> This enables someone to see easily that the .config file is a
> randconfig file.


I still do not understand why this is useful.

Who cares if it was generated by randconfig or menuconfig?
They are the same.




If I run "make randconfig" followed by "make olddefconfig",
I get the same .config file, except that "KCONFIG_SEED=..."
has disappeared.

So, you cannot carry this kind of information, anyway.



$ make  randconfig
KCONFIG_SEED=0x69256B40
#
# configuration written to .config
#

$ make olddefconfig
#
# configuration written to .config
#

$ diff -u .config.old .config
--- .config.old 2023-02-19 19:03:16.831931359 +0900
+++ .config 2023-02-19 19:03:37.147477826 +0900
@@ -1,7 +1,6 @@
 #
 # Automatically generated file; DO NOT EDIT.
 # Linux/x86 6.2.0-rc5 Kernel Configuration
-# KCONFIG_SEED=0x69256B40
 #
 CONFIG_CC_VERSION_TEXT="gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0"
 CONFIG_CC_IS_GCC=y







>
> It also allows the randconfig file to be recreated by using the
> KCONFIG_SEED environment variable, as long as KCONFIG_PROBABILITY
> was not specified (the default probability values were used) and
> as long as the file was not edited.
>
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Masahiro Yamada <masahiroy@kernel.org>
> Cc: linux-kbuild@vger.kernel.org
> ---
>  scripts/kconfig/conf.c     |    3 +++
>  scripts/kconfig/confdata.c |    2 ++
>  scripts/kconfig/lkc.h      |    2 ++
>  3 files changed, 7 insertions(+)
>
> diff -- a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
> --- a/scripts/kconfig/conf.c
> +++ b/scripts/kconfig/conf.c
> @@ -83,6 +83,8 @@ static void xfgets(char *str, int size,
>                 printf("%s", str);
>  }
>
> +unsigned int rand_seed;
> +
>  static void set_randconfig_seed(void)
>  {
>         unsigned int seed;
> @@ -109,6 +111,7 @@ static void set_randconfig_seed(void)
>                 seed = (now.tv_sec + 1) * (now.tv_usec + 1);
>         }
>
> +       rand_seed = seed;
>         printf("KCONFIG_SEED=0x%X\n", seed);
>         srand(seed);
>  }
> diff -- a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -621,6 +621,8 @@ static void conf_write_heading(FILE *fp,
>                 cs->decoration);
>
>         fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text);
> +       if (rand_seed)
> +               fprintf(fp, "%s KCONFIG_SEED=0x%X\n", cs->decoration, rand_seed);


If 'rand_seed' just happens to become zero,
this does not print it, which is weird.


The seed is generated by:

     seed = (now.tv_sec + 1) * (now.tv_usec + 1);


This is very rare, but it may become zero.
  

Patch

diff -- a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -83,6 +83,8 @@  static void xfgets(char *str, int size,
 		printf("%s", str);
 }
 
+unsigned int rand_seed;
+
 static void set_randconfig_seed(void)
 {
 	unsigned int seed;
@@ -109,6 +111,7 @@  static void set_randconfig_seed(void)
 		seed = (now.tv_sec + 1) * (now.tv_usec + 1);
 	}
 
+	rand_seed = seed;
 	printf("KCONFIG_SEED=0x%X\n", seed);
 	srand(seed);
 }
diff -- a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -621,6 +621,8 @@  static void conf_write_heading(FILE *fp,
 		cs->decoration);
 
 	fprintf(fp, "%s %s\n", cs->decoration, rootmenu.prompt->text);
+	if (rand_seed)
+		fprintf(fp, "%s KCONFIG_SEED=0x%X\n", cs->decoration, rand_seed);
 
 	fprintf(fp, "%s\n", cs->postfix);
 }
diff -- a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -43,6 +43,8 @@  const char *zconf_curname(void);
 const char *conf_get_configname(void);
 void set_all_choice_values(struct symbol *csym);
 
+extern unsigned int rand_seed;
+
 /* confdata.c and expr.c */
 static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out)
 {