searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

CPU性能调整方法

2023-10-13 07:12:06
55
0

1.简介

bios里面设置performance,包括多项调整,cpu只是其中一项,其他调整项,不同厂家不同,大致包括内存频率,ACPI T-States,散热策略,monitor/mwait等;

系统里面可以将cpu的性能调至最优,主要是pstate, cstate及monit/mwait这几项,其他方面目前看无法调整;

2.Kernel cpu频率调整策略

  • 控制cpu频率的kernel cpufreq driver分两种acpi cpufreq和intel pstate.
  • 在centos7上,针对Intel Xeon E系列及更新的cpu,默认是使用intel pstate控制cpu的频率,较新的cpu若支持hwp(hardware-managed P-states),则可根据driver配置的频率值硬件自动进行调节,否则软件会根据算法选择频率(注:配置和读取频率信息都是通过相关的MSR);
  • 经简单测试,skylake之前不支持hwp,从skylake开始支持hwp;
  • 不支持hwp的cpu,根据intel pstate代码,最快10ms(可通过/sys/kernel/debug/pstate_snb/sample_rate_ms调整这个时间)会根据算法调整一次频率,参考kernel函数:intel_pstate_init_cpu;
  • 通过intel pstate不可能将cpu控制在某一频率,真正的运行频率是cpu本身决定的,通过pstate设置的值仅是代表性能高低。参考kernel文档: Documentation\cpu-freq\intel-pstate.txt 有如下内容:“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.”

若intel pstate使用了hwp,则通过dmesg可查到如下信息:

[root@A01-R06-I12-98-BHD8HP2 cpufreq]# dmesg
[ 3.843891] Intel P-state driver initializing.
[ 3.846331] intel_pstate: HWP enabled

3.Kernel idle实现

  • 当前系统idle driver分两种acpi idle及intel idle,同时cstate也分intel cstate与acpi cstate,有一定的对应关系,但不完全一样。
  • 如果当前系统使用的idle是intel idle, 则可在如下路径:/sys/devices/system/cpu/cpu*/cpuidle/state* 查询cstate名称,延时,存在时间等信息。
  • centos intel idle driver默认使用monitor/mwait 进入cstate,唤醒时间相对ioport方式更快,(acpi idle driver进入cstate时,可选择使用mwait或ioport方式);
  • C0-C6 latency从0到上百微秒,级别越高,延时越大,唤醒时间越长;
  • 可通过在kernel启动参数中添加max_cstate=<*> 来设置cpu使用的最大cstate级别;

1cstate简介

为了在CPU空闲时节约能源,可以使用命令让CPU进入低功耗模式。每个CPU都有几种功耗模式,它们统称为“C-State”或“C-模式”。它们从C0开始编号,C0是正常的CPU操作模式,即CPU完全开启。C编号越高,CPU睡眠模式越深,也就是说关闭的电路和信号更多,CPU需要更多时间才能恢复到C0,即唤醒。

在下面的表中,列举了一些C-State模式。模式C1到C3的工作方式基本上是切断CPU内使用的时钟信号,而模式C4到C6的工作方式是降低CPU电压。“增强”模式可以同时执行这两个操作。具体的实现每款cpu都不太一样,具体实现哪些cstate也不确定,依具体型号而定。

 

4.相关kernel启动参数

  • max_cstate=1         //设置为0时,会使用acpi idle driver, 设置为1时, idle仅进入C1
  • intel_pstate=disable/no_hwp   //disable:配置kernel不使用intel_pstate而是使用acpi driver, no_hwp: 不使用cpu的hwp功能
  • max_cstate=0           //使用acpi idle driver时生效
  • idle=halt/nomwait                    //配置此参数后,不再使用intel_idle driver,而是使用acpi idle driver,=halt时,不会进入C2/C3,=nowait时, 在进入c1-state时不使用mwait命令,而是halt命令,在进入c2/c3时,使用ioport指令

5.Centos内调整cpu性能

通过cpupower控制pstate及cstate:

  • cpupower -c all frequency-set -g performance    //调整cpu pstate到最高性能
  • cpupower -c all frequency-info -wm                     //查看cpu频率
  • cpupower -c all idle-set -D 3                                 //关闭latency大于等于3的所有cstate
  • cpupower idle-info                                                //查看cpu cstate状态信息
  • cpupower monitor -i 10                                         //监控cpu 10s内平均频率与各cstate百分比

通过sys接口控制pstate及cstate:

  • echo 100 > /sys/devices/system/cpu/intel_pstate/min_perf_pct                  //调整driver能设置的最低性能为100%
  • echo 1 | tee -a /sys/devices/system/cpu/cpu[0-9]*/cpuidle/state2/disable  //通过sys接口手动关闭cstate-2

6.推荐配置参数

根据上述分析,以DELL R640为例,有两种配置比较适合线上机器:

1)兼顾性能及功耗:

调整pstate为powersave模式,同时只开启c1-state, 其它都关闭,可让所有cpu工作在基频及以上频率,如gold 6148基频2.6G,作如下配置后,所有cpu频率都在2.6G左右;

cpupower -c all frequency-set -g powersave

cpupower -c all idle-set -D 3                             //-D之后的值为/sys/devices/system/cpu/cpu0/cpuidle/state1/latency的值+1

2)偏重于性能:

调整pstate为performance模式,同时只开启c1-state, 其它都关闭,可让所有cpu工作在较高的频率,如gold 6148基频2.6G,作如下配置后,所有cpu频率都在3.1G左右;

cpupower -c all frequency-set -g performance

cpupower -c all idle-set -D 3                               //-D之后的值为/sys/devices/system/cpu/cpu0/cpuidle/state1/latency的值+1

设置为上述工作模式后,有两个缺点:

1)所有cpu频率都比较高,但是最高频率没有打开所有cstate时高, 因为打开所有cstate时,部分cpu频率很低,部分cpu频率就可以变的很高;

2)cpu电源消耗较大,不确定cpu及服务器能否长时间稳定工作;

0条评论
0 / 1000