linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Daniel Vetter <daniel@ffwll.ch>, Lukas Wunner <lukas@wunner.de>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Russell King - ARM Linux <linux@armlinux.org.uk>,
	Lucas Stach <l.stach@pengutronix.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Joerg Roedel <jroedel@suse.de>
Subject: Re: [PATCH v2 0/9] driver core: Fix some device links issues and add "consumer autoprobe" flag
Date: Wed, 6 Feb 2019 12:23:26 +0100	[thread overview]
Message-ID: <CAPDyKFoUfM8kopWfkorDhVKfk35wVaKVPzJeZ55RPRdc2Y1MYw@mail.gmail.com> (raw)
In-Reply-To: <CAJZ5v0gBYyoumVkLTuEcHsFE8QKEXdYuhDRGwmvoKPhx7gPvgQ@mail.gmail.com>

On Wed, 6 Feb 2019 at 10:56, Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Tue, Feb 5, 2019 at 12:27 PM Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
> >
> > On Tuesday, February 5, 2019 9:15:49 AM CET Ulf Hansson wrote:
> > > On Mon, 4 Feb 2019 at 12:45, Rafael J. Wysocki <rafael@kernel.org> wrote:
> > > >
> > > > On Mon, Feb 4, 2019 at 12:40 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> > > > >
> > > > > On Fri, Feb 1, 2019 at 4:18 PM Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> [cut]
>
> > > >
> > > > For example, if the consumer device is suspended after the
> > > > device_link_add() that incremented the supplier's PM-runtime count and
> > > > then resumed again, the rpm_active refcount will be greater than one
> > > > because of the last resume and not because of the initial link
> > > > creation.  In that case, dropping the supplier's PM-runtime count on
> > > > link deletion may not work as expected.
> > >
> > > I see what your are saying and I must admit, by looking at the code,
> > > that it has turned into being rather complicated. Assuming of good
> > > reasons, of course.
> > >
> > > Anyway, I will play a little bit more with my tests to see what I can find out.
> > >
> > > >
> > > > > Arguably, device_link_del() could be made automatically drop the
> > > > > supplier's PM-runtime count by one if the link's rpm_active refcount
> > > > > is not one, but there will be failing scenarios in that case too
> > > > > AFAICS.
> > >
> > > Let's see.
> >
> > So for the record, below is the (untested) patch I'm thinking about.
> >
> > Having considered this for some time, I think that it would be better to
> > try to drop the supplier's PM-runtime usage counter on link removal even if
> > the link doesn't go away then.  That would be more consistent at least IMO.
>
> So I can't convince myself that this is the case.
>
> Either way, if there are two callers of device_link_add() for one
> consumer-supplier pair trying to add a stateless link between them and
> one of these callers passes DL_FLAG_RPM_ACTIVE set in the flags to it,
> there may be issues regardless of what device_link_del() and
> device_link_remove() do.  However, if they decrement the link's
> rpm_active refcount (and possibly the supplier's PM-runtime usage
> counter too), the supplier may be suspended prematurely, whereas in
> the other case (no decrementation of rpm_active, which how the code
> works after this series) it may just be prevented from suspending.  To
> me, the former is worse than the latter.

Well, I would say it sucks in both cases. :-)

>
> Moreover, there is a workaround for the latter issue that seems to be
> easy enough: it is sufficient to let the consumer runtime suspend
> after calling device_link_add() to create the link (with
> DL_FLAG_RPM_ACTIVE set) and before trying to remove it.

I get your point, but unfortunate I don't think it's that simple.

For example, someone (like a child) may prevent runtime suspend for
the consumer. Hence, also the supplier is prevented from being runtime
suspended.

So, if you want to push this responsibility to the driver, then I
think we need make __pm_runtime_set_status() to respect device links,
similar to how it already deals with child/parents.

In that way, the driver could call pm_runtime_set_suspended(), before
dropping the device link in ->probe(), which would allow the supplier
to also become runtime suspended.

I did a quick research of users of device links, unless I am mistaken,
this seems like an okay approach.

What do you think?

>
> Because of the above, I'm just going to post a patch to document the
> current behavior of the code as a known limitation.

Let's not give up, yet, please. I am sure we can figure something out.

Kind regards
Uffe

  reply	other threads:[~2019-02-06 11:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-01  0:44 [PATCH v2 0/9] driver core: Fix some device links issues and add "consumer autoprobe" flag Rafael J. Wysocki
2019-02-01  0:45 ` [PATCH v2 1/9] driver core: Fix DL_FLAG_AUTOREMOVE_SUPPLIER device link flag handling Rafael J. Wysocki
2019-02-01  0:46 ` [PATCH v2 2/9] driver core: Avoid careless re-use of existing device links Rafael J. Wysocki
2019-02-07 19:03   ` Lukas Wunner
2019-02-07 19:11     ` Rafael J. Wysocki
2019-02-01  0:47 ` [PATCH v2 3/9] driver core: Do not resume suppliers under device_links_write_lock() Rafael J. Wysocki
2019-02-01  0:49 ` [PATCH v2 4/9] driver core: Fix handling of runtime PM flags in device_link_add() Rafael J. Wysocki
2019-02-07 19:15   ` Lukas Wunner
2019-02-07 19:20     ` Rafael J. Wysocki
2019-02-01  0:50 ` [PATCH v2 5/9] driver core: Fix adding device links to probing suppliers Rafael J. Wysocki
2019-02-01  0:52 ` [PATCH v2 6/9] driver core: Do not call rpm_put_suppliers() in pm_runtime_drop_link() Rafael J. Wysocki
2019-02-01  0:54 ` [PATCH v2 7/9] IOMMU: Make dwo drivers use stateless device links Rafael J. Wysocki
2019-02-01  0:58 ` [PATCH v2 8/9] driver core: Make driver core own stateful " Rafael J. Wysocki
2019-02-01  0:59 ` [PATCH v2 9/9] driver core: Add device link flag DL_FLAG_AUTOPROBE_CONSUMER Rafael J. Wysocki
2019-02-01  9:05 ` [PATCH v2 0/9] driver core: Fix some device links issues and add "consumer autoprobe" flag Greg Kroah-Hartman
2019-02-01  9:45   ` Rafael J. Wysocki
2019-02-01 15:17 ` Ulf Hansson
2019-02-04 11:40   ` Rafael J. Wysocki
2019-02-04 11:45     ` Rafael J. Wysocki
2019-02-05  8:15       ` Ulf Hansson
2019-02-05 11:26         ` Rafael J. Wysocki
2019-02-06  9:56           ` Rafael J. Wysocki
2019-02-06 11:23             ` Ulf Hansson [this message]
2019-02-06 12:10               ` Rafael J. Wysocki
2019-02-06 13:02                 ` Ulf Hansson
2019-02-06 23:16                   ` Rafael J. Wysocki

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=CAPDyKFoUfM8kopWfkorDhVKfk35wVaKVPzJeZ55RPRdc2Y1MYw@mail.gmail.com \
    --to=ulf.hansson@linaro.org \
    --cc=a.hajda@samsung.com \
    --cc=daniel@ffwll.ch \
    --cc=gregkh@linuxfoundation.org \
    --cc=jroedel@suse.de \
    --cc=l.stach@pengutronix.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=lukas@wunner.de \
    --cc=m.szyprowski@samsung.com \
    --cc=rafael@kernel.org \
    --cc=rjw@rjwysocki.net \
    --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;
as well as URLs for NNTP newsgroup(s).