Re: [PATCH] base: power: domain: Replace mdelay with msleep
From: Lucas Stach
Date: Mon Feb 12 2018 - 05:38:30 EST
Am Freitag, den 09.02.2018, 14:58 +0100 schrieb Ulf Hansson:
> On 26 January 2018 at 09:38, Jia-Ju Bai <baijiaju1990@xxxxxxxxx>
> 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@xxxxxxxxx>
> > ---
> > Â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