cpu frequency scaling

Optimize your system for ultimate performance.

Moderators: khz, MattKingUSA

cpu frequency scaling

Postby raboof » Sat Jan 24, 2009 11:11 am

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/
raboof
Establlshed Member
 
Posts: 1293
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL

Re: cpu frequency scaling

Postby studio32 » Sat Jan 24, 2009 11:33 am

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!
User avatar
studio32
Establlshed Member
 
Posts: 2361
Joined: Mon Apr 07, 2008 5:09 pm

Re: cpu frequency scaling

Postby studio32 » Mon Jan 26, 2009 9:56 am

I think mine looks fine, with my 2.8

Code: Select all
$  more /proc/cpuinfo | grep MHz
cpu MHz         : 2793.065
User avatar
studio32
Establlshed Member
 
Posts: 2361
Joined: Mon Apr 07, 2008 5:09 pm

Re: cpu frequency scaling

Postby Jiyunatori » Mon Jan 26, 2009 4:44 pm

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
Jiyunatori
Establlshed Member
 
Posts: 7
Joined: Mon Jan 26, 2009 9:46 am

Re: cpu frequency scaling

Postby philip888 » Wed Jan 28, 2009 5:41 am

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
User avatar
philip888
Establlshed Member
 
Posts: 14
Joined: Sun Aug 03, 2008 7:39 pm
Location: Utah,USA

Re: cpu frequency scaling

Postby thorgal » Wed Jan 28, 2009 9:31 am

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 ...
thorgal
Establlshed Member
 
Posts: 739
Joined: Mon Apr 07, 2008 6:04 pm

Re: cpu frequency scaling

Postby Jiyunatori » Wed Jan 28, 2009 10:15 am

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
Jiyunatori
Establlshed Member
 
Posts: 7
Joined: Mon Jan 26, 2009 9:46 am

Re: cpu frequency scaling

Postby philip888 » Wed Jan 28, 2009 5:00 pm

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
User avatar
philip888
Establlshed Member
 
Posts: 14
Joined: Sun Aug 03, 2008 7:39 pm
Location: Utah,USA

Re: cpu frequency scaling

Postby Yeri » Thu Jan 29, 2009 5:08 pm

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.
User avatar
Yeri
Establlshed Member
 
Posts: 158
Joined: Tue Dec 09, 2008 6:33 pm
Location: Spain

Re: cpu frequency scaling

Postby studio32 » Fri Jul 23, 2010 5:32 pm

User avatar
studio32
Establlshed Member
 
Posts: 2361
Joined: Mon Apr 07, 2008 5:09 pm

Re: cpu frequency scaling

Postby AutoStatic » Fri Jul 23, 2010 9:59 pm


chmodding stuff in the /sys directory to get things to work? Not the way to do it if you ask me.
User avatar
AutoStatic
Establlshed Member
 
Posts: 1665
Joined: Wed Dec 09, 2009 5:26 pm
Location: Beverwijk, The Netherlands

Re: cpu frequency scaling

Postby SR » Sat Jul 24, 2010 12:45 am

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
SR
Establlshed Member
 
Posts: 211
Joined: Wed May 07, 2008 6:01 pm
Location: Houston, Tx

Re: cpu frequency scaling

Postby Scary Hallo » Sat Jul 24, 2010 1:38 pm

Thank you for this article. This helps to solve my problem with xruns (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
User avatar
Scary Hallo
Establlshed Member
 
Posts: 229
Joined: Fri Oct 23, 2009 2:21 pm
Location: Germany / Pforzheim

Re: cpu frequency scaling

Postby raboof » Sat Jul 24, 2010 2:24 pm

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/
raboof
Establlshed Member
 
Posts: 1293
Joined: Tue Apr 08, 2008 11:58 am
Location: Deventer, NL

Re: cpu frequency scaling

Postby morko » Mon Jul 26, 2010 12:49 pm

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. ;)
morko
Establlshed Member
 
Posts: 45
Joined: Thu Mar 25, 2010 8:08 am
Location: Finland

Next

Return to System Tuning and Configuration

Who is online

Users browsing this forum: No registered users and 1 guest