cpu frequency scaling
Moderators: MattKingUSA, khz
- raboof
- Established Member
- Posts: 1855
- Joined: Tue Apr 08, 2008 11:58 am
- Location: Deventer, NL
- Has thanked: 50 times
- Been thanked: 74 times
- Contact:
cpu frequency scaling
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/
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
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!
thanks all!
Re: cpu frequency scaling
I think mine looks fine, with my 2.8
Code: Select all
$ more /proc/cpuinfo | grep MHz
cpu MHz : 2793.065
-
- Established Member
- Posts: 7
- Joined: Mon Jan 26, 2009 9:46 am
Re: cpu frequency scaling
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 :
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 :
(or whatever you use instead of sudo)
Hope this helps
~tori
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.
Code: Select all
sudo cpufreq-set -g performance
Hope this helps
~tori
Re: cpu frequency scaling
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
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
it's not optimal but it will work:
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:
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 ...
Code: Select all
echo "cpufreq-set -g performance" >> /etc/rc.local
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
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 ...
-
- Established Member
- Posts: 7
- Joined: Mon Jan 26, 2009 9:46 am
Re: cpu frequency scaling
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
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
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"
On debian/ubuntu systems, it might be stored somewhere else - but there is probably something equivalent.
~ tori
Re: cpu frequency scaling
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.
To.
Saved the script and rebooted.
When I ran before the change I would get
Now when I run I get
Also running "cpufreq-info" yeilds the following.
Again thanks for the incite.
Philip
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
Code: Select all
ENABLE="true"
GOVERNOR="performance"
MAX_SPEED="0"
MIN_SPEED="0"
When I ran
Code: Select all
~$ more /proc/cpuinfo | grep MHz
Code: Select all
cpu MHz : 1000
cpu MHz : 1000
Code: Select all
more /proc/cpuinfo | grep MHz
Code: Select all
cpu MHz : 2200.000
cpu MHz : 2200.000
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.
Philip
Re: cpu frequency scaling
in my sistem (Ubuntu hardy heron) there is the directory /sys/devices/system/cpu/cpu*/cpufreq which contains:
where, for example, the file scaling_governor contains:
Hope it helps to ubunteros,
Gerard.
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
Code: Select all
gerard@procrustes:/sys/devices/system/cpu/cpu0/cpufreq$ sudo cat scaling_governor
ondemand
Gerard.
- autostatic
- Established Member
- Posts: 1994
- Joined: Wed Dec 09, 2009 5:26 pm
- Location: Beverwijk, The Netherlands
- Has thanked: 32 times
- Been thanked: 104 times
- Contact:
Re: cpu frequency scaling
chmodding stuff in the /sys directory to get things to work? Not the way to do it if you ask me.studio32 wrote:See also http://www.youtube.com/watch?v=Bn6g_YCxq2o
Re: cpu frequency scaling
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
- Scary Hallo
- Established Member
- Posts: 280
- Joined: Fri Oct 23, 2009 2:21 pm
- Location: Germany / Pforzheim
- Contact:
Re: cpu frequency scaling
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.
I installed the 'CPU Frequency Scaling Monitor' and switched from 'Ondemand' to 'Performance'. All is good now.
- raboof
- Established Member
- Posts: 1855
- Joined: Tue Apr 08, 2008 11:58 am
- Location: Deventer, NL
- Has thanked: 50 times
- Been thanked: 74 times
- Contact:
Re: cpu frequency scaling
Cool!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.
Added this check to the http://code.google.com/p/realtimeconfigquickscan/
Re: cpu frequency scaling
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.