Skip to contentSkip to conversation

moduleparams: Add hexint type parameter

PATCH In review Paul Menzel 2 participants 3 messages Jul 3, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 moduleparams: Add hexint type parameter

For bitmasks printing values in hex is more convenient.

Prefix with 0x to make it clear, that it’s a hex value, and pad it out.

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

---
v2: Address review comments: Rename hex to hexint, and pad sizes

 include/linux/moduleparam.h |  7 ++++++-
 kernel/params.c             | 17 +++++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)
include/linux/moduleparam.h +6 -1
index 3ef917ff0964..cff7261e98bb 100644
@@ -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, hexint, 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_hexint;
+extern int param_set_hexint(const char *val, const struct kernel_param *kp);
+extern int param_get_hexint(char *buffer, const struct kernel_param *kp);
+#define param_check_hexint(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);
kernel/params.c +9 -8
index 8e56f8b12d8f..487261eb836f 100644
@@ -233,14 +233,15 @@ char *parse_args(const char *doing,
 	EXPORT_SYMBOL(param_ops_##name)
 
 
-STANDARD_PARAM_DEF(byte,	unsigned char,		"%hhu", kstrtou8);
-STANDARD_PARAM_DEF(short,	short,			"%hi",  kstrtos16);
-STANDARD_PARAM_DEF(ushort,	unsigned short,		"%hu",  kstrtou16);
-STANDARD_PARAM_DEF(int,		int,			"%i",   kstrtoint);
-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(byte,	unsigned char,		"%hhu",  kstrtou8);
+STANDARD_PARAM_DEF(short,	short,			"%hi",   kstrtos16);
+STANDARD_PARAM_DEF(ushort,	unsigned short,		"%hu",   kstrtou16);
+STANDARD_PARAM_DEF(int,		int,			"%i",    kstrtoint);
+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(hexint,	unsigned int,		"%#08x", kstrtouint);
 
 int param_set_charp(const char *val, const struct kernel_param *kp)
 {
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 2/2 drm/amdgpu: Change type of module param `ppfeaturemask` to hexint

The newly added hexint helper is more convenient for bitmasks.

Before:

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

After:

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

---
v2: Use new name hexint

 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2 -2
index 126e74758a34..5c4263335cba 100644
@@ -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 (hexint)
  * 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, hexint, 0444);
 
 /**
  * DOC: forcelongtraining (uint)
Signature · 1 line
2.26.2
maintainer
#2 lore raw
In reply to Paul Menzel

Am 03.07.20 um 15:49 schrieb Paul Menzel:

Quoted 67 lines

For bitmasks printing values in hex is more convenient.

Prefix with 0x to make it clear, that it’s a hex value, and pad it out.

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

---
v2: Address review comments: Rename hex to hexint, and pad sizes

  include/linux/moduleparam.h |  7 ++++++-
  kernel/params.c             | 17 +++++++++--------
  2 files changed, 15 insertions(+), 9 deletions(-)
include/linux/moduleparam.h +6 -1
index 3ef917ff0964..cff7261e98bb 100644
@@ -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, hexint, 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_hexint;
+extern int param_set_hexint(const char *val, const struct kernel_param *kp);
+extern int param_get_hexint(char *buffer, const struct kernel_param *kp);
+#define param_check_hexint(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);
kernel/params.c +0 -7
index 8e56f8b12d8f..487261eb836f 100644
@@ -233,14 +233,15 @@ char *parse_args(const char *doing,
  	EXPORT_SYMBOL(param_ops_##name)
 
 
-STANDARD_PARAM_DEF(byte,	unsigned char,		"%hhu", kstrtou8);
-STANDARD_PARAM_DEF(short,	short,			"%hi",  kstrtos16);
-STANDARD_PARAM_DEF(ushort,	unsigned short,		"%hu",  kstrtou16);
-STANDARD_PARAM_DEF(int,		int,			"%i",   kstrtoint);
-STANDARD_PARAM_DEF(uint,	unsigned int,		"%u",   kstrtouint);
-STANDARD_PARAM_DEF(long,	long,			"%li",  kstrtol);
-STANDARD_PARAM_DEF(ulong,	unsigned long,		"%lu",  kstrtoul);

kernel/params.c char *parse_args(const char *doing, · line 244

Quoted 10 lines
kernel/params.c +9 -1
-STANDARD_PARAM_DEF(ullong,	unsigned long long,	"%llu", kstrtoull);
+STANDARD_PARAM_DEF(byte,	unsigned char,		"%hhu",  kstrtou8);
+STANDARD_PARAM_DEF(short,	short,			"%hi",   kstrtos16);
+STANDARD_PARAM_DEF(ushort,	unsigned short,		"%hu",   kstrtou16);
+STANDARD_PARAM_DEF(int,		int,			"%i",    kstrtoint);
+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(hexint,	unsigned int,		"%#08x", kstrtouint);

All other indentations uses tabs, only the last one seems to use a space. If you touch this, then maybe make it consistent as well.

Apart from that looks good to me,
Christian.

kernel/params.c char *parse_args(const char *doing, · line 247

Quoted 3 lines
kernel/params.c +0 -0
  int param_set_charp(const char *val, const struct kernel_param *kp)
  {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx