• Home
  • Raw
  • Download

Lines Matching full:policy

79 static unsigned int __cpufreq_get(struct cpufreq_policy *policy);
80 static int cpufreq_init_governor(struct cpufreq_policy *policy);
81 static void cpufreq_exit_governor(struct cpufreq_policy *policy);
82 static void cpufreq_governor_limits(struct cpufreq_policy *policy);
83 static int cpufreq_set_policy(struct cpufreq_policy *policy,
88 * Two notifier lists: the "policy" list is involved in the
89 * validation process for a new CPU frequency policy; the
116 struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy) in get_governor_parent_kobj() argument
119 return &policy->kobj; in get_governor_parent_kobj()
168 * - policy->cpus with all possible CPUs
170 void cpufreq_generic_init(struct cpufreq_policy *policy, in cpufreq_generic_init() argument
174 policy->freq_table = table; in cpufreq_generic_init()
175 policy->cpuinfo.transition_latency = transition_latency; in cpufreq_generic_init()
181 cpumask_setall(policy->cpus); in cpufreq_generic_init()
187 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); in cpufreq_cpu_get_raw() local
189 return policy && cpumask_test_cpu(cpu, policy->cpus) ? policy : NULL; in cpufreq_cpu_get_raw()
195 struct cpufreq_policy *policy = cpufreq_cpu_get_raw(cpu); in cpufreq_generic_get() local
197 if (!policy || IS_ERR(policy->clk)) { in cpufreq_generic_get()
199 __func__, policy ? "clk" : "policy", cpu); in cpufreq_generic_get()
203 return clk_get_rate(policy->clk) / 1000; in cpufreq_generic_get()
208 * cpufreq_cpu_get - Return policy for a CPU and mark it as busy.
209 * @cpu: CPU to find the policy for.
211 * Call cpufreq_cpu_get_raw() to obtain a cpufreq policy for @cpu and increment
212 * the kobject reference counter of that policy. Return a valid policy on
215 * The policy returned by this function has to be released with the help of
220 struct cpufreq_policy *policy = NULL; in cpufreq_cpu_get() local
231 policy = cpufreq_cpu_get_raw(cpu); in cpufreq_cpu_get()
232 if (policy) in cpufreq_cpu_get()
233 kobject_get(&policy->kobj); in cpufreq_cpu_get()
238 return policy; in cpufreq_cpu_get()
243 * cpufreq_cpu_put - Decrement kobject usage counter for cpufreq policy.
244 * @policy: cpufreq policy returned by cpufreq_cpu_get().
246 void cpufreq_cpu_put(struct cpufreq_policy *policy) in cpufreq_cpu_put() argument
248 kobject_put(&policy->kobj); in cpufreq_cpu_put()
253 * cpufreq_cpu_release - Unlock a policy and decrement its usage counter.
254 * @policy: cpufreq policy returned by cpufreq_cpu_acquire().
256 void cpufreq_cpu_release(struct cpufreq_policy *policy) in cpufreq_cpu_release() argument
258 if (WARN_ON(!policy)) in cpufreq_cpu_release()
261 lockdep_assert_held(&policy->rwsem); in cpufreq_cpu_release()
263 up_write(&policy->rwsem); in cpufreq_cpu_release()
265 cpufreq_cpu_put(policy); in cpufreq_cpu_release()
269 * cpufreq_cpu_acquire - Find policy for a CPU, mark it as busy and lock it.
270 * @cpu: CPU to find the policy for.
272 * Call cpufreq_cpu_get() to get a reference on the cpufreq policy for @cpu and
273 * if the policy returned by it is not NULL, acquire its rwsem for writing.
274 * Return the policy if it is active or release it and return NULL otherwise.
276 * The policy returned by this function has to be released with the help of
282 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_cpu_acquire() local
284 if (!policy) in cpufreq_cpu_acquire()
287 down_write(&policy->rwsem); in cpufreq_cpu_acquire()
289 if (policy_is_inactive(policy)) { in cpufreq_cpu_acquire()
290 cpufreq_cpu_release(policy); in cpufreq_cpu_acquire()
294 return policy; in cpufreq_cpu_acquire()
335 * @policy: cpufreq policy to enable fast frequency switching for.
343 static void cpufreq_notify_transition(struct cpufreq_policy *policy, in cpufreq_notify_transition() argument
354 freqs->policy = policy; 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()
381 cpumask_pr_args(policy->cpus)); in cpufreq_notify_transition()
383 for_each_cpu(cpu, policy->cpus) 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()
395 static void cpufreq_notify_post_transition(struct cpufreq_policy *policy, in cpufreq_notify_post_transition() argument
398 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE); in cpufreq_notify_post_transition()
403 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE); in cpufreq_notify_post_transition()
404 cpufreq_notify_transition(policy, freqs, CPUFREQ_POSTCHANGE); in cpufreq_notify_post_transition()
407 void cpufreq_freq_transition_begin(struct cpufreq_policy *policy, in cpufreq_freq_transition_begin() argument
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()
437 cpufreq_notify_transition(policy, freqs, CPUFREQ_PRECHANGE); in cpufreq_freq_transition_begin()
441 void cpufreq_freq_transition_end(struct cpufreq_policy *policy, in cpufreq_freq_transition_end() argument
444 if (WARN_ON(!policy->transition_ongoing)) in cpufreq_freq_transition_end()
447 cpufreq_notify_post_transition(policy, freqs, transition_failed); 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 spin_lock(&policy->transition_lock); in cpufreq_freq_transition_end()
454 policy->transition_ongoing = false; in cpufreq_freq_transition_end()
455 policy->transition_task = NULL; in cpufreq_freq_transition_end()
456 spin_unlock(&policy->transition_lock); in cpufreq_freq_transition_end()
458 wake_up(&policy->transition_wait); in cpufreq_freq_transition_end()
484 * cpufreq_enable_fast_switch - Enable fast frequency switching for policy.
485 * @policy: cpufreq policy to enable fast frequency switching for.
487 * Try to enable fast frequency switching for @policy.
494 void cpufreq_enable_fast_switch(struct cpufreq_policy *policy) in cpufreq_enable_fast_switch() argument
496 lockdep_assert_held(&policy->rwsem); in cpufreq_enable_fast_switch()
498 if (!policy->fast_switch_possible) in cpufreq_enable_fast_switch()
504 policy->fast_switch_enabled = true; in cpufreq_enable_fast_switch()
507 policy->cpu); in cpufreq_enable_fast_switch()
515 * cpufreq_disable_fast_switch - Disable fast frequency switching for policy.
516 * @policy: cpufreq policy to disable fast frequency switching for.
518 void cpufreq_disable_fast_switch(struct cpufreq_policy *policy) in cpufreq_disable_fast_switch() argument
521 if (policy->fast_switch_enabled) { in cpufreq_disable_fast_switch()
522 policy->fast_switch_enabled = false; in cpufreq_disable_fast_switch()
533 * @policy: associated policy to interrogate
536 * The target to driver frequency mapping is cached in the policy.
539 * given target_freq, subject to policy (min/max) and driver limitations.
541 unsigned int cpufreq_driver_resolve_freq(struct cpufreq_policy *policy, in cpufreq_driver_resolve_freq() argument
544 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_resolve_freq()
545 policy->cached_target_freq = target_freq; in cpufreq_driver_resolve_freq()
550 idx = cpufreq_frequency_table_target(policy, target_freq, in cpufreq_driver_resolve_freq()
552 policy->cached_resolved_idx = idx; in cpufreq_driver_resolve_freq()
553 return policy->freq_table[idx].frequency; in cpufreq_driver_resolve_freq()
557 return cpufreq_driver->resolve_freq(policy, target_freq); in cpufreq_driver_resolve_freq()
563 unsigned int cpufreq_policy_transition_delay_us(struct cpufreq_policy *policy) in cpufreq_policy_transition_delay_us() argument
567 if (policy->transition_delay_us) in cpufreq_policy_transition_delay_us()
568 return policy->transition_delay_us; in cpufreq_policy_transition_delay_us()
570 latency = policy->cpuinfo.transition_latency / NSEC_PER_USEC; in cpufreq_policy_transition_delay_us()
682 * Write out information from cpufreq_driver->policy[cpu]; object must be
688 (struct cpufreq_policy *policy, char *buf) \
690 return sprintf(buf, "%u\n", policy->object); \
704 static ssize_t show_scaling_cur_freq(struct cpufreq_policy *policy, char *buf) in show_scaling_cur_freq() argument
709 freq = arch_freq_get_on_cpu(policy->cpu); in show_scaling_cur_freq()
713 ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); in show_scaling_cur_freq()
715 ret = sprintf(buf, "%u\n", policy->cur); in show_scaling_cur_freq()
724 (struct cpufreq_policy *policy, const char *buf, size_t count) \
733 ret = freq_qos_update_request(policy->object##_freq_req, val);\
743 static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy, in show_cpuinfo_cur_freq() argument
746 unsigned int cur_freq = __cpufreq_get(policy); in show_cpuinfo_cur_freq()
755 * show_scaling_governor - show the current policy for the specified CPU
757 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) in show_scaling_governor() argument
759 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) in show_scaling_governor()
761 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) in show_scaling_governor()
763 else if (policy->governor) in show_scaling_governor()
765 policy->governor->name); in show_scaling_governor()
770 * store_scaling_governor - store policy for the specified CPU
772 static ssize_t store_scaling_governor(struct cpufreq_policy *policy, in store_scaling_governor() argument
789 ret = cpufreq_set_policy(policy, NULL, new_pol); in store_scaling_governor()
797 ret = cpufreq_set_policy(policy, new_gov, in store_scaling_governor()
809 static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf) in show_scaling_driver() argument
817 static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, in show_scaling_available_governors() argument
862 static ssize_t show_related_cpus(struct cpufreq_policy *policy, char *buf) in show_related_cpus() argument
864 return cpufreq_show_cpus(policy->related_cpus, buf); in show_related_cpus()
870 static ssize_t show_affected_cpus(struct cpufreq_policy *policy, char *buf) in show_affected_cpus() argument
872 return cpufreq_show_cpus(policy->cpus, buf); in show_affected_cpus()
875 static ssize_t store_scaling_setspeed(struct cpufreq_policy *policy, in store_scaling_setspeed() argument
881 if (!policy->governor || !policy->governor->store_setspeed) in store_scaling_setspeed()
888 policy->governor->store_setspeed(policy, freq); in store_scaling_setspeed()
893 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf) in show_scaling_setspeed() argument
895 if (!policy->governor || !policy->governor->show_setspeed) in show_scaling_setspeed()
898 return policy->governor->show_setspeed(policy, buf); in show_scaling_setspeed()
904 static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf) in show_bios_limit() argument
908 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); in show_bios_limit()
911 return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); in show_bios_limit()
949 struct cpufreq_policy *policy = to_policy(kobj); in show() local
956 down_read(&policy->rwsem); in show()
957 ret = fattr->show(policy, buf); in show()
958 up_read(&policy->rwsem); in show()
966 struct cpufreq_policy *policy = to_policy(kobj); in store() local
980 if (cpu_online(policy->cpu)) { in store()
981 down_write(&policy->rwsem); in store()
982 ret = fattr->store(policy, buf, count); in store()
983 up_write(&policy->rwsem); in store()
993 struct cpufreq_policy *policy = to_policy(kobj); in cpufreq_sysfs_release() local
995 complete(&policy->kobj_unregister); in cpufreq_sysfs_release()
1009 static void add_cpu_dev_symlink(struct cpufreq_policy *policy, unsigned int cpu, in add_cpu_dev_symlink() argument
1015 if (cpumask_test_and_set_cpu(cpu, policy->real_cpus)) in add_cpu_dev_symlink()
1019 if (sysfs_create_link(&dev->kobj, &policy->kobj, "cpufreq")) in add_cpu_dev_symlink()
1023 static void remove_cpu_dev_symlink(struct cpufreq_policy *policy, in remove_cpu_dev_symlink() argument
1030 static int cpufreq_add_dev_interface(struct cpufreq_policy *policy) in cpufreq_add_dev_interface() argument
1038 ret = sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); in cpufreq_add_dev_interface()
1044 ret = sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); in cpufreq_add_dev_interface()
1049 ret = sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); in cpufreq_add_dev_interface()
1054 ret = sysfs_create_file(&policy->kobj, &bios_limit.attr); in cpufreq_add_dev_interface()
1062 static int cpufreq_init_policy(struct cpufreq_policy *policy) in cpufreq_init_policy() argument
1069 /* Update policy governor to the one used before hotplug. */ in cpufreq_init_policy()
1070 gov = get_governor(policy->last_governor); in cpufreq_init_policy()
1073 gov->name, policy->cpu); in cpufreq_init_policy()
1085 /* Use the default policy if there is no last_policy. */ in cpufreq_init_policy()
1086 if (policy->last_policy) { in cpufreq_init_policy()
1087 pol = policy->last_policy; in cpufreq_init_policy()
1092 * nor "powersave", fall back to the initial policy in cpufreq_init_policy()
1096 pol = policy->policy; in cpufreq_init_policy()
1103 ret = cpufreq_set_policy(policy, gov, pol); in cpufreq_init_policy()
1110 static int cpufreq_add_policy_cpu(struct cpufreq_policy *policy, unsigned int cpu) in cpufreq_add_policy_cpu() argument
1115 if (cpumask_test_cpu(cpu, policy->cpus)) in cpufreq_add_policy_cpu()
1118 down_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1120 cpufreq_stop_governor(policy); in cpufreq_add_policy_cpu()
1122 cpumask_set_cpu(cpu, policy->cpus); in cpufreq_add_policy_cpu()
1125 ret = cpufreq_start_governor(policy); in cpufreq_add_policy_cpu()
1129 up_write(&policy->rwsem); in cpufreq_add_policy_cpu()
1133 void refresh_frequency_limits(struct cpufreq_policy *policy) in refresh_frequency_limits() argument
1135 if (!policy_is_inactive(policy)) { in refresh_frequency_limits()
1136 pr_debug("updating policy for CPU %u\n", policy->cpu); in refresh_frequency_limits()
1138 cpufreq_set_policy(policy, policy->governor, policy->policy); in refresh_frequency_limits()
1145 struct cpufreq_policy *policy = in handle_update() local
1148 pr_debug("handle_update for cpu %u called\n", policy->cpu); in handle_update()
1149 down_write(&policy->rwsem); in handle_update()
1150 refresh_frequency_limits(policy); in handle_update()
1151 up_write(&policy->rwsem); in handle_update()
1157 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_min); in cpufreq_notifier_min() local
1159 schedule_work(&policy->update); in cpufreq_notifier_min()
1166 struct cpufreq_policy *policy = container_of(nb, struct cpufreq_policy, nb_max); in cpufreq_notifier_max() local
1168 schedule_work(&policy->update); in cpufreq_notifier_max()
1172 static void cpufreq_policy_put_kobj(struct cpufreq_policy *policy) in cpufreq_policy_put_kobj() argument
1177 down_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1178 cpufreq_stats_free_table(policy); in cpufreq_policy_put_kobj()
1179 kobj = &policy->kobj; in cpufreq_policy_put_kobj()
1180 cmp = &policy->kobj_unregister; in cpufreq_policy_put_kobj()
1181 up_write(&policy->rwsem); in cpufreq_policy_put_kobj()
1196 struct cpufreq_policy *policy; in cpufreq_policy_alloc() local
1203 policy = kzalloc(sizeof(*policy), GFP_KERNEL); in cpufreq_policy_alloc()
1204 if (!policy) in cpufreq_policy_alloc()
1207 if (!alloc_cpumask_var(&policy->cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1210 if (!zalloc_cpumask_var(&policy->related_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1213 if (!zalloc_cpumask_var(&policy->real_cpus, GFP_KERNEL)) in cpufreq_policy_alloc()
1216 init_completion(&policy->kobj_unregister); in cpufreq_policy_alloc()
1217 ret = kobject_init_and_add(&policy->kobj, &ktype_cpufreq, in cpufreq_policy_alloc()
1218 cpufreq_global_kobject, "policy%u", cpu); in cpufreq_policy_alloc()
1220 dev_err(dev, "%s: failed to init policy->kobj: %d\n", __func__, ret); in cpufreq_policy_alloc()
1222 * The entire policy object will be freed below, but the extra in cpufreq_policy_alloc()
1226 kobject_put(&policy->kobj); in cpufreq_policy_alloc()
1230 freq_constraints_init(&policy->constraints); in cpufreq_policy_alloc()
1232 policy->nb_min.notifier_call = cpufreq_notifier_min; in cpufreq_policy_alloc()
1233 policy->nb_max.notifier_call = cpufreq_notifier_max; in cpufreq_policy_alloc()
1235 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1236 &policy->nb_min); in cpufreq_policy_alloc()
1239 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1243 ret = freq_qos_add_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_alloc()
1244 &policy->nb_max); in cpufreq_policy_alloc()
1247 ret, cpumask_pr_args(policy->cpus)); in cpufreq_policy_alloc()
1251 INIT_LIST_HEAD(&policy->policy_list); in cpufreq_policy_alloc()
1252 init_rwsem(&policy->rwsem); in cpufreq_policy_alloc()
1253 spin_lock_init(&policy->transition_lock); in cpufreq_policy_alloc()
1254 init_waitqueue_head(&policy->transition_wait); in cpufreq_policy_alloc()
1255 INIT_WORK(&policy->update, handle_update); in cpufreq_policy_alloc()
1257 policy->cpu = cpu; in cpufreq_policy_alloc()
1258 return policy; in cpufreq_policy_alloc()
1261 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_alloc()
1262 &policy->nb_min); in cpufreq_policy_alloc()
1264 cpufreq_policy_put_kobj(policy); in cpufreq_policy_alloc()
1266 free_cpumask_var(policy->real_cpus); in cpufreq_policy_alloc()
1268 free_cpumask_var(policy->related_cpus); in cpufreq_policy_alloc()
1270 free_cpumask_var(policy->cpus); in cpufreq_policy_alloc()
1272 kfree(policy); in cpufreq_policy_alloc()
1277 static void cpufreq_policy_free(struct cpufreq_policy *policy) in cpufreq_policy_free() argument
1282 /* Remove policy from list */ in cpufreq_policy_free()
1284 list_del(&policy->policy_list); in cpufreq_policy_free()
1286 for_each_cpu(cpu, policy->related_cpus) in cpufreq_policy_free()
1290 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MAX, in cpufreq_policy_free()
1291 &policy->nb_max); in cpufreq_policy_free()
1292 freq_qos_remove_notifier(&policy->constraints, FREQ_QOS_MIN, in cpufreq_policy_free()
1293 &policy->nb_min); in cpufreq_policy_free()
1295 /* Cancel any pending policy->update work before freeing the policy. */ in cpufreq_policy_free()
1296 cancel_work_sync(&policy->update); in cpufreq_policy_free()
1298 if (policy->max_freq_req) { in cpufreq_policy_free()
1304 CPUFREQ_REMOVE_POLICY, policy); in cpufreq_policy_free()
1305 freq_qos_remove_request(policy->max_freq_req); in cpufreq_policy_free()
1308 freq_qos_remove_request(policy->min_freq_req); in cpufreq_policy_free()
1309 kfree(policy->min_freq_req); in cpufreq_policy_free()
1311 cpufreq_policy_put_kobj(policy); in cpufreq_policy_free()
1312 free_cpumask_var(policy->real_cpus); in cpufreq_policy_free()
1313 free_cpumask_var(policy->related_cpus); in cpufreq_policy_free()
1314 free_cpumask_var(policy->cpus); in cpufreq_policy_free()
1315 kfree(policy); in cpufreq_policy_free()
1320 struct cpufreq_policy *policy; in cpufreq_online() local
1328 /* Check if this CPU already has a policy to manage it */ in cpufreq_online()
1329 policy = per_cpu(cpufreq_cpu_data, cpu); in cpufreq_online()
1330 if (policy) { in cpufreq_online()
1331 WARN_ON(!cpumask_test_cpu(cpu, policy->related_cpus)); in cpufreq_online()
1332 if (!policy_is_inactive(policy)) in cpufreq_online()
1333 return cpufreq_add_policy_cpu(policy, cpu); in cpufreq_online()
1335 /* This is the only online CPU for the policy. Start over. */ in cpufreq_online()
1337 down_write(&policy->rwsem); in cpufreq_online()
1338 policy->cpu = cpu; in cpufreq_online()
1339 policy->governor = NULL; in cpufreq_online()
1340 up_write(&policy->rwsem); in cpufreq_online()
1343 policy = cpufreq_policy_alloc(cpu); in cpufreq_online()
1344 if (!policy) in cpufreq_online()
1349 ret = cpufreq_driver->online(policy); in cpufreq_online()
1356 /* Recover policy->cpus using related_cpus */ in cpufreq_online()
1357 cpumask_copy(policy->cpus, policy->related_cpus); in cpufreq_online()
1359 cpumask_copy(policy->cpus, cpumask_of(cpu)); in cpufreq_online()
1365 ret = cpufreq_driver->init(policy); in cpufreq_online()
1373 * The initialization has succeeded and the policy is online. in cpufreq_online()
1377 ret = cpufreq_table_validate_and_sort(policy); in cpufreq_online()
1381 /* related_cpus should at least include policy->cpus. */ in cpufreq_online()
1382 cpumask_copy(policy->related_cpus, policy->cpus); in cpufreq_online()
1385 down_write(&policy->rwsem); in cpufreq_online()
1390 cpumask_and(policy->cpus, policy->cpus, cpu_online_mask); in cpufreq_online()
1393 for_each_cpu(j, policy->related_cpus) { in cpufreq_online()
1394 per_cpu(cpufreq_cpu_data, j) = policy; in cpufreq_online()
1395 add_cpu_dev_symlink(policy, j, get_cpu_device(j)); in cpufreq_online()
1398 policy->min_freq_req = kzalloc(2 * sizeof(*policy->min_freq_req), in cpufreq_online()
1400 if (!policy->min_freq_req) in cpufreq_online()
1403 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1404 policy->min_freq_req, FREQ_QOS_MIN, in cpufreq_online()
1411 kfree(policy->min_freq_req); in cpufreq_online()
1412 policy->min_freq_req = NULL; in cpufreq_online()
1421 policy->max_freq_req = policy->min_freq_req + 1; in cpufreq_online()
1423 ret = freq_qos_add_request(&policy->constraints, in cpufreq_online()
1424 policy->max_freq_req, FREQ_QOS_MAX, in cpufreq_online()
1427 policy->max_freq_req = NULL; in cpufreq_online()
1432 CPUFREQ_CREATE_POLICY, policy); in cpufreq_online()
1436 policy->cur = cpufreq_driver->get(policy->cpu); in cpufreq_online()
1437 if (!policy->cur) { in cpufreq_online()
1453 * for the next freq which is >= policy->cur ('cur' must be set by now, in cpufreq_online()
1457 * We are passing target-freq as "policy->cur - 1" otherwise in cpufreq_online()
1458 * __cpufreq_driver_target() would simply fail, as policy->cur will be in cpufreq_online()
1463 unsigned int old_freq = policy->cur; in cpufreq_online()
1466 ret = cpufreq_frequency_table_get_index(policy, old_freq); in cpufreq_online()
1468 ret = __cpufreq_driver_target(policy, old_freq - 1, in cpufreq_online()
1478 __func__, policy->cpu, old_freq, policy->cur); in cpufreq_online()
1483 ret = cpufreq_add_dev_interface(policy); in cpufreq_online()
1487 cpufreq_stats_create_table(policy); in cpufreq_online()
1490 list_add(&policy->policy_list, &cpufreq_policy_list); in cpufreq_online()
1494 ret = cpufreq_init_policy(policy); in cpufreq_online()
1496 pr_err("%s: Failed to initialize policy for cpu: %d (%d)\n", in cpufreq_online()
1501 up_write(&policy->rwsem); in cpufreq_online()
1503 kobject_uevent(&policy->kobj, KOBJ_ADD); in cpufreq_online()
1505 /* Callback for handling stuff after policy is ready */ in cpufreq_online()
1507 cpufreq_driver->ready(policy); in cpufreq_online()
1510 policy->cdev = of_cpufreq_cooling_register(policy); in cpufreq_online()
1517 for_each_cpu(j, policy->real_cpus) in cpufreq_online()
1518 remove_cpu_dev_symlink(policy, get_cpu_device(j)); in cpufreq_online()
1520 up_write(&policy->rwsem); in cpufreq_online()
1524 cpufreq_driver->offline(policy); in cpufreq_online()
1528 cpufreq_driver->exit(policy); in cpufreq_online()
1531 cpufreq_policy_free(policy); in cpufreq_online()
1542 struct cpufreq_policy *policy; in cpufreq_add_dev() local
1555 policy = per_cpu(cpufreq_cpu_data, cpu); in cpufreq_add_dev()
1556 if (policy) in cpufreq_add_dev()
1557 add_cpu_dev_symlink(policy, cpu, dev); in cpufreq_add_dev()
1562 static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy) in __cpufreq_offline() argument
1567 cpufreq_stop_governor(policy); in __cpufreq_offline()
1569 cpumask_clear_cpu(cpu, policy->cpus); in __cpufreq_offline()
1571 if (!policy_is_inactive(policy)) { in __cpufreq_offline()
1573 if (cpu == policy->cpu) in __cpufreq_offline()
1574 policy->cpu = cpumask_any(policy->cpus); in __cpufreq_offline()
1576 /* Start the governor again for the active policy. */ in __cpufreq_offline()
1578 ret = cpufreq_start_governor(policy); in __cpufreq_offline()
1587 strncpy(policy->last_governor, policy->governor->name, in __cpufreq_offline()
1590 policy->last_policy = policy->policy; in __cpufreq_offline()
1593 cpufreq_cooling_unregister(policy->cdev); in __cpufreq_offline()
1594 policy->cdev = NULL; in __cpufreq_offline()
1598 cpufreq_driver->stop_cpu(policy); in __cpufreq_offline()
1601 cpufreq_exit_governor(policy); in __cpufreq_offline()
1608 cpufreq_driver->offline(policy); in __cpufreq_offline()
1613 cpufreq_driver->exit(policy); in __cpufreq_offline()
1615 policy->freq_table = NULL; in __cpufreq_offline()
1620 struct cpufreq_policy *policy; in cpufreq_offline() local
1624 policy = cpufreq_cpu_get_raw(cpu); in cpufreq_offline()
1625 if (!policy) { in cpufreq_offline()
1630 down_write(&policy->rwsem); in cpufreq_offline()
1632 __cpufreq_offline(cpu, policy); in cpufreq_offline()
1634 up_write(&policy->rwsem); in cpufreq_offline()
1646 struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu); in cpufreq_remove_dev() local
1648 if (!policy) in cpufreq_remove_dev()
1651 down_write(&policy->rwsem); in cpufreq_remove_dev()
1654 __cpufreq_offline(cpu, policy); in cpufreq_remove_dev()
1656 cpumask_clear_cpu(cpu, policy->real_cpus); in cpufreq_remove_dev()
1657 remove_cpu_dev_symlink(policy, dev); in cpufreq_remove_dev()
1659 if (!cpumask_empty(policy->real_cpus)) { in cpufreq_remove_dev()
1660 up_write(&policy->rwsem); in cpufreq_remove_dev()
1666 cpufreq_driver->exit(policy); in cpufreq_remove_dev()
1668 up_write(&policy->rwsem); in cpufreq_remove_dev()
1670 cpufreq_policy_free(policy); in cpufreq_remove_dev()
1676 * @policy: policy managing CPUs
1682 static void cpufreq_out_of_sync(struct cpufreq_policy *policy, in cpufreq_out_of_sync() argument
1688 policy->cur, new_freq); in cpufreq_out_of_sync()
1690 freqs.old = policy->cur; in cpufreq_out_of_sync()
1693 cpufreq_freq_transition_begin(policy, &freqs); in cpufreq_out_of_sync()
1694 cpufreq_freq_transition_end(policy, &freqs, 0); in cpufreq_out_of_sync()
1697 static unsigned int cpufreq_verify_current_freq(struct cpufreq_policy *policy, bool update) in cpufreq_verify_current_freq() argument
1701 new_freq = cpufreq_driver->get(policy->cpu); in cpufreq_verify_current_freq()
1706 * If fast frequency switching is used with the given policy, the check in cpufreq_verify_current_freq()
1707 * against policy->cur is pointless, so skip it in that case. in cpufreq_verify_current_freq()
1709 if (policy->fast_switch_enabled || !has_target()) in cpufreq_verify_current_freq()
1712 if (policy->cur != new_freq) { in cpufreq_verify_current_freq()
1713 cpufreq_out_of_sync(policy, new_freq); in cpufreq_verify_current_freq()
1715 schedule_work(&policy->update); in cpufreq_verify_current_freq()
1722 * cpufreq_quick_get - get the CPU frequency (in kHz) from policy->cur
1730 struct cpufreq_policy *policy; in cpufreq_quick_get() local
1744 policy = cpufreq_cpu_get(cpu); in cpufreq_quick_get()
1745 if (policy) { in cpufreq_quick_get()
1746 ret_freq = policy->cur; in cpufreq_quick_get()
1747 cpufreq_cpu_put(policy); in cpufreq_quick_get()
1762 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_quick_get_max() local
1765 if (policy) { in cpufreq_quick_get_max()
1766 ret_freq = policy->max; in cpufreq_quick_get_max()
1767 cpufreq_cpu_put(policy); in cpufreq_quick_get_max()
1782 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_get_hw_max_freq() local
1785 if (policy) { in cpufreq_get_hw_max_freq()
1786 ret_freq = policy->cpuinfo.max_freq; in cpufreq_get_hw_max_freq()
1787 cpufreq_cpu_put(policy); in cpufreq_get_hw_max_freq()
1794 static unsigned int __cpufreq_get(struct cpufreq_policy *policy) in __cpufreq_get() argument
1796 if (unlikely(policy_is_inactive(policy))) in __cpufreq_get()
1799 return cpufreq_verify_current_freq(policy, true); in __cpufreq_get()
1810 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); in cpufreq_get() local
1813 if (policy) { in cpufreq_get()
1814 down_read(&policy->rwsem); in cpufreq_get()
1816 ret_freq = __cpufreq_get(policy); in cpufreq_get()
1817 up_read(&policy->rwsem); in cpufreq_get()
1819 cpufreq_cpu_put(policy); in cpufreq_get()
1837 int cpufreq_generic_suspend(struct cpufreq_policy *policy) in cpufreq_generic_suspend() argument
1841 if (!policy->suspend_freq) { in cpufreq_generic_suspend()
1847 policy->suspend_freq); in cpufreq_generic_suspend()
1849 ret = __cpufreq_driver_target(policy, policy->suspend_freq, in cpufreq_generic_suspend()
1853 __func__, policy->suspend_freq, ret); in cpufreq_generic_suspend()
1869 struct cpufreq_policy *policy; in cpufreq_suspend() local
1879 for_each_active_policy(policy) { in cpufreq_suspend()
1881 down_write(&policy->rwsem); in cpufreq_suspend()
1882 cpufreq_stop_governor(policy); in cpufreq_suspend()
1883 up_write(&policy->rwsem); in cpufreq_suspend()
1886 if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy)) in cpufreq_suspend()
1903 struct cpufreq_policy *policy; in cpufreq_resume() local
1919 for_each_active_policy(policy) { in cpufreq_resume()
1920 if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) { in cpufreq_resume()
1922 policy); in cpufreq_resume()
1924 down_write(&policy->rwsem); in cpufreq_resume()
1925 ret = cpufreq_start_governor(policy); in cpufreq_resume()
1926 up_write(&policy->rwsem); in cpufreq_resume()
1929 pr_err("%s: Failed to start governor for policy: %p\n", in cpufreq_resume()
1930 __func__, policy); in cpufreq_resume()
1989 * changes in cpufreq policy.
2075 * @policy: cpufreq policy to switch the frequency for.
2085 * This function must not be called if policy->fast_switch_enabled is unset.
2088 * twice in parallel for the same policy and that it will never be called in
2089 * parallel with either ->target() or ->target_index() for the same policy.
2096 unsigned int cpufreq_driver_fast_switch(struct cpufreq_policy *policy, in cpufreq_driver_fast_switch() argument
2102 target_freq = clamp_val(target_freq, policy->min, policy->max); in cpufreq_driver_fast_switch()
2103 freq = cpufreq_driver->fast_switch(policy, target_freq); in cpufreq_driver_fast_switch()
2108 policy->cur = freq; in cpufreq_driver_fast_switch()
2109 arch_set_freq_scale(policy->related_cpus, freq, in cpufreq_driver_fast_switch()
2110 policy->cpuinfo.max_freq); in cpufreq_driver_fast_switch()
2111 cpufreq_stats_record_transition(policy, freq); in cpufreq_driver_fast_switch()
2114 for_each_cpu(cpu, policy->cpus) in cpufreq_driver_fast_switch()
2123 static int __target_intermediate(struct cpufreq_policy *policy, in __target_intermediate() argument
2128 freqs->new = cpufreq_driver->get_intermediate(policy, index); in __target_intermediate()
2135 __func__, policy->cpu, freqs->old, freqs->new); in __target_intermediate()
2137 cpufreq_freq_transition_begin(policy, freqs); in __target_intermediate()
2138 ret = cpufreq_driver->target_intermediate(policy, index); in __target_intermediate()
2139 cpufreq_freq_transition_end(policy, freqs, ret); in __target_intermediate()
2148 static int __target_index(struct cpufreq_policy *policy, int index) in __target_index() argument
2150 struct cpufreq_freqs freqs = {.old = policy->cur, .flags = 0}; in __target_index()
2152 unsigned int newfreq = policy->freq_table[index].frequency; in __target_index()
2156 if (newfreq == policy->cur) in __target_index()
2163 retval = __target_intermediate(policy, &freqs, index); in __target_index()
2175 __func__, policy->cpu, freqs.old, freqs.new); in __target_index()
2177 cpufreq_freq_transition_begin(policy, &freqs); in __target_index()
2180 retval = cpufreq_driver->target_index(policy, index); in __target_index()
2186 cpufreq_freq_transition_end(policy, &freqs, retval); in __target_index()
2196 freqs.new = policy->restore_freq; in __target_index()
2197 cpufreq_freq_transition_begin(policy, &freqs); in __target_index()
2198 cpufreq_freq_transition_end(policy, &freqs, 0); in __target_index()
2205 int __cpufreq_driver_target(struct cpufreq_policy *policy, in __cpufreq_driver_target() argument
2216 target_freq = clamp_val(target_freq, policy->min, policy->max); in __cpufreq_driver_target()
2219 policy->cpu, target_freq, relation, old_target_freq); in __cpufreq_driver_target()
2227 if (target_freq == policy->cur && in __cpufreq_driver_target()
2232 policy->restore_freq = policy->cur; in __cpufreq_driver_target()
2235 return cpufreq_driver->target(policy, target_freq, relation); in __cpufreq_driver_target()
2240 index = cpufreq_frequency_table_target(policy, target_freq, relation); in __cpufreq_driver_target()
2242 return __target_index(policy, index); in __cpufreq_driver_target()
2246 int cpufreq_driver_target(struct cpufreq_policy *policy, in cpufreq_driver_target() argument
2252 down_write(&policy->rwsem); in cpufreq_driver_target()
2254 ret = __cpufreq_driver_target(policy, target_freq, relation); in cpufreq_driver_target()
2256 up_write(&policy->rwsem); in cpufreq_driver_target()
2267 static int cpufreq_init_governor(struct cpufreq_policy *policy) in cpufreq_init_governor() argument
2278 if (!policy->governor) in cpufreq_init_governor()
2282 if (policy->governor->flags & CPUFREQ_GOV_DYNAMIC_SWITCHING && in cpufreq_init_governor()
2288 policy->governor->name, gov->name); in cpufreq_init_governor()
2289 policy->governor = gov; in cpufreq_init_governor()
2295 if (!try_module_get(policy->governor->owner)) in cpufreq_init_governor()
2298 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_init_governor()
2300 if (policy->governor->init) { in cpufreq_init_governor()
2301 ret = policy->governor->init(policy); in cpufreq_init_governor()
2303 module_put(policy->governor->owner); in cpufreq_init_governor()
2308 policy->strict_target = !!(policy->governor->flags & CPUFREQ_GOV_STRICT_TARGET); in cpufreq_init_governor()
2313 static void cpufreq_exit_governor(struct cpufreq_policy *policy) in cpufreq_exit_governor() argument
2315 if (cpufreq_suspended || !policy->governor) in cpufreq_exit_governor()
2318 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_exit_governor()
2320 if (policy->governor->exit) in cpufreq_exit_governor()
2321 policy->governor->exit(policy); in cpufreq_exit_governor()
2323 module_put(policy->governor->owner); in cpufreq_exit_governor()
2326 int cpufreq_start_governor(struct cpufreq_policy *policy) in cpufreq_start_governor() argument
2333 if (!policy->governor) in cpufreq_start_governor()
2336 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_start_governor()
2339 cpufreq_verify_current_freq(policy, false); in cpufreq_start_governor()
2341 if (policy->governor->start) { in cpufreq_start_governor()
2342 ret = policy->governor->start(policy); in cpufreq_start_governor()
2347 if (policy->governor->limits) in cpufreq_start_governor()
2348 policy->governor->limits(policy); in cpufreq_start_governor()
2353 void cpufreq_stop_governor(struct cpufreq_policy *policy) in cpufreq_stop_governor() argument
2355 if (cpufreq_suspended || !policy->governor) in cpufreq_stop_governor()
2358 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_stop_governor()
2360 if (policy->governor->stop) in cpufreq_stop_governor()
2361 policy->governor->stop(policy); in cpufreq_stop_governor()
2364 static void cpufreq_governor_limits(struct cpufreq_policy *policy) in cpufreq_governor_limits() argument
2366 if (cpufreq_suspended || !policy->governor) in cpufreq_governor_limits()
2369 pr_debug("%s: for CPU %u\n", __func__, policy->cpu); in cpufreq_governor_limits()
2371 if (policy->governor->limits) in cpufreq_governor_limits()
2372 policy->governor->limits(policy); in cpufreq_governor_limits()
2400 struct cpufreq_policy *policy; in cpufreq_unregister_governor() local
2411 for_each_inactive_policy(policy) { in cpufreq_unregister_governor()
2412 if (!strcmp(policy->last_governor, governor->name)) { in cpufreq_unregister_governor()
2413 policy->governor = NULL; in cpufreq_unregister_governor()
2414 strcpy(policy->last_governor, "\0"); in cpufreq_unregister_governor()
2427 * POLICY INTERFACE *
2432 * @policy: struct cpufreq_policy into which the current cpufreq_policy
2434 * @cpu: CPU to find the policy for
2436 * Reads the current cpufreq policy.
2438 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) in cpufreq_get_policy() argument
2441 if (!policy) in cpufreq_get_policy()
2448 memcpy(policy, cpu_policy, sizeof(*policy)); in cpufreq_get_policy()
2456 * cpufreq_set_policy - Modify cpufreq policy parameters.
2457 * @policy: Policy object to modify.
2458 * @new_gov: Policy governor pointer.
2459 * @new_pol: Policy value (for drivers with built-in governors).
2462 * limits to be set for the policy, update @policy with the verified limits
2464 * carry out a governor update for @policy. That is, run the current governor's
2466 * @policy) or replace the governor for @policy with @new_gov.
2468 * The cpuinfo part of @policy is not updated by this function.
2470 static int cpufreq_set_policy(struct cpufreq_policy *policy, in cpufreq_set_policy() argument
2478 memcpy(&new_data.cpuinfo, &policy->cpuinfo, sizeof(policy->cpuinfo)); in cpufreq_set_policy()
2479 new_data.freq_table = policy->freq_table; in cpufreq_set_policy()
2480 new_data.cpu = policy->cpu; in cpufreq_set_policy()
2485 new_data.min = freq_qos_read_value(&policy->constraints, FREQ_QOS_MIN); in cpufreq_set_policy()
2486 new_data.max = freq_qos_read_value(&policy->constraints, FREQ_QOS_MAX); in cpufreq_set_policy()
2488 pr_debug("setting new policy for CPU %u: %u - %u kHz\n", in cpufreq_set_policy()
2499 policy->min = new_data.min; in cpufreq_set_policy()
2500 policy->max = new_data.max; in cpufreq_set_policy()
2501 trace_cpu_frequency_limits(policy); in cpufreq_set_policy()
2503 policy->cached_target_freq = UINT_MAX; in cpufreq_set_policy()
2506 policy->min, policy->max); in cpufreq_set_policy()
2509 policy->policy = new_pol; in cpufreq_set_policy()
2511 return cpufreq_driver->setpolicy(policy); in cpufreq_set_policy()
2514 if (new_gov == policy->governor) { in cpufreq_set_policy()
2516 cpufreq_governor_limits(policy); in cpufreq_set_policy()
2523 old_gov = policy->governor; in cpufreq_set_policy()
2526 cpufreq_stop_governor(policy); in cpufreq_set_policy()
2527 cpufreq_exit_governor(policy); in cpufreq_set_policy()
2531 policy->governor = new_gov; in cpufreq_set_policy()
2532 ret = cpufreq_init_governor(policy); in cpufreq_set_policy()
2534 ret = cpufreq_start_governor(policy); in cpufreq_set_policy()
2537 sched_cpufreq_governor_change(policy, old_gov); in cpufreq_set_policy()
2540 cpufreq_exit_governor(policy); in cpufreq_set_policy()
2544 pr_debug("starting governor %s failed\n", policy->governor->name); in cpufreq_set_policy()
2546 policy->governor = old_gov; in cpufreq_set_policy()
2547 if (cpufreq_init_governor(policy)) in cpufreq_set_policy()
2548 policy->governor = NULL; in cpufreq_set_policy()
2550 cpufreq_start_governor(policy); in cpufreq_set_policy()
2557 * cpufreq_update_policy - Re-evaluate an existing cpufreq policy.
2558 * @cpu: CPU to re-evaluate the policy for.
2560 * Update the current frequency for the cpufreq policy of @cpu and use
2562 * evaluation of policy notifiers and the cpufreq driver's ->verify() callback
2563 * for the policy in question, among other things.
2567 struct cpufreq_policy *policy = cpufreq_cpu_acquire(cpu); in cpufreq_update_policy() local
2569 if (!policy) in cpufreq_update_policy()
2577 (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false)))) in cpufreq_update_policy()
2580 refresh_frequency_limits(policy); in cpufreq_update_policy()
2583 cpufreq_cpu_release(policy); in cpufreq_update_policy()
2588 * cpufreq_update_limits - Update policy limits for a given CPU.
2589 * @cpu: CPU to update the policy limits for.
2606 static int cpufreq_boost_set_sw(struct cpufreq_policy *policy, int state) in cpufreq_boost_set_sw() argument
2610 if (!policy->freq_table) in cpufreq_boost_set_sw()
2613 ret = cpufreq_frequency_table_cpuinfo(policy, policy->freq_table); in cpufreq_boost_set_sw()
2615 pr_err("%s: Policy frequency update failed\n", __func__); in cpufreq_boost_set_sw()
2619 ret = freq_qos_update_request(policy->max_freq_req, policy->max); in cpufreq_boost_set_sw()
2628 struct cpufreq_policy *policy; in cpufreq_boost_trigger_state() local
2640 for_each_active_policy(policy) { in cpufreq_boost_trigger_state()
2641 ret = cpufreq_driver->set_boost(policy, state); in cpufreq_boost_trigger_state()