Lines Matching refs:policy

82 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
83 static int cpufreq_init_governor(struct cpufreq_policy *policy);
84 static void cpufreq_exit_governor(struct cpufreq_policy *policy);
85 static void cpufreq_governor_limits(struct cpufreq_policy *policy);
86 static int cpufreq_set_policy(struct cpufreq_policy *policy,
92 * Two notifier lists: the "policy" list is involved in the
93 * validation process for a new CPU frequency policy; the
120 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy)
123 return &policy->kobj;
172 * - policy->cpus with all possible CPUs
174 void cpufreq_generic_init(struct cpufreq_policy *policy,
178 policy->freq_table = table;
179 policy->cpuinfo.transition_latency = transition_latency;
185 cpumask_setall(policy->cpus);
191 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
193 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL;
199 struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu);
201 if (!policy || IS_ERR(policy->clk)) {
203 __func__, policy ? "clk" : "policy", cpu);
207 return clk_get_rate(policy->clk) / 1000;
212 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
213 * @cpu: CPU to find the policy for.
215 * Call cpufreq_cpu_get_raw() to obtain a cpufreq policy for @cpu and increment
216 * the kobject reference counter of that policy. Return a valid policy on
219 * The policy returned by this function has to be released with the help of
224 struct cpufreq_policy *policy = NULL;
235 policy = cpufreq_cpu_get_raw(cpu);
236 if (policy)
237 kobject_get(&policy->kobj);
242 return policy;
247 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
248 * @policy: cpufreq policy returned by cpufreq_cpu_get().
250 void cpufreq_cpu_put(struct cpufreq_policy *policy)
252 kobject_put(&policy->kobj);
257 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
258 * @policy: cpufreq policy returned by cpufreq_cpu_acquire().
260 void cpufreq_cpu_release(struct cpufreq_policy *policy)
262 if (WARN_ON(!policy))
265 lockdep_assert_held(&policy->rwsem);
267 up_write(&policy->rwsem);
269 cpufreq_cpu_put(policy);
273 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
274 * @cpu: CPU to find the policy for.
276 * Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and
277 * if the policy returned by it is not NULL, acquire its rwsem for writing.
278 * Return the policy if it is active or release it and return NULL otherwise.
280 * The policy returned by this function has to be released with the help of
286 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
288 if (!policy)
291 down_write(&policy->rwsem);
293 if (policy_is_inactive(policy)) {
294 cpufreq_cpu_release(policy);
298 return policy;
341 * @policy: cpufreq policy to enable fast frequency switching for.
349 static void cpufreq_notify_transition(struct cpufreq_policy *policy,
360 freqs->policy = policy;
372 if (policy->cur && policy->cur != freqs->old) {
374 freqs->old, policy->cur);
375 freqs->old = policy->cur;
387 cpumask_pr_args(policy->cpus));
389 for_each_cpu(cpu, policy->cpus)
395 cpufreq_stats_record_transition(policy, freqs->new);
396 policy->cur = freqs->new;
401 static void cpufreq_notify_post_transition(struct cpufreq_policy *policy,
404 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
409 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
410 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE);
413 void cpufreq_freq_transition_begin(struct cpufreq_policy *policy,
426 && current == policy->transition_task);
429 wait_event(policy->transition_wait, !policy->transition_ongoing);
431 spin_lock(&policy->transition_lock);
433 if (unlikely(policy->transition_ongoing)) {
434 spin_unlock(&policy->transition_lock);
438 policy->transition_ongoing = true;
439 policy->transition_task = current;
441 spin_unlock(&policy->transition_lock);
443 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE);
447 void cpufreq_freq_transition_end(struct cpufreq_policy *policy,
450 if (WARN_ON(!policy->transition_ongoing))
453 cpufreq_notify_post_transition(policy, freqs, transition_failed);
455 arch_set_freq_scale(policy->related_cpus,
456 policy->cur,
457 policy->cpuinfo.max_freq);
459 spin_lock(&policy->transition_lock);
460 policy->transition_ongoing = false;
461 policy->transition_task = NULL;
462 spin_unlock(&policy->transition_lock);
464 wake_up(&policy->transition_wait);
490 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
491 * @policy: cpufreq policy to enable fast frequency switching for.
493 * Try to enable fast frequency switching for @policy.
500 void cpufreq_enable_fast_switch(struct cpufreq_policy *policy)
502 lockdep_assert_held(&policy->rwsem);
504 if (!policy->fast_switch_possible)
510 policy->fast_switch_enabled = true;
513 policy->cpu);
521 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
522 * @policy: cpufreq policy to disable fast frequency switching for.
524 void cpufreq_disable_fast_switch(struct cpufreq_policy *policy)
527 if (policy->fast_switch_enabled) {
528 policy->fast_switch_enabled = false;
536 static unsigned int __resolve_freq(struct cpufreq_policy *policy,
541 target_freq = clamp_val(target_freq, policy->min, policy->max);
543 if (!policy->freq_table)
546 idx = cpufreq_frequency_table_target(policy, target_freq, relation);
547 policy->cached_resolved_idx = idx;
548 policy->cached_target_freq = target_freq;
549 return policy->freq_table[idx].frequency;
555 * @policy: associated policy to interrogate
558 * The target to driver frequency mapping is cached in the policy.
561 * given target_freq, subject to policy (min/max) and driver limitations.
563 unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy,
566 return __resolve_freq(policy, target_freq, CPUFREQ_RELATION_LE);
570 unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy)
574 if (policy->transition_delay_us)
575 return policy->transition_delay_us;
577 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC;
627 static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf)
629 return sysfs_emit(buf, "%d\n", policy->boost_enabled);
632 static ssize_t store_local_boost(struct cpufreq_policy *policy,
644 if (policy->boost_enabled == enable)
647 policy->boost_enabled = enable;
650 ret = cpufreq_driver->set_boost(policy, enable);
654 policy->boost_enabled = !policy->boost_enabled;
725 * Write out information from cpufreq_driver->policy[cpu]; object must be
731 (struct cpufreq_policy *policy, char *buf) \
733 return sprintf(buf, "%u\n", policy->object); \
747 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
752 freq = arch_freq_get_on_cpu(policy->cpu);
756 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
758 ret = sprintf(buf, "%u\n", policy->cur);
767 (struct cpufreq_policy *policy, const char *buf, size_t count) \
776 ret = freq_qos_update_request(policy->object##_freq_req, val);\
786 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
789 unsigned int cur_freq = __cpufreq_get(policy);
798 * show_scaling_governor - show the current policy for the specified CPU
800 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
802 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
804 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
806 else if (policy->governor)
808 policy->governor->name);
813 * store_scaling_governor - store policy for the specified CPU
815 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
832 ret = cpufreq_set_policy(policy, NULL, new_pol);
840 ret = cpufreq_set_policy(policy, new_gov,
852 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
860 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
907 static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
909 return cpufreq_show_cpus(policy->related_cpus, buf);
915 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
917 return cpufreq_show_cpus(policy->cpus, buf);
920 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
926 if (!policy->governor || !policy->governor->store_setspeed)
933 policy->governor->store_setspeed(policy, freq);
938 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
940 if (!policy->governor || !policy->governor->show_setspeed)
943 return policy->governor->show_setspeed(policy, buf);
949 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
953 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
956 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
995 struct cpufreq_policy *policy = to_policy(kobj);
1002 down_read(&policy->rwsem);
1003 if (likely(!policy_is_inactive(policy)))
1004 ret = fattr->show(policy, buf);
1005 up_read(&policy->rwsem);
1013 struct cpufreq_policy *policy = to_policy(kobj);
1020 down_write(&policy->rwsem);
1021 if (likely(!policy_is_inactive(policy)))
1022 ret = fattr->store(policy, buf, count);
1023 up_write(&policy->rwsem);
1030 struct cpufreq_policy *policy = to_policy(kobj);
1032 complete(&policy->kobj_unregister);
1046 static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu,
1052 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus))
1056 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"))
1060 static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu,
1065 cpumask_clear_cpu(cpu, policy->real_cpus);
1068 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
1076 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
1082 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
1087 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
1092 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
1098 ret = sysfs_create_file(&policy->kobj, &local_boost.attr);
1106 static int cpufreq_init_policy(struct cpufreq_policy *policy)
1113 /* Update policy governor to the one used before hotplug. */
1114 gov = get_governor(policy->last_governor);
1117 gov->name, policy->cpu);
1129 /* Use the default policy if there is no last_policy. */
1130 if (policy->last_policy) {
1131 pol = policy->last_policy;
1136 * nor "powersave", fall back to the initial policy
1140 pol = policy->policy;
1147 ret = cpufreq_set_policy(policy, gov, pol);
1154 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1159 if (cpumask_test_cpu(cpu, policy->cpus))
1162 down_write(&policy->rwsem);
1164 cpufreq_stop_governor(policy);
1166 cpumask_set_cpu(cpu, policy->cpus);
1169 ret = cpufreq_start_governor(policy);
1173 up_write(&policy->rwsem);
1177 void refresh_frequency_limits(struct cpufreq_policy *policy)
1179 if (!policy_is_inactive(policy)) {
1180 pr_debug("updating policy for CPU %u\n", policy->cpu);
1182 cpufreq_set_policy(policy, policy->governor, policy->policy);
1189 struct cpufreq_policy *policy =
1192 pr_debug("handle_update for cpu %u called\n", policy->cpu);
1193 down_write(&policy->rwsem);
1194 refresh_frequency_limits(policy);
1195 up_write(&policy->rwsem);
1201 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min);
1203 schedule_work(&policy->update);
1210 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max);
1212 schedule_work(&policy->update);
1216 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
1221 down_write(&policy->rwsem);
1222 cpufreq_stats_free_table(policy);
1223 kobj = &policy->kobj;
1224 cmp = &policy->kobj_unregister;
1225 up_write(&policy->rwsem);
1240 struct cpufreq_policy *policy;
1247 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1248 if (!policy)
1251 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1254 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1257 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1260 init_completion(&policy->kobj_unregister);
1261 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
1262 cpufreq_global_kobject, "policy%u", cpu);
1264 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret);
1266 * The entire policy object will be freed below, but the extra
1270 kobject_put(&policy->kobj);
1274 freq_constraints_init(&policy->constraints);
1276 policy->nb_min.notifier_call = cpufreq_notifier_min;
1277 policy->nb_max.notifier_call = cpufreq_notifier_max;
1279 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN,
1280 &policy->nb_min);
1287 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX,
1288 &policy->nb_max);
1295 INIT_LIST_HEAD(&policy->policy_list);
1296 init_rwsem(&policy->rwsem);
1297 spin_lock_init(&policy->transition_lock);
1298 init_waitqueue_head(&policy->transition_wait);
1299 INIT_WORK(&policy->update, handle_update);
1301 policy->cpu = cpu;
1302 return policy;
1305 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1306 &policy->nb_min);
1308 cpufreq_policy_put_kobj(policy);
1310 free_cpumask_var(policy->real_cpus);
1312 free_cpumask_var(policy->related_cpus);
1314 free_cpumask_var(policy->cpus);
1316 kfree(policy);
1321 static void cpufreq_policy_free(struct cpufreq_policy *policy)
1327 * The callers must ensure the policy is inactive by now, to avoid any
1330 if (unlikely(!policy_is_inactive(policy)))
1331 pr_warn("%s: Freeing active policy\n", __func__);
1333 /* Remove policy from list */
1335 list_del(&policy->policy_list);
1337 for_each_cpu(cpu, policy->related_cpus)
1341 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX,
1342 &policy->nb_max);
1343 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1344 &policy->nb_min);
1346 /* Cancel any pending policy->update work before freeing the policy. */
1347 cancel_work_sync(&policy->update);
1349 if (policy->max_freq_req) {
1356 CPUFREQ_REMOVE_POLICY, policy);
1357 freq_qos_remove_request(policy->max_freq_req);
1360 freq_qos_remove_request(policy->min_freq_req);
1361 kfree(policy->min_freq_req);
1363 cpufreq_policy_put_kobj(policy);
1364 free_cpumask_var(policy->real_cpus);
1365 free_cpumask_var(policy->related_cpus);
1366 free_cpumask_var(policy->cpus);
1367 kfree(policy);
1372 struct cpufreq_policy *policy;
1380 /* Check if this CPU already has a policy to manage it */
1381 policy = per_cpu(cpufreq_cpu_data, cpu);
1382 if (policy) {
1383 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));
1384 if (!policy_is_inactive(policy))
1385 return cpufreq_add_policy_cpu(policy, cpu);
1387 /* This is the only online CPU for the policy. Start over. */
1389 down_write(&policy->rwsem);
1390 policy->cpu = cpu;
1391 policy->governor = NULL;
1394 policy = cpufreq_policy_alloc(cpu);
1395 if (!policy)
1397 down_write(&policy->rwsem);
1401 /* Recover policy->cpus using related_cpus */
1402 cpumask_copy(policy->cpus, policy->related_cpus);
1404 ret = cpufreq_driver->online(policy);
1411 cpumask_copy(policy->cpus, cpumask_of(cpu));
1417 ret = cpufreq_driver->init(policy);
1424 /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
1425 policy->boost_enabled = cpufreq_boost_enabled() && policy_has_boost_freq(policy);
1428 * The initialization has succeeded and the policy is online.
1432 ret = cpufreq_table_validate_and_sort(policy);
1436 /* related_cpus should at least include policy->cpus. */
1437 cpumask_copy(policy->related_cpus, policy->cpus);
1444 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1447 for_each_cpu(j, policy->related_cpus) {
1448 per_cpu(cpufreq_cpu_data, j) = policy;
1449 add_cpu_dev_symlink(policy, j, get_cpu_device(j));
1452 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
1454 if (!policy->min_freq_req) {
1459 ret = freq_qos_add_request(&policy->constraints,
1460 policy->min_freq_req, FREQ_QOS_MIN,
1467 kfree(policy->min_freq_req);
1468 policy->min_freq_req = NULL;
1477 policy->max_freq_req = policy->min_freq_req + 1;
1479 ret = freq_qos_add_request(&policy->constraints,
1480 policy->max_freq_req, FREQ_QOS_MAX,
1483 policy->max_freq_req = NULL;
1488 CPUFREQ_CREATE_POLICY, policy);
1492 policy->cur = cpufreq_driver->get(policy->cpu);
1493 if (!policy->cur) {
1510 * for the next freq which is >= policy->cur ('cur' must be set by now,
1514 * We are passing target-freq as "policy->cur - 1" otherwise
1515 * __cpufreq_driver_target() would simply fail, as policy->cur will be
1520 unsigned int old_freq = policy->cur;
1523 ret = cpufreq_frequency_table_get_index(policy, old_freq);
1525 ret = __cpufreq_driver_target(policy, old_freq - 1,
1535 __func__, policy->cpu, old_freq, policy->cur);
1540 ret = cpufreq_add_dev_interface(policy);
1544 cpufreq_stats_create_table(policy);
1547 list_add(&policy->policy_list, &cpufreq_policy_list);
1554 * once the energy model is properly initialized for the policy
1557 * Also, this should be called before the policy is registered
1561 cpufreq_driver->register_em(policy);
1564 ret = cpufreq_init_policy(policy);
1566 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
1571 up_write(&policy->rwsem);
1573 kobject_uevent(&policy->kobj, KOBJ_ADD);
1575 /* Callback for handling stuff after policy is ready */
1577 cpufreq_driver->ready(policy);
1580 policy->cdev = of_cpufreq_cooling_register(policy);
1587 for_each_cpu(j, policy->real_cpus)
1588 remove_cpu_dev_symlink(policy, j, get_cpu_device(j));
1592 cpufreq_driver->offline(policy);
1596 cpufreq_driver->exit(policy);
1599 cpumask_clear(policy->cpus);
1600 up_write(&policy->rwsem);
1602 cpufreq_policy_free(policy);
1613 struct cpufreq_policy *policy;
1626 policy = per_cpu(cpufreq_cpu_data, cpu);
1627 if (policy)
1628 add_cpu_dev_symlink(policy, cpu, dev);
1633 static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
1638 cpufreq_stop_governor(policy);
1640 cpumask_clear_cpu(cpu, policy->cpus);
1642 if (!policy_is_inactive(policy)) {
1644 if (cpu == policy->cpu)
1645 policy->cpu = cpumask_any(policy->cpus);
1647 /* Start the governor again for the active policy. */
1649 ret = cpufreq_start_governor(policy);
1658 strncpy(policy->last_governor, policy->governor->name,
1661 policy->last_policy = policy->policy;
1664 cpufreq_cooling_unregister(policy->cdev);
1665 policy->cdev = NULL;
1669 cpufreq_exit_governor(policy);
1676 cpufreq_driver->offline(policy);
1678 cpufreq_driver->exit(policy);
1679 policy->freq_table = NULL;
1685 struct cpufreq_policy *policy;
1689 policy = cpufreq_cpu_get_raw(cpu);
1690 if (!policy) {
1695 down_write(&policy->rwsem);
1697 __cpufreq_offline(cpu, policy);
1699 up_write(&policy->rwsem);
1711 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1713 if (!policy)
1716 down_write(&policy->rwsem);
1719 __cpufreq_offline(cpu, policy);
1721 remove_cpu_dev_symlink(policy, cpu, dev);
1723 if (!cpumask_empty(policy->real_cpus)) {
1724 up_write(&policy->rwsem);
1730 cpufreq_driver->exit(policy);
1732 up_write(&policy->rwsem);
1734 cpufreq_policy_free(policy);
1739 * @policy: Policy managing CPUs.
1745 static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
1751 policy->cur, new_freq);
1753 freqs.old = policy->cur;
1756 cpufreq_freq_transition_begin(policy, &freqs);
1757 cpufreq_freq_transition_end(policy, &freqs, 0);
1760 static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update)
1764 new_freq = cpufreq_driver->get(policy->cpu);
1769 * If fast frequency switching is used with the given policy, the check
1770 * against policy->cur is pointless, so skip it in that case.
1772 if (policy->fast_switch_enabled || !has_target())
1775 if (policy->cur != new_freq) {
1783 if (abs(policy->cur - new_freq) < KHZ_PER_MHZ)
1784 return policy->cur;
1786 cpufreq_out_of_sync(policy, new_freq);
1788 schedule_work(&policy->update);
1795 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1803 struct cpufreq_policy *policy;
1817 policy = cpufreq_cpu_get(cpu);
1818 if (policy) {
1819 ret_freq = policy->cur;
1820 cpufreq_cpu_put(policy);
1835 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1838 if (policy) {
1839 ret_freq = policy->max;
1840 cpufreq_cpu_put(policy);
1855 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1858 if (policy) {
1859 ret_freq = policy->cpuinfo.max_freq;
1860 cpufreq_cpu_put(policy);
1867 static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1869 if (unlikely(policy_is_inactive(policy)))
1872 return cpufreq_verify_current_freq(policy, true);
1883 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1886 if (policy) {
1887 down_read(&policy->rwsem);
1889 ret_freq = __cpufreq_get(policy);
1890 up_read(&policy->rwsem);
1892 cpufreq_cpu_put(policy);
1910 int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1914 if (!policy->suspend_freq) {
1920 policy->suspend_freq);
1922 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1926 __func__, policy->suspend_freq, ret);
1942 struct cpufreq_policy *policy;
1952 for_each_active_policy(policy) {
1954 down_write(&policy->rwsem);
1955 cpufreq_stop_governor(policy);
1956 up_write(&policy->rwsem);
1959 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
1976 struct cpufreq_policy *policy;
1992 for_each_active_policy(policy) {
1993 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
1997 down_write(&policy->rwsem);
1998 ret = cpufreq_start_governor(policy);
1999 up_write(&policy->rwsem);
2002 pr_err("%s: Failed to start governor for CPU%u's policy\n",
2003 __func__, policy->cpu);
2061 * of notifiers that ron on cpufreq policy changes.
2147 * @policy: cpufreq policy to switch the frequency for.
2157 * This function must not be called if policy->fast_switch_enabled is unset.
2160 * twice in parallel for the same policy and that it will never be called in
2161 * parallel with either ->target() or ->target_index() for the same policy.
2168 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
2174 target_freq = clamp_val(target_freq, policy->min, policy->max);
2175 freq = cpufreq_driver->fast_switch(policy, target_freq);
2180 policy->cur = freq;
2181 arch_set_freq_scale(policy->related_cpus, freq,
2182 policy->cpuinfo.max_freq);
2183 cpufreq_stats_record_transition(policy, freq);
2186 for_each_cpu(cpu, policy->cpus)
2208 * This function must not be called if policy->fast_switch_enabled is unset.
2235 static int __target_intermediate(struct cpufreq_policy *policy,
2240 freqs->new = cpufreq_driver->get_intermediate(policy, index);
2247 __func__, policy->cpu, freqs->old, freqs->new);
2249 cpufreq_freq_transition_begin(policy, freqs);
2250 ret = cpufreq_driver->target_intermediate(policy, index);
2251 cpufreq_freq_transition_end(policy, freqs, ret);
2260 static int __target_index(struct cpufreq_policy *policy, int index)
2262 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
2264 unsigned int newfreq = policy->freq_table[index].frequency;
2268 if (newfreq == policy->cur)
2272 restore_freq = policy->cur;
2278 retval = __target_intermediate(policy, &freqs, index);
2290 __func__, policy->cpu, freqs.old, freqs.new);
2292 cpufreq_freq_transition_begin(policy, &freqs);
2295 retval = cpufreq_driver->target_index(policy, index);
2301 cpufreq_freq_transition_end(policy, &freqs, retval);
2312 cpufreq_freq_transition_begin(policy, &freqs);
2313 cpufreq_freq_transition_end(policy, &freqs, 0);
2320 int __cpufreq_driver_target(struct cpufreq_policy *policy,
2329 target_freq = __resolve_freq(policy, target_freq, relation);
2332 policy->cpu, target_freq, relation, old_target_freq);
2340 if (target_freq == policy->cur &&
2349 if (!policy->efficiencies_available)
2352 return cpufreq_driver->target(policy, target_freq, relation);
2358 return __target_index(policy, policy->cached_resolved_idx);
2362 int cpufreq_driver_target(struct cpufreq_policy *policy,
2368 down_write(&policy->rwsem);
2370 ret = __cpufreq_driver_target(policy, target_freq, relation);
2372 up_write(&policy->rwsem);
2383 static int cpufreq_init_governor(struct cpufreq_policy *policy)
2394 if (!policy->governor)
2398 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
2404 policy->governor->name, gov->name);
2405 policy->governor = gov;
2411 if (!try_module_get(policy->governor->owner))
2414 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2416 if (policy->governor->init) {
2417 ret = policy->governor->init(policy);
2419 module_put(policy->governor->owner);
2424 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
2429 static void cpufreq_exit_governor(struct cpufreq_policy *policy)
2431 if (cpufreq_suspended || !policy->governor)
2434 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2436 if (policy->governor->exit)
2437 policy->governor->exit(policy);
2439 module_put(policy->governor->owner);
2442 int cpufreq_start_governor(struct cpufreq_policy *policy)
2449 if (!policy->governor)
2452 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2455 cpufreq_verify_current_freq(policy, false);
2457 if (policy->governor->start) {
2458 ret = policy->governor->start(policy);
2463 if (policy->governor->limits)
2464 policy->governor->limits(policy);
2469 void cpufreq_stop_governor(struct cpufreq_policy *policy)
2471 if (cpufreq_suspended || !policy->governor)
2474 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2476 if (policy->governor->stop)
2477 policy->governor->stop(policy);
2480 static void cpufreq_governor_limits(struct cpufreq_policy *policy)
2482 if (cpufreq_suspended || !policy->governor)
2485 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2487 if (policy->governor->limits)
2488 policy->governor->limits(policy);
2516 struct cpufreq_policy *policy;
2527 for_each_inactive_policy(policy) {
2528 if (!strcmp(policy->last_governor, governor->name)) {
2529 policy->governor = NULL;
2530 strcpy(policy->last_governor, "\0");
2548 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2550 * @cpu: CPU to find the policy for
2552 * Reads the current cpufreq policy.
2554 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
2557 if (!policy)
2564 memcpy(policy, cpu_policy, sizeof(*policy));
2572 * cpufreq_set_policy - Modify cpufreq policy parameters.
2573 * @policy: Policy object to modify.
2578 * limits to be set for the policy, update @policy with the verified limits
2580 * carry out a governor update for @policy. That is, run the current governor's
2582 * @policy) or replace the governor for @policy with @new_gov.
2584 * The cpuinfo part of @policy is not updated by this function.
2586 static int cpufreq_set_policy(struct cpufreq_policy *policy,
2594 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2595 new_data.freq_table = policy->freq_table;
2596 new_data.cpu = policy->cpu;
2601 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN);
2602 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX);
2604 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2616 * Resolve policy min/max to available frequencies. It ensures
2620 policy->min = new_data.min;
2621 policy->max = new_data.max;
2622 policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L);
2623 policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H);
2624 trace_cpu_frequency_limits(policy);
2626 policy->cached_target_freq = UINT_MAX;
2629 policy->min, policy->max);
2632 policy->policy = new_pol;
2634 return cpufreq_driver->setpolicy(policy);
2637 if (new_gov == policy->governor) {
2639 cpufreq_governor_limits(policy);
2646 old_gov = policy->governor;
2649 cpufreq_stop_governor(policy);
2650 cpufreq_exit_governor(policy);
2654 policy->governor = new_gov;
2655 ret = cpufreq_init_governor(policy);
2657 ret = cpufreq_start_governor(policy);
2660 sched_cpufreq_governor_change(policy, old_gov);
2663 cpufreq_exit_governor(policy);
2667 pr_debug("starting governor %s failed\n", policy->governor->name);
2669 policy->governor = old_gov;
2670 if (cpufreq_init_governor(policy))
2671 policy->governor = NULL;
2673 cpufreq_start_governor(policy);
2680 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2681 * @cpu: CPU to re-evaluate the policy for.
2683 * Update the current frequency for the cpufreq policy of @cpu and use
2685 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2686 * for the policy in question, among other things.
2690 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
2692 if (!policy)
2700 (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
2703 refresh_frequency_limits(policy);
2706 cpufreq_cpu_release(policy);
2711 * cpufreq_update_limits - Update policy limits for a given CPU.
2712 * @cpu: CPU to update the policy limits for.
2729 static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
2733 if (!policy->freq_table)
2736 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
2742 ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2751 struct cpufreq_policy *policy;
2763 for_each_active_policy(policy) {
2764 policy->boost_enabled = state;
2765 ret = cpufreq_driver->set_boost(policy, state);
2767 policy->boost_enabled = !policy->boost_enabled;