A133 Thermal

芯片温度控制

Posted by LXG on July 5, 2023

概念

Thermal 俗称热控制系统,其功能是通过 temperature sensor 测量当前 CPU、GPU 等设备的温度值,然后根据此温度值,影响 CPU、GPU 等设备的调频策略,对 CPU、GPU 等设备的最大频率进行限制, 最终实现对 CPU、GPU 等设备温度的闭环控制,避免 SOC 温度过高。

IPA(Intelligent Power allocator) 温控策略:引入 PID 控制,根据系统温度动态分配 power给各个设备,并将 power 转化为频率限制

驱动配置

board.dts


		ths: thermal_sensor{
			compatible = "allwinner,sun50iw10p1-ths";
			reg = <0x0 0x05070400 0x0 0x400>;
			clocks = <&clk_ths>;
			clock-names = "bus";
			nvmem-cells = <&ths_calib>;
			nvmem-cell-names = "calibration";
			#thermal-sensor-cells = <1>;
		};

		thermal-zones {
			cpu_thermal_zone {
				polling-delay-passive = <500>;  // 温度超过阈值,轮询温度周期(ms)
				polling-delay = <1000>;         // 温度未超过阈值,轮询温度周期(ms)
				thermal-sensors = <&ths 0>;
				sustainable-power = <1200>;     // 温度达到预设温度最大值,系统可分配的最大power
				k_po = <66>;
				k_pu = <132>;
				k_i = <0>;

				cpu_trips: trips {
					cpu_threshold: trip-point@0 {
						temperature = <70000>;   // 代表系统温控在70度左右开启
						type = "passive";
						hysteresis = <0>;
					};
					cpu_target: trip-point@1 {
						temperature = <90000>;   // 代表系统最高温度是80度左右
						type = "passive";
						hysteresis = <0>;
					};
					cpu_crit: cpu_crit@0 {
						temperature = <110000>;  // 代表系统到达110度就会过温关机
						type = "critical";
						hysteresis = <0>;
					};
				};

				cooling-maps {
					map0 {
						trip = <&cpu_target>;
						cooling-device = <&cpu0
						THERMAL_NO_LIMIT
						THERMAL_NO_LIMIT>;
						contribution = <1024>;
					};
				/*	map1{
						trip = <&cpu_target>;
						cooling-device = <&gpu
						THERMAL_NO_LIMIT
						THERMAL_NO_LIMIT>;
						contribution = <1024>;
					};	*/
				};
			};
			gpu_thermal_zone{
				polling-delay-passive = <500>;
				polling-delay = <1000>;
				thermal-sensors = <&ths 1>;
				sustainable-power = <1100>;
			};
			ddr_thermal_zone{
				polling-delay-passive = <0>;
				polling-delay = <0>;
				thermal-sensors = <&ths 2>;
			};
		};


查看温度

方法1


ceres-c3:/ $ cat sys/class/thermal/thermal_zone0/type                                                                                                                                                                          
cpu_thermal_zone
ceres-c3:/ $ cat sys/class/thermal/thermal_zone0/temp                                                                                                                                                                          
41299

ceres-c3:/ $ cat sys/class/thermal/thermal_zone1/type                                                                                                                                                                          
gpu_thermal_zone
ceres-c3:/ $ cat sys/class/thermal/thermal_zone1/temp                                                                                                                                                                          
42907

ceres-c3:/ $ cat sys/class/thermal/thermal_zone2/type                                                                                                                                                                          
ddr_thermal_zone
ceres-c3:/ $ cat sys/class/thermal/thermal_zone2/temp                                                                                                                                                                          
43443

方法2


130|ceres-c3:/ $ cpu_monitor -s 1000                                                                                                                                                                                           
------------------------- CPU[x]<Freq:MHZ>-<Usage:%>-------------------------
      CPU0         CPU1         CPU2         CPU3     Temp   GPU  GTemp   DDR   Times
  |   0  32%|  |   0  10%|  |   0  13%|  |   0   6%|  41768   504   42907     0     0 
  |   0   3%|  |   0   3%|  |   0   4%|  |   0   2%|  42036   504   43041     0     1 
  |   0   4%|  |   0   5%|  |   0   3%|  |   0   7%|  41701   504   42773     0     2 
  |   0   7%|  |   0   4%|  |   0   6%|  |   0  10%|  41768   504   42572     0     3 
  |   0   1%|  |   0   0%|  |   0   0%|  |   0   0%|  41433   504   42572     0     4 
  |   0   4%|  |   0   2%|  |   0   3%|  |   0   0%|  41165   504   42639     0     5 
  |   0   0%|  |   0   0%|  |   0   1%|  |   0   0%|  41031   504   42371     0     6

模拟温度


设置模拟温度

echo 80000 > /sys/class/thermal/thermal_zone0/emul_temp

关闭模拟温度

echo 0 > /sys/class/thermal/thermal_zone0/emul_temp

关闭温控


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