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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

RK3399 Thermal (温度控制)

發(fā)布時(shí)間:2023/12/16 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 RK3399 Thermal (温度控制) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
RK3399 Thermal (溫度控制)

本文采用知識(shí)共享署名 4.0 國(guó)際許可協(xié)議進(jìn)行許可,轉(zhuǎn)載時(shí)請(qǐng)注明原文鏈接,圖片在使用時(shí)請(qǐng)保留全部?jī)?nèi)容,可適當(dāng)縮放并在引用處附上圖片所在的文章鏈接。

  • Thermal 是什么
  • 配置?法
    • Menuconfig配置
    • Tsadc配置
    • CPU & GPU配置
    • Termal zone 配置
  • ??態(tài)接口
  • 常用設(shè)置
    • 獲取當(dāng)前溫度
    • 關(guān)閉溫度控制功能
  • 參考

Thermal 是什么

Thermal是內(nèi)核開發(fā)者定義的?套?持根據(jù)指定governor控制系統(tǒng)溫度,以防?芯?過熱的框架模型。Thermal framework由governor、core、cooling device、sensor driver組成,軟件架構(gòu)如下:

  • Thermal governor:?于決定cooling device是否需要降頻,降到什么程度。?前Linux4.4內(nèi)核中包含了如下?種governor:
  • power_allocator:引?PID(?例-積分-微分)控制,根據(jù)當(dāng)前溫度,動(dòng)態(tài)給各cooling device分配power,并將power轉(zhuǎn)換為頻率,從而達(dá)到根據(jù)溫度限制頻率的效果。
  • step_wise :根據(jù)當(dāng)前溫度,cooling device逐級(jí)降頻。
  • fair share :頻率檔位?較多的cooling device優(yōu)先降頻。
  • userspace:不限制頻率。
  • Thermal core: 對(duì)thermal governors和thermal driver進(jìn)?了封裝和抽象,并定義了清晰的接口。
  • Thermal sensor driver:sensor驅(qū)動(dòng),?于獲取溫度,?如tsadc。
  • Thermal cooling device:發(fā)熱源或者可以降溫的設(shè)備,?如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”配置項(xiàng),可以選擇溫控策略,開發(fā)者可以根據(jù)實(shí)際產(chǎn)品需求進(jìn)?修改。

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>; /* 中斷號(hào)及中斷觸發(fā)?式 */assigned -clocks = <& cru SCLK_TSADC >; /* ?作時(shí)鐘,750KHz */assigned -clock -rates = <750000 >;clocks = <& cru SCLK_TSADC >, <& cru PCLK_TSADC >; /* ?作時(shí)鐘和配置時(shí)鐘 */clock -names = "tsadc" , "apb_pclk" ;resets = <& cru SRST_TSADC >; /* 復(fù)位信號(hào) */reset -names = "tsadc-apb" ;rockchip ,grf = <& grf >; /* 引?grf 模塊,部分平臺(tái)需要 */rockchip ,hw -tshut -temp = <120000 >; /* 過溫重啟閥值,120 攝?度 *//* tsadc 輸出引腳配置,?持兩種模式:gpio 和otpout */pinctrl -names = "gpio" , "otpout" ;pinctrl -0 = <& otp_gpio >;pinctrl -1 = <& otp_out >;/** thermal sensor 標(biāo)識(shí),表?tsadc 可以作為?個(gè)thermal sensor ,* 并指定了引?tsadc 節(jié)點(diǎn)的時(shí)候需要帶?個(gè)參數(shù)。* 如果SoC ??只有?個(gè)tsadc ,可以設(shè)置為0,超過?個(gè)必須設(shè)置為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復(fù)位還是GPIO復(fù)位,低電平復(fù)位還是?電平復(fù)位。需要特別注意的是如果配置成GPIO復(fù)位,硬件上需要否把tsadc輸出引腳連到PMIC的復(fù)位腳,否則只能配置成CRU復(fù)位。

&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,節(jié)點(diǎn)中需要包含#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 標(biāo)識(shí),表?該設(shè)備可以作為?個(gè)cooling device */clocks = <& cru ARMCLKL >;cpu -idle -states = <& CPU_SLEEP &CLUSTER_SLEEP >;dynamic -power -coefficient = <100 >; /* 動(dòng)態(tài)功耗常數(shù)C,動(dòng)態(tài)功耗公式為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 標(biāo)識(shí),表?該設(shè)備可以作為?個(gè)cooling device */clocks = <& cru ARMCLKB >;cpu -idle -states = <& CPU_SLEEP &CLUSTER_SLEEP >;dynamic -power -coefficient = <436 >; /* ?于計(jì)算動(dòng)態(tài)功耗的參數(shù) */ };

GPU在溫控中作為cooling device,節(jié)點(diǎn)需要包含#cooling-cells屬性和power_model?節(jié)點(diǎn)。
以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 標(biāo)識(shí),表?該設(shè)備可以作為?個(gè)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 >; /* ?于計(jì)算靜態(tài)功耗的參數(shù) */dynamic -coefficient = <733 >; /* ?于計(jì)算動(dòng)態(tài)功耗的參數(shù) */ts = <32000 4700 ( -80 ) 2>; /* ?于計(jì)算靜態(tài)功耗的參數(shù) */thermal -zone = "gpu-thermal" ; /* 從gpu-thermal 獲取溫度,?于計(jì)算靜態(tài)功耗 */}; };

Termal zone 配置

Termal zone節(jié)點(diǎn)主要?于配置溫控策略相關(guān)的參數(shù)并?成對(duì)應(yīng)的??態(tài)接口。
以RK3399為例:

thermal_zones : thermal -zones {/* ?個(gè)節(jié)點(diǎn)對(duì)應(yīng)?個(gè)thermal zone ,并包含溫控策略相關(guān)參數(shù) */soc_thermal : soc -thermal {/* 溫度?于trip-point-0 指定的值,每隔20ms 獲取?次溫度 */polling -delay -passive = <20 >; /* milliseconds *//* 溫度低于trip-point-0 指定的值,每隔1000ms 獲取?次溫度 */polling -delay = <1000 >; /* milliseconds *//* 溫度等于trip-point-1 指定的值時(shí),系統(tǒng)分配給cooling device 的能量 */sustainable -power = <1000 >; /* milliwatts *//* 當(dāng)前thermal zone 通過tsadc0 獲取溫度 */thermal -sensors = <& tsadc 0>;/* trips 包含不同溫度閥值,不同的溫控策略,配置不?定相同 */trips {/** 溫控閥值,超過該值溫控策略開始?作,但不?定?上限制頻率,* power 小到?定程度才開始限制頻率*/threshold : trip -point -0 {/* 超過70 攝?度,溫控策略開始?作,并且70 攝?度也是tsadc 觸發(fā)中斷的?個(gè)閥值 */temperature = <70000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時(shí)觸發(fā)中斷,當(dāng)前未實(shí)現(xiàn),但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "passive" ; /* 表?超過該溫度值時(shí),使?polling-delay-passive */};/* 溫控?標(biāo)溫度,期望通過降頻使得芯?不超過該值 */target : trip -point -1 {/* 期望通過降頻使得芯?不超過85 攝?度,并且85 攝?度也是tsadc 觸發(fā)中斷的?個(gè)閥值 */temperature = <85000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時(shí)觸發(fā)中斷,當(dāng)前未實(shí)現(xiàn),但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "passive" ; /* 表?超過該溫度值時(shí),使?polling-delay-passive */};/* 過溫保護(hù)閥值,如果降頻后溫度仍然上升,那么超過該值后,讓系統(tǒng)重啟 */soc_crit : soc -crit {/* 超過115 攝?度重啟,并且115 攝?度也是tsadc 觸發(fā)中斷的?個(gè)閥值 */temperature = <115000 >; /* millicelsius *//* 溫度低于temperature-hysteresis 時(shí)觸發(fā)中斷,當(dāng)前未實(shí)現(xiàn),但是框架要求必須填 */hysteresis = <2000 >; /* millicelsius */type = "critical" ; /* 表?超過該溫度值時(shí),重啟 */};};/* cooling device 配置節(jié)點(diǎn),每個(gè)?節(jié)點(diǎn)代表?個(gè)cooling device */cooling -maps {map0 {/** 表?在target trip 下,該cooling device 才起作?,* 對(duì)于power allocater 策略必須填target*/trip = <& target >;/* A53 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& cpu_l0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <4096 >; /* 計(jì)算功耗時(shí)乘以4096/1024 倍,?于調(diào)整降頻順序和尺度 */};map1 {/** 表?在target trip 下,該cooling device 才起作?,* 對(duì)于power allocater 策略必須填target*/trip = <& target >;/* A72 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& cpu_b0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <1024 >;/* 計(jì)算功耗時(shí)乘以1024/1024 倍,?于調(diào)整降頻順序和尺度 */};map2 {/** 表?在target trip 下,該cooling device 才起作?,* 對(duì)于power allocater 策略必須填target*/trip = <& target >;/* GPU 做為cooloing device , THERMAL_NO_LIMIT 不起作?,但必須填 */cooling -device = <& gpu THERMAL_NO_LIMIT THERMAL_NO_LIMIT >;contribution = <4096 >;/* 計(jì)算功耗時(shí)乘以4096/1024 倍,?于調(diào)整降頻順序和尺度 */};};};/* ?個(gè)節(jié)點(diǎn)對(duì)應(yīng)?個(gè)thermal zone ,并包含溫控策略相關(guān)參數(shù),當(dāng)前thermal zone 只?于獲取溫度 */gpu_thermal : gpu -thermal {/* 包含溫控策略配置的情況下才起作?,架要求必須填 */polling -delay -passive = <100 >; /* milliseconds *//* 每隔1000ms 獲取?次溫度 */polling -delay = <1000 >; /* milliseconds *//* 當(dāng)前thermal zone 通過tsadc1 獲取溫度 */thermal -sensors = <& tsadc 1>;}; };

??態(tài)接口

??態(tài)接口在/sys/class/thermal/?錄下,具體內(nèi)容和DTSI中thermal zone節(jié)點(diǎn)的配置對(duì)應(yīng)。有的平臺(tái)thermalzone節(jié)點(diǎn)下只有?個(gè)?節(jié)點(diǎn),對(duì)應(yīng)/sys/class/thermal/?錄下也只有thermal_zone0??錄;有的平臺(tái)有兩個(gè)?節(jié)點(diǎn),對(duì)應(yīng)/sys/class/thermal/?錄下就會(huì)有thermal_zone0和thermal_zone1??錄。通過??態(tài)接口可以切換溫控策略,查看當(dāng)前溫度等。
以RK3399為例?,/sys/class/thermal/thermal_zone0/?錄下包含如下常?的信息:

temp /* 當(dāng)前溫度 */ available_policies /* ?持的溫控策略 */ policy /* 當(dāng)前使?的溫控策略 */ sustainable_power /* 期望的最?溫度下對(duì)應(yīng)的power 值 */ integral_cutoff /* PID 算法中I的觸發(fā)條件:當(dāng)前溫度-期望的最?溫度<integral_cutoff */ k_d /* PID 算法中計(jì)算D的時(shí)候?的參數(shù) */ k_i /* PID 算法中計(jì)算I的時(shí)候?的參數(shù) */ k_po /* PID 算法中計(jì)算P的時(shí)候?的參數(shù) */ k_pu /* PID 算法中計(jì)算P的時(shí)候?的參數(shù) */ mode /* enabled :?帶定時(shí)獲取溫度,判斷是否需要降頻。disabled 關(guān)閉該功能 */ type /* 當(dāng)前thermal zone 的類型 */ /* 不同的溫度閥值,對(duì)應(yīng)trips 節(jié)點(diǎn)的配置 */ 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 的狀態(tài),對(duì)應(yīng)cooling-maps 節(jié)點(diǎn)的配置 */ cdev0 /* 代表?個(gè)cooling devic ,有的平臺(tái)還有cdev1 、cdev2 等 */cur_state /* 該cooling device 當(dāng)前頻率的檔位 */max_state /* 該cooling device 最多有?個(gè)檔位 */type /* 該cooling device 的類型 */ cdev0_weight /* 該cooling devic 在計(jì)算power 時(shí)擴(kuò)?的倍數(shù) */

常用設(shè)置

獲取當(dāng)前溫度

直接查看??態(tài)接口thermal_zone0或者thermal_zone1?錄下的temp節(jié)點(diǎn)即可。
以RK3399為例,獲取CPU溫度,在串口中輸?如下命令:

cat /sys /class /thermal /thermal_zone0 /temp

獲取GPU溫度,在串口中輸?如下命令:

cat /sys /class /thermal /thermal_zone1 /temp

關(guān)閉溫度控制功能

?法?:menuconfig中默認(rèn)溫控策略設(shè)置為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 */

?法?:開機(jī)后通過命令關(guān)溫控。
?先,把溫控策略切換到user_space,即把??態(tài)接口下的policy節(jié)點(diǎn)改成user_space;或者把mode設(shè)置成
disabled狀態(tài);然后,解除頻率限制,即將??態(tài)接口下的所有cdev的cur_state設(shè)置為0。
以RK3399為例,策略切換到user_space:

echo user_space > /sys /class /thermal /thermal_zone0 /policy

或者把mode設(shè)置成disabled狀態(tài):

echo disabled > /sys /class /thermal /thermal_zone0 /mode

解除頻率限制:

/* 具體有多少個(gè)cdev ,根據(jù)實(shí)際情況修改 */ 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開發(fā)指南

總結(jié)

以上是生活随笔為你收集整理的RK3399 Thermal (温度控制)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。