This website is not maintained anymore. If you want to keep track of me or my projects (or hire me) check www.conveniencefactory.com or follow me @conveniencedev

Ruwebit
HARDWARE REVIEWS, DIY PROJECTS, IN-DEPTH ARTICLES
Start DIY projectsReviewsHow-to'sNewsAutomotiveAbout the websiteArchive | Most popularLast updatedTags Sitemap
amdhow-to'slinux
Frequency scaling under Linux: overclocking on demand
Download article as PDF
By Maurice on March 30, 2010 popularity:
Cpufreq scales the frequency of your processor - if it supports it - according to the load. This technique is also known as frequency throttling. Intel calls it SpeedStep, AMD calls it Cool 'n Quiet. It can save a lot of power when the system is idle, thus ideal for your home server. But the features of cpufreq are a little bit limited. Cpufreqd extends those features by wrapping cpufreq. With cpufreqd (with a D) you can scale the frequency of your processor according to your server's conditions like (CPU) temperature, specific processes that are running... you can even overclock your system when you need the extra processing power!

About cpufreq and powerstates

Cpufreq is a set of utilities to configure the frequency scaling under Linux. With cpufreq-set you can set the different frequencies for each powerstate. A processor has different powerstates with different frequencies and (sometimes, depending on the type of the processor, even voltages). Each powerstate consume a different amount of power. P0 is the fastest, but most power consuming state Pn (where n is the maximum powerstate, for AMD Phenom/Phenom processors this is 3) is the slowest, but least power consuming state

Whit cpufreq-set you can also set the governor. A governor defines a set of rules that are used to determine when the processor should switch to another powerstate. To view what frequencies and governors are supported by your processor you can use cpufreq-info. Examples of governors are: powersave, ondemand and performance. 'Performance' always uses the fasted powerstate (Pn) and doesn't scale back. 'Powersave' is the most power efficient, but can be a bottleneck for things like videotranscoding because of the fact that it switches quickly back to lower powerstates. 'Ondemand' is the default governor and waits longer before switching back to lower power states. There is also something called a 'userspace governor', where cpufreq lets another (userspace) program decide which powerstate to choose, but that's not recommended because it's usually slower then the existing (kernelspace) governors.

You don't have to configure anything for cpufreq, it should work out-of-the-box with any modern Linux distribution. I use openSUSE 11.2 for example. However, the frequencies of the powerstates are pre-defined. You cannot change these. When you have an AMD Phenom processor you can use k10ctl (and my wrapper script) to set the frequency and voltage for each powerstate. When you combine k10ctl with cpufreqd and cpufreq you can use it to dynamically set the frequency depending on load, temperature, well the things I mentioned above.

About cpufreqd and installation

Cpufreqd is, I quote..

Quote: A small daemon to adjust cpu speed and voltage for kernels using any of the cpufreq drivers available. Cpufreqd is not a userspace governor. Cpufreqd allows you to apply governor profiles from rules based on battery level, ac status, temperature (ACPI or sensors), running programs, cpu usage and (maybe) more. You can also change your nforce FSB clock and video card frequency (NVidia only) or execute arbitrary commands when a specific rule is applied.

That sounds promising...

The steps below are written with openSUSE 11.2 and an AMD Phenom II 965 Black Edition (965 BE) processor in mind. If you know what you are doing it can be applied to other system configurations as well.

I couldn't find a pre-built package wich also was compiled with lm-sensors support, so I downloaded and built one myself.

Be sure you have the latest lm-sensor development package installed. I first used libsensors3, but could get all my temperature sensor to work with cpufreqd. So I recommend libsensors4 eg.

zypper install libsensors4 libsensors4-devel

Download the cpufreqd source here. I picked version 2.4.1.

Unpack it and build it (I assume that you have all needed (C++) development packages installed):

tar -jxvf cpufreqd-2.4.1.tar.bz2
cd cpufreqd-2.4.1/
./configure --exec-prefix=/usr --prefix=/
make
make install

If you have a 4 core CPU you can use make -j4 to speed up the build process (or -j2 for two cores).

You can start cpufreqd with:

/etc/init.d/cpufreqd start

To make it start on boot:

chkconfig cpufreqd on

To debug you can use:

cpufreqd -D -V7

Cpufreqd configuration

The configuration file of cpufreqd can be found in /etc/cpufreqd.conf. The configuration file contains both profiles and rules. A profile chooses what governor is used and which CPU speeds are allowed. A rule defines on what conditions a specific profile should be used. Examples of supported conditions:

Battery level of your laptop's battery
If your laptop is connected to AC power or not
Temperature of your CPU or motherboard
Fanspeed of one the connected fans
CPU load (of 1 core or CPU or over all cores)
If a specific process is started

You can also start scripts when a profile is selected and that comes in handy if you want to change the frequency and voltage with k10ctl. Furthermore you can set a lot of parameters for the governors used, you can even set the frequency of your nvidia chip. Checkout man cpufreqd.conf for all the possible options.

Putting it al together, I came up with the state diagram below.

statediagram.png


The state in this diagram is what I call 'meta powerstates':

