Thermal框架
一、设备树配置
设备树添加温度传感器
1
2
3
4
5
6
7
8
9
10
11&i2c3 {
status = "okay";
tmp451_0: thermal@4c {
compatible = "ti,tmp451";
reg = <0x4c>;
};
}设备树cooling_device pwm风扇
1
2
3
4
5
6
7
8fan0: pwm-fan-0 {
compatible = "pwm-fan";
pwms = <&pwm0 0 101>;
cooling-min_state = <0>;
cooling-max_state = <3>;
cooling-levels = <50 128 192 255>;
};软件将tsensor和NTC(热敏电阻)等可以获取温度的设备描述为thermal zone, 在代码中以dts的形式来描述。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25/*thermal_zones 下每一个子节点都是一个 thermal, 在 /sys/class/thermal 下对应一个 thermal_zoneX 目录,ntc的也在里面*/
thermal_zones: thermal-zones {
...
soc_max {
polling-delay = <0>; /* /* 温控未发生时(超过阈值时)轮询周期(ms) */ */
polling-delay-passive = <0>; /* 温控发生时(未超过阈值时)的轮询周期(ms) 配置为0,代表不使用轮询方式,通过tsensor中断触发温控。*/
thermal-governor = "step_wise"; /* 补充的,该温区发生温控时所使用的算法*/
thermal-sensors = <&lvts 0>; /* 对应的sensor,表示使用 lvts 这个温度传感器的通道0 */
trips { /* 温控触发点 */
soc_max_crit: soc_max_crit@0 {
/* 触发温度为(116500)/1000 = 116.5 度发生温控,对应 trip_point_0_temp 文件 */
temperature = <116500>;
/* 滞后温度,表示当下降到(116.5 – 2000/1000) = 114.5 度时解除温控,对应 trip_point_0_hyst 文件 */
hysteresis = <2000>;
/*
* "critical"表示触发温控后立刻重启,若配置为”passive”,表示当温控发生后由governor控制,
* 轮询周期改为使用 polling-delay-passive,对应 trip_point_0_type 文件
*/
type = "critical";
};
};
};
...
}备注:trips 即触发点,每个 thermal zone 可以维护多个 trip point,其 type 为 trip point类型,沿袭PC散热方式,分为四种类型:
- passive — 由 governor 的温控策略来降温
- active — 由 governor 的温控策略来降温
- hot— 由 governor 的温控策略来降温
- critical — 温度触发后直接触发重启
示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22thermal_zones: thermal-zones {
cpu_thermal: cpu {
polling-delay-passive = <100>;
polling-delay = <1000>;
thermal-sensors = <&tmp451_0 0>;
trips {
cpu_alert0: cpu_alert0 {
temperature = <36000>;
hysteresis = <2000>;
type = "passive";
};
};
cooling-maps {
map0 {
trip = <&cpu_alert0>;
cooling-device = <&fan0 1 2>;
};
};
};
二、文件接口
/sys/class/thermal/thermal_zoneX/sys/class/thermal/thermal_zone0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19-r--r--r-- available_policies //可选的温控governor,如 power_allocator user_space step_wise
--w------- emul_temp //模拟设置thermal的温度,单位毫摄氏度,设置后 update_temperature()中可获取到这个温度,和实际达到这个温度同效果。只有其为0,读取的才是真正的温度值,否则就是echo的模拟值
-rw-r--r-- integral_cutoff
-rw-r--r-- k_d
-rw-r--r-- k_i
-rw-r--r-- k_po
-rw-r--r-- k_pu
-rw-r--r-- mode //此thermalzone是否使能了,若是为disabled,对其sys文件的操作不生效,可以echo enabled使能
-rw-r--r-- offset
-rw-r--r-- passive
-rw-r--r-- policy //当前使用的governor是哪个
-rw-r--r-- slope
-rw-r--r-- sustainable_power
-r--r--r-- temp //该温区的当前温度,测试时往 emul_temp 中写的值也会体现在这里。
-rw-r--r-- trip_point_0_hyst //滞后温度,来自设备树 hysteresis 字段,此例中为 2000。有 trips 节点才会有此文件。
-rw-r--r-- trip_point_0_temp //触发温度,来自设备树 temperature字段,此例中为 116500,可以通过sysfs更改。
-r--r--r-- trip_point_0_type //触发点0的类型,来自设备树 type 字段,此例中为"critical"
-r--r--r-- type //该温区的名称,对应于设备树 thermal_zones 下子节点的名字,此例中为"soc_max"
-rw-r--r-- uevent/sys/class/thermal/cooling_deviceX
1
2
3
4
5
6
7
8
9
10
11
12/sys/class/thermal/cooling_device0 # ls -l
-rw-r--r-- cur_state //该 cooling_device 的当前 cooling state
-r--r--r-- max_state //该 cooling_device 的最大 cooling state
drwxr-xr-x stats
-r--r--r-- type //该cooling device的名称
-rw-r--r-- uevent
/sys/class/thermal/cooling_device0 # ls -l stats/
--w------- reset //对统计状态进行复位
-r--r--r-- time_in_state_ms //在每个state下停留的时间
-r--r--r-- total_trans //不同state之间转换的次数
-r--r--r-- trans_table //各个state状态转换表,最大只能显示1个页的内容备注:type 为 thermal-cpufreq-X 的 cool device 控制 CPU ClusterX 的频点,比如向 cur_state 中写入 max_state 的值,对应Cluster的 scaling_max_freq 文件将显示被限制到了最小频点。
type 为 thermal-cpufreq-X 的是通过 cpufreq_cooling.c 注册的 cool device,type 为 thermal-devfreq-X 的是通过 devfreq_cooling.c 注册的 cool device。示例:
通过sys节点控制风扇转速:
1
2root@ub20:/sys/devices/virtual/thermal/cooling_device0
echo 2 > cur_state