12.18. Advanced Power Management - APM

12.18.1. Linux Compatibility Check

For APM to work the machine's firmware must implement the APM Specification.
Linux supports versions 1.0 through 1.2 of the standard.
To work with Linux the APMBIOS
must support 32-bit protected mode connections.

To display information about the APMBIOS
on your system you can run dmesg | grep apm command or look
in the /proc/apm file.

12.18.2. Introduction

APM support consists of two parts: kernel support
and user-land support.

12.18.2.1. Kernel Support

You need a kernel that has the APM driver compiled
in using the appropriate kernel configuration options.
Currently most distributions do not ship kernels with the
APM driver enabled so you may have to enable the
driver using a boot option or to compile a custom kernel.
Please see
Kernel-HOWTO
or your distribution manual for details.

The APM driver can be modularized but this is
not recommended since many drivers will disable their
APM features if the APM driver
is not present when they initialize themselves.

The available APM options are (please see
Documentation/Configure.help in the kernel source
tree for more details):

CONFIG_APM_IGNORE_USER_SUSPEND
Just a workaround for some NEC Versa M series laptops.

CONFIG_APM_DO_ENABLE
Enable APM features at boot time.

CONFIG_APM_CPU_IDLE
Puts CPU in power save mode, if there is nothing to do for the kernel.

CONFIG_APM_DISPLAY_BLANK
Some laptops can use this to
turn off the LCD backlight when the screen blanker of
the Linux virtual console blanks the screen. Note that this is only used
by the virtual console screen blanker, and won't turn off the backlight
when using the X Window system.

CONFIG_APM_POWER_OFF
Turns the machine completely
down, when using halt. This feature works with most
laptops without problems.

CONFIG_APM_IGNORE_MULTIPLE_SUSPEND
Just a workaround for IBM™ ThinkPad 560.

CONFIG_APM_IGNORE_SUSPEND_BOUNCE
Just a workaround for Dell Inspiron 3200 and other notebooks.

CONFIG_APM_RTC_IS_GMT
Stores time in Greenwich Mean Time format.
It is in fact recommended to store GMT in your real time clock (RTC) in the BIOS.

CONFIG_APM_ALLOW_INTS
Resolves some problems with Suspend to Disk
for some laptops, for instance many newer IBM™ ThinkPads.

CONFIG_SMP Symmetric Multi-Processing support.
This enables support for systems with more than one CPU. If you have
a system with only one CPU, like most personal computers, say N.
Though the default seems to be Y. So it may be enabled if you are
unaware.
I have got reports that SMP support enabled does interfere with APM.
So with a single CPU machine like a laptop you are on the save side,
when you N.

Features of the APM driver according to the Kernel
documentation file Documentation/Configure.help:
"The system time will be reset after a USER RESUME operation, the
/proc/apm device will provide battery status
information, and user-space programs will receive notification of
APMevents (e.g., battery status
change). "

12.18.2.2. Userland Support

The most important userland utility is
apmd,
a daemon that handles APM events.

If you run a 2.2.x or later kernel and
want to experiment, Gabor Kuti <seasons_AT_falcon.sch.bme.hu>
has made a kernel patch that allows you to
hibernate any Linux system to disk, even if your
computers APMBIOS doesn't
support it directly. In my humble opinion you don't need this features
if your laptop provides a function key to invoke suspend mode
directly.

apmd(8): logs the battery status to syslog every now and then and
runs a proxy script that can take action before suspend or after
resume

apm(1): prints the current battery status or suspends the computer

apmsleep(1): suspends the machine for a limited time

xapm(1x): provides a battery meter for X11

libapm.a: a library for writing APM applications

Some APM firmware fails to restore mixer
settings properly which can result in squeals of feedback in the
music after the machine has resumed. A solution is to set up the
proxy script so that it calls a mixer application after resume.

From the apmsleep(1) man page: Some computers, especially laptops,
can wake up from a low-power suspend to DRAM mode using the Real-time clock
(RTC) chip. Apmsleep can be used to set the alarm time in the RTC and to go
into suspend or standby mode. An interrupt from the RTC causes the
computer to wake-up. The program detects this event, by waiting for a
leap in the kernel time and terminates successfully. If no time leap
occurs within one minute, or something goes wrong, the exit value will
be non-zero. Apmsleep is part of the apmd package.

In 2001 Richard Gooch wrote a simple apmd alternative
which is available in the
pmutils
package.

12.18.3. Caveats

If you use another operating system at the same computer make sure
that its "suspend" and "hibernate" features don't write to partitions
that are used by Linux.

12.18.4. Troubleshooting

If your machine worked with 2.0.x kernels but not with the 2.2.x series,
take this advice from Klaus Franken kfr_AT_klaus.franken.de : "The
default changed in 2.2. Search in the init-scripts for
halt and change it to halt -p or
poweroff. See man halt , if you
don't have this option you need a newer version of
halt." You may find it in the
SysVinit package.

