cchalpha 发表于 2008-2-24 11:56

【原创】Linux下的cpu降压内核补丁——phc

Windows下的cpu降压软件有nhc,rmc,linux当然也有类似的东西,这就是phc kernel patch,和windows下的单个软件的实现不同,phc是内核补丁,应用过程涉及内核编译、cpu电压调整等,可能造成你的系统和硬件不稳定,风险自负。

phc现在的主页在http://phc.athousandnights.de/

phc适用的cpu类型,支持acpi-cpufreq,speedstep-cpufreq和powernow-k8的cpu,一般而言,pentiumM、Core和Core2, AMD的mobile Athlon64, Turion64 anc compatible。

1、选择补丁类型
2、给内核源码打补丁
3、配置编译内核
4、内核安装,phc系统接口检查
5、phc设置,系统脚本安装

[ Edited bycchalpha on 2008-2-24 15:12 ]

cchalpha 发表于 2008-2-24 12:05

1、选择补丁类型
在http://phc.athousandnights.de/files,我们可以下载phc的补丁代码,根据你内核选择cpufreq processor驱动的不同,分别有3个不同驱动的补丁

patches for acpi-cpufreq
patches for speedstep-centrino
patches for powernow-k8

先看看这些不同的cpufreq驱动在内核中的描述

CONFIG_X86_ACPI_CPUFREQ:                                       
│                                                                         │
│ This driver adds a CPUFreq driver which utilizes the ACPI               │
│ Processor Performance States.                                           │
│ This driver also supports Intel Enhanced Speedstep.

支持ESS,可以用于pentium M、Core和Core2的cpu。

CONFIG_X86_POWERNOW_K8:                                                 │
│                                                                         │
│ This adds the CPUFreq driver for mobile AMD Opteron/Athlon64 processors │
│                                                                         │
│ To compile this driver as a module, choose M here: the                  │
│ module will be called powernow-k8.

AMD的,不太熟悉,不过已经列出cpu型号了,mobile AMD Opteron/Athlon64。

CONFIG_X86_SPEEDSTEP_CENTRINO:                                          │
│                                                                         │
│ This is deprecated and this functionality is now merged into            │
│ acpi_cpufreq (X86_ACPI_CPUFREQ). Use that driver instead of             │
│ speedstep_centrino.                                                   │
│ This adds the CPUFreq driver for Enhanced SpeedStep enabled             │
│ mobile CPUs.This means Intel Pentium M (Centrino) CPUs                │
│ or 64bit enabled Intel Xeons.

也是支持ESS cpu的驱动,不过描述里面已经建议用acpi_cpufreq (X86_ACPI_CPUFREQ)了。

所以不难选择,intel选acpi-cpufreq,amd选powernow-k8。

[ Edited bycchalpha on 2008-2-24 15:12 ]

cchalpha 发表于 2008-2-24 12:07

2、给内核源码打补丁

2.1 下载phc补丁
下载phc需要用到版本管理工具subversion,一般系统没有缺省安装,可以先装上,
aptitude install subversion
然后按http://phc.athousandnights.de/files上的提示下载你需要的补丁
例如,
svn co http://phcpatches.googlecode.com/svn/trunk/acpi-cpufreq phcpatches/cpufreq
将acpi-cpufreq的phc补丁下载到当前目录的phcpatches/cpufreq

2.2下载内核代码
你可以从www.kernel.org下载内核代码,也可以下载你所用系统提供的内核的代码,详细的内核下载安装不在这个帖子的讨论范围,请自行搜索相关信息。

ubunto中取得某内核映像源码
apt-get source linux-image-2.6.24-8-generic

正常情况下内核源码会自动解压缩到/usr/src下

2.3给内核打phc补丁
在phc补丁目录内找到与内核源码版本相符的补丁文件,拷贝到内核源码目录
cp acpi-cpufreq/patches/linux-phc-kernel-vanilla-2.6.24-rc1.patch /usr/src/ubuntu-hardy/

到源码目录,先跑一次,测试一下

root@ubuntu:/home/alpha/phc# cd /usr/src/ubuntu-hardy/
root@ubuntu:/usr/src/ubuntu-hardy# cat linux-phc-kernel-vanilla-2.6.24-rc1.patch| patch -p1 --dry-run
patching file arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
Hunk #4 succeeded at 741 (offset -1 lines).
Hunk #5 succeeded at 760 (offset -1 lines).


没问题就打补丁

root@ubuntu:/usr/src/ubuntu-hardy# cat linux-phc-kernel-vanilla-2.6.24-rc1.patch| patch -p1

