paulv
Posts: 546
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Controlling the Power Consumption of RPi Models

Sun Jun 26, 2016 12:51 pm

When you need to run your RPi Model 2 or 3 on a battery or a cell for a period of time, the power consumption becomes an important element. The same is true if you don’t have a wall wart that can supply the energy needed for your RPi. (when you get the dreaded rainbow box on your display)

With the advent of these multiple core models, a job that will activate the maximum number of cores at the maximum clock speed can raise the power budget dramatically.

As an example, the standard Model 3 power budget can literally jump from an idling current of around 300mA to a whopping 780 mA. Running all 4 cores at 1.2GHz will more than double the energy requirement.

Adding power hungry USB devices will only make the total energy needed jump to figures that will be hard to satisfy with batteries and their needed controllers.

In my most recent design for an automatic power supply intended for embedded applications and/or remote locations, a battery (cell) backup was needed to prevent SD card corruption and to provide a UPS period with a graceful termination and automatic restart based on the availability of the main power.
Here is that post:
viewtopic.php?f=37&t=150358

I based that particular design on the Powerboost 1000c module from Adafruit that seems perfect for the job, unfortunately, the power budget it can provide is limited. The realistic current that can be supplied with a mains voltage present is about 1Amp while it is charging the cell, and without mains, while running on the boosted Lipo cell capacity, the maximum I measured is “only” 850mA.

Using a Model (1) A or B, or a Model A+ or B+ will function within this power budget, provided you do not attach any power hungry USB devices or the camera to it. You’ll probably want an internet connection, and my Edimax WiFi adapter consumes about 50-60mA and a LAN cable connection to a router about 60-70mA, both are within this power budget.

The Models 2B and 3B need some extra attention to make them work within these constraints. Obviously, you need to make a conscious decision to use any of these two models in an embedded application that needs battery backup. The other models maybe better suited, but if all you have is a hammer, everything looks like a nail, right?

There are few quite simple things that can be done to harness the power requirements of the RPi Model 2 and 3:
1. Reduce the number of cores that can be activated.
2. Lower the maximum clock speed for the core(s).
3. Lower the minimum clock speed for the core(s).
4. Change the scaling governor setting.
5. Drastic : Disable the LAN chip.

Let me elaborate my findings on all 5 possibilities.

1. Reduce the number of cores that can be activated.
Depending on your application needs, it is quite simple to reduce the number of active cpu’s or cores that can be activated by the kernel. The activation of the cores based on the required processing power needed is a dynamic process, unfortunately, you cannot change the active cores on the fly. It’s a static setting determined at boot time and set in the /boot/cmdline.txt file.
Just add the following to set the number of active cores :

Code: Select all

maxcpus=n 
where n can be 1, 2, 3, 4. If there is no maxcpus command on the command line, the default is 4 for the Model 2 and 3. I also observed that there is no accurate linear progression or correlation in energy from activating or de-activating the cores one by one. If you’re living on the edge, you have to measure the actual behavior.

A nice touch of the Raspi designers is that the number of active cpu's (core's) is shown by the number of Raspberry Pi logo's on the console.

2. Lower the maximum clock speed for the cores.
The clock speed the cores are running at are also playing a factor in the power budget. The faster the speed of the cpu is, the more energy is needed. The setting for this feature is done in /boot/config.txt. The default is 1.2Ghz for the Model 3B and 900MHz for the Model 2B, and can be set to another value by adding the following command:

Code: Select all

arm_freq=n 
where n is in MHz, and can start from 100, which is the lowest possible setting to the maximum over-clocking speed.

The current clock speed on a running RPi can be measured in several ways:

Code: Select all

vcgencmd measure_clock arm
It will show the result in Hz.
Another method is to use:

Code: Select all

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies
This will show you the minimum and maximum frequencies in KHz that will be used by the scaling governor, discussed below.
The maximum frequency can also be listed with:

Code: Select all

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
The maximum scaling frequency, as used by the governor, is :

Code: Select all

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
3. Lower the minimum clock speed for the cores.
The default low level of the clock speed is 600Mhz for the Model 3. This number can be lowered to a minimum of 100Mhz by the following command in /boot/config.txt :

Code: Select all

arm_freq_min=100 
This sets it to 100MHz, don’t use anything lower because the RPi won’t boot anymore.

The current minimum frequency can be listed with:

Code: Select all

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
The minimum scaling frequency, as used by the governor, is :

Code: Select all

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
4. Change the scaling governor setting.
In simple terms, the power/frequency scaling governor is a software kernel program that actually uses the above two min and max clock speeds, and based on the demand, switches the clock speed dynamically and either gradually or quickly, based on the processor load and the governor setting.

When the RPi has booted and starts to idle, the governor will lower the clock speed to the lower clock setting, and based on the governor setting and demands, will increase the clock speed to the maximum and back.

There are 5 different governor settings:
1. ondemand : default, moves speed from min to max and back at a % of load
2. conservative : gradually switch frequencies at % of load
3. userspace : use user specified frequencies
4. powersave : all cores set at minimum frequency
5. performance : all cores set at maximum frequency

