Category:How to - Low Power

From Gumstix User Wiki
Revision as of 14:43, 7 March 2011 by Maroc (Talk | contribs) (DVFS: First attempt to fill in DVFS section.)

Jump to: navigation, search

Status

This page is a work in progress. Many users are running Gumstix COMs in power sensitive applications and need to reduce power consumption as much as possible. This page is being developed by the Gumstix community as the steps are learned for reducing power.

Relevant Community Mailing List Threads

sample numbers for Overo Earth COM power consumption

Building a linux omap3 pm for Overo

cpufreq on the Overo

Background

The default omap3 openembedded build does not provide an optimal setup for power reduction on Gumstix Overo COMS. In order to achieve the lowest power possible for your application, you have to perform a combination of the following:

  • Use the latest OMAP Power Management (pm) kernel branch
  • Enable power saving features such as sleep when idle, off mode, and dvfs
  • Disable internal OMAP devices
  • Hold unused external chips such as USB, Wifi, Bluetooth, etc. in reset
  • Turn off unused LEDs

PM Kernel

The PM kernel is a development branch of the linux-omap kernel focused on developing the power management features of OMAP. By default, openembedded does not use the PM kernel, but instead uses the mainstream linux-omap kernel. Many of the changes of the PM branch have been merged to the mainstream linux-omap branch. However, not all changes have been merged so you must manually configure openembedded to use the PM kernel instead of the mainstream branch.

Compile PM Kernel

NOTE: The linux-omap-pm bitbake recipe is setup to use the 2.6.29 PM kernel. This kernel is significantly older than the 2.6.36 mainstream linux-omap kernel available in the open embedded build. The 2.6.36 linux-omap kernel contains many of the changes in the 2.6.29 PM branch. However, the most recent 2.6.36 PM kernel has additional features for power saving. You must follow the alternate method below to use the most recent PM kernel.

TODO: Figure out how to update recipe for latest PM branch.

To enable the PM kernel edit the file

org.openembedded.dev/conf/machine/overo.conf

and change the line

PREFERRED_PROVIDER_virtual/kernel = "linux-omap3"

to

PREFERRED_PROVIDER_virtual/kernel = "linux-omap-pm"

Save the changes and then run bitbake as usual e.g.

$ bitbake omap3-console-image

The pm branch will be downloaded and compiled.

Once you have the PM kernel built, follow the instructions for copying the new image and filesystem to your microSD card.

PM Kernel Alternate Method

There is an alternate method for building the omap-pm kernel taken from Peter Lawrence on the Gumstix mailing list.

NOTE: As per the comments below, this method disables nand and microSD access.

TODO: See how to get nand and microSD working with the latest PM kernel.


Here are steps to build the kernel "the traditional way".

1) Download and install cross-compiler tools:

The easiest solution is to download the CodeSourcery binaries:

http://www.codesourcery.com/sgpp/lite/arm

CodeSourcery provides an install program.  (You'll have to set the 
executable bit on the file to run it.)

Note that the CodeSourcery install modifies .bash_profile to add the
path, but this file does not run automatically in Ubuntu.  To fix
this, refer to:

http://www.linuxquestions.org/questions/linux-general-1/do-i-put-path-in-bash_profile-or-bashrc-or-both-540288/

which says:

"You can change the second by opening a gnome-terminal window and
going to Edit / Profiles - select the Default profile and click the
Edit button. On the Title and Command tab, click the check box for Run
command as a login shell. Your .bash_profile file should be sourced
the next time you open a gnome-terminal."

2) Get latest Linux OMAP PM code

"git" the latest code:

git clone git://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-omap-pm.git

The result will be in the subdirectory "linux-omap-pm".

3) Build the OMAP3_PM Linux Kernel

Extract the download Linux kernel code and cd to that directory.  The
command sequence is:

export ARCH=arm
make omap3_pm_defconfig

This creates a .config file suitable for Linux OMAP3 PM.

TBD: patch the .config file for JFFS2 and SD card

export CROSS_COMPILE=arm-none-eabi-
make uImage [this takes a very long while]

The resultant kernel file will be in: ./arch/arm/boot/uImage

4) Download the initramfs filesystem

Obtain "rd-ext2-8M.bin" from:

http://code.google.com/p/beagleboard/downloads/list

5) Create a bootable MicroSD card

Follow the [http://www.gumstix.net/Setup-and-Programming/view/Overo-Setup-and-Programming/Creating-a-bootable-microSD-card/111.html instructions here].

However, one can omit the "MLO" and the "u-boot.bin" files.

One should, however, copy over the "uImage" file created in step #3,
and the "rd-ext2-8M.bin" (as "rd-ext2.bin") created in step #4.

6) Boot the Overo

Use the "Press any key" prompt at boot to operate the U-Boot app.

Enter the following commands: (these commands must be done individually,
as U-Boot does not have a large enough buffer for the entire quantity
to be pasted at once)

mmc init
fatload mmc 1:1 0x80300000 uImage.pm
fatload mmc 1:1 0x81600000 rd-ext2.bin
setenv bootargs console=ttyS2,115200n8 ramdisk_size=8192
root=/dev/ram0 rw rootfstype=ext2 initrd=0x81600000,8M
bootm 0x80300000

 TBD: change u-boot parameters to perform this automatically

 Linux should boot to a BusyBox console prompt.
 

PM Features

For a full list of PM features see OMAP Power Management. The features listed here are the most common needed to reduce power.

Setup Debug FS

Before you can enable PM features, you need to setup the debug file system for manipulating pm configuration.

mkdir /debug
mount -t debugfs debugfs /debug

Sleep While Idle

Next, enable "sleep while idle". This will allow the processor to attempt deeper sleep states when idle. You must also enable sleep timeouts for the serial ports, otherwise this will result in increased power consumption.

$ echo 5 > /sys/devices/platform/serial8250.0/sleep_timeout
$ echo 5 > /sys/devices/platform/serial8250.1/sleep_timeout
$ echo 5 > /sys/devices/platform/serial8250.2/sleep_timeout 
$ echo 1 > /debug/pm_debug/sleep_while_idle

You can also enable "off mode" after enabling "sleep while idle".

$ echo 1 > /debug/pm_debug/enable_off_mode 

NOTE: Enabling sleep when idle will cause the device to "miss" the first character or two from the serial console (and most likely all UARTS). Since the UART is asleep, a character must be sent to wake it up. This character will be missed as well as subsequent characters until the UART is fully awake.

DVFS

Dynamic frequency and voltage scaling dynamically reduces clock frequency and voltage for further power savings. You must be running the PM kernel for DVFS functionality.

The cpufreq utils and daemon are needed to enable and configure DVFS. Use bitbake to manually build cpufreqd and cpufrequtils.

$ bitbake cpufreqd
$ bitbake cpufrequtils

You can also place these dependencies in your user config recipie....TODO

Once the cpufreqd and cpufrequtils are built, you can build your image as normal, or you can simply copy the ipk files to your SD card and install them.

$ cp tmp/deploy/glibc/ipk/armv7a/cpufreqd_* tmp/deploy/glib/ipk/armv7a/cpufrequtils_* /media/SD_CARD/home/root/

To install, run the following command from your Overo COM:

# opkg install /home/root/cpufreq*.ipk

You may see some errors about a "hicolor-icon-theme" which can be ignored.

Now that you have cpufreq tools setup, run cpufreq-info and you will see output describing the cpu frequency modes for your cpu.

root@overo:~#cpufreq-info
cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: omap
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.00 ms.
  hardware limits: 125 MHz - 600 MHz
  available frequency steps: 600 MHz, 550 MHz, 500 MHz, 250 MHz, 125 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 125 MHz and 600 MHz.
                  The governor "performance" may decide which speed to use
                  within this range.
  current CPU frequency is 600 MHz (asserted by call to hardware).
  cpufreq stats: 600 MHz:100.00%, 550 MHz:0.00%, 500 MHz:0.00%, 250 MHz:0.00%, 125 MHz:0.00%  (1)

As you can see from the cpufreq stats line, we have run at full speed 600 MHz for 100% of the time. In order to reduce cpu frequency automatically, we have to change to a different "governor". For example, switching to the powersave governor will limit cpu frequency to between 0% and 33% of max speed.

root@overo:~# cpufreq-set -g powersave
root@overo:~# cpufreq-info
cpufrequtils 006: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: omap
  CPUs which run at the same hardware frequency: 0
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 0.00 ms.
  hardware limits: 125 MHz - 600 MHz
  available frequency steps: 600 MHz, 550 MHz, 500 MHz, 250 MHz, 125 MHz
  available cpufreq governors: conservative, ondemand, userspace, powersave, performance
  current policy: frequency should be within 125 MHz and 600 MHz.
                  The governor "powersave" may decide which speed to use
                  within this range.
  current CPU frequency is 125 MHz (asserted by call to hardware).
  cpufreq stats: 600 MHz:86.17%, 550 MHz:0.00%, 500 MHz:0.00%, 250 MHz:0.00%, 125 MHz:13.83%  (2)

The cpufreq daemon automatically switches governors based on rules defined in

/etc/cpufreqd.conf

TODO: Examine how to use cpufreqd to manage the active governor.

Disable Internal Devices

The internal peripherals and devices such as the DSP and GPU consume power if not being used. All unused peripherals, DSP, and GPU should be turned off.

Turn Off Peripherals

TBD

Turn Off DSP

This section applies only to the OMAP3530-based Overo COMs, as the OMAP3530 has both a DSP and Graphics engine.

TBD

Turn Off GPU

This section applies only to the OMAP3530-based Overo COMs, as the OMAP3530 has both a DSP and Graphics engine.

TBD

Disable External Chipsets

Several external chipsets on the Gumstix COM consume power even if not being used. Their power consumption can be reduced (although not completely eliminated) by holding the chips in reset.

USB

You can hold the USB chip in reset with the following commands:

$ echo 183 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio183/direction
$ echo 0 > /sys/class/gpio/gpio183/value 

These commands will export GPIO 183 for access through the sys interface, set the GPIO to output, and drive "0" to the reset line on the USB chip.

You can also turn off power to the USB chip.

If someone wanted to try the same nasty kernel hack, I added this two lines:
       twl_i2c_write_u8(TWL4030_MODULE_USB, 0x08 /* value */, 0xBB /* register (CARKIT_ANA_CTRL) */);
       twl_i2c_write_u8(TWL4030_MODULE_USB, 0x01 /* value */, 0xFD /*register (PHY_PWR_CTRL) */);
in the function "twl_probe" in /drivers/mfd/twl-core.c just prior to the comment "load power event scripts". 

Wifi/Bluetooth

If not using the combined Wifi/Bluetooth module, you can hold it in reset. You can also hold it in reset and only enable as needed for periodic connectivity.

TBD

Disable LEDs

The on-board blue LED can be disabled with the following commands.

$ echo 211 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio211/direction
$ echo 1 > /sys/class/gpio/gpio211/value

This category currently contains no pages or media.