Skip to contentSkip to conversation

PM QoS: implement the OMAP low level constraints management code

PATCH Superseded Jean Pihet 3 participants 20 messages Jun 14, 2012 – Jul 20, 2012

Subsystems (9)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Jean Pihet

author
#0 lore raw

v8 cover PM QoS: implement the OMAP low level constraints management code

. Implement the devices wake-up latency constraints using the global
device PM QoS notification handler which applies the constraints to the underlying layer,
. Implement the low level code which controls the power domains next
functional power states, through the hwmod and pwrdm layers,
. Include a fix for the cpuidle code to always return a valid C-state, . Add cpuidle and power domains wake-up latency figures for OMAP3, cf.
comments in the code and [1] for the details on where the numbers are magically coming from,
. Implement the relation between the cpuidle and per-device PM QoS frameworks
in the OMAP3 specific idle callbacks.
The chosen C-state shall satisfy the following conditions:
. it satisfies the enable_off_mode flag,
. the next state for MPU and CORE power domains is not lower than the
state programmed by the per-device PM QoS.
. convert I2C driver to PM QoS for latency constraints,
. remove the latency related functions from the API (omap_pm_set_*) and
update the kernel Documentation accordingly.

ToDo:
1. Re-visit the OMAP power domains states initialization procedure. Currently the power states that have been changed from the constraints API which were applied before the initialization of the power domains are lost
2. Further clean-up the OMAP PM layer, use the generic frameworks instead (OPP, PM QoS for throughput constraints ...)

Note: the following commits are required and so are included in this series,
although they are planned for inclusion into mainline via the linux-omap tree:
. ARM: OMAP2+: hwmod: manage the wake-up latency constraints
. ARM: OMAP3: PM: cpuidle: default to C1 in next_valid_state

Based on mainline kernel 3.5.0-rc2 with the functional power states changes applied.

Tested cpuidle and suspend on OMAP3 Beagleboard (ES2.x) with constraints on MPU, CORE, PER in RETention and OFF modes.

[1] http://www.omappedia.org/wiki/Power_Management_Device_Latencies_Measurement

History:
v8:
. reworked the code after internal review and testing with OMAP3&4 device
OFF

v7:
. rebased on top of the functional power state changes

v6:
. minor change in the commits description after Kevin's review . added Kevin's Reviewed-by

v5:
. rebased on latest linux-omap
. rework after Kevin's comments on the MLs

v4:
. split up the patches which remove the omap_pm_ code from the patch set.
Those patches are to be submitted later, on top of this patch set.
. latency numbers: provide the measurements setup and conditions in the code
comments, added the link to the details on wiki [1].
. improved kerneldoc
. split big functions into smaller ones, in order to improve the readability

v3: reworked the error return path and improved the kerneldoc

v2: reworked the OMAP specific cpuidle code to demote the initial C-state to
a valid C-state which fulfills the per-device constraints

v1: initial version

Jean Pihet (10):
ARM: OMAP2+: PM QoS: control the power domains next state from the
constraints
ARM: OMAP2+: hwmod: manage the wake-up latency constraints
ARM: OMAP2+: PM QoS: manage the per-device latency constraints in
hwmod
ARM: OMAP: omap_device: register to the per-device PM QoS framework
ARM: OMAP3: cpuidle: next C-state decision depends on the PM QoS MPU
and CORE constraints
ARM: OMAP3: PM: cpuidle: default to C1 in next_valid_state
ARM: OMAP3: update cpuidle latency and threshold figures
ARM: OMAP3: powerdomain data: add wake-up latency figures
ARM: OMAP: convert I2C driver to PM QoS for latency constraints
ARM: OMAP: PM: remove the latency related functions from the API

 Documentation/arm/OMAP/omap_pm               |   68 +++------
 arch/arm/mach-omap2/cpuidle34xx.c            |  124 ++++++++++-----
 arch/arm/mach-omap2/omap_hwmod.c             |   44 +++++-
 arch/arm/mach-omap2/powerdomain.c            |  215 ++++++++++++++++++++++++++
 arch/arm/mach-omap2/powerdomain.h            |   18 ++
 arch/arm/mach-omap2/powerdomains3xxx_data.c  |   83 ++++++++++
 arch/arm/plat-omap/i2c.c                     |   21 ---
 arch/arm/plat-omap/include/plat/omap-pm.h    |   99 ------------
 arch/arm/plat-omap/include/plat/omap_hwmod.h |    5 +
 arch/arm/plat-omap/omap-pm-noop.c            |   88 -----------
 arch/arm/plat-omap/omap_device.c             |   81 ++++++++++-
 drivers/i2c/busses/i2c-omap.c                |   28 ++--
 include/linux/i2c-omap.h                     |    1 -
 13 files changed, 563 insertions(+), 312 deletions(-)
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH v8 1/10 ARM: OMAP2+: PM QoS: control the power domains next state from the constraints

When a PM QoS device latency constraint is requested or removed the constraint is stored in the constraints list of the corresponding power domain, then the aggregated constraint value is applied by programming the next functional power state using omap_set_pwrdm_state.

Tested on OMAP3 Beagleboard and OMAP4 Pandaboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

---
 arch/arm/mach-omap2/powerdomain.c |  215 +++++++++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/powerdomain.h |   18 +++
 2 files changed, 233 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/powerdomain.c +215 -0
index f6885f9..82797c2 100644
@@ -17,8 +17,10 @@
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/list.h>
+#include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/string.h>
+#include <linux/pm_qos.h>
 #include <trace/events/power.h>
 
 #include "cm2xxx_3xxx.h"
@@ -113,6 +115,12 @@ static int _pwrdm_register(struct powerdomain *pwrdm)
 	for (i = 0; i < pwrdm->banks; i++)
 		pwrdm->ret_mem_off_counter[i] = 0;
 
+	/* Initialize the per-device wake-up constraints framework data */
+	mutex_init(&pwrdm->wkup_lat_plist_lock);
+	plist_head_init(&pwrdm->wkup_lat_plist_head);
+	pwrdm->wkup_lat_next_state = PWRDM_FUNC_PWRST_OFF;
+
+	/* Initialize the pwrdm state */
 	pwrdm_wait_transition(pwrdm);
 	pwrdm->state = pwrdm_read_func_pwrst(pwrdm);
 	pwrdm->state_counter[pwrdm->state] = 1;
@@ -200,6 +208,58 @@ static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
 	return 0;
 }
 
+/**
+ * _pwrdm_wakeuplat_update_pwrst - Update power domain power state if needed
+ * @pwrdm: struct powerdomain * to which requesting device belongs to.
+ * @min_latency: the allowed wake-up latency for the given power domain. A
+ *  value of PM_QOS_DEV_LAT_DEFAULT_VALUE means 'no constraint' on the pwrdm.
+ *
+ * Finds the power domain next power state that fulfills the constraint.
+ * Programs a new target state if it is different from current power state.
+ * The power domains get the next power state programmed directly in the
+ * registers.
+ *
+ * Returns 0 in case of success, -EINVAL in case of invalid parameters,
+ * or the return value from omap_set_pwrdm_state.
+ */
+static int _pwrdm_wakeuplat_update_pwrst(struct powerdomain *pwrdm,
+					 long min_latency)
+{
+	int ret = 0, state, new_state = PWRDM_FUNC_PWRST_ON;
+
+	if (!pwrdm) {
+		WARN(1, "powerdomain: %s: invalid parameter(s)", __func__);
+		return -EINVAL;
+	}
+
+	/*
+	 * Find the next supported power state with
+	 *  wakeup latency <= min_latency.
+	 * Pick the lower state if no constraint on the pwrdm
+	 *  (min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE).
+	 * Skip the states marked as unsupported (UNSUP_STATE).
+	 * If no power state found, fall back to PWRDM_FUNC_PWRST_ON.
+	 */
+	for (state = 0x0; state < PWRDM_MAX_FUNC_PWRSTS; state++) {
+		if ((min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE) ||
+		    ((pwrdm->wakeup_lat[state] != UNSUP_STATE) &&
+		     (pwrdm->wakeup_lat[state] <= min_latency))) {
+			new_state = state;
+			break;
+		}
+	}
+
+	pwrdm->wkup_lat_next_state = new_state;
+	ret = omap_set_pwrdm_state(pwrdm, new_state);
+
+	pr_debug("%s: func pwrst for %s: curr=%d, next=%d, min_latency=%ld, new_state=%d\n",
+		 __func__, pwrdm->name, pwrdm_read_func_pwrst(pwrdm),
+		 pwrdm_read_next_func_pwrst(pwrdm), min_latency, new_state);
+
+	return ret;
+}
+
+
 /* Public functions */
 
 /**
@@ -1317,6 +1377,161 @@ int pwrdm_post_transition(void)
 }
 
 /**
+ * pwrdm_wakeuplat_update_constraint - Set or update a powerdomain wakeup
+ *  latency constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ * @min_latency: minimum wakeup latency constraint (in microseconds) for
+ *  the given pwrdm
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint set/update: Adds a new entry to powerdomain's wake-up latency
+ * constraint list. If the constraint identifier already exists in the list,
+ * the old value is overwritten.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -ENOMEM in case of memory shortage, -EINVAL in
+ * case of invalid latency value, or the return value from
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * The caller must check the validity of the parameters.
+ */
+int pwrdm_wakeuplat_update_constraint(struct powerdomain *pwrdm, void *cookie,
+				      long min_latency)
+{
+	struct pwrdm_wkup_constraints_entry *tmp_user, *new_user, *user = NULL;
+	long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+	int free_new_user = 0;
+
+	pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p, min_latency=%ld\n",
+		 __func__, pwrdm->name, cookie, min_latency);
+
+	if (min_latency <= PM_QOS_DEV_LAT_DEFAULT_VALUE) {
+		pr_warn("%s: min_latency >= PM_QOS_DEV_LAT_DEFAULT_VALUE\n",
+			__func__);
+		return -EINVAL;
+	}
+
+	/* Allocate a new entry for insertion in the list */
+	new_user = kzalloc(sizeof(struct pwrdm_wkup_constraints_entry),
+			   GFP_KERNEL);
+	if (!new_user) {
+		pr_err("%s: FATAL ERROR: kzalloc failed\n", __func__);
+		return -ENOMEM;
+	}
+
+	mutex_lock(&pwrdm->wkup_lat_plist_lock);
+
+	/* Check if there already is a constraint for cookie */
+	plist_for_each_entry(tmp_user, &pwrdm->wkup_lat_plist_head, node) {
+		if (tmp_user->cookie == cookie) {
+			user = tmp_user;
+			break;
+		}
+	}
+
+	/* If nothing to update, job done */
+	if (user && (user->node.prio == min_latency))
+		goto out;
+
+	if (!user) {
+		/* Add new entry to the list */
+		user = new_user;
+		user->cookie = cookie;
+	} else {
+		/* Update existing entry */
+		plist_del(&user->node, &pwrdm->wkup_lat_plist_head);
+		free_new_user = 1;
+	}
+
+	plist_node_init(&user->node, min_latency);
+	plist_add(&user->node, &pwrdm->wkup_lat_plist_head);
+
+	/* Find the aggregated constraint value from the list */
+	if (!plist_head_empty(&pwrdm->wkup_lat_plist_head))
+		value = plist_first(&pwrdm->wkup_lat_plist_head)->prio;
+
+	mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+
+	/* Free the newly allocated entry if not in use */
+	if (free_new_user)
+		kfree(new_user);
+
+	/* Apply the constraint to the pwrdm */
+	pr_debug("powerdomain: %s: pwrdm %s, value=%ld\n",
+		 __func__, pwrdm->name, value);
+	return _pwrdm_wakeuplat_update_pwrst(pwrdm, value);
+
+out:
+	mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+	return 0;
+}
+
+/**
+ * pwrdm_wakeuplat_remove_constraint - Release a powerdomain wakeup latency
+ *  constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint removal: Removes the identifier's entry from powerdomain's
+ * wakeup latency constraint list.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -EINVAL in case the constraint to remove is not
+ * existing, or the return value from _pwrdm_wakeuplat_update_pwrst.
+ *
+ * The caller must check the validity of the parameters.
+ */
+int pwrdm_wakeuplat_remove_constraint(struct powerdomain *pwrdm, void *cookie)
+{
+	struct pwrdm_wkup_constraints_entry *tmp_user, *user = NULL;
+	long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+
+	pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p\n",
+		 __func__, pwrdm->name, cookie);
+
+	mutex_lock(&pwrdm->wkup_lat_plist_lock);
+
+	/* Check if there is a constraint for cookie */
+	plist_for_each_entry(tmp_user, &pwrdm->wkup_lat_plist_head, node) {
+		if (tmp_user->cookie == cookie) {
+			user = tmp_user;
+			break;
+		}
+	}
+
+	/* If constraint not existing or list empty, return -EINVAL */
+	if (!user)
+		goto out;
+
+	/* Remove the constraint from the list */
+	plist_del(&user->node, &pwrdm->wkup_lat_plist_head);
+
+	/* Find the aggregated constraint value from the list */
+	if (!plist_head_empty(&pwrdm->wkup_lat_plist_head))
+		value = plist_first(&pwrdm->wkup_lat_plist_head)->prio;
+
+	mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+
+	/* Release the constraint memory */
+	kfree(user);
+
+	/* Apply the constraint to the pwrdm */
+	pr_debug("powerdomain: %s: pwrdm %s, value=%ld\n",
+		 __func__, pwrdm->name, value);
+	return _pwrdm_wakeuplat_update_pwrst(pwrdm, value);
+
+out:
+	mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+	return -EINVAL;
+}
+
+/**
  * pwrdm_get_context_loss_count - get powerdomain's context loss count
  * @pwrdm: struct powerdomain * to wait for
  *
arch/arm/mach-omap2/powerdomain.h +18 -0
index 06fb396..fca82fc 100644
@@ -16,6 +16,7 @@
 
 #include <linux/types.h>
 #include <linux/list.h>
+#include <linux/plist.h>
 #include <linux/mutex.h>
 #include <linux/atomic.h>
 
@@ -85,6 +86,8 @@ extern void omap44xx_powerdomains_init(void);
 
 #define PWRDM_MAX_PWRSTS	4
 
+#define UNSUP_STATE		-1
+
 /* Powerdomain allowable state bitfields */
 #define PWRSTS_ON		(1 << PWRDM_POWER_ON)
 #define PWRSTS_INACTIVE		(1 << PWRDM_POWER_INACTIVE)
