* [PATCH v8 0/4] Introduce the for_each_set_clump macro @ 2020-06-15 12:50 Syed Nayyar Waris 2020-06-15 12:53 ` [PATCH v8 3/4] gpio: thunderx: Utilize " Syed Nayyar Waris 2020-06-15 12:54 ` [PATCH v8 4/4] gpio: xilinx: " Syed Nayyar Waris 0 siblings, 2 replies; 10+ messages in thread From: Syed Nayyar Waris @ 2020-06-15 12:50 UTC (permalink / raw) To: linus.walleij, akpm Cc: andriy.shevchenko, vilhelm.gray, michal.simek, arnd, rrichter, linus.walleij, bgolaszewski, yamada.masahiro, rui.zhang, daniel.lezcano, amit.kucheria, linux-arch, linux-gpio, linux-kernel, linux-arm-kernel, linux-pm Hello Linus, Since this patchset primarily affects GPIO drivers, would you like to pick it up through your GPIO tree? This patchset introduces a new generic version of for_each_set_clump. The previous version of for_each_set_clump8 used a fixed size 8-bit clump, but the new generic version can work with clump of any size but less than or equal to BITS_PER_LONG. The patchset utilizes the new macro in several GPIO drivers. The earlier 8-bit for_each_set_clump8 facilitated a for-loop syntax that iterates over a memory region entire groups of set bits at a time. For example, suppose you would like to iterate over a 32-bit integer 8 bits at a time, skipping over 8-bit groups with no set bit, where XXXXXXXX represents the current 8-bit group: Example: 10111110 00000000 11111111 00110011 First loop: 10111110 00000000 11111111 XXXXXXXX Second loop: 10111110 00000000 XXXXXXXX 00110011 Third loop: XXXXXXXX 00000000 11111111 00110011 Each iteration of the loop returns the next 8-bit group that has at least one set bit. But with the new for_each_set_clump the clump size can be different from 8 bits. Moreover, the clump can be split at word boundary in situations where word size is not multiple of clump size. Following are examples showing the working of new macro for clump sizes of 24 bits and 6 bits. Example 1: clump size: 24 bits, Number of clumps (or ports): 10 bitmap stores the bit information from where successive clumps are retrieved. /* bitmap memory region */ 0x00aa0000ff000000; /* Most significant bits */ 0xaaaaaa0000ff0000; 0x000000aa000000aa; 0xbbbbabcdeffedcba; /* Least significant bits */ Different iterations of for_each_set_clump:- 'offset' is the bit position and 'clump' is the 24 bit clump from the above bitmap. Iteration first: offset: 0 clump: 0xfedcba Iteration second: offset: 24 clump: 0xabcdef Iteration third: offset: 48 clump: 0xaabbbb Iteration fourth: offset: 96 clump: 0xaa Iteration fifth: offset: 144 clump: 0xff Iteration sixth: offset: 168 clump: 0xaaaaaa Iteration seventh: offset: 216 clump: 0xff Loop breaks because in the end the remaining bits (0x00aa) size was less than clump size of 24 bits. In above example it can be seen that in iteration third, the 24 bit clump that was retrieved was split between bitmap[0] and bitmap[1]. This example also shows that 24 bit zeroes if present in between, were skipped (preserving the previous for_each_set_macro8 behaviour). Example 2: clump size = 6 bits, Number of clumps (or ports) = 3. /* bitmap memory region */ 0x00aa0000ff000000; /* Most significant bits */ 0xaaaaaa0000ff0000; 0x0f00000000000000; 0x0000000000000ac0; /* Least significant bits */ Different iterations of for_each_set_clump: 'offset' is the bit position and 'clump' is the 6 bit clump from the above bitmap. Iteration first: offset: 6 clump: 0x2b Loop breaks because 6 * 3 = 18 bits traversed in bitmap. Here 6 * 3 is clump size * no. of clumps. Changes in v8: - [Patch 2/4]: Minor change: Use '__initdata' for correct section mismatch in 'clump_test_data' array. Changes in v7: - [Patch 2/4]: Minor changes: Use macro 'DECLARE_BITMAP()' and split 'struct' definition and test data. Changes in v6: - [Patch 2/4]: Make 'for loop' inside test_for_each_set_clump more succinct. Changes in v5: - [Patch 4/4]: Minor change: Hardcode value for better code readability. Changes in v4: - [Patch 2/4]: Use 'for' loop in test function of for_each_set_clump. - [Patch 3/4]: Minor change: Inline value for better code readability. - [Patch 4/4]: Minor change: Inline value for better code readability. Changes in v3: - [Patch 3/4]: Change datatype of some variables from u64 to unsigned long in function thunderx_gpio_set_multiple. CHanges in v2: - [Patch 2/4]: Unify different tests for 'for_each_set_clump'. Pass test data as function parameters. - [Patch 2/4]: Remove unnecessary bitmap_zero calls. Syed Nayyar Waris (4): bitops: Introduce the for_each_set_clump macro lib/test_bitmap.c: Add for_each_set_clump test cases gpio: thunderx: Utilize for_each_set_clump macro gpio: xilinx: Utilize for_each_set_clump macro drivers/gpio/gpio-thunderx.c | 11 ++- drivers/gpio/gpio-xilinx.c | 62 ++++++------- include/asm-generic/bitops/find.h | 19 ++++ include/linux/bitmap.h | 61 +++++++++++++ include/linux/bitops.h | 13 +++ lib/find_bit.c | 14 +++ lib/test_bitmap.c | 145 ++++++++++++++++++++++++++++++ 7 files changed, 291 insertions(+), 34 deletions(-) base-commit: 444fc5cde64330661bf59944c43844e7d4c2ccd8 -- 2.26.2 ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v8 3/4] gpio: thunderx: Utilize for_each_set_clump macro 2020-06-15 12:50 [PATCH v8 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris @ 2020-06-15 12:53 ` Syed Nayyar Waris 2020-06-15 12:54 ` [PATCH v8 4/4] gpio: xilinx: " Syed Nayyar Waris 1 sibling, 0 replies; 10+ messages in thread From: Syed Nayyar Waris @ 2020-06-15 12:53 UTC (permalink / raw) To: linus.walleij, akpm Cc: andriy.shevchenko, vilhelm.gray, rrichter, bgolaszewski, linux-gpio, linux-kernel 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: 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 v8: - No change. Changes in v7: - No change. Changes in v6: - No change. Changes in v5: - No change. Changes in v4: - Minor change: Inline value '64' in code for better code readability. Changes in v3: - Change datatype of some variables from u64 to unsigned long in function thunderx_gpio_set_multiple. Changes in v2: - No change. drivers/gpio/gpio-thunderx.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-thunderx.c b/drivers/gpio/gpio-thunderx.c index 9f66deab46ea..58c9bb25a377 100644 --- a/drivers/gpio/gpio-thunderx.c +++ b/drivers/gpio/gpio-thunderx.c @@ -275,12 +275,15 @@ static void thunderx_gpio_set_multiple(struct gpio_chip *chip, unsigned long *bits) { int bank; - u64 set_bits, clear_bits; + unsigned long set_bits, clear_bits, gpio_mask; + 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, 64) { + bank = offset / 64; + 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); } -- 2.26.2 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-15 12:50 [PATCH v8 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris 2020-06-15 12:53 ` [PATCH v8 3/4] gpio: thunderx: Utilize " Syed Nayyar Waris @ 2020-06-15 12:54 ` Syed Nayyar Waris 2020-06-15 20:09 ` kernel test robot 2020-06-19 19:17 ` Robin Murphy 1 sibling, 2 replies; 10+ messages in thread From: Syed Nayyar Waris @ 2020-06-15 12:54 UTC (permalink / raw) To: linus.walleij, akpm Cc: andriy.shevchenko, vilhelm.gray, bgolaszewski, michal.simek, linux-gpio, linux-arm-kernel, linux-kernel This patch reimplements the xgpio_set_multiple function in drivers/gpio/gpio-xilinx.c to use the new for_each_set_clump macro. Instead of looping for each bit in xgpio_set_multiple function, now we can check each channel at a time and save cycles. Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com> Cc: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com> Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> --- Changes in v8: - No change. Changes in v7: - No change. Changes in v6: - No change. Changes in v5: - Minor change: Inline values '32' and '64' in code for better code readability. Changes in v4: - Minor change: Inline values '32' and '64' in code for better code readability. Changes in v3: - No change. Changes in v2: - No change. drivers/gpio/gpio-xilinx.c | 62 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c index 67f9f82e0db0..e81092dea27e 100644 --- a/drivers/gpio/gpio-xilinx.c +++ b/drivers/gpio/gpio-xilinx.c @@ -136,39 +136,41 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { - unsigned long flags; + unsigned long flags[2]; struct xgpio_instance *chip = gpiochip_get_data(gc); - int index = xgpio_index(chip, 0); - int offset, i; - - spin_lock_irqsave(&chip->gpio_lock[index], flags); - - /* Write to GPIO signals */ - for (i = 0; i < gc->ngpio; i++) { - if (*mask == 0) - break; - /* Once finished with an index write it out to the register */ - if (index != xgpio_index(chip, i)) { - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + - index * XGPIO_CHANNEL_OFFSET, - chip->gpio_state[index]); - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); - index = xgpio_index(chip, i); - spin_lock_irqsave(&chip->gpio_lock[index], flags); - } - if (__test_and_clear_bit(i, mask)) { - offset = xgpio_offset(chip, i); - if (test_bit(i, bits)) - chip->gpio_state[index] |= BIT(offset); - else - chip->gpio_state[index] &= ~BIT(offset); - } + u32 *const state = chip->gpio_state; + unsigned int *const width = chip->gpio_width; + unsigned long offset, clump; + size_t index; + + DECLARE_BITMAP(old, 64); + DECLARE_BITMAP(new, 64); + DECLARE_BITMAP(changed, 64); + + spin_lock_irqsave(&chip->gpio_lock[0], flags[0]); + spin_lock_irqsave(&chip->gpio_lock[1], flags[1]); + + bitmap_set_value(old, state[0], 0, width[0]); + bitmap_set_value(old, state[1], width[0], width[1]); + bitmap_replace(new, old, bits, mask, gc->ngpio); + + bitmap_set_value(old, state[0], 0, 32); + bitmap_set_value(old, state[1], 32, 32); + state[0] = bitmap_get_value(new, 0, width[0]); + state[1] = bitmap_get_value(new, width[0], width[1]); + bitmap_set_value(new, state[0], 0, 32); + bitmap_set_value(new, state[1], 32, 32); + bitmap_xor(changed, old, new, 64); + + for_each_set_clump(offset, clump, changed, 64, 32) { + index = offset / 32; + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + + index * XGPIO_CHANNEL_OFFSET, + state[index]); } - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + - index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); - - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); + spin_unlock_irqrestore(&chip->gpio_lock[1], flags[1]); + spin_unlock_irqrestore(&chip->gpio_lock[0], flags[0]); } /** -- 2.26.2 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-15 12:54 ` [PATCH v8 4/4] gpio: xilinx: " Syed Nayyar Waris @ 2020-06-15 20:09 ` kernel test robot 2020-06-16 5:57 ` Syed Nayyar Waris 2020-06-19 7:00 ` Syed Nayyar Waris 2020-06-19 19:17 ` Robin Murphy 1 sibling, 2 replies; 10+ messages in thread From: kernel test robot @ 2020-06-15 20:09 UTC (permalink / raw) To: Syed Nayyar Waris, linus.walleij, akpm Cc: kbuild-all, andriy.shevchenko, vilhelm.gray, bgolaszewski, michal.simek, linux-gpio, linux-arm-kernel, linux-kernel [-- Attachment #1: Type: text/plain, Size: 4203 bytes --] Hi Syed, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on 444fc5cde64330661bf59944c43844e7d4c2ccd8] url: https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200615-205729 base: 444fc5cde64330661bf59944c43844e7d4c2ccd8 config: sparc64-randconfig-s032-20200615 (attached as .config) compiler: sparc64-linux-gcc (GCC) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.2-rc1-3-g55607964-dirty # save the attached .config to linux build tree make W=1 C=1 ARCH=sparc64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> sparse warnings: (new ones prefixed by >>) >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long >> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8) vim +639 include/linux/bitmap.h 169c474fb22d8a William Breathitt Gray 2019-12-04 613 803024b6c8a375 Syed Nayyar Waris 2020-06-15 614 /** 803024b6c8a375 Syed Nayyar Waris 2020-06-15 615 * bitmap_set_value - set n-bit value within a memory region 803024b6c8a375 Syed Nayyar Waris 2020-06-15 616 * @map: address to the bitmap memory region 803024b6c8a375 Syed Nayyar Waris 2020-06-15 617 * @value: value of nbits 803024b6c8a375 Syed Nayyar Waris 2020-06-15 618 * @start: bit offset of the n-bit value 803024b6c8a375 Syed Nayyar Waris 2020-06-15 619 * @nbits: size of value in bits 803024b6c8a375 Syed Nayyar Waris 2020-06-15 620 */ 803024b6c8a375 Syed Nayyar Waris 2020-06-15 621 static inline void bitmap_set_value(unsigned long *map, 803024b6c8a375 Syed Nayyar Waris 2020-06-15 622 unsigned long value, 803024b6c8a375 Syed Nayyar Waris 2020-06-15 623 unsigned long start, unsigned long nbits) 803024b6c8a375 Syed Nayyar Waris 2020-06-15 624 { 803024b6c8a375 Syed Nayyar Waris 2020-06-15 625 const size_t index = BIT_WORD(start); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 626 const unsigned long offset = start % BITS_PER_LONG; 803024b6c8a375 Syed Nayyar Waris 2020-06-15 627 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 628 const unsigned long space = ceiling - start; 803024b6c8a375 Syed Nayyar Waris 2020-06-15 629 803024b6c8a375 Syed Nayyar Waris 2020-06-15 630 value &= GENMASK(nbits - 1, 0); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 631 803024b6c8a375 Syed Nayyar Waris 2020-06-15 632 if (space >= nbits) { 803024b6c8a375 Syed Nayyar Waris 2020-06-15 633 map[index] &= ~(GENMASK(nbits + offset - 1, offset)); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 634 map[index] |= value << offset; 803024b6c8a375 Syed Nayyar Waris 2020-06-15 635 } else { 803024b6c8a375 Syed Nayyar Waris 2020-06-15 636 map[index] &= ~BITMAP_FIRST_WORD_MASK(start); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 637 map[index] |= value << offset; 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @639 map[index + 1] |= (value >> space); 803024b6c8a375 Syed Nayyar Waris 2020-06-15 640 } 803024b6c8a375 Syed Nayyar Waris 2020-06-15 641 } 803024b6c8a375 Syed Nayyar Waris 2020-06-15 642 :::::: The code at line 639 was first introduced by commit :::::: 803024b6c8a375ba9e9e9467595d7d52d4f6a38e bitops: Introduce 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 [-- Attachment #2: .config.gz --] [-- Type: application/gzip, Size: 26635 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-15 20:09 ` kernel test robot @ 2020-06-16 5:57 ` Syed Nayyar Waris 2020-06-19 14:26 ` Luc Van Oostenryck 2020-06-19 7:00 ` Syed Nayyar Waris 1 sibling, 1 reply; 10+ messages in thread From: Syed Nayyar Waris @ 2020-06-16 5:57 UTC (permalink / raw) To: kernel test robot Cc: Linus Walleij, Andrew Morton, kbuild-all, Andy Shevchenko, William Breathitt Gray, Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM, linux-arm Mailing List, Linux Kernel Mailing List On Tue, Jun 16, 2020 at 1:39 AM kernel test robot <lkp@intel.com> wrote: > > Hi Syed, > > Thank you for the patch! Perhaps something to improve: > > [auto build test WARNING on 444fc5cde64330661bf59944c43844e7d4c2ccd8] > > url: https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200615-205729 > base: 444fc5cde64330661bf59944c43844e7d4c2ccd8 > config: sparc64-randconfig-s032-20200615 (attached as .config) > compiler: sparc64-linux-gcc (GCC) 9.3.0 > reproduce: > # apt-get install sparse > # sparse version: v0.6.2-rc1-3-g55607964-dirty > # save the attached .config to linux build tree > make W=1 C=1 ARCH=sparc64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp@intel.com> > > > sparse warnings: (new ones prefixed by >>) > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8) > > vim +639 include/linux/bitmap.h > > 169c474fb22d8a William Breathitt Gray 2019-12-04 613 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 614 /** > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 615 * bitmap_set_value - set n-bit value within a memory region > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 616 * @map: address to the bitmap memory region > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 617 * @value: value of nbits > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 618 * @start: bit offset of the n-bit value > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 619 * @nbits: size of value in bits > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 620 */ > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 621 static inline void bitmap_set_value(unsigned long *map, > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 622 unsigned long value, > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 623 unsigned long start, unsigned long nbits) > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 624 { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 625 const size_t index = BIT_WORD(start); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 626 const unsigned long offset = start % BITS_PER_LONG; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 627 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 628 const unsigned long space = ceiling - start; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 629 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 630 value &= GENMASK(nbits - 1, 0); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 631 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 632 if (space >= nbits) { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 633 map[index] &= ~(GENMASK(nbits + offset - 1, offset)); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 634 map[index] |= value << offset; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 635 } else { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 636 map[index] &= ~BITMAP_FIRST_WORD_MASK(start); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 637 map[index] |= value << offset; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @639 map[index + 1] |= (value >> space); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 640 } > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 641 } > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 642 Regarding the compilation warning reported above: "sparse: shift too big (64) for type unsigned long" at line 639 "sparse: invalid access past the end of 'old' (8 8)" at line 638 Kindly refer to the code above, at these line numbers. I am in the process of fixing this warning. But what would be the fix ? At the moment can't think of a code-fix to make the compilation warning disappear (specially at line 639). Can anyone please explain to me the meaning of the compilation warning more deeply? By the way, this warning was not reported in (earlier) v7 of the patchset. Regards Syed Nayyar Waris ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-16 5:57 ` Syed Nayyar Waris @ 2020-06-19 14:26 ` Luc Van Oostenryck 0 siblings, 0 replies; 10+ messages in thread From: Luc Van Oostenryck @ 2020-06-19 14:26 UTC (permalink / raw) To: Syed Nayyar Waris Cc: kernel test robot, Linus Walleij, Andrew Morton, kbuild-all, Andy Shevchenko, William Breathitt Gray, Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM, linux-arm Mailing List, Linux Kernel Mailing List On Tue, Jun 16, 2020 at 11:27:18AM +0530, Syed Nayyar Waris wrote: Hi, > Regarding the compilation warning reported above: > > "sparse: shift too big (64) for type unsigned long" at line 639 > "sparse: invalid access past the end of 'old' (8 8)" at line 638 > > Kindly refer to the code above, at these line numbers. > > I am in the process of fixing this warning. But what would be the fix? > ? At the moment can't think of a code-fix to make the compilation > warning disappear (specially at line 639). Can anyone please explain > to me the meaning of the compilation warning more deeply? This error message is caused by sparse doing the check too early. There is thus nothing to be fixed for it in this code. Best regards, -- Luc ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-15 20:09 ` kernel test robot 2020-06-16 5:57 ` Syed Nayyar Waris @ 2020-06-19 7:00 ` Syed Nayyar Waris 2020-06-19 8:38 ` Andy Shevchenko 1 sibling, 1 reply; 10+ messages in thread From: Syed Nayyar Waris @ 2020-06-19 7:00 UTC (permalink / raw) To: kernel test robot Cc: Linus Walleij, Andrew Morton, kbuild-all, Andy Shevchenko, William Breathitt Gray, Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM, linux-arm Mailing List, Linux Kernel Mailing List > > Hi Syed, > > Thank you for the patch! Perhaps something to improve: > > [auto build test WARNING on 444fc5cde64330661bf59944c43844e7d4c2ccd8] > > url: https://github.com/0day-ci/linux/commits/Syed-Nayyar-Waris/Introduce-the-for_each_set_clump-macro/20200615-205729 > base: 444fc5cde64330661bf59944c43844e7d4c2ccd8 > config: sparc64-randconfig-s032-20200615 (attached as .config) > compiler: sparc64-linux-gcc (GCC) 9.3.0 > reproduce: > # apt-get install sparse > # sparse version: v0.6.2-rc1-3-g55607964-dirty > # save the attached .config to linux build tree > make W=1 C=1 ARCH=sparc64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' > > > > sparse warnings: (new ones prefixed by >>) > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > >> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8) > Hi All, It seems to me that to reproduce this warning, I have to use the sparc64 compiler. I have installed 'sparc64-linux-gnu-gcc' on my computer. I have to specify that this compiler needs to be used for build process. How/ Where do I specify this? I have downloaded the config.gz (has config file) and placed it at the root of the linux kernel project tree. But the Makefile STILL has 'gcc' as the compiler. When I build, it is the 'gcc' compiler being used and not 'sparc64-linux-gnu-gcc'. I know I can manually change the Makefile to use sparc64 compiler, but I think there must be some more elegant way to do this, perhaps using make menuconfig? Kindly illuminate as to how shall I reproduce the compiler warning. Regards Syed Nayyar Waris > vim +639 include/linux/bitmap.h > > 169c474fb22d8a William Breathitt Gray 2019-12-04 613 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 614 /** > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 615 * bitmap_set_value - set n-bit value within a memory region > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 616 * @map: address to the bitmap memory region > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 617 * @value: value of nbits > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 618 * @start: bit offset of the n-bit value > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 619 * @nbits: size of value in bits > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 620 */ > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 621 static inline void bitmap_set_value(unsigned long *map, > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 622 unsigned long value, > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 623 unsigned long start, unsigned long nbits) > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 624 { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 625 const size_t index = BIT_WORD(start); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 626 const unsigned long offset = start % BITS_PER_LONG; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 627 const unsigned long ceiling = roundup(start + 1, BITS_PER_LONG); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 628 const unsigned long space = ceiling - start; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 629 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 630 value &= GENMASK(nbits - 1, 0); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 631 > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 632 if (space >= nbits) { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 633 map[index] &= ~(GENMASK(nbits + offset - 1, offset)); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 634 map[index] |= value << offset; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 635 } else { > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 636 map[index] &= ~BITMAP_FIRST_WORD_MASK(start); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 637 map[index] |= value << offset; > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @639 map[index + 1] |= (value >> space); > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 640 } > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 641 } > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 642 > > :::::: The code at line 639 was first introduced by commit > :::::: 803024b6c8a375ba9e9e9467595d7d52d4f6a38e bitops: Introduce the for_each_set_clump macro > > :::::: TO: Syed Nayyar Waris <syednwaris@gmail.com> ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-19 7:00 ` Syed Nayyar Waris @ 2020-06-19 8:38 ` Andy Shevchenko 2020-06-19 9:05 ` Andy Shevchenko 0 siblings, 1 reply; 10+ messages in thread From: Andy Shevchenko @ 2020-06-19 8:38 UTC (permalink / raw) To: Syed Nayyar Waris Cc: kernel test robot, Linus Walleij, Andrew Morton, kbuild-all, Andy Shevchenko, William Breathitt Gray, Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM, linux-arm Mailing List, Linux Kernel Mailing List On Fri, Jun 19, 2020 at 10:02 AM Syed Nayyar Waris <syednwaris@gmail.com> wrote: ... > > config: sparc64-randconfig-s032-20200615 (attached as .config) > > compiler: sparc64-linux-gcc (GCC) 9.3.0 > > reproduce: > > # apt-get install sparse > > # sparse version: v0.6.2-rc1-3-g55607964-dirty > > # save the attached .config to linux build tree > > make W=1 C=1 ARCH=sparc64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ... > > sparse warnings: (new ones prefixed by >>) > > > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > >> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8) > It seems to me that to reproduce this warning, I have to use the > sparc64 compiler. I have installed 'sparc64-linux-gnu-gcc' on my > computer. Sparse is not a compiler. > I have to specify that this compiler needs to be used for build > process. How/ Where do I specify this? > > I have downloaded the config.gz (has config file) and placed it at the > root of the linux kernel project tree. But the Makefile STILL has > 'gcc' as the compiler. When I build, it is the 'gcc' compiler being > used and not 'sparc64-linux-gnu-gcc'. I know I can manually change the > Makefile to use sparc64 compiler, but I think there must be some more > elegant way to do this, perhaps using make menuconfig? If you wish to run a compilation, download a compiler from [1], and, after adding its bin/ folder to PATH, run make CROSS_COMPILE=sparc64-linux- ARCH=sparc64 ... # first generate .config > Kindly illuminate as to how shall I reproduce the compiler warning. > > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @639 map[index + 1] |= (value >> space); Hmm... I think I sent a reply [2] where I explained how space can be 64. Do you agree with analysis? [1]: https://mirrors.edge.kernel.org/pub/tools/crosstool/ [2]: https://lore.kernel.org/lkml/20200616081428.GP2428291@smile.fi.intel.com/ -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-19 8:38 ` Andy Shevchenko @ 2020-06-19 9:05 ` Andy Shevchenko 0 siblings, 0 replies; 10+ messages in thread From: Andy Shevchenko @ 2020-06-19 9:05 UTC (permalink / raw) To: Syed Nayyar Waris Cc: kernel test robot, Linus Walleij, Andrew Morton, kbuild-all, William Breathitt Gray, Bartosz Golaszewski, Michal Simek, open list:GPIO SUBSYSTEM, linux-arm Mailing List, Linux Kernel Mailing List On Fri, Jun 19, 2020 at 11:38:59AM +0300, Andy Shevchenko wrote: > On Fri, Jun 19, 2020 at 10:02 AM Syed Nayyar Waris <syednwaris@gmail.com> wrote: > > ... > > > > config: sparc64-randconfig-s032-20200615 (attached as .config) > > > compiler: sparc64-linux-gcc (GCC) 9.3.0 > > > reproduce: > > > # apt-get install sparse > > > # sparse version: v0.6.2-rc1-3-g55607964-dirty > > > # save the attached .config to linux build tree > > > make W=1 C=1 ARCH=sparc64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' > > ... > > > > sparse warnings: (new ones prefixed by >>) > > > > > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > > include/linux/bitmap.h:594:63: sparse: sparse: shift too big (64) for type unsigned long > > > >> include/linux/bitmap.h:639:45: sparse: sparse: shift too big (64) for type unsigned long > > > >> include/linux/bitmap.h:638:17: sparse: sparse: invalid access past the end of 'old' (8 8) > > > It seems to me that to reproduce this warning, I have to use the > > sparc64 compiler. I have installed 'sparc64-linux-gnu-gcc' on my > > computer. > > Sparse is not a compiler. On x86_64: CHECK drivers/gpio/gpio-xilinx.c include/linux/bitmap.h:639:45: warning: shift too big (64) for type unsigned long include/linux/bitmap.h:639:45: warning: shift too big (64) for type unsigned long include/linux/bitmap.h:594:63: warning: shift too big (64) for type unsigned long include/linux/bitmap.h:639:45: warning: shift too big (64) for type unsigned long include/linux/bitmap.h:638:17: warning: invalid access past the end of 'old' (8 8) > > I have to specify that this compiler needs to be used for build > > process. How/ Where do I specify this? > > > > I have downloaded the config.gz (has config file) and placed it at the > > root of the linux kernel project tree. But the Makefile STILL has > > 'gcc' as the compiler. When I build, it is the 'gcc' compiler being > > used and not 'sparc64-linux-gnu-gcc'. I know I can manually change the > > Makefile to use sparc64 compiler, but I think there must be some more > > elegant way to do this, perhaps using make menuconfig? > > If you wish to run a compilation, download a compiler from [1], and, > after adding its bin/ folder to PATH, run > make CROSS_COMPILE=sparc64-linux- ARCH=sparc64 ... # first generate .config > > > Kindly illuminate as to how shall I reproduce the compiler warning. > > > > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @638 map[index + 1] &= ~BITMAP_LAST_WORD_MASK(start + nbits); > > > 803024b6c8a375 Syed Nayyar Waris 2020-06-15 @639 map[index + 1] |= (value >> space); > > Hmm... I think I sent a reply [2] where I explained how space can be > 64. Do you agree with analysis? > > [1]: https://mirrors.edge.kernel.org/pub/tools/crosstool/ > [2]: https://lore.kernel.org/lkml/20200616081428.GP2428291@smile.fi.intel.com/ -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v8 4/4] gpio: xilinx: Utilize for_each_set_clump macro 2020-06-15 12:54 ` [PATCH v8 4/4] gpio: xilinx: " Syed Nayyar Waris 2020-06-15 20:09 ` kernel test robot @ 2020-06-19 19:17 ` Robin Murphy 1 sibling, 0 replies; 10+ messages in thread From: Robin Murphy @ 2020-06-19 19:17 UTC (permalink / raw) To: Syed Nayyar Waris, linus.walleij, akpm Cc: linux-gpio, linux-kernel, vilhelm.gray, michal.simek, bgolaszewski, andriy.shevchenko, linux-arm-kernel On 2020-06-15 13:54, Syed Nayyar Waris wrote: > This patch reimplements the xgpio_set_multiple function in > drivers/gpio/gpio-xilinx.c to use the new for_each_set_clump macro. > Instead of looping for each bit in xgpio_set_multiple > function, now we can check each channel at a time and save cycles. > > Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com> > Cc: Michal Simek <michal.simek@xilinx.com> > Signed-off-by: Syed Nayyar Waris <syednwaris@gmail.com> > Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com> > --- > Changes in v8: > - No change. > > Changes in v7: > - No change. > > Changes in v6: > - No change. > > Changes in v5: > - Minor change: Inline values '32' and '64' in code for better > code readability. > > Changes in v4: > - Minor change: Inline values '32' and '64' in code for better > code readability. > > Changes in v3: > - No change. > > Changes in v2: > - No change. > > drivers/gpio/gpio-xilinx.c | 62 ++++++++++++++++++++------------------ > 1 file changed, 32 insertions(+), 30 deletions(-) > > diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c > index 67f9f82e0db0..e81092dea27e 100644 > --- a/drivers/gpio/gpio-xilinx.c > +++ b/drivers/gpio/gpio-xilinx.c > @@ -136,39 +136,41 @@ static void xgpio_set(struct gpio_chip *gc, unsigned int gpio, int val) > static void xgpio_set_multiple(struct gpio_chip *gc, unsigned long *mask, > unsigned long *bits) > { > - unsigned long flags; > + unsigned long flags[2]; > struct xgpio_instance *chip = gpiochip_get_data(gc); > - int index = xgpio_index(chip, 0); > - int offset, i; > - > - spin_lock_irqsave(&chip->gpio_lock[index], flags); > - > - /* Write to GPIO signals */ > - for (i = 0; i < gc->ngpio; i++) { > - if (*mask == 0) > - break; > - /* Once finished with an index write it out to the register */ > - if (index != xgpio_index(chip, i)) { > - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + > - index * XGPIO_CHANNEL_OFFSET, > - chip->gpio_state[index]); > - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); > - index = xgpio_index(chip, i); > - spin_lock_irqsave(&chip->gpio_lock[index], flags); > - } > - if (__test_and_clear_bit(i, mask)) { > - offset = xgpio_offset(chip, i); > - if (test_bit(i, bits)) > - chip->gpio_state[index] |= BIT(offset); > - else > - chip->gpio_state[index] &= ~BIT(offset); > - } > + u32 *const state = chip->gpio_state; > + unsigned int *const width = chip->gpio_width; Immutable pointers to mutable data are pretty unusual, especially for temporary local variables. Let me share my thought process upon seeing this: - hmm, is "* const" simply a mistake that's meant to be "const *"? - <scan the rest of the function> no, updating chip->gpio_state seems appropriate, so it can't be that. - does anything take the address of either of these variables that might justify it? - <scan the rest of the function again> nope, they're only ever used by value - hmm, maybe it's just paranoia, but in that case why isn't width "const * const" since chip->gpio_width shouldn't need to be modified? - hmm... And at that point I've spent nearly a minute parsing what should have been be some trivial definitions of local shorthand variables. Defensive programming is all very well, but the distraction to readers (I can't be the only one) can easily outweigh any perceived value in trying to harden against theoretical future developer error in a straightforward ~30-line function. > + unsigned long offset, clump; > + size_t index; > + > + DECLARE_BITMAP(old, 64); > + DECLARE_BITMAP(new, 64); > + DECLARE_BITMAP(changed, 64); > + > + spin_lock_irqsave(&chip->gpio_lock[0], flags[0]); > + spin_lock_irqsave(&chip->gpio_lock[1], flags[1]); Why _irqsave on the inner lock? (think about it...) > + > + bitmap_set_value(old, state[0], 0, width[0]); > + bitmap_set_value(old, state[1], width[0], width[1]); > + bitmap_replace(new, old, bits, mask, gc->ngpio); > + > + bitmap_set_value(old, state[0], 0, 32); > + bitmap_set_value(old, state[1], 32, 32); > + state[0] = bitmap_get_value(new, 0, width[0]); > + state[1] = bitmap_get_value(new, width[0], width[1]); > + bitmap_set_value(new, state[0], 0, 32); > + bitmap_set_value(new, state[1], 32, 32); > + bitmap_xor(changed, old, new, 64); > + > + for_each_set_clump(offset, clump, changed, 64, 32) { > + index = offset / 32; > + xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + > + index * XGPIO_CHANNEL_OFFSET, > + state[index]); > } TBH this looks like a rather overcomplicated and horribly inefficient way of doing: if (((u32 *)changed)[0]) xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET, state[0]); if (((u32 *)changed)[1]) xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + XGPIO_CHANNEL_OFFSET, state[1]); (and doing the changed/state update itself one word at a time for each condition would probably be a fair bit more efficient in terms of minimising spilling to the stack on 32-bit machines) I can see this API having merit if the clumps are a weird size or expected to be significantly sparse in the bitmap, but making out-of-line calls to an iterator which itself involves another out-of-line call and an integer division, all just to process two halves of a 64-bit value, seems... unnecessarily silly :/ [drive-by review since I had a "packing small values into bitmaps" use-case and wondered if there might be anything interesting here] Robin. > > - xgpio_writereg(chip->regs + XGPIO_DATA_OFFSET + > - index * XGPIO_CHANNEL_OFFSET, chip->gpio_state[index]); > - > - spin_unlock_irqrestore(&chip->gpio_lock[index], flags); > + spin_unlock_irqrestore(&chip->gpio_lock[1], flags[1]); > + spin_unlock_irqrestore(&chip->gpio_lock[0], flags[0]); > } > > /** > ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2020-06-19 19:17 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-06-15 12:50 [PATCH v8 0/4] Introduce the for_each_set_clump macro Syed Nayyar Waris 2020-06-15 12:53 ` [PATCH v8 3/4] gpio: thunderx: Utilize " Syed Nayyar Waris 2020-06-15 12:54 ` [PATCH v8 4/4] gpio: xilinx: " Syed Nayyar Waris 2020-06-15 20:09 ` kernel test robot 2020-06-16 5:57 ` Syed Nayyar Waris 2020-06-19 14:26 ` Luc Van Oostenryck 2020-06-19 7:00 ` Syed Nayyar Waris 2020-06-19 8:38 ` Andy Shevchenko 2020-06-19 9:05 ` Andy Shevchenko 2020-06-19 19:17 ` Robin Murphy
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).