LinuxCPU频率控制|Conflicting CPU frequency values detected使用cpupower设置CPU Performance模式

千磨万击还坚劲,任尔东西南北风。这篇文章主要讲述LinuxCPU频率控制|Conflicting CPU frequency values detected使用cpupower设置CPU Performance模式相关的知识,希望能为你提供帮助。

目录
??即看即用??
??背景??
??相关/原理:??
??使用cpupower设置CPU Performance模式??
??前言??
??更新历史??
??cpufreq的五种模式??
??cpupower设置performance??
??附录:??
??cpupower命令 – 调整CPU主频??



@UESTC
即看即用Linux 内部共有五种对频率的管理策略 userspace , conservative , ondemand , powersave(省电模式)和performance(性能模式)。
??查看当前CPU模式:??
??查看cpu0??
??cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor??
查看所有cpu
??cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor??
查看所有CPU频率:
cpupower -c allfrequency-info
设置CPU模式:
??cpupower frequency-set -g performance #设置成性能模式??
??cpupower frequency-set -g ??powersave??#设置成省电模式??
背景在测试IB网络中,遇到如下问题:
1.在一个节点上启动ib_write_bw

[root@storage2 ~]# ib_write_bw
------------------------------------------------------------------
RDMA_Write BW Test
Number of qps: 1
Connection type : RC
CQ Moderation: 50
Link type: IB
Mtu: 2048
Inline data is used up to 0 bytes message
local address: LID 0x04 QPN 0x38004d PSN 0x26358e RKey 0x70003000 VAddr 0x007f1986890000
remote address: LID 0x03 QPN 0x38004d PSN 0x4c35aa RKey 0x80003000 VAddr 0x007fa5ecb82000
2.在另一个节点上启动测试
[root@storage1 ~]# ib_write_bw 192.168.126.12
------------------------------------------------------------------
RDMA_Write BW Test
Number of qps: 1
Connection type : RC
TX depth: 300
CQ Moderation: 50
Mtu: 2048B
Link type: IB
Max inline data : 0B
rdma_cm QPs : OFF
Data ex. method : Ethernet
------------------------------------------------------------------
local address: LID 0x03 QPN 0x6c0053 PSN 0x38d98e RKey 0x50003000 VAddr 0x007facff0ed000
remote address: LID 0x04 QPN 0x2c004d PSN 0xd95310 RKey 0x58003000 VAddr 0x007f902e7d7000
------------------------------------------------------------------
#bytes#iterationsBW peak[MB/sec]BW average[MB/sec]
Conflicting CPU frequency values detected: 1200.000000 != 2001.000000
6553650000.000.00
------------------------------------------------------------------
3.运行后,没有结果,提示如下:
Conflicting CPU frequency values detected: 1200.000000 != 2001.000000
4.解决办法:
需要关闭两个节点上的cpuspeed服务。
[root@storage2 ~]# service cpuspeed stop
Disabling ondemand cpu frequency scaling:[OK]
[root@storage1 ~]# service cpuspeed stop
Disabling ondemand cpu frequency scaling:[OK]
关闭服务后,上述测试可以正常进行。
(我在本机执行上面的命令失败,因为cpuspeed是CPU管理工具,可能我的机器没有安装或者安装的不是这个CPU管理工具。经验证,是cpupower ?
cpupower 命令使用方法:??https://www.lmlphp.com/user/10313/article/item/419926/??
5.关于cpuspeed
【参考】http://linux.die.net/man/8/cpuspeed
cpuspeed用来根据运行情况,调整cpu的频率以降低功耗。

如何查看多个CPU的负载呢?
方法1:使用top命令,然后按1,即可看到每个CPU的负载;
方法2:使用mpstat命令,
#mpstat -P ALL 3,每3秒刷新一次数据
相关/原理:《Linux CPU频率控制》?
1.概述
Linux 内部共有五种对频率的管理策略 userspace , conservative , ondemand , powersave和performance。
l performance: CPU 会固定工作在其支持的最高运行频率上;
l powersave: CPU 会固定工作在其支持的最低运行频率上。因此这两种 governors都属于静态governor,即在使用它们时CPU的运行频率不会根据系统运行时负载的变化动态作出调整。这两种 governors对应的是两种极端的应用场景,使用performancegovernor体现的是对系统高性能的最大追求,而使用powersave governor则是对系统低功耗的最大追求。
l Userspace :最早的cpufreq子系统通过userspace governor 为用户提供了这种灵活性。系统将变频策略的决策权交给了用户态应用程序,并提供了相应的接口供用户态应用程序调节CPU 运行频率使用。(可以使用 Dominik等人开发了 cpufrequtils工具包)
l ondemand: userspace 是内核态的检测,效率低。而 ondemand 正是人们长期以来希望看到的一个完全在内核态下工作并且能够以更加细粒度的时间间隔对系统负载情况进行采样分析的governor 。
l conservative:ondemand governor的最初实现是在可选的频率范围内调低至下一个可用频率。这种降频策略的主导思想是尽量减小对系统性能的负面影响,从而不会使得系统性能在短时间内迅速降低以影响用户体验。但是在ondemand governor的这种最初实现版本在社区发布后,大量用户的使用结果表明这种担心实际上是多余的,ondemand governor 在降频时对于目标频率的选择完全可以更加激进。因此最新的 ondemand governor在降频时会在所有可选频率中一次性选择出可以保证 CPU工作在80%以上负荷的频率,当然如果没有任何一个可选频率满足要求的话则会选择CPU支持的最低运行频率。大量用户的测试结果表明这种新的算法可以在不影响系统性能的前提下做到更高效的节能。在算法改进后,ondemand governor的名字并没有改变,而ondemandgovernor最初的实现也保存了下来,并且由于其算法的保守性而得名conservative。
Ondemand 降频更加激进,conservative 降频比较缓慢保守,事实使用 ondemand 的效果也是比较好的。
2.相关工具
Cpupower指令可以控制(具体使用方法参见:cpupower help< command> ):
Usage:cpupower [-d|--debug] [-c|--cpu cpulist ]< command> [< args> ]
Supported commands are:
frequency-info
frequency-set
idle-info
idle-set
set
info
monitor
help
比如:
[root@localhost ~]#cpupower -c allfrequency-info
analyzing CPU 0:
driver: acpi-cpufreq
CPUs which run at the same hardwarefrequency: 0
CPUs which need to have their frequencycoordinated by software: 0

maximum transition latency: 10.0 us.
hardware limits: 1.60 GHz - 2.93 GHz
available frequency steps: 2.93 GHz, 2.67GHz, 2.40 GHz, 2.13 GHz, 1.87 GHz, 1.60 GHz
available cpufreq governors: conservative, userspace, powersave,ondemand, performance
current policy: frequency should be within1.60 GHz and 2.93 GHz.
The governor "conservative"may decide which speed to use
within this range.
current CPU frequency is 1.60 GHz (assertedby call to hardware).

boost state support:
Supported: no
Active: no

analyzing CPU 1:
driver: acpi-cpufreq
CPUs which run at the same hardwarefrequency: 1
CPUs which need to have their frequencycoordinated by software: 1
maximum transition latency: 10.0 us.
hardware limits: 1.60 GHz - 2.93 GHz
available frequency steps: 2.93 GHz, 2.67GHz, 2.40 GHz, 2.13 GHz, 1.87 GHz, 1.60 GHz
available cpufreq governors: conservative,userspace, powersave, ondemand, performance
current policy: frequency should be within1.60 GHz and 2.93 GHz.
The governor"conservative" may decide which speed to use
within this range.
current CPU frequency is 1.60 GHz (assertedby call to hardware).

boost state support:
Supported: no
Active: no


3.相关文件
Cpu频率相关的文件在/sys/devices/system/cpu/cpu0/cpufreq/目录。
Cpufreq 在用户态所呈现的接口:
l cpuinfo_max_freqcpuinfo_min_freq :分别给出了CPU硬件所支持的最高运行频率及最低运行频率,
l cpuinfo_cur_freq则会从CPU 硬件寄存器中读取CPU 当前所处的运行频率。
l Governor 在选择合适的运行频率时只会在scaling_max_freq 和 scaling_min_freq所确定的频率范围内进行选择
l scaling_cur_freq返回的是cpufreq 模块缓存的CPU当前运行频率,而不会对CPU 硬件寄存器进行检查。
l scaling_available_governors 会告诉用户当前有哪些governors可供用户使用
l scaling_driver则会显示该CPU所使用的变频驱动程序
l Scaling_governor则会显示当前的管理策略,往这个上 echo 其他类型会有相应的转变。
l scaling_setspeed :需将 governor 类型切换为 userspace ,才会出现,往这个文件 echo 数值,会切换主频
4.相关内核模块
内核编译时的控制参数:
#
# x86 CPU frequency scalingdrivers
#
CONFIG_X86_INTEL_PSTATE=y
CONFIG_X86_PCC_CPUFREQ=m
CONFIG_X86_ACPI_CPUFREQ=m
CONFIG_X86_ACPI_CPUFREQ_CPB=y
相关的内核模块:
/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/cpufreq
/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/cpufreq/acpi-cpufreq.ko
/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/cpufreq/cpufreq_stats.ko
/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/cpufreq/pcc-cpufreq.ko
5. 其他问题
较新的linux版本对于Intel的处理器有优化,导致无法看到五种governors,只有powersave,和performance两种,但实际效果并不好。这是由于使用intel_pstate驱动导致,可以通过在引导脚本增加intel_pstate=disable关闭。
6. 参考

http://unix.stackexchange.com/questions/153693/cant-use-userspace-cpufreq-governor-and-set-cpu-frequency
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1188647/comments/0

使用cpupower设置CPU Performance模式前言CPU动态节能技术用于降低服务器功耗,通过选择系统空闲状态不同的电源管理策 略,可以实现不同程度降低服务器功耗,更低的功耗策略意味着CPU唤醒更慢对性能 影响更大。对于对时延和性能要求高的应用,建议关闭CPU的动态调节功能,禁止 CPU休眠,并把CPU频率固定到最高。通常建议在服务器Bios中修改电源管理为Performance,如果发现CPU模式为conservative或者powersave,可以使用cpupower设置CPU Performance模式,效果也是相当显著的。
CPU优化建议使用cpupower设置CPU Performance模式
?


cpufreq的五种模式cpufreq是一个动态调整cpu频率的模块,系统启动时生成一个文件夹/sys/devices/system/cpu/cpu0/cpufreq/,里面有几个文件,其中scaling_min_freq代表最低频率,scaling_max_freq代表最高频率,scalin_governor代表cpu频率调整模式,用它来控制CPU频率。


??cd /sys/devices/system/cpu/cpu0/cpufreq/??
??affected_cpus??
??bios_limit??
??cpuinfo_cur_freq??
??cpuinfo_max_freq??
??cpuinfo_min_freq??
??cpuinfo_transition_latency??
??freqdomain_cpus??
??related_cpus??
??scaling_available_frequencies??
??scaling_available_governors??
??scaling_cur_freq??
??scaling_driver??
??scaling_governor??
??scaling_max_freq??
??scaling_min_freq??
??scaling_setspeed??
??# 查看当前的调节器??
??cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor??
??conservative??
??# 查看频率信息??
??cpupower frequency-info??
??analyzing CPU 0:??
??driver: acpi-cpufreq??
??CPUs which run at the same hardware frequency: 0??
??CPUs which need to have their frequency coordinated by software: 0??
??maximum transition latency: 10.0 us??
??hardware limits: 800 MHz - 2.10 GHz??
??available frequency steps: 2.10 GHz, 2.10 GHz, 2.00 GHz, 1.90 GHz, 1.80 GHz, 1.70 GHz, 1.60 GHz, 1.50 GHz, 1.40 GHz, 1.30 GHz, 1.20 GHz, 1.10 GHz, 1000 MHz, 900 MHz, 800 MHz??
??available cpufreq governors: conservative userspace powersave ondemand performance??
??current policy: frequency should be within 800 MHz and 2.10 GHz.??
??The governor "performance" may decide which speed to use??
??within this range.??
??current CPU frequency: Unable to call hardware??
??current CPU frequency: 2.10 GHz (asserted by call to kernel)??
??boost state support:??
??Supported: yes??
??Active: yes??
  1. performance: 顾名思义只注重效率,将CPU频率固定工作在其支持的最高运行频率上,而不动态调节。
  2. Userspace:最早的cpufreq子系统通过userspace governor为用户提供了这种灵活性。系统将变频策略的决策权交给了用户态应用程序,并提供了相应的接口供用户态应用程序调节CPU 运行频率使用。也就是长期以来都在用的那个模式。可以通过手动编辑配置文件进行配置
  3. powersave: 将CPU频率设置为最低的所谓“省电”模式,CPU会固定工作在其支持的最低运行频率上。因此这两种governors 都属于静态governor,即在使用它们时CPU 的运行频率不会根据系统运行时负载的变化动态作出调整。这两种governors 对应的是两种极端的应用场景,使用performance governor 是对系统高性能的最大追求,而使用powersave governor 则是对系统低功耗的最大追求。
  4. ondemand: 按需快速动态调整CPU频率, 一有cpu计算量的任务,就会立即达到最大频率运行,等执行完毕就立即回到最低频率;ondemand:userspace是内核态的检测,用户态调整,效率低。而ondemand正是人们长期以来希望看到的一个完全在内核态下工作并且能够以更加细粒度的时间间隔对系统负载情况进行采样分析的governor。 在 ondemand governor 监测到系统负载超过 up_threshold 所设定的百分比时,说明用户当前需要 CPU 提供更强大的处理能力,因此 ondemand governor 会将CPU设置在最高频率上运行。但是当 ondemand governor 监测到系统负载下降,可以降低 CPU 的运行频率时,到底应该降低到哪个频率呢? ondemand governor 的最初实现是在可选的频率范围内调低至下一个可用频率,例如 CPU 支持三个可选频率,分别为 1.67GHz、1.33GHz 和 1GHz ,如果 CPU 运行在 1.67GHz 时 ondemand governor 发现可以降低运行频率,那么 1.33GHz 将被选作降频的目标频率。
  5. conservative: 与ondemand不同,平滑地调整CPU频率,频率的升降是渐变式的,会自动在频率上下限调整,和ondemand的区别在于它会按需分配频率,而不是一味追求最高频率;
cpupower设置performance
从conservative或者powersave切换到performance的效果还是杠杠的


??# CentOS 安装 kernel-tools??
??yum install kernel-tools??
??# Ubuntu 安装 CPU 模式无图形化切换器??
??yum install cpufrequtils??
??# cpupower设置performance模式??
??cpupower frequency-set -g performance??
??# 查看当前的调节器??
??cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor??
??performance??
LinuxCPU频率控制|Conflicting CPU frequency values detected使用cpupower设置CPU Performance模式

文章图片

相关资源:??C++ rapidjson 对类序列化(完美二次封装)下载??
参考:??https://www.mail-archive.com/users@lists.open-mpi.org/msg20213.html???
附录:??cpupower命令 – 调整CPU主频????https://www.lmlphp.com/user/10313/article/item/419926/??
cpupower 是一组为辅助 CPU 调频而设计的用户空间工具。linux内核支持调节CPU主频,降低功耗,已到达节能的效果。对于移动设备和笔记本来说,在没有接通电源的时候,续航是很重要的。
通过选择系统空闲状态不同的电源管理策略,可以实现不同程度降低服务器功耗。但是,更低的功耗策略意味着 CPU 唤醒更慢对性能影响更大。对于对时延和性能要求高的应用。
对于服务器,一般都是接着电源的,而且要求性能比较高,因此,建议关闭 CPU 的动态调节功能,禁止 CPU 休眠,并把 CPU 频率固定到最高。
一般在服务器 BIOS 中修改电源管理为 Performance,如果发现 CPU 模式为 conservative 或者 powersave,可以使用 cpupower 设置 CPU Performance 模式,效果也是相当显著的。
语法格式:cpupower [参数]
常用参数:
参考实例
查看当前生效的策略:

[root@lmlphp.com ~]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
powersave


查看当前CPU频率:

[root@lmlphp.com ~]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
900022


查看当前所有CPU的信息:

[root@lmlphp.com ~]# cpupower -c all frequency-info


设置所有CPU为性能模式:

[root@lmlphp.com ~]# cpupower -c all frequency-set -g performance


设置所有CPU为节能模式:

[root@lmlphp.com ~]# cpupower -c all frequency-set -g powersave


查看频率信息:

[root@lmlphp.com ~]# cpupower frequency-info


cpupower设置performance:

[root@lmlphp.com ~]# cpupower frequency-set -g performance


【LinuxCPU频率控制|Conflicting CPU frequency values detected使用cpupower设置CPU Performance模式】

    推荐阅读