最近注意到一台使用 Intel Core i5-9400F 的 Linux 主机,即使系统处于 idle 状态,监控工具显示的 CPU 频率仍然接近 4.0 GHz。
第一反应可能是:CPU 是否一直在高负载运行?实际上,显示高频并不一定等于核心一直在做大量工作。Linux 的 CPU 调频驱动、governor,以及监控工具采用的采样方式,都会影响我们看到的结果。
本文记录这次排查过程,并整理 performance、ondemand 和 powersave 的区别。
Linux 的 CPUFreq 子系统会为每个逻辑 CPU 暴露调频策略。可以直接读取:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
也可以保留每个文件的路径,方便确认所有核心的状态:
grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
我的输出是:
/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor:performance
/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor:performance
/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor:performance
/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor:performance
/sys/devices/system/cpu/cpu4/cpufreq/scaling_governor:performance
/sys/devices/system/cpu/cpu5/cpufreq/scaling_governor:performance
原因基本明确了:所有核心都在使用 performance governor。
performance 会积极请求较高的性能状态,因此监控软件经常会显示接近最高睿频的数值。即便 CPU 没有多少实际负载,频率读数也可能长期维持在较高水平。
这里需要区分三个概念:
空闲核心可以进入 C-State 休眠。此时,即便某个工具显示 4.0 GHz,也不意味着该核心在整个采样周期内持续以 4.0 GHz 执行指令。
因此,仅查看 /proc/cpuinfo 中的 cpu MHz 并不足以判断待机功耗:
watch -n 1 "grep 'cpu MHz' /proc/cpuinfo"
更合适的工具是 turbostat:
sudo turbostat
重点关注:
Busy%:CPU 实际忙碌时间比例;Bzy_MHz:CPU 忙碌期间的平均频率;PkgWatt:处理器封装功耗;C6、C7 等列:深度休眠状态驻留比例。如果 Busy% 很低、PkgWatt 只有几瓦,而且深度 C-State 比例较高,那么即便界面显示接近 4 GHz,系统通常仍处于正常的低功耗待机状态。
还可以使用以下工具寻找持续唤醒 CPU 的后台程序:
top
或者:
sudo powertop
先查看 CPUFreq 驱动:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver
再查看当前驱动提供的 governor:
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
常见情况有两种。
intel_pstate输出可能是:
intel_pstate
可用 governor 往往只有:
performance powersave
这里的 powersave 并不等于把 CPU 永久锁在低频。它仍然会根据负载动态提高性能,有需要时也可以进入睿频状态。它只是采用更偏向能效的调节策略。
acpi-cpufreq如果驱动是:
acpi-cpufreq
系统通常还会提供:
ondemand conservative schedutil performance powersave
实际列表取决于内核配置和发行版。
performance、ondemand 和 powersave 的区别performanceperformance 倾向于使用较高的性能状态。
特点:
ondemandondemand 是传统 CPUFreq governor。它会周期性检查 CPU 利用率:负载超过阈值时快速升频,负载下降后再逐步降频。
特点:
acpi-cpufreq 等传统驱动。powersavepowersave 的实际行为取决于驱动。
在传统 CPUFreq 驱动中,它可能更接近选择最低频率;但在 intel_pstate 下,它仍然是动态调节策略,并不会阻止 CPU 在有负载时升频。
因此,对使用 intel_pstate 的现代 Intel CPU 来说:
intel_pstate + powersave
通常可以视为更适合日常使用的动态策略,而不是传统意义上的“强制低频模式”。
安装 cpupower 后,可以使用统一命令切换策略。
切换到 powersave:
sudo cpupower frequency-set -g powersave
如果可用列表中确实存在 ondemand,可以切换为:
sudo cpupower frequency-set -g ondemand
切换后再次确认:
grep . /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
也可以不使用 cpupower,直接写入 sysfs:
for governor in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do
echo powersave | sudo tee "$governor"
done
这种修改通常只在当前启动周期内有效,重启后可能恢复为发行版或服务预设的值。
cpupower不同发行版的软件包名称略有不同。
Debian / Ubuntu:
sudo apt install linux-tools-common linux-tools-$(uname -r)
Arch Linux:
sudo pacman -S cpupower
Fedora:
sudo dnf install kernel-tools
查看完整的驱动和频率信息:
cpupower frequency-info
具体方式取决于发行版。部分系统提供 cpupower.service:
sudo systemctl enable --now cpupower
相关配置文件可能位于:
/etc/default/cpupower
/etc/sysconfig/cpupower
应先检查当前发行版的软件包说明和服务内容,确认配置文件路径及变量名称。
桌面发行版还可能运行 power-profiles-daemon、TLP 或 tuned。这些电源管理服务可能会在启动、切换电源模式或插拔电源时重新设置 governor。因此,若手动设置总是自动恢复,应检查:
systemctl status power-profiles-daemon
systemctl status tlp
systemctl status tuned
不要同时启用多个相互竞争的电源管理工具。
ondemand 禁用 intel_pstate如果当前使用 intel_pstate,但可用 governor 中没有 ondemand,理论上可以通过内核启动参数禁用它:
intel_pstate=disable
重启后系统可能回退到 acpi-cpufreq,从而提供 ondemand。
不过,仅仅为了看到待机频率下降,通常没有必要这样做。intel_pstate + powersave 已经能动态调节性能,并且更了解 Intel 处理器的性能状态。
判断策略是否合适,应该看:
而不是只看监控界面中的 GHz 数字。
对这台 i5-9400F 主机,我的结论是:
performance;intel_pstate,日常用途优先选择 powersave;acpi-cpufreq 且提供 ondemand,可以将其作为动态调频方案;turbostat 的 Busy%、PkgWatt 和 C-State 数据判断实际待机状态,不要只看瞬时频率。最终使用的临时调整命令是:
sudo cpupower frequency-set -g powersave
CPU 在需要性能时仍然可以升频,而空闲时也更容易回到偏向能效的状态。这比单纯追求监控界面显示一个较低的频率数字更有意义。
完