On some new machines (for instance HP Omnibook 4150 - 366 MHz model)
when accessing /proc/apm,
you may get a kernel fault general protection fault: f000.
Stephen Rothwell
explaines: "This is your APMBIOS
attempting to use a real mode segment while in protected mode,
i.e. it is a bug in your BIOS. .. We have seen a few of
these recently, except all the others are in the power off
code in the BIOS where we can work around
it by returning to real mode before attempting to power off. Here we cannot do this."

According to Kernel docs
Documentation/Configure.help: "Some other things
you should try when experiencing seemingly random,
weird problems:

make sure that you have enough swap space and that it is enabled
swapon -s.

pass the no-hlt option to the kernel.

switch on floating point emulation in the kernel and pass the
no387 option to the kernel.

pass the floppy=nodma option to the kernel.

pass the mem=4M option to the kernel (thereby
disabling all but the first 4 MB of RAM).

make sure that the CPU is not over clocked (doesn't seem suitable for
mobile machines).

install a better fan for the CPU (doesn't seem suitable for mobile
machines).

exchange RAM chips (doesn't seem suitable for mobile machines).

exchange the motherboard (doesn't seem suitable for mobile machines).

12.18.5. APM and PCMCIA

From the
PCMCIA-HOWTO:
"Card Services can be compiled with support for
APM (Advanced Power Management) if you've configured
your kernel with APM support. ... The
PCMCIA modules will automatically be configured for
APM if a compatible version is detected on your
system. Whether or not APM is configured, you can use
cardctl suspend before suspending your laptop, and
cardctl resume after resuming, to cleanly shut down
and restart your PCMCIA cards. This will not work
with a modem that is in use, because the serial driver isn't able to
save and restore the modem operating parameters. APM
seems to be unstable on some systems. If you experience trouble with
APM and PCMCIA on your system, try
to narrow down the problem to one package or the other before reporting
a bug. Some drivers, notably the PCMCIA SCSI drivers,
cannot recover from a suspend/resume cycle. When using a
PCMCIA SCSI card, always use cardctl
eject prior to suspending the system.".

12.18.6. APM and Resuming X Windows

Some machines have APM firmware that fails to save
and restore display controller chip registers across a suspend.
Earlier versions of the XFree86 X server did not restore the screen
properly after resume, a problem which was addressed by
Linux Laptops.
However, contemporary versions of XFree86 mostly do the right thing.

Sometimes X and APM don't work smoothly together.
The machine might even hang. A recommendation from Steve Rader:
Some linux systems have their X11 server hang when doing
apm -s. Folks with this affliction might want to switch
to the console virtual terminal and then suspend
chvt 1; apm -s as root, or, more appropiately
sudo chvt 1; sudo apm -s. I have these commands in a script, say,
my-suspend and then do
xapmload --click-command my-suspend .

12.18.7. Software Suspend

Software suspend
enables the possibility of suspending a machine. It doesn't need APM.
You may suspend your machine by either pressing Sysrq-d or with
swsusp or shutdown -z (patch for
sysvinit needed). It creates an image which is
saved in your active swaps. By the next booting the kernel detects the
saved image, restores the memory from it and then it continues to run
as before you've suspended. If you don't want the previous state to
continue use the noresume kernel option.

Software suspends may even be better than hibernate, because now I can
suspend my Linux system, boot into Microsoft Windows, perform a few
illegal operations and be shut down, and then restart my Linux setup
exactly where I left off! This is something that cannot be done with
hibernation, since that always restores the last state that you
suspended from, be it Microsoft Windows or Linux. So if I want to switch
to Microsoft Windows to play games or do anything else, I can leave my
Linux desktop exactly as it is and return to how I left it.

In recent 2.6 kernels SoftWareSuspend is part of the kernel. You may
find it in the section Power Management. But there are also
backports to 2.4 available.

Since the original Software Suspend code was written by Gabor Kuti and Pavel
Machek back in 1998, three different implementations have been created for the
2.6 kernel, all forks of the same original codebase.

TuxOnIce, former known as
Software Suspend 2, has a long feature list, including the ability to cancel a
suspend by pressing Escape, image compression to save time and space, a
versatile plugin architecture, and support for machines with Highmem,
preemption and SMP.

12.18.8. Tips and Tricks

12.18.8.1. Battery Status on Text Console

You may use the following entry in .bashrc
to show the battery level on the command prompt.

12.18.8.2. Debian GNU/Linux

All "normal" Debian GNU/Linux kernels are APM capable, they just need an append
line added to the boot loader configuration file (e.g. /etc/lilo.conf.

append="apm=on"

You might use the following parameters (with the appropriate changes)
in your boot loader configuration file (e.g. /etc/lilo.conf
to experiment with ACPI and APM, when compiled in the same kernel.
Usage of APM and ACPI at the same time doesn't work, see Kernel docs for
details.