I’m only going to cover 4 and 5 here, you can use Google (scaling governor) to find more details.

The good news is that the governor setting is dynamic, and you can change it on the fly. I suggest that you leave the default to “ondemand”, but that you change the setting to “powersave” as soon as the power supply detects a loss of the mains power and the RPi starts to run on the cell. The effect will be that the clock speed will go down to the minimum level. As soon as the main power comes back the program can set the governor back to ondemand. When the RPi is rebooted, the setting is back to ondemand again as well.

The current governor setting in effect can be obtained by:

Code: Select all

sudo cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
The governor can be set to any of the above 5 settings as follows:

Code: Select all

echo "powersave"| sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
Although it seems you are only setting the governor for cpu0, the setting is actually changing for all active cpu’s (as per maxcpus in /boot/cmdline.txt)

With a Model 3B, the power savings of reducing the clock speed can be considerable. With 4 cores, and a maximum (default) clock speed of 1.2GHz and a minimum of 100MHz, the power budget plummets from 780mA at a maximum load on all 4 cores to about 320mA. With only one active core, the current goes from about 430mA at 1.2GHz to about 300mA at 100MHz. The difference for a mostly idling RPi is not so great. The current goes from about 320-330mA to about 296 mA.

Note that the current figures I measured are all “about” because the current is fluctuating with the overall activity of the RPi. It can jump around quite a bit, so I made several observations over longer periods. It’s never going to be very stable or exact though, keep that in mind.

6. Disable the LAN chip.
If you need a drastic move, you can disable the LAN chip and since it controls the USB ports, they go as well. The LAN chip itself consumes about 70-80mA.
First you’ll need to find the device number of the DWC OTG Controller:

Code: Select all

dmesg –t | grep dwc_otg | grep DWC
It will return something like : 3f980000.usb, and this needs to be used in the following command:
NOTE
I suggest you put the following into a batch file or execute it all together (in one command line) with a sleep period and turning it back on because you’ll lose all abilities to communicate with the RPi. The only other way to get control back is to reboot it.

Code: Select all

echo 0 | sudo tee /sys/devices/platform/soc/3f980000.usb/buspower > /dev/null && 
sleep 20 &&
echo 1 | sudo tee /sys/devices/platform/soc/3f980000.usb/buspower > /dev/null
Conclusion
With some tuning and by making some power requirement measurements, it is perfectly possible to “wedge” a Model 2B or 3B into a reduced power budget.

The clock settings and the governor settings can also be used on the other RPi models, but with only one core, the results are not that dramatic.

I used sysbench (sudo apt-get install sysbench) with a prime calculation and various thread settings to put a load on the RPi cores, and I used a precise Voltage and Amp DMM to measure the energy consumption of the RPi.
I tested both the Model 2B and the Model 3B.

If you have experiences or something to contribute to aid in the understanding, please chime in!

Enjoy!

User avatar
GeekMike
Posts: 6
Joined: Mon Jun 27, 2016 8:42 pm

Re: Controlling the Power Consumption of RPi Models

Mon Jun 27, 2016 8:54 pm

Power states and Heartbeat signals communicated via GPIO pins.

We recognized the same potential power problems with SBC’s (Single Board Computers) like Raspberry. Our solution is simple: Create a power management controller to manage battery and computer uptime.

It works like this: When main power drops, a battery will provide power to the SBC and communicate to the SBC that main power is off via GPIO. When the battery degrades a GPIO pin communicates to the SBC that a reboot (power shut off) is imminent. Shortly after communicating a reboot to the SBC, power to the SBC is terminated.

Power to the SBC is turned on shortly after main power is restored, which will cause the SBC to start up. In addition to power management, we included an optional GPIO heartbeat from the SBC to indicate to the power controller that all is well with the SBC. If the heartbeat stops, power is cycled causing a reboot.

Small, easy to set up, and inexpensive - Our idea is patent pending. Let us know if you are interested.

paulv
Posts: 546
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlling the Power Consumption of RPi Models

Tue Jun 28, 2016 6:35 am

GeekMike,
Thank you for the plug to your product, but the link in my post already describes such a system for the DIY inclined forum users, and it is free of any patent issues.

In case you overlooked it, you can also use the "on-board" watchdog the SOC on the RPi, and in combination with the supply I described, you can create a pretty good fail-safe system. I described that here: viewtopic.php?f=37&t=150358

The idea of a separate or external hardware watchdog is not new. If you care to look at this much earlier post for a power supply that already uses such a hardware watchdog :
viewtopic.php?f=37&t=50470&start=25
This was posted in August 2013 and has been viewed more than 7.000 times so it can be found.
I came up with this part of the design myself, but in retrospect it is so simple that I'm 99% sure I was not the first one with that idea.
Don't spend your money on patent lawyers. Use Google, it's free.
Last edited by paulv on Tue Jun 28, 2016 10:37 am, edited 2 times in total.

User avatar
bensimmo
Posts: 3113
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Controlling the Power Consumption of RPi Models

