Skip to contentSkip to conversation

lib: test get_count_order/long in test_bitops.c

PATCH Applied Wei Yang 5 participants 15 messages Jun 2, 2020 – Jun 12, 2020

Subsystems (2)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH v2 1/1 lib: test get_count_order/long in test_bitops.c

Add some test for get_count_order/long in test_bitops.c.

---
v2: merge the test into test_bitops.c

---
 lib/Kconfig.debug | 10 +++++-----
 lib/test_bitops.c | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)
lib/Kconfig.debug +5 -5
index f80d5609798f..512111a72e34 100644
@@ -1987,15 +1987,15 @@ config TEST_LKM
 	  If unsure, say N.
 
 config TEST_BITOPS
-	tristate "Test module for compilation of clear_bit/set_bit operations"
+	tristate "Test module for compilation of bitops operations"
 	depends on m
 	help
 	  This builds the "test_bitops" module that is much like the
 	  TEST_LKM module except that it does a basic exercise of the
-	  clear_bit and set_bit macros to make sure there are no compiler
-	  warnings from C=1 sparse checker or -Wextra compilations. It has
-	  no dependencies and doesn't run or load unless explicitly requested
-	  by name.  for example: modprobe test_bitops.
+	  set/clear_bit macros and get_count_order/long to make sure there are
+	  no compiler warnings from C=1 sparse checker or -Wextra
+	  compilations. It has no dependencies and doesn't run or load unless
+	  explicitly requested by name.  for example: modprobe test_bitops.
 
 	  If unsure, say N.
 
lib/test_bitops.c +38 -2
index fd50b3ae4a14..702d5973a5b6 100644
@@ -9,7 +9,11 @@
 #include <linux/module.h>
 #include <linux/printk.h>
 
-/* a tiny module only meant to test set/clear_bit */
+/* a tiny module only meant to test
+ *
+ *   set/clear_bit
+ *   get_count_order/long
+ */
 
 /* use an enum because thats the most common BITMAP usage */
 enum bitops_fun {
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+	{0x00000003,  2},
+	{0x00000004,  2},
+	{0x00001fff, 13},
+	{0x00002000, 13},
+	{0x50000000, 31},
+	{0x80000000, 31},
+	{0x80003000, 32},
+};
+
+unsigned long order_comb_long[][2] = {
+	{0x0000000300000000, 34},
+	{0x0000000400000000, 34},
+	{0x00001fff00000000, 45},
+	{0x0000200000000000, 45},
+	{0x5000000000000000, 63},
+	{0x8000000000000000, 63},
+	{0x8000300000000000, 64},
+};
+
 static int __init test_bitops_startup(void)
 {
 	pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
 	set_bit(BITOPS_11, g_bitmap);
 	set_bit(BITOPS_31, g_bitmap);
 	set_bit(BITOPS_88, g_bitmap);
+
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
+			pr_warn("get_count_order wrong for %x\n",
+				       order_comb[i][0]); }
+
+	for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+		if (order_comb_long[i][1] !=
+			       get_count_order_long(order_comb_long[i][0]))
+			pr_warn("get_count_order_long wrong for %lx\n",
+				       order_comb_long[i][0]); }
+
 	return 0;
 }
 
@@ -55,6 +91,6 @@ static void __exit test_bitops_unstartup(void)
 module_init(test_bitops_startup);
 module_exit(test_bitops_unstartup);
 
-MODULE_AUTHOR("Jesse Brandeburg <[email protected]>");
+MODULE_AUTHOR("Jesse Brandeburg <[email protected]>, Wei Yang <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Bit testing module");
Signature · 1 line
2.23.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 1 line · Wei Yang

Add some test for get_count_order/long in test_bitops.c.

Thanks! LGTM,

Note, we can have as many MODULE_AUTHOR() lines as we want.

Quoted 108 lines

---
v2: merge the test into test_bitops.c

---
 lib/Kconfig.debug | 10 +++++-----
 lib/test_bitops.c | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)
lib/Kconfig.debug +5 -5
index f80d5609798f..512111a72e34 100644
@@ -1987,15 +1987,15 @@ config TEST_LKM
 	  If unsure, say N.
 
 config TEST_BITOPS
-	tristate "Test module for compilation of clear_bit/set_bit operations"
+	tristate "Test module for compilation of bitops operations"
 	depends on m
 	help
 	  This builds the "test_bitops" module that is much like the
 	  TEST_LKM module except that it does a basic exercise of the
