Advanced Power Management under Linux
Advanced Power Management under Linux
As usual, the following informations are provided as is, with no warranty of any kind. Use this at your own risk.
Advanced Power Management under SuSE is managed by several layers : the apm kernel module, an apmd server and a script apmd-proxy. This page proposes some improvements to this script in order to increase battery performances and a kernel patch to correct some BIOS misbehaviour. Some settings are suggested to decrease power consumption.
More information can be found on the official apmd
This script is called by the apmd daemon every time a signal from the BIOS is received. Have a look at the
manual page for more information.
In SuSE 7.2 the apmd_proxy script is located in /usr/sbin. Its configuration file is
I've slightly modified the
script in order to be able to shut off some services when battery powered.
This script is located in /usr/sbin under SuSE.
These new features are configured by new options of
that can be set under yast.
The installation is as simple as copying those files in place of the old ones. The features are tuned by the following variables.
This new variable is used to stop services before suspending. The idea here is that network services may introduce some instability if they are not properly shut down before suspending. Usually, even if some sessions are opened through the network, they can be restored if resuming is done before timeouts.
To restart services upon resume, use this other variable. The list of services should be the same as APMD_STOP_SERVICES_BEFORE_SUSPEND in reverse order. I have set two different variables because in some case it could be useful not to restart some services if they cause hang on resume.
This variable can be set to yes if you want to unload unused modules before suspending. This is done after stopping services. Upon resume the modules will be automatically reloaded by kernel. This will hopefully reinitiate correctly peripherical devices.
This is experimental and disable swap when the laptop is used on battery power. This is intended to reduce the number of access to hard disk, allowing it to spin down. On some laptops, it may have the exact inverse effect.
This variable can be set to a list of services that will be stopped on battery power and restarted on AC power.
This variable can be set to yes if you want to do the same thing while going in standby mode or in suspend mode. This is intended to use with
The only setting that remain separate is the APMD_LEAVE_X_BEFORE_SUSPEND/STANDBY one.
Besides the formerly described improvements, I have also slightly modify the script as follows:
- Make automatically a call to "apmd_proxy change power" 2 minutes after resuming, in order to reset hard disk parameters.
- Fix a problem with the original script and my BIOS. Before starting a shutdown, the new script check that the battery status is critical. My BIOS send a battery low event at 70% and I don't want a shutdown to be performed in such a situation :-)
I have noticed on my
that the kernel apm driver was not getting correct information on AC power if the change occurs during suspension. For instance, you work with AC power plugged in, shut your lid which provokes suspension, take your laptop out and resume it afterwards. On my
the status that is then displayed by apm is AC on which is problematic since the laptop keeps its old settings and do not reduce power consumption. After careful analysis, it seems that the error comes from the BIOS itself since the problem disappear if you plug in and out the AC adaptor. Otherwise, the battery state is correctly updated and the battery capacity decreased while apparently on power ! I have therefore patched my kernel to detect this behaviour. In such a case, the kernel will log a warning as follows
Nov 8 09:52:02 fuji kernel: apm: Buggy BIOS : battery is charging, assuming AC on line
Nov 8 11:58:00 fuji kernel: apm: Buggy BIOS : battery is discharging, assuming AC off line
Another buggy feature of my BIOS is that a battery low event is sent to the kernel when battery capacity goes below.... 70% but when the status become critical there is no signal from the BIOS ! This patch will create battery low events as soon as the battery status become critical even if the BIOS send nothing. The multiplication of such events is not a problem since the normal behaviour in such a case is to properly shutdown the laptop or suspend on disk.
The patches can be applied against official linux kernel source tree. I have tested the indicated versions but it is such a simple patch that it should apply to any 2.4.x kernel.
||Date and size
I discuss hereafter some of my settings. On my laptop, these settings achieved almost 100% increase in autonomy.
I use APMD_STOP_SERVICES_BEFORE_SUSPEND to stop the following services:
Upon resume, I restart these services in reverse order using APMD_START_SERVICES_AFTER_RESUME.
I also unload unused modules after stopping services using APMD_UNLOAD_MODULES_BEFORE_SUSPEND.
Eventually, I shut down cron, at, pcmcia, xntpd, and lpd services while on battery using APMD_ADJUST_SERVICES_PERF.
- sendmail because resuming can occur in a different network with different name server.
- ypbind for the same reason.
- apache because if external sessions are opened, they will be properly shut down.
- xntpd because time servers can be different if connected network is changed.
- dhclient and/or network to shut down the net devices before suspending.
Configuring autofs seems to me very important for a laptop since it will allow automatic reconfiguration of laptop when suspending, docking and so on. Every foreign partition including dos, vfat or ntfs as well as nfs and smbfs should therefore be auto-mounted. The delay for unmount should be as small as possible because that will allow the kernel to unload unused modules, saving some memory. I personnaly use 3 seconds setting in rc.config file: AUTOFS_OPTIONS="--timeout 3"
The flushing of buffers on disk is controlled by the
file. It should be activated by the APMD_ADJUST_DISK_PERF variable.
I use the following settings
- APMD_BATTERY_DISK_TIMEOUT="6" makes the hard disk spin down after 30 seconds.
- APMD_BATTERY_DATA_TIMEOUT="240" this flushes data on disk every 4 minutes.
- APMD_BATTERY_METADATA_TIMEOUT="240" this flushed metadata every 4 minutes. This setting may be dangerous if you have crashes since you will more likely experience unexepected inconsistency in e2fs filesystem.
- APMD_BATTERY_FILL_LEVEL="80" this will initiate flushing only if free space in buffers go below 20%. This setting may be dangerous also.