Timely tips for speeding up your Raspberry Pi


Running sensitive hardware outside of its specification is never easy. In the first revision of the Pi, for example, a single overclocking attempt irreversibly changed a bit in the processor – and voided the warranty in the process. Meanwhile, the makers of the Raspberry have learned from their mistakes and allow overclocking within certain limits. If you go beyond these limits, however, you void your warranty.

Overclocking speeds up the Rasp Pi's clock to make it execute more instructions in a given time frame. (Actually, the Rasp Pi does not explicitly have one system clock, but rather several interdependent clocks. For each clock, a configuration constant appears in the /boot/config.txt file.)

For example, the arm_freq is for the CPU frequency, core_freq for the overall system clock, and sdram_freq for the main memory clock. The eLinux wiki provides details on this and other constants [3]. The main reference points are arm_freq and core_freq.

You can modify the /boot/config.txt configuration file with the text editor of your choice or – more easily – using the raspi-config configuration utility. The Overclocking menu item defines several levels. Not all of them will work because the upper limit depends on the hardware – in particular on production variants, connected components, and the power supply. You have to gradually work your way up to the optimum.

Even if you ultimately modify the configuration manually, you should configure overclocking once beforehand with raspi-config. The raspi-config utility not only modifies the system clocks but also enables the OnDemand governor Linux system component. The OnDemand governor monitors the system clock, and without it, the frequency stays at the fixed set value. Additionally, you need to set the force_turbo 1= switch in /boot/config.txt; otherwise, you will see nothing of the higher CPU clock speed: The governor only overclocks when needed.

The default limit in the Raspbian image is 95 percent load. To change this limit, you can write the new limit to the appropriate control file, as root, preferably from /etc/rc.local during system startup. To do so, add the following line:

echo 60 > /sys/devices/system/cpu/ cpufreq/ondemand/up_threshold

If the Raspberry Pi then fails to boot, you need to edit the file on the SD card using another computer. If you are not running your Rasp Pi in headless mode, an alternative is to hold down the Shift key during the boot process. (Headless mode means without a keyboard and monitor. The Rasp Pi is accessed remotely in headless mode using SSH.)

Risks and Side Effects

A higher CPU clock speed also causes the Rasp Pi to heat up faster. Without overclocking, the temperature in the case is typically around 50 degrees Celsius. A small script by the name of cpustatus.sh [4] outputs the current status of the processor (Figure 3).

Figure 3: Output from cpustatus.sh on the console informs the user about the current CPU state.

However, if you want more than just a snapshot, you might prefer to call the script from Listing 2 in your /etc/rc.local file. Every 60 seconds, it sends the current temperature and the CPU frequency to Ganglia (Figure 4).

Listing 2

Logging the Temperature

( while true; do
  gmetric -n temp \
          -v `sed -e "s/\(^..\)/\1\./" "$TEMP_FILE"`\
          -t float \
     -u Celsius \
     -x "$INTERVAL" \
     -g other \
     -D "Temperature of `hostname`" \
     -T "Temperature"
  freq gmetric n.
          -v `sed -e "s/\(^...\)/\1\./" "$FREQ_FILE"`\
          -t float \
     -u MHz \
     -x "$INTERVAL" \
     -g other \
     -D "CPU frequency of `hostname`" \
     -T "CPU Frequency"
   sleep "$INTERVAL"
done ) &
Figure 4: Ganglia displaying the temperature and CPU frequency under load.

A little stress test shows the effects of overclocking: To honor the Raspberry Pi, I decided to compute the number pi to 3,400 decimal places. To do this, I installed the bc command-line calculator, which supports arbitrarily precise computations:

$ bc -l <<< "scale=3400; 4*a(1)"

This example computes pi with the well-known formula 4*arctan(1). The computation overhead is equivalent to about 100 seconds of computing time on my Rasp Pi without overclocking. It increases the temperature on average by around two and a half degrees. With some overclocking (Modest setting in raspi-config), the computation takes only 85 seconds, but the temperature rises for a short time by nearly five degrees.

If you think the temperature rise is too critical, you can kit your Rasp Pi out with small heat sinks. A set of three heat sinks for the CPU, voltage regulator, and LAN/USB controller costs around EUR 10 (US$ 7.50). A prolonged stress test showed that the alignment of the Rasp Pi housing has much more of an effect on the temperature. Annoyingly, the vents face downward in the standard packages, so the heat builds up underneath the Pi. However, simply turning the case on its side in our lab caused the temperature to drop by nearly 10 degrees.

A test using the industry-standard Linpack benchmark [5] showed an increase from 44MFLOPS without overclocking to 66MFLOPS for arm_freq=1000 and core_freq=400. When I tried to set core_freq=500 in raspi-config, the Pi just froze. Computing pi and using Linpack both test the floating point processing power, which only plays a minor role in normal operation. That said, the numbers are probably similar for integer performance, which means that under favorable conditions, a performance increase of up to 50 percent might be possible.

How stable the hardware and software are with a permanently overclocked CPU is something you need to test yourself. However, an eLinux.org wiki page [3] points out that the SD card driver can run into trouble with overclocked CPUs – after days or weeks, you can expect the filesystem to be corrupted. This problem seemingly only occurs in newer kernels; version 3.6.11 from the current Raspbian distributions is not affected. You can also configure the Raspberry Pi to just boot from the SD card and otherwise use a USB storage medium [6].

The overclock stability test from the eLinux.org wiki is not really suitable: Even without overclocking, the program triggers memory allocation errors, which then appear in the system log /var/log/messages. This seems to be a fundamental problem with the Raspbian kernel – in normal operation or hard drive tests with bonnie++, the error never occurred.

Incidentally, overclocking has proved very useful on my own Pi; the system responds noticeably faster. Because the clock only rises briefly in times of high demand, I do not have a permanent thermal problem.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content