@@ -173,6 +176,16 @@ struct powerdomain {
 	s64 timer;
 	s64 state_timer[PWRDM_MAX_FUNC_PWRSTS];
 #endif
+	const s32 wakeup_lat[PWRDM_MAX_FUNC_PWRSTS];
+	struct plist_head wkup_lat_plist_head;
+	struct mutex wkup_lat_plist_lock;
+	int wkup_lat_next_state;
+};
+
+/* Linked list for the wake-up latency constraints */
+struct pwrdm_wkup_constraints_entry {
+	void			*cookie;
+	struct plist_node	node;
 };
 
 /**
@@ -270,6 +283,11 @@ int pwrdm_state_switch(struct powerdomain *pwrdm);
 int pwrdm_pre_transition(void);
 int pwrdm_post_transition(void);
 int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm);
+
+int pwrdm_wakeuplat_update_constraint(struct powerdomain *pwrdm, void *cookie,
+				      long min_latency);
+int pwrdm_wakeuplat_remove_constraint(struct powerdomain *pwrdm, void *cookie);
+
 int pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
 bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
 
Signature · 1 line
1.7.7.6
author
#2 lore raw

PATCH v8 1/10 ARM: OMAP2+: PM QoS: control the power domains next state from the constraints

Hi,

Here are some remarks I got after an internal review. I think those points need to be discussed with a broader audience.

Quoted 139 lines · Jean Pihet

When a PM QoS device latency constraint is requested or removed the constraint is stored in the constraints list of the corresponding power domain, then the aggregated constraint value is applied by programming the next functional power state using omap_set_pwrdm_state.

Tested on OMAP3 Beagleboard and OMAP4 Pandaboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

---
?arch/arm/mach-omap2/powerdomain.c | ?215 +++++++++++++++++++++++++++++++++++++ ?arch/arm/mach-omap2/powerdomain.h | ? 18 +++
?2 files changed, 233 insertions(+), 0 deletions(-)

arch/arm/mach-omap2/powerdomain.c +0 -0
index f6885f9..82797c2 100644
@@ -17,8 +17,10 @@

?#include <linux/kernel.h>
?#include <linux/types.h>
?#include <linux/list.h>
+#include <linux/slab.h>
?#include <linux/errno.h>
?#include <linux/string.h>
+#include <linux/pm_qos.h>
?#include <trace/events/power.h>

?#include "cm2xxx_3xxx.h"

arch/arm/mach-omap2/powerdomain.c +58 -0
@@ -113,6 +115,12 @@ static int _pwrdm_register(struct powerdomain *pwrdm)
 ? ? ? ?for (i = 0; i < pwrdm->banks; i++)
 ? ? ? ? ? ? ? ?pwrdm->ret_mem_off_counter[i] = 0;
 
+ ? ? ? /* Initialize the per-device wake-up constraints framework data */
+ ? ? ? mutex_init(&pwrdm->wkup_lat_plist_lock);
+ ? ? ? plist_head_init(&pwrdm->wkup_lat_plist_head);
+ ? ? ? pwrdm->wkup_lat_next_state = PWRDM_FUNC_PWRST_OFF;
+
+ ? ? ? /* Initialize the pwrdm state */
 ? ? ? ?pwrdm_wait_transition(pwrdm);
 ? ? ? ?pwrdm->state = pwrdm_read_func_pwrst(pwrdm);
 ? ? ? ?pwrdm->state_counter[pwrdm->state] = 1;
@@ -200,6 +208,58 @@ static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused)
 ? ? ? ?return 0;
 ?}
 
+/**
+ * _pwrdm_wakeuplat_update_pwrst - Update power domain power state if needed
+ * @pwrdm: struct powerdomain * to which requesting device belongs to.
+ * @min_latency: the allowed wake-up latency for the given power domain. A
+ * ?value of PM_QOS_DEV_LAT_DEFAULT_VALUE means 'no constraint' on the pwrdm.
+ *
+ * Finds the power domain next power state that fulfills the constraint.
+ * Programs a new target state if it is different from current power state.
+ * The power domains get the next power state programmed directly in the
+ * registers.
+ *
+ * Returns 0 in case of success, -EINVAL in case of invalid parameters,
+ * or the return value from omap_set_pwrdm_state.
+ */
+static int _pwrdm_wakeuplat_update_pwrst(struct powerdomain *pwrdm,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?long min_latency)
+{
+ ? ? ? int ret = 0, state, new_state = PWRDM_FUNC_PWRST_ON;
+
+ ? ? ? if (!pwrdm) {
+ ? ? ? ? ? ? ? WARN(1, "powerdomain: %s: invalid parameter(s)", __func__);
+ ? ? ? ? ? ? ? return -EINVAL;
+ ? ? ? }
+
+ ? ? ? /*
+ ? ? ? ?* Find the next supported power state with
+ ? ? ? ?* ?wakeup latency <= min_latency.
+ ? ? ? ?* Pick the lower state if no constraint on the pwrdm
+ ? ? ? ?* ?(min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE).
+ ? ? ? ?* Skip the states marked as unsupported (UNSUP_STATE).
+ ? ? ? ?* If no power state found, fall back to PWRDM_FUNC_PWRST_ON.
+ ? ? ? ?*/
+ ? ? ? for (state = 0x0; state < PWRDM_MAX_FUNC_PWRSTS; state++) {
+ ? ? ? ? ? ? ? if ((min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE) ||
+ ? ? ? ? ? ? ? ? ? ((pwrdm->wakeup_lat[state] != UNSUP_STATE) &&
+ ? ? ? ? ? ? ? ? ? ?(pwrdm->wakeup_lat[state] <= min_latency))) {
+ ? ? ? ? ? ? ? ? ? ? ? new_state = state;
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? }
+ ? ? ? }
+
+ ? ? ? pwrdm->wkup_lat_next_state = new_state;
+ ? ? ? ret = omap_set_pwrdm_state(pwrdm, new_state);
+
+ ? ? ? pr_debug("%s: func pwrst for %s: curr=%d, next=%d, min_latency=%ld, new_state=%d\n",
+ ? ? ? ? ? ? ? ?__func__, pwrdm->name, pwrdm_read_func_pwrst(pwrdm),
+ ? ? ? ? ? ? ? ?pwrdm_read_next_func_pwrst(pwrdm), min_latency, new_state);
+
+ ? ? ? return ret;
+}
+
+

?/* Public functions */

?/**

arch/arm/mach-omap2/powerdomain.c +0 -0
@@ -1317,6 +1377,161 @@ int pwrdm_post_transition(void)
 ?}
 

?/**
+ * pwrdm_wakeuplat_update_constraint - Set or update a powerdomain wakeup
+ * ?latency constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ * @min_latency: minimum wakeup latency constraint (in microseconds) for
+ * ?the given pwrdm
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint set/update: Adds a new entry to powerdomain's wake-up latency
+ * constraint list. If the constraint identifier already exists in the list,
+ * the old value is overwritten.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -ENOMEM in case of memory shortage, -EINVAL in
+ * case of invalid latency value, or the return value from
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * The caller must check the validity of the parameters.
+ */

arch/arm/mach-omap2/powerdomain.c +13 -0
+int pwrdm_wakeuplat_update_constraint(struct powerdomain *pwrdm, void *cookie,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? long min_latency)
+{
+ ? ? ? struct pwrdm_wkup_constraints_entry *tmp_user, *new_user, *user = NULL;
+ ? ? ? long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+ ? ? ? int free_new_user = 0;
+
+ ? ? ? pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p, min_latency=%ld\n",
+ ? ? ? ? ? ? ? ?__func__, pwrdm->name, cookie, min_latency);
+
+ ? ? ? if (min_latency <= PM_QOS_DEV_LAT_DEFAULT_VALUE) {
+ ? ? ? ? ? ? ? pr_warn("%s: min_latency >= PM_QOS_DEV_LAT_DEFAULT_VALUE\n",
+ ? ? ? ? ? ? ? ? ? ? ? __func__);

arch/arm/mach-omap2/powerdomain.c

Quoted 10 lines
arch/arm/mach-omap2/powerdomain.c +10 -0
+ ? ? ? ? ? ? ? return -EINVAL;
+ ? ? ? }
+
+ ? ? ? /* Allocate a new entry for insertion in the list */
+ ? ? ? new_user = kzalloc(sizeof(struct pwrdm_wkup_constraints_entry),
+ ? ? ? ? ? ? ? ? ? ? ? ? ?GFP_KERNEL);
+ ? ? ? if (!new_user) {
+ ? ? ? ? ? ? ? pr_err("%s: FATAL ERROR: kzalloc failed\n", __func__);
+ ? ? ? ? ? ? ? return -ENOMEM;
+ ? ? ? }

"
- pwrdm_wakeuplat_update_constraint: please do not allocate unless you need to!!! remove the variable free_new_user
"
This allocation mechanism is used since allocating under a lock is not safe. The free_new_user variable is used to keep track of the allocation usefulness. If the allocation was not needed (which is known only after parsing the constraints list) the entry is free'd.