[ Edited bycchalpha on 2008-2-24 12:53 ]

cchalpha 发表于 2008-2-24 12:09

3、配置编译内核
内核配置和编译这里不详细说明,不过内核配置中需要把需要的cpufreq驱动选上。如图,



ubuntu的内核编译可以参考https://help.ubuntu.com/community/Kernel/Compile。

例如

AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic


[ Edited bycchalpha on 2008-2-24 14:09 ]

cchalpha 发表于 2008-2-24 12:10

4、内核安装,phc系统接口检查

内核成功编译后可以安装了,不过建议保留一个可以启动的内核。

重新用带phc补丁的内核启动后,可以在/sys/devices/system/cpu/cpu0/cpufreq/下见到phc的接口。


root@ubuntu:/sys/devices/system/cpu/cpu0/cpufreq# ls
affected_cpus         phc_default_vids               scaling_driver
cpuinfo_cur_freq      phc_fids                     scaling_governor
cpuinfo_max_freq      phc_version                  scaling_max_freq
cpuinfo_min_freq      phc_vids                     scaling_min_freq
ondemand            scaling_available_frequenciesstats
phc_controls          scaling_available_governors
phc_default_controlsscaling_cur_freq


检查缺省的频率/电压控制

root@ubuntu:/sys/devices/system/cpu/cpu0/cpufreq# cat phc_default_controls
17:40 14:34 12:30 10:26 8:22 6:18


这些fid:vid,fid可以看做倍频,vid的计算公式是 电压(伏)=(700+vid x 16)/1000

[ Edited bycchalpha on 2008-2-24 14:44 ]

cchalpha 发表于 2008-2-24 12:10

5、phc设置,系统脚本安装

5.1 cpu最低运行电压
至于cpu在每个频率下降到那个电压运行,建议nhc,rmc等工具先测出来,然后直接在linux下配置。

5.2 cpu温度显示工具
在设置phc前,我们需要一个工具来检测cpu温度的变化,在gnome下,可以安装sensors-applet。

然后添加到panel上,如图



配置显示CPU的温度,如图



5.3 设置phc
phc提供的接口中只有两个是可写的,分别是phc_controls和phc_vids,一般使用phc_vids就可以了。

phc设置命令可以用

echo "40 31 24 16 9 2" > /sys/devices/system/cpu/cpu0/cpufreq/phc_vids

其中数字是每个频率下的vid,必须一一对应。

设置phc后,cpu温度的降低可以从sensors-applet看到。

5.4 phc系统脚本安装
如果需要系统启动后就自动设置phc的配置,可以安装phc的系统脚本工具,该工具可以在http://phc.athousandnights.de/files 下载。


svn co http://phctool.googlecode.com/svn/trunk/ phctool


在tools/init-scripts/有gentoo和ubuntu系统的系统初始化脚本,安装就只需把下面的目录拷贝到相应的系统目录。

然后编辑/etc/phc-config/undervolt


# CONFIG_FILE FOR UNDERVOLTAGING
#

# Path to the voltage table sysfs interface file
VTABLE_PATH="/sys/devices/system/cpu/cpu0/cpufreq/phc_vids"

# Switch back to DEFAULT_VTABLE if undervoltage is stopped?
SWITCH_BACK="no"


# Default voltages that will be restored at shutdown if SWITCH_BACK=yes
# DEFAULT_VTABLE="15 14 13 11 10 7"

DEFAULT_VTABLE="40 34 30 26 22 18"


# Custom voltages that will be applied at boot time
# CUSTOM_VTABLE="8 6 4 2 1 0"

CUSTOM_VTABLE="40 31 24 16 9 2"

# Set the following to "yes" when the all the settings are configured
# This is a safety to disable setting the voltages with the default
# values of this file that are probably wrong for your CPU

IS_CONFIGURED="yes"


这里主要是修改CUSTOM_VTABLE为自己的vid序列,修改IS_CONFIGURED为"yes",让系统启动后自动设置phc。

[ Edited bycchalpha on 2008-2-24 15:53 ]

zealoghu 发表于 2008-2-24 12:58

这个应当谨慎操作,毕竟每个cpu能降多少电压是不一样的。

maithon 发表于 2008-4-30 16:11

不错,收藏了,

seu2002 发表于 2008-4-30 18:25

不错不错,还没有尝试过给内核打补丁呢。
页: [1]
查看完整版本: 【原创】Linux下的cpu降压内核补丁——phc