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 * @cooling_ops: cpufreq callbacks to thermal cooling device ops
94 for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { in get_level()
95 if (freq > cpufreq_cdev->em->table[i].frequency) in get_level()
99 return cpufreq_cdev->max_level - i - 1; in get_level()
108 for (i = cpufreq_cdev->max_level - 1; i >= 0; i--) { in cpu_freq_to_power()
109 if (freq > cpufreq_cdev->em->table[i].frequency) in cpu_freq_to_power()
113 power_mw = cpufreq_cdev->em->table[i + 1].power; in cpu_freq_to_power()
125 for (i = cpufreq_cdev->max_level; i > 0; i--) { in cpu_power_to_freq()
126 /* Convert EM power to milli-Watts to make safe comparison */ in cpu_power_to_freq()
127 em_power_mw = cpufreq_cdev->em->table[i].power; in cpu_power_to_freq()
133 return cpufreq_cdev->em->table[i].frequency; in cpu_power_to_freq()
137 * get_load() - get load for a cpu
159 struct time_in_idle *idle_time = &cpufreq_cdev->idle_time[cpu_idx]; in get_load()
162 delta_idle = now_idle - idle_time->time; in get_load()
163 delta_time = now - idle_time->timestamp; in get_load()
168 load = div64_u64(100 * (delta_time - delta_idle), delta_time); in get_load()
170 idle_time->time = now_idle; in get_load()
171 idle_time->timestamp = now; in get_load()
178 * get_dynamic_power() - calculate the dynamic power
191 return (raw_cpu_power * cpufreq_cdev->last_load) / 100; in get_dynamic_power()
195 * cpufreq_get_requested_power() - get the current power
222 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_requested_power()
223 struct cpufreq_policy *policy = cpufreq_cdev->policy; in cpufreq_get_requested_power()
225 freq = cpufreq_quick_get(policy->cpu); in cpufreq_get_requested_power()
227 for_each_cpu(cpu, policy->related_cpus) { in cpufreq_get_requested_power()
238 cpufreq_cdev->last_load = total_load; in cpufreq_get_requested_power()
242 trace_thermal_power_cpu_get_power_simple(policy->cpu, *power); in cpufreq_get_requested_power()
248 * cpufreq_state2power() - convert a cpu cdev state to power consumed
250 * @state: cooling device state to be converted
253 * Convert cooling device state @state into power consumption in
257 * Return: 0 on success, -EINVAL if the cooling device state is bigger
264 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_state2power()
267 if (state > cpufreq_cdev->max_level) in cpufreq_state2power()
268 return -EINVAL; in cpufreq_state2power()
270 num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus); in cpufreq_state2power()
272 idx = cpufreq_cdev->max_level - state; in cpufreq_state2power()
273 freq = cpufreq_cdev->em->table[idx].frequency; in cpufreq_state2power()
280 * cpufreq_power2state() - convert power to a cooling device state
285 * Calculate a cooling device state for the cpus described by @cdev
289 * as input can yield different cooling device states depending on those
299 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_power2state()
300 struct cpufreq_policy *policy = cpufreq_cdev->policy; in cpufreq_power2state()
302 last_load = cpufreq_cdev->last_load ?: 1; in cpufreq_power2state()
307 trace_thermal_power_cpu_limit(policy->related_cpus, target_freq, *state, in cpufreq_power2state()
320 policy = cpufreq_cdev->policy; in em_is_sane()
321 if (!cpumask_equal(policy->related_cpus, em_span_cpus(em))) { in em_is_sane()
324 cpumask_pr_args(policy->related_cpus)); in em_is_sane()
328 nr_levels = cpufreq_cdev->max_level + 1; in em_is_sane()
330 …e number of performance states in pd %*pbl (%u) doesn't match the number of cooling levels (%u)\n", in em_is_sane()
352 unsigned int num_cpus = cpumask_weight(cpufreq_cdev->policy->related_cpus); in allocate_idle_time()
354 cpufreq_cdev->idle_time = kcalloc(num_cpus, in allocate_idle_time()
355 sizeof(*cpufreq_cdev->idle_time), in allocate_idle_time()
357 if (!cpufreq_cdev->idle_time) in allocate_idle_time()
358 return -ENOMEM; in allocate_idle_time()
365 kfree(cpufreq_cdev->idle_time); in free_idle_time()
366 cpufreq_cdev->idle_time = NULL; in free_idle_time()
378 if (cpufreq_cdev->em) { in get_state_freq()
379 idx = cpufreq_cdev->max_level - state; in get_state_freq()
380 return cpufreq_cdev->em->table[idx].frequency; in get_state_freq()
385 policy = cpufreq_cdev->policy; in get_state_freq()
386 if (policy->freq_table_sorted == CPUFREQ_TABLE_SORTED_ASCENDING) in get_state_freq()
387 idx = cpufreq_cdev->max_level - state; in get_state_freq()
391 return policy->freq_table[idx].frequency; in get_state_freq()
394 /* cpufreq cooling device callback functions are defined below */
397 * cpufreq_get_max_state - callback function to get the max cooling state.
398 * @cdev: thermal cooling device pointer.
399 * @state: fill this variable with the max cooling state.
401 * Callback for the thermal cooling device to return the cpufreq
402 * max cooling state.
409 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_max_state()
411 *state = cpufreq_cdev->max_level; in cpufreq_get_max_state()
416 * cpufreq_get_cur_state - callback function to get the current cooling state.
417 * @cdev: thermal cooling device pointer.
418 * @state: fill this variable with the current cooling state.
420 * Callback for the thermal cooling device to return the cpufreq
421 * current cooling state.
428 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_get_cur_state()
430 *state = cpufreq_cdev->cpufreq_state; in cpufreq_get_cur_state()
436 * cpufreq_set_cur_state - callback function to set the current cooling state.
437 * @cdev: thermal cooling device pointer.
438 * @state: set this variable to the current cooling state.
440 * Callback for the thermal cooling device to change the cpufreq
441 * current cooling state.
448 struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; in cpufreq_set_cur_state()
454 if (state > cpufreq_cdev->max_level) in cpufreq_set_cur_state()
455 return -EINVAL; in cpufreq_set_cur_state()
457 /* Check if the old cooling action is same as new cooling action */ in cpufreq_set_cur_state()
458 if (cpufreq_cdev->cpufreq_state == state) in cpufreq_set_cur_state()
463 ret = freq_qos_update_request(&cpufreq_cdev->qos_req, frequency); in cpufreq_set_cur_state()
465 cpufreq_cdev->cpufreq_state = state; in cpufreq_set_cur_state()
466 cpus = cpufreq_cdev->policy->related_cpus; in cpufreq_set_cur_state()
475 * __cpufreq_cooling_register - helper function to create cpufreq cooling device
476 * @np: a valid struct device_node to the cooling device tree node
478 * Normally this should be same as cpufreq policy->related_cpus.
481 * This interface function registers the cpufreq cooling device with the name
482 * "cpufreq-%s". This API can support multiple instances of cpufreq
483 * cooling devices. It also gives the opportunity to link the cooling device
504 return ERR_PTR(-EINVAL); in __cpufreq_cooling_register()
507 dev = get_cpu_device(policy->cpu); in __cpufreq_cooling_register()
509 pr_warn("No cpu device for cpu %d\n", policy->cpu); in __cpufreq_cooling_register()
510 return ERR_PTR(-ENODEV); in __cpufreq_cooling_register()
517 return ERR_PTR(-ENODEV); in __cpufreq_cooling_register()
522 return ERR_PTR(-ENOMEM); in __cpufreq_cooling_register()
524 cpufreq_cdev->policy = policy; in __cpufreq_cooling_register()
533 cpufreq_cdev->max_level = i - 1; in __cpufreq_cooling_register()
535 cooling_ops = &cpufreq_cdev->cooling_ops; in __cpufreq_cooling_register()
536 cooling_ops->get_max_state = cpufreq_get_max_state; in __cpufreq_cooling_register()
537 cooling_ops->get_cur_state = cpufreq_get_cur_state; in __cpufreq_cooling_register()
538 cooling_ops->set_cur_state = cpufreq_set_cur_state; in __cpufreq_cooling_register()
542 cpufreq_cdev->em = em; in __cpufreq_cooling_register()
543 cooling_ops->get_requested_power = cpufreq_get_requested_power; in __cpufreq_cooling_register()
544 cooling_ops->state2power = cpufreq_state2power; in __cpufreq_cooling_register()
545 cooling_ops->power2state = cpufreq_power2state; in __cpufreq_cooling_register()
548 if (policy->freq_table_sorted == CPUFREQ_TABLE_UNSORTED) { in __cpufreq_cooling_register()
551 cdev = ERR_PTR(-EINVAL); in __cpufreq_cooling_register()
555 ret = freq_qos_add_request(&policy->constraints, in __cpufreq_cooling_register()
556 &cpufreq_cdev->qos_req, FREQ_QOS_MAX, in __cpufreq_cooling_register()
565 cdev = ERR_PTR(-ENOMEM); in __cpufreq_cooling_register()
566 name = kasprintf(GFP_KERNEL, "cpufreq-%s", dev_name(dev)); in __cpufreq_cooling_register()
580 freq_qos_remove_request(&cpufreq_cdev->qos_req); in __cpufreq_cooling_register()
589 * cpufreq_cooling_register - function to create cpufreq cooling device.
592 * This interface function registers the cpufreq cooling device with the name
593 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
607 * of_cpufreq_cooling_register - function to create cpufreq cooling device.
610 * This interface function registers the cpufreq cooling device with the name
611 * "cpufreq-%s". This API can support multiple instances of cpufreq cooling
612 * devices. Using this API, the cpufreq cooling device will be linked to the
615 * Using this function, the cooling device will implement the power
625 struct device_node *np = of_get_cpu_node(policy->cpu, NULL); in of_cpufreq_cooling_register()
630 policy->cpu); in of_cpufreq_cooling_register()
634 if (of_property_present(np, "#cooling-cells")) { in of_cpufreq_cooling_register()
635 struct em_perf_domain *em = em_cpu_get(policy->cpu); in of_cpufreq_cooling_register()
639 pr_err("cpufreq_cooling: cpu%d failed to register as cooling device: %ld\n", in of_cpufreq_cooling_register()
640 policy->cpu, PTR_ERR(cdev)); in of_cpufreq_cooling_register()
651 * cpufreq_cooling_unregister - function to remove cpufreq cooling device.
652 * @cdev: thermal cooling device pointer.
654 * This interface function unregisters the "cpufreq-%x" cooling device.
663 cpufreq_cdev = cdev->devdata; in cpufreq_cooling_unregister()
666 freq_qos_remove_request(&cpufreq_cdev->qos_req); in cpufreq_cooling_unregister()