Quoted 111 lines
arch/arm/mach-omap2/powerdomain.c +111 -0
+
+ ? ? ? mutex_lock(&pwrdm->wkup_lat_plist_lock);
+
+ ? ? ? /* Check if there already is a constraint for cookie */
+ ? ? ? plist_for_each_entry(tmp_user, &pwrdm->wkup_lat_plist_head, node) {
+ ? ? ? ? ? ? ? if (tmp_user->cookie == cookie) {
+ ? ? ? ? ? ? ? ? ? ? ? user = tmp_user;
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? }
+ ? ? ? }
+
+ ? ? ? /* If nothing to update, job done */
+ ? ? ? if (user && (user->node.prio == min_latency))
+ ? ? ? ? ? ? ? goto out;
+
+ ? ? ? if (!user) {
+ ? ? ? ? ? ? ? /* Add new entry to the list */
+ ? ? ? ? ? ? ? user = new_user;
+ ? ? ? ? ? ? ? user->cookie = cookie;
+ ? ? ? } else {
+ ? ? ? ? ? ? ? /* Update existing entry */
+ ? ? ? ? ? ? ? plist_del(&user->node, &pwrdm->wkup_lat_plist_head);
+ ? ? ? ? ? ? ? free_new_user = 1;
+ ? ? ? }
+
+ ? ? ? plist_node_init(&user->node, min_latency);
+ ? ? ? plist_add(&user->node, &pwrdm->wkup_lat_plist_head);
+
+ ? ? ? /* Find the aggregated constraint value from the list */
+ ? ? ? if (!plist_head_empty(&pwrdm->wkup_lat_plist_head))
+ ? ? ? ? ? ? ? value = plist_first(&pwrdm->wkup_lat_plist_head)->prio;
+
+ ? ? ? mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+
+ ? ? ? /* Free the newly allocated entry if not in use */
+ ? ? ? if (free_new_user)
+ ? ? ? ? ? ? ? kfree(new_user);
+
+ ? ? ? /* Apply the constraint to the pwrdm */
+ ? ? ? pr_debug("powerdomain: %s: pwrdm %s, value=%ld\n",
+ ? ? ? ? ? ? ? ?__func__, pwrdm->name, value);
+ ? ? ? return _pwrdm_wakeuplat_update_pwrst(pwrdm, value);
+
+out:
+ ? ? ? mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+ ? ? ? return 0;
+}
+
+/**
+ * pwrdm_wakeuplat_remove_constraint - Release a powerdomain wakeup latency
+ * ?constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint removal: Removes the identifier's entry from powerdomain's
+ * wakeup latency constraint list.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -EINVAL in case the constraint to remove is not
+ * existing, or the return value from _pwrdm_wakeuplat_update_pwrst.
+ *
+ * The caller must check the validity of the parameters.
+ */
+int pwrdm_wakeuplat_remove_constraint(struct powerdomain *pwrdm, void *cookie)
+{
+ ? ? ? struct pwrdm_wkup_constraints_entry *tmp_user, *user = NULL;
+ ? ? ? long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+
+ ? ? ? pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p\n",
+ ? ? ? ? ? ? ? ?__func__, pwrdm->name, cookie);
+
+ ? ? ? mutex_lock(&pwrdm->wkup_lat_plist_lock);
+
+ ? ? ? /* Check if there is a constraint for cookie */
+ ? ? ? plist_for_each_entry(tmp_user, &pwrdm->wkup_lat_plist_head, node) {
+ ? ? ? ? ? ? ? if (tmp_user->cookie == cookie) {
+ ? ? ? ? ? ? ? ? ? ? ? user = tmp_user;
+ ? ? ? ? ? ? ? ? ? ? ? break;
+ ? ? ? ? ? ? ? }
+ ? ? ? }
+
+ ? ? ? /* If constraint not existing or list empty, return -EINVAL */
+ ? ? ? if (!user)
+ ? ? ? ? ? ? ? goto out;
+
+ ? ? ? /* Remove the constraint from the list */
+ ? ? ? plist_del(&user->node, &pwrdm->wkup_lat_plist_head);
+
+ ? ? ? /* Find the aggregated constraint value from the list */
+ ? ? ? if (!plist_head_empty(&pwrdm->wkup_lat_plist_head))
+ ? ? ? ? ? ? ? value = plist_first(&pwrdm->wkup_lat_plist_head)->prio;
+
+ ? ? ? mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+
+ ? ? ? /* Release the constraint memory */
+ ? ? ? kfree(user);
+
+ ? ? ? /* Apply the constraint to the pwrdm */
+ ? ? ? pr_debug("powerdomain: %s: pwrdm %s, value=%ld\n",
+ ? ? ? ? ? ? ? ?__func__, pwrdm->name, value);
+ ? ? ? return _pwrdm_wakeuplat_update_pwrst(pwrdm, value);
+
+out:
+ ? ? ? mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+ ? ? ? return -EINVAL;
+}
+
+/**
Quoted 3 lines

?* pwrdm_get_context_loss_count - get powerdomain's context loss count ?* @pwrdm: struct powerdomain * to wait for
?*

"
- we need a debugfs entry to list all the constraints currently active in the system.
"
This point is valid. Having a debug mechanism is certainly useful in product development.
This functionality can/will be added as a separate patch after this series is accepted.

Regards,
Jean

Quoted 53 lines
arch/arm/mach-omap2/powerdomain.h +0 -0
index 06fb396..fca82fc 100644
@@ -16,6 +16,7 @@
 

?#include <linux/types.h>
?#include <linux/list.h>
+#include <linux/plist.h>
?#include <linux/mutex.h>
?#include <linux/atomic.h>

arch/arm/mach-omap2/powerdomain.h +0 -0
@@ -85,6 +86,8 @@ extern void omap44xx_powerdomains_init(void);
 

?#define PWRDM_MAX_PWRSTS ? ? ? 4

arch/arm/mach-omap2/powerdomain.h +2 -0
+#define UNSUP_STATE ? ? ? ? ? ?-1
+

?/* Powerdomain allowable state bitfields */
?#define PWRSTS_ON ? ? ? ? ? ? ?(1 << PWRDM_POWER_ON) ?#define PWRSTS_INACTIVE ? ? ? ? ? ? ? ?(1 << PWRDM_POWER_INACTIVE)

arch/arm/mach-omap2/powerdomain.h +0 -0
@@ -173,6 +176,16 @@ struct powerdomain {
 ? ? ? ?s64 timer;
 ? ? ? ?s64 state_timer[PWRDM_MAX_FUNC_PWRSTS];

?#endif
+ ? ? ? const s32 wakeup_lat[PWRDM_MAX_FUNC_PWRSTS];
+ ? ? ? struct plist_head wkup_lat_plist_head;
+ ? ? ? struct mutex wkup_lat_plist_lock;
+ ? ? ? int wkup_lat_next_state;

arch/arm/mach-omap2/powerdomain.h +6 -0
+};
+
+/* Linked list for the wake-up latency constraints */
+struct pwrdm_wkup_constraints_entry {
+ ? ? ? void ? ? ? ? ? ? ? ? ? ?*cookie;
+ ? ? ? struct plist_node ? ? ? node;

?};

?/**

arch/arm/mach-omap2/powerdomain.h +5 -1
@@ -270,6 +283,11 @@ int pwrdm_state_switch(struct powerdomain *pwrdm);
 ?int pwrdm_pre_transition(void);
 ?int pwrdm_post_transition(void);
 ?int pwrdm_set_lowpwrstchange(struct powerdomain *pwrdm);
+
+int pwrdm_wakeuplat_update_constraint(struct powerdomain *pwrdm, void *cookie,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? long min_latency);
+int pwrdm_wakeuplat_remove_constraint(struct powerdomain *pwrdm, void *cookie);
+
 ?int pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
 ?bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
 
--

1.7.7.6

#3 lore raw

PATCH 1/10 ARM: OMAP2+: PM QoS: control the power domains next state from the constraints

In reply to Jean Pihet

On Thu, Jun 14, 2012 at 10:05 AM, Jean Pihet <[email protected]> wrote:
Minor comment follows:
[...]

Quoted 13 lines
arch/arm/mach-omap2/powerdomain.c +13 -0
+/**
+ * _pwrdm_wakeuplat_update_pwrst - Update power domain power state if needed
+ * @pwrdm: struct powerdomain * to which requesting device belongs to.
+ * @min_latency: the allowed wake-up latency for the given power domain. A
+ *  value of PM_QOS_DEV_LAT_DEFAULT_VALUE means 'no constraint' on the pwrdm.
+ *
+ * Finds the power domain next power state that fulfills the constraint.
+ * Programs a new target state if it is different from current power state.
+ * The power domains get the next power state programmed directly in the
+ * registers.
+ *
+ * Returns 0 in case of success, -EINVAL in case of invalid parameters,
+ * or the return value from omap_set_pwrdm_state.

arch/arm/mach-omap2/powerdomain.c static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused) · line 233

Quoted 10 lines
arch/arm/mach-omap2/powerdomain.c +10 -0
+ */
+static int _pwrdm_wakeuplat_update_pwrst(struct powerdomain *pwrdm,
+                                        long min_latency)
+{
+       int ret = 0, state, new_state = PWRDM_FUNC_PWRST_ON;
+
+       if (!pwrdm) {
+               WARN(1, "powerdomain: %s: invalid parameter(s)", __func__);
+               return -EINVAL;
+       }

_pwrdm_wakeuplat_update_pwrst is an helper function, we check pwrdm to be valid here,
however,

[...]

Quoted 24 lines

/* Public functions */

/**
+ * pwrdm_wakeuplat_update_constraint - Set or update a powerdomain wakeup
+ * latency constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ * @min_latency: minimum wakeup latency constraint (in microseconds) for
+ * the given pwrdm
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint set/update: Adds a new entry to powerdomain's wake-up latency
+ * constraint list. If the constraint identifier already exists in the list,
+ * the old value is overwritten.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -ENOMEM in case of memory shortage, -EINVAL in
+ * case of invalid latency value, or the return value from
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * The caller must check the validity of the parameters.
+ */

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1409

Quoted 9 lines
arch/arm/mach-omap2/powerdomain.c +9 -0
+int pwrdm_wakeuplat_update_constraint(struct powerdomain *pwrdm, void *cookie,
+                                     long min_latency)
+{
+       struct pwrdm_wkup_constraints_entry *tmp_user, *new_user, *user = NULL;
+       long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+       int free_new_user = 0;
+
+       pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p, min_latency=%ld\n",
+                __func__, pwrdm->name, cookie, min_latency);

here,

Quoted 6 lines
arch/arm/mach-omap2/powerdomain.c +6 -0
+
+       if (min_latency <= PM_QOS_DEV_LAT_DEFAULT_VALUE) {
+               pr_warn("%s: min_latency >= PM_QOS_DEV_LAT_DEFAULT_VALUE\n",
+                       __func__);
+               return -EINVAL;
+       }

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1425

Quoted 10 lines
arch/arm/mach-omap2/powerdomain.c +10 -0
+
+       /* Allocate a new entry for insertion in the list */
+       new_user = kzalloc(sizeof(struct pwrdm_wkup_constraints_entry),
+                          GFP_KERNEL);
+       if (!new_user) {
+               pr_err("%s: FATAL ERROR: kzalloc failed\n", __func__);
+               return -ENOMEM;
+       }
+
+       mutex_lock(&pwrdm->wkup_lat_plist_lock);

here,

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1433

Quoted 8 lines
arch/arm/mach-omap2/powerdomain.c +8 -0
+
+       /* Check if there already is a constraint for cookie */
+       plist_for_each_entry(tmp_user, &pwrdm->wkup_lat_plist_head, node) {
+               if (tmp_user->cookie == cookie) {
+                       user = tmp_user;
+                       break;
+               }
+       }

here,

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1445

Quoted 12 lines
arch/arm/mach-omap2/powerdomain.c +12 -0
+
+       /* If nothing to update, job done */
+       if (user && (user->node.prio == min_latency))
+               goto out;
+
+       if (!user) {
+               /* Add new entry to the list */
+               user = new_user;
+               user->cookie = cookie;
+       } else {
+               /* Update existing entry */
+               plist_del(&user->node, &pwrdm->wkup_lat_plist_head);

here

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1450

Quoted 5 lines
arch/arm/mach-omap2/powerdomain.c +5 -0
+               free_new_user = 1;
+       }
+
+       plist_node_init(&user->node, min_latency);
+       plist_add(&user->node, &pwrdm->wkup_lat_plist_head);

here

Quoted 3 lines
arch/arm/mach-omap2/powerdomain.c +3 -0
+
+       /* Find the aggregated constraint value from the list */
+       if (!plist_head_empty(&pwrdm->wkup_lat_plist_head))

...

Quoted 1 line

+ value = plist_first(&pwrdm->wkup_lat_plist_head)->prio;

...

Quoted 2 lines
(quoted diff) +2 -0
+
+       mutex_unlock(&pwrdm->wkup_lat_plist_lock);

...

Quoted 8 lines
arch/arm/mach-omap2/powerdomain.c +8 -0
+
+       /* Free the newly allocated entry if not in use */
+       if (free_new_user)
+               kfree(new_user);
+
+       /* Apply the constraint to the pwrdm */
+       pr_debug("powerdomain: %s: pwrdm %s, value=%ld\n",
+                __func__, pwrdm->name, value);

...

Quoted 1 line

+ return _pwrdm_wakeuplat_update_pwrst(pwrdm, value);

we have already crashed before we do a WARN in helper.

Quoted 21 lines
arch/arm/mach-omap2/powerdomain.c +21 -0
+
+out:
+       mutex_unlock(&pwrdm->wkup_lat_plist_lock);
+       return 0;
+}
+
+/**
+ * pwrdm_wakeuplat_remove_constraint - Release a powerdomain wakeup latency
+ *  constraint and apply it
+ * @pwrdm: struct powerdomain * which the constraint applies to
+ * @cookie: constraint identifier, used for tracking
+ *
+ * Tracks the constraints by @cookie.
+ * Constraint removal: Removes the identifier's entry from powerdomain's
+ * wakeup latency constraint list.
+ *
+ * Applies the aggregated constraint value for the given pwrdm by calling
+ * _pwrdm_wakeuplat_update_pwrst.
+ *
+ * Returns 0 upon success, -EINVAL in case the constraint to remove is not
+ * existing, or the return value from _pwrdm_wakeuplat_update_pwrst.

arch/arm/mach-omap2/powerdomain.c int pwrdm_post_transition(void) · line 1496

Quoted 10 lines
arch/arm/mach-omap2/powerdomain.c +10 -0
+ *
+ * The caller must check the validity of the parameters.
+ */
+int pwrdm_wakeuplat_remove_constraint(struct powerdomain *pwrdm, void *cookie)
+{
+       struct pwrdm_wkup_constraints_entry *tmp_user, *user = NULL;
+       long value = PM_QOS_DEV_LAT_DEFAULT_VALUE;
+
+       pr_debug("powerdomain: %s: pwrdm %s, cookie=0x%p\n",
+                __func__, pwrdm->name, cookie);

... same story here as well.. and so on..

Regards,
Nishanth Menon

#4 lore raw

PATCH 1/10 ARM: OMAP2+: PM QoS: control the power domains next state from the constraints

In reply to Jean Pihet
Quoted 13 lines · Jean Pihet
arch/arm/mach-omap2/powerdomain.c +7 -0
+static int _pwrdm_wakeuplat_update_pwrst(struct powerdomain *pwrdm,
+                                        long min_latency)
+{
+       int ret = 0, state, new_state = PWRDM_FUNC_PWRST_ON;
+
+       if (!pwrdm) {
+               WARN(1, "powerdomain: %s: invalid parameter(s)",

__func__);

arch/arm/mach-omap2/powerdomain.c +3 -0
+               return -EINVAL;
+       }
+

arch/arm/mach-omap2/powerdomain.c static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused) · line 244

Quoted 10 lines
arch/arm/mach-omap2/powerdomain.c +10 -0
+       /*
+        * Find the next supported power state with
+        *  wakeup latency <= min_latency.
+        * Pick the lower state if no constraint on the pwrdm
+        *  (min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE).
+        * Skip the states marked as unsupported (UNSUP_STATE).
+        * If no power state found, fall back to PWRDM_FUNC_PWRST_ON.
+        */
+       for (state = 0x0; state < PWRDM_MAX_FUNC_PWRSTS; state++) {
+               if ((min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE) ||

Since we search for default_value, we will endup matching OFF always, even if it is supported
state(marked UNSUP_STATE) or not. That is not correct, even though omap_setpwrdm_state
will check for achievable state before setting it.

arch/arm/mach-omap2/powerdomain.c static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused) · line 246

Quoted 2 lines
arch/arm/mach-omap2/powerdomain.c +2 -0
+                   ((pwrdm->wakeup_lat[state] != UNSUP_STATE) &&
+                    (pwrdm->wakeup_lat[state] <= min_latency))) {

further instead of the ()s, can we make it simple as:
if (pwrdm->wakeup_lat[state] == UNSUP_STATE)

        continue;
if (min_latency == PM_QOS_DEV_LAT_DEFAULT_VALUE ||
     pwrdm->wakeup_lat[state] <= min_latency) {
        new_state = state;
        break;
}

arch/arm/mach-omap2/powerdomain.c static int _pwrdm_post_transition_cb(struct powerdomain *pwrdm, void *unused) · line 250

Quoted 4 lines
arch/arm/mach-omap2/powerdomain.c +4 -0
+                       new_state = state;
+                       break;
+               }
+       }

