All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@ti.com>
To: "Rafael J. Wysocki" <rjw@sisk.pl>
Cc: Linux-pm mailing list <linux-pm@lists.linux-foundation.org>,
	linux-omap@vger.kernel.org
Subject: calling runtime PM from system PM methods
Date: Wed, 01 Jun 2011 17:05:31 -0700	[thread overview]
Message-ID: <87k4d55c8k.fsf@ti.com> (raw)

Hi Rafael,

Once again, I'm back to some problems with using runtime PM from system
PM methods.  On OMAP, many drivers don't need to do anything different
for runtime PM compared to system PM, so the system PM methods can
simply use runtime PM.

The obvious complication arises when runtime PM is disabled from
userspace, preventing system PM.

Taking into consideration that runtime PM can be disabled from
userspace, the system PM methods need to manually call the subsystems
runtime PM callbask. An example of the resulting system PM methods can
be found in the currenty OMAP I2C driver (excerpt below[1])

This was working, but now we have device power domains which complicate
the story.  My first take was to change the system PM methods to check
the device power domain callbacks as well[2], and take care of the
precedence.  That seems OK, but it's starting to feel like extra work
for each driver that is easy to screw up, and includes some assumptions
about how the PM core works (e.g. power domain precedence.)

It also has the disadvantage of not taking into consideration the
IRQ-safe capabilities of the PM core.

Rather than adding this additional logic to every driver, what would be
best is if we could just take advantage of all the existing logic in the
runtime PM core, rather than duplicating some of it in the drivers.

The ideal case would be for system PM methods to be able to simply call
pm_runtime_get_sync/_put_sync as well, but somehow force the
transitions, even when pm_runtime_forbid() has been called.

I suspect you won't like that idea, but am curious about your opinions.

In the process of experimenting with other solutions, I found an
interesting discovery:

In the driver's ->suspend() hook, I did something like this:

	priv->forced_suspend = false;
	if (!pm_runtime_suspended(dev)) {
		pm_runtime_put_sync(dev);
		priv->forced_suspend = true;
	}

and in the resume hook I did this:

	if (priv->forced_suspend)
		pm_runtime_get_sync(dev);

Even after disabling runtime PM from userspace via
/sys/devices/.../power/control, the ->suspend() hook triggered an actual
transition.  This is because pm_runtime_forbid() just uses the usage
counter, so the _put_sync() in the ->suspend callback decrements the
counter and triggers an rpm_idle().   Is this expected behavior?

If I can count on this behavior, then the above solution seems better
than my workaround below[2], although I kinda don't like making
assumptions about how pm_runtime_forbid() is implemented.

Kevin

[1] from drivers/i2c/busses/i2c-omap.c

static int omap_i2c_suspend(struct device *dev)
{
	if (!pm_runtime_suspended(dev))
		if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend)
			dev->bus->pm->runtime_suspend(dev);

	return 0;
}

static int omap_i2c_resume(struct device *dev)
{
	if (!pm_runtime_suspended(dev))
		if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume)
			dev->bus->pm->runtime_resume(dev);

	return 0;
}




[2] 
static int omap_i2c_suspend(struct device *dev)
{
	int (*callback)(struct device *) = NULL;
	int ret = 0;

	if (!pm_runtime_suspended(dev)) {
		if (dev->pwr_domain)
			callback = dev->pwr_domain->ops.runtime_suspend;
		else if (dev->bus && dev->bus->pm)
			callback = dev->bus->pm->runtime_suspend;

		ret = callback(dev);
	}

	return ret;
}

static int omap_i2c_resume(struct device *dev)
{
	int (*callback)(struct device *) = NULL;
	int ret = 0;

	if (!pm_runtime_suspended(dev)) {
		if (dev->pwr_domain)
			callback = dev->pwr_domain->ops.runtime_resume;
		else if (dev->bus && dev->bus->pm)
			callback = dev->bus->pm->runtime_resume;

		ret = callback(dev);
	}

	return ret;
}


             reply	other threads:[~2011-06-02  0:05 UTC|newest]

