Skip to contentSkip to conversation

kconfig: do not write 'n' defaults to .config

PATCH In review Ulf Magnusson 4 participants 13 messages Feb 23, 2018 – Feb 28, 2018

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

PATCH 1/1 kconfig: do not write 'n' defaults to .config

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
 			if (!sym_is_choice(sym)) {
 				prop = sym_get_default_prop(sym);
 				if (prop) {
-					sym->flags |= SYMBOL_WRITE;
 					newval.tri = EXPR_AND(expr_calc_value(prop->expr),
 							      prop->visible.tri);
+					if (newval.tri != no)
+						sym->flags |= SYMBOL_WRITE;
 				}
 				if (sym->implied.tri != no) {
 					sym->flags |= SYMBOL_WRITE;
Signature · 1 line
2.14.1
#1 lore raw
Quoted 74 lines · Ulf Magnusson

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -2
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
--
Quoted 2 lines

2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

Cheers,
Ulf

#2 lore raw
Quoted 21 lines · Ulf Magnusson
Quoted 19 lines · Ulf Magnusson
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 8 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

I had to read the patch description twice to see that you are only changing the invisible symbols. This seems fine for any automated interaction with the .config file.

The only possible downside I can think of is that it's sometimes easier to see the '# CONFIG_FOO is unset' when using 'grep CONFIG_FOO .config' to see if something was set. On the other hand, I might edit .config and remove that line today, and then be surprised that 'make oldconfig' doesn't ask me about it again (since it's invisible).

So no, I don't see a strong reason against it either.

Arnd

#3 lore raw
Quoted 31 lines · Arnd Bergmann
Quoted 21 lines · Ulf Magnusson
Quoted 19 lines · Ulf Magnusson
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 8 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

Quoted 3 lines

I had to read the patch description twice to see that you are only changing the invisible symbols. This seems fine for any automated interaction with the .config file.

Yeah... maybe a patch title like "kconfig: only write '# CONFIG_FOO is not set' for visible symbols" would make it clearer (or something to that effect early on in the commit message).

Quoted 6 lines

The only possible downside I can think of is that it's sometimes easier to see the '# CONFIG_FOO is unset' when using 'grep CONFIG_FOO .config' to see if something was set. On the other hand, I might edit .config and remove that line today, and then be surprised that 'make oldconfig' doesn't ask me about it again (since it's invisible).

Note that it only affects symbols that get the value 'n' through an explicit 'default'. You won't get a '# CONFIG_FOO is not set' for n-valued invisible symbols without a 'default' property neither before nor after this patch.

Quoted 4 lines

So no, I don't see a strong reason against it either.

Arnd

Cheers,
Ulf

#4 lore raw

PATCH v2 1/1 kconfig: only write '# CONFIG_FOO is not set' for visible symbols

In reply to Arnd Bergmann

=== Background ===

- Visible n-valued bool/tristate symbols generate a
'# CONFIG_FOO is not set' line in the .config file. The idea is to remember the user selection without having to set a Makefile variable. Having n correspond to the variable being undefined in the Makefiles makes for easy CONFIG_* tests.

- Invisible n-valued bool/tristate symbols normally do not generate a '# CONFIG_FOO is not set' line, because user values from .config files have no effect on invisible symbols anyway.

Currently, there is one exception to this rule: Any bool/tristate symbol that gets the value n through a 'default' property generates a '# CONFIG_FOO is not set' line, even if the symbol is invisible.

Note that this only applies to explicitly given defaults, and not when the symbol implicitly defaults to n (like bool/tristate symbols without 'default' properties do).

This is inconsistent, and seems redundant:

- As mentioned, the '# CONFIG_FOO is not set' won't affect the symbol once the .config is read back in.

- Even if the symbol is invisible at first but becomes visible later, there shouldn't be any harm in recalculating the default value rather than viewing the '# CONFIG_FOO is not set' as an previous user value of n.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults.

This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of (and the main motivation for) this change is making the following two definitions behave exactly the same:

config FOO
bool

config FOO
bool
default n

With this change, neither of these will generate a
'# CONFIG_FOO is not set' line (assuming FOO isn't selected/implied). That might make it clearer to people that a bare 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
Changes in v2:
Make it more explicit in the commit title and message that only invisible symbols are affected by the change. The previous commit title was "do not write 'n' defaults to .config".

 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
 			if (!sym_is_choice(sym)) {
 				prop = sym_get_default_prop(sym);
 				if (prop) {
-					sym->flags |= SYMBOL_WRITE;
 					newval.tri = EXPR_AND(expr_calc_value(prop->expr),
 							      prop->visible.tri);
+					if (newval.tri != no)
+						sym->flags |= SYMBOL_WRITE;
 				}
 				if (sym->implied.tri != no) {
 					sym->flags |= SYMBOL_WRITE;
Signature · 1 line
2.14.1
#5 lore raw

PATCH v3 1/1 kconfig: only write '# CONFIG_FOO is not set' for visible symbols

In reply to Arnd Bergmann

=== Background ===

- Visible n-valued bool/tristate symbols generate a
'# CONFIG_FOO is not set' line in the .config file. The idea is to remember the user selection without having to set a Makefile variable. Having n correspond to the variable being undefined in the Makefiles makes for easy CONFIG_* tests.

- Invisible n-valued bool/tristate symbols normally do not generate a '# CONFIG_FOO is not set' line, because user values from .config files have no effect on invisible symbols anyway.

Currently, there is one exception to this rule: Any bool/tristate symbol that gets the value n through a 'default' property generates a '# CONFIG_FOO is not set' line, even if the symbol is invisible.

Note that this only applies to explicitly given defaults, and not when the symbol implicitly defaults to n (like bool/tristate symbols without 'default' properties do).

This is inconsistent, and seems redundant:

- As mentioned, the '# CONFIG_FOO is not set' won't affect the symbol once the .config is read back in.

- Even if the symbol is invisible at first but becomes visible later, there shouldn't be any harm in recalculating the default value rather than viewing the '# CONFIG_FOO is not set' as a previous user value of n.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n-valued 'default' properties.

Note that SYMBOL_WRITE is always set for visible symbols regardless of whether they have 'default' properties or not, so this change only affects invisible symbols.

This reduces the size of the x86 .config on my system by about 1% (due to removed '# CONFIG_FOO is not set' entries).

One side effect of (and the main motivation for) this change is making the following two definitions behave exactly the same:

config FOO
bool

config FOO
bool
default n

With this change, neither of these will generate a
'# CONFIG_FOO is not set' line (assuming FOO isn't selected/implied). That might make it clearer to people that a bare 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
Changes in v3:
Mention that SYMBOL_WRITE is always set for visible symbols. It might look like this change would affect those too otherwise.

Changes in v2:
Make it more explicit in the commit title and message that only invisible symbols are affected by the change. The previous commit title was "do not write 'n' defaults to .config".

 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
 			if (!sym_is_choice(sym)) {
 				prop = sym_get_default_prop(sym);
 				if (prop) {
-					sym->flags |= SYMBOL_WRITE;
 					newval.tri = EXPR_AND(expr_calc_value(prop->expr),
 							      prop->visible.tri);
+					if (newval.tri != no)
+						sym->flags |= SYMBOL_WRITE;
 				}
 				if (sym->implied.tri != no) {
 					sym->flags |= SYMBOL_WRITE;
Signature · 1 line
2.14.1
#7 lore raw
In reply to Ulf Magnusson

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

I am not sure how many people want to check .config to know the compiler capability...

Signature · 2 lines
Best Regards
Masahiro Yamada
#8 lore raw

2018-02-23 22:25 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 101 lines

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"
Quoted 7 lines

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

I am not sure how many people want to check .config to know the compiler capability...

I thought a bit more, then probably the grammatical consistency would win. (default n is always redundant)

I want to apply this, but take a bit time
in case somebody may have comments.

BTW, do you want to check redundant 'default n'
by checkpatch.pl ?

Signature · 2 lines
Best Regards
Masahiro Yamada
#9 lore raw
Quoted 106 lines · Masahiro Yamada

2018-02-23 22:25 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 105 lines

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

Quoted 7 lines
Quoted 3 lines

I am not sure how many people want to check .config to know the compiler capability...

I thought a bit more, then probably the grammatical consistency would win. (default n is always redundant)

The behavior should be easy to explain in kconfig-language.txt too: A missing entry means n, except visible n-valued symbols generate a '# CONFIG_FOO is not set' comment just to keep track of the user's choice. No weird exception for 'default'.

That would demystify those '...is not set' lines too.

Quoted 7 lines

I want to apply this, but take a bit time
in case somebody may have comments.

BTW, do you want to check redundant 'default n'
by checkpatch.pl ?

Was thinking of that. Guess you could generate a warning for any of the following:

default n
default "n"
default 'n'

Could skip the warning for defaults with conditions maybe, as people sometimes do stuff like

default n if <cond>
default FOO

(Though some of those look like they could refactored as well.)

Or you could just say something like this for all of them:

warning: check whether 'default n' is redundant -- n is the implicit default value for bool/tristate symbols

Cheers,
Ulf

#10 lore raw
Quoted 115 lines · Ulf Magnusson
Quoted 106 lines · Masahiro Yamada

2018-02-23 22:25 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 105 lines

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

Quoted 7 lines
Quoted 3 lines

I am not sure how many people want to check .config to know the compiler capability...

I thought a bit more, then probably the grammatical consistency would win. (default n is always redundant)

Quoted 7 lines

The behavior should be easy to explain in kconfig-language.txt too: A missing entry means n, except visible n-valued symbols generate a '# CONFIG_FOO is not set' comment just to keep track of the user's choice. No weird exception for 'default'.

That would demystify those '...is not set' lines too.

Looks like someone already did it, see b7d4ec395673 ("Documentation/kbuild: Add guidance for the use of default"). I could add a small note to kconfig-language.txt to explain '...is not set' separately later as well.

Cheers,
Ulf

#11 lore raw
In reply to Ulf Magnusson
Quoted 130 lines · Ulf Magnusson
Quoted 106 lines · Masahiro Yamada

2018-02-23 22:25 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 105 lines

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

Quoted 7 lines
Quoted 3 lines

I am not sure how many people want to check .config to know the compiler capability...

I thought a bit more, then probably the grammatical consistency would win. (default n is always redundant)

The behavior should be easy to explain in kconfig-language.txt too: A missing entry means n, except visible n-valued symbols generate a '# CONFIG_FOO is not set' comment just to keep track of the user's choice. No weird exception for 'default'.

That would demystify those '...is not set' lines too.

Quoted 7 lines

I want to apply this, but take a bit time
in case somebody may have comments.

BTW, do you want to check redundant 'default n'
by checkpatch.pl ?

Quoted 6 lines

Was thinking of that. Guess you could generate a warning for any of the following:

default n
default "n"
default 'n'

We also sometimes see:
default N
:)

Quoted 11 lines

Could skip the warning for defaults with conditions maybe, as people sometimes do stuff like

default n if <cond>
default FOO

(Though some of those look like they could refactored as well.)

Or you could just say something like this for all of them:

warning: check whether 'default n' is redundant -- n is the implicit default value for bool/tristate symbols

Signature · 1 line
~Randy
#12 lore raw
Quoted 134 lines · Randy Dunlap
Quoted 133 lines · Ulf Magnusson
Quoted 106 lines · Masahiro Yamada

2018-02-23 22:25 GMT+09:00 Masahiro Yamada <[email protected]>:

Quoted 105 lines

2018-02-23 15:14 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 74 lines · Ulf Magnusson
Quoted 73 lines

=== Background ===

A "# CONFIG_FOO is not set" line is written to .config for visible bool/tristate symbols with value n. The idea is to remember the user selection without having to set a Makefile variable (having undefined Make variables correspond to n is handy when testing them in the Makefiles).

Currently, a "# CONFIG_FOO is not set" line is also written to .config for all bool/tristate symbols that get the value n through a 'default'. This is inconsistent with how 'select' and 'imply' work, which only write non-n symbols. It also seems redundant:

- If the symbol is visible and has value n, then "# CONFIG_FOO is not set" will always be written anyway.

- If the symbol is not visible, then "# CONFIG_FOO is not set" has no effect on it.

- If the symbol becomes visible later, there shouldn't be any harm in recalculating the default value at that point.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n defaults. This reduces the size of the x86 .config on my system by about 1% (due to removed "# CONFIG_FOO is not set" entries).

One side effect of this change is making 'default n' equivalent to having no explicit default. That might make it clearer to people that 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -1
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
Quoted 9 lines
Quoted 3 lines

--
2.14.1

This stuff gets pretty obscure, so please tell me if you can think of any practical benefits to remembering an n default as a user selection for non-visible symbols (which is all '# CONFIG_FOO is not set' does in practice). I couldn't think of anything.

In the context of

config CC_HAS_STACKPROTECTOR

       def_bool $(cc-option -fstack-protector)

Currently, we have 3 cases:

[1] CONFIG_CC_HAS_STACKPROTECTOR=y

       -> compiler flag is supported
 [2] # CONFIG_CC_HAS_STACKPROTECTOR is not set
       -> compiler flag is unsupported
 [3] Missing
       -> The symbol was hidden probably due to unmet "if ... endif"

With this change, [2] will be turned into [3].

That is the only drawback I came up with.

Quoted 7 lines
Quoted 3 lines

I am not sure how many people want to check .config to know the compiler capability...

I thought a bit more, then probably the grammatical consistency would win. (default n is always redundant)

The behavior should be easy to explain in kconfig-language.txt too: A missing entry means n, except visible n-valued symbols generate a '# CONFIG_FOO is not set' comment just to keep track of the user's choice. No weird exception for 'default'.

That would demystify those '...is not set' lines too.

Quoted 7 lines

I want to apply this, but take a bit time
in case somebody may have comments.

BTW, do you want to check redundant 'default n'
by checkpatch.pl ?

Was thinking of that. Guess you could generate a warning for any of the following:

Quoted 8 lines
Quoted 3 lines

default n
default "n"
default 'n'

We also sometimes see:
default N
:)

Could add a warning that looks for 'default N/M/Y' and says to use 'default n/m/y' as well, maybe (after which you'd get a new warning telling you to get rid of the "default n"... never happy :P).

Masahiro:
Could you bump https://lkml.org/lkml/2018/2/22/935 if you're happy with it? Maybe Joe is waiting to see if you have objections.

After that I could add some new checks.

Cheers,
Ulf

#6 lore raw

Re: [PATCH v3] kconfig: only write '# CONFIG_FOO is not set' for visible symbols

In reply to Ulf Magnusson

2018-02-23 20:49 GMT+09:00 Ulf Magnusson <[email protected]>:

Quoted 83 lines

=== Background ===

- Visible n-valued bool/tristate symbols generate a
'# CONFIG_FOO is not set' line in the .config file. The idea is to remember the user selection without having to set a Makefile variable. Having n correspond to the variable being undefined in the Makefiles makes for easy CONFIG_* tests.

- Invisible n-valued bool/tristate symbols normally do not generate a '# CONFIG_FOO is not set' line, because user values from .config files have no effect on invisible symbols anyway.

Currently, there is one exception to this rule: Any bool/tristate symbol that gets the value n through a 'default' property generates a '# CONFIG_FOO is not set' line, even if the symbol is invisible.

Note that this only applies to explicitly given defaults, and not when the symbol implicitly defaults to n (like bool/tristate symbols without 'default' properties do).

This is inconsistent, and seems redundant:

- As mentioned, the '# CONFIG_FOO is not set' won't affect the symbol once the .config is read back in.

- Even if the symbol is invisible at first but becomes visible later, there shouldn't be any harm in recalculating the default value rather than viewing the '# CONFIG_FOO is not set' as a previous user value of n.

=== Changes ===

Change sym_calc_value() to only set SYMBOL_WRITE (write to .config) for non-n-valued 'default' properties.

Note that SYMBOL_WRITE is always set for visible symbols regardless of whether they have 'default' properties or not, so this change only affects invisible symbols.

This reduces the size of the x86 .config on my system by about 1% (due to removed '# CONFIG_FOO is not set' entries).

One side effect of (and the main motivation for) this change is making the following two definitions behave exactly the same:

config FOO
bool

config FOO
bool
default n

With this change, neither of these will generate a
'# CONFIG_FOO is not set' line (assuming FOO isn't selected/implied). That might make it clearer to people that a bare 'default n' is redundant.

This change only affects generated .config files and not autoconf.h:
autoconf.h only includes #defines for non-n bool/tristate symbols.

=== Testing ===

The following testing was done with the x86 Kconfigs:

- .config files generated before and after the change were compared to verify that the only difference is some '# CONFIG_FOO is not set' entries disappearing. A couple of these were inspected manually, and most turned out to be from redundant 'default n/def_bool n' properties.

- The generated include/generated/autoconf.h was compared before and after the change and verified to be identical.

- As a sanity check, the same modification was done to Kconfiglib. The Kconfiglib test suite was then run to check for any mismatches against the output of the C implementation.

---
Changes in v3:
Mention that SYMBOL_WRITE is always set for visible symbols. It might look like this change would affect those too otherwise.

Quoted 4 lines

Changes in v2:
Make it more explicit in the commit title and message that only invisible symbols are affected by the change. The previous commit title was "do not write 'n' defaults to .config".

Applied to linux-kbuild/kconfig.
Thanks!

Quoted 26 lines
 scripts/kconfig/symbol.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/kconfig/symbol.c +2 -2
index cca9663be5dd..02eb8b10a83c 100644
@@ -403,9 +403,10 @@ void sym_calc_value(struct symbol *sym)
                        if (!sym_is_choice(sym)) {
                                prop = sym_get_default_prop(sym);
                                if (prop) {
-                                       sym->flags |= SYMBOL_WRITE;
                                        newval.tri = EXPR_AND(expr_calc_value(prop->expr),
                                                              prop->visible.tri);
+                                       if (newval.tri != no)
+                                               sym->flags |= SYMBOL_WRITE;
                                }
                                if (sym->implied.tri != no) {
                                        sym->flags |= SYMBOL_WRITE;
--

2.14.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Best Regards
Masahiro Yamada