LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()
@ 2015-03-10 22:07 Rafael J. Wysocki
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2015-03-10 22:07 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, Linux Kernel Mailing List, ACPI Devel Maling List,
	Mika Westerberg

Hi,

As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is
rather costly.

Kind regards,
Rafael


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()
  2015-03-10 22:07 [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
@ 2015-03-10 22:08 ` Rafael J. Wysocki
  2015-03-11  1:36   ` Hanjun Guo
                     ` (2 more replies)
  2015-03-10 22:10 ` [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE() Rafael J. Wysocki
  2015-03-18  1:37 ` [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
  2 siblings, 3 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2015-03-10 22:08 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If dev is NULL in __gpiod_get_index() and both ACPI and OF are
enabled, it will be checked twice before the code decides to give
up with DT/ACPI lookup, so avoid that.

Also use the observation that ACPI_COMPANION() is much more efficient
than ACPI_HANDLE(), because the latter uses the former and carries out
a check and a pointer dereference on top of it, so replace the
ACPI_HANDLE() check with an ACPI_COMPANION() one which does not
require the additional IS_ENABLED(CONFIG_ACPI) check too.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/gpio/gpiolib.c |   16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Index: linux-pm/drivers/gpio/gpiolib.c
===================================================================
--- linux-pm.orig/drivers/gpio/gpiolib.c
+++ linux-pm/drivers/gpio/gpiolib.c
@@ -1865,13 +1865,15 @@ struct gpio_desc *__must_check __gpiod_g
 
 	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
 
-	/* Using device tree? */
-	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) {
-		dev_dbg(dev, "using device tree for GPIO lookup\n");
-		desc = of_find_gpio(dev, con_id, idx, &lookupflags);
-	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
-		dev_dbg(dev, "using ACPI for GPIO lookup\n");
-		desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+	if (dev) {
+		/* Using device tree? */
+		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+			dev_dbg(dev, "using device tree for GPIO lookup\n");
+			desc = of_find_gpio(dev, con_id, idx, &lookupflags);
+		} else if (ACPI_COMPANION(dev)) {
+			dev_dbg(dev, "using ACPI for GPIO lookup\n");
+			desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
+		}
 	}
 
 	/*


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE()
  2015-03-10 22:07 [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
@ 2015-03-10 22:10 ` Rafael J. Wysocki
  2015-03-11  8:43   ` Mika Westerberg
  2015-03-18  1:35   ` Linus Walleij
  2015-03-18  1:37 ` [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
  2 siblings, 2 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2015-03-10 22:10 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

In acpi_gpiochip_request_interrupts() the handle local
variable already contains the value that we want to pass
to acpi_walk_resources(), so it is better to use that
variable instead of evaluating ACPI_HANDLE() once more
for the same device.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/gpio/gpiolib-acpi.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: linux-pm/drivers/gpio/gpiolib-acpi.c
===================================================================
--- linux-pm.orig/drivers/gpio/gpiolib-acpi.c
+++ linux-pm/drivers/gpio/gpiolib-acpi.c
@@ -300,7 +300,7 @@ void acpi_gpiochip_request_interrupts(st
 		return;
 
 	INIT_LIST_HEAD(&acpi_gpio->events);
-	acpi_walk_resources(ACPI_HANDLE(chip->dev), "_AEI",
+	acpi_walk_resources(handle, "_AEI",
 			    acpi_gpiochip_request_interrupt, acpi_gpio);
 }
 


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
@ 2015-03-11  1:36   ` Hanjun Guo
  2015-03-11  8:43   ` Mika Westerberg
  2015-03-18  1:33   ` Linus Walleij
  2 siblings, 0 replies; 11+ messages in thread
From: Hanjun Guo @ 2015-03-11  1:36 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linus Walleij
  Cc: Alexandre Courbot, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

On 2015/3/11 6:08, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> If dev is NULL in __gpiod_get_index() and both ACPI and OF are
> enabled, it will be checked twice before the code decides to give
> up with DT/ACPI lookup, so avoid that.
>
> Also use the observation that ACPI_COMPANION() is much more efficient
> than ACPI_HANDLE(), because the latter uses the former and carries out
> a check and a pointer dereference on top of it, so replace the
> ACPI_HANDLE() check with an ACPI_COMPANION() one which does not
> require the additional IS_ENABLED(CONFIG_ACPI) check too.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Quite straight forward to me, for both two patches,

Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>

Thanks
Hanjun

> ---
>  drivers/gpio/gpiolib.c |   16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)
>
> Index: linux-pm/drivers/gpio/gpiolib.c
> ===================================================================
> --- linux-pm.orig/drivers/gpio/gpiolib.c
> +++ linux-pm/drivers/gpio/gpiolib.c
> @@ -1865,13 +1865,15 @@ struct gpio_desc *__must_check __gpiod_g
>  
>  	dev_dbg(dev, "GPIO lookup for consumer %s\n", con_id);
>  
> -	/* Using device tree? */
> -	if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) {
> -		dev_dbg(dev, "using device tree for GPIO lookup\n");
> -		desc = of_find_gpio(dev, con_id, idx, &lookupflags);
> -	} else if (IS_ENABLED(CONFIG_ACPI) && dev && ACPI_HANDLE(dev)) {
> -		dev_dbg(dev, "using ACPI for GPIO lookup\n");
> -		desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
> +	if (dev) {
> +		/* Using device tree? */
> +		if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
> +			dev_dbg(dev, "using device tree for GPIO lookup\n");
> +			desc = of_find_gpio(dev, con_id, idx, &lookupflags);
> +		} else if (ACPI_COMPANION(dev)) {
> +			dev_dbg(dev, "using ACPI for GPIO lookup\n");
> +			desc = acpi_find_gpio(dev, con_id, idx, &lookupflags);
> +		}
>  	}
>  
>  	/*
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> .
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
  2015-03-11  1:36   ` Hanjun Guo
@ 2015-03-11  8:43   ` Mika Westerberg
  2015-03-18  1:33   ` Linus Walleij
  2 siblings, 0 replies; 11+ messages in thread
From: Mika Westerberg @ 2015-03-11  8:43 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linus Walleij, Alexandre Courbot, linux-gpio,
	Linux Kernel Mailing List, ACPI Devel Maling List

On Tue, Mar 10, 2015 at 11:08:57PM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> If dev is NULL in __gpiod_get_index() and both ACPI and OF are
> enabled, it will be checked twice before the code decides to give
> up with DT/ACPI lookup, so avoid that.
> 
> Also use the observation that ACPI_COMPANION() is much more efficient
> than ACPI_HANDLE(), because the latter uses the former and carries out
> a check and a pointer dereference on top of it, so replace the
> ACPI_HANDLE() check with an ACPI_COMPANION() one which does not
> require the additional IS_ENABLED(CONFIG_ACPI) check too.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE()
  2015-03-10 22:10 ` [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE() Rafael J. Wysocki
@ 2015-03-11  8:43   ` Mika Westerberg
  2015-03-18  1:35   ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Mika Westerberg @ 2015-03-11  8:43 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linus Walleij, Alexandre Courbot, linux-gpio,
	Linux Kernel Mailing List, ACPI Devel Maling List

On Tue, Mar 10, 2015 at 11:10:01PM +0100, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> In acpi_gpiochip_request_interrupts() the handle local
> variable already contains the value that we want to pass
> to acpi_walk_resources(), so it is better to use that
> variable instead of evaluating ACPI_HANDLE() once more
> for the same device.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index()
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
  2015-03-11  1:36   ` Hanjun Guo
  2015-03-11  8:43   ` Mika Westerberg
@ 2015-03-18  1:33   ` Linus Walleij
  2 siblings, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2015-03-18  1:33 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Alexandre Courbot, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

On Tue, Mar 10, 2015 at 11:08 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:

> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> If dev is NULL in __gpiod_get_index() and both ACPI and OF are
> enabled, it will be checked twice before the code decides to give
> up with DT/ACPI lookup, so avoid that.
>
> Also use the observation that ACPI_COMPANION() is much more efficient
> than ACPI_HANDLE(), because the latter uses the former and carries out
> a check and a pointer dereference on top of it, so replace the
> ACPI_HANDLE() check with an ACPI_COMPANION() one which does not
> require the additional IS_ENABLED(CONFIG_ACPI) check too.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Patch applied with review and ACK tags.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE()
  2015-03-10 22:10 ` [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE() Rafael J. Wysocki
  2015-03-11  8:43   ` Mika Westerberg
@ 2015-03-18  1:35   ` Linus Walleij
  1 sibling, 0 replies; 11+ messages in thread
From: Linus Walleij @ 2015-03-18  1:35 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Alexandre Courbot, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

On Tue, Mar 10, 2015 at 11:10 PM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:

> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> In acpi_gpiochip_request_interrupts() the handle local
> variable already contains the value that we want to pass
> to acpi_walk_resources(), so it is better to use that
> variable instead of evaluating ACPI_HANDLE() once more
> for the same device.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Patch applied with Mika's ACK.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()
  2015-03-10 22:07 [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
  2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
  2015-03-10 22:10 ` [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE() Rafael J. Wysocki
@ 2015-03-18  1:37 ` Rafael J. Wysocki
  2015-03-18  1:47   ` Alexandre Courbot
  2 siblings, 1 reply; 11+ messages in thread
From: Rafael J. Wysocki @ 2015-03-18  1:37 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot
  Cc: linux-gpio, Linux Kernel Mailing List, ACPI Devel Maling List,
	Mika Westerberg

On Tuesday, March 10, 2015 11:07:36 PM Rafael J. Wysocki wrote:
> Hi,
> 
> As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is
> rather costly.

Linus, Alexandre, any objections to this series?

If not, would there be any problem if I took these to my tree?  I'll probably
have material on top of them.

Rafael


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()
  2015-03-18  1:37 ` [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
@ 2015-03-18  1:47   ` Alexandre Courbot
  2015-03-18 14:37     ` Rafael J. Wysocki
  0 siblings, 1 reply; 11+ messages in thread
From: Alexandre Courbot @ 2015-03-18  1:47 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linus Walleij, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

On Wed, Mar 18, 2015 at 10:37 AM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> On Tuesday, March 10, 2015 11:07:36 PM Rafael J. Wysocki wrote:
>> Hi,
>>
>> As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is
>> rather costly.
>
> Linus, Alexandre, any objections to this series?
>
> If not, would there be any problem if I took these to my tree?  I'll probably
> have material on top of them.

Sorry for the delay. Looks like Linus just took the patches in his
tree, I hope that's ok?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE()
  2015-03-18  1:47   ` Alexandre Courbot
@ 2015-03-18 14:37     ` Rafael J. Wysocki
  0 siblings, 0 replies; 11+ messages in thread
From: Rafael J. Wysocki @ 2015-03-18 14:37 UTC (permalink / raw)
  To: Alexandre Courbot
  Cc: Linus Walleij, linux-gpio, Linux Kernel Mailing List,
	ACPI Devel Maling List, Mika Westerberg

On Wednesday, March 18, 2015 10:47:30 AM Alexandre Courbot wrote:
> On Wed, Mar 18, 2015 at 10:37 AM, Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> > On Tuesday, March 10, 2015 11:07:36 PM Rafael J. Wysocki wrote:
> >> Hi,
> >>
> >> As per the subject, avoid evaluating ACPI_HANDLE() if we can as that one is
> >> rather costly.
> >
> > Linus, Alexandre, any objections to this series?
> >
> > If not, would there be any problem if I took these to my tree?  I'll probably
> > have material on top of them.
> 
> Sorry for the delay. Looks like Linus just took the patches in his
> tree, I hope that's ok?

Yes, that's fine, thanks!


-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-03-18 14:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-10 22:07 [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
2015-03-10 22:08 ` [PATCH 1/2] gpio / ACPI: Avoid unnecessary checks in __gpiod_get_index() Rafael J. Wysocki
2015-03-11  1:36   ` Hanjun Guo
2015-03-11  8:43   ` Mika Westerberg
2015-03-18  1:33   ` Linus Walleij
2015-03-10 22:10 ` [PATCH 2/2] gpio / ACPI: Use local variable instead of ACPI_HANDLE() Rafael J. Wysocki
2015-03-11  8:43   ` Mika Westerberg
2015-03-18  1:35   ` Linus Walleij
2015-03-18  1:37 ` [PATCH 0/2] gpio / ACPI: Two minor cleanups related to ACPI_HANDLE() Rafael J. Wysocki
2015-03-18  1:47   ` Alexandre Courbot
2015-03-18 14:37     ` Rafael J. Wysocki

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).