# CPUFreq Guide

## darkfolk

CPUFreq Guide and Review

CPUFreq can be very useful on laptops, and even on desktops; to set it up on Gentoo to work perfectly how you want it takes time, but once tweaked, CPUFreq can run very smoothly.

First, you need a kernel with...

Power Management Options (ACPI,APM) -->

        CPU Frequency Scaling -->

               # we will use the cpufreqd daemon, so do not handle it automatically

               Default CPUFreq Governor (userspace) -->

               CPU Frequency Table Helpers (if your driver doesn't show up)

                And a driver ( I chose Intel Pentium 4 Clock Modulation)

```

emerge cpufreqd

# if you will use the "human-readable" frequency reading, 

emerge cpufrequtils

# this if you don't have it. It looks nice ;)

emerge torsmo

# Torsmo tells me all the temps and frequencies in this setup.

```

after that is all set up, you will need a /etc/cpufreqd.conf. Example:

```

# Remember to modify this with your own CPU frequencies (in Hz, check /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies for the HZ settings you

 can use)

# Also, you need spaces between the sections like [Rule] [General] and [Profile] (they are already here in this example)

# This file was configured P4 2.80ghz (C version, Hyper-Threading, Northwood cor

e) on a desktop

[General]

pidfile=/var/run/cpufreqd.pid

poll_interval=1

pm_type=acpi #(acpi, apm or pmu)

# Uncomment the following line to enable ACPI workaround (see cpufreqd.conf(5))

# acpi_workaround=1

verbosity=3 #(if you want a minimal logging set to 5)

[Profile]

name=max_power

# These should be replaced with your own frequencies

minfreq=2100000

maxfreq=2800000

policy=userspace

[Profile]

name=medium_power

minfreq=1400000

maxfreq=1400000

policy=userspace

[Profile]

name=lo_power

minfreq=700000

maxfreq=1050000

policy=userspace

# for low power operations, use lo_power profile, since it will not need added pow

er. replace cpu_interval=0-40 with whatever CPU load you think should need only 700mhz-1000mhz (or whatever you chose) like cpu_interval=0-30.

[Rule]

name=lo_cpu_boost

ac=on

cpu_interval=0-40

profile=lo_power

# Something around the middle is happening, like the end of a portage sync or co

mpile; the CPU should be good in the 1.4ghz-1.75ghz range.

[Rule]

name=medium_cpu_boost

ac=on

cpu_interval=41-49

profile=medium_power

# Now the CPU needs some power, so give it full strength. This runs when you are doing something not listed in the last rule (which counts as more if the programs listed are running) is using a lot of cpu power

[Rule]

name=max_cpu_boost

ac=on

cpu_interval=50-100

profile=max_power

# various progs need full power, so give it to them, no matter what. These include movie players, and most things that run during a emerge. Modify this with programs that need power

[Rule]

name=power_needed

ac=on

# These programs, if running, will cause your CPU to go at 100% (in this case, 2.8ghz) remove any that you think should not cause this.

programs=xine,mplayer,gmplayer,avidemux,gcc,g++,emerge,cc,nbench,automake,config

ure,autoconfig,make

# CPU Interval = CPU Load

cpu_interval=0-100

profile=max_power

```

If you have a processor with HyperThreading or SMP, check /sys/devices/cpu/cpu0/cpufreq/affected_cpus . Of course, on HT, the same processor is being used, so it doesn't matter, but on other processors you should check it.

Now that that is done and over with, open three consoles. (or one, if you will run cpufreqd without a temperature reading or frequency reading (or do not need a script to do this)) One will run tailfreq, the other temps. The last one will run:

cpufreqd -D -f /etc/cpufreqd.conf  -V  6

Now you will see tons of output. Keep an eye on whatever you use to see the frequencies, so you know what speed your CPU is running.

Congratulations, you are done!

Questions, Comments?

Of course, the tailfreq and temps script could be replaced with a torsmo or anything else you want to use ( I use torsmo)Last edited by darkfolk on Tue Feb 01, 2005 10:18 pm; edited 3 times in total

----------

## darkfolk

```

${color red}Burning CPU Frequency:

 ${execi 1 cpufreq-info -c 0 -m -f}

```

Now you'll need to emerge CPUfrequtils, but this looks a lot nicer (thanks)Last edited by darkfolk on Tue Feb 01, 2005 10:06 pm; edited 1 time in total

----------

## brodo

Also of use is the (new) cpufrequtils package and its two tools cpufreq-info and cpufreq-set. E.g. 

```
cpufreq-info -c 1 -f
```

 returns the current CPU frequency on CPU 1. cpufreqd will depend on cpufrequtils soon.

----------

## darkfolk

cpufreq-info -c 0 -m -f works better (comes in Mhz/Ghz form instead of Hz)  :Wink: 

I'd show you some screenshots, but I forgot how to take them without using something like ksnapshot so no screenies  :Sad: 

----------

## brodo

 *darkfolk wrote:*   

> cpufreq-info -c 0 -m -f works better (comes in Mhz/Ghz form instead of Hz) 

 

I'm glad you like this feature   :Wink: 

----------

## Pleun

small question: does /proc/cpuinfo list the real-time cpuspeed, or only the 'normal' cpuspeed?

Seems like my cpufreqd is running, and cpufreq-info tells me it's running on 383,xxx mhz, but my /proc/cpuinfo still shows 3.064 ghz, and i don't see a big change on my battery-usage too. I'm using HT btw, maybe that has something  to do with it?

----------

## brodo

/proc/cpuinfo does not report "true" CPU frequency if the kernel is built with SMP support, and as HT requires SMP support, you better use cpufreq-info from cpufrequtils

----------

## Pleun

So cpufreqd is running then. Weird, I don't really see a "batterylife-boost", while it should use way less power at 400 mhz.

----------

## Vishruth

I wrote this little python script that works with the userspace governor. I wrote it for my own use, but others may also find it useful... Great thread, btw.

Oh, and also, this script automatically checks what the scaling governor is when you try to change the frequency. If scaling_governor is not set to 'userspace', it will try to automatically do it for you and then it will attempt to change the frequency. You can check for the current frequency and governor as a normal user, but you'll need to be root to change the CPU frequency and the scaling governor.

http://www.thepyromania.com/python/pycf.py

```
pycf (Python Cpufreq) ver. 01 for supported processors.

(single processors only!)

pycf v. 01 only supports the 'userspace' governor.

Usage:

    pycf.py <option> <arg>

    

    -a   >> Show all available frequencies for the current CPU.

    -c   >> Show current CPU frequency and current scaling governor.

    -f   >> pycf.py -f <freq.>

            Changes CPU frequency to the number given.

    -g   >> Sets governor to 'userspace'.

    -h   >> Show this help message.

    -m   >> pycf.py -m <other options> <args>

            Use MHz instead of the default KHz.
```

----------

## camillo

I have a laptop with a Pentium 3 NON mobile.

Is possible to use frequency scaling or I need a Pentium M?

Thanks

----------

## brettlpb

Sorry pentium-3's don't support freq scaling afaik.

----------

## sidkdbl07

I'm a real noob at this....

I have cpufreqd running like you said....

Do I have to do "rc-update add..." or anything to get this to run automatically?

What do I do with torsmo?

----------

## jballou

sid: Yes, 'rc-update add cpufreqd default' works.

----------

## leks

 *brettlpb wrote:*   

> Sorry pentium-3's don't support freq scaling afaik.

 

wrong

----------

## The Funky Pkunk

In the default config there are the following lines:

```
cpu_nice_scale=1.5

delay_cycles=3
```

However, I can't seem to find anything in the manpage or from googling as to what these lines actually do. Anyone got an idea?

----------