Regards,
Nishanth Menon

author
#5 lore raw

PATCH v8 2/10 ARM: OMAP2+: hwmod: manage the wake-up latency constraints

In reply to Jean Pihet

The OMAP PM code implements a handler for the per-device PM QoS framework. The handler queries the omap_hwmod layer in order to manage the power domains wake-up latency constraints. Hwmod retrieves the correct power domain and if it exists it calls the corresponding power domain function.

Tested on OMAP3 Beagleboard and OMAP4 Pandaboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

[paul at pwsan.com: cleaned some documentation; split set/remove constraint
functions; modified to return -EINVAL until underlying code is ready]

---
 arch/arm/mach-omap2/omap_hwmod.c             |   54 +++++++++++++++++++++++++-
 arch/arm/plat-omap/include/plat/omap_hwmod.h |    5 ++
 2 files changed, 58 insertions(+), 1 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +53 -1
index bf86f7e..cc173d9 100644
@@ -145,6 +145,7 @@
 #include "powerdomain.h"
 #include <plat/clock.h>
 #include <plat/omap_hwmod.h>
+#include <plat/omap_device.h>
 #include <plat/prcm.h>
 
 #include "cm2xxx_3xxx.h"
@@ -3301,10 +3302,61 @@ ohsps_unlock:
 }
 
 /**
+ * omap_hwmod_set_wakeuplat_constraint - set/release a wake-up latency
+ * constraint
+ * @oh: struct omap_hwmod* to which the target device belongs to.
+ * @cookie: identifier of the constraints list for @oh.
+ * @min_latency: the minimum allowed wake-up latency for @oh.
+ *
+ * Sets a wakeup latency contraint.  (To remove a wakeup latency
+ * constraint, call omap_hwmod_remove_wakeuplat_constraint()).
+ * Returns the return value from pwrdm_wakeuplat_remove_constraint(),
+ * or -EINVAL in case of invalid parameters.
+ */
+int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
+					long min_latency)
+{
+	struct powerdomain *pwrdm = omap_hwmod_get_pwrdm(oh);
+
+	if (!pwrdm)
+		return -EINVAL;
+
+	/*
+	 * XXX Update to use pwrdm_wakeuplat_update_constraint() when
+	 * that code is ready
+	 */
+	return -EINVAL;
+}
+
+/**
+ * omap_hwmod_remove_wakeuplat_constraint - release a wake-up latency
+ * constraint
+ * @oh: struct omap_hwmod* to which the target device belongs to.
+ * @cookie: identifier of the constraints list for @oh.
+ *
+ * Removes a wakeup latency contraint.  Returns the return value from
+ * pwrdm_wakeuplat_update_constraint(), or -EINVAL in case of invalid
+ * parameters.
+ */
+int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)
+{
+	struct powerdomain *pwrdm = omap_hwmod_get_pwrdm(oh);
+
+	if (!pwrdm)
+		return -EINVAL;
+
+	/*
+	 * XXX Update to use pwrdm_wakeuplat_remove_constraint() when
+	 * that code is ready
+	 */
+	return -EINVAL;
+}
+
+/**
  * omap_hwmod_get_context_loss_count - get lost context count
  * @oh: struct omap_hwmod *
  *
- * Query the powerdomain of of @oh to get the context loss
+ * Query the powerdomain of @oh to get the context loss
  * count for this device.
  *
  * Returns the context loss count of the powerdomain assocated with @oh
arch/arm/plat-omap/include/plat/omap_hwmod.h +5 -0
index c835b71..3aa10df 100644
@@ -623,6 +623,11 @@ int omap_hwmod_for_each_by_class(const char *classname,
 				 void *user);
 
 int omap_hwmod_set_postsetup_state(struct omap_hwmod *oh, u8 state);
+
+int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
+					long min_latency);
+int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie);
+
 int omap_hwmod_get_context_loss_count(struct omap_hwmod *oh);
 
 int omap_hwmod_no_setup_reset(struct omap_hwmod *oh);
Signature · 1 line
1.7.7.6
author
#6 lore raw

PATCH v8 3/10 ARM: OMAP2+: PM QoS: manage the per-device latency constraints in hwmod

In reply to Jean Pihet

Call the per-device PM QoS functions of the power domain code from the hwmod layer, in order to apply the constraints requested to a device.

While at it, correct the functions kerneldoc.

---
 arch/arm/mach-omap2/omap_hwmod.c |   22 ++++++----------------
 1 files changed, 6 insertions(+), 16 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +6 -16
index cc173d9..4f43e0c 100644
@@ -3302,15 +3302,13 @@ ohsps_unlock:
 }
 
 /**
- * omap_hwmod_set_wakeuplat_constraint - set/release a wake-up latency
+ * omap_hwmod_set_wakeuplat_constraint - Set or update a wake-up latency
  * constraint
  * @oh: struct omap_hwmod* to which the target device belongs to.
  * @cookie: identifier of the constraints list for @oh.
  * @min_latency: the minimum allowed wake-up latency for @oh.
  *
- * Sets a wakeup latency contraint.  (To remove a wakeup latency
- * constraint, call omap_hwmod_remove_wakeuplat_constraint()).
- * Returns the return value from pwrdm_wakeuplat_remove_constraint(),
+ * Returns the return value from pwrdm_wakeuplat_update_constraint(),
  * or -EINVAL in case of invalid parameters.
  */
 int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
@@ -3321,21 +3319,17 @@ int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
 	if (!pwrdm)
 		return -EINVAL;
 
-	/*
-	 * XXX Update to use pwrdm_wakeuplat_update_constraint() when
-	 * that code is ready
-	 */
-	return -EINVAL;
+	return pwrdm_wakeuplat_update_constraint(pwrdm, cookie, min_latency);
 }
 
 /**
- * omap_hwmod_remove_wakeuplat_constraint - release a wake-up latency
+ * omap_hwmod_remove_wakeuplat_constraint - Release a wake-up latency
  * constraint
  * @oh: struct omap_hwmod* to which the target device belongs to.
  * @cookie: identifier of the constraints list for @oh.
  *
  * Removes a wakeup latency contraint.  Returns the return value from
- * pwrdm_wakeuplat_update_constraint(), or -EINVAL in case of invalid
+ * pwrdm_wakeuplat_remove_constraint(), or -EINVAL in case of invalid
  * parameters.
  */
 int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)
@@ -3345,11 +3339,7 @@ int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)
 	if (!pwrdm)
 		return -EINVAL;
 
-	/*
-	 * XXX Update to use pwrdm_wakeuplat_remove_constraint() when
-	 * that code is ready
-	 */
-	return -EINVAL;
+	return pwrdm_wakeuplat_remove_constraint(pwrdm, cookie);
 }
 
 /**
Signature · 1 line
1.7.7.6
#7 lore raw

PATCH 3/10 ARM: OMAP2+: PM QoS: manage the per-device latency constraints in hwmod

Quoted 4 lines · Jean Pihet

Call the per-device PM QoS functions of the power domain code from the hwmod layer, in order to apply the constraints requested to a device.

While at it, correct the functions kerneldoc.

Shouldn't this patch be just merged with PATCH 02/10?

Quoted 66 lines
---
  arch/arm/mach-omap2/omap_hwmod.c |   22 ++++++----------------
  1 files changed, 6 insertions(+), 16 deletions(-)
arch/arm/mach-omap2/omap_hwmod.c +6 -16
index cc173d9..4f43e0c 100644
@@ -3302,15 +3302,13 @@ ohsps_unlock:
  }
 
  /**
- * omap_hwmod_set_wakeuplat_constraint - set/release a wake-up latency
+ * omap_hwmod_set_wakeuplat_constraint - Set or update a wake-up latency
   * constraint
   * @oh: struct omap_hwmod* to which the target device belongs to.
   * @cookie: identifier of the constraints list for @oh.
   * @min_latency: the minimum allowed wake-up latency for @oh.
   *
- * Sets a wakeup latency contraint.  (To remove a wakeup latency
- * constraint, call omap_hwmod_remove_wakeuplat_constraint()).
- * Returns the return value from pwrdm_wakeuplat_remove_constraint(),
+ * Returns the return value from pwrdm_wakeuplat_update_constraint(),
   * or -EINVAL in case of invalid parameters.
   */
  int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
