Chinaunix首页 | 论坛 | 博客
  • 博客访问: 825679
  • 博文数量: 188
  • 博客积分: 4433
  • 博客等级: 上校
  • 技术积分: 1905
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-14 07:14
个人简介

linux

文章分类

全部博文(188)

文章存档

2016年(6)

2015年(22)

2014年(18)

2013年(5)

2012年(125)

2011年(10)

2010年(2)

分类: LINUX

2015-03-08 20:04:49



8
4

In Linux you can shut down CPU cores (or physical CPU's) with echo 0 > /sys/devices/system/cpu/cpu1/online Assuming that the hardware fully turn off the CPU and cuts power to it would it not be better to disabled the cores entirely instead of relying on the various sleep states of a processor?

To illustrate the principle I was thinking something along these lines (pseudocode) for a system with four CPU's:

if(loadavg > 3.00) echo 1 > /sys/devices/system/cpu/cpu3/online
if(loadavg < 3.00) echo 0 > /sys/devices/system/cpu/cpu3/online

if(loadavg > 2.00) echo 1 > /sys/devices/system/cpu/cpu2/online
if(loadavg < 2.00) echo 0 > /sys/devices/system/cpu/cpu2/online

if(loadavg > 1.00) echo 1 > /sys/devices/system/cpu/cpu1/online
if(loadavg < 1.00) echo 0 > /sys/devices/system/cpu/cpu1/online 


5

Setting the online status of the CPU core just tells the process scheduler to not use that core for any processes. On a hardware level, the core is simply sitting idle (doing NOPs), but still powered. While this will save power, it won't save nearly as much power as putting the computer to sleep. Why?

Well, your motherboard, CPU, and GPU are all still running! When you put the computer to sleep, all of these components are literally unpowered, and just enough power to keep your RAM alive is used (on the order of a couple watts).

Again, while I agree it will save power, even shutting off half of your CPU cores may halve the power consumption of the processor (although in reality, you may only save 30-40% since those cores still need to sit idle), but this is far from the only component in the system using power. Even if you save 50W by doing this, you're entire computer is still drawing far more power than mere watts in sleep mode.


Final thoughts: While I agree this is a great idea in practice, this is also why many CPU manufacturers include dynamic frequency scaling (Intel's "Speed Step"), with support for Linux. You may yield better overall performance, as well as power efficiency, by setting these frequencies more appropriately for your needs. This can be done in both hardware (BIOS settings), as well as software (the Linux kernel allows you to modify some CPU parameters, see the link I posted above or for details).

This works, because the following is the generic equation for power consumption of a CMOS circuit:

P = CV2f, where C = capacitance (assume fixed), V = voltage, and f = frequency.

Thus, dividing the frequency by 2 will half the original power consumption. Dividing the voltage by 2 will reduce power consumption to 1/4 the original.

http://blog.sina.com.cn/s/blog_858820890101cplt.html
转自: 

http://sunj.iteye.com/blog/1940948

Linux双核cpu转为单核运行 echo 0 > /sys/devices/system/cpu/cpu1/online 
若你机器是双核的cpu,上面命令使你的第二个内核停止运行。 
这样/sys/devices/system/cpu/cpu1/下的所有关于第二个内核的文件消失。 
单核运行,cpu很容易就飙到100的,只需移动一下窗口。不知道省电否。 


echo 1 > /sys/devices/system/cpu/cpu1/online 
恢复双核运行 

cat /sys/devices/system/cpu/online 可以显示你的当前工作的cpu数。 

echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
可以设置你的cpu为省电模式 

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors 
可用的模式 

[root@shine cpufreq]# ls 
affected_cpus               related_cpus                   scaling_governor 
cpuinfo_cur_freq            scaling_available_frequencies  scaling_max_freq 
cpuinfo_max_freq            scaling_available_governors    scaling_min_freq 
cpuinfo_min_freq            scaling_cur_freq               scaling_setspeed 
cpuinfo_transition_latency  scaling_driver                 stats 

网上看到的脚本不知道是否管用 
#!/bin/bash 
# author: fcicq 
# requirement: 
# acpi,cpufreq 
# a Dual Core CPU (like Intel core 2) 
chkavg() { 
thisloadavg=`cat /proc/loadavg | awk -F . '{print $1}'` 
if [ $thisloadavg -ge 2 ]; then 
# >2 
if [ `cat /sys/devices/system/cpu/cpu1/online` -eq 0 ]; then 
echo 1 > /sys/devices/system/cpu/cpu1/online 
fi 
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 
cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq > /sys/devices/system/cpu/cpu1/cpufreq/scaling_setspeed 
elif [ $thisloadavg -ge 1 ]; then 
# 1-2 
if [ `cat /sys/devices/system/cpu/cpu1/online` -eq 1 ]; then 
echo 0 > /sys/devices/system/cpu/cpu1/online 
fi 
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 
else 
# 0-1 
if [ `cat /sys/devices/system/cpu/cpu1/online` -eq 1 ]; then 
echo 0 > /sys/devices/system/cpu/cpu1/online 
fi 
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed 
fi 

while true; do 
chkavg 
sleep 60 
done  

阅读(1011) | 评论(0) | 转发(0) |
0

上一篇:Django学习

下一篇:模拟disk IO error

给主人留下些什么吧!~~