-	  clear_bit and set_bit macros to make sure there are no compiler
-	  warnings from C=1 sparse checker or -Wextra compilations. It has
-	  no dependencies and doesn't run or load unless explicitly requested
-	  by name.  for example: modprobe test_bitops.
+	  set/clear_bit macros and get_count_order/long to make sure there are
+	  no compiler warnings from C=1 sparse checker or -Wextra
+	  compilations. It has no dependencies and doesn't run or load unless
+	  explicitly requested by name.  for example: modprobe test_bitops.
 
 	  If unsure, say N.
 
lib/test_bitops.c +38 -2
index fd50b3ae4a14..702d5973a5b6 100644
@@ -9,7 +9,11 @@
 #include <linux/module.h>
 #include <linux/printk.h>
 
-/* a tiny module only meant to test set/clear_bit */
+/* a tiny module only meant to test
+ *
+ *   set/clear_bit
+ *   get_count_order/long
+ */
 
 /* use an enum because thats the most common BITMAP usage */
 enum bitops_fun {
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+	{0x00000003,  2},
+	{0x00000004,  2},
+	{0x00001fff, 13},
+	{0x00002000, 13},
+	{0x50000000, 31},
+	{0x80000000, 31},
+	{0x80003000, 32},
+};
+
+unsigned long order_comb_long[][2] = {
+	{0x0000000300000000, 34},
+	{0x0000000400000000, 34},
+	{0x00001fff00000000, 45},
+	{0x0000200000000000, 45},
+	{0x5000000000000000, 63},
+	{0x8000000000000000, 63},
+	{0x8000300000000000, 64},
+};
+
 static int __init test_bitops_startup(void)
 {
 	pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
 	set_bit(BITOPS_11, g_bitmap);
 	set_bit(BITOPS_31, g_bitmap);
 	set_bit(BITOPS_88, g_bitmap);
+
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
+			pr_warn("get_count_order wrong for %x\n",
+				       order_comb[i][0]); }
+
+	for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+		if (order_comb_long[i][1] !=
+			       get_count_order_long(order_comb_long[i][0]))
+			pr_warn("get_count_order_long wrong for %lx\n",
+				       order_comb_long[i][0]); }
+
 	return 0;
 }
 
@@ -55,6 +91,6 @@ static void __exit test_bitops_unstartup(void)
 module_init(test_bitops_startup);
 module_exit(test_bitops_unstartup);
 
-MODULE_AUTHOR("Jesse Brandeburg <[email protected]>");
+MODULE_AUTHOR("Jesse Brandeburg <[email protected]>, Wei Yang <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Bit testing module");
Signature · 1 line
2.23.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

Add some test for get_count_order/long in test_bitops.c.

Thanks! LGTM,

Note, we can have as many MODULE_AUTHOR() lines as we want.

Ah, got it.

Quoted 113 lines
Quoted 108 lines

---
v2: merge the test into test_bitops.c

---
 lib/Kconfig.debug | 10 +++++-----
 lib/test_bitops.c | 40 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)
lib/Kconfig.debug +5 -5
index f80d5609798f..512111a72e34 100644
@@ -1987,15 +1987,15 @@ config TEST_LKM
 	  If unsure, say N.
 
 config TEST_BITOPS
-	tristate "Test module for compilation of clear_bit/set_bit operations"
+	tristate "Test module for compilation of bitops operations"
 	depends on m
 	help
 	  This builds the "test_bitops" module that is much like the
 	  TEST_LKM module except that it does a basic exercise of the
-	  clear_bit and set_bit macros to make sure there are no compiler
-	  warnings from C=1 sparse checker or -Wextra compilations. It has
-	  no dependencies and doesn't run or load unless explicitly requested
-	  by name.  for example: modprobe test_bitops.
+	  set/clear_bit macros and get_count_order/long to make sure there are
+	  no compiler warnings from C=1 sparse checker or -Wextra
+	  compilations. It has no dependencies and doesn't run or load unless
+	  explicitly requested by name.  for example: modprobe test_bitops.
 
 	  If unsure, say N.
 
lib/test_bitops.c +38 -2
index fd50b3ae4a14..702d5973a5b6 100644
@@ -9,7 +9,11 @@
 #include <linux/module.h>
 #include <linux/printk.h>
 
