[PATCH 1/3] kernel: Add a new config option to remove command line parsing

42 views
Skip to first unread message

Iulia Manda

unread,
Mar 3, 2015, 9:14:28 AM3/3/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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:

add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
function old new delta
load_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

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
arch/x86/Kconfig | 15 +++++++++++++++
include/linux/moduleparam.h | 14 ++++++++++++++
kernel/params.c | 2 ++
3 files changed, 31 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c2fb8a8..e8d8186 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2003,8 +2003,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
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 1c9effa..f97397c 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -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
diff --git a/kernel/params.c b/kernel/params.c
index 728e05b..d3bfe47 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -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) \
--
1.9.1

Iulia Manda

unread,
Mar 3, 2015, 9:14:29 AM3/3/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
This patch introduces two macros for kernel command line arguments subsequently
defined as core parameters:
* DECLARE_CORE_PARAM declares a constant variable.
* DEFINE_CORE_PARAM is a wrapper around core_param which, in addition, defines a
variable with a default value.

Because at some point we need to access the address of var, it can not be const.
This is why we need to add a dummy variable that does not affect the rest of the
code and only provides us with a valid address of __var, knowing that in this
case that address will never be used. This way the variable's value is known at
compile time and we can rely on GCC to be able to constant fold it.

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
include/linux/init.h | 8 ++++++++
include/linux/moduleparam.h | 11 +++++++++++
2 files changed, 19 insertions(+)

diff --git a/include/linux/init.h b/include/linux/init.h
index 2df8e8d..ef32825 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -155,6 +155,14 @@ int __init init_rootfs(void);

extern void (*late_time_init)(void);

+#ifdef CONFIG_CMDLINE_PARSE
+#define DECLARE_CORE_PARAM(name) \
+ bool name
+#else
+#define DECLARE_CORE_PARAM(name) \
+ const bool name
+#endif
+
extern bool initcall_debug;

