Lines Matching +full:performance +full:- +full:affecting
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()
108 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); in have_governor_per_policy()
117 return &policy->kobj; in get_governor_parent_kobj()
141 idle_time = cur_wall_time - busy_time; in get_cpu_idle_time_jiffy()
152 if (idle_time == -1ULL) in get_cpu_idle_time()
164 * - validate & show freq table passed
165 * - set policies transition latency
166 * - policy->cpus with all possible CPUs
172 policy->freq_table = table; in cpufreq_generic_init()
173 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
179 cpumask_setall(policy->cpus); in cpufreq_generic_init()
187 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
195 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
201 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
206 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
231 kobject_get(&policy->kobj); in cpufreq_cpu_get()
241 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
246 kobject_put(&policy->kobj); in cpufreq_cpu_put()
251 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
259 lockdep_assert_held(&policy->rwsem); in cpufreq_cpu_release()
261 up_write(&policy->rwsem); in cpufreq_cpu_release()
267 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
285 down_write(&policy->rwsem); in cpufreq_cpu_acquire()
296 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
300 * adjust_jiffies - Adjust the system "loops_per_jiffy".
307 * per-CPU loops_per_jiffy value wherever possible.
315 if (ci->flags & CPUFREQ_CONST_LOOPS) in adjust_jiffies()
320 l_p_j_ref_freq = ci->old; in adjust_jiffies()
324 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) { in adjust_jiffies()
326 ci->new); in adjust_jiffies()
328 loops_per_jiffy, ci->new); in adjust_jiffies()
334 * cpufreq_notify_transition - Notify frequency transition and adjust jiffies.
354 freqs->policy = policy; in cpufreq_notify_transition()
355 freqs->flags = cpufreq_driver->flags; in cpufreq_notify_transition()
357 state, freqs->new); in cpufreq_notify_transition()
366 if (policy->cur && policy->cur != freqs->old) { in cpufreq_notify_transition()
368 freqs->old, policy->cur); in cpufreq_notify_transition()
369 freqs->old = policy->cur; in cpufreq_notify_transition()
380 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, in cpufreq_notify_transition()
381 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
383 for_each_cpu(cpu, policy->cpus) in cpufreq_notify_transition()
384 trace_cpu_frequency(freqs->new, cpu); in cpufreq_notify_transition()
389 cpufreq_stats_record_transition(policy, freqs->new); in cpufreq_notify_transition()
390 policy->cur = freqs->new; in cpufreq_notify_transition()
402 swap(freqs->old, freqs->new); in cpufreq_notify_post_transition()
412 * Catch double invocations of _begin() which lead to self-deadlock. in cpufreq_freq_transition_begin()
416 * where these checks can emit false-positive warnings in these in cpufreq_freq_transition_begin()
419 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION) in cpufreq_freq_transition_begin()
420 && current == policy->transition_task); in cpufreq_freq_transition_begin()
423 wait_event(policy->transition_wait, !policy->transition_ongoing); in cpufreq_freq_transition_begin()
425 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_begin()
427 if (unlikely(policy->transition_ongoing)) { in cpufreq_freq_transition_begin()
428 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
432 policy->transition_ongoing = true; in cpufreq_freq_transition_begin()
433 policy->transition_task = current; in cpufreq_freq_transition_begin()
435 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
444 if (WARN_ON(!policy->transition_ongoing)) in cpufreq_freq_transition_end()
449 arch_set_freq_scale(policy->related_cpus, in cpufreq_freq_transition_end()
450 policy->cur, in cpufreq_freq_transition_end()
451 policy->cpuinfo.max_freq); in cpufreq_freq_transition_end()
453 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
454 policy->transition_task = NULL; in cpufreq_freq_transition_end()
456 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
475 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) in cpufreq_list_transition_notifiers()
476 pr_info("%pS\n", nb->notifier_call); in cpufreq_list_transition_notifiers()
482 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
494 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
496 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
502 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
505 policy->cpu); in cpufreq_enable_fast_switch()
513 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
519 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
520 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
522 cpufreq_fast_switch_count--; in cpufreq_disable_fast_switch()
533 target_freq = clamp_val(target_freq, policy->min, policy->max); in __resolve_freq()
535 if (!policy->freq_table) in __resolve_freq()
539 policy->cached_resolved_idx = idx; in __resolve_freq()
540 policy->cached_target_freq = target_freq; in __resolve_freq()
541 return policy->freq_table[idx].frequency; in __resolve_freq()
545 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
552 * Return: Lowest driver-supported frequency greater than or equal to the
566 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
567 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
569 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
594 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
604 return -EINVAL; in store_boost()
609 return -EINVAL; in store_boost()
624 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
639 if (!try_module_get(t->owner)) in get_governor()
650 if (!strncasecmp(str_governor, "performance", CPUFREQ_NAME_LEN)) in cpufreq_parse_policy()
660 * cpufreq_parse_governor - parse a governor string only for has_target()
678 * cpufreq_per_cpu_attr_read() / show_##file_name() -
681 * Write out information from cpufreq_driver->policy[cpu]; object must be
689 return sprintf(buf, "%u\n", policy->object); \
708 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
711 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) in show_scaling_cur_freq()
712 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
714 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
719 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
730 return -EINVAL; \
732 ret = freq_qos_update_request(policy->object##_freq_req, val);\
740 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
754 * show_scaling_governor - show the current policy for the specified CPU
758 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
760 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
761 return sprintf(buf, "performance\n"); in show_scaling_governor()
762 else if (policy->governor) in show_scaling_governor()
764 policy->governor->name); in show_scaling_governor()
765 return -EINVAL; in show_scaling_governor()
769 * store_scaling_governor - store policy for the specified CPU
779 return -EINVAL; in store_scaling_governor()
781 if (cpufreq_driver->setpolicy) { in store_scaling_governor()
786 return -EINVAL; in store_scaling_governor()
794 return -EINVAL; in store_scaling_governor()
799 module_put(new_gov->owner); in store_scaling_governor()
806 * show_scaling_driver - show the cpufreq driver currently loaded
810 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
814 * show_scaling_available_governors - show the available CPUfreq governors
823 i += sprintf(buf, "performance powersave"); in show_scaling_available_governors()
830 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
832 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); in show_scaling_available_governors()
846 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); in cpufreq_show_cpus()
847 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
852 i--; in cpufreq_show_cpus()
860 * show_related_cpus - show the CPUs affected by each transition even if
865 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
869 * show_affected_cpus - show the CPUs affected by each transition
873 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
882 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
883 return -EINVAL; in store_scaling_setspeed()
887 return -EINVAL; in store_scaling_setspeed()
889 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
896 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
899 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
903 * show_bios_limit - show the current cpufreq HW/BIOS limitation
909 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
912 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
953 ssize_t ret = -EBUSY; in show()
955 if (!fattr->show) in show()
956 return -EIO; in show()
958 down_read(&policy->rwsem); in show()
960 ret = fattr->show(policy, buf); in show()
961 up_read(&policy->rwsem); in show()
971 ssize_t ret = -EBUSY; in store()
973 if (!fattr->store) in store()
974 return -EIO; in store()
976 down_write(&policy->rwsem); in store()
978 ret = fattr->store(policy, buf, count); in store()
979 up_write(&policy->rwsem); in store()
988 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1008 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1012 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1020 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
1021 cpumask_clear_cpu(cpu, policy->real_cpus); in remove_cpu_dev_symlink()
1030 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
1032 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1037 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1038 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1043 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1047 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1048 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1064 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1067 gov->name, policy->cpu); in cpufreq_init_policy()
1074 __module_get(gov->owner); in cpufreq_init_policy()
1080 if (policy->last_policy) { in cpufreq_init_policy()
1081 pol = policy->last_policy; in cpufreq_init_policy()
1085 * In case the default governor is neither "performance" in cpufreq_init_policy()
1090 pol = policy->policy; in cpufreq_init_policy()
1094 return -ENODATA; in cpufreq_init_policy()
1099 module_put(gov->owner); in cpufreq_init_policy()
1109 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1112 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1116 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1123 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1130 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1132 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1142 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1143 down_write(&policy->rwsem); in handle_update()
1145 up_write(&policy->rwsem); in handle_update()
1153 schedule_work(&policy->update); in cpufreq_notifier_min()
1162 schedule_work(&policy->update); in cpufreq_notifier_max()
1171 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1173 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1174 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1175 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1201 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1204 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1207 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1210 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1213 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1219 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1223 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1225 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1226 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1228 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1229 &policy->nb_min); in cpufreq_policy_alloc()
1232 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1236 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1237 &policy->nb_max); in cpufreq_policy_alloc()
1240 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1244 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1245 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1246 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1247 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1248 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1249 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1251 policy->cpu = cpu; in cpufreq_policy_alloc()
1255 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1256 &policy->nb_min); in cpufreq_policy_alloc()
1260 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1262 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1264 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1285 list_del(&policy->policy_list); in cpufreq_policy_free()
1287 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1291 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1292 &policy->nb_max); in cpufreq_policy_free()
1293 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1294 &policy->nb_min); in cpufreq_policy_free()
1296 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1297 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1299 if (policy->max_freq_req) { in cpufreq_policy_free()
1307 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1310 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1311 kfree(policy->min_freq_req); in cpufreq_policy_free()
1314 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1315 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1316 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1333 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1339 down_write(&policy->rwsem); in cpufreq_online()
1340 policy->cpu = cpu; in cpufreq_online()
1341 policy->governor = NULL; in cpufreq_online()
1346 return -ENOMEM; in cpufreq_online()
1347 down_write(&policy->rwsem); in cpufreq_online()
1350 if (!new_policy && cpufreq_driver->online) { in cpufreq_online()
1351 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1352 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1354 ret = cpufreq_driver->online(policy); in cpufreq_online()
1361 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1365 * to accept all calls to ->verify and ->setpolicy for this CPU. in cpufreq_online()
1367 ret = cpufreq_driver->init(policy); in cpufreq_online()
1383 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1384 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1391 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1394 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1399 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1401 if (!policy->min_freq_req) { in cpufreq_online()
1402 ret = -ENOMEM; in cpufreq_online()
1406 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1407 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1414 kfree(policy->min_freq_req); in cpufreq_online()
1415 policy->min_freq_req = NULL; in cpufreq_online()
1424 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1426 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1427 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1430 policy->max_freq_req = NULL; in cpufreq_online()
1438 if (cpufreq_driver->get && has_target()) { in cpufreq_online()
1439 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1440 if (!policy->cur) { in cpufreq_online()
1441 ret = -EIO; in cpufreq_online()
1442 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1452 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1453 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1454 * isn't found in freq-table. in cpufreq_online()
1457 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1461 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1462 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1463 * equal to target-freq. in cpufreq_online()
1465 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1467 unsigned int old_freq = policy->cur; in cpufreq_online()
1471 if (ret == -EINVAL) { in cpufreq_online()
1472 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1482 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1494 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1507 if (cpufreq_driver->register_em) in cpufreq_online()
1508 cpufreq_driver->register_em(policy); in cpufreq_online()
1518 up_write(&policy->rwsem); in cpufreq_online()
1520 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1523 if (cpufreq_driver->ready) in cpufreq_online()
1524 cpufreq_driver->ready(policy); in cpufreq_online()
1527 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1534 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1538 if (cpufreq_driver->offline) in cpufreq_online()
1539 cpufreq_driver->offline(policy); in cpufreq_online()
1542 if (cpufreq_driver->exit) in cpufreq_online()
1543 cpufreq_driver->exit(policy); in cpufreq_online()
1546 cpumask_clear(policy->cpus); in cpufreq_online()
1547 up_write(&policy->rwsem); in cpufreq_online()
1554 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1561 unsigned cpu = dev->id; in cpufreq_add_dev()
1587 cpumask_clear_cpu(cpu, policy->cpus); in __cpufreq_offline()
1591 if (cpu == policy->cpu) in __cpufreq_offline()
1592 policy->cpu = cpumask_any(policy->cpus); in __cpufreq_offline()
1605 strncpy(policy->last_governor, policy->governor->name, in __cpufreq_offline()
1608 policy->last_policy = policy->policy; in __cpufreq_offline()
1611 cpufreq_cooling_unregister(policy->cdev); in __cpufreq_offline()
1612 policy->cdev = NULL; in __cpufreq_offline()
1619 * Perform the ->offline() during light-weight tear-down, as in __cpufreq_offline()
1622 if (cpufreq_driver->offline) { in __cpufreq_offline()
1623 cpufreq_driver->offline(policy); in __cpufreq_offline()
1624 } else if (cpufreq_driver->exit) { in __cpufreq_offline()
1625 cpufreq_driver->exit(policy); in __cpufreq_offline()
1626 policy->freq_table = NULL; in __cpufreq_offline()
1642 down_write(&policy->rwsem); in cpufreq_offline()
1646 up_write(&policy->rwsem); in cpufreq_offline()
1651 * cpufreq_remove_dev - remove a CPU device
1657 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1663 down_write(&policy->rwsem); in cpufreq_remove_dev()
1670 if (!cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1671 up_write(&policy->rwsem); in cpufreq_remove_dev()
1675 /* We did light-weight exit earlier, do full tear down now */ in cpufreq_remove_dev()
1676 if (cpufreq_driver->offline) in cpufreq_remove_dev()
1677 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1679 up_write(&policy->rwsem); in cpufreq_remove_dev()
1685 * cpufreq_out_of_sync - Fix up actual and saved CPU frequency difference.
1698 policy->cur, new_freq); in cpufreq_out_of_sync()
1700 freqs.old = policy->cur; in cpufreq_out_of_sync()
1711 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1717 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1719 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1722 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1730 if (abs(policy->cur - new_freq) < HZ_PER_MHZ) in cpufreq_verify_current_freq()
1731 return policy->cur; in cpufreq_verify_current_freq()
1735 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1742 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1756 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1757 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1766 ret_freq = policy->cur; in cpufreq_quick_get()
1775 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1786 ret_freq = policy->max; in cpufreq_quick_get_max()
1795 * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1806 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1823 * cpufreq_get - get the current CPU frequency (in kHz)
1834 down_read(&policy->rwsem); in cpufreq_get()
1835 if (cpufreq_driver->get) in cpufreq_get()
1837 up_read(&policy->rwsem); in cpufreq_get()
1861 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1866 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1867 policy->suspend_freq); in cpufreq_generic_suspend()
1869 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1872 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1873 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1880 * cpufreq_suspend() - Suspend CPUFreq governors.
1894 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1901 down_write(&policy->rwsem); in cpufreq_suspend()
1903 up_write(&policy->rwsem); in cpufreq_suspend()
1906 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1908 cpufreq_driver->name); in cpufreq_suspend()
1916 * cpufreq_resume() - Resume CPUFreq governors.
1934 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
1940 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1944 down_write(&policy->rwsem); in cpufreq_resume()
1946 up_write(&policy->rwsem); in cpufreq_resume()
1956 * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
1964 return !!(cpufreq_driver->flags & flags); in cpufreq_driver_test_flags()
1968 * cpufreq_get_current_driver - Return the current driver's name.
1976 return cpufreq_driver->name; in cpufreq_get_current_driver()
1983 * cpufreq_get_driver_data - Return current driver data.
1991 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
2002 * cpufreq_register_notifier - Register a notifier with cpufreq.
2018 return -EINVAL; in cpufreq_register_notifier()
2026 return -EBUSY; in cpufreq_register_notifier()
2031 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
2040 ret = -EINVAL; in cpufreq_register_notifier()
2048 * cpufreq_unregister_notifier - Unregister a notifier from cpufreq.
2062 return -EINVAL; in cpufreq_unregister_notifier()
2080 ret = -EINVAL; in cpufreq_unregister_notifier()
2093 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
2099 * The driver's ->fast_switch() callback invoked by this function must be
2100 * suitable for being called from within RCU-sched read-side critical sections
2104 * This function must not be called if policy->fast_switch_enabled is unset.
2108 * parallel with either ->target() or ->target_index() for the same policy.
2112 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
2121 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2122 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2127 policy->cur = freq; in cpufreq_driver_fast_switch()
2128 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2129 policy->cpuinfo.max_freq); in cpufreq_driver_fast_switch()
2133 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2142 * cpufreq_driver_adjust_perf - Adjust CPU performance level in one go.
2144 * @min_perf: Minimum (required) performance level (units of @capacity).
2145 * @target_perf: Target (desired) performance level (units of @capacity).
2148 * Carry out a fast performance level switch of @cpu without sleeping.
2150 * The driver's ->adjust_perf() callback invoked by this function must be
2151 * suitable for being called from within RCU-sched read-side critical sections
2152 * and it is expected to select a suitable performance level equal to or above
2155 * This function must not be called if policy->fast_switch_enabled is unset.
2159 * parallel with either ->target() or ->target_index() or ->fast_switch() for
2167 cpufreq_driver->adjust_perf(cpu, min_perf, target_perf, capacity); in cpufreq_driver_adjust_perf()
2171 * cpufreq_driver_has_adjust_perf - Check "direct fast switch" callback.
2173 * Return 'true' if the ->adjust_perf callback is present for the
2178 return !!cpufreq_driver->adjust_perf; in cpufreq_driver_has_adjust_perf()
2181 /* Must set freqs->new to intermediate frequency */
2187 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2190 if (!freqs->new) in __target_intermediate()
2194 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2197 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2209 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2211 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2212 int retval = -EINVAL; in __target_index()
2215 if (newfreq == policy->cur) in __target_index()
2219 restore_freq = policy->cur; in __target_index()
2221 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
2224 if (cpufreq_driver->get_intermediate) { in __target_index()
2237 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2242 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2274 return -ENODEV; in __cpufreq_driver_target()
2279 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2287 if (target_freq == policy->cur && in __cpufreq_driver_target()
2288 !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) in __cpufreq_driver_target()
2291 if (cpufreq_driver->target) { in __cpufreq_driver_target()
2296 if (!policy->efficiencies_available) in __cpufreq_driver_target()
2299 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2302 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
2303 return -EINVAL; in __cpufreq_driver_target()
2305 return __target_index(policy, policy->cached_resolved_idx); in __cpufreq_driver_target()
2315 down_write(&policy->rwsem); in cpufreq_driver_target()
2319 up_write(&policy->rwsem); in cpufreq_driver_target()
2341 if (!policy->governor) in cpufreq_init_governor()
2342 return -EINVAL; in cpufreq_init_governor()
2345 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2346 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2351 policy->governor->name, gov->name); in cpufreq_init_governor()
2352 policy->governor = gov; in cpufreq_init_governor()
2354 return -EINVAL; in cpufreq_init_governor()
2358 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2359 return -EINVAL; in cpufreq_init_governor()
2361 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2363 if (policy->governor->init) { in cpufreq_init_governor()
2364 ret = policy->governor->init(policy); in cpufreq_init_governor()
2366 module_put(policy->governor->owner); in cpufreq_init_governor()
2371 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2378 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2381 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2383 if (policy->governor->exit) in cpufreq_exit_governor()
2384 policy->governor->exit(policy); in cpufreq_exit_governor()
2386 module_put(policy->governor->owner); in cpufreq_exit_governor()
2396 if (!policy->governor) in cpufreq_start_governor()
2397 return -EINVAL; in cpufreq_start_governor()
2399 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2401 if (cpufreq_driver->get) in cpufreq_start_governor()
2404 if (policy->governor->start) { in cpufreq_start_governor()
2405 ret = policy->governor->start(policy); in cpufreq_start_governor()
2410 if (policy->governor->limits) in cpufreq_start_governor()
2411 policy->governor->limits(policy); in cpufreq_start_governor()
2418 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2421 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2423 if (policy->governor->stop) in cpufreq_stop_governor()
2424 policy->governor->stop(policy); in cpufreq_stop_governor()
2429 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2432 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2434 if (policy->governor->limits) in cpufreq_governor_limits()
2435 policy->governor->limits(policy); in cpufreq_governor_limits()
2443 return -EINVAL; in cpufreq_register_governor()
2446 return -ENODEV; in cpufreq_register_governor()
2450 err = -EBUSY; in cpufreq_register_governor()
2451 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2453 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2475 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2476 policy->governor = NULL; in cpufreq_unregister_governor()
2477 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2483 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2494 * cpufreq_get_policy - get the current cpufreq_policy
2505 return -EINVAL; in cpufreq_get_policy()
2509 return -EINVAL; in cpufreq_get_policy()
2519 * cpufreq_set_policy - Modify cpufreq policy parameters.
2522 * @new_pol: Policy value (for drivers with built-in governors).
2524 * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2526 * values and either invoke the driver's ->setpolicy() callback (if present) or
2528 * ->limits() callback (if @new_gov points to the same object as the one in
2541 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2542 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2543 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2548 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2549 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2551 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2558 ret = cpufreq_driver->verify(&new_data); in cpufreq_set_policy()
2567 policy->min = new_data.min; in cpufreq_set_policy()
2568 policy->max = new_data.max; in cpufreq_set_policy()
2569 policy->min = __resolve_freq(policy, policy->min, CPUFREQ_RELATION_L); in cpufreq_set_policy()
2570 policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H); in cpufreq_set_policy()
2573 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2575 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2576 policy->min, policy->max); in cpufreq_set_policy()
2578 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2579 policy->policy = new_pol; in cpufreq_set_policy()
2581 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2584 if (new_gov == policy->governor) { in cpufreq_set_policy()
2593 old_gov = policy->governor; in cpufreq_set_policy()
2601 policy->governor = new_gov; in cpufreq_set_policy()
2613 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2614 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2616 policy->governor = old_gov; in cpufreq_set_policy()
2618 policy->governor = NULL; in cpufreq_set_policy()
2627 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2628 * @cpu: CPU to re-evaluate the policy for.
2631 * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2632 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2644 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2646 if (cpufreq_driver->get && has_target() && in cpufreq_update_policy()
2658 * cpufreq_update_limits - Update policy limits for a given CPU.
2661 * Invoke the driver's ->update_limits callback if present or call
2666 if (cpufreq_driver->update_limits) in cpufreq_update_limits()
2667 cpufreq_driver->update_limits(cpu); in cpufreq_update_limits()
2680 if (!policy->freq_table) in cpufreq_boost_set_sw()
2681 return -ENXIO; in cpufreq_boost_set_sw()
2683 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2689 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2702 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2706 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2711 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()
2723 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2734 return cpufreq_driver->set_boost; in cpufreq_boost_supported()
2758 return -EINVAL; in cpufreq_enable_boost_support()
2763 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2772 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2796 * cpufreq_register_driver - register a CPU Frequency driver
2801 * returns zero on success, -EEXIST when another driver got here first
2811 return -ENODEV; in cpufreq_register_driver()
2818 return -EPROBE_DEFER; in cpufreq_register_driver()
2820 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2821 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2822 driver_data->target) || in cpufreq_register_driver()
2823 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2824 driver_data->target)) || in cpufreq_register_driver()
2825 (!driver_data->get_intermediate != !driver_data->target_intermediate) || in cpufreq_register_driver()
2826 (!driver_data->online != !driver_data->offline)) in cpufreq_register_driver()
2827 return -EINVAL; in cpufreq_register_driver()
2829 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2837 ret = -EEXIST; in cpufreq_register_driver()
2847 if (!cpufreq_driver->setpolicy) { in cpufreq_register_driver()
2852 if (driver_data->setpolicy) in cpufreq_register_driver()
2853 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2866 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2867 ret = -ENODEV; in cpufreq_register_driver()
2869 driver_data->name); in cpufreq_register_driver()
2882 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2900 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2904 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2912 return -EINVAL; in cpufreq_unregister_driver()
2914 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
2939 return -ENODEV; in cpufreq_core_init()
2941 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); in cpufreq_core_init()
2945 strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); in cpufreq_core_init()