RK3399 Thermal (溫度控制)
本文采用知識共享署名 4.0 國際許可協議進行許可,轉載時請注明原文鏈接,圖片在使用時請保留全部內容,可適當縮放并在引用處附上圖片所在的文章鏈接。
- Thermal 是什么
- 配置?法
- Menuconfig配置
- Tsadc配置
- CPU & GPU配置
- Termal zone 配置
- ??態接口
- 常用設置
- 參考
Thermal 是什么
Thermal是內核開發者定義的?套?持根據指定governor控制系統溫度,以防?芯?過熱的框架模型。Thermal framework由governor、core、cooling device、sensor driver組成,軟件架構如下:
- Thermal governor:?于決定cooling device是否需要降頻,降到什么程度。?前Linux4.4內核中包含了如下?種governor:
- power_allocator:引?PID(?例-積分-微分)控制,根據當前溫度,動態給各cooling device分配power,并將power轉換為頻率,從而達到根據溫度限制頻率的效果。
- step_wise :根據當前溫度,cooling device逐級降頻。
- fair share :頻率檔位?較多的cooling device優先降頻。
- userspace:不限制頻率。
- Thermal core: 對thermal governors和thermal driver進?了封裝和抽象,并定義了清晰的接口。
- Thermal sensor driver:sensor驅動,?于獲取溫度,?如tsadc。
- Thermal cooling device:發熱源或者可以降溫的設備,?如CPU、GPU、DDR等。
配置?法
Menuconfig配置
<*
> Generic Thermal sysfs driver ---
>--- Generic Thermal sysfs driver
[*
] APIs to parse thermal data out of device tree
[*
] Enable writable trip pointsDefault Thermal governor
( power_allocator
) ---
> /* default thermal governor */
[ ] Fair -share thermal governor
[ ] Step_wise thermal governor /* step_wise governor */
[ ] Bang Bang thermal governor
[*
] User_space thermal governor /* user_space governor */-*- Power allocator thermal governor /* power_allocator governor */
[*
] generic cpu cooling support /* cooling device */
[ ] Generic clock cooling support
[*
] Generic device cooling support /* cooling device */
[ ] Thermal emulation mode support
< > Temperature sensor driver
for Freescale i.MX SoCs
<*
> Rockchip thermal driver /* thermal sensor driver */
< > rk_virtual thermal driver
<*
> rk3368 thermal driver legacy /* thermal sensor driver */
通過“Default Thermal governor”配置項,可以選擇溫控策略,開發者可以根據實際產品需求進?修改。
Tsadc配置
Tsadc在溫控中作為thermal sensor,?于獲取溫度,通常需要在DTSI和DTS都做配置。
以RK3399為例,DTSI包括如下配置:
tsadc
: tsadc@ff260000
{compatible
= "rockchip,rk3399-tsadc" ;reg
= <0x0 0xff260000 0x0 0x100 >; interrupts
= <GIC_SPI 97 IRQ_TYPE_LEVEL_HIGH 0>; assigned
-clocks
= <& cru
SCLK_TSADC >; assigned
-clock
-rates
= <750000 >;clocks
= <& cru
SCLK_TSADC >, <& cru
PCLK_TSADC >; clock
-names
= "tsadc" , "apb_pclk" ;resets
= <& cru
SRST_TSADC >; reset
-names
= "tsadc-apb" ;rockchip
,grf
= <& grf
>; rockchip
,hw
-tshut
-temp
= <120000 >; pinctrl
-names
= "gpio" , "otpout" ;pinctrl
-0 = <& otp_gpio
>;pinctrl
-1 = <& otp_out
>;#thermal
-sensor
-cells
= <1>;status
= "disabled" ;
};
pinctrl
: pinctrl
{...tsadc
{otp_gpio
: otp
-gpio
{rockchip
,pins
= <1 6 RK_FUNC_GPIO &pcfg_pull_none
>;};otp_out
: otp
-out
{rockchip
,pins
= <1 6 RK_FUNC_1 &pcfg_pull_none
>;};};....
}
DTS的配置,主要?于選擇通過CRU復位還是GPIO復位,低電平復位還是?電平復位。需要特別注意的是如果配置成GPIO復位,硬件上需要否把tsadc輸出引腳連到PMIC的復位腳,否則只能配置成CRU復位。
&tsadc
{rockchip
,hw
-tshut
-mode
= <1>; rockchip
,hw
-tshut
-polarity
= <1>; status
= "okay" ;
};
CPU & GPU配置
CPU在溫控中作為cooling device,節點中需要包含#cooling-cells、dynamic-power-coefficient屬性。
以RK3399為例:
cpu_l0
: cpu@
0 {device_type
= "cpu" ;compatible
= "arm,cortex-a53" , "arm,armv8" ;reg
= <0x0 0x0 >;enable
-method
= "psci" ;#cooling
-cells
= <2>; clocks
= <& cru
ARMCLKL >;cpu
-idle
-states
= <& CPU_SLEEP &CLUSTER_SLEEP >;dynamic
-power
-coefficient
= <100 >;
};
...
cpu_b0
: cpu@
100 {device_type
= "cpu" ;compatible
= "arm,cortex-a72" , "arm,armv8" ;reg
= <0x0 0x100 >;enable
-method
= "psci" ;#cooling
-cells
= <2>; clocks
= <& cru
ARMCLKB >;cpu
-idle
-states
= <& CPU_SLEEP &CLUSTER_SLEEP >;dynamic
-power
-coefficient
= <436 >;
};
GPU在溫控中作為cooling device,節點需要包含#cooling-cells屬性和power_model?節點。
以RK3399為例:
gpu
: gpu@ff9a0000
{compatible
= "arm,malit860" ,"arm,malit86x" ,"arm,malit8xx" , "arm,mali-midgard" ;reg
= <0x0 0xff9a0000 0x0 0x10000 >;interrupts
= <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH 0>, <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH 0>, <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH 0>;interrupt
-names
= "GPU" , "JOB" , "MMU" ;clocks
= <& cru
ACLK_GPU >;clock
-names
= "clk_mali" ;#cooling
-cells
= <2>; power
-domains
= <& power
RK3399_PD_GPU >;power
-off
-delay
-ms
= <200 >;status
= "disabled" ;gpu_power_model
: power_model
{compatible
= "arm,mali-simple-power-model" ;static -coefficient
= <411000 >; dynamic
-coefficient
= <733 >; ts
= <32000 4700 ( -80 ) 2>; thermal
-zone
= "gpu-thermal" ; };
};
Termal zone 配置
Termal zone節點主要?于配置溫控策略相關的參數并?成對應的??態接口。
以RK3399為例:
thermal_zones
: thermal
-zones
{soc_thermal
: soc
-thermal
{polling
-delay
-passive
= <20 >; polling
-delay
= <1000 >; sustainable
-power
= <1000 >; thermal
-sensors
= <& tsadc
0>;trips
{threshold
: trip
-point
-0 {temperature
= <70000 >; hysteresis
= <2000 >; type
= "passive" ; };target
: trip
-point
-1 {temperature
= <85000 >; hysteresis
= <2000 >; type
= "passive" ; };soc_crit
: soc
-crit
{temperature
= <115000 >; hysteresis
= <2000 >; type
= "critical" ; };};cooling
-maps
{map0
{trip
= <& target
>;cooling
-device
= <& cpu_l0
THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution
= <4096 >; };map1
{trip
= <& target
>;cooling
-device
= <& cpu_b0
THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution
= <1024 >;};map2
{trip
= <& target
>;cooling
-device
= <& gpu
THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution
= <4096 >;};};};gpu_thermal
: gpu
-thermal
{polling
-delay
-passive
= <100 >; polling
-delay
= <1000 >; thermal
-sensors
= <& tsadc
1>;};
};
??態接口
??態接口在/sys/class/thermal/?錄下,具體內容和DTSI中thermal zone節點的配置對應。有的平臺thermalzone節點下只有?個?節點,對應/sys/class/thermal/?錄下也只有thermal_zone0??錄;有的平臺有兩個?節點,對應/sys/class/thermal/?錄下就會有thermal_zone0和thermal_zone1??錄。通過??態接口可以切換溫控策略,查看當前溫度等。
以RK3399為例?,/sys/class/thermal/thermal_zone0/?錄下包含如下常?的信息:
temp /* 當前溫度 */
available_policies /* ?持的溫控策略 */
policy /* 當前使?的溫控策略 */
sustainable_power /* 期望的最?溫度下對應的power 值 */
integral_cutoff /* PID 算法中I的觸發條件:當前溫度-期望的最?溫度<integral_cutoff */
k_d /* PID 算法中計算D的時候?的參數 */
k_i /* PID 算法中計算I的時候?的參數 */
k_po /* PID 算法中計算P的時候?的參數 */
k_pu /* PID 算法中計算P的時候?的參數 */
mode /* enabled :?帶定時獲取溫度,判斷是否需要降頻。disabled 關閉該功能 */
type /* 當前thermal zone 的類型 */
/* 不同的溫度閥值,對應trips 節點的配置 */
trip_point_0_hyst
trip_point_0_temp
trip_point_0_type
trip_point_1_hyst
trip_point_1_temp
trip_point_1_type
trip_point_2_hyst
trip_point_2_temp
trip_point_2_type
/* 不同cooling devic 的狀態,對應cooling-maps 節點的配置 */
cdev0 /* 代表?個cooling devic ,有的平臺還有cdev1 、cdev2 等 */cur_state /* 該cooling device 當前頻率的檔位 */max_state /* 該cooling device 最多有?個檔位 */type /* 該cooling device 的類型 */
cdev0_weight /* 該cooling devic 在計算power 時擴?的倍數 */
常用設置
獲取當前溫度
直接查看??態接口thermal_zone0或者thermal_zone1?錄下的temp節點即可。
以RK3399為例,獲取CPU溫度,在串口中輸?如下命令:
cat /sys /class /thermal /thermal_zone0 /temp
獲取GPU溫度,在串口中輸?如下命令:
cat /sys /class /thermal /thermal_zone1 /temp
關閉溫度控制功能
?法?:menuconfig中默認溫控策略設置為user_space。
<*> Generic Thermal sysfs driver --->--- Generic Thermal sysfs driver[*] APIs to parse thermal data out of device tree[*] Enable writable trip pointsDefault Thermal governor ( user_space ) ---> /* power_allocator 改為user_space */
?法?:開機后通過命令關溫控。
?先,把溫控策略切換到user_space,即把??態接口下的policy節點改成user_space;或者把mode設置成
disabled狀態;然后,解除頻率限制,即將??態接口下的所有cdev的cur_state設置為0。
以RK3399為例,策略切換到user_space:
echo user_space > /sys /class /thermal /thermal_zone0 /policy
或者把mode設置成disabled狀態:
echo disabled > /sys /class /thermal /thermal_zone0 /mode
解除頻率限制:
/* 具體有多少個cdev ,根據實際情況修改 */
echo 0 > /sys /class /thermal /thermal_zone0 /cdev0 /cur_state
echo 0 > /sys /class /thermal /thermal_zone0 /cdev1 /cur_state
echo 0 > /sys /class /thermal /thermal_zone0 /cdev2 /cur_state
參考
Thermal開發指南
總結
以上是生活随笔為你收集整理的RK3399 Thermal (温度控制)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。