@@ -3321,21 +3319,17 @@ int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,
  	if (!pwrdm)
  		return -EINVAL;
 
-	/*
-	 * XXX Update to use pwrdm_wakeuplat_update_constraint() when
-	 * that code is ready
-	 */
-	return -EINVAL;
+	return pwrdm_wakeuplat_update_constraint(pwrdm, cookie, min_latency);
  }
 
  /**
- * omap_hwmod_remove_wakeuplat_constraint - release a wake-up latency
+ * omap_hwmod_remove_wakeuplat_constraint - Release a wake-up latency
   * constraint
   * @oh: struct omap_hwmod* to which the target device belongs to.
   * @cookie: identifier of the constraints list for @oh.
   *
   * Removes a wakeup latency contraint.  Returns the return value from
- * pwrdm_wakeuplat_update_constraint(), or -EINVAL in case of invalid
+ * pwrdm_wakeuplat_remove_constraint(), or -EINVAL in case of invalid
   * parameters.
   */
  int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)
@@ -3345,11 +3339,7 @@ int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)
  	if (!pwrdm)
  		return -EINVAL;
 
-	/*
-	 * XXX Update to use pwrdm_wakeuplat_remove_constraint() when
-	 * that code is ready
-	 */
-	return -EINVAL;
+	return pwrdm_wakeuplat_remove_constraint(pwrdm, cookie);
  }
 
  /**
author
#8 lore raw

PATCH v8 3/10 ARM: OMAP2+: PM QoS: manage the per-device latency constraints in hwmod

Rajendra,

Quoted 9 lines · Rajendra Nayak
Quoted 5 lines · Jean Pihet

Call the per-device PM QoS functions of the power domain code from the hwmod layer, in order to apply the constraints requested to a device.

While at it, correct the functions kerneldoc.

Shouldn't this patch be just merged with PATCH 02/10?

Ideally yes!

Paul,
Is this possiblr or is the patch 02/10 already scheduled for inclusion in l-o or mainline?

Regards,
Jean

Quoted 76 lines
Quoted 74 lines

---
?arch/arm/mach-omap2/omap_hwmod.c | ? 22 ++++++---------------- ?1 files changed, 6 insertions(+), 16 deletions(-)

arch/arm/mach-omap2/omap_hwmod.c +0 -0
index cc173d9..4f43e0c 100644
@@ -3302,15 +3302,13 @@ ohsps_unlock:
 ?}
 

?/**
- * omap_hwmod_set_wakeuplat_constraint - set/release a wake-up latency
+ * omap_hwmod_set_wakeuplat_constraint - Set or update a wake-up latency ? * constraint
? * @oh: struct omap_hwmod* to which the target device belongs to. ? * @cookie: identifier of the constraints list for @oh.
? * @min_latency: the minimum allowed wake-up latency for @oh. ? *
- * Sets a wakeup latency contraint. ?(To remove a wakeup latency
- * constraint, call omap_hwmod_remove_wakeuplat_constraint()).
- * Returns the return value from pwrdm_wakeuplat_remove_constraint(),
+ * Returns the return value from pwrdm_wakeuplat_update_constraint(), ? * or -EINVAL in case of invalid parameters.
? */
?int omap_hwmod_set_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie,

arch/arm/mach-omap2/omap_hwmod.c +1 -5
@@ -3321,21 +3319,17 @@ int omap_hwmod_set_wakeuplat_constraint(struct
 omap_hwmod *oh, void *cookie,
 ? ? ? ?if (!pwrdm)
 ? ? ? ? ? ? ? ?return -EINVAL;
 
- ? ? ? /*
- ? ? ? ?* XXX Update to use pwrdm_wakeuplat_update_constraint() when
- ? ? ? ?* that code is ready
- ? ? ? ?*/
- ? ? ? return -EINVAL;
+ ? ? ? return pwrdm_wakeuplat_update_constraint(pwrdm, cookie,
 min_latency);
 ?}
 

?/**
- * omap_hwmod_remove_wakeuplat_constraint - release a wake-up latency
+ * omap_hwmod_remove_wakeuplat_constraint - Release a wake-up latency ? * constraint
? * @oh: struct omap_hwmod* to which the target device belongs to. ? * @cookie: identifier of the constraints list for @oh.
? *
? * Removes a wakeup latency contraint. ?Returns the return value from
- * pwrdm_wakeuplat_update_constraint(), or -EINVAL in case of invalid
+ * pwrdm_wakeuplat_remove_constraint(), or -EINVAL in case of invalid ? * parameters.
? */
?int omap_hwmod_remove_wakeuplat_constraint(struct omap_hwmod *oh, void *cookie)

arch/arm/mach-omap2/omap_hwmod.c +1 -5
@@ -3345,11 +3339,7 @@ int omap_hwmod_remove_wakeuplat_constraint(struct
 omap_hwmod *oh, void *cookie)
 ? ? ? ?if (!pwrdm)
 ? ? ? ? ? ? ? ?return -EINVAL;
 
- ? ? ? /*
- ? ? ? ?* XXX Update to use pwrdm_wakeuplat_remove_constraint() when
- ? ? ? ?* that code is ready
- ? ? ? ?*/
- ? ? ? return -EINVAL;
+ ? ? ? return pwrdm_wakeuplat_remove_constraint(pwrdm, cookie);
 ?}
 

?/**

author
#9 lore raw

PATCH v8 4/10 ARM: OMAP: omap_device: register to the per-device PM QoS framework

In reply to Jean Pihet

Implement the devices wake-up latency constraints using the global device PM QoS notification handler which applies the constraints to the underlying layer by calling the corresponding function at hwmod level.

Tested on OMAP3 Beagleboard and OMAP4 Pandaboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

[paul at pwsan.com: modified to work with omap_devices with large numbers of
hwmods; moved code to mach-omap2/omap_device.c; added documentation; use notifier return codes]

---
 arch/arm/plat-omap/omap_device.c |   81 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)
arch/arm/plat-omap/omap_device.c +80 -1
index c490240..241705b 100644
@@ -3,6 +3,7 @@
  * omap_device implementation
  *
  * Copyright (C) 2009-2010 Nokia Corporation
+ * Copyright (C) 2011 Texas Instruments, Inc.
  * Paul Walmsley, Kevin Hilman
  *
  * Developed in collaboration with (alphabetical order): Benoit
@@ -89,6 +90,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/of.h>
 #include <linux/notifier.h>
+#include <linux/pm_qos.h>
 
 #include <plat/omap_device.h>
 #include <plat/omap_hwmod.h>
@@ -401,6 +403,72 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
 	return NOTIFY_DONE;
 }
 
+/**
+ * _omap_device_pm_qos_handler - interface to the per-device PM QoS framework
+ * @nb: pointer to omap_device_pm_qos_nb (not used)
+ * @new_value: new maximum wakeup latency constraint for @req->dev (in us)
+ * @req: struct dev_pm_qos_request * passed by the Linux PM QoS code
+ *
+ * Called by the Linux core device PM QoS code to alter the maximum
+ * wakeup latency constraint on a device.  If the underlying device is
+ * an omap_device, then this code will pass the constraint on to the
+ * underlying hwmods.  Returns -EINVAL if this code can't handle the
+ * constraint for some reason, or passes along the return code from the
+ * hwmod wakeup latency constraint functions.
+ */
+static int _omap_device_pm_qos_handler(struct notifier_block *nb,
+				       unsigned long new_value,
+				       void *req)
+{
+	struct omap_device *od;
+	struct omap_hwmod *oh;
+	struct platform_device *pdev;
+	struct dev_pm_qos_request *dev_pm_qos_req = req;
+	int ret = NOTIFY_OK;
+	int r, i;
+
+	pr_debug("OMAP PM constraints: req at 0x%p, new_value=%lu\n",
+		 req, new_value);
+
+	/* Look for the platform device for the constraint target device */
+	pdev = to_platform_device(dev_pm_qos_req->dev);
+
+	/* Try to catch non platform devices */
+	if (pdev->name == NULL) {
+		pr_err("%s: Error: platform device for device %s not valid\n",
+		       __func__, dev_name(dev_pm_qos_req->dev));
+		return NOTIFY_DONE;
+	}
+
+	/* Find the associated omap_device for dev */
+	od = to_omap_device(pdev);
+	if (od == NULL) {
+		pr_err("%s: Error: no omap_device for device %s\n",
+		       __func__, dev_name(dev_pm_qos_req->dev));
+		return NOTIFY_DONE;
+	}
+
+	pr_debug("OMAP PM constraints: req at 0x%p, dev=0x%p, new_value=%lu\n",
+		 req, dev_pm_qos_req->dev, new_value);
+
+	for (i = 0; i < od->hwmods_cnt; i++) {
+		oh = od->hwmods[i];
+		if (new_value == PM_QOS_DEV_LAT_DEFAULT_VALUE)
+			r = omap_hwmod_remove_wakeuplat_constraint(
+							oh,
+							dev_pm_qos_req);
+		else
+			r = omap_hwmod_set_wakeuplat_constraint(
+							oh,
+							dev_pm_qos_req,
+							new_value);
+
+		if (!r)
+			ret = NOTIFY_BAD;
+	}
+
+	return ret;
+}
 
 /* Public functions for use by core code */
 
@@ -1115,13 +1183,24 @@ int omap_device_enable_clocks(struct omap_device *od)
 	return 0;
 }
 
+static struct notifier_block omap_device_pm_qos_nb = {
+	.notifier_call = _omap_device_pm_qos_handler,
+};
+
 static struct notifier_block platform_nb = {
 	.notifier_call = _omap_device_notifier_call,
 };
 
 static int __init omap_device_init(void)
 {
+	int ret;
+
 	bus_register_notifier(&platform_bus_type, &platform_nb);
-	return 0;
+
+	ret = dev_pm_qos_add_global_notifier(&omap_device_pm_qos_nb);
+	if (ret)
+		pr_err("omap_device: cannot add global notifier for dev PM QoS\n");
+
+	return ret;
 }
 core_initcall(omap_device_init);
Signature · 1 line
1.7.7.6
#10 lore raw

PATCH 4/10 ARM: OMAP: omap_device: register to the per-device PM QoS framework

Quoted 22 lines · Jean Pihet

Implement the devices wake-up latency constraints using the global device PM QoS notification handler which applies the constraints to the underlying layer by calling the corresponding function at hwmod level.

Tested on OMAP3 Beagleboard and OMAP4 Pandaboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

[paul at pwsan.com: modified to work with omap_devices with large numbers of
hwmods; moved code to mach-omap2/omap_device.c; added documentation; use notifier return codes]

---
  arch/arm/plat-omap/omap_device.c |   81 +++++++++++++++++++++++++++++++++++++-
  1 files changed, 80 insertions(+), 1 deletions(-)
arch/arm/plat-omap/omap_device.c +0 -0
index c490240..241705b 100644

arch/arm/plat-omap/omap_device.c line 6

Quoted 4 lines
arch/arm/plat-omap/omap_device.c +1 -0
@@ -3,6 +3,7 @@
   * omap_device implementation
   *
   * Copyright (C) 2009-2010 Nokia Corporation
+ * Copyright (C) 2011 Texas Instruments, Inc.

2012?

Quoted 37 lines
arch/arm/plat-omap/omap_device.c +23 -0
   * Paul Walmsley, Kevin Hilman
   *
   * Developed in collaboration with (alphabetical order): Benoit
