玩客云armbian动态调频降温

  1. 安装apt install cpufrequtils
  2. 查看是否支持ondemand
    cpufreq-info
    cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
    1. powersave 是无论如何都只会保持最低频率的所谓“省电”模式;
    2. userspace 是自定义频率时的模式,这个是当你设定特定频率时自动转变的;
    3. ondemand 默认模式。一有cpu计算量的任务,就会立即达到最大频率运行,等执行完毕就立即回到最低频率;
    4. conservative 保守模式,会自动在频率上下限调整,和ondemand的区别在于它会按需分配频率,而不是一味追求最高频率;
    5. performance 只注重效率,无论如何一直保持以最大频率运行。
    6. schedutil 基于调度程序调整 CPU 频率。
  3. 如果不是调整为ondemand
    cpufreq-set -g ondemand
  4. 新建cpu-control.sh
    vi /usr/sbin/cpu-control.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/sh  
#脚本功能:每过6秒检测一次,当cpu温度低于42℃时,调整cpu频率为400MHz-1540MHz之间;高于46℃时,调整cpu频率为400MHz-800MHz之间。
#引入i、j变量,防止重复执行调频命令。
i=1 #低温提高主频
j=0 #高温降低主频
while true
do
   
set -- $(cat /sys/class/thermal/thermal_zone0/temp \
             /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
    TEMP=$1
    GOVERNOR=$2
    if [ "$TEMP" -le 42000 ] && [ "$GOVERNOR" = "ondemand" ] && [ $i -eq 1 ]; then
        cpufreq-set -d 400MHz -u 1540MHz
        echo "已升频"
        i=0
        j=0
    fi
   
    if [ "$TEMP" -ge 46000 ] && [ "$GOVERNOR" = "ondemand" ] && [ $j -eq 0 ]; then
        cpufreq-set -d 400MHz -u 800MHz
        echo "已降频"
        i=1
        j=1
    fi
   
    echo "当前cpu温度:" $(($TEMP / 1000))"℃"
    echo $i $j "【提示:1 1处于降频状态;0 0处于升频状态;1 0处于初始状态】"
   
sleep 6
done

设置权限
cd /usr/sbin/
sudo chmod -R 755 cpu-control.sh

  1. 设置服务开机自启
    vi /lib/systemd/system/cpu-control.service
1
2
3
4
5
6
7
8
9
10
11
[Unit]  
#服务描述
Description=CPU Governor Control by Temperature

[Service]
#执行命令
Type=simple
ExecStart=/bin/sh /usr/sbin/cpu-control.sh

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl enable cpu-control.service
systemctl start cpu-control.service
systemctl status cpu-control.service

参考
https://www.right.com.cn/forum/thread-6728637-1-1.html
推荐armbian版本
https://www.right.com.cn/forum/forum.php?mod=viewthread&tid=4103842


玩客云armbian动态调频降温
https://hexo.psorai.eu.org/2023/10/17/玩客云armbian动态调频降温/
Author
Sora
Posted on
October 17, 2023
Licensed under