#endif
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index f97397c..4e1e2f2 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -310,6 +310,17 @@ static inline void __kernel_param_unlock(void)
#define core_param(name, var, type, perm) \
param_check_##type(name, &(var)); \
__module_param_call("", name, &param_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) \
+ const type var = val; \
+ type __##var; \
+ core_param(name, __##var, type, perm);
+#endif
#endif /* !MODULE */

/**
--
1.9.1

Iulia Manda

unread,
Mar 3, 2015, 9:14:29 AM3/3/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
Test the previously implemented macros on initcall_debug parameter.

Bloat-o-meter output:

add/remove: 1/0 grow/shrink: 0/2 up/down: 1/-95 (-94)
function old new delta
__initcall_debug - 1 +1
async_run_entry_fn 178 174 -4
do_one_initcall 339 248 -91

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
include/linux/init.h | 2 +-
init/main.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index ef32825..50863b7 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -163,7 +163,7 @@ extern void (*late_time_init)(void);
const bool name
#endif

-extern bool initcall_debug;
+extern DECLARE_CORE_PARAM(initcall_debug);

#endif

diff --git a/init/main.c b/init/main.c
index 6f0f1c5f..27c446e 100644
--- a/init/main.c
+++ b/init/main.c
@@ -685,8 +685,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, 0, bool, 0644);

#ifdef CONFIG_KALLSYMS
struct blacklist_entry {
--
1.9.1

jo...@joshtriplett.org

unread,
Mar 3, 2015, 11:37:32 AM3/3/15
to Iulia Manda, opw-k...@googlegroups.com
On Tue, Mar 03, 2015 at 04:13:43PM +0200, Iulia Manda wrote:
> 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:
>
> add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
> function old new delta
> load_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

Very nice!

A couple of comments below.

> Signed-off-by: Iulia Manda <iulia....@gmail.com>
> ---
> arch/x86/Kconfig | 15 +++++++++++++++
> include/linux/moduleparam.h | 14 ++++++++++++++
> kernel/params.c | 2 ++
> 3 files changed, 31 insertions(+)
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index c2fb8a8..e8d8186 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -2003,8 +2003,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---

This needs to use a tab for indentation.

> + 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 needs to use a tab and two spaces for indentation.

> config CMDLINE_BOOL
> bool "Built-in kernel command line"
> + depends on CMDLINE_PARSE

This needs to use a tab for indentation.

jo...@joshtriplett.org

unread,
Mar 3, 2015, 1:11:45 PM3/3/15
to Iulia Manda, opw-k...@googlegroups.com
On Tue, Mar 03, 2015 at 04:13:44PM +0200, Iulia Manda wrote:
> This patch introduces two macros for kernel command line arguments subsequently
> defined as core parameters:
> * DECLARE_CORE_PARAM declares a constant variable.
> * DEFINE_CORE_PARAM is a wrapper around core_param which, in addition, defines a
> variable with a default value.
>
> Because at some point we need to access the address of var, it can not be const.
> This is why we need to add a dummy variable that does not affect the rest of the
> code and only provides us with a valid address of __var, knowing that in this
> case that address will never be used. This way the variable's value is known at
> compile time and we can rely on GCC to be able to constant fold it.

I still don't think we need the dummy variable and the call to
core_param in the !CONFIG_CMDLINE_PARSE case.

> Signed-off-by: Iulia Manda <iulia....@gmail.com>
> ---
> include/linux/init.h | 8 ++++++++
> include/linux/moduleparam.h | 11 +++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/linux/init.h b/include/linux/init.h
> index 2df8e8d..ef32825 100644
> --- a/include/linux/init.h
> +++ b/include/linux/init.h
> @@ -155,6 +155,14 @@ int __init init_rootfs(void);
>
> extern void (*late_time_init)(void);
>
> +#ifdef CONFIG_CMDLINE_PARSE
> +#define DECLARE_CORE_PARAM(name) \
> + bool name
> +#else
> +#define DECLARE_CORE_PARAM(name) \
> + const bool name
> +#endif

This shouldn't be defined in init.h; it should be in moduleparam.h next
to DEFINE_CORE_PARAM. For consistency with DEFINE_CORE_PARAM, the
variable name should be called "var", since "name" refers to the name of
the command line option (which may differ). Also, it shouldn't be
hardcoded to bool, and it needs an "extern".

Actually, that raises a problematic issue. "extern const" doesn't allow
for constant folding; I think the only constant folding you're getting
in commit #3 of this series is in init/main.c, not in the various other
files that reference initcall_debug.

On that basis, I wonder if it'd make more sense to make
DECLARE_CORE_PARAM (with !CONFIG_CMDLINE_PARSE) turn into "static const
type var = val;", and then have DEFINE_CORE_PARAM compile to nothing at
all in that case. That'll work for initcall_debug; the only minor
annoyance is that for a parameter kept entirely in the same file without
an associated header, you still have to use both DECLARE_CORE_PARAM and
DEFINE_CORE_PARAM, rather than just the latter. That seems OK though.

> extern bool initcall_debug;
>
> #endif
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index f97397c..4e1e2f2 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -310,6 +310,17 @@ static inline void __kernel_param_unlock(void)
> #define core_param(name, var, type, perm) \
> param_check_##type(name, &(var)); \
> __module_param_call("", name, &param_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) \
> + const type var = val; \
> + type __##var; \
> + core_param(name, __##var, type, perm);
> +#endif

In the #else cases here, you should drop the __##var and core_param.
Or, as suggested above, you could define it to nothing and declare a
static const in DECLARE_CORE_PARAM.

> #endif /* !MODULE */
>
> /**
> --
> 1.9.1
>
> --
> You received this message because you are subscribed to the Google Groups "opw-kernel" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to opw-kernel+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

jo...@joshtriplett.org

unread,
Mar 3, 2015, 1:17:24 PM3/3/15
to Iulia Manda, opw-k...@googlegroups.com
On Tue, Mar 03, 2015 at 04:13:45PM +0200, Iulia Manda wrote:
> Test the previously implemented macros on initcall_debug parameter.

Works for now, though for the final series the commit message should
explain in more detail. :)

> Bloat-o-meter output:
>
> add/remove: 1/0 grow/shrink: 0/2 up/down: 1/-95 (-94)
> function old new delta
> __initcall_debug - 1 +1
> async_run_entry_fn 178 174 -4
> do_one_initcall 339 248 -91

This should improve significantly if the version in the header becomes a
static const.

> Signed-off-by: Iulia Manda <iulia....@gmail.com>
> ---
> include/linux/init.h | 2 +-
> init/main.c | 3 +--
> 2 files changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/init.h b/include/linux/init.h
> index ef32825..50863b7 100644
> --- a/include/linux/init.h
> +++ b/include/linux/init.h
> @@ -163,7 +163,7 @@ extern void (*late_time_init)(void);
> const bool name
> #endif
>
> -extern bool initcall_debug;
> +extern DECLARE_CORE_PARAM(initcall_debug);

This should drop the extern, and let DECLARE_CORE_PARAM handle that. In
the CONFIG_CMDLINE_PARSE case, DECLARE_CORE_PARAM should include extern;
in the other case, DECLARE_CORE_PARAM can declare a static const.
You'll need additional macro arguments for the type "bool" and the value
"false".

> #endif
>
> diff --git a/init/main.c b/init/main.c
> index 6f0f1c5f..27c446e 100644
> --- a/init/main.c
> +++ b/init/main.c
> @@ -685,8 +685,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, 0, bool, 0644);

For a bool, the default value should be "false", not "0", right? Or does
the command-line parsing not handle that?

- Josh Triplett

Iulia Manda

unread,
Mar 4, 2015, 5:48:06 PM3/4/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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 preivous version in which builtin cmdline
was also set to 'Y'):

add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
function old new delta
load_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

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v1:
- solve indentation issues

arch/x86/Kconfig | 15 +++++++++++++++
include/linux/moduleparam.h | 14 ++++++++++++++
kernel/params.c | 2 ++
3 files changed, 31 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c2fb8a8..f1e02ea 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2003,8 +2003,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
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 1c9effa..f97397c 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h

Iulia Manda

unread,
Mar 4, 2015, 5:48:07 PM3/4/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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.

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v1:
- make the variable static const instead of extern const; this allows
for constant folding in all the places where it is used;
- by making the previous change the header containing the
implementation of the DECLARE_CORE_PARAM macro has to be included everywhere
var is used; for now, I chose to leave the definition and the declaration in
separate files. Having them both in moduleparam.h causes:
* circular includes (in the headers that are included in
moduleparam.h and that would use DECLARE_CORE_PARAM);
* a lot of lines of code added and also some bloated code because of
the inclusion of moduleparam.h in multiple files.
* naive solution: add a new header file containing the macros;
- get rid of hardcoded types and dummy variable;
- keep consistency;

include/linux/init.h | 8 ++++++++
include/linux/moduleparam.h | 9 +++++++++
2 files changed, 17 insertions(+)

diff --git a/include/linux/init.h b/include/linux/init.h
index 2df8e8d..ce6d39b 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -155,6 +155,14 @@ int __init init_rootfs(void);

extern void (*late_time_init)(void);

+#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
+
extern bool initcall_debug;

#endif
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index f97397c..17efa97 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -310,6 +310,15 @@ static inline void __kernel_param_unlock(void)
#define core_param(name, var, type, perm) \
param_check_##type(name, &(var)); \
__module_param_call("", name, &param_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
+

Iulia Manda

unread,
Mar 4, 2015, 5:48:07 PM3/4/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
Test the previously implemented macros on initcall_debug parameter, after
setting CONFIG_CMDLINE_PARSE to 'n'.

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 delta
initcall_debug 1 - -1
pm_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

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v1:
- use "false" as a default value for bool type
include/linux/init.h | 2 +-
init/main.c | 3 +--
2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index ce6d39b..e55db5c 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -163,7 +163,7 @@ extern void (*late_time_init)(void);
static const type var = val
#endif

-extern bool initcall_debug;
+DECLARE_CORE_PARAM(initcall_debug, false, bool);

#endif

diff --git a/init/main.c b/init/main.c
index 6f0f1c5f..85e9001 100644
--- a/init/main.c
+++ b/init/main.c
@@ -685,8 +685,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);

Iulia Manda

unread,
Mar 7, 2015, 11:26:29 AM3/7/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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 preivous version in which builtin cmdline
was also set to 'Y'):

add/remove: 0/8 grow/shrink: 0/6 up/down: 0/-3669 (-3669)
function old new delta
load_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

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 1c9effa..f97397c 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h

Iulia Manda

unread,
Mar 7, 2015, 11:26:30 AM3/7/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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.

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v2:
- introduce a new header in order to avoid the inclusion of heavy weight
headers such as moduleparam.h; also, the inclusion of an existing header in all
the places where the static const variable is used may cause circular includes;
* this header contains the declaration for core_param variables and
shall be completed with other types of kernel command line parameters variable
declarations.
* this may be just a temorary solution; if any other include file
seems to be more fitted for this, that suggestion is welcomed.

include/linux/moduleparam.h | 9 +++++++++
include/linux/params.h | 12 ++++++++++++
2 files changed, 21 insertions(+)
create mode 100644 include/linux/params.h

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index f97397c..17efa97 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -310,6 +310,15 @@ static inline void __kernel_param_unlock(void)
#define core_param(name, var, type, perm) \
param_check_##type(name, &(var)); \
__module_param_call("", name, &param_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 */

/**
diff --git a/include/linux/params.h b/include/linux/params.h
new file mode 100644
index 0000000..c1ee6ff
--- /dev/null
+++ b/include/linux/params.h
@@ -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_INIT_H */
--
1.9.1

Iulia Manda

unread,
Mar 7, 2015, 11:26:34 AM3/7/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
Test the previously implemented macros on initcall_debug parameter, after
setting CONFIG_CMDLINE_PARSE to 'n'.

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 delta
initcall_debug 1 - -1
pm_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

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v2:
- use DECLARE_CORE_PARAM macro from linux/params.h
include/linux/init.h | 3 ++-
init/main.c | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 2df8e8d..d53f28d 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -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);

Iulia Manda

unread,
Mar 7, 2015, 11:37:27 AM3/7/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
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.

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v3:
- fix comment
+#endif /* _LINUX_PARAMS_H */
--
1.9.1

Reply all
Reply to author
Forward
0 new messages