Android Thermal

转自: blog.csdn.net/shichaog/article/details/60959260

包括两个部分kernel thermal monitor(KTM)和thermal engine。

  • Thermal 管理包括的内容如下:
  1. 硅片结温
  2. 内存温度限制
  3. 外表面温度限制
  • 当thermal engine完全初始化后,KTM确保所有环境条件下的结温处于限定的范围之内。
  • Thermal engine monitor监控系统的温度限制范围。
  • 机械结构设计模拟是获得最佳性能的必要步骤
  • Thermal management软件控制thermal响应。

DCVS:Dynamic Cloclk Frequency and Voltage Scaling.

下图包括了thermal 管理框架的四个部分:thermal engine, sensor driver以及其它温度管理设备。

在安卓用户空间thermal engine作为一个超级用户运行,thermal engine是温度管理的核心。启动时thermal engine初始化系统。threshold,set point以及管理的设备配置缺省情况从代码读取。参数用于设置温度传感器的中断门限。

为了在温度规范内获得最佳性能,这些参数在每一个设计中都要调优。温度传感器有:

  • 嵌入芯片硅结的温度传感器,这些是被称之为TSENS
  • thermal management 设备是软件抽象的设备,用于控制硬件,如GPU,CPU等

除了上述thermal架构,还有两个温度管理算法用于thermal engine完全启动前的设备启动和linux内核初始化阶段的温度管理。

Android温度限制和特点

  • KTM

内核启动时保护系统

设置110°为CPU热插拔的门限

将控制移交给thermal engine

  • Thermal engine

完整的温度保护策略

对特定对象必须调节

  • Thermal reset

异常情况

TM移交时间线

KTM

KTM函数和相关的调试

循环查询指定TSENS的温度,并根据得到的温度有如下的行为:

  • check_temp()--位于drivers/thermal/msm_thermal.c;每一个采样周期(msm_thermal_info.poll_ms)将被调用
  • do_therm_reset()---如果任意一个温度传感器的温度超过critical门限,这将导致看门狗(其参数由设备树的qcom,therm-reset-temp指定)喂狗,

  1. msm_thermal:msm_thermal_bite: TSENS:α reached temperature:β. System reset  
msm_thermal:msm_thermal_bite: TSENS:α reached temperature:β. System reset

  • therm_get_temp()--获得设备树<qcom, sensor_id>字段指定sensor的温度,在调试时需要将该温度打印出来。
  • do_core_control()--到CPU温度超过门限时将cpu unplug,其打印的信息如下:
    1. msm_thermal:do_core_control: Set Offline: CPU$ Temp: β  
    2. msm_thermal:do_core_control: Allow Online CPU$ Temp: β  
    msm_thermal:do_core_control: Set Offline: CPU$ Temp: β
    msm_thermal:do_core_control: Allow Online CPU$ Temp: β
  • do_vdd_mx()--对linux设备,KTM管理所有的温度传感器,如果温度掉于某个门限,其提升内存供电电压,在收到内存门限后KTM打印如下信息:

  1. msm_thermal: vdd_mx_notify: Sensorα trigger received for type <threshold_type>  
msm_thermal: vdd_mx_notify: Sensorα trigger received for type <threshold_type>

  • do_psm()--对于PMIC,温度超过一个门限后,其将被自动disable,KTM将发送一个命令让PMIC工作在PWM(pulse width modulation)模式,发送该命令时打印的信息如下:

  1. msm_thermal:do_psm: Requested PMIC PWM Mode tsens:α. Temp:β  
  2. msm_thermal:do_psm: Requested PMIC AUTO Mode  
msm_thermal:do_psm: Requested PMIC PWM Mode tsens:α. Temp:β
msm_thermal:do_psm: Requested PMIC AUTO Mode

  • do_gfx_phase_cond() and do_cx_phase_cond()---DIGITAL/GFX的多阶段电压轨。

  1. msm_thermal:send_temperature_band: Sending <rail> temperature band<band_number> where, <rail>: DIGITAL or GFX with multiple BAND definition  
  2. depending on chipset  
msm_thermal:send_temperature_band: Sending <rail> temperature band<band_number> where, <rail>: DIGITAL or GFX with multiple BAND definition
depending on chipset

  • do_ocr()--对于一些设备,KTM监控温度,如果发现任意一个传感器温度超过门限,其向regulator发送最优电流请求。
  • do_vdd_restriction()--用于限制温度低门限(5°)时,KTM打印的信息如下:

  1. msm_thermal:vdd_restriction_notify: sensor:α reached high thresh for Vddrestriction  
  2. msm_thermal:vdd_restriction_notify: sensor:α reached low thresh for Vddrestriction  
msm_thermal:vdd_restriction_notify: sensor:α reached high thresh for Vddrestriction
msm_thermal:vdd_restriction_notify: sensor:α reached low thresh for Vddrestriction

  • do_freq_control()---当一个温度超过门限时CPU调频控制,其打印的信息如下:

  1. msm_thermal:do_freq_control: Limiting CPU$ max frequency to 1958400. Temp:β  
