diff mbox series

[v2,5/6] gpio: thunderx: Utilize for_each_set_clump macro

Message ID 9c5e25b982728467c5c681876d0e60e49dedb5fb.1587840670.git.syednwaris@gmail.com
State New
Headers show
Series Introduce the for_each_set_clump macro | expand

Commit Message

Syed Nayyar Waris April 25, 2020, 7:06 p.m. UTC
This patch reimplements the thunderx_gpio_set_multiple function in
drivers/gpio/gpio-thunderx.c to use the new for_each_set_clump macro.
Instead of looping for each bank in thunderx_gpio_set_multiple
function, now we can skip bank which is not set and save cycles.

Cc: Robert Richter <rrichter@marvell.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com>
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
---
Changes in v2:
 - No change.

 drivers/gpio/gpio-thunderx.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

kernel test robot April 27, 2020, 4:38 p.m. UTC | #1
Hi Syed,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on gpio/for-next]
[also build test ERROR on linus/master v5.7-rc3 next-20200424]
[cannot apply to xlnx/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200427-184103
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next
config: x86_64-randconfig-g001-20200427 (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   In file included from arch/x86/include/asm/bitops.h:383:0,
                    from include/linux/bitops.h:29,
                    from drivers/gpio/gpio-thunderx.c:9:
   drivers/gpio/gpio-thunderx.c: In function 'thunderx_gpio_set_multiple':
>> include/asm-generic/bitops/find.h:100:18: error: passing argument 1 of 'find_next_clump' from incompatible pointer type [-Werror=incompatible-pointer-types]
     find_next_clump((clump), (bits), (size), 0, (clump_size))
                     ^
>> include/linux/bitops.h:62:17: note: in expansion of macro 'find_first_clump'
     for ((start) = find_first_clump(&(clump), (bits), (size), (clump_size)); \
                    ^~~~~~~~~~~~~~~~
   drivers/gpio/gpio-thunderx.c:284:2: note: in expansion of macro 'for_each_set_clump'
     for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
     ^~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/find.h:94:22: note: expected 'long unsigned int *' but argument is of type 'u64 * {aka long long unsigned int *}'
    extern unsigned long find_next_clump(unsigned long *clump,
                         ^~~~~~~~~~~~~~~
   In file included from drivers/gpio/gpio-thunderx.c:9:0:
   include/linux/bitops.h:64:33: error: passing argument 1 of 'find_next_clump' from incompatible pointer type [-Werror=incompatible-pointer-types]
          (start) = find_next_clump(&(clump), (bits), (size), (start) + (clump_size), (clump_size)))
                                    ^
   drivers/gpio/gpio-thunderx.c:284:2: note: in expansion of macro 'for_each_set_clump'
     for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
     ^~~~~~~~~~~~~~~~~~
   In file included from arch/x86/include/asm/bitops.h:383:0,
                    from include/linux/bitops.h:29,
                    from drivers/gpio/gpio-thunderx.c:9:
   include/asm-generic/bitops/find.h:94:22: note: expected 'long unsigned int *' but argument is of type 'u64 * {aka long long unsigned int *}'
    extern unsigned long find_next_clump(unsigned long *clump,
                         ^~~~~~~~~~~~~~~
   cc1: some warnings being treated as errors

vim +/find_next_clump +100 include/asm-generic/bitops/find.h

708ff2a0097b02 Akinobu Mita      2010-09-29   82  
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   83  /**
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   84   * find_next_clump - find next clump with set bits in a memory region
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   85   * @clump: location to store copy of found clump
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   86   * @addr: address to base the search on
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   87   * @size: bitmap size in number of bits
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   88   * @offset: bit offset at which to start searching
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   89   * @clump_size: clump size in bits
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   90   *
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   91   * Returns the bit offset for the next set clump; the found clump value is
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   92   * copied to the location pointed by @clump. If no bits are set, returns @size.
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   93   */
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   94  extern unsigned long find_next_clump(unsigned long *clump,
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   95  				      const unsigned long *addr,
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   96  				      unsigned long size, unsigned long offset,
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   97  				      unsigned long clump_size);
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   98  
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26   99  #define find_first_clump(clump, bits, size, clump_size) \
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26 @100  	find_next_clump((clump), (bits), (size), 0, (clump_size))
c1b8ffb88d31d5 Syed Nayyar Waris 2020-04-26  101  

:::::: The code at line 100 was first introduced by commit
:::::: c1b8ffb88d31d5ed311afb9fec47eded4b9410c6 bitops: Introduce the the for_each_set_clump macro

:::::: TO: Syed Nayyar Waris <syednwaris@gmail.com>
:::::: CC: 0day robot <lkp@intel.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot April 27, 2020, 6:27 p.m. UTC | #2
Hi Syed,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on gpio/for-next]
[also build test ERROR on linus/master asm-generic/master v5.7-rc3 next-20200423]
[cannot apply to xlnx/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200427-184103
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next
config: s390-allyesconfig (attached as .config)
compiler: s390-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day GCC_VERSION=9.3.0 make.cross ARCH=s390 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All error/warnings (new ones prefixed by >>):

   In file included from arch/s390/include/asm/bitops.h:425,
                    from include/linux/bitops.h:29,
                    from drivers/gpio/gpio-thunderx.c:9:
   drivers/gpio/gpio-thunderx.c: In function 'thunderx_gpio_set_multiple':
>> include/linux/bitops.h:62:34: error: passing argument 1 of 'find_next_clump' from incompatible pointer type [-Werror=incompatible-pointer-types]
      62 |  for ((start) = find_first_clump(&(clump), (bits), (size), (clump_size)); \
   include/asm-generic/bitops/find.h:100:19: note: in definition of macro 'find_first_clump'
     100 |  find_next_clump((clump), (bits), (size), 0, (clump_size))
         |                   ^~~~~
>> drivers/gpio/gpio-thunderx.c:284:2: note: in expansion of macro 'for_each_set_clump'
     284 |  for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
         |  ^~~~~~~~~~~~~~~~~~
   include/asm-generic/bitops/find.h:94:53: note: expected 'long unsigned int *' but argument is of type 'u64 *' {aka 'long long unsigned int *'}
      94 | extern unsigned long find_next_clump(unsigned long *clump,
         |                                      ~~~~~~~~~~~~~~~^~~~~
   In file included from drivers/gpio/gpio-thunderx.c:9:
   include/linux/bitops.h:64:33: error: passing argument 1 of 'find_next_clump' from incompatible pointer type [-Werror=incompatible-pointer-types]
      64 |       (start) = find_next_clump(&(clump), (bits), (size), (start) + (clump_size), (clump_size)))
         |                                 ^~~~~~~~
         |                                 |
         |                                 u64 * {aka long long unsigned int *}
>> drivers/gpio/gpio-thunderx.c:284:2: note: in expansion of macro 'for_each_set_clump'
     284 |  for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
         |  ^~~~~~~~~~~~~~~~~~
   In file included from arch/s390/include/asm/bitops.h:425,
                    from include/linux/bitops.h:29,
                    from drivers/gpio/gpio-thunderx.c:9:
   include/asm-generic/bitops/find.h:94:53: note: expected 'long unsigned int *' but argument is of type 'u64 *' {aka 'long long unsigned int *'}
      94 | extern unsigned long find_next_clump(unsigned long *clump,
         |                                      ~~~~~~~~~~~~~~~^~~~~
   cc1: some warnings being treated as errors

vim +/for_each_set_clump +284 drivers/gpio/gpio-thunderx.c

   272	
   273	static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
   274					       unsigned long *mask,
   275					       unsigned long *bits)
   276	{
   277		int bank;
   278		u64 set_bits, clear_bits, gpio_mask;
   279		const unsigned long bank_size = 64;
   280		unsigned long offset;
   281	
   282		struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
   283	
 > 284		for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
   285			bank = offset / bank_size;
   286			set_bits = bits[bank] & gpio_mask;
   287			clear_bits = ~bits[bank] & gpio_mask;
   288			writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);
   289			writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);
   290		}
   291	}
   292	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot April 28, 2020, 1:41 a.m. UTC | #3
Hi Syed,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on gpio/for-next]
[also build test WARNING on linus/master asm-generic/master v5.7-rc3 next-20200424]
[cannot apply to xlnx/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200427-184103
base:   https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git for-next
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.1-191-gc51a0382-dirty
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)

>> drivers/gpio/gpio-thunderx.c:284:9: sparse: sparse: incorrect type in argument 1 (different type sizes) @@    expected unsigned long *clump @@    got unsigunsigned long *clump @@
>> drivers/gpio/gpio-thunderx.c:284:9: sparse:    expected unsigned long *clump
>> drivers/gpio/gpio-thunderx.c:284:9: sparse:    got unsigned long long *
>> drivers/gpio/gpio-thunderx.c:284:9: sparse: sparse: incorrect type in argument 1 (different type sizes) @@    expected unsigned long *clump @@    got unsigunsigned long *clump @@
>> drivers/gpio/gpio-thunderx.c:284:9: sparse:    expected unsigned long *clump
>> drivers/gpio/gpio-thunderx.c:284:9: sparse:    got unsigned long long *

vim +284 drivers/gpio/gpio-thunderx.c

   272	
   273	static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
   274					       unsigned long *mask,
   275					       unsigned long *bits)
   276	{
   277		int bank;
   278		u64 set_bits, clear_bits, gpio_mask;
   279		const unsigned long bank_size = 64;
   280		unsigned long offset;
   281	
   282		struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
   283	
 > 284		for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
   285			bank = offset / bank_size;
   286			set_bits = bits[bank] & gpio_mask;
   287			clear_bits = ~bits[bank] & gpio_mask;
   288			writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);
   289			writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);
   290		}
   291	}
   292	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c
index 9f66dea..74aea25 100644
--- a/drivers/gpio/gpio-thunderx.c
+++ b/drivers/gpio/gpio-thunderx.c
@@ -275,12 +275,16 @@  static void thunderx_gpio_set_multiple(struct gpio_chip *chip,
 				       unsigned long *bits)
 {
 	int bank;
-	u64 set_bits, clear_bits;
+	u64 set_bits, clear_bits, gpio_mask;
+	const unsigned long bank_size = 64;
+	unsigned long offset;
+
 	struct thunderx_gpio *txgpio = gpiochip_get_data(chip);
 
-	for (bank = 0; bank <= chip->ngpio / 64; bank++) {
-		set_bits = bits[bank] & mask[bank];
-		clear_bits = ~bits[bank] & mask[bank];
+	for_each_set_clump(offset, gpio_mask, mask, chip->ngpio, bank_size) {
+		bank = offset / bank_size;
+		set_bits = bits[bank] & gpio_mask;
+		clear_bits = ~bits[bank] & gpio_mask;
 		writeq(set_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_SET);
 		writeq(clear_bits, txgpio->register_base + (bank * GPIO_2ND_BANK) + GPIO_TX_CLR);
 	}