Tue Jun 28, 2016 8:03 am

Isn't there a HDMI and other components WiFI\Bluetooth, Sound?
That can be turned off for power savings?

paulv
Posts: 546
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Controlling the Power Consumption of RPi Models

Tue Jun 28, 2016 8:44 am

Hi bensimmo,

Yes, you can turn off the HDMI plug.
sudo /opt/vc/bin/tvservice –o (or –p to turn it back on)
However that saves less than 10mA, but that may depend on the monitor and keyboard that is connected.

I measured the power requirements of my Dell monitor (1703FPs) connected to the HDMI interface and my Dell SK-8125 USB keyboard and the combined current was only 7mA. Normally, these two would not be connected to an embedded or remote application anyway.

As I mentioned in my post, you can also turn off the WiFi adapter network. (sudo /etc/init.d/networking stop) The amount of current you save depends on the amount of power the adapter needs to communicate with the router, and the country you are in (most countries limit/regulate the transmission power). The jump in (transmission) power while going from idling to doing a an apt-get update I measured to be about 70mA, but again depends on several factors. As an example, my RPi is less than 2 m. away from my router.

Stopping the network only saves the power from the transmitter/receiver part of the adapter, the adapter itself will still consume some power. Stopping the network on the idling Model 3 saved approx. 25mA and 20mA on the idling Model 2 with the Edimax.

You can also turn off the LAN chip that controls the LAN interface and the USB ports and for the Model 2, that is considerable because you turn off that chip (approx. 75mA) plus the approx. 50-70 mA from an Edimax USB WiFi adapter. I called that a drastic move in my post because you will lose all methods to communicate with the RPi Model 2.

Because the Model 3 has an on-board WiFi function, it will continue to work if you turn off the LAN chip, saving you approx. 75mA.

I hope that helps to put these savings in perspective with the hundreds of mA you can save by reducing the number of cpu's/core's and by limiting the maximum frequency. Although sluggish at the lowest 100MHz, everything is still fully functional. It all depends on your requirements and available power budget.

Enjoy!

southampton
Posts: 4
Joined: Mon Jul 16, 2018 5:51 pm

Re: Controlling the Power Consumption of RPi Models

Mon Jul 16, 2018 8:44 pm

Hi guys,

As you said before, there are 5 different governor settings:

1. ondemand : default, moves speed from min to max and back at a % of load
2. conservative : gradually switch frequencies at % of load
3. userspace : use user specified frequencies
4. powersave : all cores set at minimum frequency
5. performance : all cores set at maximum frequency.

When I consider all of them, you covered 4 and 5. I'm curious about the third section. Do you have a suggestion about userspace? Also, while doing the third section, can I manage my demand I developed. For example, when the camera is running, I run it according to the frequency value I gave.


**** it has done.. Thank you for interest

Yours Sincerely,
Southampton
Last edited by southampton on Tue Jul 17, 2018 12:31 am, edited 1 time in total.

drgeoff
Posts: 8442
Joined: Wed Jan 25, 2012 6:39 pm

Re: Controlling the Power Consumption of RPi Models

Mon Jul 16, 2018 9:55 pm

If GeekMike is applying for a US patent, the US Patent Office will grant almost anything that is not blindingly obvious even if prior art exists.

mosespi
Posts: 502
Joined: Mon May 12, 2014 3:35 pm
Location: 34,-118
Contact: Website

Re: Controlling the Power Consumption of RPi Models

Tue Jul 17, 2018 5:26 am

drgeoff wrote:
Mon Jul 16, 2018 9:55 pm
If GeekMike is applying for a US patent, the US Patent Office will grant almost anything that is not blindingly obvious even if prior art exists.
They very well might grant one, doesn't mean it is correct.

The 'inventor' of the hardware watchdog is likely no longer living. I would take a guess and say every critical electronic system humans have made in the last 50 years likely has a watchdog or supervisory circuit of some sort. Satellites, airplanes, and probably a modern toaster now has one too.

I have a product that does exactly what is described, almost word for word. I've been selling them for several years now.

Paulv has some good info.. all this power saving information in one post. Taking it one step further.. the best way to save the most power is to shut the Pi off when not needed and the turn it back on when you do, like a timer or something, which you can do with additional circui... WAIT A MINUTE!!! I got to go see someone about something!!!

Regards,
-Moses
Power problems? MoPower UPS for the Pi
http://www.allspectrum.com/mopower/

southampton
Posts: 4
Joined: Mon Jul 16, 2018 5:51 pm

Re: Controlling the Power Consumption of RPi Models

Tue Aug 14, 2018 8:44 am

Hi,

When I focus on available frequency steps, I just see 2 values ( 700MHz and 1200MHz ). I wanna multiply frequency values. For example, it has 400 MHz,600MHz, 800MHz, and 1000MHz, instead of 700 MHz and 1200MHz. I did not find how to increase the number of available frequency steps.

I look forward to hearing from you soon.

Cheers

Return to “Advanced users”

Who is online

Users browsing this forum: No registered users and 12 guests