msm_thermal:do_freq_control: Limiting CPU$ max frequency to 1958400. Temp:β

KTM设置

一个例子是:/arch/arm64/boot/dts/qcom/msm8916.dtsi

  1. qcom,msm-thermal {  
  2. qcom,msm-thermal {  
  3. compatible = "qcom,msm-thermal";  
  4. qcom,sensor-id = <5>;  
  5. qcom,poll-ms = <250>;  
  6. qcom,limit-temp = <60>;  
  7. qcom,temp-hysteresis = <10>;  
  8. qcom,freq-step = <2>;  
  9. qcom,freq-control-mask = <0xf>;  
  10. qcom,core-limit-temp = <80>;  
  11. qcom,core-temp-hysteresis = <10>;  
  12. qcom,core-control-mask = <0xe>;  
  13. qcom,hotplug-temp = <94>;  
  14. qcom,hotplug-temp-hysteresis = <15>;  
  15. qcom,cpu-sensors = "tsens_tz_sensor5", "tsens_tz_sensor5",  
  16. "tsens_tz_sensor4", "tsens_tz_sensor4";  
  17. qcom,freq-mitigation-temp = <94>;  
  18. qcom,freq-mitigation-temp-hysteresis = <10>;  
  19. qcom,freq-mitigation-value = <400000>;  
  20. qcom,freq-mitigation-control-mask = <0x01>;  
  21. qcom,online-hotplug-core;  
  22. qcom,vdd-restriction-temp = <5>;  
  23. qcom,vdd-restriction-temp-hysteresis = <10>;  
  24. vdd-dig-supply = <&pm8916_s1_floor_corner>;  
  25. qcom,vdd-dig-rstr{  
  26. qcom,vdd-rstr-reg = "vdd-dig";  
  27. qcom,levels = <5 7 7>; /* Nominal, Super Turbo, Super  
  28. Turbo */  
  29. qcom,min-level = <1>; /* No Request */  
  30. };  
  31. qcom,vdd-apps-rstr{  
  32. qcom,vdd-rstr-reg = "vdd-apps";  
  33. qcom,levels = <533330 800000 998400>;  
  34. qcom,freq-req;  
  35. };  
  36. };  
qcom,msm-thermal {
qcom,msm-thermal {
compatible = "qcom,msm-thermal";
qcom,sensor-id = <5>;
qcom,poll-ms = <250>;
qcom,limit-temp = <60>;
qcom,temp-hysteresis = <10>;
qcom,freq-step = <2>;
qcom,freq-control-mask = <0xf>;
qcom,core-limit-temp = <80>;
qcom,core-temp-hysteresis = <10>;
qcom,core-control-mask = <0xe>;
qcom,hotplug-temp = <94>;
qcom,hotplug-temp-hysteresis = <15>;
qcom,cpu-sensors = "tsens_tz_sensor5", "tsens_tz_sensor5",
"tsens_tz_sensor4", "tsens_tz_sensor4";
qcom,freq-mitigation-temp = <94>;
qcom,freq-mitigation-temp-hysteresis = <10>;
qcom,freq-mitigation-value = <400000>;
qcom,freq-mitigation-control-mask = <0x01>;
qcom,online-hotplug-core;
qcom,vdd-restriction-temp = <5>;
qcom,vdd-restriction-temp-hysteresis = <10>;
vdd-dig-supply = <&pm8916_s1_floor_corner>;
qcom,vdd-dig-rstr{
qcom,vdd-rstr-reg = "vdd-dig";
qcom,levels = <5 7 7>; /* Nominal, Super Turbo, Super
Turbo */
qcom,min-level = <1>; /* No Request */
};
qcom,vdd-apps-rstr{
qcom,vdd-rstr-reg = "vdd-apps";
qcom,levels = <533330 800000 998400>;
qcom,freq-req;
};
};
CPU0传感器用于控制算法,如果温度超过limit-temp给定的值,CPU的最高主频将被限制,如果后续轮询温度继续升高,则频率会被进一步降低,轮询的时间间隔是poll-ms定义的值。如果温度调到limit-temp和temp-hysteresis之和以下,那么可以达到的最高主频将被增加。CPU频率的高低在DCVS表中仅一步。

除了CPU调频,第二个温度门限core-limit-temp定义了CPU热插拔的门限。当温度超过该门限时CPU将被unplug。

设备树中的freq-control-mask和core-control-mask定义了那个cpu核按上述定义的规则工作,bit 0对应CPU0,默认core-control-mask 不包括CPU0,因为其不可以热插拔。

该算法位于/drivers/thermal/msm_thermal.c,对应的温度参数定义于arch/arm64/boot/dts/qcom/msm8916.dtsi。

Thermal Engine

这属于安卓侧的温度管理策略,其根据一个configure文件(default is /etc/thermal-engine.conf),但是一般会有一个平台对应文件,如/system/etc/thermal-engine-8974.conf

Thermal 管理策略--嵌入式和配置方式

三种算法

  • SS(single step),PID(Proportional-Integral-Derivative)和monitor。
  • 所有的规则要么定义于config文件,要么硬编码到thermal engine 数据文件里。

对于嵌入式规则,要求必须提供电压限制和PSM控制,可选的是所有CPU启动SS/PID控制算法

对于配置文件定义的算法,管理结温的算法通常采用SS算法,管理Pop 内存的采用SS或者monitor算法。

SS/PID/MONITOR算法实例

SS algorithm

本例中label是surface_control_dtm,该名称必须是唯一的,SS算法(algo_type = ss)通过每隔一秒(sampling = 1000)采样ID是3(sensor = tsens_tz_sensor3)的传感器来进行温度控制,DTM控制所有CPU的最大允许的主频(device = cpu),Sensor ID 3的温度设置根据系统表面温度是25°时设定的,所以控制表面温度在45°时,ID 3的温度传感器的温度应该在70°,安全门限温度设置在了55°,这一温度将不会限制CPU主频。

  1. [surface_control_dtm]  
  2. algo_type ss  
  3. sensor tsens_tz_sensor3  
  4. device cpu  
  5. sampling 1000  
  6. set_point 70000  
  7. set_point_clr 55000  
[surface_control_dtm]
algo_type ss
sensor tsens_tz_sensor3
device cpu
sampling 1000
set_point 70000
set_point_clr 55000

PID algorithm

标号是urface_control_pid,算法类型是(algo_type = pid),其65ms(sampling = 65)间隔采样ID 5温度传感器(sensor = tsens_tz_sensor5),PID调节最大允许的cpu主频(device = cpu0),ID 5是CPU0,所以控制温度设置成了95°,安全门限温度是55°,所谓的安全门限就是在这一温度以下,主频可以放开跑。

  1. [CPU0_control_pid]  
  2. algo_type pid  
  3. sensor tsens_tz_sensor5  
  4. device cpu0  
  5. sampling 65  
  6. set_point 95000  
  7. set_point_clr 55000  
[CPU0_control_pid]
algo_type pid
sensor tsens_tz_sensor5
device cpu0
sampling 65
set_point 95000
set_point_clr 55000

Monitor algorithm

  1. [modem]  
  2. algo_type monitor  
  3. sensor pa_therm0  
  4. sampling 1000  
  5. thresholds 70000 80000  
  6. thresholds_clr 65000 75000  
  7. actions modem mode  
[modem]
algo_type monitor
sensor pa_therm0
sampling 1000
thresholds 70000 80000
thresholds_clr 65000 75000
actions modem mode

Thermal engine 调试

1.找到当前的thermal engine配置

  1. adb shell thermal-engine –o > thermal-engine.conf  
adb shell thermal-engine –o > thermal-engine.conf

2.修改该文件后推送到设备上

3.将”debug“放到thermal-engine.conf的首行,然后重新启动thermal-engine服务

  1. adb shell stop thermal-engine  
  2. adb root  
  3. adb remount  
  4. adb push thermal-engine.conf /system/etc/thermal-engine.conf  
  5. adb shell sync .  
  6. adb shell strat thermal-engine --debug &  
adb shell stop thermal-engine
adb root
adb remount
adb push thermal-engine.conf /system/etc/thermal-engine.conf
adb shell sync .
adb shell strat thermal-engine --debug &
4.logcat查看系统温度log

  1. adb logcat –v time –s ThermalEngine  
adb logcat –v time –s ThermalEngine

Temperature日志

内部传感器log

1.绝大多数信息已经导入到了sysfs node节点里。

2.log脚本周期性记录温度并保存到文件里

3.当前主频和最高主频也要记录到文件里

  1. // checking for temp zone 0 value if sensor available  
  2. if (tz_flags[0]) {  
  3. tz_temp= 0;  
  4. tzs=  
  5. fopen("/sys/devices/virtual/thermal/thermal_zone0/temp","r");  
  6. if(tzs) {  
  7. fscanf(tzs,"%d",&tz_temp);  
  8. if (debug) {  
  9. printf("\nReadTEMPZONE0  
  10. file %d\n",tz_temp);  
  11. }  
  12. fclose(tzs);  
  13. }  
  14. fprintf(out_fd,"%d,",tz_temp);  
  15. }  
// checking for temp zone 0 value if sensor available
if (tz_flags[0]) {
tz_temp= 0;
tzs=
fopen("/sys/devices/virtual/thermal/thermal_zone0/temp","r");
if(tzs) {
fscanf(tzs,"%d",&tz_temp);
if (debug) {
printf("\nReadTEMPZONE0
file %d\n",tz_temp);
}
fclose(tzs);
}
fprintf(out_fd,"%d,",tz_temp);
}
4.POP内存/表面温度记录

可以使用热电偶或者红外摄像机

5,读取当前的温度

  1. adb shell cat /sys/devices/virtual/thermal/thermal_*/temp  
adb shell cat /sys/devices/virtual/thermal/thermal_*/temp


  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值