日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

RK3399 Thermal (温度控制)

發布時間:2023/12/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 RK3399 Thermal (温度控制) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 >; /* ?作時鐘,750KHz */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 >; /* 引?grf 模塊,部分平臺需要 */rockchip ,hw -tshut -temp = <120000 >; /* 過溫重啟閥值,120 攝?度 *//* tsadc 輸出引腳配置,?持兩種模式:gpio 和otpout */pinctrl -names = "gpio" , "otpout" ;pinctrl -0 = <& otp_gpio >;pinctrl -1 = <& otp_out >;/** thermal sensor 標識,表?tsadc 可以作為?個thermal sensor ,* 并指定了引?tsadc 節點的時候需要帶?個參數。* 如果SoC ??只有?個tsadc ,可以設置為0,超過?個必須設置為1。*/#thermal-sensor-cells = <1>;status = "disabled" ; }; /* IO 口配置 */ pinctrl : pinctrl {...tsadc {/* 配置為gpio 模式 */otp_gpio : otp -gpio {rockchip ,pins = <1 6 RK_FUNC_GPIO &pcfg_pull_none >;};/* 配置為over temperature protection 模式 */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>; /* tshut mode 0:CRU 1:GPIO */rockchip ,hw -tshut -polarity = <1>; /* tshut polarity 0:LOW 1:HIGH */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>; /* cooling device 標識,表?該設備可以作為?個cooling device */clocks = <& cru ARMCLKL >;cpu -idle -states = <& CPU_SLEEP &CLUSTER_SLEEP >;dynamic -power -coefficient = <100 >; /* 動態功耗常數C,動態功耗公式為Pdyn=C*V^2*F */ }; ... cpu_b0 : cpu@100 {device_type = "cpu" ;compatible = "arm,cortex-a72" , "arm,armv8" ;reg = <0x0 0x100 >;enable -method = "psci" ;#cooling-cells = <2>; /* cooling device 標識,表?該設備可以作為?個cooling device */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>; /* cooling device 標識,表?該設備可以作為?個cooling device */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" ; /* 從gpu-thermal 獲取溫度,?于計算靜態功耗 */}; };

Termal zone 配置

Termal zone節點主要?于配置溫控策略相關的參數并?成對應的??態接口。
以RK3399為例:

thermal_zones : thermal -zones {/* ?個節點對應?個thermal zone ,并包含溫控策略相關參數 */soc_thermal : soc -thermal {/* 溫度?于trip-point-0 指定的值,每隔20ms 獲取?次溫度 */polling -delay -passive = <20 >; /* milliseconds *//* 溫度低于trip-point-0 指定的值,每隔1000ms 獲取?次溫度 */polling -delay = <1000 >; /* milliseconds *//* 溫度等于trip-point-1 指定的值時,系統分配給cooling device 的能量 */sustainable -power = <1000 >; /* milliwatts *//* 當前thermal zone 通過tsadc0 獲取溫度 */thermal -sensors = <& tsadc 0>;/* trips 包含不同溫度閥值,不同的溫控策略,配置不?定相同 */trips {/** 溫控閥值,超過該值溫控策略開始?作,但不?定?上限制頻率,* power 小到?定程度才開始限制頻率*/threshold : trip -point -0 {/* 超過70 攝?度,溫控策略開始?作,并且70 攝?度也是tsadc 觸發中斷的?個閥值 */temperature = <70000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時觸發中斷,當前未實現,但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "passive" ; /* 表?超過該溫度值時,使?polling-delay-passive */};/* 溫控?標溫度,期望通過降頻使得芯?不超過該值 */target : trip -point -1 {/* 期望通過降頻使得芯?不超過85 攝?度,并且85 攝?度也是tsadc 觸發中斷的?個閥值 */temperature = <85000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時觸發中斷,當前未實現,但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "passive" ; /* 表?超過該溫度值時,使?polling-delay-passive */};/* 過溫保護閥值,如果降頻后溫度仍然上升,那么超過該值后,讓系統重啟 */soc_crit : soc -crit {/* 超過115 攝?度重啟,并且115 攝?度也是tsadc 觸發中斷的?個閥值 */temperature = <115000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時觸發中斷,當前未實現,但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "critical" ; /* 表?超過該溫度值時,重啟 */};};/* cooling device 配置節點,每個?節點代表?個cooling device */cooling -maps {map0 {/** 表?在target trip 下,該cooling device 才起作?,* 對于power allocater 策略必須填target*/trip = <& target >;/* A53 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <4096 >; /* 計算功耗時乘以4096/1024 倍,?于調整降頻順序和尺度 */};map1 {/** 表?在target trip 下,該cooling device 才起作?,* 對于power allocater 策略必須填target*/trip = <& target >;/* A72 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <1024 >;/* 計算功耗時乘以1024/1024 倍,?于調整降頻順序和尺度 */};map2 {/** 表?在target trip 下,該cooling device 才起作?,* 對于power allocater 策略必須填target*/trip = <& target >;/* GPU 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <4096 >;/* 計算功耗時乘以4096/1024 倍,?于調整降頻順序和尺度 */};};};/* ?個節點對應?個thermal zone ,并包含溫控策略相關參數,當前thermal zone 只?于獲取溫度 */gpu_thermal : gpu -thermal {/* 包含溫控策略配置的情況下才起作?,架要求必須填 */polling -delay -passive = <100 >; /* milliseconds *//* 每隔1000ms 獲取?次溫度 */polling -delay = <1000 >; /* milliseconds *//* 當前thermal zone 通過tsadc1 獲取溫度 */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 (温度控制)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。