From: Johan Hovold <johan@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove()
Date: Fri, 12 May 2023 17:00:52 +0200 [thread overview]
Message-ID: <ZF5UpOzmvXLX-056@hovoldconsulting.com> (raw)
In-Reply-To: <CAJZ5v0gRcaL5y4nyDcFYfnH8sNYOHSHZN1qwcv+Z7yu4jhSiMA@mail.gmail.com>
On Fri, May 12, 2023 at 04:04:59PM +0200, Rafael J. Wysocki wrote:
> On Fri, May 12, 2023 at 9:39 AM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Thu, May 11, 2023 at 04:44:25PM +0200, Rafael J. Wysocki wrote:
> > > On Thu, May 11, 2023 at 1:48 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > > > No, this seems like very bad idea and even violates the documentation
> > > > which clearly states that the usage counter is balanced before calling
> > > > remove() so that drivers can use pm_runtime_suspend() to put devices
> > > > into suspended state.
> > >
> > > I missed that, sorry.
> > >
> > > > There's is really no good reason to even try to change as this is in no
> > > > way a fast path.
> > >
> > > Still, I think that while the "put" part needs to be done before
> > > device_remove(), the actual state change can be carried out later.
> > >
> > > So something like
> > >
> > > pm_runtime_put_noidle(dev);
> > >
> > > device_remove(dev);
> > >
> > > pm_runtime_suspend(dev);
> > >
> > > would generally work, wouldn't it?
> >
> > No, as drivers typically disable runtime pm in their remove callbacks,
>
> What exactly do you mean by "typically"? None of the PCI drivers
> should do that, for instance.
I had platform drivers in mind, but so do i2c drivers for example.
> > that pm_runtime_suspend() would amount to a no-op (and calling the
> > driver pm ops post unbind and the driver having freed its data would
> > not work either).
>
> Well, not really.
>
> There are drivers and there are bus types/PM domains. Drivers need
> not disable PM-runtime in their "remove" callbacks if they know that
> the bus type/PM domain will take care of handling PM-runtime properly
> after the driver's remove callback has run and the bus type/PM domain
> may very well want its PM-runtime suspend callback to run then (for
> example, to remove power from the unused device). Arguably it can
> invoke runtime_suspend() from its "remove" callback, so it's not like
> this is a big deal, but IMO it helps if the most general case is
> considered.
My point was that hundreds of drivers do and for these this call becomes
a no-op. Same for buses that disable runtime pm at remove.
> Anyway, the question here really is: Does it make sense to carry out a
> runtime suspend immediately before device_remove()? Honestly, I'm not
> sure about that.
I'd say it doesn't really matter as driver unbind is not a common
operation and drivers using autosuspend would generally not be affected
either.
You can try to rework this, but clearly it needs more thought than
simply moving the put sync and some drivers may also be relying on the
current behaviour.
A quick grep reveals a few which would be left active if you change
pm_runtime_put_sync() to pm_runtime_put_noidle(), even if that could be
fixed driver by driver of course.
Johan
next prev parent reply other threads:[~2023-05-12 15:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 7:34 [PATCH] driver core: Call pm_runtime_put_sync() only after device_remove() Uwe Kleine-König
2023-05-11 10:18 ` Rafael J. Wysocki
2023-05-11 10:39 ` Uwe Kleine-König
2023-05-11 11:48 ` Johan Hovold
2023-05-11 14:44 ` Rafael J. Wysocki
2023-05-12 7:40 ` Johan Hovold
2023-05-12 14:04 ` Rafael J. Wysocki
2023-05-12 15:00 ` Johan Hovold [this message]
2023-05-12 15:04 ` Rafael J. Wysocki
2023-05-12 18:49 ` Uwe Kleine-König
2023-05-17 8:28 ` Johan Hovold
2023-05-17 9:55 ` Marc Kleine-Budde
2023-05-11 14:46 ` Uwe Kleine-König
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=ZF5UpOzmvXLX-056@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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