-/* a tiny module only meant to test set/clear_bit */
+/* a tiny module only meant to test
+ *
+ *   set/clear_bit
+ *   get_count_order/long
+ */
 
 /* use an enum because thats the most common BITMAP usage */
 enum bitops_fun {
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+	{0x00000003,  2},
+	{0x00000004,  2},
+	{0x00001fff, 13},
+	{0x00002000, 13},
+	{0x50000000, 31},
+	{0x80000000, 31},
+	{0x80003000, 32},
+};
+
+unsigned long order_comb_long[][2] = {
+	{0x0000000300000000, 34},
+	{0x0000000400000000, 34},
+	{0x00001fff00000000, 45},
+	{0x0000200000000000, 45},
+	{0x5000000000000000, 63},
+	{0x8000000000000000, 63},
+	{0x8000300000000000, 64},
+};
+
 static int __init test_bitops_startup(void)
 {
 	pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
 	set_bit(BITOPS_11, g_bitmap);
 	set_bit(BITOPS_31, g_bitmap);
 	set_bit(BITOPS_88, g_bitmap);
+
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
+			pr_warn("get_count_order wrong for %x\n",
+				       order_comb[i][0]); }
+
+	for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+		if (order_comb_long[i][1] !=
+			       get_count_order_long(order_comb_long[i][0]))
+			pr_warn("get_count_order_long wrong for %lx\n",
+				       order_comb_long[i][0]); }
+
 	return 0;
 }
 
@@ -55,6 +91,6 @@ static void __exit test_bitops_unstartup(void)
 module_init(test_bitops_startup);
 module_exit(test_bitops_unstartup);
 
-MODULE_AUTHOR("Jesse Brandeburg <[email protected]>");
+MODULE_AUTHOR("Jesse Brandeburg <[email protected]>, Wei Yang <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Bit testing module");
Signature · 1 line
2.23.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw
In reply to Wei Yang

Hi Wei,

Quoted 3 lines · Wei Yang

Add some test for get_count_order/long in test_bitops.c.

Thanks for your patch, which is now commit 7851d6639caeea40 ("lib:
test get_count_order/long in test_bitops.c") in linux-next.

Quoted 16 lines
lib/test_bitops.c +9 -0
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+       {0x00000003,  2},
+       {0x00000004,  2},
+       {0x00001fff, 13},
+       {0x00002000, 13},
+       {0x50000000, 31},
+       {0x80000000, 31},
+       {0x80003000, 32},
+};

lib/test_bitops.c enum bitops_fun { · line 49

Quoted 10 lines
lib/test_bitops.c +10 -0
+
+unsigned long order_comb_long[][2] = {
+       {0x0000000300000000, 34},
+       {0x0000000400000000, 34},
+       {0x00001fff00000000, 45},
+       {0x0000200000000000, 45},
+       {0x5000000000000000, 63},
+       {0x8000000000000000, 63},
+       {0x8000300000000000, 64},
+};

[email protected] reported for m68k-allmodconfig:

lib/test_bitops.c:42:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '12884901888' to '0' [-Werror=overflow]
lib/test_bitops.c:43:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '17179869184' to '0' [-Werror=overflow]
lib/test_bitops.c:44:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35180077121536' to '0' [-Werror=overflow]
lib/test_bitops.c:45:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35184372088832' to '0' [-Werror=overflow]
lib/test_bitops.c:46:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '5764607523034234880' to '0' [-Werror=overflow]
lib/test_bitops.c:47:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223372036854775808' to '0' [-Werror=overflow]
lib/test_bitops.c:48:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223424813412909056' to '0' [-Werror=overflow]

Indeed, on 32-bit, none of these values fit in unsigned long.

Quoted 10 lines
lib/test_bitops.c +3 -0
 static int __init test_bitops_startup(void)
 {
        pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
        set_bit(BITOPS_11, g_bitmap);
        set_bit(BITOPS_31, g_bitmap);
        set_bit(BITOPS_88, g_bitmap);
+
+       for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+               if (order_comb[i][1] != get_count_order(order_comb[i][0]))

lib/test_bitops.c static int __init test_bitops_startup(void) · line 71

Quoted 10 lines
lib/test_bitops.c +9 -0
+                       pr_warn("get_count_order wrong for %x\n",
+                                      order_comb[i][0]); }
+
+       for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+               if (order_comb_long[i][1] !=
+                              get_count_order_long(order_comb_long[i][0]))
+                       pr_warn("get_count_order_long wrong for %lx\n",
+                                      order_comb_long[i][0]); }
+
        return 0;

