Proxmox VE 调节cpu频率

一般我们可以使用linux-power来调节频率,实现节能或者提高性能的目的。

安装软件包

apt update && apt install linux-cpupower powertop -y

快速设置策略

# 全核高性能
cpupower  frequency-set -g performance

# 全核省电
cpupower  frequency-set -g powersave

# 0-16 开启高性能
cpupower -c 0-15  frequency-set -g  performance

performance核powersave都是调度策略,一共有下面几个

  • conservative
  • ondemand
  • userspace
  • powersave
  • performance
  • schedutil

这几个,可以参考这个文章

https://blog.csdn.net/lixiaojie1012/article/details/123742376

不过都是废话,总结来说,就powersave 和performance最好用。

内核驱动

一般在intel平台,系统使用intel_cpufreq作为驱动,amd平台使用amd-cpufreq。

对于intel来说一切正常,但是在pve8,amd使用acpi-cpufreq则会有点问题。下面是7d12默认情况下的信息。

root@cnode6:~# cpupower frequency-info
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency:  Cannot determine or is not supported.
  hardware limits: 1000 MHz - 1.96 GHz
  available frequency steps:  1.10 GHz, 1000 MHz
  available cpufreq governors: conservative ondemand userspace powersave performance schedutil
  current policy: frequency should be within 1000 MHz and 1.10 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency: 1.10 GHz (asserted by call to hardware)
  boost state support:
    Supported: yes
    Active: yes
    Boost States: 0
    Total States: 3
    Pstate-P0:  1100MHz
    Pstate-P1:  1000MHz
    Pstate-P2:  1000MHz

我们可以看到硬件限制只有2G最高,7d12可是可以全核2.9的存在。

针对amd来说我们只需要在linux启动命令中添加amd_pstate=passive即可,使用amd_pstate。

 

 

 

 

白名单模式手动调频

但这2者都是绝对的,我们需要手动进行修改。在pve7.3中 引入了核心绑定,意思是可以将虚拟机的运行线程指定到某些核心上。

那么我们就可以将重要的虚拟机运行的核心 设置成performance,其他不用的核心设置成powersave。

这种就相当于是白名单模式,

将全核设置成省电。

cpupower frequency-set -g powersave

对单个虚拟机进行核心绑定,核心绑定教程参考https://foxi.buduanwang.vip/virtualization/pve/2796.html/

#假如虚拟机id为133
cpupin=`qm config 133|grep affin|awk '{print $2}'`
cpupower -c $cpupin frequency-set -g performance

当虚拟关机之后,可以设置成powersave。

自动化

那么如何自动化呢?我们可以利用pve的hookscripts

使用下面命令创建一个hookscript,当开机时,设置成高性能,当关机时,设置省电。

cat > /var/lib/vz/snippets/cpupower.sh << "EOF"
#!/bin/bash
vmid=$1
status=$2

cpupin=`qm config $vmid|grep affin|awk '{print $2}'`
echo $status
if [ "$status" == "pre-start" ];then
        cpupower -c $cpupin frequency-set -g performance
fi

if [ "$status" == "post-stop" ];then
        cpupower -c $cpupin frequency-set -g powersave
fi
EOF

然后给与脚本执行权限,chmod +x /var/lib/vz/snippets/cpupower.sh

随后给虚拟机绑定钩子脚本,请把下面的133改成你的虚拟机id。

qm set 133 --hookscript local:snippets/cpupower.sh

这样有一个弊端,就是虚拟机如果有绑核重复在不同时间关机,会造成影响

 

 

 

https://foxi.buduanwang.vip/virtualization/pve/bestpractice/3031.html/

评论

  1. CC2024
    Windows Chrome 102.0.0.0
    1月前
    2024-3-21 15:13:12

    设置了全核省电模式后,重启pve为什么又变成性能模式的?

  2. mildnes
    Macintosh Edge 118.0.2088.46
    6月前
    2023-10-16 18:55:54

    对了,另外补充一下,其实amd直接开启性能模式之后,就已经是全核睿频了,我用命令watch grep \"cpu MHz\" /proc/cpuinfo查看了。没啥问题。结合之前绑定cpu的教程,把大部分时间待机的虚拟机绑定到了固定核心上面,然后开启了省电,其他常用的改成了性能模式,功耗大概降低了10多W。全核省电对比全核性能模式,下降了大概40W

  3. mildnes
    Macintosh Edge 118.0.2088.46
    6月前
    2023-10-16 18:41:52

    大佬,我这个之前测试过,amd的cpu在启动命令中添加了amd_pstate=passive这个,实际上可能就读取不到cpu的频率了,或者没有变化。比如我用的7302P。改了之后可以使用的策略没了,然后档位也没有了。。

    • 佛西 博主
      Macintosh Safari 17.0
      6月前
      2023-10-17 10:16:32

      amd有些麻烦,zen3默认就还行。没有档位应该需要在bios里设置pstate的档位。然后由os调用。

  4. FlyingDtchmn
    iPhone Safari 16.6
    7月前
    2023-10-15 15:11:30

    使用pve也有两年了,想请教一下,硬盘都挂载在宿主机上的情况下,虚拟机想要读写这些硬盘怎样才是最省资源的?使用smb、nfs数据貌似会经过物理网卡,影响带宽;如果单独开一个虚拟交换机,cpu占用又会变高。有没有别的分享方式,或者万兆网卡硬件虚拟化是不是会解决问题?真心求教🙏

    • 佛西 博主
      Macintosh Safari 17.0
      6月前
      2023-10-17 10:13:31

      使用virtiofs


Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/wwwroot/foxi.buduanwang.vip_80/wwwroot/wp-content/themes/argon-theme-master/functions.php on line 1383

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