10de967f2SLukasz Luba // SPDX-License-Identifier: GPL-2.0 20015d9a2SAmit Kucheria /* 30015d9a2SAmit Kucheria * A power allocator to manage temperature 40015d9a2SAmit Kucheria * 50015d9a2SAmit Kucheria * Copyright (C) 2014 ARM Ltd. 60015d9a2SAmit Kucheria * 70015d9a2SAmit Kucheria */ 80015d9a2SAmit Kucheria 90015d9a2SAmit Kucheria #define pr_fmt(fmt) "Power allocator: " fmt 100015d9a2SAmit Kucheria 110015d9a2SAmit Kucheria #include <linux/rculist.h> 120015d9a2SAmit Kucheria #include <linux/slab.h> 130015d9a2SAmit Kucheria #include <linux/thermal.h> 140015d9a2SAmit Kucheria 150015d9a2SAmit Kucheria #define CREATE_TRACE_POINTS 160015d9a2SAmit Kucheria #include <trace/events/thermal_power_allocator.h> 170015d9a2SAmit Kucheria 180015d9a2SAmit Kucheria #include "thermal_core.h" 190015d9a2SAmit Kucheria 200015d9a2SAmit Kucheria #define INVALID_TRIP -1 210015d9a2SAmit Kucheria 220015d9a2SAmit Kucheria #define FRAC_BITS 10 230015d9a2SAmit Kucheria #define int_to_frac(x) ((x) << FRAC_BITS) 240015d9a2SAmit Kucheria #define frac_to_int(x) ((x) >> FRAC_BITS) 250015d9a2SAmit Kucheria 260015d9a2SAmit Kucheria /** 270015d9a2SAmit Kucheria * mul_frac() - multiply two fixed-point numbers 280015d9a2SAmit Kucheria * @x: first multiplicand 290015d9a2SAmit Kucheria * @y: second multiplicand 300015d9a2SAmit Kucheria * 310015d9a2SAmit Kucheria * Return: the result of multiplying two fixed-point numbers. The 320015d9a2SAmit Kucheria * result is also a fixed-point number. 330015d9a2SAmit Kucheria */ 340015d9a2SAmit Kucheria static inline s64 mul_frac(s64 x, s64 y) 350015d9a2SAmit Kucheria { 360015d9a2SAmit Kucheria return (x * y) >> FRAC_BITS; 370015d9a2SAmit Kucheria } 380015d9a2SAmit Kucheria 390015d9a2SAmit Kucheria /** 400015d9a2SAmit Kucheria * div_frac() - divide two fixed-point numbers 410015d9a2SAmit Kucheria * @x: the dividend 420015d9a2SAmit Kucheria * @y: the divisor 430015d9a2SAmit Kucheria * 440015d9a2SAmit Kucheria * Return: the result of dividing two fixed-point numbers. The 450015d9a2SAmit Kucheria * result is also a fixed-point number. 460015d9a2SAmit Kucheria */ 470015d9a2SAmit Kucheria static inline s64 div_frac(s64 x, s64 y) 480015d9a2SAmit Kucheria { 490015d9a2SAmit Kucheria return div_s64(x << FRAC_BITS, y); 500015d9a2SAmit Kucheria } 510015d9a2SAmit Kucheria 520015d9a2SAmit Kucheria /** 530015d9a2SAmit Kucheria * struct power_allocator_params - parameters for the power allocator governor 540015d9a2SAmit Kucheria * @allocated_tzp: whether we have allocated tzp for this thermal zone and 550015d9a2SAmit Kucheria * it needs to be freed on unbind 560015d9a2SAmit Kucheria * @err_integral: accumulated error in the PID controller. 570015d9a2SAmit Kucheria * @prev_err: error in the previous iteration of the PID controller. 580015d9a2SAmit Kucheria * Used to calculate the derivative term. 590015d9a2SAmit Kucheria * @trip_switch_on: first passive trip point of the thermal zone. The 600015d9a2SAmit Kucheria * governor switches on when this trip point is crossed. 610015d9a2SAmit Kucheria * If the thermal zone only has one passive trip point, 620015d9a2SAmit Kucheria * @trip_switch_on should be INVALID_TRIP. 630015d9a2SAmit Kucheria * @trip_max_desired_temperature: last passive trip point of the thermal 640015d9a2SAmit Kucheria * zone. The temperature we are 650015d9a2SAmit Kucheria * controlling for. 66eda1ecfaSLukasz Luba * @sustainable_power: Sustainable power (heat) that this thermal zone can 67eda1ecfaSLukasz Luba * dissipate 680015d9a2SAmit Kucheria */ 690015d9a2SAmit Kucheria struct power_allocator_params { 700015d9a2SAmit Kucheria bool allocated_tzp; 710015d9a2SAmit Kucheria s64 err_integral; 720015d9a2SAmit Kucheria s32 prev_err; 730015d9a2SAmit Kucheria int trip_switch_on; 740015d9a2SAmit Kucheria int trip_max_desired_temperature; 75eda1ecfaSLukasz Luba u32 sustainable_power; 760015d9a2SAmit Kucheria }; 770015d9a2SAmit Kucheria 780015d9a2SAmit Kucheria /** 790015d9a2SAmit Kucheria * estimate_sustainable_power() - Estimate the sustainable power of a thermal zone 800015d9a2SAmit Kucheria * @tz: thermal zone we are operating in 810015d9a2SAmit Kucheria * 820015d9a2SAmit Kucheria * For thermal zones that don't provide a sustainable_power in their 830015d9a2SAmit Kucheria * thermal_zone_params, estimate one. Calculate it using the minimum 840015d9a2SAmit Kucheria * power of all the cooling devices as that gives a valid value that 850015d9a2SAmit Kucheria * can give some degree of functionality. For optimal performance of 860015d9a2SAmit Kucheria * this governor, provide a sustainable_power in the thermal zone's 870015d9a2SAmit Kucheria * thermal_zone_params. 880015d9a2SAmit Kucheria */ 890015d9a2SAmit Kucheria static u32 estimate_sustainable_power(struct thermal_zone_device *tz) 900015d9a2SAmit Kucheria { 910015d9a2SAmit Kucheria u32 sustainable_power = 0; 920015d9a2SAmit Kucheria struct thermal_instance *instance; 930015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 940015d9a2SAmit Kucheria 950015d9a2SAmit Kucheria list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 960015d9a2SAmit Kucheria struct thermal_cooling_device *cdev = instance->cdev; 970015d9a2SAmit Kucheria u32 min_power; 980015d9a2SAmit Kucheria 990015d9a2SAmit Kucheria if (instance->trip != params->trip_max_desired_temperature) 1000015d9a2SAmit Kucheria continue; 1010015d9a2SAmit Kucheria 1028132df3aSLukasz Luba if (!cdev_is_power_actor(cdev)) 1038132df3aSLukasz Luba continue; 1048132df3aSLukasz Luba 1058132df3aSLukasz Luba if (cdev->ops->state2power(cdev, instance->upper, &min_power)) 1060015d9a2SAmit Kucheria continue; 1070015d9a2SAmit Kucheria 1080015d9a2SAmit Kucheria sustainable_power += min_power; 1090015d9a2SAmit Kucheria } 1100015d9a2SAmit Kucheria 1110015d9a2SAmit Kucheria return sustainable_power; 1120015d9a2SAmit Kucheria } 1130015d9a2SAmit Kucheria 1140015d9a2SAmit Kucheria /** 1150015d9a2SAmit Kucheria * estimate_pid_constants() - Estimate the constants for the PID controller 1160015d9a2SAmit Kucheria * @tz: thermal zone for which to estimate the constants 1170015d9a2SAmit Kucheria * @sustainable_power: sustainable power for the thermal zone 1180015d9a2SAmit Kucheria * @trip_switch_on: trip point number for the switch on temperature 1190015d9a2SAmit Kucheria * @control_temp: target temperature for the power allocator governor 1200015d9a2SAmit Kucheria * 1210015d9a2SAmit Kucheria * This function is used to update the estimation of the PID 1220015d9a2SAmit Kucheria * controller constants in struct thermal_zone_parameters. 1230015d9a2SAmit Kucheria */ 1240015d9a2SAmit Kucheria static void estimate_pid_constants(struct thermal_zone_device *tz, 1250015d9a2SAmit Kucheria u32 sustainable_power, int trip_switch_on, 12690a99654SLukasz Luba int control_temp) 1270015d9a2SAmit Kucheria { 1280015d9a2SAmit Kucheria int ret; 1290015d9a2SAmit Kucheria int switch_on_temp; 1300015d9a2SAmit Kucheria u32 temperature_threshold; 131e34a7233SLukasz Luba s32 k_i; 1320015d9a2SAmit Kucheria 1330015d9a2SAmit Kucheria ret = tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); 1340015d9a2SAmit Kucheria if (ret) 1350015d9a2SAmit Kucheria switch_on_temp = 0; 1360015d9a2SAmit Kucheria 1370015d9a2SAmit Kucheria temperature_threshold = control_temp - switch_on_temp; 1380015d9a2SAmit Kucheria /* 1390015d9a2SAmit Kucheria * estimate_pid_constants() tries to find appropriate default 1400015d9a2SAmit Kucheria * values for thermal zones that don't provide them. If a 1410015d9a2SAmit Kucheria * system integrator has configured a thermal zone with two 1420015d9a2SAmit Kucheria * passive trip points at the same temperature, that person 1430015d9a2SAmit Kucheria * hasn't put any effort to set up the thermal zone properly 1440015d9a2SAmit Kucheria * so just give up. 1450015d9a2SAmit Kucheria */ 1460015d9a2SAmit Kucheria if (!temperature_threshold) 1470015d9a2SAmit Kucheria return; 1480015d9a2SAmit Kucheria 1490015d9a2SAmit Kucheria tz->tzp->k_po = int_to_frac(sustainable_power) / 1500015d9a2SAmit Kucheria temperature_threshold; 1510015d9a2SAmit Kucheria 1520015d9a2SAmit Kucheria tz->tzp->k_pu = int_to_frac(2 * sustainable_power) / 1530015d9a2SAmit Kucheria temperature_threshold; 1540015d9a2SAmit Kucheria 155e34a7233SLukasz Luba k_i = tz->tzp->k_pu / 10; 156e34a7233SLukasz Luba tz->tzp->k_i = k_i > 0 ? k_i : 1; 157e34a7233SLukasz Luba 1580015d9a2SAmit Kucheria /* 1590015d9a2SAmit Kucheria * The default for k_d and integral_cutoff is 0, so we can 1600015d9a2SAmit Kucheria * leave them as they are. 1610015d9a2SAmit Kucheria */ 1620015d9a2SAmit Kucheria } 1630015d9a2SAmit Kucheria 1640015d9a2SAmit Kucheria /** 165eda1ecfaSLukasz Luba * get_sustainable_power() - Get the right sustainable power 166eda1ecfaSLukasz Luba * @tz: thermal zone for which to estimate the constants 167eda1ecfaSLukasz Luba * @params: parameters for the power allocator governor 168eda1ecfaSLukasz Luba * @control_temp: target temperature for the power allocator governor 169eda1ecfaSLukasz Luba * 170eda1ecfaSLukasz Luba * This function is used for getting the proper sustainable power value based 171eda1ecfaSLukasz Luba * on variables which might be updated by the user sysfs interface. If that 172eda1ecfaSLukasz Luba * happen the new value is going to be estimated and updated. It is also used 173eda1ecfaSLukasz Luba * after thermal zone binding, where the initial values where set to 0. 174eda1ecfaSLukasz Luba */ 175eda1ecfaSLukasz Luba static u32 get_sustainable_power(struct thermal_zone_device *tz, 176eda1ecfaSLukasz Luba struct power_allocator_params *params, 177eda1ecfaSLukasz Luba int control_temp) 178eda1ecfaSLukasz Luba { 179eda1ecfaSLukasz Luba u32 sustainable_power; 180eda1ecfaSLukasz Luba 181eda1ecfaSLukasz Luba if (!tz->tzp->sustainable_power) 182eda1ecfaSLukasz Luba sustainable_power = estimate_sustainable_power(tz); 183eda1ecfaSLukasz Luba else 184eda1ecfaSLukasz Luba sustainable_power = tz->tzp->sustainable_power; 185eda1ecfaSLukasz Luba 186eda1ecfaSLukasz Luba /* Check if it's init value 0 or there was update via sysfs */ 187eda1ecfaSLukasz Luba if (sustainable_power != params->sustainable_power) { 188eda1ecfaSLukasz Luba estimate_pid_constants(tz, sustainable_power, 18990a99654SLukasz Luba params->trip_switch_on, control_temp); 190eda1ecfaSLukasz Luba 191eda1ecfaSLukasz Luba /* Do the estimation only once and make available in sysfs */ 192eda1ecfaSLukasz Luba tz->tzp->sustainable_power = sustainable_power; 193eda1ecfaSLukasz Luba params->sustainable_power = sustainable_power; 194eda1ecfaSLukasz Luba } 195eda1ecfaSLukasz Luba 196eda1ecfaSLukasz Luba return sustainable_power; 197eda1ecfaSLukasz Luba } 198eda1ecfaSLukasz Luba 199eda1ecfaSLukasz Luba /** 2000015d9a2SAmit Kucheria * pid_controller() - PID controller 2010015d9a2SAmit Kucheria * @tz: thermal zone we are operating in 2020015d9a2SAmit Kucheria * @control_temp: the target temperature in millicelsius 2030015d9a2SAmit Kucheria * @max_allocatable_power: maximum allocatable power for this thermal zone 2040015d9a2SAmit Kucheria * 2050015d9a2SAmit Kucheria * This PID controller increases the available power budget so that the 2060015d9a2SAmit Kucheria * temperature of the thermal zone gets as close as possible to 2070015d9a2SAmit Kucheria * @control_temp and limits the power if it exceeds it. k_po is the 2080015d9a2SAmit Kucheria * proportional term when we are overshooting, k_pu is the 2090015d9a2SAmit Kucheria * proportional term when we are undershooting. integral_cutoff is a 2100015d9a2SAmit Kucheria * threshold below which we stop accumulating the error. The 2110015d9a2SAmit Kucheria * accumulated error is only valid if the requested power will make 2120015d9a2SAmit Kucheria * the system warmer. If the system is mostly idle, there's no point 2130015d9a2SAmit Kucheria * in accumulating positive error. 2140015d9a2SAmit Kucheria * 2150015d9a2SAmit Kucheria * Return: The power budget for the next period. 2160015d9a2SAmit Kucheria */ 2170015d9a2SAmit Kucheria static u32 pid_controller(struct thermal_zone_device *tz, 2180015d9a2SAmit Kucheria int control_temp, 2190015d9a2SAmit Kucheria u32 max_allocatable_power) 2200015d9a2SAmit Kucheria { 2210015d9a2SAmit Kucheria s64 p, i, d, power_range; 2220015d9a2SAmit Kucheria s32 err, max_power_frac; 2230015d9a2SAmit Kucheria u32 sustainable_power; 2240015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 2250015d9a2SAmit Kucheria 2260015d9a2SAmit Kucheria max_power_frac = int_to_frac(max_allocatable_power); 2270015d9a2SAmit Kucheria 228eda1ecfaSLukasz Luba sustainable_power = get_sustainable_power(tz, params, control_temp); 2290015d9a2SAmit Kucheria 2300015d9a2SAmit Kucheria err = control_temp - tz->temperature; 2310015d9a2SAmit Kucheria err = int_to_frac(err); 2320015d9a2SAmit Kucheria 2330015d9a2SAmit Kucheria /* Calculate the proportional term */ 2340015d9a2SAmit Kucheria p = mul_frac(err < 0 ? tz->tzp->k_po : tz->tzp->k_pu, err); 2350015d9a2SAmit Kucheria 2360015d9a2SAmit Kucheria /* 2370015d9a2SAmit Kucheria * Calculate the integral term 2380015d9a2SAmit Kucheria * 2390015d9a2SAmit Kucheria * if the error is less than cut off allow integration (but 2400015d9a2SAmit Kucheria * the integral is limited to max power) 2410015d9a2SAmit Kucheria */ 2420015d9a2SAmit Kucheria i = mul_frac(tz->tzp->k_i, params->err_integral); 2430015d9a2SAmit Kucheria 2440015d9a2SAmit Kucheria if (err < int_to_frac(tz->tzp->integral_cutoff)) { 2450015d9a2SAmit Kucheria s64 i_next = i + mul_frac(tz->tzp->k_i, err); 2460015d9a2SAmit Kucheria 2470015d9a2SAmit Kucheria if (abs(i_next) < max_power_frac) { 2480015d9a2SAmit Kucheria i = i_next; 2490015d9a2SAmit Kucheria params->err_integral += err; 2500015d9a2SAmit Kucheria } 2510015d9a2SAmit Kucheria } 2520015d9a2SAmit Kucheria 2530015d9a2SAmit Kucheria /* 2540015d9a2SAmit Kucheria * Calculate the derivative term 2550015d9a2SAmit Kucheria * 2560015d9a2SAmit Kucheria * We do err - prev_err, so with a positive k_d, a decreasing 2570015d9a2SAmit Kucheria * error (i.e. driving closer to the line) results in less 2580015d9a2SAmit Kucheria * power being applied, slowing down the controller) 2590015d9a2SAmit Kucheria */ 2600015d9a2SAmit Kucheria d = mul_frac(tz->tzp->k_d, err - params->prev_err); 261b39d2dd5SDaniel Lezcano d = div_frac(d, jiffies_to_msecs(tz->passive_delay_jiffies)); 2620015d9a2SAmit Kucheria params->prev_err = err; 2630015d9a2SAmit Kucheria 2640015d9a2SAmit Kucheria power_range = p + i + d; 2650015d9a2SAmit Kucheria 2660015d9a2SAmit Kucheria /* feed-forward the known sustainable dissipatable power */ 2670015d9a2SAmit Kucheria power_range = sustainable_power + frac_to_int(power_range); 2680015d9a2SAmit Kucheria 2690015d9a2SAmit Kucheria power_range = clamp(power_range, (s64)0, (s64)max_allocatable_power); 2700015d9a2SAmit Kucheria 2710015d9a2SAmit Kucheria trace_thermal_power_allocator_pid(tz, frac_to_int(err), 2720015d9a2SAmit Kucheria frac_to_int(params->err_integral), 2730015d9a2SAmit Kucheria frac_to_int(p), frac_to_int(i), 2740015d9a2SAmit Kucheria frac_to_int(d), power_range); 2750015d9a2SAmit Kucheria 2760015d9a2SAmit Kucheria return power_range; 2770015d9a2SAmit Kucheria } 2780015d9a2SAmit Kucheria 2790015d9a2SAmit Kucheria /** 280345a8af7SLukasz Luba * power_actor_set_power() - limit the maximum power a cooling device consumes 281345a8af7SLukasz Luba * @cdev: pointer to &thermal_cooling_device 282345a8af7SLukasz Luba * @instance: thermal instance to update 283345a8af7SLukasz Luba * @power: the power in milliwatts 284345a8af7SLukasz Luba * 285345a8af7SLukasz Luba * Set the cooling device to consume at most @power milliwatts. The limit is 286345a8af7SLukasz Luba * expected to be a cap at the maximum power consumption. 287345a8af7SLukasz Luba * 288345a8af7SLukasz Luba * Return: 0 on success, -EINVAL if the cooling device does not 289345a8af7SLukasz Luba * implement the power actor API or -E* for other failures. 290345a8af7SLukasz Luba */ 291345a8af7SLukasz Luba static int 292345a8af7SLukasz Luba power_actor_set_power(struct thermal_cooling_device *cdev, 293345a8af7SLukasz Luba struct thermal_instance *instance, u32 power) 294345a8af7SLukasz Luba { 295345a8af7SLukasz Luba unsigned long state; 296345a8af7SLukasz Luba int ret; 297345a8af7SLukasz Luba 298345a8af7SLukasz Luba ret = cdev->ops->power2state(cdev, power, &state); 299345a8af7SLukasz Luba if (ret) 300345a8af7SLukasz Luba return ret; 301345a8af7SLukasz Luba 302345a8af7SLukasz Luba instance->target = clamp_val(state, instance->lower, instance->upper); 303345a8af7SLukasz Luba mutex_lock(&cdev->lock); 304ab39c885SLukasz Luba __thermal_cdev_update(cdev); 305345a8af7SLukasz Luba mutex_unlock(&cdev->lock); 306345a8af7SLukasz Luba 307345a8af7SLukasz Luba return 0; 308345a8af7SLukasz Luba } 309345a8af7SLukasz Luba 310345a8af7SLukasz Luba /** 3110015d9a2SAmit Kucheria * divvy_up_power() - divvy the allocated power between the actors 3120015d9a2SAmit Kucheria * @req_power: each actor's requested power 3130015d9a2SAmit Kucheria * @max_power: each actor's maximum available power 3140015d9a2SAmit Kucheria * @num_actors: size of the @req_power, @max_power and @granted_power's array 3150015d9a2SAmit Kucheria * @total_req_power: sum of @req_power 3160015d9a2SAmit Kucheria * @power_range: total allocated power 3170015d9a2SAmit Kucheria * @granted_power: output array: each actor's granted power 3180015d9a2SAmit Kucheria * @extra_actor_power: an appropriately sized array to be used in the 3190015d9a2SAmit Kucheria * function as temporary storage of the extra power given 3200015d9a2SAmit Kucheria * to the actors 3210015d9a2SAmit Kucheria * 3220015d9a2SAmit Kucheria * This function divides the total allocated power (@power_range) 3230015d9a2SAmit Kucheria * fairly between the actors. It first tries to give each actor a 3240015d9a2SAmit Kucheria * share of the @power_range according to how much power it requested 3250015d9a2SAmit Kucheria * compared to the rest of the actors. For example, if only one actor 3260015d9a2SAmit Kucheria * requests power, then it receives all the @power_range. If 3270015d9a2SAmit Kucheria * three actors each requests 1mW, each receives a third of the 3280015d9a2SAmit Kucheria * @power_range. 3290015d9a2SAmit Kucheria * 3300015d9a2SAmit Kucheria * If any actor received more than their maximum power, then that 3310015d9a2SAmit Kucheria * surplus is re-divvied among the actors based on how far they are 3320015d9a2SAmit Kucheria * from their respective maximums. 3330015d9a2SAmit Kucheria * 3340015d9a2SAmit Kucheria * Granted power for each actor is written to @granted_power, which 3350015d9a2SAmit Kucheria * should've been allocated by the calling function. 3360015d9a2SAmit Kucheria */ 3370015d9a2SAmit Kucheria static void divvy_up_power(u32 *req_power, u32 *max_power, int num_actors, 3380015d9a2SAmit Kucheria u32 total_req_power, u32 power_range, 3390015d9a2SAmit Kucheria u32 *granted_power, u32 *extra_actor_power) 3400015d9a2SAmit Kucheria { 3410015d9a2SAmit Kucheria u32 extra_power, capped_extra_power; 3420015d9a2SAmit Kucheria int i; 3430015d9a2SAmit Kucheria 3440015d9a2SAmit Kucheria /* 3450015d9a2SAmit Kucheria * Prevent division by 0 if none of the actors request power. 3460015d9a2SAmit Kucheria */ 3470015d9a2SAmit Kucheria if (!total_req_power) 3480015d9a2SAmit Kucheria total_req_power = 1; 3490015d9a2SAmit Kucheria 3500015d9a2SAmit Kucheria capped_extra_power = 0; 3510015d9a2SAmit Kucheria extra_power = 0; 3520015d9a2SAmit Kucheria for (i = 0; i < num_actors; i++) { 3530015d9a2SAmit Kucheria u64 req_range = (u64)req_power[i] * power_range; 3540015d9a2SAmit Kucheria 3550015d9a2SAmit Kucheria granted_power[i] = DIV_ROUND_CLOSEST_ULL(req_range, 3560015d9a2SAmit Kucheria total_req_power); 3570015d9a2SAmit Kucheria 3580015d9a2SAmit Kucheria if (granted_power[i] > max_power[i]) { 3590015d9a2SAmit Kucheria extra_power += granted_power[i] - max_power[i]; 3600015d9a2SAmit Kucheria granted_power[i] = max_power[i]; 3610015d9a2SAmit Kucheria } 3620015d9a2SAmit Kucheria 3630015d9a2SAmit Kucheria extra_actor_power[i] = max_power[i] - granted_power[i]; 3640015d9a2SAmit Kucheria capped_extra_power += extra_actor_power[i]; 3650015d9a2SAmit Kucheria } 3660015d9a2SAmit Kucheria 3670015d9a2SAmit Kucheria if (!extra_power) 3680015d9a2SAmit Kucheria return; 3690015d9a2SAmit Kucheria 3700015d9a2SAmit Kucheria /* 3710015d9a2SAmit Kucheria * Re-divvy the reclaimed extra among actors based on 3720015d9a2SAmit Kucheria * how far they are from the max 3730015d9a2SAmit Kucheria */ 3740015d9a2SAmit Kucheria extra_power = min(extra_power, capped_extra_power); 3750015d9a2SAmit Kucheria if (capped_extra_power > 0) 3766e3e14c9Sjeson.gao for (i = 0; i < num_actors; i++) { 3776e3e14c9Sjeson.gao u64 extra_range = (u64)extra_actor_power[i] * extra_power; 3786e3e14c9Sjeson.gao granted_power[i] += DIV_ROUND_CLOSEST_ULL(extra_range, 3796e3e14c9Sjeson.gao capped_extra_power); 3806e3e14c9Sjeson.gao } 3810015d9a2SAmit Kucheria } 3820015d9a2SAmit Kucheria 3830015d9a2SAmit Kucheria static int allocate_power(struct thermal_zone_device *tz, 3840015d9a2SAmit Kucheria int control_temp) 3850015d9a2SAmit Kucheria { 3860015d9a2SAmit Kucheria struct thermal_instance *instance; 3870015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 3880015d9a2SAmit Kucheria u32 *req_power, *max_power, *granted_power, *extra_actor_power; 3890015d9a2SAmit Kucheria u32 *weighted_req_power; 3900015d9a2SAmit Kucheria u32 total_req_power, max_allocatable_power, total_weighted_req_power; 3910015d9a2SAmit Kucheria u32 total_granted_power, power_range; 3920015d9a2SAmit Kucheria int i, num_actors, total_weight, ret = 0; 3930015d9a2SAmit Kucheria int trip_max_desired_temperature = params->trip_max_desired_temperature; 3940015d9a2SAmit Kucheria 3950015d9a2SAmit Kucheria num_actors = 0; 3960015d9a2SAmit Kucheria total_weight = 0; 3970015d9a2SAmit Kucheria list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 3980015d9a2SAmit Kucheria if ((instance->trip == trip_max_desired_temperature) && 3990015d9a2SAmit Kucheria cdev_is_power_actor(instance->cdev)) { 4000015d9a2SAmit Kucheria num_actors++; 4010015d9a2SAmit Kucheria total_weight += instance->weight; 4020015d9a2SAmit Kucheria } 4030015d9a2SAmit Kucheria } 4040015d9a2SAmit Kucheria 405*63561fe3SDaniel Lezcano if (!num_actors) 406*63561fe3SDaniel Lezcano return -ENODEV; 4070015d9a2SAmit Kucheria 4080015d9a2SAmit Kucheria /* 4090015d9a2SAmit Kucheria * We need to allocate five arrays of the same size: 4100015d9a2SAmit Kucheria * req_power, max_power, granted_power, extra_actor_power and 4110015d9a2SAmit Kucheria * weighted_req_power. They are going to be needed until this 4120015d9a2SAmit Kucheria * function returns. Allocate them all in one go to simplify 4130015d9a2SAmit Kucheria * the allocation and deallocation logic. 4140015d9a2SAmit Kucheria */ 4150015d9a2SAmit Kucheria BUILD_BUG_ON(sizeof(*req_power) != sizeof(*max_power)); 4160015d9a2SAmit Kucheria BUILD_BUG_ON(sizeof(*req_power) != sizeof(*granted_power)); 4170015d9a2SAmit Kucheria BUILD_BUG_ON(sizeof(*req_power) != sizeof(*extra_actor_power)); 4180015d9a2SAmit Kucheria BUILD_BUG_ON(sizeof(*req_power) != sizeof(*weighted_req_power)); 4190015d9a2SAmit Kucheria req_power = kcalloc(num_actors * 5, sizeof(*req_power), GFP_KERNEL); 420*63561fe3SDaniel Lezcano if (!req_power) 421*63561fe3SDaniel Lezcano return -ENOMEM; 4220015d9a2SAmit Kucheria 4230015d9a2SAmit Kucheria max_power = &req_power[num_actors]; 4240015d9a2SAmit Kucheria granted_power = &req_power[2 * num_actors]; 4250015d9a2SAmit Kucheria extra_actor_power = &req_power[3 * num_actors]; 4260015d9a2SAmit Kucheria weighted_req_power = &req_power[4 * num_actors]; 4270015d9a2SAmit Kucheria 4280015d9a2SAmit Kucheria i = 0; 4290015d9a2SAmit Kucheria total_weighted_req_power = 0; 4300015d9a2SAmit Kucheria total_req_power = 0; 4310015d9a2SAmit Kucheria max_allocatable_power = 0; 4320015d9a2SAmit Kucheria 4330015d9a2SAmit Kucheria list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 4340015d9a2SAmit Kucheria int weight; 4350015d9a2SAmit Kucheria struct thermal_cooling_device *cdev = instance->cdev; 4360015d9a2SAmit Kucheria 4370015d9a2SAmit Kucheria if (instance->trip != trip_max_desired_temperature) 4380015d9a2SAmit Kucheria continue; 4390015d9a2SAmit Kucheria 4400015d9a2SAmit Kucheria if (!cdev_is_power_actor(cdev)) 4410015d9a2SAmit Kucheria continue; 4420015d9a2SAmit Kucheria 443ecd1d2a3Szhuguangqing if (cdev->ops->get_requested_power(cdev, &req_power[i])) 4440015d9a2SAmit Kucheria continue; 4450015d9a2SAmit Kucheria 4460015d9a2SAmit Kucheria if (!total_weight) 4470015d9a2SAmit Kucheria weight = 1 << FRAC_BITS; 4480015d9a2SAmit Kucheria else 4490015d9a2SAmit Kucheria weight = instance->weight; 4500015d9a2SAmit Kucheria 4510015d9a2SAmit Kucheria weighted_req_power[i] = frac_to_int(weight * req_power[i]); 4520015d9a2SAmit Kucheria 4538132df3aSLukasz Luba if (cdev->ops->state2power(cdev, instance->lower, 4548132df3aSLukasz Luba &max_power[i])) 4550015d9a2SAmit Kucheria continue; 4560015d9a2SAmit Kucheria 4570015d9a2SAmit Kucheria total_req_power += req_power[i]; 4580015d9a2SAmit Kucheria max_allocatable_power += max_power[i]; 4590015d9a2SAmit Kucheria total_weighted_req_power += weighted_req_power[i]; 4600015d9a2SAmit Kucheria 4610015d9a2SAmit Kucheria i++; 4620015d9a2SAmit Kucheria } 4630015d9a2SAmit Kucheria 4640015d9a2SAmit Kucheria power_range = pid_controller(tz, control_temp, max_allocatable_power); 4650015d9a2SAmit Kucheria 4660015d9a2SAmit Kucheria divvy_up_power(weighted_req_power, max_power, num_actors, 4670015d9a2SAmit Kucheria total_weighted_req_power, power_range, granted_power, 4680015d9a2SAmit Kucheria extra_actor_power); 4690015d9a2SAmit Kucheria 4700015d9a2SAmit Kucheria total_granted_power = 0; 4710015d9a2SAmit Kucheria i = 0; 4720015d9a2SAmit Kucheria list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 4730015d9a2SAmit Kucheria if (instance->trip != trip_max_desired_temperature) 4740015d9a2SAmit Kucheria continue; 4750015d9a2SAmit Kucheria 4760015d9a2SAmit Kucheria if (!cdev_is_power_actor(instance->cdev)) 4770015d9a2SAmit Kucheria continue; 4780015d9a2SAmit Kucheria 4790015d9a2SAmit Kucheria power_actor_set_power(instance->cdev, instance, 4800015d9a2SAmit Kucheria granted_power[i]); 4810015d9a2SAmit Kucheria total_granted_power += granted_power[i]; 4820015d9a2SAmit Kucheria 4830015d9a2SAmit Kucheria i++; 4840015d9a2SAmit Kucheria } 4850015d9a2SAmit Kucheria 4860015d9a2SAmit Kucheria trace_thermal_power_allocator(tz, req_power, total_req_power, 4870015d9a2SAmit Kucheria granted_power, total_granted_power, 4880015d9a2SAmit Kucheria num_actors, power_range, 4890015d9a2SAmit Kucheria max_allocatable_power, tz->temperature, 4900015d9a2SAmit Kucheria control_temp - tz->temperature); 4910015d9a2SAmit Kucheria 4920015d9a2SAmit Kucheria kfree(req_power); 4930015d9a2SAmit Kucheria 4940015d9a2SAmit Kucheria return ret; 4950015d9a2SAmit Kucheria } 4960015d9a2SAmit Kucheria 4970015d9a2SAmit Kucheria /** 4980015d9a2SAmit Kucheria * get_governor_trips() - get the number of the two trip points that are key for this governor 4990015d9a2SAmit Kucheria * @tz: thermal zone to operate on 5000015d9a2SAmit Kucheria * @params: pointer to private data for this governor 5010015d9a2SAmit Kucheria * 5020015d9a2SAmit Kucheria * The power allocator governor works optimally with two trips points: 5030015d9a2SAmit Kucheria * a "switch on" trip point and a "maximum desired temperature". These 5040015d9a2SAmit Kucheria * are defined as the first and last passive trip points. 5050015d9a2SAmit Kucheria * 5060015d9a2SAmit Kucheria * If there is only one trip point, then that's considered to be the 5070015d9a2SAmit Kucheria * "maximum desired temperature" trip point and the governor is always 5080015d9a2SAmit Kucheria * on. If there are no passive or active trip points, then the 5090015d9a2SAmit Kucheria * governor won't do anything. In fact, its throttle function 5100015d9a2SAmit Kucheria * won't be called at all. 5110015d9a2SAmit Kucheria */ 5120015d9a2SAmit Kucheria static void get_governor_trips(struct thermal_zone_device *tz, 5130015d9a2SAmit Kucheria struct power_allocator_params *params) 5140015d9a2SAmit Kucheria { 5150015d9a2SAmit Kucheria int i, last_active, last_passive; 5160015d9a2SAmit Kucheria bool found_first_passive; 5170015d9a2SAmit Kucheria 5180015d9a2SAmit Kucheria found_first_passive = false; 5190015d9a2SAmit Kucheria last_active = INVALID_TRIP; 5200015d9a2SAmit Kucheria last_passive = INVALID_TRIP; 5210015d9a2SAmit Kucheria 522e5bfcd30SDaniel Lezcano for (i = 0; i < tz->num_trips; i++) { 5230015d9a2SAmit Kucheria enum thermal_trip_type type; 5240015d9a2SAmit Kucheria int ret; 5250015d9a2SAmit Kucheria 5260015d9a2SAmit Kucheria ret = tz->ops->get_trip_type(tz, i, &type); 5270015d9a2SAmit Kucheria if (ret) { 5280015d9a2SAmit Kucheria dev_warn(&tz->device, 5290015d9a2SAmit Kucheria "Failed to get trip point %d type: %d\n", i, 5300015d9a2SAmit Kucheria ret); 5310015d9a2SAmit Kucheria continue; 5320015d9a2SAmit Kucheria } 5330015d9a2SAmit Kucheria 5340015d9a2SAmit Kucheria if (type == THERMAL_TRIP_PASSIVE) { 5350015d9a2SAmit Kucheria if (!found_first_passive) { 5360015d9a2SAmit Kucheria params->trip_switch_on = i; 5370015d9a2SAmit Kucheria found_first_passive = true; 5380015d9a2SAmit Kucheria } else { 5390015d9a2SAmit Kucheria last_passive = i; 5400015d9a2SAmit Kucheria } 5410015d9a2SAmit Kucheria } else if (type == THERMAL_TRIP_ACTIVE) { 5420015d9a2SAmit Kucheria last_active = i; 5430015d9a2SAmit Kucheria } else { 5440015d9a2SAmit Kucheria break; 5450015d9a2SAmit Kucheria } 5460015d9a2SAmit Kucheria } 5470015d9a2SAmit Kucheria 5480015d9a2SAmit Kucheria if (last_passive != INVALID_TRIP) { 5490015d9a2SAmit Kucheria params->trip_max_desired_temperature = last_passive; 5500015d9a2SAmit Kucheria } else if (found_first_passive) { 5510015d9a2SAmit Kucheria params->trip_max_desired_temperature = params->trip_switch_on; 5520015d9a2SAmit Kucheria params->trip_switch_on = INVALID_TRIP; 5530015d9a2SAmit Kucheria } else { 5540015d9a2SAmit Kucheria params->trip_switch_on = INVALID_TRIP; 5550015d9a2SAmit Kucheria params->trip_max_desired_temperature = last_active; 5560015d9a2SAmit Kucheria } 5570015d9a2SAmit Kucheria } 5580015d9a2SAmit Kucheria 5590015d9a2SAmit Kucheria static void reset_pid_controller(struct power_allocator_params *params) 5600015d9a2SAmit Kucheria { 5610015d9a2SAmit Kucheria params->err_integral = 0; 5620015d9a2SAmit Kucheria params->prev_err = 0; 5630015d9a2SAmit Kucheria } 5640015d9a2SAmit Kucheria 5650952177fSLukasz Luba static void allow_maximum_power(struct thermal_zone_device *tz, bool update) 5660015d9a2SAmit Kucheria { 5670015d9a2SAmit Kucheria struct thermal_instance *instance; 5680015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 569d3b60ed9SLukasz Luba u32 req_power; 5700015d9a2SAmit Kucheria 5710015d9a2SAmit Kucheria list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 572d3b60ed9SLukasz Luba struct thermal_cooling_device *cdev = instance->cdev; 573d3b60ed9SLukasz Luba 5740015d9a2SAmit Kucheria if ((instance->trip != params->trip_max_desired_temperature) || 5750015d9a2SAmit Kucheria (!cdev_is_power_actor(instance->cdev))) 5760015d9a2SAmit Kucheria continue; 5770015d9a2SAmit Kucheria 5780015d9a2SAmit Kucheria instance->target = 0; 5790015d9a2SAmit Kucheria mutex_lock(&instance->cdev->lock); 580d3b60ed9SLukasz Luba /* 581d3b60ed9SLukasz Luba * Call for updating the cooling devices local stats and avoid 582d3b60ed9SLukasz Luba * periods of dozen of seconds when those have not been 583d3b60ed9SLukasz Luba * maintained. 584d3b60ed9SLukasz Luba */ 585d3b60ed9SLukasz Luba cdev->ops->get_requested_power(cdev, &req_power); 586d3b60ed9SLukasz Luba 5870952177fSLukasz Luba if (update) 5880952177fSLukasz Luba __thermal_cdev_update(instance->cdev); 5890952177fSLukasz Luba 5900015d9a2SAmit Kucheria mutex_unlock(&instance->cdev->lock); 5910015d9a2SAmit Kucheria } 5920015d9a2SAmit Kucheria } 5930015d9a2SAmit Kucheria 5940015d9a2SAmit Kucheria /** 5957a583405SLukasz Luba * check_power_actors() - Check all cooling devices and warn when they are 5967a583405SLukasz Luba * not power actors 5977a583405SLukasz Luba * @tz: thermal zone to operate on 5987a583405SLukasz Luba * 5997a583405SLukasz Luba * Check all cooling devices in the @tz and warn every time they are missing 6007a583405SLukasz Luba * power actor API. The warning should help to investigate the issue, which 6017a583405SLukasz Luba * could be e.g. lack of Energy Model for a given device. 6027a583405SLukasz Luba * 6037a583405SLukasz Luba * Return: 0 on success, -EINVAL if any cooling device does not implement 6047a583405SLukasz Luba * the power actor API. 6057a583405SLukasz Luba */ 6067a583405SLukasz Luba static int check_power_actors(struct thermal_zone_device *tz) 6077a583405SLukasz Luba { 6087a583405SLukasz Luba struct thermal_instance *instance; 6097a583405SLukasz Luba int ret = 0; 6107a583405SLukasz Luba 6117a583405SLukasz Luba list_for_each_entry(instance, &tz->thermal_instances, tz_node) { 6127a583405SLukasz Luba if (!cdev_is_power_actor(instance->cdev)) { 6137a583405SLukasz Luba dev_warn(&tz->device, "power_allocator: %s is not a power actor\n", 6147a583405SLukasz Luba instance->cdev->type); 6157a583405SLukasz Luba ret = -EINVAL; 6167a583405SLukasz Luba } 6177a583405SLukasz Luba } 6187a583405SLukasz Luba 6197a583405SLukasz Luba return ret; 6207a583405SLukasz Luba } 6217a583405SLukasz Luba 6227a583405SLukasz Luba /** 6230015d9a2SAmit Kucheria * power_allocator_bind() - bind the power_allocator governor to a thermal zone 6240015d9a2SAmit Kucheria * @tz: thermal zone to bind it to 6250015d9a2SAmit Kucheria * 6260015d9a2SAmit Kucheria * Initialize the PID controller parameters and bind it to the thermal 6270015d9a2SAmit Kucheria * zone. 6280015d9a2SAmit Kucheria * 6297a583405SLukasz Luba * Return: 0 on success, or -ENOMEM if we ran out of memory, or -EINVAL 6307a583405SLukasz Luba * when there are unsupported cooling devices in the @tz. 6310015d9a2SAmit Kucheria */ 6320015d9a2SAmit Kucheria static int power_allocator_bind(struct thermal_zone_device *tz) 6330015d9a2SAmit Kucheria { 6340015d9a2SAmit Kucheria int ret; 6350015d9a2SAmit Kucheria struct power_allocator_params *params; 6360015d9a2SAmit Kucheria int control_temp; 6370015d9a2SAmit Kucheria 6387a583405SLukasz Luba ret = check_power_actors(tz); 6397a583405SLukasz Luba if (ret) 6407a583405SLukasz Luba return ret; 6417a583405SLukasz Luba 6420015d9a2SAmit Kucheria params = kzalloc(sizeof(*params), GFP_KERNEL); 6430015d9a2SAmit Kucheria if (!params) 6440015d9a2SAmit Kucheria return -ENOMEM; 6450015d9a2SAmit Kucheria 6460015d9a2SAmit Kucheria if (!tz->tzp) { 6470015d9a2SAmit Kucheria tz->tzp = kzalloc(sizeof(*tz->tzp), GFP_KERNEL); 6480015d9a2SAmit Kucheria if (!tz->tzp) { 6490015d9a2SAmit Kucheria ret = -ENOMEM; 6500015d9a2SAmit Kucheria goto free_params; 6510015d9a2SAmit Kucheria } 6520015d9a2SAmit Kucheria 6530015d9a2SAmit Kucheria params->allocated_tzp = true; 6540015d9a2SAmit Kucheria } 6550015d9a2SAmit Kucheria 6560015d9a2SAmit Kucheria if (!tz->tzp->sustainable_power) 6570015d9a2SAmit Kucheria dev_warn(&tz->device, "power_allocator: sustainable_power will be estimated\n"); 6580015d9a2SAmit Kucheria 6590015d9a2SAmit Kucheria get_governor_trips(tz, params); 6600015d9a2SAmit Kucheria 661e5bfcd30SDaniel Lezcano if (tz->num_trips > 0) { 6620015d9a2SAmit Kucheria ret = tz->ops->get_trip_temp(tz, 6630015d9a2SAmit Kucheria params->trip_max_desired_temperature, 6640015d9a2SAmit Kucheria &control_temp); 6650015d9a2SAmit Kucheria if (!ret) 6660015d9a2SAmit Kucheria estimate_pid_constants(tz, tz->tzp->sustainable_power, 6670015d9a2SAmit Kucheria params->trip_switch_on, 66890a99654SLukasz Luba control_temp); 6690015d9a2SAmit Kucheria } 6700015d9a2SAmit Kucheria 6710015d9a2SAmit Kucheria reset_pid_controller(params); 6720015d9a2SAmit Kucheria 6730015d9a2SAmit Kucheria tz->governor_data = params; 6740015d9a2SAmit Kucheria 6750015d9a2SAmit Kucheria return 0; 6760015d9a2SAmit Kucheria 6770015d9a2SAmit Kucheria free_params: 6780015d9a2SAmit Kucheria kfree(params); 6790015d9a2SAmit Kucheria 6800015d9a2SAmit Kucheria return ret; 6810015d9a2SAmit Kucheria } 6820015d9a2SAmit Kucheria 6830015d9a2SAmit Kucheria static void power_allocator_unbind(struct thermal_zone_device *tz) 6840015d9a2SAmit Kucheria { 6850015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 6860015d9a2SAmit Kucheria 6870015d9a2SAmit Kucheria dev_dbg(&tz->device, "Unbinding from thermal zone %d\n", tz->id); 6880015d9a2SAmit Kucheria 6890015d9a2SAmit Kucheria if (params->allocated_tzp) { 6900015d9a2SAmit Kucheria kfree(tz->tzp); 6910015d9a2SAmit Kucheria tz->tzp = NULL; 6920015d9a2SAmit Kucheria } 6930015d9a2SAmit Kucheria 6940015d9a2SAmit Kucheria kfree(tz->governor_data); 6950015d9a2SAmit Kucheria tz->governor_data = NULL; 6960015d9a2SAmit Kucheria } 6970015d9a2SAmit Kucheria 6980015d9a2SAmit Kucheria static int power_allocator_throttle(struct thermal_zone_device *tz, int trip) 6990015d9a2SAmit Kucheria { 700*63561fe3SDaniel Lezcano int ret = 0; 7010015d9a2SAmit Kucheria int switch_on_temp, control_temp; 7020015d9a2SAmit Kucheria struct power_allocator_params *params = tz->governor_data; 7030952177fSLukasz Luba bool update; 7040015d9a2SAmit Kucheria 705*63561fe3SDaniel Lezcano mutex_lock(&tz->lock); 706*63561fe3SDaniel Lezcano 7070015d9a2SAmit Kucheria /* 7080015d9a2SAmit Kucheria * We get called for every trip point but we only need to do 7090015d9a2SAmit Kucheria * our calculations once 7100015d9a2SAmit Kucheria */ 7110015d9a2SAmit Kucheria if (trip != params->trip_max_desired_temperature) 712*63561fe3SDaniel Lezcano goto out; 7130015d9a2SAmit Kucheria 7140015d9a2SAmit Kucheria ret = tz->ops->get_trip_temp(tz, params->trip_switch_on, 7150015d9a2SAmit Kucheria &switch_on_temp); 7160015d9a2SAmit Kucheria if (!ret && (tz->temperature < switch_on_temp)) { 7170952177fSLukasz Luba update = (tz->last_temperature >= switch_on_temp); 7180015d9a2SAmit Kucheria tz->passive = 0; 7190015d9a2SAmit Kucheria reset_pid_controller(params); 7200952177fSLukasz Luba allow_maximum_power(tz, update); 721*63561fe3SDaniel Lezcano goto out; 7220015d9a2SAmit Kucheria } 7230015d9a2SAmit Kucheria 7240015d9a2SAmit Kucheria tz->passive = 1; 7250015d9a2SAmit Kucheria 7260015d9a2SAmit Kucheria ret = tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature, 7270015d9a2SAmit Kucheria &control_temp); 7280015d9a2SAmit Kucheria if (ret) { 7290015d9a2SAmit Kucheria dev_warn(&tz->device, 7300015d9a2SAmit Kucheria "Failed to get the maximum desired temperature: %d\n", 7310015d9a2SAmit Kucheria ret); 732*63561fe3SDaniel Lezcano goto out; 7330015d9a2SAmit Kucheria } 7340015d9a2SAmit Kucheria 735*63561fe3SDaniel Lezcano ret = allocate_power(tz, control_temp); 736*63561fe3SDaniel Lezcano 737*63561fe3SDaniel Lezcano mutex_unlock(&tz->lock); 738*63561fe3SDaniel Lezcano out: 739*63561fe3SDaniel Lezcano return ret; 7400015d9a2SAmit Kucheria } 7410015d9a2SAmit Kucheria 7420015d9a2SAmit Kucheria static struct thermal_governor thermal_gov_power_allocator = { 7430015d9a2SAmit Kucheria .name = "power_allocator", 7440015d9a2SAmit Kucheria .bind_to_tz = power_allocator_bind, 7450015d9a2SAmit Kucheria .unbind_from_tz = power_allocator_unbind, 7460015d9a2SAmit Kucheria .throttle = power_allocator_throttle, 7470015d9a2SAmit Kucheria }; 7480015d9a2SAmit Kucheria THERMAL_GOVERNOR_DECLARE(thermal_gov_power_allocator); 749