[OPW kernel] [PATCH RFC] include/linux: Constant folding for kernel core_param

josh at joshtriplett.org josh at joshtriplett.org
Fri Feb 27 19:49:35 EET 2015


On Fri, Feb 27, 2015 at 06:34:35PM +0200, Iulia Manda wrote:
> This patch aims to prove GCC's capability to constant fold kernel command line
> arguments, if they are specified at compile time and no argument is passed at
> boot time.
> 
> At the moment, this patch treats only core_param arguments and exemplified on
> initcall_debug. Also, initcall_debug variable is set to a default value,
> known at compile time.
> 
> 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.

The kernel config option needs to have "no" as the "don't support kernel
command-line, make everything const" option, and "yes" as the "do
support parsing a kernel command line" option, so that "make
allnoconfig" and "make tinyconfig" do the right thing.  (Related to
that, the option could actually turn off kernel command-line processing,
and the option to compile in a kernel command line should depend on it.
You also need to include the Kconfig bits in the patch.)

Also, you don't want to introduce ifdefs at the point of usage.
Instead, core_default_param should always exist, and should use "const"
when the config option is enabled.  I'd also suggest renaming it to
DEFINE_CORE_PARAM, as a parallel to similar macros that define
variables.  Similarly, you should have a DECLARE_CORE_PARAM, which
translates to the necessary "extern" statement.  Then neither the
definition nor the declaration of initcall_debug will need an ifdef.

When the config option is disabled, you should *only* define the const
variable, and not define the command-line handling at all.

Finally, you'll want to post this as a two-patch series, the first
introducing the macros, and the second changing something like
initcall_debug over to use it.

- Josh Triplett


More information about the firefly mailing list