Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora Resources > Guides & Solutions (No Questions)
FedoraForum Search

Forgot Password? Join Us!

Guides & Solutions (No Questions) Post your guides here (No links to Blogs accepted). You can also append your comments/questions to a guide, but don't start a new thread to ask a question. Use another forum for that.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 28th June 2010, 12:02 AM
dd_wizard Offline
Registered User
 
Join Date: Sep 2009
Posts: 1,437
linuxfedorafirefox
How to extend battery life by automatically changing cpu governors.

Edit Note: After doing more reading, I realized that the power manager handles calling this script automatically when ac power is removed or applied, when the laptop first boots, and when the laptop resumes from suspend or hibernate. This simplifies things considerably. All that is needed is a modifed version of the original script in the /etc/pm/power.d directory. This also removes the requirement for running the acpi daemon (acpid), which isn't needed for pure gnome or KDE installations. Rather than posting the new version, this edit replaces the original post. End Note


This how to, along with autosuspending a laptop's webcam can noticeably extend laptop battery life. The following description of the conservative governor is from the kernel documentation:
Code:
165	The CPUfreq governor "conservative", much like the "ondemand"
166	governor, sets the CPU depending on the current usage.  It differs in
167	behaviour in that it gracefully increases and decreases the CPU speed
168	rather than jumping to max speed the moment there is any load on the
169	CPU.  This behaviour more suitable in a battery powered environment.
Currently, Ubuntu's gnome-power-manager supports using the conservative governor. But as of F14 rawhide, Fedora's does not. This script enables automatically changing governors when the ac adapter goes on and off line. It also allows throttling the maximum cpu frequency at the same time. Limiting the maximum frequency provides a cubic energy reduction, rather than linear, for drivers that support voltage scaling. (From the kernel/linux-2.6.34/drivers/acpi/processor_thermal.c source code).

The method described here only works with kernels and hardware that support cpu frequency scaling governors. It takes advantage of the cpufrequtils package, which should be installed with yum or your favorite package manager. Once it's installed, run cpufreq-info to make sure your laptop/kernel is supported.

Step 0:
Code:
[gene@Mobile-PC ~]$ sudo yum install cpufrequtils
...
[gene@Mobile-PC ~]$ cpufreq-info
cpufrequtils 007: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
  driver: acpi-cpufreq
  CPUs which run at the same hardware frequency: 0 1
  CPUs which need to have their frequency coordinated by software: 0
  maximum transition latency: 10.0 us.
  hardware limits: 800 MHz - 1.73 GHz
  available frequency steps: 1.73 GHz, 1.33 GHz, 1.07 GHz, 800 MHz
  available cpufreq governors: ondemand, userspace, performance
  current policy: frequency should be within 800 MHz and 1.73 GHz.
                  The governor "ondemand" may decide which speed to use
                  within this range.
  current CPU frequency is 800 MHz.
analyzing CPU 1:
...
Notice that a default installation doesn't include the conservative governor. That's taken care of by the script. The other important item is the driver. The list of drivers that support frequency scaling is in /etc/rc.d/init.d/cpuspeed. As long as the driver shown by cpufreq-info is in the following list, this script should work for you.
Code:
centrino powernow-k8 acpi-cpufreq e_powersaver
The directory involved is owned by root, so you'll need to use sudo or su -c to create, edit, and chmod the file. If you haven't set up sudo yet, use:
Code:
 su -c "command that was passed to sudo"
whenever sudo is shown. You will need the quotes with su -c, and you will be prompted for the root password.

Step 1: Create the powersave script in /etc/pm/power.d and make it executable. You may notice that the default online governor has been set to performance instead of the Fedora default of ondemand. Feel free to change it back to ondemand if you prefer. Also, the default script reduces the maximum frequency by 1 entry in the frequency table on battery power. Using 0 saves less energy, and 2 will save more. Try different values to test the trade off between battery life and responsiveness.
Code:
sudo gedit /etc/pm/power.d/governor-max-freq-powersave
I'm told vim isn't for everyone... Paste the following script into your favorite editor window:
Code:
#!/bin/bash
# This script will be called by the power manager subsystem at boot, on resume
# from suspend or hibernate, and when the ac power goes on or off line.

# Change the following two lines to use different governors.
# See /lib/modules/2.6.*/kernel/drivers/cpufreq/* for available governors.
online_governor=performance
battery_governor=conservative
# Change the following two lines to change the maximum cpu frequency reduction.
online_throttle=0
battery_throttle=1
# This list is from /etc/rc.d/init.d/cpuspeed.  If your driver isn't listed,
# but does support frequency scaling governors, add it to this list.
supporting_drivers="centrino powernow-k8 acpi-cpufreq e_powersaver"

