Lines Matching +full:switching +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
58 * The "cpufreq driver" - the arch- or hardware-dependent low
77 return cpufreq_driver->target_index || cpufreq_driver->target; in has_target()
112 return !!(cpufreq_driver->flags & CPUFREQ_HAVE_GOVERNOR_PER_POLICY); in have_governor_per_policy()
121 return &policy->kobj; in get_governor_parent_kobj()
145 idle_time = cur_wall_time - busy_time; in get_cpu_idle_time_jiffy()
156 if (idle_time == -1ULL) in get_cpu_idle_time()
168 * - validate & show freq table passed
169 * - set policies transition latency
170 * - policy->cpus with all possible CPUs
176 policy->freq_table = table; in cpufreq_generic_init()
177 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
183 cpumask_setall(policy->cpus); in cpufreq_generic_init()
191 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
199 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
205 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
210 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
235 kobject_get(&policy->kobj); in cpufreq_cpu_get()
245 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
250 kobject_put(&policy->kobj); in cpufreq_cpu_put()
255 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
263 lockdep_assert_held(&policy->rwsem); in cpufreq_cpu_release()
265 up_write(&policy->rwsem); in cpufreq_cpu_release()
271 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
289 down_write(&policy->rwsem); in cpufreq_cpu_acquire()
304 * adjust_jiffies - adjust the system "loops_per_jiffy"
309 * per-CPU loops_per_jiffy value wherever possible.
317 if (ci->flags & CPUFREQ_CONST_LOOPS) in adjust_jiffies()
322 l_p_j_ref_freq = ci->old; in adjust_jiffies()
323 pr_debug("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", in adjust_jiffies()
326 if (val == CPUFREQ_POSTCHANGE && ci->old != ci->new) { in adjust_jiffies()
328 ci->new); in adjust_jiffies()
330 loops_per_jiffy, ci->new); in adjust_jiffies()
336 * cpufreq_notify_transition - Notify frequency transition and adjust_jiffies.
337 * @policy: cpufreq policy to enable fast frequency switching for.
356 freqs->policy = policy; in cpufreq_notify_transition()
357 freqs->flags = cpufreq_driver->flags; in cpufreq_notify_transition()
359 state, freqs->new); in cpufreq_notify_transition()
368 if (policy->cur && policy->cur != freqs->old) { in cpufreq_notify_transition()
370 freqs->old, policy->cur); in cpufreq_notify_transition()
371 freqs->old = policy->cur; in cpufreq_notify_transition()
382 pr_debug("FREQ: %u - CPUs: %*pbl\n", freqs->new, in cpufreq_notify_transition()
383 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
385 for_each_cpu(cpu, policy->cpus) in cpufreq_notify_transition()
386 trace_cpu_frequency(freqs->new, cpu); in cpufreq_notify_transition()
391 cpufreq_stats_record_transition(policy, freqs->new); in cpufreq_notify_transition()
392 cpufreq_times_record_transition(policy, freqs->new); in cpufreq_notify_transition()
393 policy->cur = freqs->new; in cpufreq_notify_transition()
406 swap(freqs->old, freqs->new); in cpufreq_notify_post_transition()
416 * Catch double invocations of _begin() which lead to self-deadlock. in cpufreq_freq_transition_begin()
420 * where these checks can emit false-positive warnings in these in cpufreq_freq_transition_begin()
423 WARN_ON(!(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION) in cpufreq_freq_transition_begin()
424 && current == policy->transition_task); in cpufreq_freq_transition_begin()
427 wait_event(policy->transition_wait, !policy->transition_ongoing); in cpufreq_freq_transition_begin()
429 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_begin()
431 if (unlikely(policy->transition_ongoing)) { in cpufreq_freq_transition_begin()
432 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
436 policy->transition_ongoing = true; in cpufreq_freq_transition_begin()
437 policy->transition_task = current; in cpufreq_freq_transition_begin()
439 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_begin()
448 if (WARN_ON(!policy->transition_ongoing)) in cpufreq_freq_transition_end()
453 arch_set_freq_scale(policy->related_cpus, in cpufreq_freq_transition_end()
454 policy->cur, in cpufreq_freq_transition_end()
455 policy->cpuinfo.max_freq); in cpufreq_freq_transition_end()
457 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
458 policy->transition_task = NULL; in cpufreq_freq_transition_end()
460 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
465 * Fast frequency switching status count. Positive means "enabled", negative
479 for (nb = cpufreq_transition_notifier_list.head; nb; nb = nb->next) in cpufreq_list_transition_notifiers()
480 pr_info("%pS\n", nb->notifier_call); in cpufreq_list_transition_notifiers()
486 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
487 * @policy: cpufreq policy to enable fast frequency switching for.
489 * Try to enable fast frequency switching for @policy.
492 * at this point, as fast frequency switching is quite fundamentally at odds
498 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
500 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
506 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
508 pr_warn("CPU%u: Fast frequency switching not enabled\n", in cpufreq_enable_fast_switch()
509 policy->cpu); in cpufreq_enable_fast_switch()
517 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
518 * @policy: cpufreq policy to disable fast frequency switching for.
523 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
524 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
526 cpufreq_fast_switch_count--; in cpufreq_disable_fast_switch()
533 * cpufreq_driver_resolve_freq - Map a target frequency to a driver-supported
540 * Return: Lowest driver-supported frequency greater than or equal to the
548 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_resolve_freq()
550 policy->cached_target_freq = target_freq; in cpufreq_driver_resolve_freq()
552 if (cpufreq_driver->target_index) { in cpufreq_driver_resolve_freq()
557 policy->cached_resolved_idx = idx; in cpufreq_driver_resolve_freq()
558 return policy->freq_table[idx].frequency; in cpufreq_driver_resolve_freq()
561 if (cpufreq_driver->resolve_freq) in cpufreq_driver_resolve_freq()
562 return cpufreq_driver->resolve_freq(policy, target_freq); in cpufreq_driver_resolve_freq()
572 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
573 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
575 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
600 return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); in show_boost()
610 return -EINVAL; in store_boost()
615 return -EINVAL; in store_boost()
630 if (!strncasecmp(str_governor, t->name, CPUFREQ_NAME_LEN)) in find_governor()
645 if (!try_module_get(t->owner)) in get_governor()
666 * cpufreq_parse_governor - parse a governor string only for has_target()
684 * cpufreq_per_cpu_attr_read() / show_##file_name() -
687 * Write out information from cpufreq_driver->policy[cpu]; object must be
695 return sprintf(buf, "%u\n", policy->object); \
700 unsigned int max_freq = policy->cpuinfo.max_freq; in show_cpuinfo_max_freq()
720 unsigned int freq; in show_scaling_cur_freq() local
722 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
723 if (freq) in show_scaling_cur_freq()
724 ret = sprintf(buf, "%u\n", freq); in show_scaling_cur_freq()
725 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) in show_scaling_cur_freq()
726 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
728 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
733 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
744 return -EINVAL; \
746 ret = freq_qos_update_request(policy->object##_freq_req, val);\
754 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
768 * show_scaling_governor - show the current policy for the specified CPU
772 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
774 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
776 else if (policy->governor) in show_scaling_governor()
778 policy->governor->name); in show_scaling_governor()
779 return -EINVAL; in show_scaling_governor()
783 * store_scaling_governor - store policy for the specified CPU
793 return -EINVAL; in store_scaling_governor()
795 if (cpufreq_driver->setpolicy) { in store_scaling_governor()
800 return -EINVAL; in store_scaling_governor()
808 return -EINVAL; in store_scaling_governor()
813 module_put(new_gov->owner); in store_scaling_governor()
820 * show_scaling_driver - show the cpufreq driver currently loaded
824 return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name); in show_scaling_driver()
828 * show_scaling_available_governors - show the available CPUfreq governors
844 - (CPUFREQ_NAME_LEN + 2))) in show_scaling_available_governors()
846 i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); in show_scaling_available_governors()
861 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); in cpufreq_show_cpus()
862 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); in cpufreq_show_cpus()
863 if (i >= (PAGE_SIZE - 5)) in cpufreq_show_cpus()
872 * show_related_cpus - show the CPUs affected by each transition even if
877 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
881 * show_affected_cpus - show the CPUs affected by each transition
885 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
891 unsigned int freq = 0; in store_scaling_setspeed() local
894 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
895 return -EINVAL; in store_scaling_setspeed()
897 ret = sscanf(buf, "%u", &freq); in store_scaling_setspeed()
899 return -EINVAL; in store_scaling_setspeed()
901 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
908 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
911 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
915 * show_bios_limit - show the current cpufreq HW/BIOS limitation
921 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
924 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
966 if (!fattr->show) in show()
967 return -EIO; in show()
969 down_read(&policy->rwsem); in show()
970 ret = fattr->show(policy, buf); in show()
971 up_read(&policy->rwsem); in show()
981 ssize_t ret = -EINVAL; in store()
983 if (!fattr->store) in store()
984 return -EIO; in store()
991 return -EBUSY; in store()
993 if (cpu_online(policy->cpu)) { in store()
994 down_write(&policy->rwsem); in store()
995 ret = fattr->store(policy, buf, count); in store()
996 up_write(&policy->rwsem); in store()
1008 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1028 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1032 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1040 sysfs_remove_link(&dev->kobj, "cpufreq"); in remove_cpu_dev_symlink()
1049 drv_attr = cpufreq_driver->attr; in cpufreq_add_dev_interface()
1051 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1056 if (cpufreq_driver->get) { in cpufreq_add_dev_interface()
1057 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1062 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1066 if (cpufreq_driver->bios_limit) { in cpufreq_add_dev_interface()
1067 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1083 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1086 gov->name, policy->cpu); in cpufreq_init_policy()
1093 __module_get(gov->owner); in cpufreq_init_policy()
1099 if (policy->last_policy) { in cpufreq_init_policy()
1100 pol = policy->last_policy; in cpufreq_init_policy()
1109 pol = policy->policy; in cpufreq_init_policy()
1113 return -ENODATA; in cpufreq_init_policy()
1118 module_put(gov->owner); in cpufreq_init_policy()
1128 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1131 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1135 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1142 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1149 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1151 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1161 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1162 down_write(&policy->rwsem); in handle_update()
1164 up_write(&policy->rwsem); in handle_update()
1167 static int cpufreq_notifier_min(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_min() argument
1172 schedule_work(&policy->update); in cpufreq_notifier_min()
1176 static int cpufreq_notifier_max(struct notifier_block *nb, unsigned long freq, in cpufreq_notifier_max() argument
1181 schedule_work(&policy->update); in cpufreq_notifier_max()
1190 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1192 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1193 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1194 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1220 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1223 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1226 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1229 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1232 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1238 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1242 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1244 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1245 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1247 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1248 &policy->nb_min); in cpufreq_policy_alloc()
1251 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1255 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1256 &policy->nb_max); in cpufreq_policy_alloc()
1259 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1263 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1264 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1265 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1266 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1267 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1268 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1270 policy->cpu = cpu; in cpufreq_policy_alloc()
1274 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1275 &policy->nb_min); in cpufreq_policy_alloc()
1279 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1281 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1283 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1297 list_del(&policy->policy_list); in cpufreq_policy_free()
1299 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1303 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1304 &policy->nb_max); in cpufreq_policy_free()
1305 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1306 &policy->nb_min); in cpufreq_policy_free()
1308 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1309 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1311 if (policy->max_freq_req) { in cpufreq_policy_free()
1318 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1321 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1322 kfree(policy->min_freq_req); in cpufreq_policy_free()
1325 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1326 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1327 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1344 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1350 down_write(&policy->rwsem); in cpufreq_online()
1351 policy->cpu = cpu; in cpufreq_online()
1352 policy->governor = NULL; in cpufreq_online()
1353 up_write(&policy->rwsem); in cpufreq_online()
1358 return -ENOMEM; in cpufreq_online()
1361 if (!new_policy && cpufreq_driver->online) { in cpufreq_online()
1362 ret = cpufreq_driver->online(policy); in cpufreq_online()
1369 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1370 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1372 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1376 * to accept all calls to ->verify and ->setpolicy for this CPU. in cpufreq_online()
1378 ret = cpufreq_driver->init(policy); in cpufreq_online()
1394 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1395 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1398 down_write(&policy->rwsem); in cpufreq_online()
1403 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1406 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1411 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1413 if (!policy->min_freq_req) in cpufreq_online()
1416 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1417 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1424 kfree(policy->min_freq_req); in cpufreq_online()
1425 policy->min_freq_req = NULL; in cpufreq_online()
1434 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1436 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1437 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1440 policy->max_freq_req = NULL; in cpufreq_online()
1448 if (cpufreq_driver->get && has_target()) { in cpufreq_online()
1449 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1450 if (!policy->cur) { in cpufreq_online()
1451 pr_err("%s: ->get() failed\n", __func__); in cpufreq_online()
1461 * freq-table. This also makes cpufreq stats inconsistent as in cpufreq_online()
1462 * cpufreq-stats would fail to register because current frequency of CPU in cpufreq_online()
1463 * isn't found in freq-table. in cpufreq_online()
1466 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1467 * otherwise we will end up setting freq to lowest of the table as 'cur' in cpufreq_online()
1470 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1471 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1472 * equal to target-freq. in cpufreq_online()
1474 if ((cpufreq_driver->flags & CPUFREQ_NEED_INITIAL_FREQ_CHECK) in cpufreq_online()
1476 unsigned int old_freq = policy->cur; in cpufreq_online()
1480 if (ret == -EINVAL) { in cpufreq_online()
1481 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1491 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1504 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1515 up_write(&policy->rwsem); in cpufreq_online()
1517 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1520 if (cpufreq_driver->ready) in cpufreq_online()
1521 cpufreq_driver->ready(policy); in cpufreq_online()
1524 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1531 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1534 up_write(&policy->rwsem); in cpufreq_online()
1537 if (cpufreq_driver->offline) in cpufreq_online()
1538 cpufreq_driver->offline(policy); in cpufreq_online()
1541 if (cpufreq_driver->exit) in cpufreq_online()
1542 cpufreq_driver->exit(policy); in cpufreq_online()
1550 * cpufreq_add_dev - the cpufreq interface for a CPU device.
1557 unsigned cpu = dev->id; in cpufreq_add_dev()
1589 down_write(&policy->rwsem); in cpufreq_offline()
1593 cpumask_clear_cpu(cpu, policy->cpus); in cpufreq_offline()
1597 strncpy(policy->last_governor, policy->governor->name, in cpufreq_offline()
1600 policy->last_policy = policy->policy; in cpufreq_offline()
1601 } else if (cpu == policy->cpu) { in cpufreq_offline()
1603 policy->cpu = cpumask_any(policy->cpus); in cpufreq_offline()
1618 cpufreq_cooling_unregister(policy->cdev); in cpufreq_offline()
1619 policy->cdev = NULL; in cpufreq_offline()
1622 if (cpufreq_driver->stop_cpu) in cpufreq_offline()
1623 cpufreq_driver->stop_cpu(policy); in cpufreq_offline()
1629 * Perform the ->offline() during light-weight tear-down, as in cpufreq_offline()
1632 if (cpufreq_driver->offline) { in cpufreq_offline()
1633 cpufreq_driver->offline(policy); in cpufreq_offline()
1634 } else if (cpufreq_driver->exit) { in cpufreq_offline()
1635 cpufreq_driver->exit(policy); in cpufreq_offline()
1636 policy->freq_table = NULL; in cpufreq_offline()
1640 up_write(&policy->rwsem); in cpufreq_offline()
1645 * cpufreq_remove_dev - remove a CPU device
1651 unsigned int cpu = dev->id; in cpufreq_remove_dev()
1660 cpumask_clear_cpu(cpu, policy->real_cpus); in cpufreq_remove_dev()
1663 if (cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1664 /* We did light-weight exit earlier, do full tear down now */ in cpufreq_remove_dev()
1665 if (cpufreq_driver->offline) in cpufreq_remove_dev()
1666 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1673 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're
1687 policy->cur, new_freq); in cpufreq_out_of_sync()
1689 freqs.old = policy->cur; in cpufreq_out_of_sync()
1700 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1705 * If fast frequency switching is used with the given policy, the check in cpufreq_verify_current_freq()
1706 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1708 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1711 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1714 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1721 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1724 * This is the last known freq, without actually getting it from the driver.
1735 if (cpufreq_driver && cpufreq_driver->setpolicy && cpufreq_driver->get) { in cpufreq_quick_get()
1736 ret_freq = cpufreq_driver->get(cpu); in cpufreq_quick_get()
1745 ret_freq = policy->cur; in cpufreq_quick_get()
1754 * cpufreq_quick_get_max - get the max reported CPU frequency for this CPU
1765 ret_freq = policy->max; in cpufreq_quick_get_max()
1774 * cpufreq_get_hw_max_freq - get the max hardware frequency of the CPU
1785 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1802 * cpufreq_get - get the current CPU frequency (in kHz)
1813 down_read(&policy->rwsem); in cpufreq_get()
1814 if (cpufreq_driver->get) in cpufreq_get()
1816 up_read(&policy->rwsem); in cpufreq_get()
1840 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1845 pr_debug("%s: Setting suspend-freq: %u\n", __func__, in cpufreq_generic_suspend()
1846 policy->suspend_freq); in cpufreq_generic_suspend()
1848 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1851 pr_err("%s: unable to set suspend-freq: %u. err: %d\n", in cpufreq_generic_suspend()
1852 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1859 * cpufreq_suspend() - Suspend CPUFreq governors
1873 if (!has_target() && !cpufreq_driver->suspend) in cpufreq_suspend()
1880 down_write(&policy->rwsem); in cpufreq_suspend()
1882 up_write(&policy->rwsem); in cpufreq_suspend()
1885 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1887 cpufreq_driver->name); in cpufreq_suspend()
1895 * cpufreq_resume() - Resume CPUFreq governors
1913 if (!has_target() && !cpufreq_driver->resume) in cpufreq_resume()
1919 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1923 down_write(&policy->rwsem); in cpufreq_resume()
1925 up_write(&policy->rwsem); in cpufreq_resume()
1935 * cpufreq_driver_test_flags - Test cpufreq driver's flags against given ones.
1943 return !!(cpufreq_driver->flags & flags); in cpufreq_driver_test_flags()
1947 * cpufreq_get_current_driver - return current driver's name
1955 return cpufreq_driver->name; in cpufreq_get_current_driver()
1962 * cpufreq_get_driver_data - return current driver data
1970 return cpufreq_driver->driver_data; in cpufreq_get_driver_data()
1981 * cpufreq_register_notifier - register a driver with cpufreq
1998 return -EINVAL; in cpufreq_register_notifier()
2006 return -EBUSY; in cpufreq_register_notifier()
2011 cpufreq_fast_switch_count--; in cpufreq_register_notifier()
2020 ret = -EINVAL; in cpufreq_register_notifier()
2028 * cpufreq_unregister_notifier - unregister a driver with cpufreq
2042 return -EINVAL; in cpufreq_unregister_notifier()
2060 ret = -EINVAL; in cpufreq_unregister_notifier()
2073 * cpufreq_driver_fast_switch - Carry out a fast CPU frequency switch.
2079 * The driver's ->fast_switch() callback invoked by this function must be
2080 * suitable for being called from within RCU-sched read-side critical sections
2084 * This function must not be called if policy->fast_switch_enabled is unset.
2088 * parallel with either ->target() or ->target_index() for the same policy.
2092 * If 0 is returned by the driver's ->fast_switch() callback to indicate an
2098 unsigned int freq; in cpufreq_driver_fast_switch() local
2102 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2104 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2106 if (!freq) in cpufreq_driver_fast_switch()
2109 policy->cur = freq; in cpufreq_driver_fast_switch()
2110 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2111 policy->cpuinfo.max_freq); in cpufreq_driver_fast_switch()
2112 cpufreq_stats_record_transition(policy, freq); in cpufreq_driver_fast_switch()
2113 cpufreq_times_record_transition(policy, freq); in cpufreq_driver_fast_switch()
2117 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2118 trace_cpu_frequency(freq, cpu); in cpufreq_driver_fast_switch()
2121 return freq; in cpufreq_driver_fast_switch()
2125 /* Must set freqs->new to intermediate frequency */
2131 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2133 /* We don't need to switch to intermediate freq */ in __target_intermediate()
2134 if (!freqs->new) in __target_intermediate()
2137 pr_debug("%s: cpu: %d, switching to intermediate freq: oldfreq: %u, intermediate freq: %u\n", in __target_intermediate()
2138 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2141 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2153 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2155 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2156 int retval = -EINVAL; in __target_index()
2159 if (newfreq == policy->cur) in __target_index()
2162 notify = !(cpufreq_driver->flags & CPUFREQ_ASYNC_NOTIFICATION); in __target_index()
2164 /* Handle switching to intermediate frequency */ in __target_index()
2165 if (cpufreq_driver->get_intermediate) { in __target_index()
2171 /* Set old freq to intermediate */ in __target_index()
2177 pr_debug("%s: cpu: %d, oldfreq: %u, new freq: %u\n", in __target_index()
2178 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2183 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2192 * Failed after setting to intermediate freq? Driver should have in __target_index()
2195 * case we haven't switched to intermediate freq at all. in __target_index()
2199 freqs.new = policy->restore_freq; in __target_index()
2216 return -ENODEV; in __cpufreq_driver_target()
2219 target_freq = clamp_val(target_freq, policy->min, policy->max); in __cpufreq_driver_target()
2223 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2228 * exactly same freq is called again and so we can save on few function in __cpufreq_driver_target()
2231 if (target_freq == policy->cur && in __cpufreq_driver_target()
2232 !(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS)) in __cpufreq_driver_target()
2236 policy->restore_freq = policy->cur; in __cpufreq_driver_target()
2238 if (cpufreq_driver->target) in __cpufreq_driver_target()
2239 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2241 if (!cpufreq_driver->target_index) in __cpufreq_driver_target()
2242 return -EINVAL; in __cpufreq_driver_target()
2256 down_write(&policy->rwsem); in cpufreq_driver_target()
2260 up_write(&policy->rwsem); in cpufreq_driver_target()
2282 if (!policy->governor) in cpufreq_init_governor()
2283 return -EINVAL; in cpufreq_init_governor()
2285 /* Platform doesn't want dynamic frequency switching ? */ in cpufreq_init_governor()
2286 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2287 cpufreq_driver->flags & CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING) { in cpufreq_init_governor()
2291 pr_warn("Can't use %s governor as dynamic switching is disallowed. Fallback to %s governor\n", in cpufreq_init_governor()
2292 policy->governor->name, gov->name); in cpufreq_init_governor()
2293 policy->governor = gov; in cpufreq_init_governor()
2295 return -EINVAL; in cpufreq_init_governor()
2299 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2300 return -EINVAL; in cpufreq_init_governor()
2302 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2304 if (policy->governor->init) { in cpufreq_init_governor()
2305 ret = policy->governor->init(policy); in cpufreq_init_governor()
2307 module_put(policy->governor->owner); in cpufreq_init_governor()
2312 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2319 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2322 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2324 if (policy->governor->exit) in cpufreq_exit_governor()
2325 policy->governor->exit(policy); in cpufreq_exit_governor()
2327 module_put(policy->governor->owner); in cpufreq_exit_governor()
2337 if (!policy->governor) in cpufreq_start_governor()
2338 return -EINVAL; in cpufreq_start_governor()
2340 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2342 if (cpufreq_driver->get) in cpufreq_start_governor()
2345 if (policy->governor->start) { in cpufreq_start_governor()
2346 ret = policy->governor->start(policy); in cpufreq_start_governor()
2351 if (policy->governor->limits) in cpufreq_start_governor()
2352 policy->governor->limits(policy); in cpufreq_start_governor()
2359 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2362 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2364 if (policy->governor->stop) in cpufreq_stop_governor()
2365 policy->governor->stop(policy); in cpufreq_stop_governor()
2370 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2373 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2375 if (policy->governor->limits) in cpufreq_governor_limits()
2376 policy->governor->limits(policy); in cpufreq_governor_limits()
2384 return -EINVAL; in cpufreq_register_governor()
2387 return -ENODEV; in cpufreq_register_governor()
2391 err = -EBUSY; in cpufreq_register_governor()
2392 if (!find_governor(governor->name)) { in cpufreq_register_governor()
2394 list_add(&governor->governor_list, &cpufreq_governor_list); in cpufreq_register_governor()
2416 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2417 policy->governor = NULL; in cpufreq_unregister_governor()
2418 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2424 list_del(&governor->governor_list); in cpufreq_unregister_governor()
2435 * cpufreq_get_policy - get the current cpufreq_policy
2446 return -EINVAL; in cpufreq_get_policy()
2450 return -EINVAL; in cpufreq_get_policy()
2460 * cpufreq_set_policy - Modify cpufreq policy parameters.
2463 * @new_pol: Policy value (for drivers with built-in governors).
2465 * Invoke the cpufreq driver's ->verify() callback to sanity-check the frequency
2467 * values and either invoke the driver's ->setpolicy() callback (if present) or
2469 * ->limits() callback (if @new_gov points to the same object as the one in
2482 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2483 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2484 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2489 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2490 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2492 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2499 ret = cpufreq_driver->verify(&new_data); in cpufreq_set_policy()
2503 policy->min = new_data.min; in cpufreq_set_policy()
2504 policy->max = new_data.max; in cpufreq_set_policy()
2507 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2509 pr_debug("new min and max freqs are %u - %u kHz\n", in cpufreq_set_policy()
2510 policy->min, policy->max); in cpufreq_set_policy()
2512 if (cpufreq_driver->setpolicy) { in cpufreq_set_policy()
2513 policy->policy = new_pol; in cpufreq_set_policy()
2515 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2518 if (new_gov == policy->governor) { in cpufreq_set_policy()
2527 old_gov = policy->governor; in cpufreq_set_policy()
2535 policy->governor = new_gov; in cpufreq_set_policy()
2546 /* new governor failed, so re-start old one */ in cpufreq_set_policy()
2547 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2549 policy->governor = old_gov; in cpufreq_set_policy()
2551 policy->governor = NULL; in cpufreq_set_policy()
2561 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2562 * @cpu: CPU to re-evaluate the policy for.
2565 * cpufreq_set_policy() to re-apply the min and max limits, which triggers the
2566 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2577 * BIOS might change freq behind our back in cpufreq_update_policy()
2578 * -> ask driver for current freq and notify governors about a change in cpufreq_update_policy()
2580 if (cpufreq_driver->get && has_target() && in cpufreq_update_policy()
2592 * cpufreq_update_limits - Update policy limits for a given CPU.
2595 * Invoke the driver's ->update_limits callback if present or call
2600 if (cpufreq_driver->update_limits) in cpufreq_update_limits()
2601 cpufreq_driver->update_limits(cpu); in cpufreq_update_limits()
2614 if (!policy->freq_table) in cpufreq_boost_set_sw()
2615 return -ENXIO; in cpufreq_boost_set_sw()
2617 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2623 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2636 if (cpufreq_driver->boost_enabled == state) in cpufreq_boost_trigger_state()
2640 cpufreq_driver->boost_enabled = state; in cpufreq_boost_trigger_state()
2645 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()
2657 cpufreq_driver->boost_enabled = !state; in cpufreq_boost_trigger_state()
2668 return cpufreq_driver->set_boost; in cpufreq_boost_supported()
2692 return -EINVAL; in cpufreq_enable_boost_support()
2697 cpufreq_driver->set_boost = cpufreq_boost_set_sw; in cpufreq_enable_boost_support()
2706 return cpufreq_driver->boost_enabled; in cpufreq_boost_enabled()
2730 * cpufreq_register_driver - register a CPU Frequency driver
2735 * returns zero on success, -EEXIST when another driver got here first
2745 return -ENODEV; in cpufreq_register_driver()
2752 return -EPROBE_DEFER; in cpufreq_register_driver()
2754 if (!driver_data || !driver_data->verify || !driver_data->init || in cpufreq_register_driver()
2755 !(driver_data->setpolicy || driver_data->target_index || in cpufreq_register_driver()
2756 driver_data->target) || in cpufreq_register_driver()
2757 (driver_data->setpolicy && (driver_data->target_index || in cpufreq_register_driver()
2758 driver_data->target)) || in cpufreq_register_driver()
2759 (!driver_data->get_intermediate != !driver_data->target_intermediate) || in cpufreq_register_driver()
2760 (!driver_data->online != !driver_data->offline)) in cpufreq_register_driver()
2761 return -EINVAL; in cpufreq_register_driver()
2763 pr_debug("trying to register driver %s\n", driver_data->name); in cpufreq_register_driver()
2771 ret = -EEXIST; in cpufreq_register_driver()
2781 if (!cpufreq_driver->setpolicy) { in cpufreq_register_driver()
2786 if (driver_data->setpolicy) in cpufreq_register_driver()
2787 driver_data->flags |= CPUFREQ_CONST_LOOPS; in cpufreq_register_driver()
2799 if (!(cpufreq_driver->flags & CPUFREQ_STICKY) && in cpufreq_register_driver()
2801 /* if all ->init() calls failed, unregister */ in cpufreq_register_driver()
2802 ret = -ENODEV; in cpufreq_register_driver()
2804 driver_data->name); in cpufreq_register_driver()
2817 pr_debug("driver %s up and running\n", driver_data->name); in cpufreq_register_driver()
2835 * cpufreq_unregister_driver - unregister the current CPUFreq driver
2839 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
2847 return -EINVAL; in cpufreq_unregister_driver()
2849 pr_debug("unregistering driver %s\n", driver->name); in cpufreq_unregister_driver()
2874 return -ENODEV; in cpufreq_core_init()
2876 cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj); in cpufreq_core_init()
2880 strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); in cpufreq_core_init()