轉自: blog.csdn.net/shichaog/article/details/60959260
包括兩個部分kernel thermal monitor(KTM)和thermal engine。
硅片結溫 內存溫度限制 外表面溫度限制 當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溫度限制和特點 內核啟動時保護系統
設置110°為CPU熱插拔的門限
將控制移交給thermal engine
完整的溫度保護策略
對特定對象必須調節
異常情況
TM移交時間線
KTM KTM函數和相關的調試 循環查詢指定TSENS的溫度,并根據得到的溫度有如下的行為:
check_temp()--位于drivers/thermal/msm_thermal.c;每一個采樣周期(msm_thermal_info.poll_ms)將被調用 do_therm_reset()---如果任意一個溫度傳感器的溫度超過critical門限,這將導致看門狗(其參數由設備樹的qcom,therm-reset-temp指定)喂狗,
[plain] view plain
copy print ?
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,其打印的信息如下: [plain] view plain copy print ? msm_thermal:do_core_control:?Set?Offline:?CPU$?Temp:?β?? 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打印如下信息:
[plain] view plain
copy print ?
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)模式,發送該命令時打印的信息如下:
[plain] view plain
copy print ?
msm_thermal:do_psm:?Requested?PMIC?PWM?Mode?tsens:α.?Temp:β?? 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的多階段電壓軌。
[plain] view plain
copy print ?
msm_thermal:send_temperature_band:?Sending?<rail>?temperature?band<band_number>?where,?<rail>:?DIGITAL?or?GFX?with?multiple?BAND?definition?? 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打印的信息如下:
[plain] view plain
copy print ?
msm_thermal:vdd_restriction_notify:?sensor:α?reached?high?thresh?for?Vddrestriction?? 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調頻控制,其打印的信息如下:
[plain] view plain
copy print ?
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
[plain] view plain
copy print ?
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;?? };?? };?? 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主頻。
[plain] view plain
copy print ?
[surface_control_dtm]?? algo_type?ss?? sensor?tsens_tz_sensor3?? device?cpu?? sampling?1000?? set_point?70000?? 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°,所謂的安全門限就是在這一溫度以下,主頻可以放開跑。
[plain] view plain
copy print ?
[CPU0_control_pid]?? algo_type?pid?? sensor?tsens_tz_sensor5?? device?cpu0?? sampling?65?? set_point?95000?? 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
[plain] view plain
copy print ?
[modem]?? algo_type?monitor?? sensor?pa_therm0?? sampling?1000?? thresholds?70000?80000?? thresholds_clr?65000?75000?? 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配置
[plain] view plain
copy print ?
adb?shell?thermal-engine?–o?>?thermal-engine.conf?? adb shell thermal-engine –o > thermal-engine.conf
2.修改該文件后推送到設備上
3.將”debug“放到thermal-engine.conf的首行,然后重新啟動thermal-engine服務
[plain] view plain
copy print ?
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?&?? 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
[plain] view plain
copy print ?
adb?logcat?–v?time?–s?ThermalEngine?? adb logcat –v time –s ThermalEngine
Temperature日志 內部傳感器log
1.絕大多數信息已經導入到了sysfs node節點里。
2.log腳本周期性記錄溫度并保存到文件里
3.當前主頻和最高主頻也要記錄到文件里
[plain] view plain
copy print ?
//?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);?? }?? // 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,讀取當前的溫度
[plain] view plain
copy print ?
adb?shell?cat?/sys/devices/virtual/thermal/thermal_*/temp?? adb shell cat /sys/devices/virtual/thermal/thermal_*/temp
總結
以上是生活随笔 為你收集整理的Android Thermal 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。