结论与原理
可以调整,但不是通过修改 /proc/cpuinfo。该文件中的 cpu MHz 是内核从硬件读取的“当前频率”快照,属于只读信息。实际的频率调节由内核的 cpufreq 子系统完成,策略与数值通过 /sys/devices/system/cpu/cpu0/cpufreq/ 下的接口(如 scaling_governor、scaling_max_freq、scaling_min_freq、scaling_setspeed 等)来控制。常见可调用的策略包含:performance、powersave、ondemand、conservative、userspace(部分平台还会有 interactive、schedutil)。
快速操作示例
- 查看当前策略与频率范围
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
- cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
- 使用 cpupower(推荐)
- 安装:sudo apt install linux-cpupower 或 sudo yum install cpupowerutils
- 设置全核为性能模式:sudo cpupower frequency-set -g performance
- 设置指定核心:sudo cpupower -c 0 frequency-set -g performance
- 指定固定频率(需处于 userspace 策略):sudo cpupower -c 0 frequency-set -f 2.40GHz
- 使用 cpufrequtils
- 安装:sudo apt install cpufrequtils
- 查看:cpufreq-info -m
- 设置策略:sudo cpufreq-set -g performance
- 设置上下限:sudo cpufreq-set -d 800MHz -u 2.40GHz
- 指定核心:sudo cpufreq-set -g performance -c 0
- 直接写入 sysfs(与上述等效)
- echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
- echo 2400000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed(需先切到 userspace)
- 注意:调整上下限时,通常先写 scaling_max_freq,再写 scaling_min_freq
持久化与注意事项
- 持久化方式
- 使用 cpupower 的 systemd 服务
- 新建 /etc/systemd/system/cpufreq.service
- [Unit] Description=Set CPU frequency to performance
- [Service] Type=oneshot ExecStart=/usr/bin/cpupower frequency-set -g performance
- [Install] WantedBy=multi-user.target
- 启用:sudo systemctl enable --now cpufreq.service
- 使用 tuned(RHEL/CentOS 常用)
- sudo yum install tuned
- sudo systemctl start tuned && sudo systemctl enable tuned
- sudo tuned-adm profile performance(或 power-save)
- 桌面环境可用“CPU频率范围监视器”面板插件进行交互式设置
- 平台与驱动差异
- 部分 Intel 平台使用 intel_pstate 驱动,行为与 acpi-cpufreq 不同;必要时可在内核启动参数中设置 intel_pstate=disable 切换为 acpi-cpufreq(修改 /etc/default/grub 后执行 update-grub 并重启)
- 硬件与固件限制
- 可调范围受 硬件支持 与 BIOS/UEFI 电源策略限制;在 BIOS 中将电源管理设为 Performance 常可让系统更稳定地保持高频
- 风险提示
- 将频率固定在高位会增加 功耗与发热,在笔记本或散热受限环境需谨慎;修改前建议监控温度与稳定性