From: zhangqilong <zhangqilong3@huawei.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
"fugang.duan@nxp.com" <fugang.duan@nxp.com>,
David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Linux PM <linux-pm@vger.kernel.org>,
netdev <netdev@vger.kernel.org>
Subject: 答复: [PATCH 1/2] PM: runtime: Add a general runtime get sync operation to deal with usage counter
Date: Mon, 9 Nov 2020 14:19:56 +0000 [thread overview]
Message-ID: <0f736cff81274310a3dd7c174af4ede4@huawei.com> (raw)
In-Reply-To: <CAJZ5v0ggJCFqqmFVGmxEf2MRckLU6GsF=V=cnzfveyOqOMfVZg@mail.gmail.com>
> On Mon, Nov 9, 2020 at 2:46 PM zhangqilong <zhangqilong3@huawei.com>
> wrote:
> >
> > Hi,
> >
> > >
> > > On Mon, Nov 9, 2020 at 2:24 PM zhangqilong <zhangqilong3@huawei.com>
> > > wrote:
> > > >
> > > > Hi
> > > > >
> > > > > On Mon, Nov 9, 2020 at 9:05 AM Zhang Qilong
> > > > > <zhangqilong3@huawei.com>
> > > > > wrote:
> > > > > >
> > > > > > In many case, we need to check return value of
> > > > > > pm_runtime_get_sync, but it brings a trouble to the usage
> > > > > > counter processing. Many callers forget to decrease the usage
> > > > > > counter when it failed. It has been discussed a lot[0][1]. So
> > > > > > we add a function to deal with the usage counter for better coding.
> > > > > >
> > > > > > [0]https://lkml.org/lkml/2020/6/14/88
> > > > > > [1]https://patchwork.ozlabs.org/project/linux-tegra/patch/2020
> > > > > > 0520
> > > > > > 0951 48.10995-1-dinghao.liu@zju.edu.cn/
> > > > > > Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> > > > > > ---
> > > > > > include/linux/pm_runtime.h | 32
> > > ++++++++++++++++++++++++++++++++
> > > > > > 1 file changed, 32 insertions(+)
> > > > > >
> > > > > > diff --git a/include/linux/pm_runtime.h
> > > > > > b/include/linux/pm_runtime.h index 4b708f4e8eed..2b0af5b1dffd
> > > > > > 100644
> > > > > > --- a/include/linux/pm_runtime.h
> > > > > > +++ b/include/linux/pm_runtime.h
> > > > > > @@ -386,6 +386,38 @@ static inline int
> > > > > > pm_runtime_get_sync(struct device
> > > > > *dev)
> > > > > > return __pm_runtime_resume(dev, RPM_GET_PUT); }
> > > > > >
> > > > > > +/**
> > > > > > + * gene_pm_runtime_get_sync - Bump up usage counter of a
> > > > > > +device and
> > > > > resume it.
> > > > > > + * @dev: Target device.
> > > > >
> > > > > The force argument is not documented.
> > > >
> > > > (1) Good catch, I will add it in next version.
> > > >
> > > > >
> > > > > > + *
> > > > > > + * Increase runtime PM usage counter of @dev first, and carry
> > > > > > + out runtime-resume
> > > > > > + * of it synchronously. If __pm_runtime_resume return
> > > > > > + negative value(device is in
> > > > > > + * error state) or return positive value(the runtime of
> > > > > > + device is already active)
> > > > > > + * with force is true, it need decrease the usage counter of
> > > > > > + the device when
> > > > > > + * return.
> > > > > > + *
> > > > > > + * The possible return values of this function is zero or negative value.
> > > > > > + * zero:
> > > > > > + * - it means success and the status will store the resume
> operation
> > > > > status
> > > > > > + * if needed, the runtime PM usage counter of @dev remains
> > > > > incremented.
> > > > > > + * negative:
> > > > > > + * - it means failure and the runtime PM usage counter of @dev
> has
> > > > > been
> > > > > > + * decreased.
> > > > > > + * positive:
> > > > > > + * - it means the runtime of the device is already active before
> that.
> > > If
> > > > > > + * caller set force to true, we still need to decrease the usage
> > > > > counter.
> > > > >
> > > > > Why is this needed?
> > > >
> > > > (2) If caller set force, it means caller will return even the
> > > > device has already been active (__pm_runtime_resume return
> > > > positive value) after calling gene_pm_runtime_get_sync, we still
> > > > need to decrease the
> > > usage count.
> > >
> > > But who needs this?
> > >
> > > I don't think that it is a good idea to complicate the API this way.
> >
> > The callers like:
> > ret = pm_runtime_get_sync(dev);
> > if (ret) {
> > ...
> > return (xxx);
> > }
>
> Which isn't correct really, is it?
>
> If ret is greater than 0, the error should not be returned in the first place, so
> you may want the new wrapper to return zero in that case instead.
I get your idea.
>
> > drivers/spi/spi-img-spfi.c:734 img_spfi_resume() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/mfd/arizona-core.c:49 arizona_clk32k_enable() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/usb/dwc3/dwc3-pci.c:212 dwc3_pci_resume_work() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/input/keyboard/omap4-keypad.c:279 omap4_keypad_probe() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/gpu/drm/vc4/vc4_dsi.c:839 vc4_dsi_encoder_enable() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/gpu/drm/i915/selftests/mock_gem_device.c:157 mock_gem_device()
> > warn: 'pm_runtime_get_sync(&pdev->dev)' returns positive and negative
> > drivers/watchdog/rti_wdt.c:230 rti_wdt_probe() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/media/platform/exynos4-is/mipi-csis.c:513 s5pcsis_s_stream()
> > warn: pm_runtime_get_sync() also returns 1 on success
> > drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c:89
> > mtk_vcodec_dec_pw_on() warn: pm_runtime_get_sync() also returns 1 on
> > success
> > drivers/media/platform/ti-vpe/cal.c:794 cal_probe() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/media/platform/ti-vpe/vpe.c:2478 vpe_runtime_get() warn:
> > pm_runtime_get_sync() also returns 1 on success
> > drivers/media/i2c/smiapp/smiapp-core.c:1529 smiapp_pm_get_init() warn:
> > pm_runtime_get_sync() also returns 1 on success ...
> > they need it to simplify the function.
> >
> > If we only want to simplify like
> > ret = pm_runtime_get_sync(dev);
> > if (ret < 0) {
> > ...
> > Return (xxx)
> > }
> > The parameter force could be removed.
>
> Which is exactly my point.
OK, I re-code it next version.
Thanks,
Zhang
next prev parent reply other threads:[~2020-11-09 14:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 8:09 [PATCH 0/2] Fix usage counter leak by adding a general sync ops Zhang Qilong
2020-11-09 8:09 ` [PATCH 1/2] PM: runtime: Add a general runtime get sync operation to deal with usage counter Zhang Qilong
2020-11-09 12:59 ` Rafael J. Wysocki
2020-11-09 13:24 ` 答复: " zhangqilong
2020-11-09 13:28 ` Rafael J. Wysocki
2020-11-09 13:45 ` 答复: " zhangqilong
2020-11-09 14:07 ` Rafael J. Wysocki
2020-11-09 14:19 ` zhangqilong [this message]
2020-11-09 8:09 ` [PATCH 2/2] net: fec: Fix reference count leak in fec series ops Zhang Qilong
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=0f736cff81274310a3dd7c174af4ede4@huawei.com \
--to=zhangqilong3@huawei.com \
--cc=davem@davemloft.net \
--cc=fugang.duan@nxp.com \
--cc=kuba@kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=rjw@rjwysocki.net \
/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;
as well as URLs for NNTP newsgroup(s).