Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Simple but effective ondemand CPUfreq governor tweak
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Wed May 11, 2011 9:31 am    Post subject: Simple but effective ondemand CPUfreq governor tweak Reply with quote

Since October last year the kernel (>=2.6.37) has a new tunable for the
ondemand CPUfreq governor called sampling_down_factor.

Quote from Documentation/cpu-freq/governors.txt:
Quote:
sampling_down_factor: this parameter controls the rate at which the
kernel makes a decision on when to decrease the frequency while running
at top speed. When set to 1 (the default) decisions to reevaluate load
are made at the same interval regardless of current clock speed. But
when set to greater than 1 (e.g. 100) it acts as a multiplier for the
scheduling interval for reevaluating load when the CPU is at its top
speed due to high load. This improves performance by reducing the overhead
of load evaluation and helping the CPU stay at its top speed when truly
busy, rather than shifting back and forth in speed. This tunable has no
effect on behavior at lower speeds/lower CPU loads.


If you set for example:
Code:
echo 200 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor

in your startup script, you'll get a nice speed boost especially during
the configuration phase of bigger projects.
The maximum value is 100000.

Here are the merge times for sys-libs/ncurses:
Code:
sampling_down_factor    merge time
1 (default)             1 minute and 59 seconds.
20                      1 minute and 47 seconds.
100                     1 minute and 29 seconds.
150                     1 minute and 24 seconds.
200                     1 minute and 22 seconds.
300                     1 minute and 20 seconds.
500                     1 minute and 12 seconds.
1500                    1 minute and 7 seconds.


To check the effect simply run:
Code:
watch -n.1 'cat /proc/cpuinfo|grep MHz'


Last edited by trippels on Fri Jul 22, 2011 12:41 pm; edited 3 times in total
Back to top
View user's profile Send private message
kimmie
Guru
Guru


Joined: 08 Sep 2004
Posts: 531
Location: Australia

PostPosted: Wed May 11, 2011 10:37 am    Post subject: Reply with quote

Thanks very much for that! My laptop has trouble playing HD video unless it's locked at full speed... until now I've been doing that manually, I believe you've just fixed that for me.
Back to top
View user's profile Send private message
albright
Advocate
Advocate


Joined: 16 Nov 2003
Posts: 2588
Location: Near Toronto

PostPosted: Wed May 11, 2011 1:54 pm    Post subject: Reply with quote

sampling_down_factor does not exist in my
/sys/devices/system/cpu/cpu0/cpufreq/ondemand

Code:

ls -l
total 0
-rw-r--r-- 1 root root 4096 May 11 09:45 ignore_nice_load
-rw-r--r-- 1 root root 4096 May 11 09:45 powersave_bias
-rw-r--r-- 1 root root 4096 May 11 09:45 sampling_rate
-r--r--r-- 1 root root 4096 May 11 09:45 sampling_rate_max
-r--r--r-- 1 root root 4096 May 11 09:45 sampling_rate_min
-rw-r--r-- 1 root root 4096 May 11 09:45 up_threshold


How do you enable this?
_________________
.... there is nothing - absolutely nothing - half so much worth
doing as simply messing about with Linux ...
(apologies to Kenneth Graeme)
Back to top
View user's profile Send private message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Wed May 11, 2011 2:03 pm    Post subject: Reply with quote

You need a 2.6.36 or newer kernel.
And the path is: /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
Back to top
View user's profile Send private message
theotherjoe
Guru
Guru


Joined: 22 Nov 2003
Posts: 393

PostPosted: Wed May 11, 2011 2:36 pm    Post subject: Reply with quote

Code:
localhost ~ # uname -a
Linux bigbuzz 2.6.36-gentoo-r8 #2 SMP PREEMPT Sat Apr 30 18:15:05 CEST 2011 x86_64 AMD Athlon(tm) II X4 630 Processor AuthenticAMD GNU/Linux
localhost ~ # cat  /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
cat: /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor: No such file or directory

so maybe it was introduced in 2.6.37...
Back to top
View user's profile Send private message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Wed May 11, 2011 2:40 pm    Post subject: Reply with quote

theotherjoe wrote:
Code:
localhost ~ # uname -a
Linux bigbuzz 2.6.36-gentoo-r8 #2 SMP PREEMPT Sat Apr 30 18:15:05 CEST 2011 x86_64 AMD Athlon(tm) II X4 630 Processor AuthenticAMD GNU/Linux
localhost ~ # cat  /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
cat: /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor: No such file or directory

so maybe it was introduced in 2.6.37...


Hm,
Code:
% git describe 3f78a9f7fcee0e9b44a15f39ac382664e301fad5
v2.6.35-7791-g3f78a9f

so it should be in 2.6.36...

Edit: Just double checked and you're right: it was introduced in 2.6.37.
Code:
 % git describe --contains 3f78a9f7fcee0e9b44a15f39ac382664e301fad5
v2.6.37-rc1~112^2~1
Back to top
View user's profile Send private message
albright
Advocate
Advocate


Joined: 16 Nov 2003
Posts: 2588
Location: Near Toronto

PostPosted: Wed May 11, 2011 3:46 pm    Post subject: Reply with quote

sorry, I should have noted my kernel
Code:
Linux gandalf 2.6.38-gentoo-r4 #2 SMP PREEMPT Mon May 9 08:15:02 EDT 2011 x86_64 Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz GenuineIntel GNU/Linux


But anyway, I was looking in the wrong directory, as you noted.

