Lines Matching +full:boost +full:- +full:max +full:- +full:current

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()
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()
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 arch_scale_freq_ref(policy->cpu)); 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
561 * given target_freq, subject to policy (min/max) and driver limitations.
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()
592 return sysfs_emit(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
601 return -EINVAL; in store_boost()
604 pr_err("%s: Cannot %s BOOST!\n", in store_boost()
606 return -EINVAL; in store_boost()
609 pr_debug("%s: cpufreq BOOST %s\n", in store_boost()
614 define_one_global_rw(boost);
618 return sysfs_emit(buf, "%d\n", policy->boost_enabled); in show_local_boost()
628 return -EINVAL; in store_local_boost()
630 if (!cpufreq_driver->boost_enabled) in store_local_boost()
631 return -EINVAL; in store_local_boost()
633 if (policy->boost_enabled == enable) in store_local_boost()
636 policy->boost_enabled = enable; in store_local_boost()
639 ret = cpufreq_driver->set_boost(policy, enable); in store_local_boost()
643 policy->boost_enabled = !policy->boost_enabled; in store_local_boost()
650 static struct freq_attr local_boost = __ATTR(boost, 0644, show_local_boost, store_local_boost);
657 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
672 if (!try_module_get(t->owner)) in get_governor()
693 * cpufreq_parse_governor - parse a governor string only for has_target()
711 * cpufreq_per_cpu_attr_read() / show_##file_name() -
714 * Write out information from cpufreq_driver->policy[cpu]; object must be
722 return sysfs_emit(buf, "%u\n", policy->object); \
729 show_one(scaling_max_freq, max);
741 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
744 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) in show_scaling_cur_freq()
745 ret = sysfs_emit(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
747 ret = sysfs_emit(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
752 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
765 ret = freq_qos_update_request(policy->object##_freq_req, val);\
770 store_one(scaling_max_freq, max);
773 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
787 * show_scaling_governor - show the current policy for the specified CPU
791 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
793 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
795 else if (policy->governor) in show_scaling_governor()
796 return sysfs_emit(buf, "%s\n", policy->governor->name); in show_scaling_governor()
797 return -EINVAL; in show_scaling_governor()
801 * store_scaling_governor - store policy for the specified CPU
811 return -EINVAL; in store_scaling_governor()
813 if (cpufreq_driver->setpolicy) { in store_scaling_governor()
818 return -EINVAL; in store_scaling_governor()
826 return -EINVAL; in store_scaling_governor()
831 module_put(new_gov->owner); in store_scaling_governor()
838 * show_scaling_driver - show the cpufreq driver currently loaded
842 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
846 * show_scaling_available_governors - show the available CPUfreq governors
862 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
864 i += sysfs_emit_at(buf, i, "%s ", t->name); in show_scaling_available_governors()
879 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
884 i--; in cpufreq_show_cpus()
892 * show_related_cpus - show the CPUs affected by each transition even if
897 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
901 * show_affected_cpus - show the CPUs affected by each transition
905 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
914 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
915 return -EINVAL; in store_scaling_setspeed()
919 return -EINVAL; in store_scaling_setspeed()
921 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
928 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
931 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
935 * show_bios_limit - show the current cpufreq HW/BIOS limitation
941 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
944 return sysfs_emit(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
985 ssize_t ret = -EBUSY; in show()
987 if (!fattr->show) in show()
988 return -EIO; in show()
990 down_read(&policy->rwsem); in show()
992 ret = fattr->show(policy, buf); in show()
993 up_read(&policy->rwsem); in show()
1003 ssize_t ret = -EBUSY; in store()
1005 if (!fattr->store) in store()
1006 return -EIO; in store()
1008 down_write(&policy->rwsem); in store()
1010 ret = fattr->store(policy, buf, count); in store()
1011 up_write(&policy->rwsem); in store()
1020 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1040 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1044 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1052 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
1053 cpumask_clear_cpu(cpu, policy->real_cpus); in remove_cpu_dev_symlink()
1062 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
1064 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1069 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1070 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1075 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1079 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1080 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1086 ret = sysfs_create_file(&policy->kobj, &local_boost.attr); in cpufreq_add_dev_interface()
1102 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1105 gov->name, policy->cpu); in cpufreq_init_policy()
1112 __module_get(gov->owner); in cpufreq_init_policy()
1118 if (policy->last_policy) { in cpufreq_init_policy()
1119 pol = policy->last_policy; in cpufreq_init_policy()
1128 pol = policy->policy; in cpufreq_init_policy()
1132 return -ENODATA; in cpufreq_init_policy()
1137 module_put(gov->owner); in cpufreq_init_policy()
1147 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1150 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1154 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1161 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1168 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1170 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1180 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1181 down_write(&policy->rwsem); in handle_update()
1183 up_write(&policy->rwsem); in handle_update()
1191 schedule_work(&policy->update); in cpufreq_notifier_min()
1200 schedule_work(&policy->update); in cpufreq_notifier_max()
1209 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1211 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1212 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1213 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1239 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1242 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1245 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1248 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1249 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1252 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1258 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1262 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1264 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1265 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1267 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1268 &policy->nb_min); in cpufreq_policy_alloc()
1275 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1276 &policy->nb_max); in cpufreq_policy_alloc()
1278 dev_err(dev, "Failed to register MAX QoS notifier: %d (CPU%u)\n", in cpufreq_policy_alloc()
1283 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1284 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1285 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1286 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1287 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1289 policy->cpu = cpu; in cpufreq_policy_alloc()
1293 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1294 &policy->nb_min); in cpufreq_policy_alloc()
1298 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1300 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1302 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1323 list_del(&policy->policy_list); in cpufreq_policy_free()
1325 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1329 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1330 &policy->nb_max); in cpufreq_policy_free()
1331 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1332 &policy->nb_min); in cpufreq_policy_free()
1334 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1335 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1337 if (policy->max_freq_req) { in cpufreq_policy_free()
1345 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1348 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1349 kfree(policy->min_freq_req); in cpufreq_policy_free()
1352 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1353 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1354 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1371 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1377 down_write(&policy->rwsem); in cpufreq_online()
1378 policy->cpu = cpu; in cpufreq_online()
1379 policy->governor = NULL; in cpufreq_online()
1384 return -ENOMEM; in cpufreq_online()
1385 down_write(&policy->rwsem); in cpufreq_online()
1388 if (!new_policy && cpufreq_driver->online) { in cpufreq_online()
1389 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1390 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1392 ret = cpufreq_driver->online(policy); in cpufreq_online()
1399 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1403 * to accept all calls to ->verify and ->setpolicy for this CPU. in cpufreq_online()
1405 ret = cpufreq_driver->init(policy); in cpufreq_online()
1412 /* Let the per-policy boost flag mirror the cpufreq_driver boost during init */ in cpufreq_online()
1414 policy->boost_enabled = true; in cpufreq_online()
1425 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1426 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1433 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1436 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1441 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1443 if (!policy->min_freq_req) { in cpufreq_online()
1444 ret = -ENOMEM; in cpufreq_online()
1448 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1449 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1456 kfree(policy->min_freq_req); in cpufreq_online()
1457 policy->min_freq_req = NULL; in cpufreq_online()
1466 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1468 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1469 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1472 policy->max_freq_req = NULL; in cpufreq_online()
1480 if (cpufreq_driver->get && has_target()) { in cpufreq_online()
1481 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1482 if (!policy->cur) { in cpufreq_online()
1483 ret = -EIO; in cpufreq_online()
1484 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1494 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1495 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1496 * isn't found in freq-table. in cpufreq_online()
1499 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1503 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1504 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1505 * equal to target-freq. in cpufreq_online()
1507 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1509 unsigned int old_freq = policy->cur; in cpufreq_online()
1513 if (ret == -EINVAL) { in cpufreq_online()
1514 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1524 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1536 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1549 if (cpufreq_driver->register_em) in cpufreq_online()
1550 cpufreq_driver->register_em(policy); in cpufreq_online()
1560 up_write(&policy->rwsem); in cpufreq_online()
1562 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1565 if (cpufreq_driver->ready) in cpufreq_online()
1566 cpufreq_driver->ready(policy); in cpufreq_online()
1570 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1577 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1581 if (cpufreq_driver->offline) in cpufreq_online()
1582 cpufreq_driver->offline(policy); in cpufreq_online()
1585 if (cpufreq_driver->exit) in cpufreq_online()
1586 cpufreq_driver->exit(policy); in cpufreq_online()
1589 cpumask_clear(policy->cpus); in cpufreq_online()
1590 up_write(&policy->rwsem); in cpufreq_online()
1597 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1604 unsigned cpu = dev->id; in cpufreq_add_dev()
1630 cpumask_clear_cpu(cpu, policy->cpus); in __cpufreq_offline()
1634 if (cpu == policy->cpu) in __cpufreq_offline()
1635 policy->cpu = cpumask_any(policy->cpus); in __cpufreq_offline()
1648 strscpy(policy->last_governor, policy->governor->name, in __cpufreq_offline()
1651 policy->last_policy = policy->policy; in __cpufreq_offline()
1657 * Perform the ->offline() during light-weight tear-down, as in __cpufreq_offline()
1660 if (cpufreq_driver->offline) { in __cpufreq_offline()
1661 cpufreq_driver->offline(policy); in __cpufreq_offline()
1665 if (cpufreq_driver->exit) in __cpufreq_offline()
1666 cpufreq_driver->exit(policy); in __cpufreq_offline()
1668 policy->freq_table = NULL; in __cpufreq_offline()
1683 down_write(&policy->rwsem); in cpufreq_offline()
1687 up_write(&policy->rwsem); in cpufreq_offline()
1692 * cpufreq_remove_dev - remove a CPU device
1698 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1704 down_write(&policy->rwsem); in cpufreq_remove_dev()
1711 if (!cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1712 up_write(&policy->rwsem); in cpufreq_remove_dev()
1721 cpufreq_cooling_unregister(policy->cdev); in cpufreq_remove_dev()
1722 policy->cdev = NULL; in cpufreq_remove_dev()
1725 /* We did light-weight exit earlier, do full tear down now */ in cpufreq_remove_dev()
1726 if (cpufreq_driver->offline && cpufreq_driver->exit) in cpufreq_remove_dev()
1727 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1729 up_write(&policy->rwsem); in cpufreq_remove_dev()
1735 * cpufreq_out_of_sync - Fix up actual and saved CPU frequency difference.
1739 * Adjust to the current frequency first and clean up later by either calling
1748 policy->cur, new_freq); in cpufreq_out_of_sync()
1750 freqs.old = policy->cur; in cpufreq_out_of_sync()
1761 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1767 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1769 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1772 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1780 if (abs(policy->cur - new_freq) < KHZ_PER_MHZ) in cpufreq_verify_current_freq()
1781 return policy->cur; in cpufreq_verify_current_freq()
1785 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1792 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1806 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1807 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1816 ret_freq = policy->cur; in cpufreq_quick_get()
1825 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1828 * Just return the max possible frequency for a given CPU.
1836 ret_freq = policy->max; in cpufreq_quick_get_max()
1845 * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1856 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1873 * cpufreq_get - get the current CPU frequency (in kHz)
1876 * Get the CPU current (static) CPU frequency
1884 down_read(&policy->rwsem); in cpufreq_get()
1885 if (cpufreq_driver->get) in cpufreq_get()
1887 up_read(&policy->rwsem); in cpufreq_get()
1911 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1916 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1917 policy->suspend_freq); in cpufreq_generic_suspend()
1919 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1922 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1923 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1930 * cpufreq_suspend() - Suspend CPUFreq governors.
1944 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1951 down_write(&policy->rwsem); in cpufreq_suspend()
1953 up_write(&policy->rwsem); in cpufreq_suspend()
1956 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1958 cpufreq_driver->name); in cpufreq_suspend()
1966 * cpufreq_resume() - Resume CPUFreq governors.
1984 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
1990 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1992 cpufreq_driver->name); in cpufreq_resume()
1994 down_write(&policy->rwsem); in cpufreq_resume()
1996 up_write(&policy->rwsem); in cpufreq_resume()
2000 __func__, policy->cpu); in cpufreq_resume()
2006 * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
2007 * @flags: Flags to test against the current cpufreq driver's flags.
2014 return !!(cpufreq_driver->flags & flags); in cpufreq_driver_test_flags()
2018 * cpufreq_get_current_driver - Return the current driver's name.
2026 return cpufreq_driver->name; in cpufreq_get_current_driver()
2033 * cpufreq_get_driver_data - Return current driver data.
2041 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
2052 * cpufreq_register_notifier - Register a notifier with cpufreq.
2068 return -EINVAL; in cpufreq_register_notifier()
2076 return -EBUSY; in cpufreq_register_notifier()
2081 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
2090 ret = -EINVAL; in cpufreq_register_notifier()
2098 * cpufreq_unregister_notifier - Unregister a notifier from cpufreq.
2112 return -EINVAL; in cpufreq_unregister_notifier()
2130 ret = -EINVAL; in cpufreq_unregister_notifier()
2143 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
2149 * The driver's ->fast_switch() callback invoked by this function must be
2150 * suitable for being called from within RCU-sched read-side critical sections
2154 * This function must not be called if policy->fast_switch_enabled is unset.
2158 * parallel with either ->target() or ->target_index() for the same policy.
2162 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
2171 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2172 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2177 policy->cur = freq; in cpufreq_driver_fast_switch()
2178 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2179 arch_scale_freq_ref(policy->cpu)); in cpufreq_driver_fast_switch()
2183 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2192 * cpufreq_driver_adjust_perf - Adjust CPU performance level in one go.
2200 * The driver's ->adjust_perf() callback invoked by this function must be
2201 * suitable for being called from within RCU-sched read-side critical sections
2205 * This function must not be called if policy->fast_switch_enabled is unset.
2209 * parallel with either ->target() or ->target_index() or ->fast_switch() for
2217 cpufreq_driver->adjust_perf(cpu, min_perf, target_perf, capacity); in cpufreq_driver_adjust_perf()
2221 * cpufreq_driver_has_adjust_perf - Check "direct fast switch" callback.
2223 * Return 'true' if the ->adjust_perf callback is present for the
2224 * current driver or 'false' otherwise.
2228 return !!cpufreq_driver->adjust_perf; in cpufreq_driver_has_adjust_perf()
2231 /* Must set freqs->new to intermediate frequency */
2237 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2240 if (!freqs->new) in __target_intermediate()
2244 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2247 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2259 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2261 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2262 int retval = -EINVAL; in __target_index()
2265 if (newfreq == policy->cur) in __target_index()
2269 restore_freq = policy->cur; in __target_index()
2271 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
2274 if (cpufreq_driver->get_intermediate) { in __target_index()
2287 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2292 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2324 return -ENODEV; in __cpufreq_driver_target()
2329 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2337 if (target_freq == policy->cur && in __cpufreq_driver_target()
2338 !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) in __cpufreq_driver_target()
2341 if (cpufreq_driver->target) { in __cpufreq_driver_target()
2346 if (!policy->efficiencies_available) in __cpufreq_driver_target()
2349 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2352 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
2353 return -EINVAL; in __cpufreq_driver_target()
2355 return __target_index(policy, policy->cached_resolved_idx); in __cpufreq_driver_target()
2365 down_write(&policy->rwsem); in cpufreq_driver_target()
2369 up_write(&policy->rwsem); in cpufreq_driver_target()
2391 if (!policy->governor) in cpufreq_init_governor()
2392 return -EINVAL; in cpufreq_init_governor()
2395 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2396 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2401 policy->governor->name, gov->name); in cpufreq_init_governor()
2402 policy->governor = gov; in cpufreq_init_governor()
2404 return -EINVAL; in cpufreq_init_governor()
2408 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2409 return -EINVAL; in cpufreq_init_governor()
2411 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2413 if (policy->governor->init) { in cpufreq_init_governor()
2414 ret = policy->governor->init(policy); in cpufreq_init_governor()
2416 module_put(policy->governor->owner); in cpufreq_init_governor()
2421 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2428 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2431 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2433 if (policy->governor->exit) in cpufreq_exit_governor()
2434 policy->governor->exit(policy); in cpufreq_exit_governor()
2436 module_put(policy->governor->owner); in cpufreq_exit_governor()
2446 if (!policy->governor) in cpufreq_start_governor()
2447 return -EINVAL; in cpufreq_start_governor()
2449 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2451 if (cpufreq_driver->get) in cpufreq_start_governor()
2454 if (policy->governor->start) { in cpufreq_start_governor()
2455 ret = policy->governor->start(policy); in cpufreq_start_governor()
2460 if (policy->governor->limits) in cpufreq_start_governor()
2461 policy->governor->limits(policy); in cpufreq_start_governor()
2468 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2471 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2473 if (policy->governor->stop) in cpufreq_stop_governor()
2474 policy->governor->stop(policy); in cpufreq_stop_governor()
2479 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2482 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2484 if (policy->governor->limits) in cpufreq_governor_limits()
2485 policy->governor->limits(policy); in cpufreq_governor_limits()
2493 return -EINVAL; in cpufreq_register_governor()
2496 return -ENODEV; in cpufreq_register_governor()
2500 err = -EBUSY; in cpufreq_register_governor()
2501 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2503 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2525 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2526 policy->governor = NULL; in cpufreq_unregister_governor()
2527 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2533 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2544 * cpufreq_get_policy - get the current cpufreq_policy
2545 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2549 * Reads the current cpufreq policy.
2555 return -EINVAL; in cpufreq_get_policy()
2559 return -EINVAL; in cpufreq_get_policy()
2571 * cpufreq_update_pressure() - Update cpufreq pressure for CPUs
2582 cpu = cpumask_first(policy->related_cpus); in cpufreq_update_pressure()
2584 capped_freq = policy->max; in cpufreq_update_pressure()
2587 * Handle properly the boost frequencies, which should simply clean in cpufreq_update_pressure()
2594 pressure = max_capacity - in cpufreq_update_pressure()
2598 for_each_cpu(cpu, policy->related_cpus) in cpufreq_update_pressure()
2603 * cpufreq_set_policy - Modify cpufreq policy parameters.
2606 * @new_pol: Policy value (for drivers with built-in governors).
2608 * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2610 * values and either invoke the driver's ->setpolicy() callback (if present) or
2611 * carry out a governor update for @policy. That is, run the current governor's
2612 * ->limits() callback (if @new_gov points to the same object as the one in
2625 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2626 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2627 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2632 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2633 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2635 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2636 new_data.cpu, new_data.min, new_data.max); in cpufreq_set_policy()
2640 * that min <= max. in cpufreq_set_policy()
2642 ret = cpufreq_driver->verify(&new_data); in cpufreq_set_policy()
2647 * Resolve policy min/max to available frequencies. It ensures in cpufreq_set_policy()
2651 policy->min = new_data.min; in cpufreq_set_policy()
2652 policy->max = new_data.max; in cpufreq_set_policy()
2653 policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L); in cpufreq_set_policy()
2654 policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H); in cpufreq_set_policy()
2659 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2661 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2662 policy->min, policy->max); in cpufreq_set_policy()
2664 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2665 policy->policy = new_pol; in cpufreq_set_policy()
2667 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2670 if (new_gov == policy->governor) { in cpufreq_set_policy()
2679 old_gov = policy->governor; in cpufreq_set_policy()
2687 policy->governor = new_gov; in cpufreq_set_policy()
2698 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2699 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2701 policy->governor = old_gov; in cpufreq_set_policy()
2703 policy->governor = NULL; in cpufreq_set_policy()
2712 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2713 * @cpu: CPU to re-evaluate the policy for.
2715 * Update the current frequency for the cpufreq policy of @cpu and use
2716 * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2717 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2729 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2731 if (cpufreq_driver->get && has_target() && in cpufreq_update_policy()
2743 * cpufreq_update_limits - Update policy limits for a given CPU.
2746 * Invoke the driver's ->update_limits callback if present or call
2751 if (cpufreq_driver->update_limits) in cpufreq_update_limits()
2752 cpufreq_driver->update_limits(cpu); in cpufreq_update_limits()
2759 * BOOST *
2765 if (!policy->freq_table) in cpufreq_boost_set_sw()
2766 return -ENXIO; in cpufreq_boost_set_sw()
2768 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2774 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2787 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2791 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2796 policy->boost_enabled = state; in cpufreq_boost_trigger_state()
2797 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()
2799 policy->boost_enabled = !policy->boost_enabled; in cpufreq_boost_trigger_state()
2811 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2814 pr_err("%s: Cannot %s BOOST\n", in cpufreq_boost_trigger_state()
2822 return cpufreq_driver->set_boost; in cpufreq_boost_supported()
2829 ret = sysfs_create_file(cpufreq_global_kobject, &boost.attr); in create_boost_sysfs_file()
2831 pr_err("%s: cannot register global BOOST sysfs file\n", in create_boost_sysfs_file()
2840 sysfs_remove_file(cpufreq_global_kobject, &boost.attr); in remove_boost_sysfs_file()
2846 return -EINVAL; in cpufreq_enable_boost_support()
2851 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2860 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2884 * cpufreq_register_driver - register a CPU Frequency driver
2889 * returns zero on success, -EEXIST when another driver got here first
2899 return -ENODEV; in cpufreq_register_driver()
2906 return -EPROBE_DEFER; in cpufreq_register_driver()
2908 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2909 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2910 driver_data->target) || in cpufreq_register_driver()
2911 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2912 driver_data->target)) || in cpufreq_register_driver()
2913 (!driver_data->get_intermediate != !driver_data->target_intermediate) || in cpufreq_register_driver()
2914 (!driver_data->online != !driver_data->offline) || in cpufreq_register_driver()
2915 (driver_data->adjust_perf && !driver_data->fast_switch)) in cpufreq_register_driver()
2916 return -EINVAL; in cpufreq_register_driver()
2918 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2926 ret = -EEXIST; in cpufreq_register_driver()
2936 if (!cpufreq_driver->setpolicy) { in cpufreq_register_driver()
2941 if (driver_data->setpolicy) in cpufreq_register_driver()
2942 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2955 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2956 ret = -ENODEV; in cpufreq_register_driver()
2958 driver_data->name); in cpufreq_register_driver()
2971 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2989 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2991 * Unregister the current CPUFreq driver. Only call this if you have
2993 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
3003 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
3027 return -ENODEV; in cpufreq_core_init()
3031 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &dev_root->kobj); in cpufreq_core_init()
3037 strscpy(default_governor, gov->name, CPUFREQ_NAME_LEN); in cpufreq_core_init()