linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] base: power: domain: Replace mdelay with msleep
@ 2018-01-26  8:38 Jia-Ju Bai
  2018-01-26 10:26 ` Pavel Machek
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jia-Ju Bai @ 2018-01-26  8:38 UTC (permalink / raw)
  To: rjw, khilman, ulf.hansson, len.brown, pavel, gregkh
  Cc: linux-pm, linux-kernel, Jia-Ju Bai

After checking all possible call chains to genpd_dev_pm_detach() and
genpd_dev_pm_attach() here,
my tool finds that these functions are never called in atomic context,
namely never in an interrupt handler or holding a spinlock.
Thus mdelay can be replaced with msleep to avoid busy wait.

This is found by a static analysis tool named DCNS written by myself.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/base/power/domain.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 0c80bea..f84ac72 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
 		if (ret != -EAGAIN)
 			break;
 
-		mdelay(i);
+		msleep(i);
 		cond_resched();
 	}
 
@@ -2231,7 +2231,7 @@ int genpd_dev_pm_attach(struct device *dev)
 		if (ret != -EAGAIN)
 			break;
 
-		mdelay(i);
+		msleep(i);
 		cond_resched();
 	}
 	mutex_unlock(&gpd_list_lock);
-- 
1.7.9.5

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-01-26  8:38 [PATCH] base: power: domain: Replace mdelay with msleep Jia-Ju Bai
@ 2018-01-26 10:26 ` Pavel Machek
  2018-01-26 10:28   ` Jia-Ju Bai
  2018-02-09 11:56 ` Rafael J. Wysocki
  2018-02-09 13:58 ` Ulf Hansson
  2 siblings, 1 reply; 7+ messages in thread
From: Pavel Machek @ 2018-01-26 10:26 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: rjw, khilman, ulf.hansson, len.brown, gregkh, linux-pm, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1438 bytes --]

On Fri 2018-01-26 16:38:19, Jia-Ju Bai wrote:
> After checking all possible call chains to genpd_dev_pm_detach() and
> genpd_dev_pm_attach() here,
> my tool finds that these functions are never called in atomic context,
> namely never in an interrupt handler or holding a spinlock.
> Thus mdelay can be replaced with msleep to avoid busy wait.
> 
> This is found by a static analysis tool named DCNS written by
myself.

Well, cond_resched() just after msleep certainly looks like that.

Did the patch receive any testing?

> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/base/power/domain.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 0c80bea..f84ac72 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
>  		if (ret != -EAGAIN)
>  			break;
>  
> -		mdelay(i);
> +		msleep(i);
>  		cond_resched();
>  	}
>  
> @@ -2231,7 +2231,7 @@ int genpd_dev_pm_attach(struct device *dev)
>  		if (ret != -EAGAIN)
>  			break;
>  
> -		mdelay(i);
> +		msleep(i);
>  		cond_resched();
>  	}
>  	mutex_unlock(&gpd_list_lock);

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-01-26 10:26 ` Pavel Machek
@ 2018-01-26 10:28   ` Jia-Ju Bai
  0 siblings, 0 replies; 7+ messages in thread
From: Jia-Ju Bai @ 2018-01-26 10:28 UTC (permalink / raw)
  To: Pavel Machek
  Cc: rjw, khilman, ulf.hansson, len.brown, gregkh, linux-pm, linux-kernel



On 2018/1/26 18:26, Pavel Machek wrote:
> On Fri 2018-01-26 16:38:19, Jia-Ju Bai wrote:
>> After checking all possible call chains to genpd_dev_pm_detach() and
>> genpd_dev_pm_attach() here,
>> my tool finds that these functions are never called in atomic context,
>> namely never in an interrupt handler or holding a spinlock.
>> Thus mdelay can be replaced with msleep to avoid busy wait.
>>
>> This is found by a static analysis tool named DCNS written by
> myself.
>
> Well, cond_resched() just after msleep certainly looks like that.
>
> Did the patch receive any testing?
>

Thanks for reply :)

I only perform compilation testing but did not run it in real execution.


Thanks,
Jia-Ju Bai

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-01-26  8:38 [PATCH] base: power: domain: Replace mdelay with msleep Jia-Ju Bai
  2018-01-26 10:26 ` Pavel Machek
