linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] moduleparams: Add hex type parameter
@ 2020-07-02 14:01 Paul Menzel
  2020-07-02 14:01 ` [PATCH 2/2] drm/amdgpu: Change type of module param `ppfeaturemask` to hex Paul Menzel
  2020-07-02 14:42 ` [PATCH 1/2] moduleparams: Add hex type parameter Christian König
  0 siblings, 2 replies; 5+ messages in thread
From: Paul Menzel @ 2020-07-02 14:01 UTC (permalink / raw)
  To: Linus Torvalds, Alex Deucher, Christian König
  Cc: Paul Menzel, linux-kernel, amd-gfx

For bitmasks printing values in hex is more convenient.

Prefix with 0x (#) to make it clear, that it’s a hex value.

Using the helper for `amdgpu.ppfeaturemask`, it will look like below.

Before:

    $ more /sys/module/amdgpu/parameters/ppfeaturemask
    4294950911

After:

    $ more /sys/module/amdgpu/parameters/ppfeaturemask
    0xffffbfff

Cc: linux-kernel@vger.kernel.org
Cc: amd-gfx@lists.freedesktop.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
 include/linux/moduleparam.h | 7 ++++++-
 kernel/params.c             | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 3ef917ff0964..408978fcfe27 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -118,7 +118,7 @@ struct kparam_array
  * you can create your own by defining those variables.
  *
  * Standard types are:
- *	byte, short, ushort, int, uint, long, ulong
+ *	byte, hex, short, ushort, int, uint, long, ulong
  *	charp: a character pointer
  *	bool: a bool, values 0/1, y/n, Y/N.
  *	invbool: the above, only sense-reversed (N = true).
@@ -448,6 +448,11 @@ extern int param_set_ullong(const char *val, const struct kernel_param *kp);
 extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
 #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
 
+extern const struct kernel_param_ops param_ops_hex;
+extern int param_set_hex(const char *val, const struct kernel_param *kp);
+extern int param_get_hex(char *buffer, const struct kernel_param *kp);
+#define param_check_hex(name, p) param_check_uint(name, p)
+
 extern const struct kernel_param_ops param_ops_charp;
 extern int param_set_charp(const char *val, const struct kernel_param *kp);
 extern int param_get_charp(char *buffer, const struct kernel_param *kp);
diff --git a/kernel/params.c b/kernel/params.c
index 8e56f8b12d8f..ceca8394dac5 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -241,6 +241,7 @@ STANDARD_PARAM_DEF(uint,	unsigned int,		"%u",   kstrtouint);
 STANDARD_PARAM_DEF(long,	long,			"%li",  kstrtol);
 STANDARD_PARAM_DEF(ulong,	unsigned long,		"%lu",  kstrtoul);
 STANDARD_PARAM_DEF(ullong,	unsigned long long,	"%llu", kstrtoull);
+STANDARD_PARAM_DEF(hex,		unsigned int,		"%#x",  kstrtouint);
 
 int param_set_charp(const char *val, const struct kernel_param *kp)
 {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] drm/amdgpu: Change type of module param `ppfeaturemask` to hex
  2020-07-02 14:01 [PATCH 1/2] moduleparams: Add hex type parameter Paul Menzel
@ 2020-07-02 14:01 ` Paul Menzel
  2020-07-02 14:42 ` [PATCH 1/2] moduleparams: Add hex type parameter Christian König
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Menzel @ 2020-07-02 14:01 UTC (permalink / raw)
  To: Linus Torvalds, Alex Deucher, Christian König
  Cc: Paul Menzel, amd-gfx, linux-kernel

The newly added hex helper is more convenient for bitmasks.

Before:

    $ more /sys/module/amdgpu/parameters/ppfeaturemask
    4294950911

After:

    $ more /sys/module/amdgpu/parameters/ppfeaturemask
    0xffffbfff

Cc: amd-gfx@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 126e74758a34..35a66b374e3a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -391,12 +391,12 @@ MODULE_PARM_DESC(sched_hw_submission, "the max number of HW submissions (default
 module_param_named(sched_hw_submission, amdgpu_sched_hw_submission, int, 0444);
 
 /**
- * DOC: ppfeaturemask (uint)
+ * DOC: ppfeaturemask (hex)
  * Override power features enabled. See enum PP_FEATURE_MASK in drivers/gpu/drm/amd/include/amd_shared.h.
  * The default is the current set of stable power features.
  */
 MODULE_PARM_DESC(ppfeaturemask, "all power features enabled (default))");
-module_param_named(ppfeaturemask, amdgpu_pp_feature_mask, uint, 0444);
+module_param_named(ppfeaturemask, amdgpu_pp_feature_mask, hex, 0444);
 
 /**
  * DOC: forcelongtraining (uint)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] moduleparams: Add hex type parameter
  2020-07-02 14:01 [PATCH 1/2] moduleparams: Add hex type parameter Paul Menzel
  2020-07-02 14:01 ` [PATCH 2/2] drm/amdgpu: Change type of module param `ppfeaturemask` to hex Paul Menzel
@ 2020-07-02 14:42 ` Christian König
  2020-07-02 19:42   ` Linus Torvalds
  1 sibling, 1 reply; 5+ messages in thread
From: Christian König @ 2020-07-02 14:42 UTC (permalink / raw)
  To: Paul Menzel, Linus Torvalds, Alex Deucher; +Cc: linux-kernel, amd-gfx

Am 02.07.20 um 16:01 schrieb Paul Menzel:
> For bitmasks printing values in hex is more convenient.
>
> Prefix with 0x (#) to make it clear, that it’s a hex value.
>
> Using the helper for `amdgpu.ppfeaturemask`, it will look like below.
>
> Before:
>
>      $ more /sys/module/amdgpu/parameters/ppfeaturemask
>      4294950911
>
> After:
>
>      $ more /sys/module/amdgpu/parameters/ppfeaturemask
>      0xffffbfff
>
> Cc: linux-kernel@vger.kernel.org
> Cc: amd-gfx@lists.freedesktop.org
> Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>

Good idea.

I'm just not sure how well this is received upstream because it only 
covers u32

On the other hand that is probably also the most used.

Christian.

> ---
>   include/linux/moduleparam.h | 7 ++++++-
>   kernel/params.c             | 1 +
>   2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index 3ef917ff0964..408978fcfe27 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -118,7 +118,7 @@ struct kparam_array
>    * you can create your own by defining those variables.
>    *
>    * Standard types are:
> - *	byte, short, ushort, int, uint, long, ulong
> + *	byte, hex, short, ushort, int, uint, long, ulong
>    *	charp: a character pointer
>    *	bool: a bool, values 0/1, y/n, Y/N.
>    *	invbool: the above, only sense-reversed (N = true).
> @@ -448,6 +448,11 @@ extern int param_set_ullong(const char *val, const struct kernel_param *kp);
>   extern int param_get_ullong(char *buffer, const struct kernel_param *kp);
>   #define param_check_ullong(name, p) __param_check(name, p, unsigned long long)
>   
> +extern const struct kernel_param_ops param_ops_hex;
> +extern int param_set_hex(const char *val, const struct kernel_param *kp);
> +extern int param_get_hex(char *buffer, const struct kernel_param *kp);
> +#define param_check_hex(name, p) param_check_uint(name, p)
> +
>   extern const struct kernel_param_ops param_ops_charp;
>   extern int param_set_charp(const char *val, const struct kernel_param *kp);
>   extern int param_get_charp(char *buffer, const struct kernel_param *kp);
> diff --git a/kernel/params.c b/kernel/params.c
> index 8e56f8b12d8f..ceca8394dac5 100644
> --- a/kernel/params.c
> +++ b/kernel/params.c
> @@ -241,6 +241,7 @@ STANDARD_PARAM_DEF(uint,	unsigned int,		"%u",   kstrtouint);
>   STANDARD_PARAM_DEF(long,	long,			"%li",  kstrtol);
>   STANDARD_PARAM_DEF(ulong,	unsigned long,		"%lu",  kstrtoul);
>   STANDARD_PARAM_DEF(ullong,	unsigned long long,	"%llu", kstrtoull);
> +STANDARD_PARAM_DEF(hex,		unsigned int,		"%#x",  kstrtouint);
>   
>   int param_set_charp(const char *val, const struct kernel_param *kp)
>   {


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] moduleparams: Add hex type parameter
  2020-07-02 14:42 ` [PATCH 1/2] moduleparams: Add hex type parameter Christian König
@ 2020-07-02 19:42   ` Linus Torvalds
  2020-07-03 13:52     ` Paul Menzel
  0 siblings, 1 reply; 5+ messages in thread
From: Linus Torvalds @ 2020-07-02 19:42 UTC (permalink / raw)
  To: Christian König
  Cc: Paul Menzel, Alex Deucher, Linux Kernel Mailing List, amd-gfx

On Thu, Jul 2, 2020 at 7:42 AM Christian König <christian.koenig@amd.com> wrote:
>
> I'm just not sure how well this is received upstream because it only
> covers u32
>
> On the other hand that is probably also the most used.

Not necessarily true. I'd argue that "unsigned long"  is equally
possible for some bit mask (or other hex-likely) type.

So don't call it just "hex". Call it "hexint" (the hex does imply
"unsigned", I feel - showing hex numbers with a sign sounds insane).

That way, if somebody ends up wanting it for unsigned long values,
we're not stuck.

Another option is to just say that hex values always have bit _sizes_.
So "hex32" and "hex64" would also make sense as names to me.

While at it, should the hex numbers always be padded out to the size?
The example Paul used doesn't have that issue (high bit being set).

Bbut often it may make sense to show a 32-bit hex number as "%#08x"
because it really makes things clearer when you're looking at high
bits, say.

It's really hard to tell the difference between "just bit 27 set" and
"just bit 31" set otherwise, and that's not all that uncommon when the
bitmasks are sparse.

             Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] moduleparams: Add hex type parameter
  2020-07-02 19:42   ` Linus Torvalds
@ 2020-07-03 13:52     ` Paul Menzel
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Menzel @ 2020-07-03 13:52 UTC (permalink / raw)
  To: Linus Torvalds, Christian König
  Cc: Alex Deucher, Linux Kernel Mailing List, amd-gfx

Dear Linus, dear Christian,


Am 02.07.20 um 21:42 schrieb Linus Torvalds:
> On Thu, Jul 2, 2020 at 7:42 AM Christian König <christian.koenig@amd.com> wrote:
>>
>> I'm just not sure how well this is received upstream because it only
>> covers u32
>>
>> On the other hand that is probably also the most used.
> 
> Not necessarily true. I'd argue that "unsigned long"  is equally
> possible for some bit mask (or other hex-likely) type.
> 
> So don't call it just "hex". Call it "hexint" (the hex does imply
> "unsigned", I feel - showing hex numbers with a sign sounds insane).
> 
> That way, if somebody ends up wanting it for unsigned long values,
> we're not stuck.

Good idea. Don.e

> Another option is to just say that hex values always have bit _sizes_.
> So "hex32" and "hex64" would also make sense as names to me.

I went for int to be consistent in the naming, and kstrtouint is used in 
the macro.

> While at it, should the hex numbers always be padded out to the size?
> The example Paul used doesn't have that issue (high bit being set).
> 
> Bbut often it may make sense to show a 32-bit hex number as "%#08x"
> because it really makes things clearer when you're looking at high
> bits, say.
> 
> It's really hard to tell the difference between "just bit 27 set" and
> "just bit 31" set otherwise, and that's not all that uncommon when the
> bitmasks are sparse.

Also good idea. Done.

I just sent out the v2.


Kind regards,

Paul

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-03 13:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 14:01 [PATCH 1/2] moduleparams: Add hex type parameter Paul Menzel
2020-07-02 14:01 ` [PATCH 2/2] drm/amdgpu: Change type of module param `ppfeaturemask` to hex Paul Menzel
2020-07-02 14:42 ` [PATCH 1/2] moduleparams: Add hex type parameter Christian König
2020-07-02 19:42   ` Linus Torvalds
2020-07-03 13:52     ` Paul Menzel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).