Qualcomm thermal的介绍
随着智能设备的发展,很多产品越做越小,在一块很小的板子和结构内会附带很多功能,加上很多应用需要处理数据很大,必定造成设备很容易发热。且发热不仅会带来体验的不足还会带来大量的电量消耗。所以在移动消费产品,对热量的解决方案还是很重要的。今天我们就介绍下高通410C开发板上热量管理的机制,软件如何控制。
首先在软件架构上我们分为以下部分。
一:驱动部分
驱动代码位置:
共有部分:kernel/deriver/thermal_core.c
kernel/driver/user_space.c
platform部分:
mitigation部分:
kernel/driver/msm_thermal-dev.c
kernel/driver/msm_thermal.c
sensor部分:
qpnp-temp-alarm.c
msm8974-tsens.c
简要叙述驱动文件关键位置,基本理解驱动构架以及如何运作。
msm8974-tsens.c
1:sensor的注册,将thermal注册为class类:
2:thermal_zone_device_ops接口的填充,以给thermal_core的调用。
3:触发中断与通知上层。
thermal_core.c
1:thermal_zone_devices_register()提供相应sensor register接口,按先后顺序注册/sys/class/thermal/thermal_zoneN。
2:为上层提供trip_temp、type等接口,如:
root@msm8916_32:/ # cat /sys/class/thermal/thermal_zone5/trip_point_0_type
configurable_hi
root@msm8916_32:/ # cat /sys/class/thermal/thermal_zone5/trip_point_0_temp
85
这里trip_point_0_temp为high temp thresthold,那么trip_point_1_temp为low temp thresthold
3:调用sensor相关接口:
关于tpye name与thermal_zone的对应关系:
以8016为例:
type name
thermal_zone0 battery
thermal_zone1 tsens_tz_sensor0
thermal_zone2 tsens_tz_sensor1
thermal_zone3 tsens_tz_sensor2 pop_mem
thermal_zone4 tsens_tz_sensor4 cpu2-3
thermal_zone5 tsens_tz_sensor5 cpu0-1
thermal_zone6 pm8916_tz
thermal_zone7 bms
msm_thermal.c
mitigation分为轮训与中断,首先看下poll部分:
每隔指定的时间就会check温度,当超过范围会降频,关闭cpu,重设thsreshold等操作。
interrupt部分,默认启动的是中断方式,这里是interrupt的初始化。
再以hotplug细说interrupt的运行,这里会根据dts里面的参数先设置,后通过set_threshold调用之前sensor填充的接口,写入到寄存器里面,当达到温度后,触发中断后会通知上层,再温度非常高的话会运行起kernel mitigation,通过hotplug notify来做相应处理
二:上层thermal-engine部分:
thermal工作机制:首先上层设置trig point,包括恢复温度与临界温度,thermal engine主要有algo_monitor运作sensor monitor起辅助作用够成。algo_monitor依赖 sensor_monitor的运作,而sensor_monitor的运行依赖中断的触发。
1:首先初始化engine,设置临界温度(85度)其它参数等信息。
2:当温度升高达到临界温度,底层中断触发同时通知上层,algo_monitor由block状态到运行起来,同时启动50ms的timer来采样sensor的温度:
a:当温度大于trig point时,cpu开始降频,每次温度下降一个等级。
b:当温度小于trig point时,cpu可以恢复到max状态,当时取消timer同时将trig point恢复到85度。
关于 set_point部分的设定。ss-data.c中,关于temp threshold的深入。
下面讨论高温threshold
1:首先上层set_point(默认85度)会写入/sys/class/thermal/thermal_zoneX/trip_point_0_temp。
2:当sensor温度达到85度后,触发中断通知上层与kernel mitigation
流程:tsens_isr->thermal_sensor_trip->thermal_sensor_trip->__update_sensor_thresholds
由于85度,并没有达到kernel mitigation与cpu hotplug的95度thresthold,那里这里的pos->notify()并不会跑进mitigation与hotplug。
在__update_sensor_thresholds()里面会将trip_point_0_temp由85度改为95度。这时中断不再触发,需要等到高温95度触发中断。此时thermal-engine已经在运转,超过85度已经启用cpu降频。很快cpu温度会从85度以上降低下来,假如降低到84度时,那么trip_point_0_temp是不是应该重新置为85度呢?
下面贴出重新设回threshold的方法:
在ss_algorithm.c的handle_thresh_sig()里面会去处理同时重新设定cpu可以跑到最高freq。
假如机器温度实在是太高超过了95度,那么kernel mitigation与cpu hotplug将会运转起来。
利用msm_thermal.c提供的cpus_offlined接口关闭指定的cpu。
禁用cpu3 :
echo 8 > sys/module/msm_thermal/core_control/cpus_offlined
CPU升温:
cat /dev/zero > /dev/null & 执行30次
打开feature:
stop thermal-engine
thermal-engine --debug &
logcat -v time -s ThermalEngine
logcat现场分析,第一段logcat分析:
下面的由于温度达到了pop_mem的70度,那么algo_monitor就运作起来了,
03-07 22:01:44.619 D/ThermalEngine( 2110): tsens_uevent: tsens_tz_sensor2
03-07 22:01:44.619 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Reading 70000 .
03-07 22:01:44.619 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:01:44.619 D/ThermalEngine( 2110): thresh_notify: SS Id SS-POPMEM, Update recieved pop_mem 70000 //底层中断激活
03-07 22:01:44.619 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(0), Hi(0) 2147483647, Lo(0) -2147483648, Interval(0) 2147483647
03-07 22:01:44.619 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Wait for client request.
03-07 22:01:44.619 D/ThermalEngine( 2110): algo_monitor: Thresh EVT
03-07 22:01:44.619 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC //pop_mem 70度
03-07 22:01:44.619 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM, Read pop_mem 70000mC
03-07 22:01:44.619 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM Transition State 2
03-07 22:01:44.619 D/ThermalEngine( 2110): sensors_manager_set_thresh_lvl: tsens_tz_sensor2 Hi(0) 0, Lo(1) 45000, Interval(0) 0
03-07 22:01:44.619 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(1), Hi(0) 2147483647, Lo(1) 45000, Interval(0) 2147483647 //设置低温point45度触发中断
03-07 22:01:44.619 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_type)
03-07 22:01:44.619 D/ThermalEngine( 2110): TSENS threshold at 0 enabled: 0
03-07 22:01:44.619 D/ThermalEngine( 2110): Setting up TSENS thresholds low: 45
03-07 22:01:44.619 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_1_type)
03-07 22:01:44.619 D/ThermalEngine( 2110): TSENS threshold at 1 enabled: 1 //写入低有效 45度触发
//上面的中断触发激活了timer
03-07 22:01:44.619 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:01:44.619 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:01:44.619 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Sensor wait.
03-07 22:01:45.619 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:01:45.619 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:69000 mC
03-07 22:01:45.619 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 69000mC, Err 1000mC, SampleCnt 1//此时读取到的69度
03-07 22:01:45.619 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 1000mC, E1 0mC
03-07 22:01:45.619 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:69000 mC
03-07 22:01:45.619 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM, Read pop_mem 69000mC
03-07 22:01:45.619 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM Transition State 3 //stop采样,重新设置70度高有效
03-07 22:01:45.619 D/ThermalEngine( 2110): device_clnt_cancel_request: DEV cpu
03-07 22:01:45.619 D/ThermalEngine( 2110): sensors_manager_set_thresh_lvl: tsens_tz_sensor2 Hi(1) 70000, Lo(0) 0, Interval(0) 0
03-07 22:01:45.619 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(1), Hi(1) 70000, Lo(0) -2147483648, Interval(0) 2147483647
03-07 22:01:45.619 D/ThermalEngine( 2110): Setting up TSENS thresholds high: 70
03-07 22:01:45.619 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_type)
03-07 22:01:45.619 D/ThermalEngine( 2110): TSENS threshold at 0 enabled: 1
03-07 22:01:45.619 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_1_type)
03-07 22:01:45.619 D/ThermalEngine( 2110): TSENS threshold at 1 enabled: 0
//温度在70以下取消timer
03-07 22:01:45.619 D/ThermalEngine( 2110): settimer: Start timer 0.000(sec)
//下一轮的中断激活
03-07 22:01:45.619 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:01:49.629 D/ThermalEngine( 2110): tsens_uevent: tsens_tz_sensor2
03-07 22:01:49.629 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Reading 70000 .
03-07 22:01:49.629 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:01:49.629 D/ThermalEngine( 2110): thresh_notify: SS Id SS-POPMEM, Update recieved pop_mem 70000
03-07 22:01:49.629 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(0), Hi(0) 2147483647, Lo(0) -2147483648, Interval(0) 2147483647
03-07 22:01:49.629 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Wait for client request.
03-07 22:01:49.629 D/ThermalEngine( 2110): algo_monitor: Thresh EVT
03-07 22:01:49.629 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:01:49.629 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM, Read pop_mem 70000mC
03-07 22:01:49.629 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM Transition State 2
03-07 22:01:49.629 D/ThermalEngine( 2110): sensors_manager_set_thresh_lvl: tsens_tz_sensor2 Hi(0) 0, Lo(1) 45000, Interval(0) 0
03-07 22:01:49.629 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(1), Hi(0) 2147483647, Lo(1) 45000, Interval(0) 2147483647
03-07 22:01:49.629 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_type)
03-07 22:01:49.629 D/ThermalEngine( 2110): TSENS threshold at 0 enabled: 0
03-07 22:01:49.629 D/ThermalEngine( 2110): Setting up TSENS thresholds low: 45
03-07 22:01:49.629 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_1_type)
03-07 22:01:49.629 D/ThermalEngine( 2110): TSENS threshold at 1 enabled: 1
//设定1s timer
03-07 22:01:49.629 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:01:49.629 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:01:49.629 D/ThermalEngine( 2110): sensor_monitor: tsens_tz_sensor2 Sensor wait.
03-07 22:01:50.629 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:01:50.629 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:01:50.629 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 70000mC, Err 0mC, SampleCnt 1
03-07 22:01:50.629 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 0mC, E1 0mC
第二段logcat分析:
采样到71度启动降频,这时底层会设置高位point为95度
03-07 22:04:15.669 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:04:15.669 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:04:16.669 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:04:16.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:71000 mC
03-07 22:04:16.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 71000mC, Err -1000mC, SampleCnt 1
03-07 22:04:16.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 -1000mC, E1 0mC
03-07 22:04:16.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu, op_value 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu0, op_value 1152000
03-07 22:04:16.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[0] to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): CPU[0] frequency limited to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu1, op_value 1152000
03-07 22:04:16.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[1] to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): CPU[1] frequency limited to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu2, op_value 1152000
03-07 22:04:16.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[2] to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): CPU[2] frequency limited to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu3, op_value 1152000
03-07 22:04:16.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[3] to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): CPU[3] frequency limited to 1152000
03-07 22:04:16.669 D/ThermalEngine( 2110): increase_mitigation_lvl: SS Id SS-POPMEM, Device cpu, Req. Freq 1152000Khz, Applied freq 1152000kHz, TC delay 1
03-07 22:04:16.669 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
下一轮timer:
刚才降频了,这次采样到温度恢复到了70度,那么cpu恢复最大值,同时设置低有效45度。
03-07 22:04:16.669 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:04:17.669 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:04:17.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:04:17.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 70000mC, Err 0mC, SampleCnt 1
03-07 22:04:17.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 0mC, E1 -1000mC
03-07 22:04:17.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu, op_value 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu0, op_value 1209600
03-07 22:04:17.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[0] to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): CPU[0] frequency limited to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu1, op_value 1209600
03-07 22:04:17.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[1] to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): CPU[1] frequency limited to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu2, op_value 1209600
03-07 22:04:17.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[2] to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): CPU[2] frequency limited to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): devices_manager_set_op_value: DEV cpu3, op_value 1209600
03-07 22:04:17.669 I/ThermalEngine( 2110): ACTION: CPU - Setting CPU[3] to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): CPU[3] frequency limited to 1209600
03-07 22:04:17.669 D/ThermalEngine( 2110): decrease_mitigation_lvl: SS Id SS-POPMEM, Device cpu, Req. Freq 1209600Khz, Applied freq 1209600kHz, TC delay 0
03-07 22:04:17.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:04:17.669 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM, Read pop_mem 70000mC
03-07 22:04:17.669 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM Transition State 2
03-07 22:04:17.669 D/ThermalEngine( 2110): sensors_manager_set_thresh_lvl: tsens_tz_sensor2 Hi(0) 0, Lo(1) 45000, Interval(0) 0
03-07 22:04:17.669 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(1), Hi(0) 2147483647, Lo(1) 45000, Interval(0) 2147483647
03-07 22:04:17.669 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_type)
03-07 22:04:17.669 D/ThermalEngine( 2110): TSENS threshold at 0 enabled: 0
03-07 22:04:17.669 D/ThermalEngine( 2110): Setting up TSENS thresholds low: 45
03-07 22:04:17.669 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_1_type)
03-07 22:04:17.669 D/ThermalEngine( 2110): TSENS threshold at 1 enabled: 1
03-07 22:04:17.669 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:04:17.669 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:04:18.669 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:04:18.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:04:18.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 70000mC, Err 0mC, SampleCnt 1
03-07 22:04:18.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 0mC, E1 0mC
03-07 22:04:18.669 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:04:18.669 D/ThermalEngine( 2110): algo_monitor: Wait for EV
03-07 22:04:19.669 D/ThermalEngine( 2110): algo_monitor: Timer EVT
03-07 22:04:19.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:04:19.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM Read pop_mem 70000mC, Err 0mC, SampleCnt 1
03-07 22:04:19.669 D/ThermalEngine( 2110): handle_timer_sig: SS Id SS-POPMEM, E0 0mC, E1 0mC
03-07 22:04:19.669 I/ThermalEngine( 2110): Sensor:tsens_tz_sensor2:70000 mC
03-07 22:04:19.669 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM, Read pop_mem 70000mC
03-07 22:04:19.669 D/ThermalEngine( 2110): handle_thresh_sig: SS Id SS-POPMEM Transition State 2
03-07 22:04:19.669 D/ThermalEngine( 2110): sensors_manager_set_thresh_lvl: tsens_tz_sensor2 Hi(0) 0, Lo(1) 45000, Interval(0) 0
03-07 22:04:19.669 D/ThermalEngine( 2110): update_active_thresh: tsens_tz_sensor2 Active(1), Hi(0) 2147483647, Lo(1) 45000, Interval(0) 2147483647
03-07 22:04:19.669 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_0_type)
03-07 22:04:19.669 D/ThermalEngine( 2110): TSENS threshold at 0 enabled: 0
03-07 22:04:19.669 D/ThermalEngine( 2110): Setting up TSENS thresholds low: 45
03-07 22:04:19.669 D/ThermalEngine( 2110): enable_threshold: tsens_tz_sensor2 (/sys/devices/virtual/thermal/thermal_zone3/trip_point_1_type)
03-07 22:04:19.669 D/ThermalEngine( 2110): TSENS threshold at 1 enabled: 1
03-07 22:04:19.669 D/ThermalEngine( 2110): settimer: Start timer 1.000(sec)
03-07 22:04:19.669 D/ThermalEngine( 2110): algo_monitor: Wait for EV
总结:
以上就是高通的thermal机制的介绍,它可以在温度过高时,通过软件对多核CPU的降频和关闭,达到降低温度一个目的。希望通过本文对大家能有一定帮助,对高通的thermal机制有个大概的了解,并对自己的产品做一个热量控制调试。