@ 2018-02-09 11:56 ` Rafael J. Wysocki
  2018-02-09 13:58 ` Ulf Hansson
  2 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2018-02-09 11:56 UTC (permalink / raw)
  To: Jia-Ju Bai, khilman, ulf.hansson
  Cc: len.brown, pavel, gregkh, linux-pm, linux-kernel

On Friday, January 26, 2018 9:38:19 AM CET Jia-Ju Bai wrote:
> After checking all possible call chains to genpd_dev_pm_detach() and
> genpd_dev_pm_attach() here,
> my tool finds that these functions are never called in atomic context,
> namely never in an interrupt handler or holding a spinlock.
> Thus mdelay can be replaced with msleep to avoid busy wait.
> 
> This is found by a static analysis tool named DCNS written by myself.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/base/power/domain.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 0c80bea..f84ac72 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
>  		if (ret != -EAGAIN)
>  			break;
>  
> -		mdelay(i);
> +		msleep(i);
>  		cond_resched();
>  	}
>  
> @@ -2231,7 +2231,7 @@ int genpd_dev_pm_attach(struct device *dev)
>  		if (ret != -EAGAIN)
>  			break;
>  
> -		mdelay(i);
> +		msleep(i);
>  		cond_resched();
>  	}
>  	mutex_unlock(&gpd_list_lock);
> 

Ulf, Kevin, any concerns or objections?

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-01-26  8:38 [PATCH] base: power: domain: Replace mdelay with msleep Jia-Ju Bai
  2018-01-26 10:26 ` Pavel Machek
  2018-02-09 11:56 ` Rafael J. Wysocki
@ 2018-02-09 13:58 ` Ulf Hansson
  2018-02-12 10:38   ` Lucas Stach
  2 siblings, 1 reply; 7+ messages in thread
From: Ulf Hansson @ 2018-02-09 13:58 UTC (permalink / raw)
  To: Jia-Ju Bai
  Cc: Rafael J. Wysocki, Kevin Hilman, Len Brown, Pavel Machek,
	Greg Kroah-Hartman, Linux PM, Linux Kernel Mailing List

On 26 January 2018 at 09:38, Jia-Ju Bai <baijiaju1990@gmail.com> wrote:
> After checking all possible call chains to genpd_dev_pm_detach() and
> genpd_dev_pm_attach() here,
> my tool finds that these functions are never called in atomic context,
> namely never in an interrupt handler or holding a spinlock.
> Thus mdelay can be replaced with msleep to avoid busy wait.
>
> This is found by a static analysis tool named DCNS written by myself.
>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/base/power/domain.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index 0c80bea..f84ac72 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
>                 if (ret != -EAGAIN)
>                         break;
>
> -               mdelay(i);
> +               msleep(i);

This looks like a nice improvement, however moving to msleep() makes
the call to cond_resched() below a bit superfluous. Perhaps remove
that as well.

>                 cond_resched();
>         }
>
> @@ -2231,7 +2231,7 @@ int genpd_dev_pm_attach(struct device *dev)
>                 if (ret != -EAGAIN)
>                         break;
>
> -               mdelay(i);
> +               msleep(i);

Ditto.

>                 cond_resched();
>         }
>         mutex_unlock(&gpd_list_lock);
> --
> 1.7.9.5
>

