By:GentlemanTsao
Thermal sysfs是UE中的文件节点,暴露了thermal sensor,可以通过adb读取和修改。
在UE的/sys/class/thermal目录下查看,可以得到cooling_device和thermal zone列表,如下所示:
每个cooling_device都有自己的类型(type),以区分其他device。我们可以cat cooling_device11 ~14,看到这几个属于modem,依次对应于:
PA
Modem proc
Modem VDD
Modem current
Cooling_device结构,如下所示:
接下来分别阐述这两者及其关系。
任何可以通过节流/限频以实现降温的设备。
Cooling device包含下面几部分:
每个cooling device都关联一个thermal zone的 trip。
具体实现请参考下面一段代码(位于kernel中):
Thermal_core.c
(amss\linux\android\kernel\msm-4.9\drivers\thermal)
/**
*thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
*@tz: pointer to struct thermal_zone_device
* @trip: indicates which trip point the cooling devices is
* associated with in this thermal zone.
*@cdev: pointer to struct thermal_cooling_device
* @upper: the Maximum cooling state for this trip point.
* THERMAL_NO_LIMIT means no upper limit,
* and the cooling device can be in max_state.
* @lower: the Minimum cooling state can be used for this trip point.
* THERMAL_NO_LIMIT means no lower limit,
* and the cooling device can be in cooling state 0.
*@weight: The weight of the cooling device to be bound to the
* thermal zone. Use THERMAL_WEIGHT_DEFAULT for the
* default value
*
*This interface function bind a thermal cooling device to the certain trip
*point of a thermal zone device.
*This function is usually called in the thermal zone device .bind callback.
*
*Return: 0 on success, the proper error value otherwise.
*/
int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
int trip,
struct thermal_cooling_device *cdev,
unsigned long upper, unsigned long lower,
unsigned int weight)
该方法将cooling device绑定到thermal zone并关联trip point。
参数upper和lower设置了trip point的上下限。
在sysfs(cat/sys/class/thermal/)中暴露出thermal sensor.
并且可以配置thermal sensor规则.
Thermal Zone在DTSI文件中配置,我们以8937平台为例,了解thermal
zone的形式。
文件路径:
/kernel/msm-4.9/arch/arm64/boot/dts/qcom/msm8937-thermal.dtsi
下面摘取的是GPU的thermal(右侧注释了每一项的含义):
gpu-step { // thermal zone 名称
polling-delay-passive = <250>; // 中断触发后的检查延时(频率)
polling-delay = <0>; // 非中断触发的检查延时
thermal-sensors = <&tsens0 10>; // 监测的sensor
thermal-governor = "step_wise"; // 限制cooling device的thermal 算法
wake-capable-sensor;
trips { // 关联的trip(闸)
gpu_step_trip: gpu-step-trip { // trip的名称
temperature = <95000>; // trip的值
hysteresis = <0>;
type = "passive";
};
};
cooling-maps { // 定义了cooling要做的动作
gpu_cdev0 { // cooling map名称
trip = <&gpu_step_trip>; // 对应的trip,也就是上面的
cooling-device = // cooling动作,限制GPU
<&msm_gpu THERMAL_NO_LIMIT //没有下限
THERMAL_NO_LIMIT>; // 没有上限
};
};
};
接下来具体看看两个配置项:
thermal-governor
cooling-device
thermal governor是一个温度监测算法,通过限制thermal zone中的cooling device,以达到控制thermal zone温度在一定范围内。
Step-wise:
可用于thermal引擎的算法。
该governor可监测trip point阈值并限制多个cooling device。
当超过trip所设置的阈值时,govenor将限制等级往上或往下调整一级。
Cooling device可以指定最大和最小负载,对应govenor限制等级。
监测三种类型的trip点:
l PASSIVE:
被动,即依靠被动降温的设备,例如CPU。
l ACTIVE:
主动,能够主动散热的设备,例如风扇。
l CRITICAL:
严重,触发关机。
User space:
将阈值通知给thermal引擎。
所有由thermal egine管理的sensor,都必须使用userspace governor。