All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>, Arnd Bergmann <arnd@arndb.de>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	<linux-media@vger.kernel.org>, <linux-pm@vger.kernel.org>
Subject: Re: [PATCH 1/1] smiapp: Implement power-on and power-off sequences without runtime PM
Date: Sat, 26 Nov 2016 15:10:28 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1611261451230.32289-100000@netrider.rowland.org> (raw)
In-Reply-To: <3007760.0ebxS8fqmr@avalon>

On Fri, 25 Nov 2016, Laurent Pinchart wrote:

> Hi Alan,

Hello.

> On Friday 25 Nov 2016 10:21:21 Alan Stern wrote:
> > On Fri, 25 Nov 2016, Sakari Ailus wrote:
> > > On Thu, Nov 24, 2016 at 09:15:39PM -0500, Alan Stern wrote:
> > >> On Fri, 25 Nov 2016, Laurent Pinchart wrote:
> > >>> Dear linux-pm developers, what's the suggested way to ensure that a
> > >>> runtime- pm-enabled driver can run fine on a system with CONFIG_PM
> > >>> disabled ?
> > >>
> > >> The exact point of your question isn't entirely clear.  In the most
> > >> literal sense, the best ways to ensure this are (1) audit the code, and
> > >> (2) actually try it.
> > >> 
> > >> I have a feeling this doesn't quite answer your question, however.  :-)
> > > 
> > > The question is related to devices that require certain power-up and
> > > power-down sequences that are now implemented as PM runtime hooks that,
> > > without CONFIG_PM defined, will not be executed. Is there a better way
> > > than to handle this than have an implementation in the driver for the PM
> > > runtime and non-PM runtime case separately?
> > 
> > Yes, there is a better way.  For the initial power-up and final
> > power-down sequences, don't rely on the PM core to invoke the
> > callbacks.  Just call them directly, yourself.
> > 
> > For example, as part of the probe routine, instead of doing this:
> > 
> > 	pm_runtime_set_suspended(dev);
> > 	pm_runtime_enable(dev);
> > 	pm_runtime_get_sync(dev);
> > 
> > Do this:
> > 
> > 	pm_runtime_set_active(dev);
> > 	pm_runtime_get_noresume(dev);
> > 	pm_runtime_enable(dev);
> > 	/*
> > 	 * In case CONFIG_PM is disabled, invoke the runtime-resume
> > 	 * callback directly.
> > 	 */
> > 	my_runtime_resume(dev);
> 
> Wouldn't it be cleaner for drivers not to have to handle this manually (which 
> gives an opportunity to get it wrong) but instead have pm_runtime_enable() 
> call the runtime resume callback when CONFIG_PM is disabled ?

Well, I admit it would be nicer if drivers didn't have to worry about 
whether or not CONFIG_PM was enabled.  A slightly cleaner approach 
from the one outlined above would have the probe routine do this:

	my_power_up(dev);
	pm_runtime_set_active(dev);
	pm_runtime_get_noresume(dev);
	pm_runtime_enable(dev);

and have the runtime-resume callback routine call my_power_up() to do
its work.  (Or make my_power_up() actually be the runtime-resume
callback routine.)  That's pretty straightforward and hard to mess up.

In theory, we could have pm_runtime_enable() invoke the runtime-resume
callback when CONFIG_PM is disabled.  In practice, it would be rather 
awkward.  drivers/base/power/runtime.c, which is where 
pm_runtime_enable() is defined and the runtime-PM callbacks are 
invoked, doesn't even get compiled if CONFIG_PM is off.

(Also, it would run against the grain.  CONFIG_PM=n means the kernel
ignores runtime PM, so pm_runtime_enable() shouldn't do anything.)

There's a corollary aspect to this.  If you depend on runtime PM for
powering up your device during probe, does that mean you also depend on
runtime PM for powering down the device during remove?  That is likely
not to work, because the user can prevent runtime suspends by writing
to /sys/.../power/control.

Alan Stern


WARNING: multiple messages have this Message-ID (diff)
From: Alan Stern <stern@rowland.harvard.edu>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Sakari Ailus <sakari.ailus@iki.fi>, Arnd Bergmann <arnd@arndb.de>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH 1/1] smiapp: Implement power-on and power-off sequences without runtime PM
Date: Sat, 26 Nov 2016 15:10:28 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1611261451230.32289-100000@netrider.rowland.org> (raw)
In-Reply-To: <3007760.0ebxS8fqmr@avalon>

On Fri, 25 Nov 2016, Laurent Pinchart wrote:

> Hi Alan,

Hello.

