cpu降频问题

cpu做为能耗很高的硬件,最近几年厂商在节能方面做了很多处理,在服务器运行时,基于负载情况可调节成节能模式,节省电能,副作用是cpu的频率会降低,导致应用程序性能降低。

有第三方统计,服务器规模达到万台以上时,最大的成本消耗其实是电能

bios 设置

一般服务器的BIOS设置中会有一项来说明是否开启cpu节能模式

alt

但是我们发现有些服务器即使关闭了cpu节能,还是会有被降频的情况。

操作系统

操作系统也能对cpu频率进行调整,主要有两个工具

X86_ENERGY_PERF_POLICY

x86_energy_perf_policy 是红帽提供设置intel cpu节能模式的工具,默认我们服务器都是normal模式,我们要想获取最高性能要开启性能模式。

x86_energy_perf_policy performance

它是通过msr cpu寄存器来调整cpu频率,基本就是写/dev/cpu/*/msr这个设备

参考 http://www.centosabc.com/archives/844

服务器上我们已经调整了此参数,但是还是有机器出现降频情况。最后发现在centos7中还有一个工具可以调节cpu频率,就是cpupower。

cpupower

cpupower是centos7上(实际上是在3.04内核后)引入的一个工具,用于在用户态微调cpu频率。

x86_energy_perf_policy 可理解为“硬调节”,cpupower属于“微调”

调整cpu频率无非就是要在“能耗”和“性能”上取得平衡,基本上调整的策略有以下几种。

alt

而在centos7上有一个kernel-tools的包,提供一些工具来调整和查看cpu的状态

/etc/sysconfig/cpupower
/usr/bin/centrino-decode
/usr/bin/cpupower
/usr/bin/powernow-k8-decode
/usr/bin/tmon
/usr/bin/turbostat
/usr/bin/x86_energy_perf_policy
/usr/lib/systemd/system/cpupower.service

我们默认的策略是这样

cpupower frequency-info --policy
analyzing CPU 0:
1200000 3200000 powersave

powersave运行最小频率,当然cpu也会根据使用繁忙程度来升频率,有可能它的算法没有那么智能,导致你要用cpu时候,它还没来得及升上来。 注意这个文件“/usr/lib/systemd/system/cpupower.service”,说明cpupower已经变成一个服务了,再看下这个文件“/etc/sysconfig/cpupower”

# See "cpupower help" and cpupower(1) for more info
CPUPOWER_START_OPTS="frequency-set -g performance"
CPUPOWER_STOP_OPTS="frequency-set -g ondemand

说明只要启动这个服务,默认就调整成performance模式了。

systemctl start cpupower

其它

查看当前cpu策略

cpupower frequency-info --policy

修改策略

cpupower frequency-set -g powersave

实时查看cpu频率

watch -n 1 "cat /proc/cpuinfo | grep MHz"

内核信息查看

#使用的intel驱动

/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver

#intel_pstate驱动详细信息

/sys/devices/system/cpu/intel_pstate/

#各种频率相关

/sys/devices/system/cpu/cpu0/cpufreq/

#查看当前cpu策略

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

本文链接:http://opsdev.cn/post/cpujiangpin.html?winzoom=1

posted on 2017-02-28 10:09  生活费  阅读(5655)  评论(0编辑  收藏  举报

导航