linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Linux PM list <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Kevin Hilman <khilman@ti.com>,
	Magnus Damm <magnus.damm@gmail.com>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	markgross@thegnar.org, Jean Pihet <j-pihet@ti.com>
Subject: [PATCH 1/3] PM / QoS: Create device constraints objects on notifier registration
Date: Sun, 29 Apr 2012 03:11:01 +0200	[thread overview]
Message-ID: <201204290311.01794.rjw@sisk.pl> (raw)
In-Reply-To: <201204290308.52416.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

The current behavior of dev_pm_qos_add_notifier() makes device PM QoS
notifiers less than useful.  Namely, it silently returns success when
called before any PM QoS constraints are added for the device, so the
caller will assume that the notifier has been registered, but when
someone actually adds some nontrivial constraints for the device
eventually, the previous callers of dev_pm_qos_add_notifier()
will not know about that and their notifier routines will not be
executed (contrary to their expectations).

To address this problem make dev_pm_qos_add_notifier() create the
constraints object for the device if it is not present when the
routine is called.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by : markgross <markgross@thegnar.org>
---
 drivers/base/power/qos.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

Index: linux/drivers/base/power/qos.c
===================================================================
--- linux.orig/drivers/base/power/qos.c
+++ linux/drivers/base/power/qos.c
@@ -352,21 +352,26 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_remove_requ
  *
  * Will register the notifier into a notification chain that gets called
  * upon changes to the target value for the device.
+ *
+ * If the device's constraints object doesn't exist when this routine is called,
+ * it will be created (or error code will be returned if that fails).
  */
 int dev_pm_qos_add_notifier(struct device *dev, struct notifier_block *notifier)
 {
-	int retval = 0;
+	int ret = 0;
 
 	mutex_lock(&dev_pm_qos_mtx);
 
-	/* Silently return if the constraints object is not present. */
-	if (dev->power.constraints)
-		retval = blocking_notifier_chain_register(
-				dev->power.constraints->notifiers,
-				notifier);
+	if (!dev->power.constraints)
+		ret = dev->power.power_state.event != PM_EVENT_INVALID ?
+			dev_pm_qos_constraints_allocate(dev) : -ENODEV;
+
+	if (!ret)
+		ret = blocking_notifier_chain_register(
+				dev->power.constraints->notifiers, notifier);
 
 	mutex_unlock(&dev_pm_qos_mtx);
-	return retval;
+	return ret;
 }
 EXPORT_SYMBOL_GPL(dev_pm_qos_add_notifier);
 


  reply	other threads:[~2012-04-29  1:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 21:46 [PATCH 0/2] PM / QoS / Domains: Fix and optimization Rafael J. Wysocki
2012-04-27 21:48 ` [PATCH 1/2] PM / QoS: Create device constraints objects on notifier registration Rafael J. Wysocki
2012-04-28 15:33   ` mark gross
2012-04-28 21:10     ` Rafael J. Wysocki
2012-04-27 21:53 ` [PATCH 2/2][RFC] PM / Domains: Cache device stop and domain power off governor results Rafael J. Wysocki
2012-04-29  1:08 ` [PATCH 0/3] PM / QoS / Domains: Fixes and optimization, take 2 Rafael J. Wysocki
2012-04-29  1:11   ` Rafael J. Wysocki [this message]
2012-04-30  8:57     ` [PATCH 1/3] PM / QoS: Create device constraints objects on notifier registration Jean Pihet
2012-04-29  1:12   ` [PATCH 2/3] PM / Domains: Make device removal more straightforward Rafael J. Wysocki
2012-04-29  1:14   ` [PATCH 3/3][RFC] PM / Domains: Cache device stop and domain power off governor results, v2 Rafael J. Wysocki
2012-04-29 14:12     ` [Update][PATCH 3/3][RFC] PM / Domains: Cache device stop and domain power off governor results, v3 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=201204290311.01794.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=j-pihet@ti.com \
    --cc=khilman@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=markgross@thegnar.org \
    /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).