> On Friday 25 Nov 2016 10:21:21 Alan Stern wrote:
> > On Fri, 25 Nov 2016, Sakari Ailus wrote:
> > > On Thu, Nov 24, 2016 at 09:15:39PM -0500, Alan Stern wrote:
> > >> On Fri, 25 Nov 2016, Laurent Pinchart wrote:
> > >>> Dear linux-pm developers, what's the suggested way to ensure that a
> > >>> runtime- pm-enabled driver can run fine on a system with CONFIG_PM
> > >>> disabled ?
> > >>
> > >> The exact point of your question isn't entirely clear.  In the most
> > >> literal sense, the best ways to ensure this are (1) audit the code, and
> > >> (2) actually try it.
> > >> 
> > >> I have a feeling this doesn't quite answer your question, however.  :-)
> > > 
> > > The question is related to devices that require certain power-up and
> > > power-down sequences that are now implemented as PM runtime hooks that,
> > > without CONFIG_PM defined, will not be executed. Is there a better way
> > > than to handle this than have an implementation in the driver for the PM
> > > runtime and non-PM runtime case separately?
> > 
> > Yes, there is a better way.  For the initial power-up and final
> > power-down sequences, don't rely on the PM core to invoke the
> > callbacks.  Just call them directly, yourself.
> > 
> > For example, as part of the probe routine, instead of doing this:
> > 
> > 	pm_runtime_set_suspended(dev);
> > 	pm_runtime_enable(dev);
> > 	pm_runtime_get_sync(dev);
> > 
> > Do this:
> > 
> > 	pm_runtime_set_active(dev);
> > 	pm_runtime_get_noresume(dev);
> > 	pm_runtime_enable(dev);
> > 	/*
> > 	 * In case CONFIG_PM is disabled, invoke the runtime-resume
> > 	 * callback directly.
> > 	 */
> > 	my_runtime_resume(dev);
> 
> Wouldn't it be cleaner for drivers not to have to handle this manually (which 
> gives an opportunity to get it wrong) but instead have pm_runtime_enable() 
> call the runtime resume callback when CONFIG_PM is disabled ?

Well, I admit it would be nicer if drivers didn't have to worry about 
whether or not CONFIG_PM was enabled.  A slightly cleaner approach 
from the one outlined above would have the probe routine do this:

	my_power_up(dev);
	pm_runtime_set_active(dev);
	pm_runtime_get_noresume(dev);
	pm_runtime_enable(dev);

and have the runtime-resume callback routine call my_power_up() to do
its work.  (Or make my_power_up() actually be the runtime-resume
callback routine.)  That's pretty straightforward and hard to mess up.

In theory, we could have pm_runtime_enable() invoke the runtime-resume
callback when CONFIG_PM is disabled.  In practice, it would be rather 
awkward.  drivers/base/power/runtime.c, which is where 
pm_runtime_enable() is defined and the runtime-PM callbacks are 
invoked, doesn't even get compiled if CONFIG_PM is off.

(Also, it would run against the grain.  CONFIG_PM=n means the kernel
ignores runtime PM, so pm_runtime_enable() shouldn't do anything.)

There's a corollary aspect to this.  If you depend on runtime PM for
powering up your device during probe, does that mean you also depend on
runtime PM for powering down the device during remove?  That is likely
not to work, because the user can prevent runtime suspends by writing
to /sys/.../power/control.

Alan Stern

  reply	other threads:[~2016-11-26 20:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-18 13:50 [PATCH 1/1] smiapp: Implement power-on and power-off sequences without runtime PM Sakari Ailus
2016-11-18 16:09 ` Arnd Bergmann
2016-11-22 18:31   ` Laurent Pinchart
2016-11-22 20:58     ` Arnd Bergmann
2016-11-25  0:43       ` Laurent Pinchart
2016-11-25  2:15         ` Alan Stern
2016-11-25  2:15           ` Alan Stern
2016-11-25  7:48           ` Sakari Ailus
2016-11-25 15:21             ` Alan Stern
2016-11-25 15:21               ` Alan Stern
2016-11-25 19:34               ` Laurent Pinchart
2016-11-26 20:10                 ` Alan Stern [this message]
2016-11-26 20:10                   ` Alan Stern
2016-11-28  7:58                   ` Laurent Pinchart
2016-11-28 15:45                     ` Alan Stern
2016-11-28 15:45                       ` Alan Stern

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=Pine.LNX.4.44L0.1611261451230.32289-100000@netrider.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=arnd@arndb.de \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sakari.ailus@iki.fi \
    --cc=sakari.ailus@linux.intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.