summaryrefslogtreecommitdiff
path: root/drivers/cpufreq
diff options
context:
space:
mode:
authorAntti P Miettinen <amiettinen@nvidia.com>2011-12-27 12:41:39 +0200
committerDan Willemsen <dwillemsen@nvidia.com>2013-09-14 01:33:20 -0700
commitaa7f78b3dcec7d9ed6fb1e01e66c1ad8583a830b (patch)
tree94765cd5558c445ff7de9a3943ad576620ee97d9 /drivers/cpufreq
parent678c2722dba55ac052d70bf207200ad9a50787b0 (diff)
cpufreq: Enforce PM QoS min/max limits
Observe PM QoS CPU frequency minimum and maximum in addition to policy settings. Bug 888312 Change-Id: Ia4f60a1649a9952e02f6847c8add3b2ea5d47524 Reviewed-on: http://git-master/r/72207 Signed-off-by: Antti P Miettinen <amiettinen@nvidia.com> Signed-off-by: Varun Wadekar <vwadekar@nvidia.com> Reviewed-on: http://git-master/r/75884 Reviewed-by: Automatic_Commit_Validation_User Rebase-Id: Red1299253123d231af705a130f07e7aa77698fd8
Diffstat (limited to 'drivers/cpufreq')
-rw-r--r--drivers/cpufreq/cpufreq.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 32d1ea9915f7..59881c3f4b51 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -31,6 +31,7 @@
#include <linux/completion.h>
#include <linux/mutex.h>
#include <linux/syscore_ops.h>
+#include <linux/pm_qos.h>
#include <trace/events/power.h>
@@ -1674,9 +1675,17 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
struct cpufreq_policy *policy)
{
int ret = 0, failed = 1;
+ unsigned int pmin = policy->min;
+ unsigned int pmax = policy->max;
+ unsigned int qmin = pm_qos_request(PM_QOS_CPU_FREQ_MIN);
+ unsigned int qmax = pm_qos_request(PM_QOS_CPU_FREQ_MAX);
- pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
- policy->min, policy->max);
+ pr_debug("setting new policy for CPU %u: %u - %u (%u - %u) kHz\n",
+ policy->cpu, pmin, pmax, qmin, qmax);
+
+ /* clamp the new policy to PM QoS limits */
+ policy->min = max(pmin, qmin);
+ policy->max = min(pmax, qmax);
memcpy(&policy->cpuinfo, &data->cpuinfo,
sizeof(struct cpufreq_cpuinfo));
@@ -1769,6 +1778,9 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data,
}
error_out:
+ /* restore the limits that the policy requested */
+ policy->min = pmin;
+ policy->max = pmax;
return ret;
}
@@ -1962,9 +1974,36 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
}
EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);
+static int cpu_freq_notify(struct notifier_block *b,
+ unsigned long l, void *v);
+
+static struct notifier_block min_freq_notifier = {
+ .notifier_call = cpu_freq_notify,
+};
+static struct notifier_block max_freq_notifier = {
+ .notifier_call = cpu_freq_notify,
+};
+
+static int cpu_freq_notify(struct notifier_block *b,
+ unsigned long l, void *v)
+{
+ int cpu;
+ pr_debug("PM QoS %s %lu\n",
+ b == &min_freq_notifier ? "min" : "max", l);
+ for_each_online_cpu(cpu) {
+ struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
+ if (policy) {
+ cpufreq_update_policy(policy->cpu);
+ cpufreq_cpu_put(policy);
+ }
+ }
+ return NOTIFY_OK;
+}
+
static int __init cpufreq_core_init(void)
{
int cpu;
+ int rc;
if (cpufreq_disabled())
return -ENODEV;
@@ -1977,6 +2016,12 @@ static int __init cpufreq_core_init(void)
cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
BUG_ON(!cpufreq_global_kobject);
register_syscore_ops(&cpufreq_syscore_ops);
+ rc = pm_qos_add_notifier(PM_QOS_CPU_FREQ_MIN,
+ &min_freq_notifier);
+ BUG_ON(rc);
+ rc = pm_qos_add_notifier(PM_QOS_CPU_FREQ_MAX,
+ &max_freq_notifier);
+ BUG_ON(rc);
return 0;
}