Page 1 of 4

cpu frequency scaling

Posted: Sat Jan 24, 2009 11:11 am
by raboof
I just noticed that my 1.86GHz CPU was running at 798MHz instead - presumably to save power.

While that's great to save battery life and the environment, when doing low-latency stuff this feature should of course be disabled :).

Note to self: check out which tools to use to inspect and modify freqency scaling. cpufreq-selector looks good but seems to hang.

See also: http://idebian.wordpress.com/2008/06/22 ... -in-linux/

Re: cpu frequency scaling

Posted: Sat Jan 24, 2009 11:33 am
by studio32
Thanks, it's such an important and great thing that this kind of information is shared and discussed on this forum! It could really improve our realtime/audio performances!

thanks all!

Re: cpu frequency scaling

Posted: Mon Jan 26, 2009 9:56 am
by studio32
I think mine looks fine, with my 2.8

Code: Select all

$  more /proc/cpuinfo | grep MHz
cpu MHz         : 2793.065

Re: cpu frequency scaling

Posted: Mon Jan 26, 2009 4:44 pm
by Jiyunatori
On somewhat recent kernels, frequency scaling is handled by the cpufreq daemon and a bunch of kernel level stuff - at least on all system I've seen so far.

cpufreq-info gives some insight :

Code: Select all

analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which need to switch frequency at the same time: 0
  hardware limits: 600 MHz - 1.20 GHz
  available frequency steps: 1.20 GHz, 1.10 GHz, 1000 MHz, 900 MHz, 800 MHz, 600 MHz
  available cpufreq governors: ondemand, performance
  current policy: frequency should be within 600 MHz and 1.20 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
The important part is the "cpufreq governor". The governor defines the freq scaling policy. With "ondemand", the freq is low by default, and is scaled up when necessary. If you want the freq to stay to the max, you should use the "performance" governor, which is set with the following cmdline :

Code: Select all

sudo cpufreq-set -g performance
(or whatever you use instead of sudo)

Hope this helps

~tori

Re: cpu frequency scaling

Posted: Wed Jan 28, 2009 5:41 am
by philip888
Thank you tori for your post. Gave me some added incite on my system.

After i run "sudo cpufreq-set -g performance" how do I get the "performance" option to stick?

After a reboot my system resets itself to the "ondemand" option.

Where and what do I edit to save the "performance" option?

Thanks

Philip

Re: cpu frequency scaling

Posted: Wed Jan 28, 2009 9:31 am
by thorgal
it's not optimal but it will work:

Code: Select all

echo "cpufreq-set -g performance" >> /etc/rc.local
and then reboot.
Note: I don't know where the utility cpufreq-set is located, never used it, but if it is in /usr/sbin or /sbin or wherever, put the full path in the echo command. I don't think the execution of rc.local will work correctly if the full path is not mentioned. Assuming it is /usr/sbin, you should echo this:

Code: Select all

echo "/usr/sbin/cpufreq-set -g performance" >> /etc/rc.local
The file /etc/rc.local is an executable script and is the last stuff to be executed at boot time (by root, mind you) before your windows manager kicks in. This is an old-fashioned way to do things.

An alternative is to compile your kernel with the performance governor as your preferred governor (which I do myself). Yet another way is to set the preference somewhere in the /sys or /proc area. Don't remember where. These process related places are a bit messy and one can never remember the exact location where stuff can be changed for a specific thing. But I know I did it a long time ago in /sys/power/blabla or was it /sys/kernel/blabla or /proc/acpi/blabla ... you see what I mean ...

Re: cpu frequency scaling

Posted: Wed Jan 28, 2009 10:15 am
by Jiyunatori
thorgal is right, the quick and dirty way to do it is to add the command to the /etc/rc.local file - this script is ran at boot time.

There is a cleaner way to do it, though. depending of the distro you use, it might be a bit different, but here is the idea.

I said cpufreq is a daemon. With every daemon usually comes a config file. On my archlinux system, it goes this way :

/etc/conf.d/cpufreq

Code: Select all

#configuration for cpufreq control

# valid governors:
#  ondemand, performance, powersave,
#  conservative, userspace
governor="ondemand"

# valid suffixes: Hz, kHz (default), MHz, GHz, THz
min_freq="600MHz"
max_freq="1.2GHz"
Obviously, all you have to do is to replace "ondemand" with "performance"

On debian/ubuntu systems, it might be stored somewhere else - but there is probably something equivalent.

~ tori

Re: cpu frequency scaling

Posted: Wed Jan 28, 2009 5:00 pm
by philip888
thorgal and tori thank you both for your responses. Through both of your posts I was able to find a solution.

For the record and anyone else who is on a Debian based system here is what I did to accomplish this.

