熱管理(Thermal Management)是什么?
熱管理指的是在電子設備或系統中通過各種方式控制其溫度來保證其正常工作或延長壽命的過程。其中包括散熱設計、溫度監測、溫度控制等方面。熱管理的重要性越來越凸顯,尤其在高性能計算、人工智能等領域的應用中更為重要。
管理之前要有策略,之后要有控制操作。
熱設計(Thermal Design)是指在產品設計階段為了滿足特定工作負載和環境條件等要求,采用合適的散熱方案和材料等措施,以達到良好的熱管理效果。其主要目的是確保產品在正常工作條件下溫度不超過設計范圍,避免由于過熱導致的性能下降、系統崩潰、壽命縮短等問題。
熱控(Thermal Control)是指在實際使用中采用各種措施控制電子設備或系統的溫度,以確保其工作在安全、穩定的溫度范圍內。主要包括基于溫度感應器的風扇旋轉控制、電壓和頻率的調整、動態散熱管理等技術。
熱管理、熱設計、熱控三者密不可分,熱設計是熱管理的前置條件,而熱控則是熱管理的具體實現。同時,三者也相互影響,優良的熱設計可以降低需要的熱控次數,有效延長產品壽命。熱控根據具體實際情況,需要根據實際情況進行決策和優化,以達到最佳熱管理效果。
1. Linux中Thermal框架
在 Linux 內核中,Thermal 特指一套關于溫控機制的驅動框架,其目的是為了防止 SoC 等硬件芯片因過熱而造成系統不穩定,甚至縮減芯片壽命。
Thermal sensor driver,SoC 內部 CPU 和 GPU 的旁邊通常會有用于獲取它們溫度的傳感器,比如 tsadc(Temperature Sensor ADC)。關于傳感器的更多細節我們在 sensor driver 章節再進行深入探討。獲取溫度的設備:在 Thermal 框架中被抽象為 Thermal Zone Device;
Thermal cooling device,降溫設備,比如風扇。這里有點特殊的是,CPU 和 GPU 不僅是發熱設備(即需要實施溫控策略的設備),也可以是降溫設備,當我們降低 CPU/GPU 的運行頻率的時候,它們就在充當降溫設備。降低產熱量即是在降溫。
Thermal governer,溫控策略,Linux 內核中的溫控策略要比空調控制精細得多,而且也提供了多種策略。
Thermal core,組織并管理上面三個組件,并通過 sysfs 和用戶空間交互。
代碼舉例:
Thermal sensor driver 代碼: drivers/thermal/rockchip_thermal.c /* tsadc驅動 */ Thermal cooling device 相關代碼: drivers/thermal/devfreq_cooling.c drivers/thermal/cpu_cooling.c Thermal governor 相關代碼: drivers/thermal/power_allocator.c /* power allocator 溫控策略 */ drivers/thermal/step_wise.c /* step wise 溫控策略 */ drivers/thermal/fair_share.c /* fair share 溫控策略 */ drivers/thermal/user_space.c /* userspace 溫控策略 */ Thermal core 相關代碼: drivers/thermal/thermal_core.c drivers/thermal/of_thermal.c
相關的節點:/sys/class/thermal
例如使用step_wise溫控策略:
2. sensor driver相關
這部分一般需要自己開發,例如rockchip平臺上
struct rockchip_thermal_sensor { struct rockchip_thermal_data *thermal; struct thermal_zone_device *tzd; int id; };
struct rockchip_thermal_sensor:RK 平臺上該結構體代表了一個 tsadc;
struct rockchip_thermal_data:見下面的介紹;
struct thermal_zone_device:一個 tsadc 會和一個 thermal zone 綁定;
int id:該 tsadc 的編號,一般來說 RK 的 SoC 內部有兩個 tsadc;
struct rockchip_thermal_data:sensor driver 的私有數據,詳見注釋。RK 的 sensor driver 為了兼容他們家很多 SoC 的 tsadc,把差異性的東西抽出來。比如那些函數指針,由于寄存器地址的不一樣函數體的具體內容也會不一樣,如 RK3399 和 PX30 之間。再比如由于 SoC 制程不一樣,默認的關機溫度也可能不一樣。
3. governor
struct thermal_governor:用來描述一個 governor(即溫控策略) 信息。
內核目前有五種 governor:
1、power_allocator:引? PID(?例-積分-微分)控制,根據當前溫度,動態給各 cooling device 分配 power,并將 power 轉換為頻率,從而達到根據溫度限制頻率的效果。
2、step_wise:根據當前溫度,cooling device 逐級降頻。
3、fair share:頻率檔位?較多的 cooling device 優先降頻。
4、bang bang:兩點溫度調節,可用于 cooling device 有風扇的場景。
5、userspace:用戶空間控制。
4. cooling device
嵌入式設備通過改變頻率電壓,來達到改變功耗的目的,cooling_device提供了獲取當前設備的溫控狀態以及設置等接口;
struct thermal_cooling_device { int id; char type[THERMAL_NAME_LENGTH]; struct device device; struct device_node *np; void *devdata; const struct thermal_cooling_device_ops *ops; bool updated; /* true if the cooling device does not need update */ struct mutex lock; /* protect thermal_instances list */ struct list_head thermal_instances; struct list_head node; }; struct thermal_cooling_device_ops { int (*get_max_state) (struct thermal_cooling_device *, unsigned long *); int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *); int (*set_cur_state) (struct thermal_cooling_device *, unsigned long); int (*get_requested_power) (struct thermal_cooling_device *, struct thermal_zone_device *, u32 *); int (*state2power) (struct thermal_cooling_device *, struct thermal_zone_device *, unsigned long, u32 *); int (*power2state) (struct thermal_cooling_device *, struct thermal_zone_device *, u32, unsigned long *);
struct thermal_cooling_device:用來描述一個 cooling device(即降溫設備) 信息,并將函數操作集抽取出來。DTS中配置:
bind1{ contribution = <0>; trip = <&cpu_trip1>; cooling-device = <&cpu_budget_cooling 2 2>; }; cpu_budget_cooling:cpu_budget_cool{ compatible = "allwinner,budget_cooling"; device_type = "cpu_budget_cooling"; #cooling-cells = <2>; status = "okay"; state_cnt = <7>; cluster_num = <1>; state0 = <1800000 4>; state1 = <1512000 4>;

5. thermal zone
獲取溫度的設備:在 Thermal 框架中被抽象為 Thermal Zone Device;
struct thermal_zone_device { int id; char type[THERMAL_NAME_LENGTH]; struct device device; struct thermal_attr *trip_temp_attrs; struct thermal_attr *trip_type_attrs; struct thermal_attr *trip_hyst_attrs; void *devdata; int trips; unsigned long trips_disabled;/* bitmap for disabled trips */ int passive_delay; int polling_delay; int temperature; int last_temperature; int emul_temperature; int passive; unsigned int forced_passive; atomic_t need_update; struct thermal_zone_device_ops *ops; struct thermal_zone_params *tzp; struct thermal_governor *governor; void *governor_data; struct list_head thermal_instances; struct idr idr; struct mutex lock; struct list_head node; struct delayed_work poll_queue; }; struct thermal_zone_device_ops { int (*bind) (struct thermal_zone_device *, struct thermal_cooling_device *); int (*unbind) (struct thermal_zone_device *, struct thermal_cooling_device *); int (*get_temp) (struct thermal_zone_device *, int *); int (*get_mode) (struct thermal_zone_device *, enum thermal_device_mode *); int (*set_mode) (struct thermal_zone_device *, enum thermal_device_mode); int (*get_trip_type) (struct thermal_zone_device *, int, enum thermal_trip_type *); int (*get_trip_temp) (struct thermal_zone_device *, int, int *); int (*set_trip_temp) (struct thermal_zone_device *, int, int);// 設置溫度窗口 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *); int (*set_trip_hyst) (struct thermal_zone_device *, int, int); int (*get_crit_temp) (struct thermal_zone_device *, int *); int (*set_emul_temp) (struct thermal_zone_device *, int); int (*get_trend) (struct thermal_zone_device *, int, enum thermal_trend *); int (*notify) (struct thermal_zone_device *, int, enum thermal_trip_type);
struct thermal_zone_device:一個 thermal zone 是根據 dts 里的配置一步步解析并構建的,包含了很多信息,比如服務于該 thermal zone 的 tsadc,服務于該 thermal zone 的降溫設備,該 thermal zone 所用的 governor,以及 thermal 機制工作時所需的一些參數,等等。
通常,RK 平臺上 thermal zone 的 dts 配置格式如下。其它平臺應該和這個大同小異,因為都要基于 thermal core 來配置。
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>; /* 計算功耗時乘以4096/1024倍,用于調整降頻順序和尺度 */ contribution = <4096>; }; 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>; /* 計算功耗時乘以1024/1024倍,用于調整降頻順序和尺度 */ contribution = <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>; /* 計算功耗時乘以4096/1024倍,用于調整降頻順序和尺度 */ contribution = <4096>; }; }; }; /* 一個節點對應一個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>; }; };
在probe中完成注冊:
sensor->tz = thermal_zone_of_sensor_register(&pdev->dev, id, sensor, &combine_ops);
溫度獲取流程:
sunxi_combine_get_temp //sunxi_ths_combine.c -->ret = controller->ops->get_temp(controller,sensor_id, &temp); sunxi_ths_get_temp // sunxi_ths_core.c -->t = ths_driver_get_temp(ths_data, id); ths_driver_reg_to_temp(reg_data, id, ths_data->ths_driver_version, ths_data->ths_coefficent->calcular_para); //sunxi_ths_driver.c
6. thermal core
在thermar core作為中樞注冊governor,注冊Thermal類,并且基于Device Tree注冊Thermal Zone;提供Thermal zone注冊函數,Cooling Device注冊函數,提供將Cooling設備綁定到Zone的函數,一個Thermal Zone可以有多個Cooling設備;同時還提供一個核心函數Thermal_zone_deviceupdate作為Thermal中斷處理函數和輪詢函數,輪詢時間會根據不同Trip Delay調節
thermal輪詢流程:
在thermal core中通過不斷的輪詢來檢測溫度變化,如果溫度沒有達到crital則調用governor的throttle,通過governor的throttle決定下一次輪詢的時間;如果溫度為crital則走關機流程;
7. SoC硬件中設計
一般傳感器使用PVT模塊實現,PVTC中會包含多個temperature sensors、Voltage Monitor、Process Detectors PVT包含以下幾種傳感器:
Thermal Sensing(TS):熱傳感,精度高,集成方便。支持功率優化和可靠性
Distributed Thermal Sensing(DTS):分布式熱傳感。支持thermal mapping,高度精細的布放,低延時
Supply Monitoring(VM):供電監控,測量多個域的電源電壓、驗證配電網絡、實施靜態和動態IR壓降分析
Process Monitoring(PD):工藝監控,在大規模量產或者單個芯片生命周期,了解硅片速度變化(slow,fast,typical)。提供功率優化和老化監控
另外一種方式是使用單獨的thermal sensor,通過I2C slave接入MCU核心。CPU核心可以通過I2C讀取穩定,可以防止內部PVT損壞的影響。
后記:
電源管理相關的知識看似不多,但是詳細研究起來,根本研究不完。有時候要做一個件事情,不一定要追求完美,要確定好要做到的程度,比如公司里面調試某個功能,那么就必須研究透徹,但是相關的知識點自學,不需要實際動手調試,那就要了解框架即可,我們不可能什么活都干一遍,但是很多活不干一遍是不能體會其精髓的。確定好度很重要,防止陷入進去,同時防止走馬觀花沒有任何效果的形式主義。
電源管理系列剛開始都是作者參與調試的代碼,后來的就是擴展學習了,雖然不進行代碼調試,但是也力求把框架搞明白,做個記錄。以后或許那天要調試了再拿出來可以看看。
-
電源管理
+關注
關注
116文章
6267瀏覽量
145570 -
Linux
+關注
關注
87文章
11406瀏覽量
212095 -
熱管理
+關注
關注
11文章
465瀏覽量
22163 -
熱設計
+關注
關注
11文章
130瀏覽量
26873
原文標題:電源管理入門-13Thermal 熱管理
文章出處:【微信號:OS與AUTOSAR研究,微信公眾號:OS與AUTOSAR研究】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
電源管理入門:驅動Runtime PM管理

電源管理入門:Power Domain管理

電源管理入門:Hypervisor中的電源管理

評論