BTW, shouldn't get_count_order_long() be tested with the values in order_comb[], too?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#4 lore raw
Quoted 61 lines · Geert Uytterhoeven

Hi Wei,

Quoted 3 lines · Wei Yang

Add some test for get_count_order/long in test_bitops.c.

Thanks for your patch, which is now commit 7851d6639caeea40 ("lib:
test get_count_order/long in test_bitops.c") in linux-next.

Quoted 16 lines
lib/test_bitops.c +9 -0
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+       {0x00000003,  2},
+       {0x00000004,  2},
+       {0x00001fff, 13},
+       {0x00002000, 13},
+       {0x50000000, 31},
+       {0x80000000, 31},
+       {0x80003000, 32},
+};

lib/test_bitops.c enum bitops_fun { · line 49

Quoted 10 lines
lib/test_bitops.c +10 -0
+
+unsigned long order_comb_long[][2] = {
+       {0x0000000300000000, 34},
+       {0x0000000400000000, 34},
+       {0x00001fff00000000, 45},
+       {0x0000200000000000, 45},
+       {0x5000000000000000, 63},
+       {0x8000000000000000, 63},
+       {0x8000300000000000, 64},
+};

[email protected] reported for m68k-allmodconfig:

lib/test_bitops.c:42:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '12884901888' to '0' [-Werror=overflow]
lib/test_bitops.c:43:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '17179869184' to '0' [-Werror=overflow]
lib/test_bitops.c:44:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35180077121536' to '0' [-Werror=overflow]
lib/test_bitops.c:45:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35184372088832' to '0' [-Werror=overflow]
lib/test_bitops.c:46:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '5764607523034234880' to '0' [-Werror=overflow]
lib/test_bitops.c:47:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223372036854775808' to '0' [-Werror=overflow]
lib/test_bitops.c:48:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223424813412909056' to '0' [-Werror=overflow]

Quoted 2 lines

Indeed, on 32-bit, none of these values fit in unsigned long.

Hmm... I didn't test on 32bit platform. Sorry for that.

Quoted 15 lines
Quoted 15 lines
lib/test_bitops.c +8 -0
 static int __init test_bitops_startup(void)
 {
        pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
        set_bit(BITOPS_11, g_bitmap);
        set_bit(BITOPS_31, g_bitmap);
        set_bit(BITOPS_88, g_bitmap);
+
+       for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+               if (order_comb[i][1] != get_count_order(order_comb[i][0]))
+                       pr_warn("get_count_order wrong for %x\n",
+                                      order_comb[i][0]); }
+
+       for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+               if (order_comb_long[i][1] !=
Quoted 9 lines

lib/test_bitops.c static int __init test_bitops_startup(void) · line 71

Quoted 5 lines
lib/test_bitops.c +4 -0
+                              get_count_order_long(order_comb_long[i][0]))
+                       pr_warn("get_count_order_long wrong for %lx\n",
+                                      order_comb_long[i][0]); }
+
        return 0;

BTW, shouldn't get_count_order_long() be tested with the values in order_comb[], too?

You mean

       {0x0000000000000003,  2},
       {0x0000000000000004,  2},
       {0x0000000000001fff, 13},
       {0x0000000000002000, 13},
       {0x0000000050000000, 31},
       {0x0000000080000000, 31},
       {0x0000000080003000, 32},
Quoted 10 lines

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                               -- Linus Torvalds
Signature · 2 lines
Wei Yang
Help you, Help me
#5 lore raw

Hi Wei,

Quoted 92 lines · Wei Yang
Quoted 59 lines · Geert Uytterhoeven
Quoted 3 lines · Wei Yang

Add some test for get_count_order/long in test_bitops.c.

