I want to change the default governor on my pi from ondemand to performance. Is there a way of doing this?

up vote 14 down vote accepted

I don't think you can change the default without recompiling the kernel. By that I mean, the one the kernel chooses when booted up.

However, you can tell it to use a different governor while running, so if you want to effectively set the default without recompiling, you can add something to /etc/rc.local or some other start-up script.

The /sys directory is not on disk; it's an in RAM fake filesystem that is actually an interface for getting information from and sending commands to the kernel. This is all relative to /sys/devices/system/cpu, so:

> cd /sys/devices/system/cpu

You also need to be root to do the writes (echo blahblah >). Anyway, relative to the above directory, to see the available governors:

> cat cpu0/cpufreq/scaling_available_governors
conservative ondemand userspace powersave performance

Apparently yours is ondemand (but read "Gotcha" below about this); to check:

> cat cpu0/cpufreq/scaling_governor
ondemand

To change it:

echo performance > cpu0/cpufreq/scaling_governor

Note this either has to be done root, or like this

sudo sh -c "echo performance > cpu0/cpufreq/scaling_governor"

Just plain sudo will not work because there is a redirect, >.

You'll now notice the /sys/devices/system/cpu/cpufreq directory, (NOT the same as /sys/devices/system/cpu/cpu0/cpufreq!), which formerly contained filehandles for configuring the ondemand governor, is empty.


Gotcha...

On Raspbian there is an init script, the confusingly named raspi-config (no, it has nothing to do with the other one, which is run on first boot by the also confusingly named apply_noobs_os_config.sh), which uses this technique to set the governor to ondemand unless the shift key is held down (the stock Raspbian kernel has powersave compiled in). It doesn't do anything else, so it is safe to disable this (systemctl disable raspi-config), or you could edit it as per Gorkamorka's answer, but then you run the risk of having it un-edited by a system update, etc. -- who knows what anyone plans to do with that.

You could try adding the non-sudo version above to /etc/rc.local. This may happen after the raspi-config script has exited.

  • Comments are not for extended discussion; this conversation has been moved to chat. – goldilocks May 27 '17 at 14:40
  • 1
    Rather then require switching to root, just use tee: echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor. – Fake Name Jun 12 '17 at 22:58
  • 1
    Other way : sudo sh -c "echo performance > cpu0/cpufreq/scaling_governor" – Moonchild Mar 19 at 22:17

similar question on RPi stack exchange here.

to paraphrase it, the on demand speed bumps up to max when cpu is at 95% busy. You can lower the amount of busy time to a lower percentage (meaning it'll be clocked higher when not as busy) by:

"writing an integer value to a file (you can put the following for example in the /etc/rc.local startup file): echo 60 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold"

so, theoretically...you could put this percentage at something incredibly low like 10 or 5, which would mean it would always be running at max.

Hope this helps. Be sure to up score the person who posted this in the linked article!

  • 3
    That's not actually an answer to the question, "how do I change the governor from ondemand to performance (they are two different governors). – goldilocks Aug 16 '13 at 6:30
  • @goldilocks I thinks this answer still adds something useful to the quesiton since it explains how to make the one behave like the other. – Dmitry Grigoryev Sep 8 '16 at 15:08

An alternative solution (if you are running Raspbian) could be to modify the init.d script in /etc/init.d/raspi-config to always disable the scaling governor. It's default behavior is to only enable it at startup if one of the shift-keys is being pressed down:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          raspi-config
# Required-Start: udev mountkernfs $remote_fs
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Switch to ondemand cpu governor (unless shift key is pressed)
# Description:
### END INIT INFO

. /lib/lsb/init-functions

case "$1" in
  start)
    log_daemon_msg "Checking if shift key is held down"
    timeout 1 thd --dump /dev/input/event* | grep -q "LEFTSHIFT\|RIGHTSHIFT"
    if [ $? -eq 0 ]; then
      printf " Yes. Not enabling ondemand scaling governor"
      log_end_msg 0
    else
      printf " No. Switching to ondemand scaling governor"
      SYS_CPUFREQ_GOVERNOR=/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor      if [ -e $SYS_CPUFREQ_GOVERNOR ]; t
hen
        echo "ondemand" > $SYS_CPUFREQ_GOVERNOR
        echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
        echo 100000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
        echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
        echo 1 | sudo tee /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy
      fi
      log_end_msg 0
    fi
    ;;
  *)
    echo "Usage: $0 start" >&2
    exit 3
    ;;
esac

I made a small programm to change it and let it be changed every boot by automatically creating an init.d script.

Link to my project

echo "performance" |sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

  • While this may answer the question, good answers require more information than you have provided here. Also, your answer does not anything that the above answers have not already provided. – Steve Robillard Sep 8 '16 at 15:56

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.