PATH=/sbin:/bin:/usr/bin
E_DRIVER=81
E_AVAIL_FREQS=82
E_ONLINE_MOD=83
E_BATTERY_MOD=84
E_SET_GOV=85
E_SET_MAX=86

powersave="$1" # The caller passes "true" or "false" in $1.
cpud=/sys/devices/system/cpu
cpu0freqd=${cpud}/cpu0/cpufreq
cpu_freqds=${cpud}/'cpu[0-9]*/cpufreq'
echo ${supporting_drivers} | \
	grep -w "`cat ${cpu0freqd}/scaling_driver`" > /dev/null || \
	exit $E_DRIVER
available_frequencies="`cat ${cpu0freqd}/scaling_available_frequencies`" && \
	[ -n "${available_frequencies}" ] || exit $E_AVAIL_FREQS
available_governors=${cpu0freqd}/scaling_available_governors

# Load the necessary governors if they aren't already loaded.
grep -w "${online_governor}" "${available_governors}" > /dev/null || \
	modprobe cpufreq_${online_governor} || exit $E_ONLINE_MOD
grep -w "${battery_governor}" "${available_governors}" > /dev/null || \
	modprobe cpufreq_${battery_governor} || exit $E_BATTERY_MOD

get_max_freq() {
# Save the passed throttle before using set and shift to get the max freq.
	throttle="$1"
	set ${available_frequencies}
	if [ "${throttle}" -lt $# ]
	then shift ${throttle}
	else shift `expr $# - 1`
	fi
	echo "$1"
}

set_cpus() {
	for cpu in ${cpu_freqds}; do
		echo "$1" > ${cpu}/scaling_governor || return $E_SET_GOV
		echo "$2" > ${cpu}/scaling_max_freq || return $E_SET_MAX
	done
}

if [ "${powersave}" == "true" ]
then set_cpus ${battery_governor} `get_max_freq ${battery_throttle}`
else set_cpus ${online_governor} `get_max_freq ${online_throttle}`
fi
exit $? # Return the exit code from set_cpus.
Code:
sudo chmod +x /etc/pm/power.d/governor-max-freq-powersave
Test the script with cpufreq-info by unplugging and plugging in the laptop.
Code:
On batteries:

[gene@Mobile-PC Fedora]$ cpufreq-info
...
analyzing CPU 0:
...
  current policy: frequency should be within 800 MHz and 1.33 GHz.
                  The governor "conservative" may decide which speed to use
                  within this range.
...

On AC power:

[gene@Mobile-PC ~]$ cpufreq-info
...
analyzing CPU 0:
...
  current policy: frequency should be within 800 MHz and 1.73 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
...
That's it for laptops that support cpu frequency scaling. I have written a version of the script in Step 1 that uses passive thermal cooling to lower the cpu frequency. If there is any interest from owners of older laptops that don't support cpu frequency scaling, I can post it.

Also, if you're laptop is running hot on ac power because of high load or ambient temperature, you can use:
Code:
sudo pm-powersave true
This will lower the cpu temperature by 10C or more with only a small impact on performance.

Last edited by dd_wizard; 28th July 2010 at 08:05 PM. Reason: Fix problem with unrelated CPUs.
Reply With Quote
  #2  
Old 3rd April 2013, 12:29 PM
teeedubb Offline
Registered User
 
Join Date: Apr 2013
Location: Down Under
Posts: 1
linuxubuntufirefox
Re: How to extend battery life by automatically changing cpu governors.

Thank you!
Reply With Quote
  #3  
Old 3rd April 2013, 06:54 PM
dd_wizard Offline
Registered User
 
Join Date: Sep 2009
Posts: 1,437
linuxfirefox
Re: How to extend battery life by automatically changing cpu governors.

You're welcome!

dd_wizard
Reply With Quote
Reply

Tags
automatically, battery, changing, cpu, extend, governors, life

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using acpi: thermal/sysfs-api To Extend Battery Life dd_wizard Hardware & Laptops 2 4th February 2010 11:56 PM
Tips on how to extend battery life infernosoft Hardware & Laptops 17 11th September 2009 08:16 AM
Battery life mitchell2345 Hardware & Laptops 23 27th January 2007 06:48 PM
Battery Life Cruzader Hardware & Laptops 14 7th July 2005 05:28 PM


Current GMT-time: 12:24 (Thursday, 23-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Jatibonico - Kiselevsk - Hoogstraten