When there isn't much to do for the CPU, the 'Power Save' state will be active wich uses low frequencies chosen by the 'ondemand' governor.
When there is some load, the 'Allround' state is active with higher frequency, also chosen by the 'ondemand' governor
When mencoder or ffmpeg is running, the 'Turbo' state is active which overclocks the CPU a little and uses the 'performance' governor to select P0
When the CPU starts to overheat the 'Cooling Down' state is active. The maximum operating temperature of my 965 BE processor is specced at 62°C, but in diverse fora I read it's recommended to keep it below 55°C. The Cooling Down state uses the same settings as the 'Power Save' state but also sends me an E-mail to notify me.

A long story short, here is my /etc/cpufreqd.conf:

[General]
pidfile=/var/run/cpufreqd.pid
poll_interval=2
verbosity=4
enable_remote=1
#remote_group=root
[/General]

[sensors_plugin]
sensors_conf=/etc/sensors3.conf
[/sensors_plugin]

#
# Cooling Down period when CPU is to hot
#
[Profile]
name=Cooling Down
minfreq=20%
maxfreq=80%
policy=ondemand
exec_pre=/usr/bin/k10_powersave
exec_post=/usr/bin/notify
[/Profile]

#
# MetaP0
#
[Profile]
name=Turbo Performance
minfreq=20%
maxfreq=100%
policy=performance
exec_pre=/usr/bin/k10_turbo
exec_post=/usr/bin/cpufreq-all -g performance
[/Profile]

#
# MetaP1
#
[Profile]
name=Turbo On Demand
minfreq=20%
maxfreq=100%
policy=ondemand
exec_pre=/usr/bin/k10_turbo
[/Profile]

#
# MetaP2
#
[Profile]
name=Allround
minfreq=20%
maxfreq=100%
policy=ondemand
exec_pre=/usr/bin/k10_allround
[/Profile]

#
# MetaP3
#
[Profile]
name=Power Save
minfreq=20%
maxfreq=100%
policy=ondemand
exec_pre=/usr/bin/k10_powersave
[/Profile]

##
# Special Rules
##

#
# Thermal protection
#
# AMD Phenom II C3 max temp specced at 62C, preferred to keep it below 55C for
# stability reasons.
# http://www.overclock.net/amd-cpus/690000-phenom-ii-x4-945-c3-max.html
#
[Rule]
name=CPU Too Hot
sensor=coretemp:50-100
cpu_interval=0-100
profile=Cooling Down
[/Rule]

#
# Movie transcoding
#
[Rule]
name=Movie transcoding
programs=mencoder,ffmpeg
cpu_interval=30-100
sensor=coretemp:10-50
profile=Turbo On Demand
[/Rule]

#
# Default profile
#
[Rule]
name=Allround
cpu_interval=ANY:15-100
sensor=temp1:10-50
profile=Allround
[/Rule]

#
# Powersave
#
[Rule]
name=Power Save
cpu_interval=ALL:0-5
profile=Power Save
[/Rule]


In this configuration file I use different scripts. I don't put these scripts here for your copy-and-paste convenience, because they can damage your CPU (but if your are curious, you can check this article):

k10_turbo which uses k10ctl to define these powerstates: P0: 3.8GHz, P1: 2.8GHz, P2: 2.0 GHz, P1: 1.0 GHz
k10_allround which uses k10ctl to define these powerstates: P0: 3.2GHz, P1: 2.8GHz, P2: 2.0 GHz, P1: 1.0 GHz
k10_powersave which uses k10ctl to define these powerstates: P0: 3.2GHz, P1: 2.8GHz, P2: 2.0 GHz, P1: 1.0 GHz
notify which sends me an email

If you are having problems with reading sensor information correctly, check out the /etc/sensors.conf or /etc/sensors.conf file. It is possible that two sensors have the same name. In the configuration file you can find examples on how to rename a sensor. For example, the renaming the CPU sensor of the 965 BE, add these lines to the end of the file:

chip "k10temp-pci-00c3"
label temp1 "cputemp"


Last update notes

Latest scripts can be found here, no support

Copyright © 1999-2010 by Maurice de Bijl. This article was published on 2010-03-30 in amd  how-to's  linux

Was this article useful to you? Please help me by using the toolbar below to tweet the article, give it an eKudo or add it to Hyves, Facebook, Delicous, Digg or another site. Thanks!

Download article as PDF

Comments on this article

There is 1 comment

Obfuscated IP-address: 786846008
Obfuscated E-mail address: ofenaopyipau
Click for more details  2011-10-22 08:12:05 posted by the dsc
"Sensors-detect" says my sensor driver is "it87". However my sensors.conf had just that:

chip "it87-*" "it8712-*" "it8716-*" "it8718-*" "it8720-*"

label in8 "Vbat"

Then followed to a different chip. I've tried to add

label temp1 "CPU0 Temp"
label temp2 "CPU1 Temp"

that I just copied from other chips, but cpufreqd kept showing a phoney static 30C average temperature for some reason. I've tried also to change "it87-*" for "it87*", but had not effect either (not the desired one at least).

I have temperature readings via KDE's "system monitor" though. I've also changed the original cpufreqd.conf with many many variations besides the defaults, "acpi_temperature=", from yours "sensor=coretemp:" to "sensor=" many other things like temp1, coretemp-isa-0000, in8, Vbat, temp1, etc.

Any suggestions? Many thanks.
POPULAR TAGS
Show all tags
SEARCH KEYWORD
FOLLOW ME
Twitter