2018-01-26 08:35:49

by Jia-Ju Bai

[permalink] [raw]
Subject: [PATCH] base: power: domain: Replace mdelay with msleep

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 <[email protected]>
---
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



2018-01-26 10:26:45

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep

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 <[email protected]>
> ---
> 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


Attachments:
(No filename) (1.40 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-01-26 10:29:30

by Jia-Ju Bai

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep



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

2018-02-09 12:01:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep

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 <[email protected]>
> ---
> 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?


2018-02-09 13:59:54

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep

On 26 January 2018 at 09:38, Jia-Ju Bai <[email protected]> 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 <[email protected]>
> ---
> 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

2018-02-12 13:14:41

by Lucas Stach

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep

Am Freitag, den 09.02.2018, 14:58 +0100 schrieb Ulf Hansson:
> On 26 January 2018 at 09:38, Jia-Ju Bai <[email protected]>
> 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 <[email protected]>
> > ---
> >  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

2018-02-12 16:51:13

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] base: power: domain: Replace mdelay with msleep

On 12 February 2018 at 11:38, Lucas Stach <[email protected]> wrote:
> Am Freitag, den 09.02.2018, 14:58 +0100 schrieb Ulf Hansson:
>> On 26 January 2018 at 09:38, Jia-Ju Bai <[email protected]>
>> 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 <[email protected]>
>> > ---
>> > 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