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 arch_scale_freq_ref(policy->cpu));
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;
636 static ssize_t show_local_boost(struct cpufreq_policy *policy, char *buf)
638 return sysfs_emit(buf, "%d\n", policy->boost_enabled);
641 static ssize_t store_local_boost(struct cpufreq_policy *policy,
653 if (policy->boost_enabled == enable)
656 policy->boost_enabled = enable;
659 ret = cpufreq_driver->set_boost(policy, enable);
663 policy->boost_enabled = !policy->boost_enabled;
734 * Write out information from cpufreq_driver->policy[cpu]; object must be
740 (struct cpufreq_policy *policy, char *buf) \
742 return sprintf(buf, "%u\n", policy->object); \
756 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf)
761 freq = arch_freq_get_on_cpu(policy->cpu);
765 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu));
767 ret = sprintf(buf, "%u\n", policy->cur);
776 (struct cpufreq_policy *policy, const char *buf, size_t count) \
785 ret = freq_qos_update_request(policy->object##_freq_req, val);\
795 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
798 unsigned int cur_freq = __cpufreq_get(policy);
807 * show_scaling_governor - show the current policy for the specified CPU
809 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
811 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
813 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
815 else if (policy->governor)
817 policy->governor->name);
822 * store_scaling_governor - store policy for the specified CPU
824 static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
841 ret = cpufreq_set_policy(policy, NULL, new_pol);
849 ret = cpufreq_set_policy(policy, new_gov,
861 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
869 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
916 static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf)
918 return cpufreq_show_cpus(policy->related_cpus, buf);
924 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf)
926 return cpufreq_show_cpus(policy->cpus, buf);
929 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy,
935 if (!policy->governor || !policy->governor->store_setspeed)
942 policy->governor->store_setspeed(policy, freq);
947 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf)
949 if (!policy->governor || !policy->governor->show_setspeed)
952 return policy->governor->show_setspeed(policy, buf);
958 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
962 ret = cpufreq_driver->bios_limit(policy->cpu, &limit);
965 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
1004 struct cpufreq_policy *policy = to_policy(kobj);
1011 down_read(&policy->rwsem);
1012 if (likely(!policy_is_inactive(policy)))
1013 ret = fattr->show(policy, buf);
1014 up_read(&policy->rwsem);
1022 struct cpufreq_policy *policy = to_policy(kobj);
1029 down_write(&policy->rwsem);
1030 if (likely(!policy_is_inactive(policy)))
1031 ret = fattr->store(policy, buf, count);
1032 up_write(&policy->rwsem);
1039 struct cpufreq_policy *policy = to_policy(kobj);
1041 complete(&policy->kobj_unregister);
1055 static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu,
1061 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus))
1065 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq"))
1069 static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, int cpu,
1074 cpumask_clear_cpu(cpu, policy->real_cpus);
1077 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy)
1085 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
1091 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
1096 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
1101 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr);
1107 ret = sysfs_create_file(&policy->kobj, &local_boost.attr);
1115 static int cpufreq_init_policy(struct cpufreq_policy *policy)
1122 /* Update policy governor to the one used before hotplug. */
1123 gov = get_governor(policy->last_governor);
1126 gov->name, policy->cpu);
1138 /* Use the default policy if there is no last_policy. */
1139 if (policy->last_policy) {
1140 pol = policy->last_policy;
1145 * nor "powersave", fall back to the initial policy
1149 pol = policy->policy;
1156 ret = cpufreq_set_policy(policy, gov, pol);
1163 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu)
1168 if (cpumask_test_cpu(cpu, policy->cpus))
1171 down_write(&policy->rwsem);
1173 cpufreq_stop_governor(policy);
1175 cpumask_set_cpu(cpu, policy->cpus);
1178 ret = cpufreq_start_governor(policy);
1182 up_write(&policy->rwsem);
1186 void refresh_frequency_limits(struct cpufreq_policy *policy)
1188 if (!policy_is_inactive(policy)) {
1189 pr_debug("updating policy for CPU %u\n", policy->cpu);
1191 cpufreq_set_policy(policy, policy->governor, policy->policy);
1198 struct cpufreq_policy *policy =
1201 pr_debug("handle_update for cpu %u called\n", policy->cpu);
1202 down_write(&policy->rwsem);
1203 refresh_frequency_limits(policy);
1204 up_write(&policy->rwsem);
1210 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min);
1212 schedule_work(&policy->update);
1219 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max);
1221 schedule_work(&policy->update);
1225 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy)
1230 down_write(&policy->rwsem);
1231 cpufreq_stats_free_table(policy);
1232 kobj = &policy->kobj;
1233 cmp = &policy->kobj_unregister;
1234 up_write(&policy->rwsem);
1249 struct cpufreq_policy *policy;
1256 policy = kzalloc(sizeof(*policy), GFP_KERNEL);
1257 if (!policy)
1260 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL))
1263 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL))
1266 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL))
1269 init_completion(&policy->kobj_unregister);
1270 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq,
1271 cpufreq_global_kobject, "policy%u", cpu);
1273 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret);
1275 * The entire policy object will be freed below, but the extra
1279 kobject_put(&policy->kobj);
1283 freq_constraints_init(&policy->constraints);
1285 policy->nb_min.notifier_call = cpufreq_notifier_min;
1286 policy->nb_max.notifier_call = cpufreq_notifier_max;
1288 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN,
1289 &policy->nb_min);
1296 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX,
1297 &policy->nb_max);
1304 INIT_LIST_HEAD(&policy->policy_list);
1305 init_rwsem(&policy->rwsem);
1306 spin_lock_init(&policy->transition_lock);
1307 init_waitqueue_head(&policy->transition_wait);
1308 INIT_WORK(&policy->update, handle_update);
1310 policy->cpu = cpu;
1311 return policy;
1314 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1315 &policy->nb_min);
1317 cpufreq_policy_put_kobj(policy);
1319 free_cpumask_var(policy->real_cpus);
1321 free_cpumask_var(policy->related_cpus);
1323 free_cpumask_var(policy->cpus);
1325 kfree(policy);
1330 static void cpufreq_policy_free(struct cpufreq_policy *policy)
1336 * The callers must ensure the policy is inactive by now, to avoid any
1339 if (unlikely(!policy_is_inactive(policy)))
1340 pr_warn("%s: Freeing active policy\n", __func__);
1342 /* Remove policy from list */
1344 list_del(&policy->policy_list);
1346 for_each_cpu(cpu, policy->related_cpus)
1350 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX,
1351 &policy->nb_max);
1352 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN,
1353 &policy->nb_min);
1355 /* Cancel any pending policy->update work before freeing the policy. */
1356 cancel_work_sync(&policy->update);
1358 if (policy->max_freq_req) {
1365 CPUFREQ_REMOVE_POLICY, policy);
1366 freq_qos_remove_request(policy->max_freq_req);
1369 freq_qos_remove_request(policy->min_freq_req);
1370 kfree(policy->min_freq_req);
1372 cpufreq_policy_put_kobj(policy);
1373 free_cpumask_var(policy->real_cpus);
1374 free_cpumask_var(policy->related_cpus);
1375 free_cpumask_var(policy->cpus);
1376 kfree(policy);
1381 struct cpufreq_policy *policy;
1389 /* Check if this CPU already has a policy to manage it */
1390 policy = per_cpu(cpufreq_cpu_data, cpu);
1391 if (policy) {
1392 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus));
1393 if (!policy_is_inactive(policy))
1394 return cpufreq_add_policy_cpu(policy, cpu);
1396 /* This is the only online CPU for the policy. Start over. */
1398 down_write(&policy->rwsem);
1399 policy->cpu = cpu;
1400 policy->governor = NULL;
1403 policy = cpufreq_policy_alloc(cpu);
1404 if (!policy)
1406 down_write(&policy->rwsem);
1410 /* Recover policy->cpus using related_cpus */
1411 cpumask_copy(policy->cpus, policy->related_cpus);
1413 ret = cpufreq_driver->online(policy);
1420 cpumask_copy(policy->cpus, cpumask_of(cpu));
1426 ret = cpufreq_driver->init(policy);
1433 /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */
1434 policy->boost_enabled = cpufreq_boost_enabled() && policy_has_boost_freq(policy);
1437 * The initialization has succeeded and the policy is online.
1441 ret = cpufreq_table_validate_and_sort(policy);
1445 /* related_cpus should at least include policy->cpus. */
1446 cpumask_copy(policy->related_cpus, policy->cpus);
1453 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask);
1456 for_each_cpu(j, policy->related_cpus) {
1457 per_cpu(cpufreq_cpu_data, j) = policy;
1458 add_cpu_dev_symlink(policy, j, get_cpu_device(j));
1461 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req),
1463 if (!policy->min_freq_req) {
1468 ret = freq_qos_add_request(&policy->constraints,
1469 policy->min_freq_req, FREQ_QOS_MIN,
1476 kfree(policy->min_freq_req);
1477 policy->min_freq_req = NULL;
1486 policy->max_freq_req = policy->min_freq_req + 1;
1488 ret = freq_qos_add_request(&policy->constraints,
1489 policy->max_freq_req, FREQ_QOS_MAX,
1492 policy->max_freq_req = NULL;
1497 CPUFREQ_CREATE_POLICY, policy);
1501 policy->cur = cpufreq_driver->get(policy->cpu);
1502 if (!policy->cur) {
1519 * for the next freq which is >= policy->cur ('cur' must be set by now,
1523 * We are passing target-freq as "policy->cur - 1" otherwise
1524 * __cpufreq_driver_target() would simply fail, as policy->cur will be
1529 unsigned int old_freq = policy->cur;
1532 ret = cpufreq_frequency_table_get_index(policy, old_freq);
1534 ret = __cpufreq_driver_target(policy, old_freq - 1,
1544 __func__, policy->cpu, old_freq, policy->cur);
1549 ret = cpufreq_add_dev_interface(policy);
1553 cpufreq_stats_create_table(policy);
1556 list_add(&policy->policy_list, &cpufreq_policy_list);
1563 * once the energy model is properly initialized for the policy
1566 * Also, this should be called before the policy is registered
1570 cpufreq_driver->register_em(policy);
1573 ret = cpufreq_init_policy(policy);
1575 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n",
1580 up_write(&policy->rwsem);
1582 kobject_uevent(&policy->kobj, KOBJ_ADD);
1584 /* Callback for handling stuff after policy is ready */
1586 cpufreq_driver->ready(policy);
1588 /* Register cpufreq cooling only for a new policy */
1590 policy->cdev = of_cpufreq_cooling_register(policy);
1597 for_each_cpu(j, policy->real_cpus)
1598 remove_cpu_dev_symlink(policy, j, get_cpu_device(j));
1602 cpufreq_driver->offline(policy);
1606 cpufreq_driver->exit(policy);
1609 cpumask_clear(policy->cpus);
1610 up_write(&policy->rwsem);
1612 cpufreq_policy_free(policy);
1623 struct cpufreq_policy *policy;
1636 policy = per_cpu(cpufreq_cpu_data, cpu);
1637 if (policy)
1638 add_cpu_dev_symlink(policy, cpu, dev);
1643 static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
1648 cpufreq_stop_governor(policy);
1650 cpumask_clear_cpu(cpu, policy->cpus);
1652 if (!policy_is_inactive(policy)) {
1654 if (cpu == policy->cpu)
1655 policy->cpu = cpumask_any(policy->cpus);
1657 /* Start the governor again for the active policy. */
1659 ret = cpufreq_start_governor(policy);
1668 strscpy(policy->last_governor, policy->governor->name,
1671 policy->last_policy = policy->policy;
1674 cpufreq_exit_governor(policy);
1681 cpufreq_driver->offline(policy);
1683 cpufreq_driver->exit(policy);
1684 policy->freq_table = NULL;
1690 struct cpufreq_policy *policy;
1694 policy = cpufreq_cpu_get_raw(cpu);
1695 if (!policy) {
1700 down_write(&policy->rwsem);
1702 __cpufreq_offline(cpu, policy);
1704 up_write(&policy->rwsem);
1716 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
1718 if (!policy)
1721 down_write(&policy->rwsem);
1724 __cpufreq_offline(cpu, policy);
1726 remove_cpu_dev_symlink(policy, cpu, dev);
1728 if (!cpumask_empty(policy->real_cpus)) {
1729 up_write(&policy->rwsem);
1734 * Unregister cpufreq cooling once all the CPUs of the policy are
1738 cpufreq_cooling_unregister(policy->cdev);
1739 policy->cdev = NULL;
1744 cpufreq_driver->exit(policy);
1746 up_write(&policy->rwsem);
1748 cpufreq_policy_free(policy);
1753 * @policy: Policy managing CPUs.
1759 static void cpufreq_out_of_sync(struct cpufreq_policy *policy,
1765 policy->cur, new_freq);
1767 freqs.old = policy->cur;
1770 cpufreq_freq_transition_begin(policy, &freqs);
1771 cpufreq_freq_transition_end(policy, &freqs, 0);
1774 static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update)
1778 new_freq = cpufreq_driver->get(policy->cpu);
1783 * If fast frequency switching is used with the given policy, the check
1784 * against policy->cur is pointless, so skip it in that case.
1786 if (policy->fast_switch_enabled || !has_target())
1789 if (policy->cur != new_freq) {
1797 if (abs(policy->cur - new_freq) < KHZ_PER_MHZ)
1798 return policy->cur;
1800 cpufreq_out_of_sync(policy, new_freq);
1802 schedule_work(&policy->update);
1809 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1817 struct cpufreq_policy *policy;
1831 policy = cpufreq_cpu_get(cpu);
1832 if (policy) {
1833 ret_freq = policy->cur;
1834 cpufreq_cpu_put(policy);
1849 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1852 if (policy) {
1853 ret_freq = policy->max;
1854 cpufreq_cpu_put(policy);
1869 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1872 if (policy) {
1873 ret_freq = policy->cpuinfo.max_freq;
1874 cpufreq_cpu_put(policy);
1881 static unsigned int __cpufreq_get(struct cpufreq_policy *policy)
1883 if (unlikely(policy_is_inactive(policy)))
1886 return cpufreq_verify_current_freq(policy, true);
1897 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1900 if (policy) {
1901 down_read(&policy->rwsem);
1903 ret_freq = __cpufreq_get(policy);
1904 up_read(&policy->rwsem);
1906 cpufreq_cpu_put(policy);
1924 int cpufreq_generic_suspend(struct cpufreq_policy *policy)
1928 if (!policy->suspend_freq) {
1934 policy->suspend_freq);
1936 ret = __cpufreq_driver_target(policy, policy->suspend_freq,
1940 __func__, policy->suspend_freq, ret);
1956 struct cpufreq_policy *policy;
1966 for_each_active_policy(policy) {
1968 down_write(&policy->rwsem);
1969 cpufreq_stop_governor(policy);
1970 up_write(&policy->rwsem);
1973 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
1990 struct cpufreq_policy *policy;
2006 for_each_active_policy(policy) {
2007 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
2011 down_write(&policy->rwsem);
2012 ret = cpufreq_start_governor(policy);
2013 up_write(&policy->rwsem);
2016 pr_err("%s: Failed to start governor for CPU%u's policy\n",
2017 __func__, policy->cpu);
2075 * of notifiers that ron on cpufreq policy changes.
2161 * @policy: cpufreq policy to switch the frequency for.
2171 * This function must not be called if policy->fast_switch_enabled is unset.
2174 * twice in parallel for the same policy and that it will never be called in
2175 * parallel with either ->target() or ->target_index() for the same policy.
2182 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy,
2188 target_freq = clamp_val(target_freq, policy->min, policy->max);
2189 freq = cpufreq_driver->fast_switch(policy, target_freq);
2194 policy->cur = freq;
2195 arch_set_freq_scale(policy->related_cpus, freq,
2196 arch_scale_freq_ref(policy->cpu));
2197 cpufreq_stats_record_transition(policy, freq);
2200 for_each_cpu(cpu, policy->cpus)
2222 * This function must not be called if policy->fast_switch_enabled is unset.
2249 static int __target_intermediate(struct cpufreq_policy *policy,
2254 freqs->new = cpufreq_driver->get_intermediate(policy, index);
2261 __func__, policy->cpu, freqs->old, freqs->new);
2263 cpufreq_freq_transition_begin(policy, freqs);
2264 ret = cpufreq_driver->target_intermediate(policy, index);
2265 cpufreq_freq_transition_end(policy, freqs, ret);
2274 static int __target_index(struct cpufreq_policy *policy, int index)
2276 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0};
2278 unsigned int newfreq = policy->freq_table[index].frequency;
2282 if (newfreq == policy->cur)
2286 restore_freq = policy->cur;
2292 retval = __target_intermediate(policy, &freqs, index);
2304 __func__, policy->cpu, freqs.old, freqs.new);
2306 cpufreq_freq_transition_begin(policy, &freqs);
2309 retval = cpufreq_driver->target_index(policy, index);
2315 cpufreq_freq_transition_end(policy, &freqs, retval);
2326 cpufreq_freq_transition_begin(policy, &freqs);
2327 cpufreq_freq_transition_end(policy, &freqs, 0);
2334 int __cpufreq_driver_target(struct cpufreq_policy *policy,
2343 target_freq = __resolve_freq(policy, target_freq, relation);
2346 policy->cpu, target_freq, relation, old_target_freq);
2354 if (target_freq == policy->cur &&
2363 if (!policy->efficiencies_available)
2366 return cpufreq_driver->target(policy, target_freq, relation);
2372 return __target_index(policy, policy->cached_resolved_idx);
2376 int cpufreq_driver_target(struct cpufreq_policy *policy,
2382 down_write(&policy->rwsem);
2384 ret = __cpufreq_driver_target(policy, target_freq, relation);
2386 up_write(&policy->rwsem);
2397 static int cpufreq_init_governor(struct cpufreq_policy *policy)
2408 if (!policy->governor)
2412 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING &&
2418 policy->governor->name, gov->name);
2419 policy->governor = gov;
2425 if (!try_module_get(policy->governor->owner))
2428 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2430 if (policy->governor->init) {
2431 ret = policy->governor->init(policy);
2433 module_put(policy->governor->owner);
2438 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET);
2443 static void cpufreq_exit_governor(struct cpufreq_policy *policy)
2445 if (cpufreq_suspended || !policy->governor)
2448 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2450 if (policy->governor->exit)
2451 policy->governor->exit(policy);
2453 module_put(policy->governor->owner);
2456 int cpufreq_start_governor(struct cpufreq_policy *policy)
2463 if (!policy->governor)
2466 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2469 cpufreq_verify_current_freq(policy, false);
2471 if (policy->governor->start) {
2472 ret = policy->governor->start(policy);
2477 if (policy->governor->limits)
2478 policy->governor->limits(policy);
2483 void cpufreq_stop_governor(struct cpufreq_policy *policy)
2485 if (cpufreq_suspended || !policy->governor)
2488 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2490 if (policy->governor->stop)
2491 policy->governor->stop(policy);
2494 static void cpufreq_governor_limits(struct cpufreq_policy *policy)
2496 if (cpufreq_suspended || !policy->governor)
2499 pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
2501 if (policy->governor->limits)
2502 policy->governor->limits(policy);
2530 struct cpufreq_policy *policy;
2541 for_each_inactive_policy(policy) {
2542 if (!strcmp(policy->last_governor, governor->name)) {
2543 policy->governor = NULL;
2544 strcpy(policy->last_governor, "\0");
2562 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2564 * @cpu: CPU to find the policy for
2566 * Reads the current cpufreq policy.
2568 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
2571 if (!policy)
2578 memcpy(policy, cpu_policy, sizeof(*policy));
2586 * cpufreq_set_policy - Modify cpufreq policy parameters.
2587 * @policy: Policy object to modify.
2592 * limits to be set for the policy, update @policy with the verified limits
2594 * carry out a governor update for @policy. That is, run the current governor's
2596 * @policy) or replace the governor for @policy with @new_gov.
2598 * The cpuinfo part of @policy is not updated by this function.
2600 static int cpufreq_set_policy(struct cpufreq_policy *policy,
2608 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo));
2609 new_data.freq_table = policy->freq_table;
2610 new_data.cpu = policy->cpu;
2615 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN);
2616 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX);
2618 pr_debug("setting new policy for CPU %u: %u - %u kHz\n",
2630 * Resolve policy min/max to available frequencies. It ensures
2634 policy->min = new_data.min;
2635 policy->max = new_data.max;
2636 policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L);
2637 policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H);
2638 trace_cpu_frequency_limits(policy);
2640 policy->cached_target_freq = UINT_MAX;
2643 policy->min, policy->max);
2646 policy->policy = new_pol;
2648 return cpufreq_driver->setpolicy(policy);
2651 if (new_gov == policy->governor) {
2653 cpufreq_governor_limits(policy);
2660 old_gov = policy->governor;
2663 cpufreq_stop_governor(policy);
2664 cpufreq_exit_governor(policy);
2668 policy->governor = new_gov;
2669 ret = cpufreq_init_governor(policy);
2671 ret = cpufreq_start_governor(policy);
2676 cpufreq_exit_governor(policy);
2680 pr_debug("starting governor %s failed\n", policy->governor->name);
2682 policy->governor = old_gov;
2683 if (cpufreq_init_governor(policy))
2684 policy->governor = NULL;
2686 cpufreq_start_governor(policy);
2693 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2694 * @cpu: CPU to re-evaluate the policy for.
2696 * Update the current frequency for the cpufreq policy of @cpu and use
2698 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2699 * for the policy in question, among other things.
2703 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu);
2705 if (!policy)
2713 (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
2716 refresh_frequency_limits(policy);
2719 cpufreq_cpu_release(policy);
2724 * cpufreq_update_limits - Update policy limits for a given CPU.
2725 * @cpu: CPU to update the policy limits for.
2742 static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state)
2746 if (!policy->freq_table)
2749 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table);
2755 ret = freq_qos_update_request(policy->max_freq_req, policy->max);
2764 struct cpufreq_policy *policy;
2776 for_each_active_policy(policy) {
2777 policy->boost_enabled = state;
2778 ret = cpufreq_driver->set_boost(policy, state);
2780 policy->boost_enabled = !policy->boost_enabled;