public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: Dmitry Osipenko <digetx@gmail.com>
Cc: linuxarm@huawei.com, mauro.chehab@huawei.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH 17/78] staging: media: vde: use pm_runtime_resume_and_get()
Date: Tue, 27 Apr 2021 11:22:50 +0200	[thread overview]
Message-ID: <20210427112250.5d40c4f4@coco.lan> (raw)
In-Reply-To: <2349831b-e7cd-d38d-fc19-5fabf06f773e@gmail.com>

Hi Dmitry,

Em Sat, 24 Apr 2021 10:35:22 +0300
Dmitry Osipenko <digetx@gmail.com> escreveu:

> 24.04.2021 09:44, Mauro Carvalho Chehab пишет:
> > Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
> > added pm_runtime_resume_and_get() in order to automatically handle
> > dev->power.usage_count decrement on errors.
> > 
> > Use the new API, in order to cleanup the error check logic.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > ---
> >  drivers/staging/media/tegra-vde/vde.c | 16 ++++++++++------
> >  1 file changed, 10 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/staging/media/tegra-vde/vde.c b/drivers/staging/media/tegra-vde/vde.c
> > index 28845b5bafaf..8936f140a246 100644
> > --- a/drivers/staging/media/tegra-vde/vde.c
> > +++ b/drivers/staging/media/tegra-vde/vde.c
> > @@ -775,9 +775,9 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  	if (ret)
> >  		goto release_dpb_frames;
> >  
> > -	ret = pm_runtime_get_sync(dev);
> > +	ret = pm_runtime_resume_and_get(dev);
> >  	if (ret < 0)
> > -		goto put_runtime_pm;
> > +		goto unlock;
> >  
> >  	/*
> >  	 * We rely on the VDE registers reset value, otherwise VDE
> > @@ -843,6 +843,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde,
> >  put_runtime_pm:
> >  	pm_runtime_mark_last_busy(dev);
> >  	pm_runtime_put_autosuspend(dev);
> > +
> > +unlock:
> >  	mutex_unlock(&vde->lock);
> >  
> >  release_dpb_frames:
> > @@ -1069,8 +1071,8 @@ static int tegra_vde_probe(struct platform_device *pdev)
> >  	 * power-cycle it in order to put hardware into a predictable lower
> >  	 * power state.
> >  	 */
> > -	pm_runtime_get_sync(dev);
> > -	pm_runtime_put(dev);
> > +	if (pm_runtime_resume_and_get(dev) >= 0)
> > +		pm_runtime_put(dev);
> >  
> >  	return 0;
> >  
> > @@ -1088,8 +1090,9 @@ static int tegra_vde_remove(struct platform_device *pdev)
> >  {
> >  	struct tegra_vde *vde = platform_get_drvdata(pdev);
> >  	struct device *dev = &pdev->dev;
> > +	int ret;
> >  
> > -	pm_runtime_get_sync(dev);
> > +	ret = pm_runtime_resume_and_get(dev);
> >  	pm_runtime_dont_use_autosuspend(dev);
> >  	pm_runtime_disable(dev);
> >  
> > @@ -1097,7 +1100,8 @@ static int tegra_vde_remove(struct platform_device *pdev)
> >  	 * Balance RPM state, the VDE power domain is left ON and hardware
> >  	 * is clock-gated. It's safe to reboot machine now.
> >  	 */
> > -	pm_runtime_put_noidle(dev);
> > +	if (ret >= 0)
> > +		pm_runtime_put_noidle(dev);
> >  	clk_disable_unprepare(vde->clk);
> >  
> >  	misc_deregister(&vde->miscdev);
> >   
> 
> Hello Mauro,
> 
> Thank you very much for the patch. It looks to me that the original
> variant was a bit simpler, this patch adds more code lines without
> changing the previous behaviour. Or am I missing something?

While on several places the newer code is simpler, the end goal here is
to replace all occurrences of pm_runtime_get_sync() from the media 
subsystem, due to the number of problems we're having with this:

1. despite its name, this is actually a PM runtime resume call,
   but some developers didn't seem to realize that, as I got this
   pattern on some drivers:

        pm_runtime_get_sync(&client->dev);
        pm_runtime_disable(&client->dev);
        pm_runtime_set_suspended(&client->dev);
        pm_runtime_put_noidle(&client->dev);

   It makes no sense to resume PM just to suspend it again ;-)

   The name of the new variant is a lot clearer:
	pm_runtime_resume_and_get()

2. Usual *_get() methods only increment their use count on success,
   but pm_runtime_get_sync() increments it unconditionally. Due to
   that, several drivers were mistakenly not calling
   pm_runtime_put_noidle() when it fails;

3. Consistency: we did similar changes subsystem wide with
   for instance strlcpy() and strcpy() that got replaced by
   strscpy(). Having all drivers using the same known-to-be-safe
   methods is a good thing;

4. Prevent newer drivers to copy-and-paste a code that it would
   be easier to break if they don't truly understand what's behind
   the scenes.

Thanks,
Mauro

  reply	other threads:[~2021-04-27  9:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-24  6:44 [PATCH 00/78] media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() Mauro Carvalho Chehab
2021-04-24  6:44 ` [PATCH 17/78] staging: media: vde: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
2021-04-24  7:35   ` Dmitry Osipenko
2021-04-27  9:22     ` Mauro Carvalho Chehab [this message]
2021-04-27 12:34       ` Johan Hovold
2021-04-24  6:44 ` [PATCH 18/78] staging: media: csi: " Mauro Carvalho Chehab
2021-04-24  6:44 ` [PATCH 19/78] staging: media: vi: " Mauro Carvalho Chehab
2021-04-28 10:13 ` [PATCH 00/78] media: use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() Dan Carpenter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210427112250.5d40c4f4@coco.lan \
    --to=mchehab+huawei@kernel.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=digetx@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mauro.chehab@huawei.com \
    --cc=mchehab@kernel.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox