[HOWTO] Save power and extend your battery life in Porteus

Post tutorials, HOWTO's and other useful resources here.
Post Reply
User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

[HOWTO] Save power and extend your battery life in Porteus

Post#1 by Ahau » 12 Jul 2011, 17:20

I discussed this issue a little on this thread: viewtopic.php?f=48&t=644

But here's my article, now in draft form, for your review and testing. As always, suggestions/edits are more than welcome! I'll let this simmer here for a few days, to see if anyone has anything to add, and then I'll transfer it to the main site. All of the ((CODE)) and ((LINK)) stuff will get fixed when I move it there.


I recently became interested in finding ways to save power in my system, in order to extend the length of time I can spend on my laptop without recharging my battery. I found some useful links and programs, and thought I'd share my experience for others to benefit from. I should note that efforts to reduce power consumption can range from the very simple to the very complex. This tutorial is aimed at putting together some relatively simple tools and procedues for a fair amount of efficiency gains. Most users will be able to put these tools to use. More advanced users will benefit from the latter sections of this tutorial, where I'll provide tools to gather more in-depth information for fine tuning.


The real "heavy lifting" in regards to saving power has already been taken care of by the Porteus maintainers. Were it not for the use of CPU frequency govenors (Porteus uses the 'ondemand' govenor by default but has several others that can be loaded as kernel modules) acpid (the ACPI daemon), and several other built-in options, Porteus would chew through batteries much more quickly. I've run some tests and, on my system at least, the 'out of the box' power consumption in Porteus compares well with other live distros.

That said, there is more that can be done to finely tune your system's power consumption. I have packaged some tools for use in Porteus that will aid in those efforts. You can find them here:

32-bit tools: http://www.mediafire.com/?gu6n9u89tr8d4l9

64-bit tools: http://www.mediafire.com/?m7st7nyd56asg8y

The module in the links above should be downloaded and extracted to a directory (right click on it and choose the 'extract porteus xzm module' option, or use 'xzm2dir' from the command line). Inside, you'll find .xzm's for PowerTop version 1 (I've called it legacypowertop), PowerTop2 (currently a beta release, aka 1.98), and Laptop-Mode-Tools (v. 1.57). Place these modules in your /porteus/modules directory and activate them (or reboot, and they'll activate automatically after your next reboot).

The first step in conserving power is gathering information about your system. You'll want to know how much power you are using, to help know how much your efforts are saving you. To get an estimate of your power consumption, open up PowerTop (note--you should do this with your laptop unplugged, or PowerTop cannot get an assessment of how quickly your battery is draining), :

(CODE) powertop

Note: You can also use Version 1 of PowerTop, which I've compiled from the latest git (the last stable release was V1.13, but this updated version works a little better with the 2.6.38.8 kernel in V1.0). You can load this program as 'legacypowertop'. Sometimes I run both versions in separate consoles to compare their output. That said, the remainder of this article assumes you are using PowerTop2 (beta). Note that PowerTop2 does not support languages other than English, as the locales failed to compile on my end -- hopefully this will be fixed before the final release.

When you start up Powertop, it gathers some data about your system, and then an interface opens up displaying your power usage and other information. There are a number of tabs across the top: Overview, Idle stats, Frequency stats, Device stats, and Tunables. Use your right and left arrow keys to navigate through the various tabs to see more information. The furthest tab to the right, 'Tunables' allows you to alter your system's configuration, which we'll cover in more detail later.

You might notice that you are not getting a lot of data on some of the screens in PowerTop -- in fact, there is even more data that could be gathered, but not with the standard Porteus kernel. In the 'Overview' screen, for example, you get information about devices and their power usage, but nothing about processes and how often they interrupt or wake up your CPU. See the "Advanced Information Gathering" section below for more information on how to view these statistics. Under the 'Frequency stats' tab, you may also be getting little to no information. To see the frequency at which your CPU is running, and to enable the use of ACPI Processor Performance States (p-states) you can modprobe the relevant kernel module for your system:

((CODE))
modprobe acpi-cpufreq #for Intel chips
modprobe powernow-k8 #for AMD chips

After this module loads (assuming your processor supports one of the two drivers listed above), PowerTop will start to show you how long your processor spends at each frequency. Let your system idle for a while and watch your power consumption and your cpu frequency. At rest, my system (a Dell laptop with an Intel Core 2 Duo @2.2Ghz) uses about 26 Watts, and the processor spends about 96% of the time in Idle, with bursts up to Turbo mode when it needs to do something.

Now, let's take another look at the 'Tunables' section of PowerTop. Arrow over to the 'Tunables' tab and take a look. My system displays a few items at the bottom of the list that are marked 'good', and then a whole bunch of things that are marked as 'bad'. To change all of the 'bad' items to 'good', you can go scroll down to each item and press 'enter' to toggle the setting. Toggle all of the settings that you can (there was one on my system that PowerTop couldn't tune), and then watch your power usage for a while to see how it responds. Doing this reduced my power consumption by about 4-5 watts.

So, this is great, you're saving power! The bad news, however (for PowerTop, anyway), is that the 'tuning' provided by PowerTop will not surve a reboot (even if you are using Porteus with saved changes). This makes it a bit of a pain to manage your settings through PowerTop alone. To automate the process of tuning your system every time you boot up, you can use Laptop-Mode-Tools. Here's how:

Reboot your system to clear the changes you made in the 'tuning' section of PowerTop. Once your system boots up, start PowerTop again, and go back to the 'tuning' section. Now, in another console, start up 'laptop-mode-tools', using the following commands:

((CODE))
cd /
./etc/rc.d/init.d/laptop-mode restart

Laptop-Mode-Tools will go through your system and make a number of changes to enhance your power savings. Many of these are listed in the 'Tunables' section of PowerTop, so keep an eye on your PowerTop console and watch what switches from 'bad' to 'good', and then watch your power consumption to see how it changes. If there are any items that Laptop-Mode-Tools doesn't toggle to 'good', you can toggle them in PowerTop or look for ways to automatically alter their settings, via scripts or changes to the Laptop-Mode-Tools configuration. You can also post a note in the forum thread for this article ((LINK, here)) for help. You can configure the default settings for Laptop-Mode-Tools in the file /etc/laptop-mode/laptop-mode.conf, and modify feature-specific configurations in the various files found in /etc/laptop-mode/conf.d/. If you were able to use one of the ACPI CPU Frequency drivers mentioned above (acpi-cpufreq or powernow-k8), you can modify your laptop-mode.conf to load this module every time you start laptop-mode-tools. There are numerous tweaks you can perform, which are outside the scope of this HOWTO -- to get started, take a look at the following:

((CODE))
man laptop-mode.conf

https://wiki.archlinux.org/index.php/La ... _frequency
http://samwel.tk/laptop_mode/faq

To make laptop-mode-tools start up each time you boot into Porteus, you should add an entry to your /etc/rc.d/rc.local file ((LINK TO HOWTO)) to restart it every time you boot up. Add the same line that you used to restart it above ('./etc/rc.d/init.d/laptop-mode restart'). Remember to store your rc.local and your /etc/laptop-mode/laptop-mode.conf to rootcopy if you will be booting into 'Always Fresh' mode.

Any comments on specific tweaks would be welcome! Again, you can post those comments here ((LINK TO THREAD))


ADDITIONAL TIPS FOR SAVING POWER:

1) One of the biggest power-drains in your system is the LCD screen's backlight. If you turn your backlight down a bit, you can get significant power savings. On my Dell laptop, for example, holding the 'Function' key and pressing the down arrow will reduce the backlight. Of course, your backlight has to be set high enough for you to read the screen! Your laptop should have buttons on it for adjusting the backlight.

2) Disable any hardware that is not in use. This is especially the case if you aren't using PowerTop or Laptop Mode Tools to manage your power settings. For example, turn off your wifi card if you're not using the internet, and spin down your hard disks if you are not using them ( use 'hdparm -Y /dev/sda' ). You can, for example, boot Porteus into 'copy2ram' mode, unplug your USB device, and spin down your hard drives (note that you'll probably still have power going to your USB controller unless you enable the power management (PM) functions for the controller, which you can do through PowerTop or Laptop Mode Tools). If you need to save anything back to your flash drive, you can plug it in and mount it manually to save your work at the end of your session.

3) Try using a different driver for your graphics card. I have an nVidia card, and changing from nouveau to the proprietary driver saves me about 3-4 watts. I haven't been able to test this with ATI or other cards, but if others are able to and would like to contribute their results, it would be appreciated!

To install and use the nVidia driver, follow the steps provided in this article:

http://porteus.org/info/docs/46-video/1 ... river.html

To create and use a custom ATI/FGLRX driver, use the script provided here:

http://porteus.org/info/docs/46-video/7 ... river.html

4) There is a known regression in the 2.6.38 kernel that affects how ASPM is used for PCI-e devices on some systems with faulty BIOS's -- see this link for more information: ((LINK http://www.phoronix.com/scan.php?page=a ... aspm&num=2 )). To check if your system is affected, try booting with the following boot parameter (i.e. cheatcode):

((CODE))
pcie_aspm=force

If affected, this cheatcode should lower your power consumption (keep an eye on your consumption in PowerTop, with and without the cheatcode).

5) If your system doesn't make use of the built-in cpu govenors and it is running at full speed all the time, you can try running the 'power_saver' script to scale back the CPU frequency.


ADVANCED INFORMATION GATHERING:

As stated previously, the 'Overview' tab in PowerTop displays information about devices, but it does not contain any detailed information about processes that are causing a high load or waking up your CPU when using the standard Porteus kernel. I have prepared a custom kernel that enables this functionality in PowerTop (for those who are interested, the configs that I have enabled in the kernel are: CONFIG_DEBUG_KERNEL, CONFIG_TIMER_STATS, CONFIG_FTRACE, and CONFIG_FUNCTION_TRACER, which autoselects CONFIG_TRACING and CONFIG_TRACEPOINTS) If you're interested in viewing this level of detail, I've included a customized kernel, initrd, 000-kernel-powersave.xzm nVidia driver module and crippled-sources module in the following packages:

((LINK))
32-bit V 1.0: http://www.mediafire.com/?r5dn4e7fbtb5i7v
64-bit V 1.0: http://www.mediafire.com/?coc3kq6vdumebq4

NOTE--moving to this custom kernel will not directly reduce your power consumption; rather, it will allow you to gather more information, so that you can find ways to tune it yourself. You can use PowerTop and Laptop-Mode-Tools to gain substantial power savings without changing kernels.

Download the relevant package for your edition of Porteus, and unpack the xzm (right click and select 'extract Porteus xzm module', or use 'xzm2dir' from the command line. Inside, you'll find the necessary files and a README file. Make a backup of all of the files you're replacing, then move the 'vmlinuz' and 'initrd.xz' files to your /boot/ folder, move the 000-kernel-powersave.xzm module to /porteus/base/ (and remove the old 000-kernel.xzm), and replace the nVidia module if you are using the nVidia proprietary driver. Any drivers that you normally need to compile with the 'crippled sources' module can be compiled against my custom kernel with the 'crippled sources' module I've included, but you probably won't need that module otherwise.

Once you get everything copied into your system and reboot, PowerTop will be able to list the processes on your system that are responsible for waking the CPU, and you can look for ways to reduce the usage. I've not done a lot of tweaking to these processes, so I'll leave it up to the reader to google and experiment at their own risk.

If you're really interested in fine tuning your system (and if you're still reading at this point then I think you are) there are some additional features included in PowerTop2 and Laptop-Mode-Tools. In PowerTop2, for example, you can start it with the --html option (i.e. 'powertop --html') to generate an html report detailing your power usage (of course, this can be run without the custom kernel, but you'll get less information). There is also an option to better calibrate PowerTop for your system -- see 'powertop --help' for more information. Laptop-Mode-Tools includes a tool called 'lm-profiler', which will watch your system for a while to debug why your hard drives might be spinning up, and it detects network services that you might not want running.


Links/Credits:

PowerTop:
http://www.linuxpowertop.org/ (Note that this site has not been updated for use with PowerTop2)

Laptop-Mode-Tools:
http://samwel.tk/laptop_mode/

More tips, tricks, and information:

http://www.lesswatts.org/
http://www.thinkwiki.org/wiki/How_to_re ... onsumption
http://www.thinkwiki.org/wiki/How_to_ma ... cy_Scaling
https://wiki.archlinux.org/index.php/Laptop_Mode_Tools
https://wiki.archlinux.org/index.php/CP ... cy_Scaling
http://www.gentoo.org/doc/en/power-management-guide.xml

Note that some, but not all, of the methods shown in the links above are incorporated into Laptop-Mode-Tools and/or PowerTop. You can make saving power a full-time job if you'd like ;)

EDIT 07/13/2011: added item #2 under "Additional Tips for Saving Power" -- thanks for the reminder fanthom!

Also, does anyone know if rmmod'ing a device driver will reduce it's power consumption? For example, I have an ethernet controller that doesn't play nice with PowerTop or Laptop Mode Tools. I can rmmod the driver, but I don't know that I'm getting any power savings out of it...
Please take a look at our online documentation, here. Suggestions are welcome!

blablotin
Black ninja
Black ninja
Posts: 67
Joined: 04 Jan 2011, 22:59
Location: Euro

Re: [HOWTO] Save power and extend your battery life in Porte

Post#2 by blablotin » 23 Jul 2011, 10:07

Hi Ahau,
great job for this How to about the power saving, with lot of detail.

However there is a way way to powersave for some ATI card using radeon instead of FGLRX:
From the radeon's wiki http://www.x.org/wiki/RadeonFeature , since the Kernel 2.6.35 powerplay is supported, with two basic method "dynpm" and "Profile" default seleccted is "profile" since "dynpm seem to be experimental"

Code: Select all

cat /sys/class/drm/card0/device/power_method
And in profile there are 5 chooses: "default" "auto" "low" "mid" "high"
"default" is default behavior: that mean no change in powerplay feature: it is the same setting than with older kernel without FGLRX.
from powertop, laptop consume 40-45 W, and from sensors, the temp is 55°C (plugged or battery).

So to be abble to power save we need to select "low" or "mid"

Code: Select all

echo low > /sys/class/drm/card0/device/power_profile
from powertop laptop consume from 25 to 30 W and from sensors, the temp has decreased to 35-37°C plugged and 44°C on battery (because of the fan setting in the BIOS)


For usb auto suspend, I have used the boot parameter to suspend after 100 seconds.
CODE

Code: Select all

usbcore.autosuspend=100

added: the 18 august 2011
When I am on battery I switch the governor from ondemand to powersave with this script (we should have run once power_save to enable cpufreq modules else the script won't work) Notice!: this way have been tested only on Intel Core2Duo inside Centrino Duo. For other CPU you may have to change the script:

Code: Select all

#!/bin/bash
# CPU_powersave
modprobe cpufreq_powersave
for i in `find /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`; do echo ondemand > $i; done
You can check the current governor for each core with

Code: Select all

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Then you can check the current frequence with the command:

Code: Select all

cat /proc/cpuinfo
Last edited by blablotin on 18 Aug 2011, 22:19, edited 2 times in total.

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: [HOWTO] Save power and extend your battery life in Porte

Post#3 by Ahau » 25 Jul 2011, 21:10

blablotin, that is great information! I'll be sure to include it in the final version. thank you!!
Please take a look at our online documentation, here. Suggestions are welcome!

blablotin
Black ninja
Black ninja
Posts: 67
Joined: 04 Jan 2011, 22:59
Location: Euro

Re: [HOWTO] Save power and extend your battery life in Porte

Post#4 by blablotin » 20 Aug 2011, 12:14

Hi,
I have find an explaination about the Linux kernel 2.6.38 and 2.6.39 power regression workaround
To sum up, PCIe ASPM is controlled with the file /sys/module/pcie_aspm/parameters/policy.
When you check the file

Code: Select all

cat /sys/module/pcie_aspm/parameters/policy
you should have an answer like "[default] performance powersave" (I have it with or without pcie_aspm=force)
Witch mean the default PCIe ASPM profile is selected, and this "default" is where the probleme lie.
So to increase battery live, it is advised to force the selection of powersave.

Code: Select all

su
echo powersave > /sys/module/pcie_aspm/parameters/policy
exit
If it display

Code: Select all

Operation not permitted
you can add "pcie_aspm=force" in boot option, and try again. But it may crash the machine: if so, leave this option off.

Finally, this power regression may not be fixed untile kernel 3.1.

User avatar
Ahau
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

Re: [HOWTO] Save power and extend your battery life in Porte

Post#5 by Ahau » 20 Aug 2011, 15:46

great, thank you!!!
Please take a look at our online documentation, here. Suggestions are welcome!

Post Reply