Thanks for your patch, which is now commit 7851d6639caeea40 ("lib:
test get_count_order/long in test_bitops.c") in linux-next.

Quoted 16 lines
lib/test_bitops.c +9 -0
@@ -24,6 +28,26 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
+unsigned int order_comb[][2] = {
+       {0x00000003,  2},
+       {0x00000004,  2},
+       {0x00001fff, 13},
+       {0x00002000, 13},
+       {0x50000000, 31},
+       {0x80000000, 31},
+       {0x80003000, 32},
+};

lib/test_bitops.c enum bitops_fun { · line 49

Quoted 10 lines
lib/test_bitops.c +10 -0
+
+unsigned long order_comb_long[][2] = {
+       {0x0000000300000000, 34},
+       {0x0000000400000000, 34},
+       {0x00001fff00000000, 45},
+       {0x0000200000000000, 45},
+       {0x5000000000000000, 63},
+       {0x8000000000000000, 63},
+       {0x8000300000000000, 64},
+};

[email protected] reported for m68k-allmodconfig:

lib/test_bitops.c:42:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '12884901888' to '0' [-Werror=overflow]
lib/test_bitops.c:43:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '17179869184' to '0' [-Werror=overflow]
lib/test_bitops.c:44:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35180077121536' to '0' [-Werror=overflow]
lib/test_bitops.c:45:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '35184372088832' to '0' [-Werror=overflow]
lib/test_bitops.c:46:3: error: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '5764607523034234880' to '0' [-Werror=overflow]
lib/test_bitops.c:47:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223372036854775808' to '0' [-Werror=overflow]
lib/test_bitops.c:48:3: error: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '9223424813412909056' to '0' [-Werror=overflow]

Quoted 2 lines

Indeed, on 32-bit, none of these values fit in unsigned long.

Hmm... I didn't test on 32bit platform. Sorry for that.

Quoted 15 lines
Quoted 15 lines
lib/test_bitops.c +8 -0
 static int __init test_bitops_startup(void)
 {
        pr_warn("Loaded test module\n");
@@ -32,6 +56,18 @@ static int __init test_bitops_startup(void)
        set_bit(BITOPS_11, g_bitmap);
        set_bit(BITOPS_31, g_bitmap);
        set_bit(BITOPS_88, g_bitmap);
+
+       for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+               if (order_comb[i][1] != get_count_order(order_comb[i][0]))
+                       pr_warn("get_count_order wrong for %x\n",
+                                      order_comb[i][0]); }
+
+       for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+               if (order_comb_long[i][1] !=
Quoted 9 lines

lib/test_bitops.c static int __init test_bitops_startup(void) · line 71

Quoted 5 lines
lib/test_bitops.c +4 -0
+                              get_count_order_long(order_comb_long[i][0]))
+                       pr_warn("get_count_order_long wrong for %lx\n",
+                                      order_comb_long[i][0]); }
+
        return 0;

BTW, shouldn't get_count_order_long() be tested with the values in order_comb[], too?

You mean

Quoted 7 lines
       {0x0000000000000003,  2},
       {0x0000000000000004,  2},
       {0x0000000000001fff, 13},
       {0x0000000000002000, 13},
       {0x0000000050000000, 31},
       {0x0000000080000000, 31},
       {0x0000000080003000, 32},

Yes, those values. And those should work with get_count_order_long() on both 32-bit and 64-bit.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#6 lore raw
Quoted 3 lines · Geert Uytterhoeven

Hi Wei,

On Thu, Jun 4, 2020 at 2:28 PM Wei Yang <[email protected]> wrote:

[...]

Quoted 11 lines
Quoted 10 lines

You mean

       {0x0000000000000003,  2},
       {0x0000000000000004,  2},
       {0x0000000000001fff, 13},
       {0x0000000000002000, 13},
       {0x0000000050000000, 31},
       {0x0000000080000000, 31},
       {0x0000000080003000, 32},
Quoted 2 lines

Yes, those values. And those should work with get_count_order_long() on both 32-bit and 64-bit.

Hi, Geert

To be frank, I am afraid I lack some of the skill to achieve this. Maybe you could give some guide.

get_count_order_long() takes one parameter, which is of type unsigned long. This one has different size on 32bit and 64bit platform. On 32bit platform, those value would be truncated.

Would you mind giving me a hint on this?

What we may achieve is like the implementation of fls_long(). This one check the size of unsigned long on running, and choose different function. We could use ifdef to check the size of unsigned long and use different data to feed get_count_order_long(). But I don't find a way to feed get_count_order_long() with 64bit data on 32bit platform.

Quoted 11 lines

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                               -- Linus Torvalds
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#7 lore raw
Quoted 16 lines · On Fri, 5 Jun 2020 23:06:10 +0000 Wei Yang <[email protected]> wrote:
Quoted 3 lines · Geert Uytterhoeven

Hi Wei,

On Thu, Jun 4, 2020 at 2:28 PM Wei Yang <[email protected]> wrote:

[...]

Quoted 11 lines
Quoted 10 lines

You mean

       {0x0000000000000003,  2},
       {0x0000000000000004,  2},
       {0x0000000000001fff, 13},
       {0x0000000000002000, 13},
       {0x0000000050000000, 31},
       {0x0000000080000000, 31},
       {0x0000000080003000, 32},
Quoted 2 lines
Quoted 2 lines

Yes, those values. And those should work with get_count_order_long() on both 32-bit and 64-bit.

Geert meant "no, the values in order_comb[]" :)

