PM QoS: Add global notification mechanism for device constraints
authorJean Pihet <j-pihet@ti.com>
Thu, 25 Aug 2011 13:35:47 +0000 (15:35 +0200)
committerRafael J. Wysocki <rjw@sisk.pl>
Thu, 25 Aug 2011 13:35:47 +0000 (15:35 +0200)
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>
Reviewed-by: Kevin Hilman <khilman@ti.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
drivers/base/power/qos.c
include/linux/pm_qos.h
kernel/power/qos.c

index cc4c541398aa39120b6654296dac5f83b6cd0a75..8d0b81151c14bb6a287a976272008a077741169f 100644 (file)
  *
  * 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
 
 
 static DEFINE_MUTEX(dev_pm_qos_mtx);
+static BLOCKING_NOTIFIER_HEAD(dev_pm_notifiers);
+
+/*
+ * apply_constraint
+ * @req: constraint request to apply
+ * @action: action to perform add/update/remove, of type enum pm_qos_req_action
+ * @value: defines the qos request
+ *
+ * Internal function to update the constraints list using the PM QoS core
+ * code and if needed call the per-device and the global notification
+ * callbacks
+ */
+static int apply_constraint(struct dev_pm_qos_request *req,
+                           enum pm_qos_req_action action, int value)
+{
+       int ret, curr_value;
+
+       ret = pm_qos_update_target(req->dev->power.constraints,
+                                  &req->node, action, 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);
+       }
+
+       return ret;
+}
 
 /*
  * dev_pm_qos_constraints_allocate
@@ -111,12 +147,11 @@ void dev_pm_qos_constraints_destroy(struct device *dev)
                                          &dev->power.constraints->list,
                                          node) {
                        /*
-                        * Update constraints list and call the per-device
+                        * Update constraints list and call the notification
                         * callbacks if needed
                         */
-                       pm_qos_update_target(req->dev->power.constraints,
-                                          &req->node, PM_QOS_REMOVE_REQ,
-                                          PM_QOS_DEFAULT_VALUE);
+                       apply_constraint(req, PM_QOS_REMOVE_REQ,
+                                        PM_QOS_DEFAULT_VALUE);
                        memset(req, 0, sizeof(*req));
                }
 
@@ -147,7 +182,7 @@ void dev_pm_qos_constraints_destroy(struct device *dev)
  * removed from the system
  */
 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
