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 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


  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值