请选择 进入手机版 | 继续访问电脑版

程序设计学堂

 找回密码
 立即注册

扫一扫,访问微社区

搜索
热搜: 活动 交友 discuz
查看: 11714|回复: 6

CentOS7中CPU频率调整问题

[复制链接]

20

主题

24

帖子

132

积分

注册会员

Rank: 2

积分
132
发表于 2015-10-22 18:32 | 显示全部楼层 |阅读模式
本帖最后由 刘涛 于 2015-10-22 18:34 编辑

CentOS7在cpufreq接口中(/sys/devices/system/cpu/cpu$i/cpufreq/)默认的scaling_available_governors包括powersave和performance,
在一些以前的文档中介绍这两种为静态策略,powersave使用最低cpu频率,performance使用最高cpu频率。
但是从centos7实际表现来看,这两种策略目前都是动态策略,performance比powersave积极一些,但也不是全速运行。

指定cpu频率,需要使用userspace策略,并配合custom工具
在centos7上实际试验,modprobe cpufreq_userspace执行无输出,但scaling_available_governor中并未加入userspace策略,用custom工具指定cpu频率操作失败。

用lsmod查看不到cpufreq_userspace模块,相应也查看不到cpufreq_powersave和cpufreq_performance模块。查找模块的机制我不是很清楚,这是FEATURE直接编到内核里了吗?如果是这样,需要指定CPU频率或使用其它governor策略的话,可能需要重新配置内核选项并编译内核。这个还需要再确认清楚。

custom工具,centos7自带了cpupower工具,应该是以前cpu-freq工具的后续版本。一些简单用例如下:

显示所有core的cpufreq信息:
cpupower -c all frequency-info

修改所有core的governor为performance:
cpupower -c all frequency-set -g performance

可设置的其它参数
[root@data02 ~]# cpupower -c all frequency-set
At least one parameter out of -f/--freq, -d/--min, -u/--max, and
-g/--governor must be passed


回复

使用道具 举报

10

主题

17

帖子

96

积分

注册会员

Rank: 2

积分
96
QQ
发表于 2015-10-22 23:16 | 显示全部楼层
我手头没有CentOS7的系统,但有个CentOS6.6的snode173。
在默认内核的config文件(/boot/config-2.6.32-504.el6.x86_64)中有以下配置。
我估计CentOS7的内核配置文件应该与此相差不多。
“=y”的那些,lsmod就都看不到了,modprobe也没用了。

#
# CPU Frequency scaling
#
CONFIG_CPU_FREQ=y
CONFIG_CPU_FREQ_TABLE=m
CONFIG_CPU_FREQ_DEBUG=y
CONFIG_CPU_FREQ_STAT=m
CONFIG_CPU_FREQ_STAT_DETAILS=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
CONFIG_CPU_FREQ_GOV_POWERSAVE=m
CONFIG_CPU_FREQ_GOV_USERSPACE=y
CONFIG_CPU_FREQ_GOV_ONDEMAND=m
CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m
回复 支持 反对

使用道具 举报

10

主题

17

帖子

96

积分

注册会员

Rank: 2

积分
96
QQ
发表于 2015-10-22 23:22 | 显示全部楼层
我就纯灌水了。

[hzg@snode173 ~]$ cd /lib/modules/2.6.32-504.el6.x86_64/
[hzg@snode173 2.6.32-504.el6.x86_64]$ find . -name "*freq*"
./kernel/drivers/cpufreq
./kernel/drivers/cpufreq/cpufreq_stats.ko
./kernel/drivers/cpufreq/cpufreq_conservative.ko
./kernel/drivers/cpufreq/freq_table.ko
./kernel/drivers/cpufreq/cpufreq_powersave.ko
./kernel/drivers/cpufreq/cpufreq_ondemand.ko
./kernel/arch/x86/kernel/cpu/cpufreq
./kernel/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.ko
./kernel/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.ko
[hzg@snode173 2.6.32-504.el6.x86_64]$ lsmod |grep freq
cpufreq_ondemand       10544  0
acpi_cpufreq                  7763  0
freq_table                      4936  2 cpufreq_ondemand,acpi_cpufreq
mperf                            1557  1 acpi_cpufreq
[hzg@snode173 2.6.32-504.el6.x86_64]$ sudo modprobe cpufreq_powersave
[hzg@snode173 2.6.32-504.el6.x86_64]$ lsmod |grep freq
cpufreq_powersave        1196  0
cpufreq_ondemand       10544  0
acpi_cpufreq                  7763  0
freq_table                      4936  2 cpufreq_ondemand,acpi_cpufreq
mperf                            1557  1 acpi_cpufreq
回复 支持 反对

使用道具 举报

20

主题

24

帖子

132

积分

注册会员

Rank: 2

积分
132
 楼主| 发表于 2015-11-3 14:13 | 显示全部楼层
搞清楚了一些问题

1)有一些governor无法加载,是因为在当前CPU架构或配置下,该策略无法使用。
2)固定CPU频率,对软件来说,并不一定总是可行。有时频率是由CPU硬件自行调整,软件配了也没用。

参考下面的文档

https://www.kernel.org/doc/Docum ... eq/intel-pstate.txt
Intel P-state driver
--------------------

