Setting a default CPU Frequency in Ubuntu?

5

3

How do I get Ubuntu to select a default cpufreq on boot? These are the frequencies my CPU has available:

$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
2300000 2200000 2000000 1800000 1000000

I want 2200000 set as default. I have learnt that running the following command will do just that:

$ cpufreq-selector -f 2200000

My question is how do I get that to run on boot and stay default?

Jim

Posted 2009-08-12T13:37:23.347

Reputation:

4

This is a question for http://www.superuser.com/

– Ricket – 2009-08-12T13:39:33.920

I agree. voting to close – None – 2009-08-12T13:41:08.880

1

Also, to answer Jim's question: http://embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/

– None – 2009-08-12T13:41:57.803

You should change the title to something more appropriate. – None – 2009-08-12T14:41:15.597

Why? You get the best results with the default ondemand policy. – psusi – 2012-04-12T14:05:17.720

Answers

6

The correct way to do this in Ubuntu is:

  • Copy /etc/init.d/skeleton to scriptname and edit it to your needs.
  • Make it executable.
  • Install your script into the Debian runlevels via this command.

sudo update-rc.d scriptname defaults

  • Check that links to your script exist in other runlevels, e.g rc2.d, rc3.d. You can also confirm that this script is properly installed through the Administration->Bootup Manager GUI.

Check /etc/init.d/README for more detailed instructions and links to the specification document. You can also impose finer control over which run-levels your scripts runs on, and the priority it should get called at:

$ sudo update-rc.d dummy defaults
 Adding system startup for /etc/init.d/dummy ...
   /etc/rc0.d/K20dummy -> ../init.d/dummy
   /etc/rc1.d/K20dummy -> ../init.d/dummy
   /etc/rc6.d/K20dummy -> ../init.d/dummy
   /etc/rc2.d/S20dummy -> ../init.d/dummy
   /etc/rc3.d/S20dummy -> ../init.d/dummy
   /etc/rc4.d/S20dummy -> ../init.d/dummy
   /etc/rc5.d/S20dummy -> ../init.d/dummy
$ sudo update-rc.d -f dummy remove
 Removing any system startup links for /etc/init.d/dummy ...
   /etc/rc0.d/K20dummy
   /etc/rc1.d/K20dummy
   /etc/rc2.d/S20dummy
   /etc/rc3.d/S20dummy
   /etc/rc4.d/S20dummy
   /etc/rc5.d/S20dummy
   /etc/rc6.d/K20dummy

$ sudo update-rc.d -n -f dummy start 20 2 3 4 5 .
 Adding system startup for /etc/init.d/dummy ...
   /etc/rc2.d/S20dummy -> ../init.d/dummy
   /etc/rc3.d/S20dummy -> ../init.d/dummy
   /etc/rc4.d/S20dummy -> ../init.d/dummy
   /etc/rc5.d/S20dummy -> ../init.d/dummy
$ sudo update-rc.d -n -f dummy stop 20 0 6 .
 Adding system startup for /etc/init.d/dummy ...
   /etc/rc0.d/K20dummy -> ../init.d/dummy
   /etc/rc6.d/K20dummy -> ../init.d/dummy

Edit: The first step initially said to follow a template I provided with the answer, but I later realized that a standardized template exists so I've modified the answer accordingly.

user4358

Posted 2009-08-12T13:37:23.347

Reputation:

5

(UBUNTU 9.10) There is already a script titled "ondemand" in the init.d that sets the cpu frequency, and if yours is not set after it does it's magic then yours will not work. An easy fix is if you edit the line that says "echo -n ondemand > $CPUFREQ" and change ondemand to powersave it will save you the headache of making your own.

BGiacoletto

Posted 2009-08-12T13:37:23.347

Reputation:

Or disable ondemand on startup and copy it to a new name appropriate to your situation and then enable that one. – MT. – 2010-03-16T04:29:34.253

do this: sudo update-rc.d ondemand defaults – Hendy Irawan – 2011-08-26T12:11:29.567

Powersave doesn't actually save power, and often uses more than ondemand. – psusi – 2012-04-12T14:06:45.427

1

On a simple case like this one I would add a line with the command to /etc/rc.local, before the "exit 0".

For more complex init scripts, follow nagul answer.

juanjux

Posted 2009-08-12T13:37:23.347

Reputation: 240

0

Write a script to execute your command, then put the script in your /etc/init.d directory.

It'll then be run at startup

Glen

Posted 2009-08-12T13:37:23.347

Reputation: 241

Scripts in /etc/init.d are not automatically executed. – Johan Boulé – 2012-09-10T00:14:20.757

0

Follow the steps:

1. edit /etc/rc.local :  sudo gedit /etc/rc.local
2. add the line berofe exit 0:  cpufreq-selector -f 2200000 [add sudo if it need]
3. save the file and exit
4. you can run the for current session : sudo /etc/rc.local
5. From next session this script will automatically run

shantanu

Posted 2009-08-12T13:37:23.347

Reputation: 111