Lines Matching +full:boost +full:- +full:low +full:- +full:freq

1 // SPDX-License-Identifier: GPL-2.0-only
6 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
9 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
11 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
12 * Fix handling for CPU hotplug -- affected CPUs
54 * The "cpufreq driver" - the arch- or hardware-dependent low
73 return cpufreq_driver->target_index || cpufreq_driver->target; in has_target()
78 return !!cpufreq_driver->target_index; in has_target_index()
114 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); in have_governor_per_policy()
123 return &policy->kobj; in get_governor_parent_kobj()
147 idle_time = cur_wall_time - busy_time; in get_cpu_idle_time_jiffy()
158 if (idle_time == -1ULL) in get_cpu_idle_time()
170 * - validate & show freq table passed
171 * - set policies transition latency
172 * - policy->cpus with all possible CPUs
178 policy->freq_table = table; in cpufreq_generic_init()
179 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
185 cpumask_setall(policy->cpus); in cpufreq_generic_init()
193 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
201 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
207 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
212 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
237 kobject_get(&policy->kobj); in cpufreq_cpu_get()
247 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
252 kobject_put(&policy->kobj); in cpufreq_cpu_put()
257 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
265 lockdep_assert_held(&policy->rwsem); in cpufreq_cpu_release()
267 up_write(&policy->rwsem); in cpufreq_cpu_release()
273 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
291 down_write(&policy->rwsem); in cpufreq_cpu_acquire()
306 * adjust_jiffies - Adjust the system "loops_per_jiffy".
313 * per-CPU loops_per_jiffy value wherever possible.
321 if (ci->flags & CPUFREQ_CONST_LOOPS) in adjust_jiffies()
326 l_p_j_ref_freq = ci->old; in adjust_jiffies()
327 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", in adjust_jiffies()
330 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) { in adjust_jiffies()
332 ci->new); in adjust_jiffies()
334 loops_per_jiffy, ci->new); in adjust_jiffies()
340 * cpufreq_notify_transition - Notify frequency transition and adjust jiffies.
360 freqs->policy = policy; in cpufreq_notify_transition()
361 freqs->flags = cpufreq_driver->flags; in cpufreq_notify_transition()
363 state, freqs->new); in cpufreq_notify_transition()
372 if (policy->cur && policy->cur != freqs->old) { in cpufreq_notify_transition()
374 freqs->old, policy->cur); in cpufreq_notify_transition()
375 freqs->old = policy->cur; in cpufreq_notify_transition()
386 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, in cpufreq_notify_transition()
387 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
389 for_each_cpu(cpu, policy->cpus) in cpufreq_notify_transition()
390 trace_cpu_frequency(freqs->new, cpu); in cpufreq_notify_transition()
395 cpufreq_stats_record_transition(policy, freqs->new); in cpufreq_notify_transition()
396 policy->cur = freqs->new; in cpufreq_notify_transition()
408 swap(freqs->old, freqs->new); in cpufreq_notify_post_transition()
418 * Catch double invocations of _begin() which lead to self-deadlock. in cpufreq_freq_transition_begin()
421 * double invocations are very low. Moreover, there are scenarios in cpufreq_freq_transition_begin()
422 * where these checks can emit false-positive warnings in these in cpufreq_freq_transition_begin()
425 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION) in cpufreq_freq_transition_begin()
426 && current == policy->transition_task); in cpufreq_freq_transition_begin()
429 wait_event(policy->transition_wait, !policy->transition_ongoing); in cpufreq_freq_transition_begin()
431 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_begin()
433 if (unlikely(policy->transition_ongoing)) { in cpufreq_freq_transition_begin()
434 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
438 policy->transition_ongoing = true; in cpufreq_freq_transition_begin()
439 policy->transition_task = current; in cpufreq_freq_transition_begin()
441 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
450 if (WARN_ON(!policy->transition_ongoing)) in cpufreq_freq_transition_end()
455 arch_set_freq_scale(policy->related_cpus, in cpufreq_freq_transition_end()
456 policy->cur, in cpufreq_freq_transition_end()
457 policy->cpuinfo.max_freq); in cpufreq_freq_transition_end()
459 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_end()
460 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
461 policy->transition_task = NULL; in cpufreq_freq_transition_end()
462 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_end()
464 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
483 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) in cpufreq_list_transition_notifiers()
484 pr_info("%pS\n", nb->notifier_call); in cpufreq_list_transition_notifiers()
490 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
502 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
504 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
510 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
513 policy->cpu); in cpufreq_enable_fast_switch()
521 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
527 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
528 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
530 cpufreq_fast_switch_count--; in cpufreq_disable_fast_switch()
541 target_freq = clamp_val(target_freq, policy->min, policy->max); in __resolve_freq()
543 if (!policy->freq_table) in __resolve_freq()
547 policy->cached_resolved_idx = idx; in __resolve_freq()
548 policy->cached_target_freq = target_freq; in __resolve_freq()
549 return policy->freq_table[idx].frequency; in __resolve_freq()
553 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
560 * Return: Lowest driver-supported frequency greater than or equal to the
574 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
575 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
577 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
602 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
612 return -EINVAL; in store_boost()
615 pr_err("%s: Cannot %s BOOST!\n", in store_boost()
617 return -EINVAL; in store_boost()
620 pr_debug("%s: cpufreq BOOST %s\n", in store_boost()
625 define_one_global_rw(boost);
629 return sysfs_emit(buf, "%d\n", policy->boost_enabled); in show_local_boost()
639 return -EINVAL; in store_local_boost()
641 if (!cpufreq_driver->boost_enabled) in store_local_boost()
642 return -EINVAL; in store_local_boost()
644 if (policy->boost_enabled == enable) in store_local_boost()
647 policy->boost_enabled = enable; in store_local_boost()
650 ret = cpufreq_driver->set_boost(policy, enable); in store_local_boost()
654 policy->boost_enabled = !policy->boost_enabled; in store_local_boost()
661 static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);
668 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
683 if (!try_module_get(t->owner)) in get_governor()
704 * cpufreq_parse_governor - parse a governor string only for has_target()
722 * cpufreq_per_cpu_attr_read() / show_##file_name() -
725 * Write out information from cpufreq_driver->policy[cpu]; object must be
733 return sprintf(buf, "%u\n", policy->object); \
750 unsigned int freq; in show_scaling_cur_freq() local
752 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
753 if (freq) in show_scaling_cur_freq()
754 ret = sprintf(buf, "%u\n", freq); in show_scaling_cur_freq()
755 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) in show_scaling_cur_freq()
756 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
758 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
763 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
776 ret = freq_qos_update_request(policy->object##_freq_req, val);\
784 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
798 * show_scaling_governor - show the current policy for the specified CPU
802 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
804 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
806 else if (policy->governor) in show_scaling_governor()
808 policy->governor->name); in show_scaling_governor()
809 return -EINVAL; in show_scaling_governor()
813 * store_scaling_governor - store policy for the specified CPU
823 return -EINVAL; in store_scaling_governor()
825 if (cpufreq_driver->setpolicy) { in store_scaling_governor()
830 return -EINVAL; in store_scaling_governor()
838 return -EINVAL; in store_scaling_governor()
843 module_put(new_gov->owner); in store_scaling_governor()
850 * show_scaling_driver - show the cpufreq driver currently loaded
854 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
858 * show_scaling_available_governors - show the available CPUfreq governors
874 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
876 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); in show_scaling_available_governors()
890 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); in cpufreq_show_cpus()
891 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
896 i--; in cpufreq_show_cpus()
904 * show_related_cpus - show the CPUs affected by each transition even if
909 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
913 * show_affected_cpus - show the CPUs affected by each transition
917 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
923 unsigned int freq = 0; in store_scaling_setspeed() local
926 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
927 return -EINVAL; in store_scaling_setspeed()
929 ret = sscanf(buf, "%u", &freq); in store_scaling_setspeed()
931 return -EINVAL; in store_scaling_setspeed()
933 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
940 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
943 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
947 * show_bios_limit - show the current cpufreq HW/BIOS limitation
953 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
956 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
997 ssize_t ret = -EBUSY; in show()
999 if (!fattr->show) in show()
1000 return -EIO; in show()
1002 down_read(&policy->rwsem); in show()
1004 ret = fattr->show(policy, buf); in show()
1005 up_read(&policy->rwsem); in show()
1015 ssize_t ret = -EBUSY; in store()
1017 if (!fattr->store) in store()
1018 return -EIO; in store()
1020 down_write(&policy->rwsem); in store()
1022 ret = fattr->store(policy, buf, count); in store()
1023 up_write(&policy->rwsem); in store()
1032 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1052 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1056 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1064 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
1065 cpumask_clear_cpu(cpu, policy->real_cpus); in remove_cpu_dev_symlink()
1074 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
1076 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1081 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1082 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1087 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1091 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1092 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1098 ret = sysfs_create_file(&policy->kobj, &local_boost.attr); in cpufreq_add_dev_interface()
1114 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1117 gov->name, policy->cpu); in cpufreq_init_policy()
1124 __module_get(gov->owner); in cpufreq_init_policy()
1130 if (policy->last_policy) { in cpufreq_init_policy()
1131 pol = policy->last_policy; in cpufreq_init_policy()
1140 pol = policy->policy; in cpufreq_init_policy()
1144 return -ENODATA; in cpufreq_init_policy()
1149 module_put(gov->owner); in cpufreq_init_policy()
1159 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1162 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1166 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1173 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1180 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1182 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1192 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1193 down_write(&policy->rwsem); in handle_update()
1195 up_write(&policy->rwsem); in handle_update()
1198 static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_min() argument
1203 schedule_work(&policy->update); in cpufreq_notifier_min()
1207 static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_max() argument
1212 schedule_work(&policy->update); in cpufreq_notifier_max()
1221 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1223 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1224 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1225 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1251 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1254 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1257 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1260 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1261 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1264 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1270 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1274 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1276 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1277 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1279 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1280 &policy->nb_min); in cpufreq_policy_alloc()
1287 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1288 &policy->nb_max); in cpufreq_policy_alloc()
1295 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1296 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1297 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1298 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1299 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1301 policy->cpu = cpu; in cpufreq_policy_alloc()
1305 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1306 &policy->nb_min); in cpufreq_policy_alloc()
1310 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1312 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1314 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1335 list_del(&policy->policy_list); in cpufreq_policy_free()
1337 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1341 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1342 &policy->nb_max); in cpufreq_policy_free()
1343 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1344 &policy->nb_min); in cpufreq_policy_free()
1346 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1347 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1349 if (policy->max_freq_req) { in cpufreq_policy_free()
1357 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1360 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1361 kfree(policy->min_freq_req); in cpufreq_policy_free()
1364 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1365 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1366 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1383 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1389 down_write(&policy->rwsem); in cpufreq_online()
1390 policy->cpu = cpu; in cpufreq_online()
1391 policy->governor = NULL; in cpufreq_online()
1396 return -ENOMEM; in cpufreq_online()
1397 down_write(&policy->rwsem); in cpufreq_online()
1400 if (!new_policy && cpufreq_driver->online) { in cpufreq_online()
1401 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1402 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1404 ret = cpufreq_driver->online(policy); in cpufreq_online()
1411 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1415 * to accept all calls to ->verify and ->setpolicy for this CPU. in cpufreq_online()
1417 ret = cpufreq_driver->init(policy); in cpufreq_online()
1424 /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ in cpufreq_online()
1426 policy->boost_enabled = true; in cpufreq_online()
1437 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1438 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1445 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1448 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1453 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1455 if (!policy->min_freq_req) { in cpufreq_online()
1456 ret = -ENOMEM; in cpufreq_online()
1460 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1461 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1468 kfree(policy->min_freq_req); in cpufreq_online()
1469 policy->min_freq_req = NULL; in cpufreq_online()
1478 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1480 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1481 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1484 policy->max_freq_req = NULL; in cpufreq_online()
1492 if (cpufreq_driver->get && has_target()) { in cpufreq_online()
1493 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1494 if (!policy->cur) { in cpufreq_online()
1495 ret = -EIO; in cpufreq_online()
1496 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1506 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1507 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1508 * isn't found in freq-table. in cpufreq_online()
1511 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1512 * otherwise we will end up setting freq to lowest of the table as 'cur' in cpufreq_online()
1515 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1516 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1517 * equal to target-freq. in cpufreq_online()
1519 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1521 unsigned int old_freq = policy->cur; in cpufreq_online()
1525 if (ret == -EINVAL) { in cpufreq_online()
1526 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1536 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1548 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1561 if (cpufreq_driver->register_em) in cpufreq_online()
1562 cpufreq_driver->register_em(policy); in cpufreq_online()
1572 up_write(&policy->rwsem); in cpufreq_online()
1574 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1577 if (cpufreq_driver->ready) in cpufreq_online()
1578 cpufreq_driver->ready(policy); in cpufreq_online()
1582 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1589 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1593 if (cpufreq_driver->offline) in cpufreq_online()
1594 cpufreq_driver->offline(policy); in cpufreq_online()
1597 if (cpufreq_driver->exit) in cpufreq_online()
1598 cpufreq_driver->exit(policy); in cpufreq_online()
1601 cpumask_clear(policy->cpus); in cpufreq_online()
1602 up_write(&policy->rwsem); in cpufreq_online()
1609 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1616 unsigned cpu = dev->id; in cpufreq_add_dev()
1642 cpumask_clear_cpu(cpu, policy->cpus); in __cpufreq_offline()
1646 if (cpu == policy->cpu) in __cpufreq_offline()
1647 policy->cpu = cpumask_any(policy->cpus); in __cpufreq_offline()
1660 strncpy(policy->last_governor, policy->governor->name, in __cpufreq_offline()
1663 policy->last_policy = policy->policy; in __cpufreq_offline()
1669 * Perform the ->offline() during light-weight tear-down, as in __cpufreq_offline()
1672 if (cpufreq_driver->offline) { in __cpufreq_offline()
1673 cpufreq_driver->offline(policy); in __cpufreq_offline()
1677 if (cpufreq_driver->exit) in __cpufreq_offline()
1678 cpufreq_driver->exit(policy); in __cpufreq_offline()
1680 policy->freq_table = NULL; in __cpufreq_offline()
1695 down_write(&policy->rwsem); in cpufreq_offline()
1699 up_write(&policy->rwsem); in cpufreq_offline()
1704 * cpufreq_remove_dev - remove a CPU device
1710 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1716 down_write(&policy->rwsem); in cpufreq_remove_dev()
1723 if (!cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1724 up_write(&policy->rwsem); in cpufreq_remove_dev()
1733 cpufreq_cooling_unregister(policy->cdev); in cpufreq_remove_dev()
1734 policy->cdev = NULL; in cpufreq_remove_dev()
1737 /* We did light-weight exit earlier, do full tear down now */ in cpufreq_remove_dev()
1738 if (cpufreq_driver->offline && cpufreq_driver->exit) in cpufreq_remove_dev()
1739 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1741 up_write(&policy->rwsem); in cpufreq_remove_dev()
1747 * cpufreq_out_of_sync - Fix up actual and saved CPU frequency difference.
1760 policy->cur, new_freq); in cpufreq_out_of_sync()
1762 freqs.old = policy->cur; in cpufreq_out_of_sync()
1773 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1779 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1781 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1784 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1792 if (abs(policy->cur - new_freq) < KHZ_PER_MHZ) in cpufreq_verify_current_freq()
1793 return policy->cur; in cpufreq_verify_current_freq()
1797 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1804 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1807 * This is the last known freq, without actually getting it from the driver.
1818 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1819 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1828 ret_freq = policy->cur; in cpufreq_quick_get()
1837 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1848 ret_freq = policy->max; in cpufreq_quick_get_max()
1857 * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1868 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1885 * cpufreq_get - get the current CPU frequency (in kHz)
1896 down_read(&policy->rwsem); in cpufreq_get()
1897 if (cpufreq_driver->get) in cpufreq_get()
1899 up_read(&policy->rwsem); in cpufreq_get()
1923 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1928 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1929 policy->suspend_freq); in cpufreq_generic_suspend()
1931 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1934 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1935 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1942 * cpufreq_suspend() - Suspend CPUFreq governors.
1956 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1963 down_write(&policy->rwsem); in cpufreq_suspend()
1965 up_write(&policy->rwsem); in cpufreq_suspend()
1968 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1970 cpufreq_driver->name); in cpufreq_suspend()
1978 * cpufreq_resume() - Resume CPUFreq governors.
1996 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
2002 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
2004 cpufreq_driver->name); in cpufreq_resume()
2006 down_write(&policy->rwsem); in cpufreq_resume()
2008 up_write(&policy->rwsem); in cpufreq_resume()
2012 __func__, policy->cpu); in cpufreq_resume()
2018 * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
2026 return !!(cpufreq_driver->flags & flags); in cpufreq_driver_test_flags()
2030 * cpufreq_get_current_driver - Return the current driver's name.
2038 return cpufreq_driver->name; in cpufreq_get_current_driver()
2045 * cpufreq_get_driver_data - Return current driver data.
2053 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
2064 * cpufreq_register_notifier - Register a notifier with cpufreq.
2080 return -EINVAL; in cpufreq_register_notifier()
2088 return -EBUSY; in cpufreq_register_notifier()
2093 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
2102 ret = -EINVAL; in cpufreq_register_notifier()
2110 * cpufreq_unregister_notifier - Unregister a notifier from cpufreq.
2124 return -EINVAL; in cpufreq_unregister_notifier()
2142 ret = -EINVAL; in cpufreq_unregister_notifier()
2155 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
2161 * The driver's ->fast_switch() callback invoked by this function must be
2162 * suitable for being called from within RCU-sched read-side critical sections
2166 * This function must not be called if policy->fast_switch_enabled is unset.
2170 * parallel with either ->target() or ->target_index() for the same policy.
2174 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
2180 unsigned int freq; in cpufreq_driver_fast_switch() local
2183 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2184 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2186 if (!freq) in cpufreq_driver_fast_switch()
2189 policy->cur = freq; in cpufreq_driver_fast_switch()
2190 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2191 policy->cpuinfo.max_freq); in cpufreq_driver_fast_switch()
2192 cpufreq_stats_record_transition(policy, freq); in cpufreq_driver_fast_switch()
2195 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2196 trace_cpu_frequency(freq, cpu); in cpufreq_driver_fast_switch()
2199 return freq; in cpufreq_driver_fast_switch()
2204 * cpufreq_driver_adjust_perf - Adjust CPU performance level in one go.
2212 * The driver's ->adjust_perf() callback invoked by this function must be
2213 * suitable for being called from within RCU-sched read-side critical sections
2217 * This function must not be called if policy->fast_switch_enabled is unset.
2221 * parallel with either ->target() or ->target_index() or ->fast_switch() for
2229 cpufreq_driver->adjust_perf(cpu, min_perf, target_perf, capacity); in cpufreq_driver_adjust_perf()
2233 * cpufreq_driver_has_adjust_perf - Check "direct fast switch" callback.
2235 * Return 'true' if the ->adjust_perf callback is present for the
2240 return !!cpufreq_driver->adjust_perf; in cpufreq_driver_has_adjust_perf()
2243 /* Must set freqs->new to intermediate frequency */
2249 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2251 /* We don't need to switch to intermediate freq */ in __target_intermediate()
2252 if (!freqs->new) in __target_intermediate()
2255 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n", in __target_intermediate()
2256 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2259 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2271 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2273 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2274 int retval = -EINVAL; in __target_index()
2277 if (newfreq == policy->cur) in __target_index()
2281 restore_freq = policy->cur; in __target_index()
2283 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
2286 if (cpufreq_driver->get_intermediate) { in __target_index()
2292 /* Set old freq to intermediate */ in __target_index()
2298 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", in __target_index()
2299 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2304 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2313 * Failed after setting to intermediate freq? Driver should have in __target_index()
2316 * case we haven't switched to intermediate freq at all. in __target_index()
2336 return -ENODEV; in __cpufreq_driver_target()
2341 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2346 * exactly same freq is called again and so we can save on few function in __cpufreq_driver_target()
2349 if (target_freq == policy->cur && in __cpufreq_driver_target()
2350 !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) in __cpufreq_driver_target()
2353 if (cpufreq_driver->target) { in __cpufreq_driver_target()
2358 if (!policy->efficiencies_available) in __cpufreq_driver_target()
2361 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2364 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
2365 return -EINVAL; in __cpufreq_driver_target()
2367 return __target_index(policy, policy->cached_resolved_idx); in __cpufreq_driver_target()
2377 down_write(&policy->rwsem); in cpufreq_driver_target()
2381 up_write(&policy->rwsem); in cpufreq_driver_target()
2403 if (!policy->governor) in cpufreq_init_governor()
2404 return -EINVAL; in cpufreq_init_governor()
2407 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2408 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2413 policy->governor->name, gov->name); in cpufreq_init_governor()
2414 policy->governor = gov; in cpufreq_init_governor()
2416 return -EINVAL; in cpufreq_init_governor()
2420 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2421 return -EINVAL; in cpufreq_init_governor()
2423 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2425 if (policy->governor->init) { in cpufreq_init_governor()
2426 ret = policy->governor->init(policy); in cpufreq_init_governor()
2428 module_put(policy->governor->owner); in cpufreq_init_governor()
2433 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2440 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2443 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2445 if (policy->governor->exit) in cpufreq_exit_governor()
2446 policy->governor->exit(policy); in cpufreq_exit_governor()
2448 module_put(policy->governor->owner); in cpufreq_exit_governor()
2458 if (!policy->governor) in cpufreq_start_governor()
2459 return -EINVAL; in cpufreq_start_governor()
2461 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2463 if (cpufreq_driver->get) in cpufreq_start_governor()
2466 if (policy->governor->start) { in cpufreq_start_governor()
2467 ret = policy->governor->start(policy); in cpufreq_start_governor()
2472 if (policy->governor->limits) in cpufreq_start_governor()
2473 policy->governor->limits(policy); in cpufreq_start_governor()
2480 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2483 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2485 if (policy->governor->stop) in cpufreq_stop_governor()
2486 policy->governor->stop(policy); in cpufreq_stop_governor()
2491 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2494 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2496 if (policy->governor->limits) in cpufreq_governor_limits()
2497 policy->governor->limits(policy); in cpufreq_governor_limits()
2505 return -EINVAL; in cpufreq_register_governor()
2508 return -ENODEV; in cpufreq_register_governor()
2512 err = -EBUSY; in cpufreq_register_governor()
2513 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2515 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2537 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2538 policy->governor = NULL; in cpufreq_unregister_governor()
2539 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2545 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2556 * cpufreq_get_policy - get the current cpufreq_policy
2567 return -EINVAL; in cpufreq_get_policy()
2571 return -EINVAL; in cpufreq_get_policy()
2581 * cpufreq_set_policy - Modify cpufreq policy parameters.
2584 * @new_pol: Policy value (for drivers with built-in governors).
2586 * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2588 * values and either invoke the driver's ->setpolicy() callback (if present) or
2590 * ->limits() callback (if @new_gov points to the same object as the one in
2603 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2604 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2605 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2610 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2611 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2613 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2620 ret = cpufreq_driver->verify(&new_data); in cpufreq_set_policy()
2629 policy->min = new_data.min; in cpufreq_set_policy()
2630 policy->max = new_data.max; in cpufreq_set_policy()
2631 policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L); in cpufreq_set_policy()
2632 policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H); in cpufreq_set_policy()
2635 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2637 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2638 policy->min, policy->max); in cpufreq_set_policy()
2640 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2641 policy->policy = new_pol; in cpufreq_set_policy()
2643 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2646 if (new_gov == policy->governor) { in cpufreq_set_policy()
2655 old_gov = policy->governor; in cpufreq_set_policy()
2663 policy->governor = new_gov; in cpufreq_set_policy()
2675 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2676 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2678 policy->governor = old_gov; in cpufreq_set_policy()
2680 policy->governor = NULL; in cpufreq_set_policy()
2689 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2690 * @cpu: CPU to re-evaluate the policy for.
2693 * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2694 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2705 * BIOS might change freq behind our back in cpufreq_update_policy()
2706 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2708 if (cpufreq_driver->get && has_target() && in cpufreq_update_policy()
2720 * cpufreq_update_limits - Update policy limits for a given CPU.
2723 * Invoke the driver's ->update_limits callback if present or call
2728 if (cpufreq_driver->update_limits) in cpufreq_update_limits()
2729 cpufreq_driver->update_limits(cpu); in cpufreq_update_limits()
2736 * BOOST *
2742 if (!policy->freq_table) in cpufreq_boost_set_sw()
2743 return -ENXIO; in cpufreq_boost_set_sw()
2745 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2751 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2764 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2768 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2773 policy->boost_enabled = state; in cpufreq_boost_trigger_state()
2774 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()
2776 policy->boost_enabled = !policy->boost_enabled; in cpufreq_boost_trigger_state()
2788 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2791 pr_err("%s: Cannot %s BOOST\n", in cpufreq_boost_trigger_state()
2799 return cpufreq_driver->set_boost; in cpufreq_boost_supported()
2806 ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr); in create_boost_sysfs_file()
2808 pr_err("%s: cannot register global BOOST sysfs file\n", in create_boost_sysfs_file()
2817 sysfs_remove_file(cpufreq_global_kobject, &boost.attr); in remove_boost_sysfs_file()
2823 return -EINVAL; in cpufreq_enable_boost_support()
2828 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2837 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2861 * cpufreq_register_driver - register a CPU Frequency driver
2866 * returns zero on success, -EEXIST when another driver got here first
2876 return -ENODEV; in cpufreq_register_driver()
2883 return -EPROBE_DEFER; in cpufreq_register_driver()
2885 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2886 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2887 driver_data->target) || in cpufreq_register_driver()
2888 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2889 driver_data->target)) || in cpufreq_register_driver()
2890 (!driver_data->get_intermediate != !driver_data->target_intermediate) || in cpufreq_register_driver()
2891 (!driver_data->online != !driver_data->offline) || in cpufreq_register_driver()
2892 (driver_data->adjust_perf && !driver_data->fast_switch)) in cpufreq_register_driver()
2893 return -EINVAL; in cpufreq_register_driver()
2895 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2903 ret = -EEXIST; in cpufreq_register_driver()
2913 if (!cpufreq_driver->setpolicy) { in cpufreq_register_driver()
2918 if (driver_data->setpolicy) in cpufreq_register_driver()
2919 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2932 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2933 ret = -ENODEV; in cpufreq_register_driver()
2935 driver_data->name); in cpufreq_register_driver()
2948 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2966 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2970 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2980 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
3004 return -ENODEV; in cpufreq_core_init()
3008 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &dev_root->kobj); in cpufreq_core_init()
3014 strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); in cpufreq_core_init()