public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: jean.pihet@newoldbits.com
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Kevin Hilman <khilman@ti.com>,
	markgross@thegnar.org,
	Linux PM mailing list <linux-pm@lists.linux-foundation.org>,
	linux-omap@vger.kernel.org, Paul Walmsley <paul@pwsan.com>,
	Magnus Damm <magnus.damm@gmail.com>,
	Todd Poynor <toddpoynor@google.com>, Jean Pihet <j-pihet@ti.com>
Subject: Re: [PATCH 07/15] PM QoS: add a global notification mechanism for the device constraints
Date: Sun, 14 Aug 2011 23:50:41 +0200	[thread overview]
Message-ID: <201108142350.42260.rjw@sisk.pl> (raw)
In-Reply-To: <1313075212-8366-8-git-send-email-j-pihet@ti.com>

Hi,

There is some code duplication in this patch that should better be
avoided (details below).

On Thursday, August 11, 2011, jean.pihet@newoldbits.com wrote:
> From: Jean Pihet <j-pihet@ti.com>
> 
> Add a global notification chain that gets called upon changes to the
> aggregated constraint value for any device.
> The notification callbacks are passing the full constraint request data
> in order for the callees to have access to it. The current use is for the
> platform low-level code to access the target device of the constraint.
> 
> Signed-off-by: Jean Pihet <j-pihet@ti.com>
> ---
>  drivers/base/power/qos.c |  114 ++++++++++++++++++++++++++++++++++++++++-----
>  include/linux/pm_qos.h   |   11 ++++
>  kernel/power/qos.c       |    2 +-
>  3 files changed, 113 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
> index 465e419..4b0b316 100644
> --- a/drivers/base/power/qos.c
> +++ b/drivers/base/power/qos.c
> @@ -8,6 +8,12 @@
>   *
>   * This QoS design is best effort based. Dependents register their QoS needs.
>   * Watchers register to keep track of the current QoS needs of the system.
> + * Watchers can register different types of notification callbacks:
> + *  . a per-device notification callback using the dev_pm_qos_*_notifier API.
> + *    The notification chain data is stored in the per-device constraint
> + *    data struct.
> + *  . a system-wide notification callback using the dev_pm_qos_*_global_notifier
> + *    API. The notification chain data is stored in a static variable.
>   *
>   * Note about the per-device constraint data struct allocation:
>   * . The per-device constraints data struct ptr is tored into the device
> @@ -41,6 +47,7 @@
>  #include <linux/kernel.h>
>  
>  
> +static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers);
>  static void dev_pm_qos_constraints_allocate(struct device *dev);
>  
>  int dev_pm_qos_request_active(struct dev_pm_qos_request *req)
> @@ -64,6 +71,8 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_request_active);
>  void dev_pm_qos_add_request(struct dev_pm_qos_request *req, struct device *dev,
>  			    s32 value)
>  {
> +	int ret, curr_value;
> +
>  	if (!req) /*guard against callers passing in null */
>  		return;
>  
> @@ -82,8 +91,19 @@ void dev_pm_qos_add_request(struct dev_pm_qos_request *req, struct device *dev,
>  	if (req->dev->power.constraints_state != DEV_PM_QOS_ALLOCATED)
>  		return;
>  
> -	pm_qos_update_target(dev->power.constraints,
> -			     &req->node, PM_QOS_ADD_REQ, value);

The following code:

> +	/*
> +	 * Update constraints list and call the per-device callbacks if needed
> +	 */
> +	ret = pm_qos_update_target(dev->power.constraints,
> +				   &req->node, PM_QOS_ADD_REQ, value);
> +
> +	if (ret) {
> +		/* Call the global callbacks if needed */
> +		curr_value = pm_qos_read_value(req->dev->power.constraints);
> +		blocking_notifier_call_chain(&dev_pm_notifiers,
> +					     (unsigned long)curr_value,
> +					     req);
> +	}

is used in dev_pm_qos_update_request() and dev_pm_qos_remove_request()
with the only difference being the command given to pm_qos_update_target().
This asks for a common function, eg. dev_pm_qos_update_target(), containing
that code that will be called by all of them (and, apparently, by
dev_pm_qos_constraints_destroy()).

...
> @@ -250,9 +329,18 @@ void dev_pm_qos_constraints_destroy(struct device *dev)
>  			 * Update constraints list and call the per-device
>  			 * callbacks if needed
>  			 */
> -			pm_qos_update_target(req->dev->power.constraints,
> -					     &req->node, PM_QOS_REMOVE_REQ,
> -					     PM_QOS_DEFAULT_VALUE);
> +			ret |= pm_qos_update_target(req->dev->power.constraints,
> +						    &req->node,
> +						    PM_QOS_REMOVE_REQ,
> +						    PM_QOS_DEFAULT_VALUE);

I'm not sure why you're using the binary or operator here.  Shouldn't that be
a simple assignment?

> +
> +		if (ret) {
> +			/* Call the global callbacks if needed */
> +			curr_value = dev->power.constraints->default_value;
> +			blocking_notifier_call_chain(&dev_pm_notifiers,
> +						     (unsigned long)curr_value,
> +						     req);
> +		}
>  
>  		kfree(dev->power.constraints->notifiers);
>  		kfree(dev->power.constraints);

Thanks,
Rafael

  reply	other threads:[~2011-08-14 21:49 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-11 15:06 [PATCH v4 00/15] PM QoS: add a per-device latency constraints class jean.pihet
2011-08-11 15:06 ` [PATCH 01/15] PM QoS: move and rename the implementation files jean.pihet
2011-08-13  2:47   ` mark gross
2011-08-11 15:06 ` [PATCH 02/15] PM QoS: minor clean-ups jean.pihet
2011-08-13  2:48   ` mark gross
2011-08-11 15:06 ` [PATCH 03/15] PM QoS: code re-organization jean.pihet
2011-08-13  2:50   ` mark gross
2011-08-11 15:06 ` [PATCH 04/15] PM QoS: re-organize data structs jean.pihet
2011-08-13  2:56   ` mark gross
2011-08-13 20:58     ` Rafael J. Wysocki
2011-08-14  8:29       ` Jean Pihet
2011-08-14 13:34         ` Rafael J. Wysocki
2011-08-11 15:06 ` [PATCH 05/15] PM QoS: generalize and export the constraints management code jean.pihet
2011-08-13  3:09   ` mark gross
2011-08-13 20:34     ` Rafael J. Wysocki
2011-08-14  8:25       ` Jean Pihet
2011-08-14 13:37         ` Rafael J. Wysocki
2011-08-16  4:08           ` mark gross
2011-08-16  6:44             ` Jean Pihet
2011-08-16 17:45               ` mark gross
2011-08-16 18:01                 ` Rafael J. Wysocki
2011-08-11 15:06 ` [PATCH 06/15] PM QoS: implement the per-device PM QoS constraints jean.pihet
2011-08-13  3:16   ` mark gross
2011-08-13 21:08   ` Rafael J. Wysocki
2011-08-14  8:50     ` Jean Pihet
2011-08-14 13:51       ` Rafael J. Wysocki
2011-08-11 15:06 ` [PATCH 07/15] PM QoS: add a global notification mechanism for the device constraints jean.pihet
2011-08-14 21:50   ` Rafael J. Wysocki [this message]
2011-08-16  9:58     ` Jean Pihet
2011-08-11 15:06 ` [PATCH 08/15] OMAP: convert I2C driver to PM QoS for latency constraints jean.pihet
2011-08-11 15:06 ` [PATCH 09/15] OMAP: PM: create a PM layer plugin for per-device constraints jean.pihet
2011-08-11 15:06 ` [PATCH 10/15] OMAP2+: powerdomain: control power domains next state jean.pihet
2011-08-11 15:06 ` [PATCH 11/15] OMAP3: powerdomain data: add wake-up latency figures jean.pihet
2011-08-11 15:06 ` [PATCH 12/15] OMAP4: " jean.pihet
2011-08-11 15:06 ` [PATCH 13/15] OMAP2+: omap_hwmod: manage the wake-up latency constraints jean.pihet
2011-08-11 15:06 ` [PATCH 14/15] OMAP: PM CONSTRAINTS: implement the devices " jean.pihet
2011-08-11 15:06 ` [PATCH 15/15] OMAP2+: cpuidle only influences the MPU state jean.pihet
2011-08-12  8:02 ` [PATCH v4 00/15] PM QoS: add a per-device latency constraints class Rafael J. Wysocki
2011-08-12 11:56   ` Jean Pihet
2011-08-12 21:56     ` Rafael J. Wysocki
2011-08-14  8:51       ` Jean Pihet
2011-08-14 13:53         ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2011-08-16 13:43 [PATCH v5 00/15] PM QoS: add a per-device latency constraints framework jean.pihet
2011-08-16 13:43 ` [PATCH 07/15] PM QoS: add a global notification mechanism for the device constraints jean.pihet
2011-08-16 21:44   ` 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=201108142350.42260.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=j-pihet@ti.com \
    --cc=jean.pihet@newoldbits.com \
    --cc=khilman@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=magnus.damm@gmail.com \
    --cc=markgross@thegnar.org \
    --cc=paul@pwsan.com \
    --cc=toddpoynor@google.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