This driver provides an interface to control the P state selection for
SandyBridge+ Intel processors.  The driver can operate two different
modes based on the processor model, legacy mode and Hardware P state (HWP)
mode.

In legacy mode, the Intel P-state implements two internal governors,
performance and powersave, that differ from the general cpufreq governors of
the same name (the general cpufreq governors implement target(), whereas the
internal Intel P-state governors implement setpolicy()).  The internal
performance governor sets the max_perf_pct and min_perf_pct to 100; that is,
the governor selects the highest available P state to maximize the performance
of the core.  The internal powersave governor selects the appropriate P state
based on the current load on the CPU.

In HWP mode P state selection is implemented in the processor
itself. The driver provides the interfaces between the cpufreq core and
the processor to control P state selection based on user preferences
and reporting frequency to the cpufreq core.  In this mode the
internal Intel P-state governor code is disabled.

In addition to the interfaces provided by the cpufreq core for
controlling frequency the driver provides sysfs files for
controlling P state selection. These files have been added to
/sys/devices/system/cpu/intel_pstate/

      max_perf_pct: limits the maximum P state that will be requested by
      the driver stated as a percentage of the available performance. The
      available (P states) performance may be reduced by the no_turbo
      setting described below.

      min_perf_pct: limits the minimum P state that will be  requested by
      the driver stated as a percentage of the max (non-turbo)
      performance level.

      no_turbo: limits the driver to selecting P states below the turbo
      frequency range.

      turbo_pct: displays the percentage of the total performance that
      is supported by hardware that is in the turbo range.  This number
      is independent of whether turbo has been disabled or not.

      num_pstates: displays the number of pstates that are supported
      by hardware.  This number is independent of whether turbo has
      been disabled or not.

For contemporary Intel processors, the frequency is controlled by the
processor itself and the P-states exposed to software are related to
performance levels.  The idea that frequency can be set to a single
frequency is fiction for Intel Core processors. Even if the scaling
driver selects a single P state the actual frequency the processor
will run at is selected by the processor itself.


For legacy mode debugfs files have also been added to allow tuning of
the internal governor algorythm. These files are located at
/sys/kernel/debug/pstate_snb/ These files are NOT present in HWP mode.

      deadband
      d_gain_pct
      i_gain_pct
      p_gain_pct
      sample_rate_ms
      setpoint
回复 支持 反对

使用道具 举报

20

主题

24

帖子

132

积分

注册会员

Rank: 2

积分
132
 楼主| 发表于 2015-11-3 15:35 | 显示全部楼层
E5-2630 V3上的实测

CPU标称频率2.4G,8核,超线程开

在Linux中,使用idle_loop来提高CPU占用率,单个core的boost最高频率3.2G
超过功耗限制后,boost频率限制为2.6G

回复 支持 反对

使用道具 举报

20

主题

24

帖子

132

积分

注册会员

Rank: 2

积分
132
 楼主| 发表于 2015-11-3 17:19 | 显示全部楼层
同样的CPU,在centos6.4里确实能指定频率。
和centos7.1比较,差别在于scaling_driver不同,
6.4使用的是acpi-cpufreq
7.1使用的是intel_pstate
回复 支持 反对

使用道具 举报

20

主题

24

帖子

132

积分

注册会员

Rank: 2

积分
132
 楼主| 发表于 2015-11-3 22:45 | 显示全部楼层
cpufreq使用了新的intel_pstate驱动造成的困惑,详细解答在这里

Take a look at this discussion:
https://plus.google.com/117091380454742934025/posts/2vEekAsG2QT

1. intel_pstate can be disabled at boot-time with intel_pstate=disable or compile it out
2. the old problem with ondemand (and conservative) governors is and was, that they don't know the specific capabilities of the cpu
3. executing some tasks with highest-frequency possible is consuming less power, than taking more time with lower frequency e.g. arithmetic stuff
4. this is not true for all tasks e.g. loading something from main-memory
5. here comes intel_pstate: it knows how the specific cpu works and does it job better than a generic solution, also it seems to handle "boost" better
6. furthermore intel_pstate offers only two governors: powersave and performance
    even "powersave" is faster than the generic acpi based approach with "performance" (maybe handles "boost" better)
    also "performance" doesn't enforce the default frequency as "lower limit", like the old generic approch, but performance is anyway only ~ 1% faster

You can still select between these two governors with "cpupower frequency-set -g powersave/performance".

Run CPU with fixed frequency
Your good right. You paid for it! There are some good reasons for this:

    Requirement of 100% reliable performance and answer-times

    Bbenchmarking/Comparsion

    Stress-Testing e.g. is CPU never throttled with your provided cooling solution

That is simple, set intel_pstate=disable at boot or remove it from your self compiled kernel. Now you can use the old generic acpi-based generic governors.
Or: Switch Powersave/Boost off in your BIOS/UEFI. This is what I do on desktops.

I will stay with intel_pstate and the default governor "powersave". It seems to do a good job at power-saving and my ThinkPad even runs faster smile
Maybe it would be less confusing if intel_pstate also overs a "fixed" governor which forces the default-frequencies. But this is merely "intel_pstate=disable".
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|SysSW  

GMT+8, 2019-9-16 07:31 , Processed in 0.107220 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表