Kind regards
Uffe

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-02-09 13:58 ` Ulf Hansson
@ 2018-02-12 10:38   ` Lucas Stach
  2018-02-12 12:40     ` Ulf Hansson
  0 siblings, 1 reply; 7+ messages in thread
From: Lucas Stach @ 2018-02-12 10:38 UTC (permalink / raw)
  To: Ulf Hansson, Jia-Ju Bai
  Cc: Rafael J. Wysocki, Kevin Hilman, Len Brown, Pavel Machek,
	Greg Kroah-Hartman, Linux PM, Linux Kernel Mailing List

Am Freitag, den 09.02.2018, 14:58 +0100 schrieb Ulf Hansson:
> On 26 January 2018 at 09:38, Jia-Ju Bai <baijiaju1990@gmail.com>
> wrote:
> > After checking all possible call chains to genpd_dev_pm_detach()
> > and
> > genpd_dev_pm_attach() here,
> > my tool finds that these functions are never called in atomic
> > context,
> > namely never in an interrupt handler or holding a spinlock.
> > Thus mdelay can be replaced with msleep to avoid busy wait.
> > 
> > This is found by a static analysis tool named DCNS written by
> > myself.
> > 
> > Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> > ---
> >  drivers/base/power/domain.c |    4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/base/power/domain.c
> > b/drivers/base/power/domain.c
> > index 0c80bea..f84ac72 100644
> > --- a/drivers/base/power/domain.c
> > +++ b/drivers/base/power/domain.c
> > @@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device
> > *dev, bool power_off)
> >                 if (ret != -EAGAIN)
> >                         break;
> > 
> > -               mdelay(i);
> > +               msleep(i);
> 
> This looks like a nice improvement, however moving to msleep() makes
> the call to cond_resched() below a bit superfluous. Perhaps remove
> that as well.

At least for small values of i, msleep also has a high chance to
overshoot the desired sleep by a lot. It would be better to convert
them to usleep_range with an acceptable slack.

Regards,
Lucas

> >                 cond_resched();
> >         }
> > 
> > @@ -2231,7 +2231,7 @@ int genpd_dev_pm_attach(struct device *dev)
> >                 if (ret != -EAGAIN)
> >                         break;
> > 
> > -               mdelay(i);
> > +               msleep(i);
> 
> Ditto.
> 
> >                 cond_resched();
> >         }
> >         mutex_unlock(&gpd_list_lock);
> > --
> > 1.7.9.5
> > 
> 
> Kind regards
> Uffe

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

* Re: [PATCH] base: power: domain: Replace mdelay with msleep
  2018-02-12 10:38   ` Lucas Stach
@ 2018-02-12 12:40     ` Ulf Hansson
  0 siblings, 0 replies; 7+ messages in thread
From: Ulf Hansson @ 2018-02-12 12:40 UTC (permalink / raw)
  To: Lucas Stach
  Cc: Jia-Ju Bai, Rafael J. Wysocki, Kevin Hilman, Len Brown,
	Pavel Machek, Greg Kroah-Hartman, Linux PM,
	Linux Kernel Mailing List

On 12 February 2018 at 11:38, Lucas Stach <l.stach@pengutronix.de> wrote:
> Am Freitag, den 09.02.2018, 14:58 +0100 schrieb Ulf Hansson:
>> On 26 January 2018 at 09:38, Jia-Ju Bai <baijiaju1990@gmail.com>
>> wrote:
>> > After checking all possible call chains to genpd_dev_pm_detach()
>> > and
>> > genpd_dev_pm_attach() here,
>> > my tool finds that these functions are never called in atomic
>> > context,
>> > namely never in an interrupt handler or holding a spinlock.
>> > Thus mdelay can be replaced with msleep to avoid busy wait.
>> >
>> > This is found by a static analysis tool named DCNS written by
>> > myself.
>> >
>> > Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> > ---
>> >  drivers/base/power/domain.c |    4 ++--
>> >  1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/drivers/base/power/domain.c
>> > b/drivers/base/power/domain.c
>> > index 0c80bea..f84ac72 100644
>> > --- a/drivers/base/power/domain.c
>> > +++ b/drivers/base/power/domain.c
>> > @@ -2144,7 +2144,7 @@ static void genpd_dev_pm_detach(struct device
>> > *dev, bool power_off)
>> >                 if (ret != -EAGAIN)
>> >                         break;
>> >
>> > -               mdelay(i);
>> > +               msleep(i);
>>
>> This looks like a nice improvement, however moving to msleep() makes
>> the call to cond_resched() below a bit superfluous. Perhaps remove
>> that as well.
>
> At least for small values of i, msleep also has a high chance to
> overshoot the desired sleep by a lot. It would be better to convert
> them to usleep_range with an acceptable slack.

Ack!

[...]

Kind regards
Uffe

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

end of thread, other threads:[~2018-02-12 12:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26  8:38 [PATCH] base: power: domain: Replace mdelay with msleep Jia-Ju Bai
2018-01-26 10:26 ` Pavel Machek
2018-01-26 10:28   ` Jia-Ju Bai
2018-02-09 11:56 ` Rafael J. Wysocki
2018-02-09 13:58 ` Ulf Hansson
2018-02-12 10:38   ` Lucas Stach
2018-02-12 12:40     ` Ulf Hansson

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