We have a table of numbers in order_comb[] so we may as well feed them into get_count_order_long() (as well as get_count_order()) just for a bit more testing.

So how about the below? order_comb_long[] just can't be used on 32-bit machines because their longs are 32-bit. If we had a get_count_order_u64() then we could use it.

I haven't runtime tested this - could you please do so?

static unsigned int order_comb[][2] = {
	{0x00000003,  2},
	{0x00000004,  2},
	{0x00001fff, 13},
	{0x00002000, 13},
	{0x50000000, 31},
	{0x80000000, 31},
	{0x80003000, 32},
};

#ifdef CONFIG_64BIT

static unsigned long order_comb_long[][2] = {
	{0x0000000300000000, 34},
	{0x0000000400000000, 34},
	{0x00001fff00000000, 45},
	{0x0000200000000000, 45},
	{0x5000000000000000, 63},
	{0x8000000000000000, 63},
	{0x8000300000000000, 64},
};

#endif

static int __init test_bitops_startup(void)

{
	int i;

	pr_warn("Loaded test module\n");
	set_bit(BITOPS_4, g_bitmap);
	set_bit(BITOPS_7, g_bitmap);
	set_bit(BITOPS_11, g_bitmap);
	set_bit(BITOPS_31, g_bitmap);
	set_bit(BITOPS_88, g_bitmap);

	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
			pr_warn("get_count_order wrong for %x\n",
				       order_comb[i][0]);
	}

	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
			pr_warn("get_count_order_long wrong for %x\n",
				       order_comb[i][0]);
	}
#ifdef CONFIG_64BIT
	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb_long[i][1] !=
			       get_count_order_long(order_comb_long[i][0]))
			pr_warn("get_count_order_long wrong for %lx\n",
				       order_comb_long[i][0]);
	}
#endif
	return 0;
}

From: Andrew Morton <[email protected]>
Subject: lib-test-get_count_order-long-in-test_bitopsc-fix

Cc Andy Shevchenko <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Wei Yang <[email protected]>

---

 lib/test_bitops.c |   23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
lib/test_bitops.c renamed from lib/test_bitops.c~lib-test-get_count_order-long-in-test_bitopsc-fix +17 -6
@@ -28,7 +28,7 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
-unsigned int order_comb[][2] = {
+static unsigned int order_comb[][2] = {
 	{0x00000003,  2},
 	{0x00000004,  2},
 	{0x00001fff, 13},
@@ -38,7 +38,8 @@ unsigned int order_comb[][2] = {
 	{0x80003000, 32},
 };
 
-unsigned long order_comb_long[][2] = {
+#ifdef CONFIG_64BIT
+static unsigned long order_comb_long[][2] = {
 	{0x0000000300000000, 34},
 	{0x0000000400000000, 34},
 	{0x00001fff00000000, 45},
@@ -47,6 +48,7 @@ unsigned long order_comb_long[][2] = {
 	{0x8000000000000000, 63},
 	{0x8000300000000000, 64},
 };
+#endif
 
 static int __init test_bitops_startup(void)
 {
@@ -62,14 +64,23 @@ static int __init test_bitops_startup(vo
 	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
 		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
 			pr_warn("get_count_order wrong for %x\n",
-				       order_comb[i][0]); }
+				       order_comb[i][0]);
+	}
 
-	for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+		if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
+			pr_warn("get_count_order_long wrong for %x\n",
+				       order_comb[i][0]);
+	}
+
+#ifdef CONFIG_64BIT
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
 		if (order_comb_long[i][1] !=
 			       get_count_order_long(order_comb_long[i][0]))
 			pr_warn("get_count_order_long wrong for %lx\n",
-				       order_comb_long[i][0]); }
-
+				       order_comb_long[i][0]);
+	}
+#endif
 	return 0;
 }
 

_

author
#8 lore raw
Quoted 139 lines · Andrew Morton
Quoted 16 lines · On Fri, 5 Jun 2020 23:06:10 +0000 Wei Yang <[email protected]> wrote:
Quoted 3 lines · Geert Uytterhoeven

Hi Wei,

On Thu, Jun 4, 2020 at 2:28 PM Wei Yang <[email protected]> wrote:

[...]

Quoted 11 lines
Quoted 10 lines

You mean

       {0x0000000000000003,  2},
       {0x0000000000000004,  2},
       {0x0000000000001fff, 13},
       {0x0000000000002000, 13},
       {0x0000000050000000, 31},
       {0x0000000080000000, 31},
       {0x0000000080003000, 32},
Quoted 2 lines
Quoted 2 lines

Yes, those values. And those should work with get_count_order_long() on both 32-bit and 64-bit.

Geert meant "no, the values in order_comb[]" :)

We have a table of numbers in order_comb[] so we may as well feed them into get_count_order_long() (as well as get_count_order()) just for a bit more testing.

So how about the below? order_comb_long[] just can't be used on 32-bit machines because their longs are 32-bit. If we had a get_count_order_u64() then we could use it.

I haven't runtime tested this - could you please do so?

static unsigned int order_comb[][2] = {
	{0x00000003,  2},
	{0x00000004,  2},
	{0x00001fff, 13},
	{0x00002000, 13},
	{0x50000000, 31},
	{0x80000000, 31},
	{0x80003000, 32},
};

#ifdef CONFIG_64BIT

static unsigned long order_comb_long[][2] = {
	{0x0000000300000000, 34},
	{0x0000000400000000, 34},
	{0x00001fff00000000, 45},
	{0x0000200000000000, 45},
	{0x5000000000000000, 63},
	{0x8000000000000000, 63},
	{0x8000300000000000, 64},
};

#endif

static int __init test_bitops_startup(void)

{
	int i;

	pr_warn("Loaded test module\n");
	set_bit(BITOPS_4, g_bitmap);
	set_bit(BITOPS_7, g_bitmap);
	set_bit(BITOPS_11, g_bitmap);
	set_bit(BITOPS_31, g_bitmap);
	set_bit(BITOPS_88, g_bitmap);

	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
			pr_warn("get_count_order wrong for %x\n",
				       order_comb[i][0]);
	}

	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
			pr_warn("get_count_order_long wrong for %x\n",
				       order_comb[i][0]);
	}
#ifdef CONFIG_64BIT
	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
		if (order_comb_long[i][1] !=
			       get_count_order_long(order_comb_long[i][0]))
			pr_warn("get_count_order_long wrong for %lx\n",
				       order_comb_long[i][0]);
	}
#endif
	return 0;
}

From: Andrew Morton <[email protected]>
Subject: lib-test-get_count_order-long-in-test_bitopsc-fix

Cc Andy Shevchenko <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Wei Yang <[email protected]>

---

lib/test_bitops.c | 23 +++++++++++++++++------

