本文以Alibaba Cloud Linux 3系统为例,介绍了查看/proc/cpuinfo文件中CPU的频率与实例规格说明中的频率不同的原因及解决方案。
问题现象
在闲置状态下,通过/proc/cpuinfo看到部分CPU的频率为800 MHz,和实例规格说明中的频率值不同,如下所示。
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 2996.976
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 3192.046
cpu MHz : 800.000
cpu MHz : 3200.000
cpu MHz : 800.000
cpu MHz : 2975.717
cpu MHz : 800.000
cpu MHz : 3005.653
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
cpu MHz : 800.000
如涉及以下内核/操作系统,也可以参考本文解决。
问题原因
为优化系统性能和CPU响应速度,Linux内核在5.11版本之后合入了patch(commit ID: 3fcd6a230fa7d03bffcb831a81b40435c146c12b)。
x86/cpu: Avoid cpuinfo-induced IPIing of idle CPUs
Currently, accessing /proc/cpuinfo sends IPIs to idle CPUs in order to
learn their clock frequency. Which is a bit strange, given that waking
them from idle likely significantly changes their clock frequency.
This commit therefore avoids sending /proc/cpuinfo-induced IPIs to
idle CPUs.
当访问/proc/cpuinfo时,将通过rcu_is_idle_cpu函数判断当前CPU是否处于idle(闲置)状态,如果CPU处于idle状态,则直接返回min_freq(默认内核定义的是800 MHz,有些内核版本获取的是CPU基频)。
解决方案
说明
在闲置状态下,只是显示的频率不符合预期,实际规格还是能够达到规格定义的频率,不影响使用和性能。
通过cpupower或turbostat等工具获取准确的频率信息。
本文以cpupower工具获取频率信息为例。
sudo cpupower frequency-info
结果如下所示,当前的CPU频率为3200 MHz。
[ecs-user@iZ2zxxx187kyZ ~]$ sudo cpupower frequency-info
analyzing CPU 0:
driver: intel_pstate
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: 800 MHz - 3.80 GHz
available cpufreq governors: performance powersave
current policy: frequency should be within 800 MHz and 3.80 GHz.
The governor "performance" may decide which speed to use
within this range.
current CPU frequency: Unable to call hardware
current CPU frequency: 3.20 GHz (asserted by call to kernel)
boost state support:
Supported: yes
Active: yes
重要
部分实例规格不支持通过上述方式查询CPU频率,请以实例规格族中具体实例的主频为准。