* [PATCH 5/6] gpio: thunderx: Utilize for_each_set_clump macro
@ 2020-04-24 12:30 Syed Nayyar Waris
2020-04-24 13:55 ` William Breathitt Gray
0 siblings, 1 reply; 3+ messages in thread
From: Syed Nayyar Waris @ 2020-04-24 12:30 UTC (permalink / raw)
To: akpm
Cc: andriy.shevchenko, vilhelm.gray, rrichter, linus.walleij,
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: 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>
---
drivers/gpio/gpio-thunderx.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
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);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 5/6] gpio: thunderx: Utilize for_each_set_clump macro
2020-04-24 12:30 [PATCH 5/6] gpio: thunderx: Utilize for_each_set_clump macro Syed Nayyar Waris
@ 2020-04-24 13:55 ` William Breathitt Gray
2020-04-24 15:14 ` William Breathitt Gray
0 siblings, 1 reply; 3+ messages in thread
From: William Breathitt Gray @ 2020-04-24 13:55 UTC (permalink / raw)
To: rrichter, linus.walleij, bgolaszewski
Cc: akpm, andriy.shevchenko, Syed Nayyar Waris, linux-gpio,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2245 bytes --]
On Fri, Apr 24, 2020 at 06:00:50PM +0530, Syed Nayyar Waris wrote:
> 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>
> ---
> drivers/gpio/gpio-thunderx.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> 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);
> }
> --
> 2.7.4
We noticed in the original code that this set_multiple callback does not
appear to work correctly on systems where BITS_PER_LONG == 32. On those
systems, the bits and mask values are 32-bit, but the for loop jumps 64
bits at a time -- that means the loop is skipping the upper 32 gpio
lines of every iteration.
Is the gpio-thunderx driver only intended for 64-bit systems? Or this
behavior a bug?
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 5/6] gpio: thunderx: Utilize for_each_set_clump macro
2020-04-24 13:55 ` William Breathitt Gray
@ 2020-04-24 15:14 ` William Breathitt Gray
0 siblings, 0 replies; 3+ messages in thread
From: William Breathitt Gray @ 2020-04-24 15:14 UTC (permalink / raw)
To: rrichter, linus.walleij, bgolaszewski
Cc: akpm, andriy.shevchenko, Syed Nayyar Waris, linux-gpio,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2555 bytes --]
On Fri, Apr 24, 2020 at 09:55:47AM -0400, William Breathitt Gray wrote:
> On Fri, Apr 24, 2020 at 06:00:50PM +0530, Syed Nayyar Waris wrote:
> > 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>
> > ---
> > drivers/gpio/gpio-thunderx.c | 12 ++++++++----
> > 1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > 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);
> > }
> > --
> > 2.7.4
>
> We noticed in the original code that this set_multiple callback does not
> appear to work correctly on systems where BITS_PER_LONG == 32. On those
> systems, the bits and mask values are 32-bit, but the for loop jumps 64
> bits at a time -- that means the loop is skipping the upper 32 gpio
> lines of every iteration.
>
> Is the gpio-thunderx driver only intended for 64-bit systems? Or this
> behavior a bug?
>
> William Breathitt Gray
Nevermind, I spoke too soon; I see there's a depends on 64BIT line in
the Kconfig for GPIO_THUNDERX.
William Breathitt Gray
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-24 15:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-24 12:30 [PATCH 5/6] gpio: thunderx: Utilize for_each_set_clump macro Syed Nayyar Waris
2020-04-24 13:55 ` William Breathitt Gray
2020-04-24 15:14 ` William Breathitt Gray
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).