[MLUG] Setting the cpu frequency permanently

Nick Nobody me at nikosapi.org
Sat Dec 27 00:42:15 EST 2008


Hello mluggers!

A long while ago I remember speaking with Jeremy regarding the "cpu MHz"
value reported in /proc/cpuinfo. We both shrugged off the fact that both
of our processors seemed to be throttled back slightly.

I recently built a media-center PC and noticed that XBMC (and
/proc/cpuinfo) reported that the 2GHz processor in the box was running at
1.2GHz even under heavy load. Upon looking into this further, it seems you
have to set a higher frequency manually, I came up with this script:

#!/bin/bash -x

cpus=/sys/devices/system/cpu/cpu[0-9]/cpufreq/

for cpu in $cpus; do
    cat "$cpu"/scaling_max_freq > "$cpu"/scaling_setspeed
done

To make sure this actually makes a difference I came up with a simple
benchmark and found that the benchmark ran 25% faster at the 2GHz setting.
Here's the benchmark if anyone is interested:

#!/usr/bin/env python

import time

max_fib = 35
tries = 5

def fib(i):
    if i in [0,1]: return i
    return fib(i-1)+fib(i-2)

t = time.time()
for i in range(tries): fib(max_fib)
print (time.time() - t)/float(tries)

It just prints the result of the average of 5 fibonacci number
calculations; crude, but it shows a significant difference.

My question is, is there a proper way to always make the processor run at
full speed (Ie. persist across reboots)? I know it's possible if you use a
cpu frequency control applet, but this system doesn't run a desktop
environment. Right now I just include the previously mentioned bash script
in an rc file, but I'd like the know the proper way (if there is a
standard way) to do it.

Thanks,

nick

P.S. If it matters, I'm using Ubuntu 8.10



More information about the mlug mailing list