The shell script for "cpufrequtils" is located in /etc/init.d/cpufrequtils.

I changed the following.

Code: Select all

ENABLE="true"
GOVERNOR="ondemand"
MAX_SPEED=0
MIN_SPEED=0
To.

Code: Select all

ENABLE="true"
GOVERNOR="performance"
MAX_SPEED="0"
MIN_SPEED="0"
Saved the script and rebooted.

When I ran

Code: Select all

~$ more /proc/cpuinfo | grep MHz
before the change I would get

Code: Select all

cpu MHz         : 1000
cpu MHz         : 1000
Now when I run

Code: Select all

 more /proc/cpuinfo | grep MHz
I get

Code: Select all

cpu MHz         : 2200.000
cpu MHz         : 2200.000
Also running "cpufreq-info" yeilds the following.

Code: Select all

~$ cpufreq-info
cpufrequtils 002: cpufreq-info (C) Dominik Brodowski 2004-2006
Report errors and bugs to linux@brodo.de, please.
analyzing CPU 0:
  driver: powernow-k8
  CPUs which need to switch frequency at the same time: 0 1
  hardware limits: 1000 MHz - 2.20 GHz
  available frequency steps: 2.20 GHz, 2.00 GHz, 1.80 GHz, 1000 MHz
  available cpufreq governors: ondemand, powersave, userspace, conservative, performance
  current policy: frequency should be within 1000 MHz and 2.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.20 GHz.
analyzing CPU 1:
  driver: powernow-k8
  CPUs which need to switch frequency at the same time: 0 1
  hardware limits: 1000 MHz - 2.20 GHz
  available frequency steps: 2.20 GHz, 2.00 GHz, 1.80 GHz, 1000 MHz
  available cpufreq governors: ondemand, powersave, userspace, conservative, performance
  current policy: frequency should be within 1000 MHz and 2.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 2.20 GHz.
Again thanks for the incite.


Philip

Re: cpu frequency scaling

Posted: Thu Jan 29, 2009 5:08 pm
by Yeri
in my sistem (Ubuntu hardy heron) there is the directory /sys/devices/system/cpu/cpu*/cpufreq which contains:

Code: Select all

gerard@procrustes:/sys/devices/system/cpu/cpu0/cpufreq$ ls
affected_cpus     ondemand                       scaling_driver    stats
cpuinfo_cur_freq  scaling_available_frequencies  scaling_governor
cpuinfo_max_freq  scaling_available_governors    scaling_max_freq
cpuinfo_min_freq  scaling_cur_freq               scaling_min_freq
where, for example, the file scaling_governor contains:

Code: Select all

gerard@procrustes:/sys/devices/system/cpu/cpu0/cpufreq$ sudo cat scaling_governor 
ondemand
Hope it helps to ubunteros,

Gerard.

Re: cpu frequency scaling

Posted: Fri Jul 23, 2010 5:32 pm
by studio32

Re: cpu frequency scaling

Posted: Fri Jul 23, 2010 9:59 pm
by autostatic
chmodding stuff in the /sys directory to get things to work? Not the way to do it if you ask me.

Re: cpu frequency scaling

Posted: Sat Jul 24, 2010 12:45 am
by SR
On my Toshiba laptop I noticed that running "cpufreq-set -g performance" only affects the first CPU (I have 8 cores). If I run this I can set all cores to performance:

Code: Select all

for x in $( seq 0 7 )
do
	cpufreq-set -c $x -g performance
done

Re: cpu frequency scaling

Posted: Sat Jul 24, 2010 1:38 pm
by Scary Hallo
Thank you for this article. This helps to solve my problem with xruns (http://www.linuxmusicians.com/viewtopic.php?f=27&t=2276).
I installed the 'CPU Frequency Scaling Monitor' and switched from 'Ondemand' to 'Performance'. All is good now.
:D :D :D :D

Re: cpu frequency scaling

Posted: Sat Jul 24, 2010 2:24 pm
by raboof
Scary Hallo wrote:This helps to solve my problem with xruns (http://www.linuxmusicians.com/viewtopic.php?f=27&t=2276). I installed the 'CPU Frequency Scaling Monitor' and switched from 'Ondemand' to 'Performance'. All is good now.
Cool!

Added this check to the http://code.google.com/p/realtimeconfigquickscan/

Re: cpu frequency scaling

Posted: Mon Jul 26, 2010 12:49 pm
by morko
I have a laptop that runs quite hot so I didn't want to use the "performance" governor. The "conservative" governor works fine for me. I think it doesn't change the frequency so rapidly and I'm not getting xruns because of it. You might want to try it if you dont want your cpu running at full power all the time. Or then you can bore yourself making your own governors. ;)