Got it now, and thanks!>
_________________
.... there is nothing - absolutely nothing - half so much worth
doing as simply messing about with Linux ...
(apologies to Kenneth Graeme)
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Tue Jun 14, 2011 10:28 pm    Post subject: Reply with quote

Quote:

cat /etc/conf.d/cpufrequtils
# /etc/conf.d/cpufrequtils: config file for /etc/init.d/cpufrequtils

# Options when starting cpufreq (given to the `cpufreq-set` program)
START_OPTS="--governor ondemand"

# Options when stopping cpufreq (given to the `cpufreq-set` program)
STOP_OPTS="--governor performance"

# Extra settings to write to sysfs cpufreq values.
#SYSFS_EXTRA="ondemand/ignore_nice_load=1 ondemand/up_threshold=70"
SYSFS_EXTRA="ondemand/sampling_down_factor=200"


a more elegant solution, then just add cpufrequtils to your runtime via rc-update
_________________
Quote:
Removed by Chiitoo
Back to top
View user's profile Send private message
albright
Advocate
Advocate


Joined: 16 Nov 2003
Posts: 2588
Location: Near Toronto

PostPosted: Wed Jul 20, 2011 5:44 pm    Post subject: Reply with quote

I tried this for a while now and -- for me at least -- there is a big
downside.

HD video plays extremely "choppy" with sound break-ups.

I'm not sure why this is happening, but when sampling_down_factor is
reset to 1, my videos play smooth.

(note this is on a notebook with 1.2ghz core 2 duo that downclocks to
800 mhz)
_________________
.... there is nothing - absolutely nothing - half so much worth
doing as simply messing about with Linux ...
(apologies to Kenneth Graeme)
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3920
Location: Hamburg

PostPosted: Wed Jul 20, 2011 5:54 pm    Post subject: Reply with quote

Do you compared the merge times of the 2nd and 3rd re-emerge of the same package ? Because emerging a package only 2 times in a row give false results due to file and/or compiler cache effects.
Back to top
View user's profile Send private message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Thu Jul 21, 2011 8:17 am    Post subject: Reply with quote

toralf wrote:
Do you compared the merge times of the 2nd and 3rd re-emerge of the same package ? Because emerging a package only 2 times in a row give false results due to file and/or compiler cache effects.


Yes, I've tested this more extensively a few weeks ago these were the results:
(ncurses merge times)
Code:

sampling_down_factor    merge time
1                       1 minute and 59 seconds.
20                      1 minute and 47 seconds. 
100                     1 minute and 29 seconds.
150                     1 minute and 24 seconds.
200                     1 minute and 22 seconds.
300                     1 minute and 20 seconds.
500                     1 minute and 12 seconds.
1500                    1 minute and 7 seconds.
Back to top
View user's profile Send private message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Thu Jul 21, 2011 9:09 am    Post subject: Reply with quote

albright wrote:
I tried this for a while now and -- for me at least -- there is a big
downside.

HD video plays extremely "choppy" with sound break-ups.

I'm not sure why this is happening, but when sampling_down_factor is
reset to 1, my videos play smooth.

(note this is on a notebook with 1.2ghz core 2 duo that downclocks to
800 mhz)


What kernel version are you running?
Because there was an important bug-fix in 2.6.39. Before the fix
the CPU frequency could accidentally be stuck at a low frequency
for a long time (depending on the sampling_down_factor).
(see commit 5cb2c3bd in the kernel git tree.)
That could explain your symptoms.
Back to top
View user's profile Send private message
albright
Advocate
Advocate


Joined: 16 Nov 2003
Posts: 2588
Location: Near Toronto

PostPosted: Thu Jul 21, 2011 11:07 pm    Post subject: Reply with quote

my kernel is:

2.6.39-pf4 #1 SMP PREEMPT
_________________
.... there is nothing - absolutely nothing - half so much worth
doing as simply messing about with Linux ...
(apologies to Kenneth Graeme)
Back to top
View user's profile Send private message
trippels
Tux's lil' helper
Tux's lil' helper


Joined: 24 Nov 2010
Posts: 137
Location: Berlin

PostPosted: Fri Jul 22, 2011 8:56 am    Post subject: Reply with quote

albright wrote:
my kernel is:

2.6.39-pf4 #1 SMP PREEMPT


Ah, ck messes with cpufreq.c.
Please try a vanilla kernel and see if your issue vanishes.
Back to top
View user's profile Send private message
tclover
Guru
Guru


Joined: 10 Apr 2011
Posts: 516

PostPosted: Fri Jul 22, 2011 1:19 pm    Post subject: Reply with quote

Hey, thanks trippels for this thread! I was having quite an issue recently with my desktop cpu being stucked at the lowest p-state while my laptop was stucked on the highest. I had and still have powersave as the default governor--I'll go for ondemand next time I build my kernels. With this trick and ondemand governor my issue vanish. I was looking for a solution only to find nothing. And anyway, I use kernel--2.6.3{8{-pf8,.8-zen},9-pf3}--with zcache (and cleancache) pach for .38*. I started, at first, suspecting zcache patch but it wasn't the culpirit. The weird thing is 38-pf8 without zcache worked great a few weeks before, the same goes for .39-pf*. As there were a few issues with BFS and such in .39, I decided to stick with .38! Actually, I have a few power profiles with hprofile but I did not bother until now to put a power profile in the init service. Now it's done! I won't bother changing it with on demand governor or change my powersave profile with ondemand governor.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum