Linux-Renesas-SoC Archive on lore.kernel.org
 help / Atom feed
* [PATCH] PM/runtime: Optimize pm_runtime_autosuspend_expiration()
@ 2019-01-30 21:40 Ladislav Michl
  2019-02-06 10:34 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Ladislav Michl @ 2019-01-30 21:40 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linux PM, Linux Kernel Mailing List, Linux ARM,
	Linux OMAP Mailing List, Ulf Hansson, Biju Das,
	Geert Uytterhoeven, Linux-Renesas, Vincent Guittot

pm_runtime_autosuspend_expiration calls ktime_get_mono_fast_ns
even when its returned value may be unused. Therefore get
current time later and remove gotos while there.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Vincent Guittot <vincent.guittot@linaro.org>
---
 This patch is based on top of bleeding-edge branch, where
 "[PATCH v2 ] PM-runtime: fix deadlock with ktime" is sitting.
 I expect v3 of that patch, which should not harm this one.
 It is meant to replace "PM/runtime: Do not needlessly call ktime_get"
 sent earlier.

 drivers/base/power/runtime.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 65e2b5f48e0c..7bbe28faca8d 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -145,24 +145,21 @@ static void pm_runtime_cancel_pending(struct device *dev)
 u64 pm_runtime_autosuspend_expiration(struct device *dev)
 {
 	int autosuspend_delay;
-	u64 last_busy, expires = 0;
-	u64 now = ktime_get_mono_fast_ns();
+	u64 expires;
 
 	if (!dev->power.use_autosuspend)
-		goto out;
+		return 0;
 
 	autosuspend_delay = READ_ONCE(dev->power.autosuspend_delay);
 	if (autosuspend_delay < 0)
-		goto out;
-
-	last_busy = READ_ONCE(dev->power.last_busy);
+		return 0;
 
-	expires = last_busy + (u64)autosuspend_delay * NSEC_PER_MSEC;
-	if (expires <= now)
-		expires = 0;	/* Already expired. */
+	expires  = READ_ONCE(dev->power.last_busy);
+	expires += (u64)autosuspend_delay * NSEC_PER_MSEC;
+	if (expires > ktime_get_mono_fast_ns())
+		return expires;	/* Expires in the future */
 
- out:
-	return expires;
+	return 0;
 }
 EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
 
-- 
2.20.1


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

* Re: [PATCH] PM/runtime: Optimize pm_runtime_autosuspend_expiration()
  2019-01-30 21:40 [PATCH] PM/runtime: Optimize pm_runtime_autosuspend_expiration() Ladislav Michl
@ 2019-02-06 10:34 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2019-02-06 10:34 UTC (permalink / raw)
  To: Ladislav Michl
  Cc: Rafael J. Wysocki, Linux PM, Linux Kernel Mailing List,
	Linux ARM, Linux OMAP Mailing List, Ulf Hansson, Biju Das,
	Geert Uytterhoeven, Linux-Renesas, Vincent Guittot

On Wednesday, January 30, 2019 10:40:17 PM CET Ladislav Michl wrote:
> pm_runtime_autosuspend_expiration calls ktime_get_mono_fast_ns
> even when its returned value may be unused. Therefore get
> current time later and remove gotos while there.
> 
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> Acked-by: Tony Lindgren <tony@atomide.com>
> Acked-by: Vincent Guittot <vincent.guittot@linaro.org>
> ---
>  This patch is based on top of bleeding-edge branch, where
>  "[PATCH v2 ] PM-runtime: fix deadlock with ktime" is sitting.
>  I expect v3 of that patch, which should not harm this one.
>  It is meant to replace "PM/runtime: Do not needlessly call ktime_get"
>  sent earlier.
> 
>  drivers/base/power/runtime.c | 19 ++++++++-----------
>  1 file changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
> index 65e2b5f48e0c..7bbe28faca8d 100644
> --- a/drivers/base/power/runtime.c
> +++ b/drivers/base/power/runtime.c
> @@ -145,24 +145,21 @@ static void pm_runtime_cancel_pending(struct device *dev)
>  u64 pm_runtime_autosuspend_expiration(struct device *dev)
>  {
>  	int autosuspend_delay;
> -	u64 last_busy, expires = 0;
> -	u64 now = ktime_get_mono_fast_ns();
> +	u64 expires;
>  
>  	if (!dev->power.use_autosuspend)
> -		goto out;
> +		return 0;
>  
>  	autosuspend_delay = READ_ONCE(dev->power.autosuspend_delay);
>  	if (autosuspend_delay < 0)
> -		goto out;
> -
> -	last_busy = READ_ONCE(dev->power.last_busy);
> +		return 0;
>  
> -	expires = last_busy + (u64)autosuspend_delay * NSEC_PER_MSEC;
> -	if (expires <= now)
> -		expires = 0;	/* Already expired. */
> +	expires  = READ_ONCE(dev->power.last_busy);
> +	expires += (u64)autosuspend_delay * NSEC_PER_MSEC;
> +	if (expires > ktime_get_mono_fast_ns())
> +		return expires;	/* Expires in the future */
>  
> - out:
> -	return expires;
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(pm_runtime_autosuspend_expiration);
>  
> 

Applied, thanks!



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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-30 21:40 [PATCH] PM/runtime: Optimize pm_runtime_autosuspend_expiration() Ladislav Michl
2019-02-06 10:34 ` Rafael J. Wysocki

Linux-Renesas-SoC Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-renesas-soc/0 linux-renesas-soc/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-renesas-soc linux-renesas-soc/ https://lore.kernel.org/linux-renesas-soc \
		linux-renesas-soc@vger.kernel.org linux-renesas-soc@archiver.kernel.org
	public-inbox-index linux-renesas-soc


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-renesas-soc


AGPL code for this site: git clone https://public-inbox.org/ public-inbox