Power allocator governor 分析
PID控制算法原理圖
k_d
|
current_temp |
| v
| +----------+ +---+
| +----->| diff_err |-->| X |------+
| | +----------+ +---+ |
| | | tdp actor
| | k_i | | get_requested_power()
| | | | | | |
| | | | | | | ...
v | v v v v v
+---+ | +-------+ +---+ +---+ +---+ +----------+
| S |-------+----->| sum e |----->| X |--->| S |-->| S |-->|power |
+---+ | +-------+ +---+ +---+ +---+ |allocation|
^ | ^ +----------+
| | | | |
| | +---+ | | |
| +------->| X |-------------------+ v v
| +---+ granted performance
desired_temperature ^
|
|
k_po/k_pu
PID Controller
The power allocator governor implements a
Proportional-Integral-Derivative controller (PID controller) with
temperature as the control input and power as the controlled output:
P_max = k_p * e + k_i * err_integral + k_d * diff_err + sustainable_power
溫控驅動策略層主要提供API:
static struct thermal_governor thermal_gov_power_allocator = {
.name = "power_allocator",
.bind_to_tz = power_allocator_bind,
.unbind_from_tz = power_allocator_unbind,
.throttle = power_allocator_throttle,
};
解析bind_to_tz接口細節:
power_allocator_bind
|
|
v
get_governor_trips
| 1:獲取的到第一個passive溫度值,當作switch on temp
| 2:獲取最後一個passive溫度值, 當作max_desired temp
v
estimate_pid_constants
| 1:temperature_threshold = control_temp - switch_on_temp
| 2:k_po = int_to_frac(sustainable_power)/ temperature_threshold
| 3:k_pu = int_to_frac(2 * sustainable_power) /
temperature_threshold
| 4:k_i = int_to_frac(10) / 1000; = 10
| 5:此函數將k_p, k_i初始化, k_d 默認爲0
v
reset_pid_controller
| err_inegral設爲0, prev_err設爲0
v
tz->governor_data = params 將策略裏面使用到的參數記錄到tz
解析throttle接口代碼細節:
power_allocator_throttle
|
v
allocate_power
| 1:輸入參數爲tz與control_temp
| 2:通過insttanse獲取所有cooling dev的weight
| 3:通過instanse 獲取到所有需求功率,最大可以持續功率,以及加權後的需求功率
|
v
pid_controller
| 1:輸入tz, 可持續最大功率,control_temp
| 2: sustainable power 從tz dts獲取
| 3:err = control_temp - current_temp(tz->temp) << 10, err即是目標溫度與當前溫度差值
| 4:p = (k_po or k_pu) * err >> 10
| 5:i = k_i * err_integral >> 10
| 6:params->err_integral += err err_integral 是所有前序err的
| 7:d = (k_d * (err - prev_err)) / passive_delay diff_err是本次err減上次err
| 8: power_range = p + i + d + ssustainable
v
divvy_up_power
| 1:根據weight power 權重分配可用功率
v
power_actor_set_power
| 1:設置各個 cooling dev的功率