最新消息:

CPU省电进程kondemand介绍

Linux ipcpu 6155浏览

kondemand概述

近日在某服务器上发现了一个kondemand进程,占用CPU1-2%左右,看起来像是个系统相关进程。

经查询发现这个是一个CPU省电模式相关的进程。

省电模式

CPU省电模式是BIOS里面的一个设定,为一些便携式及家用台式机广泛使用,当系统负载不高时降低CPU运行频率,节省电量,此时CPU温度也不会太高,CPU风扇转速低,声音小。当玩游戏时,需要消耗大量CPU,CPU频率又会自动调高,CPU温度和风扇转速也会跟进,声音会比较大。

当使用服务器时,这个省电模式就会有问题了,当瞬间使用大量CPU资源时,CPU需要升高频率,需要一段时间,造成相应缓慢,因此服务器上一般是关闭省电模式的。

省电模式一般在BIOS里设定。也可以使用ILO或者iDRAC,如下,

监测省电模式是否开启

在系统中也可以监测到省电模式是否开启

  1. #@部分或者全部CPU核的频率与标称频率不一致
  2. [root@sw36.ipcpu.com ~]# grep -E '^model name|^cpu MHz' /proc/cpuinfo
  3. model name : Intel(R) Xeon(R) CPU E5-2640 v2 @ 2.00GHz
  4. cpu MHz : 1200.000
  5. #@scaling_governor显示ondemand
  6. [root@sw36.ipcpu.com ~]# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
  7. ondemand
  8. #@系统中存在kondemand进程
  9. [root@sw36.ipcpu.com ~]# ps ax| grep kondemand
  10. 2150 ? S 2284:52 [kondemand/0]
  11. 2151 ? S 1710:57 [kondemand/1]
  12. 2152 ? S 1201:36 [kondemand/2]
  13. #@系统内核加载了cpufreq相关模块
  14. [root@sw36.ipcpu.com ~]#lsmod |grep cpufreq
  15. pcc_cpufreq 5090 0
  16. cpufreq_ondemand 10544 0
  17. freq_table 4936 1 cpufreq_ondemand

从系统中调整省电模式

从BIOS里调整是最好的办法,但是服务器不能重启的话,就只能从系统中修改了。

1. 关闭cpuspeed服务
2. 查看当前机器支持的策略
  1. [root@sw36.ipcpu.com ~]#cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
  2. ondemand userspace performance
  3. [root@sw36.swoole.qyer.idc ~]#
3. 写shell脚本进行设定
  1. #!/bin/bash
  2. #set cpu scaling governor by your self
  3. #函数查找有几个核心并将其scaling_governor文件设置成你所需要的内容
  4. set_cpu()
  5. {
  6. for i in `ls /sys/devices/system/cpu/ | grep 'cpu[0-9]?*'`
  7. doecho $1 > /sys/devices/system/cpu/$i/cpufreq/scaling_governor
  8. done
  9. }
  10. #判断输入
  11. case $1 in
  12. #performance
  13. "pf")
  14. set_cpu performance
  15. ;;
  16. #ondemand
  17. "od")
  18. ;;
  19. #conservative
  20. "cs")
  21. ;;
  22. #powersave
  23. "ps")
  24. set_cpu powersave
  25. ;;
  26. *)
  27. echo "please input [pf][od][cs][ps]"
  28. ;;
  29. esac
4. 通过观察/proc/cpuinfo显示的频率可以看到是否生效

参考资料

http://my.pc-freak.net/utilize-processor-work-linux-server-disable-cpu-scaling-linux-server-cpu-work-full-speed/
https://www.servernoobs.com/avoiding-cpu-speed-scaling-in-modern-linux-distributions-running-cpu-at-full-speed-tips/
http://www.cnblogs.com/reddusty/p/5053909.html
https://www.pantz.org/software/cpufreq/usingcpufreqonlinux.html
http://mdba.cn/2013/12/24/%E9%92%88%E5%AF%B9mysql%E7%9A%84linux%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98%E6%8A%80%E5%B7%A7/
https://www.percona.com/blog/2013/12/07/linux-performance-tuning-tips-mysql/

转载请注明:IPCPU-网络之路 » CPU省电进程kondemand介绍