-                           s32 value)
+                          s32 value)
 {
        int ret = 0;
 
@@ -178,8 +213,7 @@ int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
                ret = dev_pm_qos_constraints_allocate(dev);
 
        if (!ret)
-               ret = pm_qos_update_target(dev->power.constraints, &req->node,
-                                          PM_QOS_ADD_REQ, value);
+               ret = apply_constraint(req, PM_QOS_ADD_REQ, value);
 
 out:
        mutex_unlock(&dev_pm_qos_mtx);
@@ -220,10 +254,8 @@ int dev_pm_qos_update_request(struct dev_pm_qos_request *req,
 
        if (req->dev->power.constraints_state == DEV_PM_QOS_ALLOCATED) {
                if (new_value != req->node.prio)
-                       ret = pm_qos_update_target(req->dev->power.constraints,
-                                                  &req->node,
-                                                  PM_QOS_UPDATE_REQ,
-                                                  new_value);
+                       ret = apply_constraint(req, PM_QOS_UPDATE_REQ,
+                                              new_value);
        } else {
                /* Return if the device has been removed */
                ret = -ENODEV;
@@ -262,9 +294,8 @@ int dev_pm_qos_remove_request(struct dev_pm_qos_request *req)
        mutex_lock(&dev_pm_qos_mtx);
 
        if (req->dev->power.constraints_state == DEV_PM_QOS_ALLOCATED) {
-               ret = pm_qos_update_target(req->dev->power.constraints,
-                                          &req->node, PM_QOS_REMOVE_REQ,
-                                          PM_QOS_DEFAULT_VALUE);
+               ret = apply_constraint(req, PM_QOS_REMOVE_REQ,
+                                      PM_QOS_DEFAULT_VALUE);
                memset(req, 0, sizeof(*req));
        } else {
                /* Return if the device has been removed */
@@ -336,3 +367,33 @@ out:
        return retval;
 }
 EXPORT_SYMBOL_GPL(dev_pm_qos_remove_notifier);
+
+/**
+ * dev_pm_qos_add_global_notifier - sets notification entry for changes to
+ * target value of the PM QoS constraints for any device
+ *
+ * @notifier: notifier block managed by caller.
+ *
+ * Will register the notifier into a notification chain that gets called
+ * upon changes to the target value for any device.
+ */
+int dev_pm_qos_add_global_notifier(struct notifier_block *notifier)
+{
+       return blocking_notifier_chain_register(&dev_pm_notifiers, notifier);
+}
+EXPORT_SYMBOL_GPL(dev_pm_qos_add_global_notifier);
+
+/**
+ * dev_pm_qos_remove_global_notifier - deletes notification for changes to
+ * target value of PM QoS constraints for any device
+ *
+ * @notifier: notifier block to be removed.
+ *
+ * Will remove the notifier from the notification chain that gets called
+ * upon changes to the target value for any device.
+ */
+int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier)
+{
+       return blocking_notifier_chain_unregister(&dev_pm_notifiers, notifier);
+}
+EXPORT_SYMBOL_GPL(dev_pm_qos_remove_global_notifier);
index f75f74dd9b90978fdedc6ce74393ebb94ddff203..ca7bd3f98cb44fc5cf94129052d8f19be28681ca 100644 (file)
@@ -75,6 +75,7 @@ int pm_qos_request(int pm_qos_class);
 int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
 int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
 int pm_qos_request_active(struct pm_qos_request *req);
+s32 pm_qos_read_value(struct pm_qos_constraints *c);
 
 int dev_pm_qos_add_request(struct device *dev, struct dev_pm_qos_request *req,
                           s32 value);
@@ -84,6 +85,8 @@ int dev_pm_qos_add_notifier(struct device *dev,
                            struct notifier_block *notifier);
 int dev_pm_qos_remove_notifier(struct device *dev,
                               struct notifier_block *notifier);
+int dev_pm_qos_add_global_notifier(struct notifier_block *notifier);
+int dev_pm_qos_remove_global_notifier(struct notifier_block *notifier);
 void dev_pm_qos_constraints_init(struct device *dev);
 void dev_pm_qos_constraints_destroy(struct device *dev);
 #else
@@ -111,6 +114,8 @@ static inline int pm_qos_remove_notifier(int pm_qos_class,
                        { return 0; }
 static inline int pm_qos_request_active(struct pm_qos_request *req)
                        { return 0; }
+static inline s32 pm_qos_read_value(struct pm_qos_constraints *c)
+                       { return 0; }
 
 static inline int dev_pm_qos_add_request(struct device *dev,
                                         struct dev_pm_qos_request *req,
@@ -127,6 +132,12 @@ static inline int dev_pm_qos_add_notifier(struct device *dev,
 static inline int dev_pm_qos_remove_notifier(struct device *dev,
                                             struct notifier_block *notifier)
                        { return 0; }
+static inline int dev_pm_qos_add_global_notifier(
+                                       struct notifier_block *notifier)
+                       { return 0; }
+static inline int dev_pm_qos_remove_global_notifier(
+                                       struct notifier_block *notifier)
+                       { return 0; }
 static inline void dev_pm_qos_constraints_init(struct device *dev)
                        { return; }
 static inline void dev_pm_qos_constraints_destroy(struct device *dev)
index 7c7cd181cabefe70e0c26024c0e73c991b972c81..1c1797dd1d1d3f05c3260f47e0f6c22efc1c815c 100644 (file)
@@ -140,7 +140,7 @@ static inline int pm_qos_get_value(struct pm_qos_constraints *c)
        }
 }
 
-static inline s32 pm_qos_read_value(struct pm_qos_constraints *c)
+s32 pm_qos_read_value(struct pm_qos_constraints *c)
 {
        return c->target_value;
 }
This page took 0.029738 seconds and 5 git commands to generate.