6

I want to reduce the frequency of operation of my raspberry pi without rebooting. Is there a way to do it ??

I know I can change the frequency by changing the config.txt but it requires a reboot.

2
  • 1
    Why would you want to do this? Mar 16 '15 at 23:40
  • I am trying to do dynamic frequency scaling on my own , based on workload
    – maverick
    Mar 18 '15 at 0:03
12

cpufreq can do this for you.

On Raspbian: sudo apt-get install cpufrequtils

On Arch: sudo pacman -S cpufrequtils

You can then use cpufreq-info to see your settings and cpufreq-set to change them.

On my Pi B using Arch, without tweaking any config.txt clock settings at all, here are the defaults I see available:

> cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 355 us.
  hardware limits: 700 MHz - 800 MHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 700 MHz and 800 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 700 MHz.

On my Pi2 (also Arch):

> cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: BCM2835 CPUFreq
  CPUs which run at the same hardware frequency: 0 1 2 3
  CPUs which need to have their frequency coordinated by software: 0 1 2 3
  maximum transition latency: 355 us.
  hardware limits: 600 MHz - 900 MHz
  available frequency steps: 600 MHz, 900 MHz
  available cpufreq governors: conservative, userspace, powersave, ondemand, performance
  current policy: frequency should be within 600 MHz and 900 MHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz.
analyzing CPU 1:
# same info repeated for other 3 cores

Example changing governor policy to force higher/lower frequencies:

> sudo cpufreq-set -g powersave
> cpufreq-info| grep "current CPU" | head -1
  current CPU frequency is 600 MHz.
> sudo cpufreq-set -g performance
> cpufreq-info| grep "current CPU" | head -1
  current CPU frequency is 900 MHz.

I set and leave mine to "ondemand".

By editing your config.txt, you should be able to set a lower minimum frequency, though that would require a reboot to take effect the first time. From then out you could use the cpufreq utils to adjust up or down (or ondemand) as you like.

2
  • A well-written summary. I would think this post would be of particular interest to owners of RPi 3B+ units who live in warm climates :)
    – Seamus
    May 4 '18 at 1:09
  • 1
    See the RPi overclocking docs for the entries you need to add to /boot/config.txt
    – Bim
    Mar 3 '19 at 22:13
4

Try this (no need for cpufrequtils):

echo 700000 | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq

Depends a little which Raspberry Pi you are using, but most can only step between min (600000) and max.

RPI Zero: 700000 - 1000000
RPI:      700000
RPI2:     600000 -  900000
RPI3:     600000 - 1200000
RPI3+:    600000 - 1400000
RPI4:     600000 - 1500000

What I've seen setting anything in between will limit to the minimum.

You can check min and max:

HW DEFAULT
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq

USER SET
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq

This is preventing your Pi from running to hot. Of course it's slower.

2

Building a bit on the answer by Janghou, the following files in the sysfs dir for cpu0 (first core of the CPU, whether single core or multi-core) /sys/devices/system/cpu/cpu0/cpufreq/ are of interest too:

  • affected_cpus and related_cpus - This should be all the cores of the Pi's CPU (these make more sense with servers with multiple multi-core CPUs and complex cpufreq configuration, rather than RasPi):

    samveen@pi4:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/affected_cpus 
    0 1 2 3
    samveen@pi4:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/related_cpus 
    0 1 2 3
    
    pi@pi0:~ $ cat /sys/devices/system/cpu/cpu0/cpufreq/affected_cpus
    0
    pi@pi0:~ $ cat /sys/devices/system/cpu/cpu0/cpufreq/related_cpus
    0
    
  • scaling_governor - the scaling governer in use:

    pi@pi0:~ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
    ondemand
    
    samveen@pi4:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 
    ondemand
    
  • scaling_available_frequencies - as the name suggests:

    samveen@pi4:~$ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
    600000 750000 1000000 1500000 
    
    pi@pi0:~ $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
    700000 1000000 
    
  • scaling_min_freq and scaling_max_freq - limits on scaling (should match available frequencies)

  • scaling_cur_freq and cpuinfo_cur_freq - what the CPU is running at, and should match each other.

  • scaling_setspeed - finally write to this to set the speed. However, the governor may change this upwards or downwards depending on it's configuration, so it might be worthwhile to either dig into the configuration of the governor, or do a quick and dirty hack by limiting it by setting a lower value of scaling_max_freq.

Finally, all this and more is covered under the cpufreq documentation of the linux kernel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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