Linux thermal 是一个内核和温度检测控制有关的驱动子系统,其功能是通过PVT Sensor 检测当前CPU/GPU 温度值,然后根据当前温度值,采用一定的软件策略,影响GPU/CPU 的频率和CPU 核数量,对GPU/CPU 最大频率进行限制,对CPU 核数也可以动态调整,以此达到温度控制的闭环,避免SOC 温度过高,本文主要介绍在 G9 上配置获取 CPU 温度。
二、步骤
1、在 /buildsystem/yocto/source/linux/arch/arm64/boot/dts/semidrive/g9.dtsi 路径下添加 #include <dt-bindings/thermal/thermal.h> 库调用,并添加以下节点:
cooling_devices: cooling_devices { compatible = "simple-mfd"; status = "disabled";
cpufreq_cluster0: cpufreq_cluster0 { compatible = "semidrive, cpufreq-cooling"; status = "okay"; #cooling-cells = <2>; cluster_id = <0>; };
cpucore_cluster0: cpucore_cluster0 { compatible = "semidrive, cpucore-cooling"; status = "okay"; #cooling-cells = <2>; cluster_id = <0>; }; };
pvt_sensor: pvt_sensor@0x30880000{ compatible = "semidrive, kunlun-pvt-sensor"; reg = <0x0 0x30880000 0x0 0x1000>; #thermal-sensor-cells = <1>; pvt_sensor_mode = "temp"; alarm_num = <1>; interrupts = <GIC_SPI 228 IRQ_TYPE_LEVEL_HIGH>; status = "disabled"; alarm0 { alarm_hyst_type = "hyst_r"; alarm_low_temp = <90>; alarm_high_temp = <100>; }; };
thermal-zones{ cpu_thermal_zone0{ polling-delay-passive = <1000>; polling-delay = <2000>; thermal-sensors = <&pvt_sensor 0>; status = "okay"; trips{ cpu_trip0:t0{ temperature = <100>; type = "passive"; hysteresis = <0>; }; cpu_trip1:t1{ temperature = <110>; type = "passive"; hysteresis = <0>; }; cpu_trip2:t2{ temperature = <120>; type = "passive"; hysteresis = <0>; }; crt_trip0:t4{ temperature = <135>; type = "critical"; hysteresis = <0>; }; }; cooling-maps { bind0 { contribution = <0>; trip = <&cpu_trip0>; cooling-device = <&cpufreq_cluster0 THERMAL_NO_LIMIT 2>; }; bind1{ contribution = <0>; trip = <&cpu_trip1>; cooling-device = <&cpufreq_cluster0 THERMAL_NO_LIMIT 3>; }; bind2{ contribution = <0>; trip = <&cpu_trip2>; cooling-device = <&cpucore_cluster0 THERMAL_NO_LIMIT 3>; }; }; }; }; |
2、在 /buildsystem/yocto/source/linux/arch/arm64/boot/dts/semidrive/g9x_ref.dts 路径下添加使能以下节点:
&cooling_devices { status = "okay"; };
&pvt_sensor { status = "okay"; }; |
3、在路径 /buildsystem/yocto/source/linux/arch/arm64/configs/g9_ref_defconfig 下添加以下配置:
CONFIG_THERMAL=y CONFIG_SEMIDRIVE_THERMAL=y CONFIG_SEMIDRIVE_PVT_SENSOR=y |
4、并将/buildsystem/yocto/source/linux/drivers/Makefile、
/buildsystem/yocto/source/linux/drivers/thermal/Makefile、
/buildsystem/yocto/source/linux/drivers/thermal/semidrive/Makefile、
/buildsystem/yocto/source/linux/drivers/thermal/semidrive/semidrive_sensor/Makefile
中的 $(CONFIG_THERMAL)、$(CONFIG_SEMIDRIVE_THERMAL)、$(CONFIG_SEMIDRIVE_PVT_SENSOR)这三个参数变成 y。
5、执行 make linux,make genpac 打包。
6、系统启动后 cat /sys/devices/virtual/thermal/thermal_zone0/temp 即可看到当前 CPU 温度。
三、参考文档
1、《SemiDrive Linux BSP User Manual Rev1.1》
四、总结
以上步骤实现了在 G9 获取 CPU 温度。接下来将会更新更多关于 SemiDrive G9 系列的文章,感兴趣的可以在评论区评论或者关注。
评论