kernel: Add a new config option to remove command line parsing
Subsystems (2)
PATCH 1/3 kernel: Add a new config option to remove command line parsing
This patch introduces CONFIG_CMDLINE_PARSE option which conditionally compiles the support for parsing kernel command line arguments. The corresponding functions that actually do the parsing will be compiled out.
This is used when no parameters will be specified neither at compile time nor at boot time.
Bloat-o-meter output (compared to the version in which builtin cmdline is set to 'Y'):
add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
function old new deltaload_module 5571 5563 -8
parse_early_param 54 44 -10 parse_early_options 33 5 -28 initcall_level_names 32 - -32 kernel_init_freeable 413 360 -53 unknown_module_param_cb 60 - -60 setup_arch 3041 2972 -69 set_init_arg 73 - -73 repair_env_string 81 - -81 start_kernel 857 759 -98 do_early_param 117 - -117 unknown_bootoption 366 - -366 parse_args 626 - -626 builtin_cmdline 2048 - -2048
--- arch/x86/Kconfig | 15 +++++++++++++++ include/linux/moduleparam.h | 14 ++++++++++++++ kernel/params.c | 2 ++ 3 files changed, 31 insertions(+)
arch/x86/Kconfig +15 -0
@@ -2002,8 +2002,23 @@ config COMPAT_VDSO If unsure, say N: if you are compiling your own kernel, you are unlikely to be using a buggy version of glibc. +config CMDLINE_PARSE + bool "Enable support for command line parsing" + default y + ---help--- + With this option set to 'Y', kernel parameters, both the ones + passed at boot time and at compile time are parsed. + + If you say no here, all the kernel parameters' values will be set + to their defaults at compile time, in order to make constant + folding possible. + + Systems with no space constraints should leave this option set to + 'Y'. + config CMDLINE_BOOL bool "Built-in kernel command line" + depends on CMDLINE_PARSE ---help--- Allow for specifying boot arguments to the kernel at build time. On some systems (e.g. embedded ones), it is
include/linux/moduleparam.h +14 -0
@@ -350,6 +350,7 @@ extern bool parameq(const char *name1, const char *name2);*/ extern bool parameqn (const char *name1,const char *name2,size_t n); +#ifdef CONFIG_CMDLINE_PARSE /* Called on module insert or kernel boot */ extern char *parse_args(const char *name, char *args,
@@ -359,6 +360,19 @@ extern char *parse_args(const char *name,s16 level_max, int (*unknown)(char *param, char *val, const char *doing)); +#else +static inline char *parse_args (const char *name, +char *args, +const struct kernel_param *params, +unsigned num, +s16 level_min, +s16 level_max, +int (*unknown)(char *param,char *val, +const char *doing)) +{ +return NULL ; +} +#endif /* Called by module remove. */ #ifdef CONFIG_SYSFS
kernel/params.c +2 -0
@@ -93,6 +93,7 @@ static void param_check_unsafe(const struct kernel_param *kp) } } +#ifdef CONFIG_CMDLINE_PARSE static int parse_one(char *param, char *val, const char *doing,
@@ -239,6 +240,7 @@ char *parse_args(const char *doing,/* All parsed OK. */ return NULL; } +#endif /* Lazy bastard, eh? */ #define STANDARD_PARAM_DEF (name, type, format, strtolfn) \
Signature · 1 line
1.8.3.2
PATCH 2/3 linux: Add macros that define and declare a core_param variable
This patch introduces two macros for kernel command line arguments subsequently defined as core parameters:
* DECLARE_CORE_PARAM - declares an extern variable in case CMDLINE_PARSE is set. In the other case it will make the variable a static constant asigned with a default value to enable constant folding;
* DEFINE_CORE_PARAM - defines a core_param variable if CMDLINE_PARSE is set. In the other case it leaves the definition to be handled by DECLARE_CORE_PARAM macro.
Introducing a new header file for the declaration of kernel parameters seemed to be the best option, because it solves the circular includes problem. Any other proposal that would be fit for this case is welcomed.
--- include/linux/moduleparam.h | 7 +++++++ include/linux/params.h | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 include/linux/params.h
include/linux/moduleparam.h +7 -0
@@ -310,6 +310,13 @@ static inline void __kernel_param_unlock(void)#define core_param (name, var, type, perm) \ param_check_##type(name, &(var)); \ __module_param_call("", name, ¶m_ops_##type, &var, perm, -1, 0) +#ifdef CONFIG_CMDLINE_PARSE +#define DEFINE_CORE_PARAM (name, var, val, type, perm) \ + type var = val; \ + core_param(name, var, type, perm) +#else +#define DEFINE_CORE_PARAM (name, var, val, type, perm) +#endif #endif /* !MODULE */ /**
include/linux/params.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LINUX_PARAMS_H +#define _LINUX_PARAMS_H + +#ifdef CONFIG_CMDLINE_PARSE +#define DECLARE_CORE_PARAM (var, val, type) \ + extern type var +#else +#define DECLARE_CORE_PARAM (var, val, type) \ + static const type var = val +#endif + +#endif /* _LINUX_PARAMS_H */
Signature · 1 line
1.8.3.2
PATCH 3/3 init: Set initcall_debug to a default value
In reply to Iulia MandaTest the previously implemented macros on initcall_debug parameter, after setting CONFIG_CMDLINE_PARSE to 'n'.
This change is a first example for how knowing the values of kernel parameters at build time can allow GCC constant folding and result in an actually relevant decrease in size. Other types of parameters also need to be handled. Also, at the moment this would only work with default values. For being able to change those defaults and still know their values at compile time, a pre-compiled stand-alone parser should be run on those variables. This will be discussed in a following patch.
The variable corresponding to initcall_debug kernel parameter is set by default to false. Even though DEFINE_CORE_PARAM resumes to nothing when CONFIG_CMDLINE_PARSE is not set, we need to use it in main.c so that it is still defined when this option is 'y'.
Bloat-o-meter output:
add/remove: 0/3 grow/shrink: 0/9 up/down: 0/-385 (-385)
function old new deltainitcall_debug 1 - -1pm_init 105 100 -5
__param_str_initcall_debug 15 - -15 __param_initcall_debug 16 - -16 syscore_suspend 247 224 -23 syscore_resume 175 152 -23 syscore_shutdown 80 55 -25 pci_fixup_device 235 198 -37 async_synchronize_cookie_domain 162 116 -46 async_run_entry_fn 178 127 -51 device_shutdown 256 204 -52 do_one_initcall 339 248 -91
--- include/linux/init.h | 3 ++- init/main.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/init.h +2 -1
@@ -3,6 +3,7 @@#include <linux/compiler.h> #include <linux/types.h> +#include <linux/params.h> /* These macros are used to mark some functions or * initialized data (doesn't apply to uninitialized data)
@@ -155,7 +156,7 @@ int __init init_rootfs(void);extern void (*late_time_init)(void ); -extern bool initcall_debug; +DECLARE_CORE_PARAM (initcall_debug, false, bool);#endif
init/main.c +1 -2
@@ -688,8 +688,7 @@ static void __init do_ctors(void)#endif } -bool initcall_debug; -core_param (initcall_debug, initcall_debug, bool,0644 ); +DEFINE_CORE_PARAM (initcall_debug, initcall_debug, false, bool,0644 );#ifdef CONFIG_KALLSYMS struct blacklist_entry {
Signature · 1 line
1.8.3.2
Re: [PATCH 3/3] init: Set initcall_debug to a default value
Quoted 11 lines · Iulia Manda
Test the previously implemented macros on
initcall_debugparameter, after settingCONFIG_CMDLINE_PARSEto 'n'.This change is a first example for how knowing the values of kernel parameters at build time can allow GCC constant folding and result in an actually relevant decrease in size. Other types of parameters also need to be handled. Also, at the moment this would only work with default values. For being able to change those defaults and still know their values at compile time, a pre-compiled stand-alone parser should be run on those variables. This will be discussed in a following patch.
Quoted 2 lines
The variable corresponding to
initcall_debugkernel parameter is set by default to false. Even thoughDEFINE_CORE_PARAMresumes to nothing when
resumes to nothing?
Quoted 12 lines
CONFIG_CMDLINE_PARSEis not set, we need to use it inmain.cso that it is still defined when this option is 'y'.--- include/linux/init.h | 3 ++- init/main.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-)include/linux/init.h +0
-0
include/linux/init.h int __init init_rootfs(void); · line 159
Quoted 3 lines
include/linux/init.h +1
-1-extern bool initcall_debug; +DECLARE_CORE_PARAM (initcall_debug, false, bool);
CONFIG_CMDLINE_PARSE will never be set outside of x86, right? So does this change nothing for those other architectures?
init/main.c static void __init do_ctors(void) · line 691
Quoted 8 lines
#endif
init/main.c +1
-2-bool initcall_debug; -core_param (initcall_debug, initcall_debug, bool,0644 ); +DEFINE_CORE_PARAM (initcall_debug, initcall_debug, false, bool,0644 );
Ditto.
Thanks,
Paul Bolle
Re: [PATCH 3/3] init: Set initcall_debug to a default value
Quoted 11 lines · Paul Bolle
Quoted 9 lines · Iulia Manda
--- include/linux/init.h | 3 ++- init/main.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-)include/linux/init.h +0
-0
Quoted 5 lines
include/linux/init.h int __init init_rootfs(void); · line 159
Quoted 2 lines
include/linux/init.h +1
-1-extern bool initcall_debug; +DECLARE_CORE_PARAM (initcall_debug, false, bool);
CONFIG_CMDLINE_PARSEwill never be set outside of x86, right? So does this change nothing for those other architectures?
See comment on the previous patch; this is not x86-specific, and it should be a config option for all architectures.
- Josh Triplett
Quoted 6 lines · Iulia Manda
arch/x86/Kconfig +3
-0+config CMDLINE_PARSE + bool "Enable support for command line parsing" + default y
arch/x86/Kconfig config COMPAT_VDSO · line 2017
Quoted 10 lines
arch/x86/Kconfig +10
-0+ ---help--- + With this option set to 'Y', kernel parameters, both the ones + passed at boot time and at compile time are parsed. + + If you say no here, all the kernel parameters' values will be set + to their defaults at compile time, in order to make constant + folding possible. + + Systems with no space constraints should leave this option set to + 'Y'.
This adds a x86 specific Kconfig option.
Quoted 14 lines
include/linux/moduleparam.h +4
-0+#ifdef CONFIG_CMDLINE_PARSE /* Called on module insert or kernel boot */ extern char *parse_args(const char *name, char *args,@@ -359,6 +360,19 @@ extern char *parse_args(const char *name,s16 level_max, int (*unknown)(char *param, char *val, const char *doing)); +#else +static inline char *parse_args(const char *name, + char *args,
include/linux/moduleparam.h extern char *parse_args(const char *name, · line 375
Quoted 10 lines
include/linux/moduleparam.h +10
-0+const struct kernel_param *params, + unsigned num, + s16 level_min, + s16 level_max, + int (*unknown)(char *param, char *val, + const char *doing)) +{ + return NULL; +} +#endif
So this effectively disables parse_args() for all architectures, doesn't it? If that's OK, I'd say the patch is x86 specific. Than it should have, say, "x86:" as a prefix and it should be sent to the people and lists taking care of x86.
But a quick grep suggests it's not OK to disable this for all other architectures. Did I miss something with that quick grep?
Thanks,
Paul Bolle
Quoted 4 lines · Paul Bolle
Quoted 2 lines · Iulia Manda
arch/x86/Kconfig +0
-0
Quoted 15 lines
arch/x86/Kconfig config COMPAT_VDSO · line 2017
Quoted 13 lines
arch/x86/Kconfig +13
-0+config CMDLINE_PARSE + bool "Enable support for command line parsing" + default y + ---help--- + With this option set to 'Y', kernel parameters, both the ones + passed at boot time and at compile time are parsed. + + If you say no here, all the kernel parameters' values will be set + to their defaults at compile time, in order to make constant + folding possible. + + Systems with no space constraints should leave this option set to + 'Y'.This adds a x86 specific
Kconfigoption.
Good catch. I reviewed the Kconfig option and its usage very carefully, but completely missed that it was in the wrong file.
This needs to go in init/Kconfig or similar.
- Josh Triplett
Quoted 3 lines · Iulia Manda
This patch introduces
CONFIG_CMDLINE_PARSEoption which conditionally compiles the support for parsing kernel command line arguments. The corresponding functions that actually do the parsing will be compiled out.
Could you make it depend on EXPERT?
Thanks,
Rob
PATCH v2 1/1 kernel: Add a new config option to remove command line parsing
In reply to Iulia MandaThis patch introduces CONFIG_CMDLINE_PARSE option which conditionally compiles the support for parsing kernel command line arguments. The corresponding functions that actually do the parsing will be compiled out.
This is used when no parameters will be specified neither at compile time nor at boot time.
Bloat-o-meter output (compared to the version in which builtin cmdline is set to 'Y'):
add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
function old new deltaload_module 5571 5563 -8
parse_early_param 54 44 -10 parse_early_options 33 5 -28 initcall_level_names 32 - -32 kernel_init_freeable 413 360 -53 unknown_module_param_cb 60 - -60 setup_arch 3041 2972 -69 set_init_arg 73 - -73 repair_env_string 81 - -81 start_kernel 857 759 -98 do_early_param 117 - -117 unknown_bootoption 366 - -366 parse_args 626 - -626 builtin_cmdline 2048 - -2048
---
Changes since v1:
- make CONFIG_CMDLINE_PARSE arch independent
- make CONFIG_CMDLINE_PARSE depend on EXPERT
arch/x86/Kconfig | 1 + include/linux/moduleparam.h | 14 ++++++++++++++ init/Kconfig | 14 ++++++++++++++ kernel/params.c | 2 ++ 4 files changed, 31 insertions(+)
arch/x86/Kconfig +1 -0
@@ -2005,6 +2005,7 @@ config COMPAT_VDSO config CMDLINE_BOOL bool "Built-in kernel command line" + depends on CMDLINE_PARSE ---help--- Allow for specifying boot arguments to the kernel at build time. On some systems (e.g. embedded ones), it is
include/linux/moduleparam.h +14 -0
@@ -350,6 +350,7 @@ extern bool parameq(const char *name1, const char *name2);*/ extern bool parameqn (const char *name1,const char *name2,size_t n); +#ifdef CONFIG_CMDLINE_PARSE /* Called on module insert or kernel boot */ extern char *parse_args(const char *name, char *args,
@@ -359,6 +360,19 @@ extern char *parse_args(const char *name,s16 level_max, int (*unknown)(char *param, char *val, const char *doing)); +#else +static inline char *parse_args (const char *name, +char *args, +const struct kernel_param *params, +unsigned num, +s16 level_min, +s16 level_max, +int (*unknown)(char *param,char *val, +const char *doing)) +{ +return NULL ; +} +#endif /* Called by module remove. */ #ifdef CONFIG_SYSFS
init/Kconfig +14 -0
@@ -1372,6 +1372,20 @@ config MULTIUSER If unsure, say Y here. +config CMDLINE_PARSE + bool "Enable support for command line parsing" if EXPERT + default y + ---help--- + With this option set to 'Y', kernel parameters, both the ones + passed at boot time and at compile time are parsed. + + If you say no here, all the kernel parameters' values will be set + to their defaults at compile time, in order to make constant + folding possible. + + Systems with no space constraints should leave this option set to + 'Y'. + config SGETMASK_SYSCALL bool "sgetmask/ssetmask syscalls support" if EXPERT def_bool PARISC || MN10300 || BLACKFIN || M68K || PPC || MIPS || X86 || SPARC || CRIS || MICROBLAZE || SUPERH
kernel/params.c +2 -0
@@ -93,6 +93,7 @@ static void param_check_unsafe(const struct kernel_param *kp) } } +#ifdef CONFIG_CMDLINE_PARSE static int parse_one(char *param, char *val, const char *doing,
@@ -239,6 +240,7 @@ char *parse_args(const char *doing,/* All parsed OK. */ return NULL; } +#endif /* Lazy bastard, eh? */ #define STANDARD_PARAM_DEF (name, type, format, strtolfn) \
Signature · 1 line
1.9.1