最新消息:

SUSE 系统 CPU 节电模式 引发的故障

未分类 admin 4459浏览 0评论

生产系统的一台SUSE  Linux10服务器,在深夜零点后突然失去响应了,远程连接也无法登陆。安排驻场工程师去机房看看,发现服务器上各种指示灯均正常,网线也无松动。当接上键盘、鼠标后,现场工程师发现服务器无任何反应,键盘鼠标也无任何响应,服务器像冰冻休眠了一样。因为这台服务器是负载均衡服务器组中的一台,即使离线也不影响业务。所以就让现场工程师重启了该服务器,重启后发现一切正常,收集了日志后,发现有一段报错代码如下:

1659335535

根据英文提示:CPU不支持频率调整,需要设置’CPUFREQ_ENABLED=no’ 和SUSPEND2RAM_FORCE=yes 。

分析:现在服务器的CPU耗电很大,按需调节CPU频率有对节能有重要的意义,目前多数Linux发行版都已经默认启用了这个功能,但是也有一些LINUX发行版需要经过简单的设置才行(启用相关的模块,并安装CPU频率调节程序)。实际上这个CPU的节电模式,也就是变频技术,在负载不高的时候,CPU会自动降频使用。cpufreq的驱动程序,就是用来动态调整CPU频率以降低能源消耗的。但这个功能有的时候会有问题,比如当你没有相应的模块和频率调节驱动时,会造成内核错误,进而引发服务器不响应。

我们可以看下系统中支持CPU频率调整的模块驱动

# cd /lib/modules/2.6.16.60-0.21-smp/kernel/arch/x86_64/kernel/cpufreq
web132:/lib/modules/2.6.16.60-0.21-smp/kernel/arch/x86_64/kernel/cpufreq # ls -l
total 104
-rw-r--r-- 1 root root 30264 May  6  2008 acpi-cpufreq.ko
-rw-r--r-- 1 root root 37808 May  6  2008 powernow-k8.ko
-rw-r--r-- 1 root root 29544 May  6  2008 speedstep-centrino.ko
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">加载的方法</span>
#modprobe acpi-cpufreq
#modprobe powernow-k8
#modprobe speedstep-centrino
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">在本故障案例中,提示没有cpufreq driver available,所以解决办法</span>
# vi /etc/powersave/cpufreq
CPUFREQ_ENABLED="no"  (注:默认为yes)
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">重启/etc/init.d/powersave,然后就生效了。</span>

可以通过命令cpufreq-info 来查询cpu频率状态

#  cpufreq-info
cpufrequtils 0.4: cpufreq-info (C) Dominik Brodowski 2004
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
  no or unknown cpufreq driver is active on this CPU
analyzing CPU 1:
  no or unknown cpufreq driver is active on this CPU
analyzing CPU 2:
  no or unknown cpufreq driver is active on this CPU
analyzing CPU 3:
  no or unknown cpufreq driver is active on this CPU
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">如上显示为关闭CPU频率调整后的状态显示。</span>

如果你的CPU支持频率调整,系统会这样显示

# cpufreq-info
cpufrequtils 0.4: cpufreq-info (C) Dominik Brodowski 2004
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
  driver: centrino
  CPUs which need to switch frequency at the same time: 0
  hardware limits: 1.20 GHz - 2.50 GHz
  available frequency steps: 2.50 GHz, 2.00 GHz, 1.60 GHz, 1.20 GHz
  available cpufreq governors: ondemand, userspace, powersave, performance
  current policy: frequency should be within 1.20 GHz and 2.50 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.20 GHz (asserted by call to hardware).
analyzing CPU 1:
  driver: centrino
  CPUs which need to switch frequency at the same time: 1
  hardware limits: 1.20 GHz - 2.50 GHz
  available frequency steps: 2.50 GHz, 2.00 GHz, 1.60 GHz, 1.20 GHz
  available cpufreq governors: ondemand, userspace, powersave, performance
  current policy: frequency should be within 1.20 GHz and 2.50 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 1.20 GHz (asserted by call to hardware).

analyzing CPU 2:
driver: centrino
CPUs which need to switch frequency at the same time: 1
hardware limits: 1.20 GHz - 2.50 GHz
available frequency steps: 2.50 GHz, 2.00 GHz, 1.60 GHz, 1.20 GHz
available cpufreq governors: ondemand, userspace, powersave, performance
current policy: frequency should be within 1.20 GHz and 2.50 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1.20 GHz (asserted by call to hardware).

analyzing CPU 3:
driver: centrino
CPUs which need to switch frequency at the same time: 1
hardware limits: 1.20 GHz - 2.50 GHz
available frequency steps: 2.50 GHz, 2.00 GHz, 1.60 GHz, 1.20 GHz
available cpufreq governors: ondemand, userspace, powersave, performance
current policy: frequency should be within 1.20 GHz and 2.50 GHz.
The governor "ondemand" may decide which speed to use
within this range.
current CPU frequency is 1.20 GHz (asserted by call to hardware).
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">接下来修改</span>
#vi  /etc/powersave/sleep
SUSPEND2RAM_FORCE="yes"
#/etc/init.d/powersaved restart
<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;">通过以上修改,问题解决。</span>

补充cpufreq技术:

在cpufreq中内置了5种策略:performance、powersave、userspace、ondemand、conservation。默认采用ondemand策略,在该策略里每80个毫秒就采集一次cpu的使用率,同时假设前后两次cpu使用率是相同的。通过前一次的cpu使用率推出后一个cpu使用率,完了进行频率设置。所以就总的思想来说还不是很难理解。

目的:

变频技术是指CPU硬件本身支持在不同的频率下运行,系统在运行过程中可以根据随时可能发生变化的系统负载情况动态在这些不同的运行频率之间进行切换,从而达到对性能和功耗做到二者兼顾的目的。

管理策略:

Linux内部共有五种对频率的管理策略userspace,conservative,ondemand,powersave和 performance

  1. performance :CPU会固定工作在其支持的最高运行频率上;
  2. powersave :CPU会固定工作在其支持的最低运行频率上。因此这两种governors 都属于静态 governor ,即在使用它们时 CPU 的运行频率不会根据系统运行时负载的变化动态作出调整。这两种 governors 对应的是两种极端的应用场景,使用performance governor 体现的是对系统高性能的最大追求,而使用 powersave governor则是对系统低功耗的最大追求。
  3. Userspace:最早的 cpufreq 子系统通过 userspace governor 为用户提供了这种灵活性。系统将变频策略的决策权交给了用户态应用程序,并提供了相应的接口供用户态应用程序调节 CPU 运行频率使用。 (可以使用Dominik 等人开发了 cpufrequtils工具包 )
  4. ondemand :userspace是内核态的检测,效率低。而ondemand正是人们长期以来希望看到的一个完全在内核态下工作并且能够以更加细粒度的时间间隔对系统负载情况进行采样分析的 governor。当CPU有负载的时候选用最大的主频,当CPU空闲的时候一步
  5. conservative : ondemand governor 的最初实现是在可选的频率范围内调低至下一个可用频率。即根据CPU使用情况进行升或降频,这种降频策略的主导思想是尽量减小对系统性能的负面影响,从而不会使得系统性能在短时间内迅速降低以影响用户体验。但是在 ondemand governor 的这种最初实现版本在社区发布后,大量用户的使用结果表明这种担心实际上是多余的, ondemand governor 在降频时对于目标频率的选择完全可以更加激进。因此最新的 ondemand governor 在降频时会在所有可选频率中一次性选择出可以保证 CPU 工作在 80% 以上负荷的频率,当然如果没有任何一个可选频率满足要求的话则会选择 CPU 支持的最低运行频率。大量用户的测试结果表明这种新的算法可以在不影响系统性能的前提下做到更高效的节能。在算法改进后, ondemand governor 的名字并没有改变,而 ondemand governor 最初的实现也保存了下来,并且由于其算法的保守性而得名 conservative 。

Ondemand降频更加激进,conservative降频比较缓慢保守,事实使用ondemand的效果也是比较好的。和ondemand管理器不同的是,在CPU负载高的时候conservative并不直接跳上最高的主频,而是采用步进的方式来升高主频。Cpufreq在用户态所呈现的接口:
cpuinfo_max_freq cpuinfo_min_freq: 分别给出了 CPU 硬件所支持的最高运行频率及最低运行频率,
cpuinfo_cur_freq 则会从 CPU 硬件寄存器中读取 CPU 当前所处的运行频率。
Governor在选择合适的运行频率时只会在 scaling_max_freq 和scaling_min_freq 所确定的频率范围内进行选择
scaling_cur_freq 返回的是 cpufreq 模块缓存的 CPU 当前运行频率,而不会对CPU 硬件寄存器进行检查。
scaling_available_governors 会告诉用户当前有哪些 governors 可供用户使用
scaling_driver 则会显示该 CPU 所使用的变频驱动程序
Scaling_governor 则会显示当前的管理策略,往这个上echo其他类型会有相应的转变。
scaling_setspeed:需将governor类型切换为userspace,才会出现,往这个文件echo数值,会切换主频

1.运行命令:echo userspace >

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
让系统进入userspace模式,然后就可以通过如下命令手动修改CPU的频率:
echo freq_val > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
其中,freq_val为要设置的CPU频率值,以KHz为单位,如336000代表336MHz。freq_val的

取值范围是 36000~400000。如果freq_val的值不是12000的整数倍,运行此命令后,CPU

频率会被设置到跟freq_val最接近,但又是 12MHz的整数倍的频率。
2.运行命令:echo conservative >

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
让系统进入conservative模式,CPU频率将会逐步降低,直到最小值36MHz。

3.运行命令:echo powersave >

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
让系统进入powersave模式,CPU频率将直接降低到最小值36MHz。

4.运行命令:echo performance >

/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
让系统进入performance模式,CPU频率将直接升高到最大值396MHz。

CPU及串口的变频,当CPU变频前,发PRECHANGE通知给驱动,串口接到该通知后,将FIFO中的内容先发完,然后禁止FIFO;然后CPU做变频的相关改变,改完之后发POSTCHANGE通知;串口收到该通知,以新的时钟重新计数波特率,使能FIFO。

转载请注明:爱开源 » SUSE 系统 CPU 节电模式 引发的故障

您必须 登录 才能发表评论!