Lines Matching +full:cooling +full:- +full:levels

1 // SPDX-License-Identifier: GPL-2.0
7 * Copyright (C) 2012-2018 Linaro Limited.
29 * Cooling state <-> CPUFreq frequency
31 * Cooling states are translated to frequencies throughout this driver and this
34 * Highest cooling state corresponds to lowest possible frequency.
37 * level 0 --> 1st Max Freq
38 * level 1 --> 2nd Max Freq
43 * struct time_in_idle - Idle time stats
53 * struct cpufreq_cooling_device - data for cooling device with cpufreq
56 * cooling devices.
57 * @max_level: maximum cooling level. One less than total number of valid
61 * registered cooling device.
63 * @cooling_ops: cpufreq callbacks to thermal cooling device ops
98 table = em_perf_state_from_pd(cpufreq_cdev->em); in get_level()
99 for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { in get_level()
105 return cpufreq_cdev->max_level - i - 1; in get_level()
116 table = em_perf_state_from_pd(cpufreq_cdev->em); in cpu_freq_to_power()
117 for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { in cpu_freq_to_power()
138 table = em_perf_state_from_pd(cpufreq_cdev->em); in cpu_power_to_freq()
139 for (i = cpufreq_cdev->max_level; i > 0; i--) { in cpu_power_to_freq()
140 /* Convert EM power to milli-Watts to make safe comparison */ in cpu_power_to_freq()
153 * get_load() - get load for a cpu
175 struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx]; in get_load()
178 delta_idle = now_idle - idle_time->time; in get_load()
179 delta_time = now - idle_time->timestamp; in get_load()
184 load = div64_u64(100 * (delta_time - delta_idle), delta_time); in get_load()
186 idle_time->time = now_idle; in get_load()
187 idle_time->timestamp = now; in get_load()
194 * get_dynamic_power() - calculate the dynamic power
207 return (raw_cpu_power * cpufreq_cdev->last_load) / 100; in get_dynamic_power()
211 * cpufreq_get_requested_power() - get the current power
238 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_requested_power()
239 struct cpufreq_policy *policy = cpufreq_cdev->policy; in cpufreq_get_requested_power()
241 freq = cpufreq_quick_get(policy->cpu); in cpufreq_get_requested_power()
243 for_each_cpu(cpu, policy->related_cpus) { in cpufreq_get_requested_power()
254 cpufreq_cdev->last_load = total_load; in cpufreq_get_requested_power()
258 trace_thermal_power_cpu_get_power_simple(policy->cpu, *power); in cpufreq_get_requested_power()
264 * cpufreq_state2power() - convert a cpu cdev state to power consumed
266 * @state: cooling device state to be converted
269 * Convert cooling device state @state into power consumption in
273 * Return: 0 on success, -EINVAL if the cooling device state is bigger
279 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_state2power()
284 if (state > cpufreq_cdev->max_level) in cpufreq_state2power()
285 return -EINVAL; in cpufreq_state2power()
287 num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); in cpufreq_state2power()
289 idx = cpufreq_cdev->max_level - state; in cpufreq_state2power()
292 table = em_perf_state_from_pd(cpufreq_cdev->em); in cpufreq_state2power()
302 * cpufreq_power2state() - convert power to a cooling device state
307 * Calculate a cooling device state for the cpus described by @cdev
311 * as input can yield different cooling device states depending on those
321 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_power2state()
322 struct cpufreq_policy *policy = cpufreq_cdev->policy; in cpufreq_power2state()
324 last_load = cpufreq_cdev->last_load ?: 1; in cpufreq_power2state()
329 trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state, in cpufreq_power2state()
342 policy = cpufreq_cdev->policy; in em_is_sane()
343 if (!cpumask_equal(policy->related_cpus, em_span_cpus(em))) { in em_is_sane()
346 cpumask_pr_args(policy->related_cpus)); in em_is_sane()
350 nr_levels = cpufreq_cdev->max_level + 1; in em_is_sane()
352 …e number of performance states in pd %*pbl (%u) doesn't match the number of cooling levels (%u)\n", in em_is_sane()
374 unsigned int num_cpus = cpumask_weight(cpufreq_cdev->policy->related_cpus); in allocate_idle_time()
376 cpufreq_cdev->idle_time = kcalloc(num_cpus, in allocate_idle_time()
377 sizeof(*cpufreq_cdev->idle_time), in allocate_idle_time()
379 if (!cpufreq_cdev->idle_time) in allocate_idle_time()
380 return -ENOMEM; in allocate_idle_time()
387 kfree(cpufreq_cdev->idle_time); in free_idle_time()
388 cpufreq_cdev->idle_time = NULL; in free_idle_time()
400 if (cpufreq_cdev->em) { in get_state_freq()
404 idx = cpufreq_cdev->max_level - state; in get_state_freq()
407 table = em_perf_state_from_pd(cpufreq_cdev->em); in get_state_freq()
416 policy = cpufreq_cdev->policy; in get_state_freq()
417 if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING) in get_state_freq()
418 idx = cpufreq_cdev->max_level - state; in get_state_freq()
422 return policy->freq_table[idx].frequency; in get_state_freq()
425 /* cpufreq cooling device callback functions are defined below */
428 * cpufreq_get_max_state - callback function to get the max cooling state.
429 * @cdev: thermal cooling device pointer.
430 * @state: fill this variable with the max cooling state.
432 * Callback for the thermal cooling device to return the cpufreq
433 * max cooling state.
440 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_max_state()
442 *state = cpufreq_cdev->max_level; in cpufreq_get_max_state()
447 * cpufreq_get_cur_state - callback function to get the current cooling state.
448 * @cdev: thermal cooling device pointer.
449 * @state: fill this variable with the current cooling state.
451 * Callback for the thermal cooling device to return the cpufreq
452 * current cooling state.
459 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_cur_state()
461 *state = cpufreq_cdev->cpufreq_state; in cpufreq_get_cur_state()
467 * cpufreq_set_cur_state - callback function to set the current cooling state.
468 * @cdev: thermal cooling device pointer.
469 * @state: set this variable to the current cooling state.
471 * Callback for the thermal cooling device to change the cpufreq
472 * current cooling state.
479 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_set_cur_state()
484 if (state > cpufreq_cdev->max_level) in cpufreq_set_cur_state()
485 return -EINVAL; in cpufreq_set_cur_state()
487 /* Check if the old cooling action is same as new cooling action */ in cpufreq_set_cur_state()
488 if (cpufreq_cdev->cpufreq_state == state) in cpufreq_set_cur_state()
493 ret = freq_qos_update_request(&cpufreq_cdev->qos_req, frequency); in cpufreq_set_cur_state()
495 cpufreq_cdev->cpufreq_state = state; in cpufreq_set_cur_state()
503 * __cpufreq_cooling_register - helper function to create cpufreq cooling device
504 * @np: a valid struct device_node to the cooling device tree node
506 * Normally this should be same as cpufreq policy->related_cpus.
509 * This interface function registers the cpufreq cooling device with the name
510 * "cpufreq-%s". This API can support multiple instances of cpufreq
511 * cooling devices. It also gives the opportunity to link the cooling device
532 return ERR_PTR(-EINVAL); in __cpufreq_cooling_register()
535 dev = get_cpu_device(policy->cpu); in __cpufreq_cooling_register()
537 pr_warn("No cpu device for cpu %d\n", policy->cpu); in __cpufreq_cooling_register()
538 return ERR_PTR(-ENODEV); in __cpufreq_cooling_register()
545 return ERR_PTR(-ENODEV); in __cpufreq_cooling_register()
550 return ERR_PTR(-ENOMEM); in __cpufreq_cooling_register()
552 cpufreq_cdev->policy = policy; in __cpufreq_cooling_register()
561 cpufreq_cdev->max_level = i - 1; in __cpufreq_cooling_register()
563 cooling_ops = &cpufreq_cdev->cooling_ops; in __cpufreq_cooling_register()
564 cooling_ops->get_max_state = cpufreq_get_max_state; in __cpufreq_cooling_register()
565 cooling_ops->get_cur_state = cpufreq_get_cur_state; in __cpufreq_cooling_register()
566 cooling_ops->set_cur_state = cpufreq_set_cur_state; in __cpufreq_cooling_register()
570 cpufreq_cdev->em = em; in __cpufreq_cooling_register()
571 cooling_ops->get_requested_power = cpufreq_get_requested_power; in __cpufreq_cooling_register()
572 cooling_ops->state2power = cpufreq_state2power; in __cpufreq_cooling_register()
573 cooling_ops->power2state = cpufreq_power2state; in __cpufreq_cooling_register()
576 if (policy->freq_table_sorted == CPUFREQ_TABLE_UNSORTED) { in __cpufreq_cooling_register()
579 cdev = ERR_PTR(-EINVAL); in __cpufreq_cooling_register()
583 ret = freq_qos_add_request(&policy->constraints, in __cpufreq_cooling_register()
584 &cpufreq_cdev->qos_req, FREQ_QOS_MAX, in __cpufreq_cooling_register()
593 cdev = ERR_PTR(-ENOMEM); in __cpufreq_cooling_register()
594 name = kasprintf(GFP_KERNEL, "cpufreq-%s", dev_name(dev)); in __cpufreq_cooling_register()
608 freq_qos_remove_request(&cpufreq_cdev->qos_req); in __cpufreq_cooling_register()
617 * cpufreq_cooling_register - function to create cpufreq cooling device.
620 * This interface function registers the cpufreq cooling device with the name
621 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
635 * of_cpufreq_cooling_register - function to create cpufreq cooling device.
638 * This interface function registers the cpufreq cooling device with the name
639 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
640 * devices. Using this API, the cpufreq cooling device will be linked to the
643 * Using this function, the cooling device will implement the power
653 struct device_node *np = of_get_cpu_node(policy->cpu, NULL); in of_cpufreq_cooling_register()
658 policy->cpu); in of_cpufreq_cooling_register()
662 if (of_property_present(np, "#cooling-cells")) { in of_cpufreq_cooling_register()
663 struct em_perf_domain *em = em_cpu_get(policy->cpu); in of_cpufreq_cooling_register()
667 pr_err("cpufreq_cooling: cpu%d failed to register as cooling device: %ld\n", in of_cpufreq_cooling_register()
668 policy->cpu, PTR_ERR(cdev)); in of_cpufreq_cooling_register()
679 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
680 * @cdev: thermal cooling device pointer.
682 * This interface function unregisters the "cpufreq-%x" cooling device.
691 cpufreq_cdev = cdev->devdata; in cpufreq_cooling_unregister()
694 freq_qos_remove_request(&cpufreq_cdev->qos_req); in cpufreq_cooling_unregister()