Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-22 Thread Luis R. Rodriguez
On Wed, Apr 22, 2015 at 04:45:04PM +0930, Rusty Russell wrote:
> "Luis R. Rodriguez"  writes:
> > From: "Luis R. Rodriguez" 
> >
> > This adds a couple of bool module_param_config_*() helpers
> > which are designed to let us easily associate a booloean
> > module parameter with an associated kernel configuration
> > option, and to help us remove #ifdef'ery eyesores.
> 
> But they don't.  And I had to read the descriptions twice to understand
> what you're doing.
> 
> eg you use it like this:
> 
>  -#ifdef CONFIG_WQ_POWER_EFFICIENT_DEFAULT
>  -static bool wq_power_efficient = true;
>  -#else
>  -static bool wq_power_efficient;
>  -#endif
>  -
>  -module_param_named(power_efficient, wq_power_efficient, bool, 0444);
>  +module_param_config_on_off(power_efficient, wq_power_efficient, 0444,
>  CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
> 
> It would be much clearer to do this:
> 
>  -#ifdef CONFIG_WQ_POWER_EFFICIENT_DEFAULT
>  -static bool wq_power_efficient = true;
>  -#else
>  -static bool wq_power_efficient;
>  -#endif
>  +static bool wq_power_efficient = 
> IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT);
> 
> I know exactly what that does without having to notice the difference
> between module_param_config_on_off() and module_param_config_on().

You're right, I forgot a small step patch in between to make the change
clearer. I can add that in my next respin, anything else or do the other
changes  look OK?

 Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-22 Thread Rusty Russell
"Luis R. Rodriguez"  writes:
> From: "Luis R. Rodriguez" 
>
> This adds a couple of bool module_param_config_*() helpers
> which are designed to let us easily associate a booloean
> module parameter with an associated kernel configuration
> option, and to help us remove #ifdef'ery eyesores.

But they don't.  And I had to read the descriptions twice to understand
what you're doing.

eg you use it like this:

 -#ifdef CONFIG_WQ_POWER_EFFICIENT_DEFAULT
 -static bool wq_power_efficient = true;
 -#else
 -static bool wq_power_efficient;
 -#endif
 -
 -module_param_named(power_efficient, wq_power_efficient, bool, 0444);
 +module_param_config_on_off(power_efficient, wq_power_efficient, 0444,
 CONFIG_WQ_POWER_EFFICIENT_DEFAULT);

It would be much clearer to do this:

 -#ifdef CONFIG_WQ_POWER_EFFICIENT_DEFAULT
 -static bool wq_power_efficient = true;
 -#else
 -static bool wq_power_efficient;
 -#endif
 +static bool wq_power_efficient = 
IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT);

I know exactly what that does without having to notice the difference
between module_param_config_on_off() and module_param_config_on().

Cheers,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-21 Thread Tejun Heo
Hello, Luis.

On Tue, Apr 21, 2015 at 06:55:16PM +0200, Luis R. Rodriguez wrote:
> A use then would be for instance:
> 
> module_param_config_on_off(power_efficient, wq_power_efficient, 0444,
>  IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT));
> 
> this as an alternative would enable use of other static / global variables but
> I'm not sure if these are good use cases to promote, given that all this is to
> help with initial set up, so I believe the restrictions are for the better.

I was thinking more of cases where CONFIG should be inverted or
and/or'd.  In general I don't think we conventionally embed
IS_ENABLED() in this sort of macros.  It just jumps at me as a weird
restriction.  What do others think?

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-21 Thread Luis R. Rodriguez
On Tue, Apr 21, 2015 at 11:21:36AM -0400, Tejun Heo wrote:
> On Mon, Apr 20, 2015 at 04:30:35PM -0700, Luis R. Rodriguez wrote:
> >  /**
> > + * module_param_config_on_off - bool parameter with run time override
> > + * @name: a valid C identifier which is the parameter name.
> > + * @value: the actual lvalue to alter.
> > + * @perm: visibility in sysfs.
> > + * @config: kernel parameter which will enable this option if this
> > + * kernel configuration option has been enabled.
> > + *
> > + * This lets you define a bool module paramter which by default will be
> > + * set to true if the config option has been set on your kernel's
> > + * configuration, otherwise it is set to false.
> > + */
> > +#define module_param_config_on_off(name, var, perm, config)
> > \
> > +   static bool var = IS_ENABLED(config);   \
> > +   module_param_named(name, var, bool, perm);
> 
> Maybe we want to make @config just a boolean initializer?
> e.g. something like
> 
> #define module_param_config_on_off(name, var, perm, on_off)   \
>   static bool var = on_off;   \
>   module_param_named(name, var, bool, perm);
> 
> so that the caller does IS_ENABLED() or whatever that's necessary?  It
> just seems a bit too restricted.

