目录

即看即用

背景

相关/原理:

使用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 all  frequency-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 0x007fa5ecb820002.在另一个节点上启动测试

[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     #iterations    BW peak[MB/sec]    BW average[MB/sec]
Conflicting CPU frequency values detected: 1200.000000 != 2001.000000
 65536      5000           0.00               0.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 参考:https://blog.csdn.net/lizhiqiang50/article/details/50992847

cpupower 命令使用方法:https://www.lmlphp.com/user/10313/article/item/419926/

查看文章:https://blog.csdn.net/hddghhfd/article/details/83956197)

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频率控制》https://blog.csdn.net/lizhiqiang50/article/details/50992847

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 all  frequency-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_freq  cpuinfo_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://www.cnblogs.com/armlinux/archive/2011/11/12/2396780.html
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

原文链接:https://blog.csdn.net/lizhiqiang50/article/details/50992847

使用cpupower设置CPU Performance模式

前言

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

CPU优化建议使用cpupower设置CPU Performance模式

更新历史

2019年01月18日 - 初稿

阅读原文 - https://wsgzao.github.io/post...

扩展阅读

CPU frequency scaling - https://wiki.archlinux.org/in...


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

相关资源:C++ rapidjson 对类序列化(完美二次封装)下载

参考:https://www.mail-archive.com/users@lists.open-mpi.org/msg20213.html

https://blog.csdn.net/myarrow/article/details/7917181/

附录:

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

【Linux】CPU频率控制|Conflicting CPU frequency values detected相关推荐

  1. cpu使用率 htop显示_用top、vmstat、Htop、sar命令在Linux系统中检查CPU使用率/利用率...

    本文介绍使用top.vmstat.Htop.sar命令在Linux操作系统中检查CPU使用率/利用率,其实也可以在图形界面中通过工具查看的,可参考使用Stress Terminal UI在Linux终 ...

  2. Linux学习笔记---修改CPU频率为自动调节模式

    开发板默认的CPU频率模式为最高性能,这样的话CPU就会一直以最高频率运行,芯片摸起来比较热,为了降低CPU的功耗,需要将CPU的调频策略设置为根据负载自动调节.这里通过图形化配置界面来修改. 在Ub ...

  3. Linux中计算特定CPU使用率

    Linux中计算特定CPU使用率 需求 解决方案 拓展 参考 需求 在Linux中可以通过top指令查看某一进程占用的CPU情况,也可以查看某一个CPU使用率情况(先top指令,然后按数字" ...

  4. Linux性能测试工具之CPU(一)

    CPUs 1.1 uptime Load averages 的三个值分别代表最近 1/5/15 分钟的平均系统负载.在多核系统中,这些值有可能经常大于1,比如四核系统的 100% 负载为 4,八核系统 ...

  5. 浅谈Linux下CPU利用率和CPU负载及其代码实现原理

    编者注: 本来想写个简单的程序测试CPU利用率,后来代码实现后与top(ps)命令测试的结果做对比,疑惑了,疑惑后有了此文-- 第一节   祸起 本来就是想通过写个小程序测试CPU利用率从而可以检验其 ...

  6. Linux驱动学习记录 cpu主频

    以imx6ull芯片为例 imx6ull芯片主频是792MHz 查看cpu信息 cat /proc/cpuinfo proc/cpuinfo processor : 0 model name : AR ...

  7. Linux top命令的cpu使用率和内存使用率

    文章目录 前言 一.cpu使用率 1.1 top简介 1.2 cpu使用率的来源 1.3 内核相关源码 二.内存使用率 2.1 总内存有关的数据 2.2 进程使用内存有关的数据 2.3 内存使用率的来 ...

  8. linux 下取进程占用 cpu/内存 最高的前10个进程

    1. linux 下 取进程占用 cpu 最高的前10个进程 ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head ps auxw|head -1 ...

  9. linux查看虚拟内存和cpu占用率

    top free cat /proc/meminfo cat /proc/cpuinfo [root@centerlisdb proc]# dmidecode |grep -A16 "Mem ...

最新文章

  1. java maven 编译 清理 测试 打包项目
  2. 听说你想去大厂看妹子,带你看看腾讯产品运营实习面经
  3. python自动化开发_python自动化开发-2
  4. SpringBoot使用ControllerAdvice和ExceptionHandler进行统一异常处理
  5. IMWeb Conf2018 Native跨端融合总结
  6. 如何用Python打造你的第一个Slack Bot
  7. linux创建删除用户和用户组
  8. BOOST库介绍(五)——智能指针shared_ptr
  9. 打补丁更新不适用计算机,安装补丁“此更新不适用于你的计算机”解决办法
  10. Tomcat免安装版+Eclipse配置
  11. python excel数据框_Python快速设置Excel表格边框
  12. python矩阵求逆算法_09-30:Python矩阵求逆
  13. 5不触发系统键盘_防盗报警系统基础知识汇总
  14. Matlab 黎卡提方程
  15. 国内首届 Flutter Festival 为热爱开启!
  16. IOS开发-ERROR ITMS-90096: Your binary is not optimized for iPhone 5
  17. 数学模型天气预测方法_预测即将到来的天气的新方法
  18. 基于WeLink开发的智慧云OA系统获奖啦!
  19. ROS机器人操作系统(rospy)
  20. OS模块--批量修改文件名字(二)

热门文章

  1. Fluent动网格【8】:网格节点运动案例
  2. tf卡加卡套的区别_TF卡和SD卡的区别是什么
  3. USB接口定义;miniUSB接口定义
  4. Android 设备通过WIFI传输数据 - 点对点传输
  5. 显卡常识 电脑显卡基础知识普及
  6. VS2010 出现error C2447 如何解决,求大神支招
  7. 新品推介:乐扩PCI-E转NGFF(PCIe)SSD+SATA转NGFF(SATA)转接卡
  8. MySQL高级篇知识点——索引的数据结构
  9. 3ds max 2012 VRay 2.0-效果图设计与制作-VRay景深模糊设置
  10. win10 64位下mingw4.9编译qt5.6.2