@@ -89,6 +90,7 @@
  #include<linux/pm_runtime.h>
  #include<linux/of.h>
  #include<linux/notifier.h>
+#include<linux/pm_qos.h>
 
  #include<plat/omap_device.h>
  #include<plat/omap_hwmod.h>
@@ -401,6 +403,72 @@ static int _omap_device_notifier_call(struct notifier_block *nb,
  	return NOTIFY_DONE;
  }
 
+/**
+ * _omap_device_pm_qos_handler - interface to the per-device PM QoS framework
+ * @nb: pointer to omap_device_pm_qos_nb (not used)
+ * @new_value: new maximum wakeup latency constraint for @req->dev (in us)
+ * @req: struct dev_pm_qos_request * passed by the Linux PM QoS code
+ *
+ * Called by the Linux core device PM QoS code to alter the maximum
+ * wakeup latency constraint on a device.  If the underlying device is
+ * an omap_device, then this code will pass the constraint on to the
+ * underlying hwmods.  Returns -EINVAL if this code can't handle the
+ * constraint for some reason, or passes along the return code from the
+ * hwmod wakeup latency constraint functions.
+ */
+static int _omap_device_pm_qos_handler(struct notifier_block *nb,
+				       unsigned long new_value,
+				       void *req)
+{
+	struct omap_device *od;
+	struct omap_hwmod *oh;
+	struct platform_device *pdev;
+	struct dev_pm_qos_request *dev_pm_qos_req = req;
+	int ret = NOTIFY_OK;

arch/arm/plat-omap/omap_device.c static int _omap_device_notifier_call(struct notifier_block *nb, · line 437

Quoted 10 lines
arch/arm/plat-omap/omap_device.c +10 -0
+	int r, i;
+
+	pr_debug("OMAP PM constraints: req at 0x%p, new_value=%lu\n",
+		 req, new_value);
+
+	/* Look for the platform device for the constraint target device */
+	pdev = to_platform_device(dev_pm_qos_req->dev);
+
+	/* Try to catch non platform devices */
+	if (pdev->name == NULL) {

Is this a safe way to catch non platform devices?

regards,
Rajendra

Quoted 63 lines
arch/arm/plat-omap/omap_device.c +46 -1
+		pr_err("%s: Error: platform device for device %s not valid\n",
+		       __func__, dev_name(dev_pm_qos_req->dev));
+		return NOTIFY_DONE;
+	}
+
+	/* Find the associated omap_device for dev */
+	od = to_omap_device(pdev);
+	if (od == NULL) {
+		pr_err("%s: Error: no omap_device for device %s\n",
+		       __func__, dev_name(dev_pm_qos_req->dev));
+		return NOTIFY_DONE;
+	}
+
+	pr_debug("OMAP PM constraints: req at 0x%p, dev=0x%p, new_value=%lu\n",
+		 req, dev_pm_qos_req->dev, new_value);
+
+	for (i = 0; i<  od->hwmods_cnt; i++) {
+		oh = od->hwmods[i];
+		if (new_value == PM_QOS_DEV_LAT_DEFAULT_VALUE)
+			r = omap_hwmod_remove_wakeuplat_constraint(
+							oh,
+							dev_pm_qos_req);
+		else
+			r = omap_hwmod_set_wakeuplat_constraint(
+							oh,
+							dev_pm_qos_req,
+							new_value);
+
+		if (!r)
+			ret = NOTIFY_BAD;
+	}
+
+	return ret;
+}
 
  /* Public functions for use by core code */
 
@@ -1115,13 +1183,24 @@ int omap_device_enable_clocks(struct omap_device *od)
  	return 0;
  }
 
+static struct notifier_block omap_device_pm_qos_nb = {
+	.notifier_call = _omap_device_pm_qos_handler,
+};
+
  static struct notifier_block platform_nb = {
  	.notifier_call = _omap_device_notifier_call,
  };
 
  static int __init omap_device_init(void)
  {
+	int ret;
+
  	bus_register_notifier(&platform_bus_type,&platform_nb);
-	return 0;
+
+	ret = dev_pm_qos_add_global_notifier(&omap_device_pm_qos_nb);
+	if (ret)
+		pr_err("omap_device: cannot add global notifier for dev PM QoS\n");
+
+	return ret;
  }
  core_initcall(omap_device_init);
#11 lore raw

PATCH 4/10 ARM: OMAP: omap_device: register to the per-device PM QoS framework

Quoted 10 lines · Rajendra Nayak