A use then would be for instance:

module_param_config_on_off(power_efficient, wq_power_efficient, 0444,
   IS_ENABLED(CONFIG_WQ_POWER_EFFICIENT_DEFAULT));

this as an alternative would enable use of other static / global variables but
I'm not sure if these are good use cases to promote, given that all this is to
help with initial set up, so I believe the restrictions are for the better.

Let me know, we already have early_param_on_off() relying on @config so
we should consider both and/or address early_param_on_off() as well
while at it.

 Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-21 Thread Luis R. Rodriguez
On Tue, Apr 21, 2015 at 09:42:21AM +1000, Julian Calaby wrote:
> Hi Luis,
> 
> You made a spelling mistake:
> 
> On Tue, Apr 21, 2015 at 9:30 AM, Luis R. Rodriguez
>  wrote:
> > From: "Luis R. Rodriguez" 
> >
> > This adds a couple of bool module_param_config_*() helpers
> > which are designed to let us easily associate a booloean
> > module parameter with an associated kernel configuration
> > option, and to help us remove #ifdef'ery eyesores.
> >
> > Cc: Rusty Russell 
> > Cc: Jani Nikula 
> > Cc: Christoph Hellwig 
> > Cc: Andrew Morton 
> > Cc: Geert Uytterhoeven 
> > Cc: Hannes Reinecke 
> > Cc: Kees Cook 
> > Cc: Tejun Heo 
> > Cc: Ingo Molnar 
> > Cc: linux-kernel@vger.kernel.org
> > Cc: co...@systeme.lip6.fr
> > Signed-off-by: Luis R. Rodriguez 
> > ---
> >  include/linux/moduleparam.h | 37 +
> >  1 file changed, 37 insertions(+)
> >
> > diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> > index 7e00799..fdf7b87 100644
> > --- a/include/linux/moduleparam.h
> > +++ b/include/linux/moduleparam.h
> > @@ -155,6 +155,43 @@ struct kparam_array
> > __MODULE_PARM_TYPE(name, #type)
> >
> >  /**
> > + * module_param_config_on_off - bool parameter with run time override
> > + * @name: a valid C identifier which is the parameter name.
> > + * @value: the actual lvalue to alter.
> > + * @perm: visibility in sysfs.
> > + * @config: kernel parameter which will enable this option if this
> > + * kernel configuration option has been enabled.
> > + *
> > + * This lets you define a bool module paramter which by default will be
> 
> s/paramter/parameter/
> 
> > + * set to true if the config option has been set on your kernel's
> > + * configuration, otherwise it is set to false.
> > + */
> > +#define module_param_config_on_off(name, var, perm, config)\
> > +   static bool var = IS_ENABLED(config);   \
> > +   module_param_named(name, var, bool, perm);
> > +
> > +/**
> > + * module_param_config_on - bool parameter with run time enablement 
> > override
> > + * @name: a valid C identifier which is the parameter name.
> > + * @value: the actual lvalue to alter.
> > + * @perm: visibility in sysfs.
> > + * @config: kernel parameter which will enable this option if this
> > + * kernel configuration option has been enabled.
> > + *
> > + * This lets you define a bool module paramter which by default will be
> 
> Here too.

Fixed, thanks.

  Luis
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-21 Thread Tejun Heo
On Mon, Apr 20, 2015 at 04:30:35PM -0700, Luis R. Rodriguez wrote:
>  /**
> + * module_param_config_on_off - bool parameter with run time override
> + * @name: a valid C identifier which is the parameter name.
> + * @value: the actual lvalue to alter.
> + * @perm: visibility in sysfs.
> + * @config: kernel parameter which will enable this option if this
> + *   kernel configuration option has been enabled.
> + *
> + * This lets you define a bool module paramter which by default will be
> + * set to true if the config option has been set on your kernel's
> + * configuration, otherwise it is set to false.
> + */
> +#define module_param_config_on_off(name, var, perm, config)  \
> + static bool var = IS_ENABLED(config);   \
> + module_param_named(name, var, bool, perm);

Maybe we want to make @config just a boolean initializer?
e.g. something like

#define module_param_config_on_off(name, var, perm, on_off) \
static bool var = on_off;   \
module_param_named(name, var, bool, perm);

so that the caller does IS_ENABLED() or whatever that's necessary?  It
just seems a bit too restricted.

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-20 Thread Julian Calaby
Hi Luis,

You made a spelling mistake:

On Tue, Apr 21, 2015 at 9:30 AM, Luis R. Rodriguez
 wrote:
> From: "Luis R. Rodriguez" 
>
> This adds a couple of bool module_param_config_*() helpers
> which are designed to let us easily associate a booloean
> module parameter with an associated kernel configuration
> option, and to help us remove #ifdef'ery eyesores.
>
> Cc: Rusty Russell 
> Cc: Jani Nikula 
> Cc: Christoph Hellwig 
> Cc: Andrew Morton 
> Cc: Geert Uytterhoeven 
> Cc: Hannes Reinecke 
> Cc: Kees Cook 
> Cc: Tejun Heo 
> Cc: Ingo Molnar 
> Cc: linux-kernel@vger.kernel.org
> Cc: co...@systeme.lip6.fr
> Signed-off-by: Luis R. Rodriguez 
> ---
>  include/linux/moduleparam.h | 37 +
>  1 file changed, 37 insertions(+)
>
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index 7e00799..fdf7b87 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -155,6 +155,43 @@ struct kparam_array
> __MODULE_PARM_TYPE(name, #type)
>
>  /**
> + * module_param_config_on_off - bool parameter with run time override
> + * @name: a valid C identifier which is the parameter name.
> + * @value: the actual lvalue to alter.
> + * @perm: visibility in sysfs.
> + * @config: kernel parameter which will enable this option if this
> + * kernel configuration option has been enabled.
> + *
> + * This lets you define a bool module paramter which by default will be

s/paramter/parameter/

> + * set to true if the config option has been set on your kernel's
> + * configuration, otherwise it is set to false.
> + */
> +#define module_param_config_on_off(name, var, perm, config)\
> +   static bool var = IS_ENABLED(config);   \
> +   module_param_named(name, var, bool, perm);
> +
> +/**
> + * module_param_config_on - bool parameter with run time enablement override
> + * @name: a valid C identifier which is the parameter name.
> + * @value: the actual lvalue to alter.
> + * @perm: visibility in sysfs.
> + * @config: kernel parameter which will enable this option if this
> + * kernel configuration option has been enabled.
> + *
> + * This lets you define a bool module paramter which by default will be

Here too.

Thanks,

-- 
Julian Calaby

Email: julian.cal...@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v1 4/6] moduleparam.h: add module_param_config_*() helpers

2015-04-20 Thread Luis R. Rodriguez
From: "Luis R. Rodriguez" 

This adds a couple of bool module_param_config_*() helpers
which are designed to let us easily associate a booloean
module parameter with an associated kernel configuration
option, and to help us remove #ifdef'ery eyesores.

Cc: Rusty Russell 
Cc: Jani Nikula 
Cc: Christoph Hellwig 
Cc: Andrew Morton 
Cc: Geert Uytterhoeven 
Cc: Hannes Reinecke 
Cc: Kees Cook 
Cc: Tejun Heo 
Cc: Ingo Molnar 
Cc: linux-kernel@vger.kernel.org
Cc: co...@systeme.lip6.fr
Signed-off-by: Luis R. Rodriguez 
---
 include/linux/moduleparam.h | 37 +
 1 file changed, 37 insertions(+)

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 7e00799..fdf7b87 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -155,6 +155,43 @@ struct kparam_array
__MODULE_PARM_TYPE(name, #type)
 
 /**
+ * module_param_config_on_off - bool parameter with run time override
+ * @name: a valid C identifier which is the parameter name.
+ * @value: the actual lvalue to alter.
+ * @perm: visibility in sysfs.
+ * @config: kernel parameter which will enable this option if this
+ * kernel configuration option has been enabled.
+ *
+ * This lets you define a bool module paramter which by default will be
+ * set to true if the config option has been set on your kernel's
+ * configuration, otherwise it is set to false.
+ */
+#define module_param_config_on_off(name, var, perm, config)\
+   static bool var = IS_ENABLED(config);   \
+   module_param_named(name, var, bool, perm);
+
+/**
+ * module_param_config_on - bool parameter with run time enablement override
+ * @name: a valid C identifier which is the parameter name.
+ * @value: the actual lvalue to alter.
+ * @perm: visibility in sysfs.
+ * @config: kernel parameter which will enable this option if this
+ * kernel configuration option has been enabled.
+ *
+ * This lets you define a bool module paramter which by default will be
+ * set to true if the config option has been set on your kernel's
+ * configuration, otherwise it is set to false. This particular helper
+ * will ensure that if the kernel configuration has been set you will not
+ * be able to disable this kernel parameter. You can only use this to let
+ * the an option that was disabled on your kernel configuration be enabled
+ * at run time.
+ */
+#define module_param_config_on(name, var, perm, config)\
+   static bool var = IS_ENABLED(config);   \
+   module_param_named(name, var, bool_enable_only, perm);
+
+
+/**
  * module_param_cb - general callback for a module/cmdline parameter
  * @name: a valid C identifier which is the parameter name.
  * @ops: the set & get operations for this parameter.
-- 
2.3.2.209.gd67f9d5.dirty

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/