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 13:24:42 +0000 [thread overview]
Message-ID: <d05e3d35a68e41e2ac36acfcd577ad47@huawei.com> (raw)
In-Reply-To: <CAJZ5v0gZp_R60FN+ZrKmEn+m0F4yjt_MB+N8uGG=fxKUnZdknQ@mail.gmail.com>
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/202005200951
> > 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.
>
> > + */
> > +static inline int gene_pm_runtime_get_sync(struct device *dev, bool
> > +force)
>
> The name is not really a good one and note that pm_runtime_get() has the
> same problem as _get_sync() (ie. the usage counter is incremented regardless
> of the return value).
>
(3) I have not thought a good name now, if you have good ideas, welcome.
Thanks,
Zhang
> > +{
> > + int ret = 0;
> > +
> > + ret = __pm_runtime_resume(dev, RPM_GET_PUT);
> > + if (ret < 0 || (ret > 0 && force))
> > + pm_runtime_put_noidle(dev);
> > +
> > + return ret;
> > +}
> > +
> > /**
> > * pm_runtime_put - Drop device usage counter and queue up "idle check"
> if 0.
> > * @dev: Target device.
> > --
>
> Thanks!
next prev parent reply other threads:[~2020-11-09 13:24 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 [this message]
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
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=d05e3d35a68e41e2ac36acfcd577ad47@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).