Thread overview: 118+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02  0:05 Kevin Hilman [this message]
2011-06-02 14:18 ` [linux-pm] calling runtime PM from system PM methods Alan Stern
2011-06-02 17:10   ` Kevin Hilman
2011-06-02 17:10   ` [linux-pm] " Kevin Hilman
2011-06-02 18:38     ` Alan Stern
2011-06-02 18:38     ` Alan Stern
2011-06-06 18:29     ` [linux-pm] " Rafael J. Wysocki
2011-06-06 19:16       ` Alan Stern
2011-06-06 19:16       ` Alan Stern
2011-06-06 22:25       ` [linux-pm] " Kevin Hilman
2011-06-07 13:55         ` Alan Stern
2011-06-07 13:55         ` Alan Stern
2011-06-07 21:32         ` Rafael J. Wysocki
2011-06-07 21:32         ` [linux-pm] " Rafael J. Wysocki
2011-06-07 22:34           ` Kevin Hilman
2011-06-07 22:34           ` Kevin Hilman
2011-06-08 22:50           ` [linux-pm] " Kevin Hilman
2011-06-09  5:29             ` Magnus Damm
2011-06-09  5:29             ` Magnus Damm
2011-06-09 13:56             ` Alan Stern
2011-06-09 13:56             ` [linux-pm] " Alan Stern
2011-06-10 14:36               ` Mark Brown
2011-06-10 14:51                 ` Alan Stern
2011-06-10 15:21                   ` Mark Brown
2011-06-10 15:45                     ` Alan Stern
2011-06-10 15:57                       ` Mark Brown
2011-06-10 17:17                         ` Alan Stern
2011-06-10 17:17                         ` [linux-pm] " Alan Stern
2011-06-10 17:31                           ` Mark Brown
2011-06-10 17:31                           ` [linux-pm] " Mark Brown
2011-06-10 18:38                             ` Rafael J. Wysocki
2011-06-10 18:38                             ` [linux-pm] " Rafael J. Wysocki
2011-06-10 18:42                               ` Mark Brown
2011-06-10 18:42                               ` [linux-pm] " Mark Brown
2011-06-10 20:27                                 ` Rafael J. Wysocki
2011-06-10 20:27                                 ` [linux-pm] " Rafael J. Wysocki
2011-06-10 21:27                                   ` Alan Stern
2011-06-10 21:27                                   ` [linux-pm] " Alan Stern
2011-06-11 11:42                                   ` Mark Brown
2011-06-11 11:42                                   ` [linux-pm] " Mark Brown
2011-06-11 20:56                                     ` Rafael J. Wysocki
2011-06-13 12:22                                       ` [linux-pm] " Mark Brown
2011-06-13 12:22                                       ` Mark Brown
2011-06-10 15:57                       ` Mark Brown
2011-06-10 15:45                     ` Alan Stern
2011-06-10 15:21                   ` Mark Brown
2011-06-10 14:51                 ` Alan Stern
2011-06-10 18:49                 ` Rafael J. Wysocki
2011-06-10 18:49                 ` [linux-pm] " Rafael J. Wysocki
2011-06-10 18:54                   ` Mark Brown
2011-06-10 18:54                   ` [linux-pm] " Mark Brown
2011-06-10 20:45                     ` Rafael J. Wysocki
2011-06-10 20:45                     ` Rafael J. Wysocki
2011-06-10 14:36               ` Mark Brown
2011-06-10 23:52               ` [linux-pm] " Kevin Hilman
2011-06-11 16:42                 ` Alan Stern
2011-06-11 22:46                   ` Rafael J. Wysocki
2011-06-12 15:59                     ` Alan Stern
2011-06-12 18:27                       ` Rafael J. Wysocki
2011-06-12 18:27                       ` [linux-pm] " Rafael J. Wysocki
2011-06-12 15:59                     ` Alan Stern
2011-06-15 21:54                     ` [linux-pm] " Kevin Hilman
2011-06-16  0:01                       ` Rafael J. Wysocki
2011-06-16  0:01                       ` [linux-pm] " Rafael J. Wysocki
2011-06-16  1:17                         ` Kevin Hilman
2011-06-16  1:17                         ` [linux-pm] " Kevin Hilman
2011-06-16 14:27                           ` Alan Stern
2011-06-16 22:48                             ` Rafael J. Wysocki
2011-06-17 19:47                               ` Rafael J. Wysocki
2011-06-17 20:04                                 ` Alan Stern
2011-06-17 20:04                                 ` [linux-pm] " Alan Stern
2011-06-17 21:29                                   ` Rafael J. Wysocki
2011-06-18 11:08                                     ` Rafael J. Wysocki
2011-06-18 11:08                                     ` [linux-pm] " Rafael J. Wysocki
2011-06-18 15:31                                       ` Alan Stern
2011-06-18 21:01                                         ` Rafael J. Wysocki
2011-06-18 21:01                                         ` [linux-pm] " Rafael J. Wysocki
2011-06-18 23:57                                           ` Rafael J. Wysocki
2011-06-18 23:57                                           ` [linux-pm] " Rafael J. Wysocki
2011-06-19  1:42                                             ` Alan Stern
2011-06-19  1:42                                               ` Alan Stern
2011-06-19 14:04                                               ` Rafael J. Wysocki
2011-06-19 15:01                                                 ` Alan Stern
2011-06-19 15:01                                                 ` [linux-pm] " Alan Stern
2011-06-19 15:01                                                   ` Alan Stern
2011-06-19 19:36                                                   ` Rafael J. Wysocki
2011-06-19 19:36                                                   ` [linux-pm] " Rafael J. Wysocki
2011-06-20 14:39                                                     ` Alan Stern
2011-06-20 14:39                                                     ` [linux-pm] " Alan Stern
2011-06-20 14:39                                                       ` Alan Stern
2011-06-20 19:53                                                       ` Rafael J. Wysocki
2011-06-20 19:53                                                       ` [linux-pm] " Rafael J. Wysocki
2011-06-19 14:04                                               ` Rafael J. Wysocki
2011-06-19  1:42                                             ` Alan Stern
2011-06-18 15:31                                       ` Alan Stern
2011-06-17 21:29                                   ` Rafael J. Wysocki
2011-06-17 19:47                               ` Rafael J. Wysocki
2011-06-16 22:48                             ` Rafael J. Wysocki
2011-06-16 14:27                           ` Alan Stern
2011-06-16 22:30                           ` [linux-pm] " Rafael J. Wysocki
2011-06-16 22:30                           ` Rafael J. Wysocki
2011-06-15 21:54                     ` Kevin Hilman
2011-06-11 22:46                   ` Rafael J. Wysocki
2011-06-11 16:42                 ` Alan Stern
2011-06-10 23:52               ` Kevin Hilman
2011-06-08 22:50           ` Kevin Hilman
2011-06-10 23:14           ` [linux-pm] " Kevin Hilman
2011-06-11 16:27             ` Alan Stern
2011-06-11 16:27             ` Alan Stern
2011-06-11 23:13             ` [linux-pm] " Rafael J. Wysocki
2011-06-11 23:13             ` Rafael J. Wysocki
2011-06-10 23:14           ` Kevin Hilman
2011-06-06 22:25       ` Kevin Hilman
2011-06-06 18:29     ` Rafael J. Wysocki
2011-06-02 14:18 ` Alan Stern
2011-06-06 18:01 ` Rafael J. Wysocki
2011-06-06 18:01 ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2011-06-02  0:05 Kevin Hilman

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=87k4d55c8k.fsf@ti.com \
    --to=khilman@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=rjw@sisk.pl \
    /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.