linux cooling device
这里详细介绍并理解基于 allwinner a64 linux 下根据热量传感器 采集的温度用以自动调频 原理。
thermal sensor
a64集两个热量传感器分别监控gpu和cpu温度。
The thermal sensors have become common elements in wide range of modern system on chip (SOC) platform.
Thermal sensors are used to constantly monitor the temperature on the chip.
A64 embeds three thermal sensors in possible hot spots on the die, sensor0 located in the CPU, sensor1 and
sensor2 located in the GPU. The thermal sensor Generates interrupt to SW to lower temperature via DVFS, on
reaching a certain thermal threshold
提示:Allwinner_A64_User_Manual_V1.1_decrypted.pdf->3.18. Thermal Sensor Controller ->3.18.1. Overview。
挂载在sysfs数据属性
pi@350-tf-s2 ~$ tree /sys/class/thermal/thermal_zone0/
/sys/class/thermal/thermal_zone0/
├── mode #enalbed 、disabled ,可读写
├── policy #step_wise
├── temp #温度值
├── trip_point_0_hyst #0 看起来像一个调节范围
├── trip_point_0_temp #65 温度阈值
├── trip_point_0_type #passive
├── ......
├── trip_point_6_hyst #0
├── trip_point_6_temp #110
├── trip_point_6_type #critical
├── type #soc_thermal
└── uevent
governor
挂载sysfs 数据属性。
pi@350-tf-s2 ~$ tree /sys/devices/system/cpu/cpu0/cpufreq/
/sys/devices/system/cpu/cpu0/cpufreq/
├── affected_cpus #0 1 2 3
├── boot_lock #0
├── cpuinfo_boot_freq #1152000
├── cpuinfo_cur_freq
├── cpuinfo_max_freq #1344000
├── cpuinfo_min_freq #480000
├── cpuinfo_transition_latency #2000000
├── related_cpus #0 1 2 3
├── scaling_available_frequencies #480000 600000 720000 816000 1008000 1104000 1152000 1200000 1344000
├── scaling_available_governors #interactive conservative ondemand userspace powersave performance
├── scaling_cur_freq #当前cpu频率
├── scaling_driver #cpufreq-sunxi
├── scaling_governor #ondemand
├── scaling_max_freq #调节范围最大值
├── scaling_min_freq #调节范围最小值
├── scaling_setspeed #<unsupported>
└── stats
├── time_in_state
├── total_trans
└── trans_table
cooling device
挂载在sysfs数据属性
pi@350-tf-s2 ~$ tree /sys/class/thermal/cooling_device0
/sys/class/thermal/cooling_device0
├── cur_state # 0当前状态值,可写,写入该状态值直接影响CPU主频变化
├── max_state #6 最大值
├── power
│ ├── async
│ ├── autosuspend_delay_ms
│ ├── control
│ ├── runtime_active_kids
│ ├── runtime_active_time
│ ├── runtime_enabled
│ ├── runtime_status
│ ├── runtime_suspended_time
│ └── runtime_usage
├── subsystem -> ../../../../class/thermal
├── type
└── uevent
/var/log/syslog
日志分析
kernel: [239144.300372] CPU Budget:update CPU 0 cpufreq max to 816000 min to 480000
kernel: [239144.302585] CPU Budget hotplug: cluster0 min:0 max:4
kernel: [239144.792365] CPU Budget:update CPU 0 cpufreq max to 1008000 min to 480000
kernel: [239144.794593] CPU Budget hotplug: cluster0 min:0 max:4
kernel: [239145.776364] CPU Budget:update CPU 0 cpufreq max to 816000 min to 480000
kernel: [239145.778579] CPU Budget hotplug: cluster0 min:0 max:4
如上日志表示基于cpu核心温度变化自动调节了cpu主频最大值。
test script
如下代码片段设计:
- 设计cpu压力测试(温度高会自自动调频);
- 增加手动切换调频;
- 实时打印温度、频率范围、当前频率值;
- 可以尝试去掉cpu自动调频;
# !/bin/bash
[ -f /usr/bin/bc ] || {
wget https://mirrors.sohu.com/debian/pool/main/b/bc/bc_1.06.95-9_arm64.deb
sudo dpkg -i bc_1.06.95-9_arm64.deb
}
#cpu pressure test
echo "scale=500000; 4*a(1)" | bc -l -q &
echo "scale=500000; 4*a(1)" | bc -l -q &
echo "scale=500000; 4*a(1)" | bc -l -q &
echo "scale=500000; 4*a(1)" | bc -l -q &
echo "disabled" |sudo tee /sys/class/thermal/thermal_zone0/mode
echo 4 |sudo tee /sys/class/thermal/cooling_device0/cur_state
let flag=1
while [ 1 ]
do
if [ $flag -eq 0 ];then
let flag=1
echo 2 |sudo tee /sys/class/thermal/cooling_device0/cur_state
else
let flag=0
echo 3 |sudo tee /sys/class/thermal/cooling_device0/cur_state
fi
echo -e "\033[32m$(date) \033[0m"
echo "temp: $(cat /sys/class/thermal/thermal_zone0/temp)"
echo "cur_state: $(cat /sys/class/thermal/cooling_device0/cur_state)"
echo "min_freq: $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq)"
echo "max_freq: $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq)"
echo "cur_freq: $(sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq)"
top -bn 1 -i -c |head -n 5
echo ""
sleep 1
done
还不快抢沙发