Ubuntu CPUInfo频率如何设置
小樊
41
2025-11-21 14:53:07
Ubuntu 调整 CPU 频率的完整指南
一 概念与查看
/proc/cpuinfo 的作用 :它显示的是 CPU 的“标称信息”和“瞬时采样值”,其中的 cpu MHz 通常是采样瞬间的频率,不能用来“设置”频率。要控制和查看可变频策略,应使用 cpufreq 子系统(如 /sys/devices/system/cpu/cpu /cpufreq/ * 下的接口)。
常用查看命令:
查看策略与频率信息:cpufreq-info
快速看各逻辑核当前频率:cat /proc/cpuinfo | grep MHz | uniq
实时监控工具(可选):sudo apt-get install i7z && sudo i7z 。
二 临时调整频率与策略
安装工具(若未安装):sudo apt-get install cpufrequtils
设置调速器(governor):
查看支持的策略:cpufreq-info
全局设置:sudo cpufreq-set -g performance
指定核心:sudo cpufreq-set -c 0 -g powersave
设置频率范围(单位:kHz ):
设置上下限:sudo cpufreq-set -d 1200000 -u 2800000
手动固定频率(仅在 userspace 模式可用):
指定频率:sudo cpufreq-set -f 2200000
或范围:sudo cpufreq-set -f 1800000~2800000
多核批量设置示例(全部设为 performance):
简写循环:for c in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance | sudo tee $c; done
或用 cpufreq-set:for i in $(seq 0 $(($(nproc)-1))); do sudo cpufreq-set -c $i -g performance; done
提示:设置频率时请确保频率在 scaling_available_frequencies 范围内,且当前调速器支持手动设定。
三 永久生效的方法
systemd 服务(推荐,适用于 Ubuntu 16.04+):
创建服务:
sudo tee /etc/systemd/system/cpu-performance.service >/dev/null <<‘EOF’
[Unit]
Description=Set CPU governor to performance
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c ‘for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance > “$f”; done’
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
启用:sudo systemctl daemon-reload && sudo systemctl enable --now cpu-performance.service
GRUB 内核参数(需要切换或禁用 intel_pstate 时):
编辑:sudo sed -i ‘s/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="intel_pstate=disable /’ /etc/default/grub
更新并重启:sudo update-grub && sudo reboot
说明:部分平台在禁用 intel_pstate 后,调速器列表会变为 acpi-cpufreq ,再配合 cpufrequtils 设置策略/频率。
旧方法(sysfsutils,仍可用):
安装:sudo apt-get install sysfsutils
写入:echo “devices/system/cpu/cpu0/cpufreq/scaling_governor = performance” | sudo tee -a /etc/sysfs.conf
注意需为所有 cpuN 写入或使用循环脚本设置。
四 图形化与监控
图形化托盘工具(适合桌面环境):
安装:sudo add-apt-repository ppa:artfwo/ppa && sudo apt-get update && sudo apt-get install indicator-cpufreq
重启后右上角出现图标,可直接选择 performance/powersave/ondemand 等策略。
频率与温度监控:
实时监控:sudo apt-get install i7z && sudo i7z
面板插件(旧版 GNOME 面板):可添加 CPU Frequency Scaling Monitor 与 Hardware sensors monitor 。
五 常见问题与建议
权限问题:修改调速器/频率通常需要 root ,命令前加 sudo 。
策略与频率单位:策略名如 performance/powersave/ondemand/conservative/userspace ;频率参数单位为 kHz (如 2.2 GHz = 2200000 )。
多核/超线程:为所有逻辑处理器设置,使用 -c 指定核心或用循环写入 /sys/devices/system/cpu/cpu /cpufreq/scaling_governor *。
验证结果:
查看当前策略:cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
查看当前频率:cat /proc/cpuinfo | grep MHz | uniq
风险提示:长期固定高频会提升 功耗/温度 ,在笔记本上注意散热;某些平台/BIOS 可能限制调频或需要关闭 intel_pstate 才能使用某些调速器。