arch/arm/plat-omap/omap_device.c static int _omap_device_notifier_call(struct notifier_block *nb, · line 437

Quoted 7 lines

+ /* Look for the platform device for the constraint target device
*/

arch/arm/plat-omap/omap_device.c +4 -0
+       pdev = to_platform_device(dev_pm_qos_req->dev);
+
+       /* Try to catch non platform devices */
+       if (pdev->name == NULL) {

Is this a safe way to catch non platform devices?

in addition, we should check !pdev before attempting to dereference and check for pdev->name

Regards,
Nishanth Menon

author
#12 lore raw

PATCH v8 5/10 ARM: OMAP3: cpuidle: next C-state decision depends on the PM QoS MPU and CORE constraints

In reply to Jean Pihet

The MPU latency figures for cpuidle include the MPU itself and also the peripherals needed for the MPU to execute instructions (e.g. main memory, caches, IRQ controller, MMU etc). On OMAP3 those peripherals belong to the MPU and CORE power domains and so the cpuidle C-states are a combination of MPU and CORE states.

This patch implements the relation between the cpuidle and per- device PM QoS frameworks in the OMAP3 specific idle callbacks.

The chosen C-state shall satisfy the following conditions:
. the 'valid' field is enabled,
. it satisfies the enable_off_mode flag,
. the next state for MPU and CORE power domains is not lower than the
next state calculated by the per-device PM QoS.

Tested on OMAP3 Beagleboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

---
 arch/arm/mach-omap2/cpuidle34xx.c |   64 ++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 22 deletions(-)
arch/arm/mach-omap2/cpuidle34xx.c +42 -22
index ef8d7d4..1f33b8e 100644
@@ -92,8 +92,8 @@ static int _cpuidle_deny_idle(struct powerdomain *pwrdm,
 }
 
 static int __omap3_enter_idle(struct cpuidle_device *dev,
-				struct cpuidle_driver *drv,
-				int index)
+			      struct cpuidle_driver *drv,
+			      int index)
 {
 	struct omap3_idle_statedata *cx = &omap3_idle_data[index];
 	u32 mpu_state = cx->mpu_state, core_state = cx->core_state;
@@ -150,10 +150,14 @@ return_sleep_time:
  *
  * Called from the CPUidle framework to program the device to the
  * specified target state selected by the governor.
+ *
+ * Note: this function does not check for any pending activity or dependency
+ * between power domains states, so the caller shall check the parameters
+ * correctness.
  */
 static inline int omap3_enter_idle(struct cpuidle_device *dev,
-				struct cpuidle_driver *drv,
-				int index)
+				   struct cpuidle_driver *drv,
+				   int index)
 {
 	return cpuidle_wrap_enter(dev, drv, index, __omap3_enter_idle);
 }
@@ -168,8 +172,10 @@ static inline int omap3_enter_idle(struct cpuidle_device *dev,
  * to the caller. Else, this function searches for a lower c-state which is
  * still valid (as defined in omap3_power_states[]) and returns its index.
  *
- * A state is valid if the 'valid' field is enabled and
- * if it satisfies the enable_off_mode condition.
+ * A state is valid if:
+ * . it satisfies the enable_off_mode flag,
+ * . the next state for MPU and CORE power domains is not lower than the
+ *   state programmed by the per-device PM QoS.
  */
 static int next_valid_state(struct cpuidle_device *dev,
 			    struct cpuidle_driver *drv, int index)
@@ -177,6 +183,8 @@ static int next_valid_state(struct cpuidle_device *dev,
 	struct omap3_idle_statedata *cx = &omap3_idle_data[index];
 	u32 mpu_deepest_state = PWRDM_FUNC_PWRST_CSWR;
 	u32 core_deepest_state = PWRDM_FUNC_PWRST_CSWR;
+	u32 mpu_pm_qos_next_state = mpu_pd->wkup_lat_next_state;
+	u32 core_pm_qos_next_state = core_pd->wkup_lat_next_state;
 	int idx;
 	int next_index = -1;
 
@@ -193,7 +201,9 @@ static int next_valid_state(struct cpuidle_device *dev,
 
 	/* Check if current state is valid */
 	if ((cx->mpu_state >= mpu_deepest_state) &&
-	    (cx->core_state >= core_deepest_state))
+	    (cx->core_state >= core_deepest_state) &&
+	    (cx->mpu_state >= mpu_pm_qos_next_state) &&
+	    (cx->core_state >= core_pm_qos_next_state))
 		return index;
 
 	/*
@@ -203,7 +213,9 @@ static int next_valid_state(struct cpuidle_device *dev,
 	for (idx = index - 1; idx >= 0; idx--) {
 		cx =  &omap3_idle_data[idx];
 		if ((cx->mpu_state >= mpu_deepest_state) &&
-		    (cx->core_state >= core_deepest_state)) {
+		    (cx->core_state >= core_deepest_state) &&
+		    (cx->mpu_state >= mpu_pm_qos_next_state) &&
+		    (cx->core_state >= core_pm_qos_next_state)) {
 			next_index = idx;
 			break;
 		}
@@ -224,12 +236,15 @@ static int next_valid_state(struct cpuidle_device *dev,
  * @drv: cpuidle driver
  * @index: array index of target state to be programmed
  *
- * This function checks for any pending activity and then programs
- * the device to the specified or a safer state.
+ * Called from the CPUidle framework to program the device to the
+ * specified target state selected by the governor.
+ *
+ * This function checks for any pending activity or dependency between
+ * power domains states and then programs the device to the specified
+ * or a safer state.
  */
 static int omap3_enter_idle_bm(struct cpuidle_device *dev,
-				struct cpuidle_driver *drv,
-			       int index)
+			       struct cpuidle_driver *drv, int index)
 {
 	int new_state_idx;
 	u32 core_next_state, per_next_state = 0, per_saved_state = 0;
@@ -245,19 +260,13 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
 		goto select_state;
 	}
 
-	/*
-	 * FIXME: we currently manage device-specific idle states
-	 *        for PER and CORE in combination with CPU-specific
-	 *        idle states.  This is wrong, and device-specific
-	 *        idle management needs to be separated out into
-	 *        its own code.
-	 */
+	new_state_idx = next_valid_state(dev, drv, index);
 
 	/*
 	 * Prevent PER off if CORE is not in retention or off as this
 	 * would disable PER wakeups completely.
 	 */
-	cx = &omap3_idle_data[index];
+	cx = &omap3_idle_data[new_state_idx];
 	core_next_state = cx->core_state;
 	per_next_state = per_saved_state = pwrdm_read_next_func_pwrst(per_pd);
 	if ((per_next_state == PWRDM_FUNC_PWRST_OFF) &&
@@ -268,8 +277,6 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
 	if (per_next_state != per_saved_state)
 		omap_set_pwrdm_state(per_pd, per_next_state);
 
-	new_state_idx = next_valid_state(dev, drv, index);
-
 select_state:
 	ret = omap3_enter_idle(dev, drv, new_state_idx);
 
@@ -282,6 +289,19 @@ select_state:
 
 DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
 
+/*
+ * Note about the latency related fields of the cpuidle_driver struct:
+ *
+ * - exit_latency = sleep + wake-up latencies of the MPU,
+ *  which include the MPU itself and the peripherals needed
+ *  for the MPU to execute instructions (e.g. main memory,
+ *  caches, IRQ controller, MMU etc). Some of those peripherals
+ *  can belong to other power domains than the MPU subsystem and so
+ *  the corresponding latencies must be included in this figure
+ *
+ * - target_residency: required amount of time in the C state
+ *  to break even on energy cost
+ */
 struct cpuidle_driver omap3_idle_driver = {
 	.name = 	"omap3_idle",
 	.owner = 	THIS_MODULE,
Signature · 1 line
1.7.7.6
author
#13 lore raw

PATCH v8 6/10 ARM: OMAP3: PM: cpuidle: default to C1 in next_valid_state

In reply to Jean Pihet

If the next state is no found in the next_valid_state function, fallback to the default value of C1 (which is state 0). This prevents the use of a bogus state -1 in the rest of the cpuidle code.

---
 arch/arm/mach-omap2/cpuidle34xx.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)
arch/arm/mach-omap2/cpuidle34xx.c +1 -7
index 1f33b8e..9319f94 100644
@@ -186,7 +186,7 @@ static int next_valid_state(struct cpuidle_device *dev,
 	u32 mpu_pm_qos_next_state = mpu_pd->wkup_lat_next_state;
 	u32 core_pm_qos_next_state = core_pd->wkup_lat_next_state;
 	int idx;
-	int next_index = -1;
+	int next_index = 0; /* C1 is the default value */
 
 	if (enable_off_mode) {
 		mpu_deepest_state = PWRDM_FUNC_PWRST_OFF;
@@ -221,12 +221,6 @@ static int next_valid_state(struct cpuidle_device *dev,
 		}
 	}
 
-	/*
-	 * C1 is always valid.
-	 * So, no need to check for 'next_index == -1' outside
-	 * this loop.
-	 */
-
 	return next_index;
 }
 
Signature · 1 line
1.7.7.6
author
#14 lore raw

PATCH v8 7/10 ARM: OMAP3: update cpuidle latency and threshold figures

In reply to Jean Pihet

Update the data from the measurements performed at HW and SW levels.

Cf. http://www.omappedia.org/wiki/Power_Management_Device_Latencies_Measurement
for a detailed explanation on where are the numbers coming from.

ToDo:
- Measure the wake-up latencies for all power domains for OMAP3
- Correct some numbers when sys_clkreq and sys_offmode are supported

---
 arch/arm/mach-omap2/cpuidle34xx.c |   52 +++++++++++++++++++++++++++----------
 1 files changed, 38 insertions(+), 14 deletions(-)
arch/arm/mach-omap2/cpuidle34xx.c +38 -14
index 9319f94..9438385 100644
@@ -295,6 +295,30 @@ DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
  *
  * - target_residency: required amount of time in the C state
  *  to break even on energy cost
+ *
+ * The MPU latency and threshold values for the C-states are the worst case
+ * values from the HW and SW, as described in details at
+ * http://www.omappedia.org/wiki/Power_Management_Device_Latencies_Measurement#cpuidle_results
+ *
+ * Measurements conditions and remarks:
+ *  . the measurements have been performed at OPP50
+ *  . the sys_offmode signal is not supported and so not used for the
+ *    measurements. Instead the latency and threshold values for C9 are
+ *    corrected with the value for Triton 2, which is 11.5ms
+ *  . the sys_clkreq signal is not used and so a correction is needed - TBD
+ *  . the sys_clkoff signal is supported, this value need to be corrected with
+ *    the correct value of SYSCLK on/off timings (1ms for sysclk on, 2.5ms
+ *    for sysclk off)
+ *  . the setup time of DPLLs is included in the measured values. However
+ *    this is only valid for DPLLs that are enabled to auto-idle at
+ *    measurement time. There currently is no provision for the dynamic
+ *    nature of the auto-idle setting
+ *  . in order to force the cpuidle algorithm to chose the power efficient
+ *    C-states (C1, C3, C5, C7) in preference, the other C-states have a
+ *    threshold value equal to the next power efficient C-state
+ *
+ * The latency and threshold values can be overriden by data from the board
+ * files, using omap3_pm_init_cpuidle.
  */
 struct cpuidle_driver omap3_idle_driver = {
 	.name = 	"omap3_idle",
@@ -302,56 +326,56 @@ struct cpuidle_driver omap3_idle_driver = {
 	.states = {
 		{
 			.enter		  = omap3_enter_idle,
-			.exit_latency	  = 2 + 2,
-			.target_residency = 5,
+			.exit_latency	  = 73 + 78,
+			.target_residency = 152,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C1",
 			.desc		  = "MPU ON + CORE ON",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 10 + 10,
-			.target_residency = 30,
+			.exit_latency	  = 165 + 88,
+			.target_residency = 345,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C2",
 			.desc		  = "MPU ON + CORE ON",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 50 + 50,
-			.target_residency = 300,
+			.exit_latency	  = 163 + 182,
+			.target_residency = 345,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C3",
 			.desc		  = "MPU RET + CORE ON",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 1500 + 1800,
-			.target_residency = 4000,
+			.exit_latency	  = 2852 + 605,
+			.target_residency = 150000,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C4",
 			.desc		  = "MPU OFF + CORE ON",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 2500 + 7500,
-			.target_residency = 12000,
+			.exit_latency	  = 800 + 366,
+			.target_residency = 2120,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C5",
 			.desc		  = "MPU RET + CORE RET",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 3000 + 8500,
-			.target_residency = 15000,
+			.exit_latency	  = 4080 + 801,
+			.target_residency = 215000,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C6",
 			.desc		  = "MPU OFF + CORE RET",
 		},
 		{
 			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 10000 + 30000,
-			.target_residency = 30000,
+			.exit_latency	  = 4300 + 13000,
+			.target_residency = 215000,
 			.flags		  = CPUIDLE_FLAG_TIME_VALID,
 			.name		  = "C7",
 			.desc		  = "MPU OFF + CORE OFF",
Signature · 1 line
1.7.7.6
#15 lore raw

PATCH 7/10 ARM: OMAP3: update cpuidle latency and threshold figures

Quoted 6 lines · Jean Pihet
  		{
  			.enter		  = omap3_enter_idle_bm,
arch/arm/mach-omap2/cpuidle34xx.c +2 -2
-			.exit_latency	  = 3000 + 8500,
-			.target_residency = 15000,
+			.exit_latency	  = 4080 + 801,
+			.target_residency = 215000,

arch/arm/mach-omap2/cpuidle34xx.c struct cpuidle_driver omap3_idle_driver = { · line 378

Quoted 10 lines
arch/arm/mach-omap2/cpuidle34xx.c +2 -2
  			.flags		  = CPUIDLE_FLAG_TIME_VALID,
  			.name		  = "C6",
  			.desc		  = "MPU OFF + CORE RET",
  		},
  		{
  			.enter		  = omap3_enter_idle_bm,
-			.exit_latency	  = 10000 + 30000,
-			.target_residency = 30000,
+			.exit_latency	  = 4300 + 13000,
+			.target_residency = 215000,

Is the target_residency same for both these states?

Quoted 3 lines

.flags = CPUIDLE_FLAG_TIME_VALID,
.name = "C7",
.desc = "MPU OFF + CORE OFF",

author
#16 lore raw

PATCH v8 7/10 ARM: OMAP3: update cpuidle latency and threshold figures

Quoted 20 lines · Rajendra Nayak
Quoted 17 lines · Jean Pihet

? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?.enter ? ? ? ? ? ?= omap3_enter_idle_bm,
- ? ? ? ? ? ? ? ? ? ? ? .exit_latency ? ? = 3000 + 8500,
- ? ? ? ? ? ? ? ? ? ? ? .target_residency = 15000,
+ ? ? ? ? ? ? ? ? ? ? ? .exit_latency ? ? = 4080 + 801,
+ ? ? ? ? ? ? ? ? ? ? ? .target_residency = 215000,
? ? ? ? ? ? ? ? ? ? ? ?.flags ? ? ? ? ? ?= CPUIDLE_FLAG_TIME_VALID, ? ? ? ? ? ? ? ? ? ? ? ?.name ? ? ? ? ? ? = "C6",
? ? ? ? ? ? ? ? ? ? ? ?.desc ? ? ? ? ? ? = "MPU OFF + CORE RET", ? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ? ? ?.enter ? ? ? ? ? ?= omap3_enter_idle_bm,
- ? ? ? ? ? ? ? ? ? ? ? .exit_latency ? ? = 10000 + 30000,
- ? ? ? ? ? ? ? ? ? ? ? .target_residency = 30000,
+ ? ? ? ? ? ? ? ? ? ? ? .exit_latency ? ? = 4300 + 13000,
+ ? ? ? ? ? ? ? ? ? ? ? .target_residency = 215000,

Quoted 1 line

Is the target_residency same for both these states?

Yes it is. The details are found in the omappedia wiki page.

Thanks,
Jean

Quoted 7 lines
Quoted 5 lines

? ? ? ? ? ? ? ? ? ? ? ?.flags ? ? ? ? ? ?= CPUIDLE_FLAG_TIME_VALID, ? ? ? ? ? ? ? ? ? ? ? ?.name ? ? ? ? ? ? = "C7",
? ? ? ? ? ? ? ? ? ? ? ?.desc ? ? ? ? ? ? = "MPU OFF + CORE OFF",

author
#17 lore raw

PATCH v8 8/10 ARM: OMAP3: powerdomain data: add wake-up latency figures

In reply to Jean Pihet

Figures are added to the power domains structs for RET and OFF modes.

Note: the latency figures for MPU, PER, CORE, NEON have been obtained from actual measurements.
The latency figures for the other power domains are preliminary and shall be added.

Cf. http://www.omappedia.org/wiki/Power_Management_Device_Latencies_Measurement
for a detailed explanation on where are the numbers coming from.

Tested on OMAP3 Beagleboard in RET/OFF using wake-up latency constraints on MPU, CORE and PER.

---
 arch/arm/mach-omap2/powerdomains3xxx_data.c |   83 +++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
arch/arm/mach-omap2/powerdomains3xxx_data.c +83 -0
index fb0a0a6..edc4199 100644
@@ -32,6 +32,19 @@
 
 /*
  * Powerdomains
+ *
+ * The wakeup_lat values are derived from HW and SW measurements on
+ * the actual target. For more details cf.
+ * http://www.omappedia.org/wiki/Power_Management_Device_Latencies_Measurement#Results_for_individual_power_domains
+ *
+ * Note: the latency figures for MPU, PER, CORE, NEON have been obtained
+ * from actual measurements.
+ * The latency figures for the other power domains are preliminary and
+ * shall be added.
+ *
+ * Note: only the SW restore timing values are taken into account.
+ * The HW impact of the sys_clkreq and sys_offmode signals is not taken
+ * into account - TDB
  */
 
 static struct powerdomain iva2_pwrdm = {
@@ -52,6 +65,13 @@ static struct powerdomain iva2_pwrdm = {
 		[2] = PWRSTS_OFF_ON,
 		[3] = PWRSTS_ON,
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 1100,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 350,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "mpu_iva" },
 };
 
@@ -68,6 +88,13 @@ static struct powerdomain mpu_3xxx_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_OFF_ON,
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 1830,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 121,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "mpu_iva" },
 };
 
@@ -95,6 +122,13 @@ static struct powerdomain core_3xxx_pre_es3_1_pwrdm = {
 		[0] = PWRSTS_OFF_RET_ON, /* MEM1ONSTATE */
 		[1] = PWRSTS_OFF_RET_ON, /* MEM2ONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 3082,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 153,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -117,6 +151,13 @@ static struct powerdomain core_3xxx_es3_1_pwrdm = {
 		[0] = PWRSTS_OFF_RET_ON, /* MEM1ONSTATE */
 		[1] = PWRSTS_OFF_RET_ON, /* MEM2ONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 3082,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 153,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -132,6 +173,13 @@ static struct powerdomain dss_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_ON,  /* MEMONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 70,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 20,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -153,6 +201,13 @@ static struct powerdomain sgx_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_ON,  /* MEMONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 1000,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -168,6 +223,13 @@ static struct powerdomain cam_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_ON,  /* MEMONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 850,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 35,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -183,6 +245,13 @@ static struct powerdomain per_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_ON,  /* MEMONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 671,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 31,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
@@ -197,6 +266,13 @@ static struct powerdomain neon_pwrdm = {
 	.prcm_offs	  = OMAP3430_NEON_MOD,
 	.pwrsts		  = PWRSTS_OFF_RET_ON,
 	.pwrsts_logic_ret = PWRSTS_RET,
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 0,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 0,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "mpu_iva" },
 };
 
@@ -219,6 +295,13 @@ static struct powerdomain usbhost_pwrdm = {
 	.pwrsts_mem_on	  = {
 		[0] = PWRSTS_ON,  /* MEMONSTATE */
 	},
+	.wakeup_lat = {
+		[PWRDM_FUNC_PWRST_OFF] = 800,
+		[PWRDM_FUNC_PWRST_OSWR] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_CSWR] = 150,
+		[PWRDM_FUNC_PWRST_INACTIVE] = UNSUP_STATE,
+		[PWRDM_FUNC_PWRST_ON] = 0,
+	},
 	.voltdm           = { .name = "core" },
 };
 
Signature · 1 line
1.7.7.6
author
#18 lore raw

PATCH v8 9/10 ARM: OMAP: convert I2C driver to PM QoS for latency constraints

In reply to Jean Pihet

Convert the driver from the outdated omap_pm_set_max_mpu_wakeup_lat API to the new PM QoS API.
Since the constraint is on the MPU subsystem, use the PM_QOS_CPU_DMA_LATENCY class of PM QoS. The resulting MPU constraints are used by cpuidle to decide the next power state of the MPU subsystem.

The I2C device latency timing is derived from the FIFO size and the clock speed and so is applicable to all OMAP SoCs.

---
 arch/arm/plat-omap/i2c.c      |   21 ---------------------
 drivers/i2c/busses/i2c-omap.c |   28 +++++++++++++++++-----------
 include/linux/i2c-omap.h      |    1 -
 3 files changed, 17 insertions(+), 33 deletions(-)
arch/arm/plat-omap/i2c.c +0 -21
index db071bc..dba8338 100644
@@ -26,7 +26,6 @@
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
-#include <linux/i2c-omap.h>
 #include <linux/slab.h>
 #include <linux/err.h>
 #include <linux/clk.h>
@@ -34,7 +33,6 @@
 #include <mach/irqs.h>
 #include <plat/mux.h>
 #include <plat/i2c.h>
-#include <plat/omap-pm.h>
 #include <plat/omap_device.h>
 
 #define OMAP_I2C_SIZE		0x3f
@@ -129,16 +127,6 @@ static inline int omap1_i2c_add_bus(int bus_id)
 
 
 #ifdef CONFIG_ARCH_OMAP2PLUS
-/*
- * XXX This function is a temporary compatibility wrapper - only
- * needed until the I2C driver can be converted to call
- * omap_pm_set_max_dev_wakeup_lat() and handle a return code.
- */
-static void omap_pm_set_max_mpu_wakeup_lat_compat(struct device *dev, long t)
-{
-	omap_pm_set_max_mpu_wakeup_lat(dev, t);
-}
-
 static inline int omap2_i2c_add_bus(int bus_id)
 {
 	int l;
@@ -170,15 +158,6 @@ static inline int omap2_i2c_add_bus(int bus_id)
 	dev_attr = (struct omap_i2c_dev_attr *)oh->dev_attr;
 	pdata->flags = dev_attr->flags;
 
-	/*
-	 * When waiting for completion of a i2c transfer, we need to
-	 * set a wake up latency constraint for the MPU. This is to
-	 * ensure quick enough wakeup from idle, when transfer
-	 * completes.
-	 * Only omap3 has support for constraints
-	 */
-	if (cpu_is_omap34xx())
-		pdata->set_mpu_wkup_lat = omap_pm_set_max_mpu_wakeup_lat_compat;
 	pdev = omap_device_build(name, bus_id, oh, pdata,
 			sizeof(struct omap_i2c_bus_platform_data),
 			NULL, 0, 0);
drivers/i2c/busses/i2c-omap.c +17 -11
index 801df60..72d7076 100644
@@ -43,6 +43,7 @@
 #include <linux/slab.h>
 #include <linux/i2c-omap.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_qos.h>
 
 /* I2C controller revisions */
 #define OMAP_I2C_OMAP1_REV_2		0x20
@@ -183,8 +184,7 @@ struct omap_i2c_dev {
 	struct completion	cmd_complete;
 	struct resource		*ioarea;
 	u32			latency;	/* maximum mpu wkup latency */
-	void			(*set_mpu_wkup_lat)(struct device *dev,
-						    long latency);
+	struct pm_qos_request	pm_qos_request;
 	u32			speed;		/* Speed of bus in kHz */
 	u32			dtrev;		/* extra revision from DT */
 	u32			flags;
@@ -634,8 +634,16 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	if (r < 0)
 		goto out;
 
-	if (dev->set_mpu_wkup_lat != NULL)
-		dev->set_mpu_wkup_lat(dev->dev, dev->latency);
+	/*
+	 * When waiting for completion of a i2c transfer, we need to
+	 * set a wake up latency constraint for the MPU. This is to
+	 * ensure quick enough wakeup from idle, when transfer
+	 * completes.
+	 */
+	if (dev->latency)
+		pm_qos_add_request(&dev->pm_qos_request,
+				   PM_QOS_CPU_DMA_LATENCY,
+				   dev->latency);
 
 	for (i = 0; i < num; i++) {
 		r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)));
@@ -643,8 +651,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 			break;
 	}
 
-	if (dev->set_mpu_wkup_lat != NULL)
-		dev->set_mpu_wkup_lat(dev->dev, -1);
+	if (dev->latency)
+		pm_qos_remove_request(&dev->pm_qos_request);
 
 	if (r == 0)
 		r = num;
@@ -1032,7 +1040,6 @@ omap_i2c_probe(struct platform_device *pdev)
 	} else if (pdata != NULL) {
 		dev->speed = pdata->clkrate;
 		dev->flags = pdata->flags;
-		dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat;
 		dev->dtrev = pdata->rev;
 	}
 
@@ -1081,10 +1088,9 @@ omap_i2c_probe(struct platform_device *pdev)
 		else
 			dev->b_hw = 1; /* Enable hardware fixes */
 
-		/* calculate wakeup latency constraint for MPU */
-		if (dev->set_mpu_wkup_lat != NULL)
-			dev->latency = (1000000 * dev->fifo_size) /
-				       (1000 * dev->speed / 8);
+		/* calculate wakeup latency constraint */
+		dev->latency = (1000000 * dev->fifo_size) /
+			       (1000 * dev->speed / 8);
 	}
 
 	/* reset ASAP, clearing any IRQs */
include/linux/i2c-omap.h +0 -1
index 92a0dc7..df804ba 100644
@@ -34,7 +34,6 @@ struct omap_i2c_bus_platform_data {
 	u32		clkrate;
 	u32		rev;
 	u32		flags;
-	void		(*set_mpu_wkup_lat)(struct device *dev, long set);
 };
 
 #endif
Signature · 1 line
1.7.7.6
author
#19 lore raw

PATCH v8 10/10 ARM: OMAP: PM: remove the latency related functions from the API

In reply to Jean Pihet

Remove the following functions from the OMAP PM API:
omap_pm_set_max_mpu_wakeup_lat omap_pm_set_max_dev_wakeup_lat omap_pm_set_max_sdma_lat
and updated the kernel Documentation accordingly.

The generic per-device PM QoS functions shall be used instead of the OMAP PM API, cf. include/linux/pm_qos.h and Documentation/power/pm_qos_interface.txt.

---
 Documentation/arm/OMAP/omap_pm            |   68 ++++++--------------
 arch/arm/plat-omap/include/plat/omap-pm.h |   99 -----------------------------
 arch/arm/plat-omap/omap-pm-noop.c         |   88 -------------------------
 3 files changed, 21 insertions(+), 234 deletions(-)
Documentation/arm/OMAP/omap_pm +21 -47
index 9012bb0..90f67a3 100644
@@ -5,8 +5,19 @@ The OMAP PM interface
 This document describes the temporary OMAP PM interface.  Driver
 authors use these functions to communicate minimum latency or
 throughput constraints to the kernel power management code.
+
 Over time, the intention is to merge features from the OMAP PM
 interface into the Linux PM QoS code.
+The following PM QoS features already migrated to the PM QoS framework:
+- PM QoS CPU and DMA latency: used to specify the maximum allowed wake-up
+  latency for the CPU,
+- per device PM QoS latency: used to specifiy the maximum allowed wake-up
+  latency for a given device.
+
+Please refer to the corresponding header file and kernel documentation
+for the PM QoS framework, respectively at include/linux/pm_qos.h and
+Documentation/power/pm_qos_interface.txt.
+
 
 Drivers need to express PM parameters which:
 
@@ -29,21 +40,12 @@ Drivers need to express PM parameters which:
 
 
 This document proposes the OMAP PM interface, including the following
-five power management functions for driver code:
-
-1. Set the maximum MPU wakeup latency:
-   (*pdata->set_max_mpu_wakeup_lat)(struct device *dev, unsigned long t)
+power management functions for driver code:
 
-2. Set the maximum device wakeup latency:
-   (*pdata->set_max_dev_wakeup_lat)(struct device *dev, unsigned long t)
-
-3. Set the maximum system DMA transfer start latency (CORE pwrdm):
-   (*pdata->set_max_sdma_lat)(struct device *dev, long t)
-
-4. Set the minimum bus throughput needed by a device:
+1. Set the minimum bus throughput needed by a device:
    (*pdata->set_min_bus_tput)(struct device *dev, u8 agent_id, unsigned long r)
 
-5. Return the number of times the device has lost context
+2. Return the number of times the device has lost context
    (*pdata->get_dev_context_loss_count)(struct device *dev)
 
 
@@ -55,10 +57,12 @@ The OMAP PM layer is intended to be temporary
 ---------------------------------------------
 
 The intention is that eventually the Linux PM QoS layer should support
-the range of power management features present in OMAP3.  As this
-happens, existing drivers using the OMAP PM interface can be modified
+the range of power management features present in OMAP3. As this
+happens, existing drivers using the OMAP PM interface shall be modified
 to use the Linux PM QoS code; and the OMAP PM interface can disappear.
 
+The set_min_bus_tput function shall be converted to a throughput PM QoS
+framework.
 
 Driver usage of the OMAP PM functions
 -------------------------------------
@@ -66,39 +70,9 @@ Driver usage of the OMAP PM functions
 As the 'pdata' in the above examples indicates, these functions are
 exposed to drivers through function pointers in driver .platform_data
 structures.  The function pointers are initialized by the board-*.c
-files to point to the corresponding OMAP PM functions:
-.set_max_dev_wakeup_lat will point to
-omap_pm_set_max_dev_wakeup_lat(), etc.  Other architectures which do
-not support these functions should leave these function pointers set
-to NULL.  Drivers should use the following idiom:
-
-        if (pdata->set_max_dev_wakeup_lat)
-            (*pdata->set_max_dev_wakeup_lat)(dev, t);
-
-The most common usage of these functions will probably be to specify
-the maximum time from when an interrupt occurs, to when the device
-becomes accessible.  To accomplish this, driver writers should use the
-set_max_mpu_wakeup_lat() function to to constrain the MPU wakeup
-latency, and the set_max_dev_wakeup_lat() function to constrain the
-device wakeup latency (from clk_enable() to accessibility).  For
-example,
-
-        /* Limit MPU wakeup latency */
-        if (pdata->set_max_mpu_wakeup_lat)
-            (*pdata->set_max_mpu_wakeup_lat)(dev, tc);
-
-        /* Limit device powerdomain wakeup latency */
-        if (pdata->set_max_dev_wakeup_lat)
-            (*pdata->set_max_dev_wakeup_lat)(dev, td);
-
-        /* total wakeup latency in this example: (tc + td) */
-
-The PM parameters can be overwritten by calling the function again
-with the new value.  The settings can be removed by calling the
-function with a t argument of -1 (except in the case of
-set_max_bus_tput(), which should be called with an r argument of 0).
-
-The fifth function above, omap_pm_get_dev_context_loss_count(),
+files to point to the corresponding OMAP PM functions.
+
+The omap_pm_get_dev_context_loss_count() function
 is intended as an optimization to allow drivers to determine whether the
 device has lost its internal context.  If context has been lost, the
 driver must restore its internal context before proceeding.
arch/arm/plat-omap/include/plat/omap-pm.h +0 -99

111 lines not on this page · raw message

arch/arm/plat-omap/omap-pm-noop.c +0 -88

100 lines not on this page · raw message

Signature · 1 line
1.7.7.6