1 file changed, 17 insertions(+), 6 deletions(-)
lib/test_bitops.c renamed from lib/test_bitops.c~lib-test-get_count_order-long-in-test_bitopsc-fix +6 -3
@@ -28,7 +28,7 @@ enum bitops_fun {
 
 static DECLARE_BITMAP(g_bitmap, BITOPS_LENGTH);
 
-unsigned int order_comb[][2] = {
+static unsigned int order_comb[][2] = {
 	{0x00000003,  2},
 	{0x00000004,  2},
 	{0x00001fff, 13},
@@ -38,7 +38,8 @@ unsigned int order_comb[][2] = {
 	{0x80003000, 32},
 };
 
-unsigned long order_comb_long[][2] = {
+#ifdef CONFIG_64BIT
+static unsigned long order_comb_long[][2] = {
 	{0x0000000300000000, 34},
 	{0x0000000400000000, 34},
 	{0x00001fff00000000, 45},
@@ -47,6 +48,7 @@ unsigned long order_comb_long[][2] = {
 	{0x8000000000000000, 63},
 	{0x8000300000000000, 64},
 };
+#endif
 
 static int __init test_bitops_startup(void)
 {
@@ -62,14 +64,23 @@ static int __init test_bitops_startup(vo
 	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
 		if (order_comb[i][1] != get_count_order(order_comb[i][0]))
 			pr_warn("get_count_order wrong for %x\n",
-				       order_comb[i][0]); }
+				       order_comb[i][0]);
+	}

lib/test_bitops.c static int __init test_bitops_startup(vo · line 77

Quoted 10 lines
lib/test_bitops.c renamed from lib/test_bitops.c~lib-test-get_count_order-long-in-test_bitopsc-fix +8 -1
 
-	for (i = 0; i < ARRAY_SIZE(order_comb_long); i++) {
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
+		if (order_comb[i][1] != get_count_order_long(order_comb[i][0]))
+			pr_warn("get_count_order_long wrong for %x\n",
+				       order_comb[i][0]);
+	}
+
+#ifdef CONFIG_64BIT
+	for (i = 0; i < ARRAY_SIZE(order_comb); i++) {
                                   ^

I am afraid this one should be order_comb_long?

The test on 64bit machine pass. Since I don't have a 32bit machine by hand, Geert, would you mind have a try on 32bit machine?

Quoted 12 lines
lib/test_bitops.c renamed from lib/test_bitops.c~lib-test-get_count_order-long-in-test_bitopsc-fix +3 -2
 		if (order_comb_long[i][1] !=
 			       get_count_order_long(order_comb_long[i][0]))
 			pr_warn("get_count_order_long wrong for %lx\n",
-				       order_comb_long[i][0]); }
-
+				       order_comb_long[i][0]);
+	}
+#endif
 	return 0;
 }
 

_

Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Out of curiosity what that machine is?

Quoted 1 line

Geert, would you mind have a try on 32bit machine?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#10 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Out of curiosity what that machine is?

It is a Intel Xeon Gold CPU.

Quoted 6 lines
Quoted 1 line

Geert, would you mind have a try on 32bit machine?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Wei Yang
Help you, Help me
#11 lore raw
Quoted 4 lines · Wei Yang
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

Quoted 8 lines
Quoted 6 lines

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Out of curiosity what that machine is?

It is a Intel Xeon Gold CPU.

I suppose it's x86 (and not ia64).
In this case you can always build an i386 configuration and test on a 32-bit "machine".

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#12 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Wei Yang
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Out of curiosity what that machine is?

It is a Intel Xeon Gold CPU.

I suppose it's x86 (and not ia64).
In this case you can always build an i386 configuration and test on a 32-bit "machine".

Yes, you are right. While last time I tried to run a 32bit guest, it took me a lot of time to setup. If my understanding is correct, to run on a 32bit machine, we not only need the kernel but a whole 32bit system. This means I need to re-install a 32bit system. And I found many distro doesn't support 32bit system any more.

Do you have a better way to setup the environment?

Quoted 3 lines
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Wei Yang
Help you, Help me
#13 lore raw
Quoted 20 lines · Wei Yang
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Wei Yang
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Out of curiosity what that machine is?

It is a Intel Xeon Gold CPU.

I suppose it's x86 (and not ia64).
In this case you can always build an i386 configuration and test on a 32-bit "machine".

Quoted 7 lines

Yes, you are right. While last time I tried to run a 32bit guest, it took me a lot of time to setup. If my understanding is correct, to run on a 32bit machine, we not only need the kernel but a whole 32bit system. This means I need to re-install a 32bit system. And I found many distro doesn't support 32bit system any more.

Do you have a better way to setup the environment?

Yes, BuildRoot is your friend. I have a branch [1] to make it suitable to create bootable images for x86 machines. There is a quick instructions what it does provide.

[1]: https://github.com/andy-shev/buildroot/tree/intel/board/intel/common

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#14 lore raw
Quoted 27 lines · Andy Shevchenko
Quoted 26 lines · Wei Yang
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Wei Yang
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Wei Yang

On Fri, Jun 05, 2020 at 05:16:29PM -0700, Andrew Morton wrote:

...

Quoted 1 line

The test on 64bit machine pass. Since I don't have a 32bit machine by hand,

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

Out of curiosity what that machine is?

It is a Intel Xeon Gold CPU.

I suppose it's x86 (and not ia64).
In this case you can always build an i386 configuration and test on a 32-bit "machine".

Yes, you are right. While last time I tried to run a 32bit guest, it took me a lot of time to setup. If my understanding is correct, to run on a 32bit machine, we not only need the kernel but a whole 32bit system. This means I need to re-install a 32bit system. And I found many distro doesn't support 32bit system any more.

Quoted 8 lines
Quoted 1 line

Do you have a better way to setup the environment?

Yes, BuildRoot is your friend. I have a branch [1] to make it suitable to create bootable images for x86 machines. There is a quick instructions what it does provide.

[1]: https://github.com/andy-shev/buildroot/tree/intel/board/intel/common

Many thanks for your instruction. I will take a look into this.

Quoted 3 lines
Signature · 2 lines
With Best Regards,
Andy Shevchenko
Signature · 2 lines
Wei Yang
Help you, Help me