# [Howto] Power Management for your laptop using ACPI

## Earthwings

Battery lifetime is too short? Your laptop is getting too hot? Want to hibernate like in Windows? This howto might help you. It's was getting too big to put it here in the forums, but it's still just one click away.

Edit: It's now available at http://www.gentoo.org/doc/en/power-management-guide.xml

I'd appreciate some comments, additions, suggestions etc. Have fun  :Smile: 

For your convenience, here's a short outline of what is expecting you:

Power Management for Laptops in Gentoo Linux

Introduction

Prerequisites

-->    The BIOS part

-->    ACPI support for the kernel

-->    Creating a "battery" runlevel

CPU Power Management

LCD Power Management

Disk Power Management

Power Management for other devices

-->    Wireless Power Management

-->    USB Power Management

Sleep states: sleep, standby, suspend to RAM, hibernate, suspend to disk

Extending with Profiles

FAQ / TroubleshootingLast edited by Earthwings on Fri Mar 18, 2005 7:23 am; edited 6 times in total

----------

## bombcar

One way to make Gentoo know what it is booting into is to make the default runlevel very empty, and then all it does is decide if AC power is available, then boot to "acpower", but if only battery, boot to "battery"

----------

## dvc5

This is great! I've been looking for something like this for a long time. Now I just need a laptop w/ frequency scaling.  :Sad: 

----------

## Earthwings

 *bombcar wrote:*   

> One way to make Gentoo know what it is booting into is to make the default runlevel very empty, and then all it does is decide if AC power is available, then boot to "acpower", but if only battery, boot to "battery"

 

This is indeed nicer then my first idea (modifying /sbin/rc). However, there'll be an even better solution, I hope...

----------

## Jefklak

Very nice guide, congrats!  :Smile: 

I'm only having trouble with ACPID - he doesn't receive any events!

I tried watching my events with

```
cat /proc/acpi/button/state
```

But when I pressed power or closed/opened the lid nothing changed in that file... Is that normal?  the module button is loaded... I don't know what to do, acpi seems to ignore my events... Does anyone have a clue?

----------

## Earthwings

I don't have a file /proc/acpi/button/state. Instead, there are directories like /proc/acpi/button/lid/LID/ with file "info" and "state" inside. What do you get in dmesg when inserting the button module? I get

 *dmesg | grep ACPI wrote:*   

> 
> 
> ACPI: Battery Slot [BAT0] (battery present)
> 
> ACPI: Battery Slot [BAT1] (battery absent)
> ...

 

Does /proc/acpi/event exist? Is /etc/acpi/default.sh called when acpid is running?

----------

## Jefklak

Duh, I meant the /proc/acpi/event file instead of the button/state file... I don't know if the .sh file is called when a button is pressed or a lid is opened or closed, how can I check this? Also, acpid seems t owork (same dmesg as you) but the state thing does not work... Yes, the files you mentionned excist but some way the events aren't passed or don't work correctly... Any idea? 

Thanks!

----------

## jarealist

Thanks for the howto.  However, I'm having a problem getting the following module to load:

<M> ACPI Processor P-States driver

I get this from modprobe:

modprobe acpi

FATAL: Error inserting acpi (/lib/modules/2.6.4-gentoo-r1/kernel/arch/i386/kernel/cpu/cpufreq/acpi.ko): Device or resource busy

Any suggestions?  All the other modules load OK.  Here is my /etc/modules.autoload.d/kernel-2.6.

 ac

 battery

 button

 fan

 processor

 thermal

 acpi

 pcmcia_core

 ds

 yenta_socket

 sonypi

 fglrx

 av5100

 ipw2100

I have a Sony Viao PCG-V505DX and I'm using gentoo-dev-sources kernel ( 2.6.4-gentoo-r1.)

Will this work compiled in?  Thanks.

----------

## Kenja

Just a thought.  I have an unlocked Athlon XP Mobile.  The current Biostar I intend on using has multiplier settings in the BIOS.  I don't expect it to work for my board, but MSI has a board that has software multiplier management.  Currently they only have software for windows, but would this setup work for the MSI board as well.  In theory would the MSI board use the same commands as a board in a laptop and in effect make for a quiet desktop PC?

----------

## Earthwings

Sorry for the long delay.

Jefklak: What laptop do you have? I read a few other posts where the same happens.

jarealist: It's the same for me. I haven't yet figured out what the problem is, but if you did, please post here.

Kenja: Sorry, I don't have any experience with that.

I'm currently working on the next major update for the guide supporting laptop_mode and Power Management Profiles. It looks promising, but will take some time to finish. Stay tuned.

Edit: laptop-mode now includedLast edited by Earthwings on Tue Apr 06, 2004 6:45 pm; edited 1 time in total

----------

## Jefklak

Dell Inspiron 5150.

I reinstalled my whole box -- still no go...  :Sad: 

----------

## Earthwings

Have a look here, seems to be a common problem for the Dell 5100 serie.

https://forums.gentoo.org/viewtopic.php?t=154996

----------

## Jefklak

Thanks for the link, it seems common indeed, that sucks  :Sad: 

I already recompiled my DSDT and I was able to solve 1 WARNING (no error) but there are still 4 left (see https://forums.gentoo.org/viewtopic.php?t=122145&start=75 ...)

I already flashed my bios to A29, ill check if there's a newer version...

----------

## Earthwings

Just stumbled over this

http://bugme.osdl.org/show_bug.cgi?id=1752

----------

## angagon

I am using a program called hprofile at [url]hprofile.sf.net[/url].  It allows changing files anywhere (like /etc) so you can set it up for different power configurations and using ACPI change confs on plugging the power in or out.  Or other things.

----------

## TinheadNed

Just to be picky, your suspend/hibernate section is slightly wrong.  There are two different sets of suspend code in the 2.6 kernel, hence the two different suspend options.  There is the original Software Suspend (swsusp) that requires a resume= command line to your swap space, and the new PM code (which is the config option that requires a hardcoded partition).

If both are compiled in the kernel then

```
echo -n X >/proc/acpi/sleep
```

 activates swsusp code and 

```
echo -n {standby|mem|disk} >/sys/power/state
```

 activates the new code.

I prefer the second option.  Disk == hibernate and appears to work well, mem == suspend and doesn't work, my (shitty) laptop just suspends but won't stop.  standby doesn't seem to do anything permanent on my laptop, it enters standby and then immediately returns from it (without ANY problem) thus negating its use.  If anyone has fixed that I'd be interested  :Very Happy: 

----------

## Kuartzer

 *Quote:*   

> Note: One thing is missing: Gentoo will boot into runlevel default regardless of AC or battery plugged in. One way to get round this is to add a "softlevel=battery" boot parameter, but there has to be a more automatic way. I'll have a deeper look into this and update this document appropriatly. 

 

Can´t we put acpid on boot runlevel?? maybe there it will no go to default on boot, only starting it on acpower...

I belive that it starts runlevel default on boot only becouse acpid is included in that runlevel and becouse it´s the logical and inicial boot sequence.

----------

## Earthwings

Putting acpid in boot runlevel is not sufficient because it doesn't generate an event. However, the idea to decide which runlevel to start in the end of the boot runlevel sounds good. I'm not sure if the current battery runlevel satisfies everything a proper default runlevel has to provide (list of critical services etc). 

The workaround I did right now is putting this code in /etc/conf.d/local.start:

```

# Fake acpi event to switch runlevel if running on batteries

/etc/acpi/default.sh "battery/battery"

```

This leads to the runlevel sequence boot -> default -> battery if booted on batteries, what is not optimal, but at least working.

@TinheadNed: Thanks for reporting, I think you're right - I'll update the howto when I've got a little more time (next week). I'm also going to update the profiles section and add a FAQ/Troubleshooting like chapter.

----------

## Kuartzer

I belive that the batery runlevel it´s a full copy of the default one plus the energie savings settings. 

 *Quote:*   

> 
> 
> ```
> 
> cd /etc/runlevels
> ...

 

If that is true, can it work??

If not, why not creat one more runlevel, the acpower. or the critical, an we separate the critical servicies from others!

BTW: thanks for the howto!  :Smile:  i´m not currently using it becouse my laptop is lended to my dad, but i will use it as soon as i can  :Smile: 

----------

## Earthwings

IIRC the main problem is that /sbin/rc reads out the SOFTLEVEL value too early to update it. You are right that creating another runlevel would be a solution however.

----------

## Earthwings

I made another major update right now. Beneath some minor fixes I added a FAQ chapter and updated the suspend/hibernate section. It now mentions swsusp2, which is the first implementation for hibernation that works for me. It looks really promising, has a nice interface and even supports bootsplash. You definitely want to try it  :Wink: 

----------

## codedmart

I didn't have the directory

/sys/devices/system/cpu/cpu0/cpufreq/

and it wouldn't let me create one not sure what to do.

thanks

----------

## codedmart

I still haven't been able to resolve my problem

NO: /sys/devices/system/cpu/cpu0/cpufreq/  and I can't create one

Any ideas on what I should do.

----------

## Earthwings

Can you give some more details? Some hardware specs. and the relevant parts of the kernel config. Also make sure there's no "dumb" mistake like forgetting to mount /boot before copying the kernel etc.

----------

## codedmart

I have a gentoo system up and running. I was following your how-to and it got to the part where you said to *Quote:*   

> cat /proc/cpuinfo | grep "cpu MHz"
> 
> cd /sys/devices/system/cpu/cpu0/cpufreq/
> 
> echo -n userspace > scaling_governor
> ...

 

When I tried to cd /sys/devices/system/cpu/cpu0/cpufreq I don't have that. I have everything up to /sys/devices/system/cpu/cpu0 but no cpufreq so I tried to create one (as normal user and as root) but it wouldn't let me. So I am not sure where to go or what to do from here. 

I have a HP ze4145 laptop w/ Athlon-XP 1800+ 512mb ram

running kde 3.2.2 and 2.6.6-love1 kernel.

----------

## Earthwings

Any ACPI related errors in dmesg? 

```
dmesg | grep ACPI
```

Make sure to run the latest BIOS. It might be a problem with the DSDT. See these threads:

https://forums.gentoo.org/viewtopic.php?t=158462

https://forums.gentoo.org/viewtopic.php?t=122145

----------

## TheCoop

the ac adapter/battery state isnt updated, ie if it is plugged in on startup it keeps on saying it's plugged in regardless, similarly it keeps on saying its on battery if it isnt plugged in on startup

----------

## codedmart

If I dmesg | grep ACPI this is what I get

```
ACPI: No IRQ known for interrupt pin A of device 0000:00:10.0

powernow: Trying ACPI perflib

ACPI: (supports S0 S3 S4 S5)

ACPI: Looking for DSDT in initrd ... not found!
```

hope that helps because I have no idea what it means.[/code]

----------

## lampshad3

 *blmartin777 wrote:*   

> I have a gentoo system up and running. I was following your how-to and it got to the part where you said to *Quote:*   cat /proc/cpuinfo | grep "cpu MHz"
> 
> cd /sys/devices/system/cpu/cpu0/cpufreq/
> 
> echo -n userspace > scaling_governor
> ...

 

Same here  :Sad: 

I have a Compaq Armada e500

----------

## Xerroz

hey EarthWings, whens your kde battery profile program gonna be released??  :Wink: 

----------

## Earthwings

 *Xerroz wrote:*   

> hey EarthWings, whens your kde battery profile program gonna be released?? 

 

I'm working on it, but no promises for a release date yet  :Wink: 

@blmartin, lampshad: I've got more time tomorrow and will have a deeper look at it.

----------

## Remenic

I am using Linux 2.6.5-gentoo-r1, and ACPI does not seem to be fireing any battery/ac_adapter events. I can check the status of the ac_adapter from /proc/acpi/ac_adapter/AC0/state, and it is updated correctly. However, the default.sh script never gets called when I unplug the AC adapter.

I have added an echo "$group" >> /tmp/acpi to see what events get passed to default.sh, and so far I've only seen the 'button' event. I have compiled the  battery and ac adapter drivers built-in.

----------

## Earthwings

What laptop are you using? For a Dell 51xx, please see http://bugme.osdl.org/show_bug.cgi?id=1752 as mentioned early.

----------

## mindstormmaster

Has anyone been able to get hibernation, using any method, to work when X is running?

I can get Suspend-to-Disk to work when X is not running, but it's a pain to have to stop X each time.

----------

## Earthwings

Yes, me  :Wink: 

But only with swsusp2. Do you use that, too? If not, try it. If yes, do you have a nvidia card? I think swsusp2 also has an option to start and stop X automatically.

@Xerroz: I think in about four weeks. It's progressing well, and I'll make a real announcement once it's ready.

----------

## redflash

I have the same problem as Remenic.

I can't recognized any events from ac_adapter or battery. 

/proc/acpi/ac_adapter/ADP0/state is changed correctly

All drivers are build in.

----------

## Earthwings

What laptop, kernel version are you using?

----------

## redflash

elitegroup G551 Centrino

kernel : gentoo-dev-sources-2.6.7-r7

----------

## Earthwings

Any ACPI related error messages in dmesg? Did you check whether a BIOS update is available?

----------

## redflash

no acpi errors and the bios is uptodate

----------

## redflash

now i use cron to look every minute

it works great

----------

## pi-r

Hello,

  First of all, thanks a lot for this wonderfull guide... But if got one problem :

            -Speedfreq doesn't work for me... (In fact it had work once, decreased the CPU freq when I unplugged the AC but when I plug the AC after, I did not have an increasing... The frequency was stable around 600 MHz...)

      I've got this strange message in /var/log/messages when I switch between the runlevel :

 *Quote:*   

> Jul 12 10:52:24 germaine logger: Switching to default runlevel
> 
> Jul 12 10:52:24 germaine rc-scripts: Could not kill pid '3680'
> 
> Jul 12 10:52:24 germaine rpc.statd[21682]: Version 1.0.6 Starting
> ...

 

   As you can see, No problem for switching from default to battery runlevel, but for the battery to default, I've got a special log...

              Thanks a lot for giving me some help...

               Pi-r

    My PC : Acer 6003lmi centrino 1.6 Ghz

----------

## noookz

I have the same problem as blmartin777.  However, my problem is my chipset isn't supported...I have Intel 440 BX/ZX/DX, so looks like I'm out of luck...  :Crying or Very sad: Last edited by noookz on Sun Aug 22, 2004 6:25 pm; edited 1 time in total

----------

## noookz

-sorry, double post

----------

## forsen

hi! is there a mirror of the howto some place? my isp have lots of problems with their routing these days, and i really want to try that howto! 

forsen

----------

## brodo

 *noookz wrote:*   

> I have the same problem as blmartin777.  However, my problem is my chipset isn't supported...I have Intel 440 BX/ZX/DX, so looks like I'm out of luck... :cry:

  Not necessarily. Compile a recent (2.6.10-rc2) kernel with CONFIG_CPU_FERQ_DEBUG enabled and CONFIG_X86_SPEEDSTEP_SMI as module, pass cpufreq.debug=7 on the boot command line, issue a "modprobe speedstep-smi" and either send me (linux AT brodo DOT de) the dmesg or post it here or in a different thread. Also append the output of /proc/cpuinfo.

----------

## brodo

 *pi-r wrote:*   

> -Speedfreq doesn't work for me... (In fact it had work once, decreased the CPU freq when I unplugged the AC but when I plug the AC after, I did not have an increasing... The frequency was stable around 600 MHz...)

  Is there a directory 

```
/sys/devices/system/cpu/cpu0/cpufreq
```

? If so, what  does cpufreq-info [see https://bugs.gentoo.org/show_bug.cgi?id=69320 ] return? Do you use an userspace cpufreq daemon like speedfreq, cpufreqd, powernowd, cpudyn, ...?

----------

## Earthwings

 *forsen wrote:*   

> hi! is there a mirror of the howto some place? my isp have lots of problems with their routing these days, and i really want to try that howto! 
> 
> 

 

http://www.gentoo.org/doc/en/power-management-guide.xml

http://www.stud.uni-karlsruhe.de/~uxhz/gentoo/power-management/power-management-guide-draft.html

Notice the latter is a draft version that contains things that are currently blocked by some bugreports.

Edit: fixed linkLast edited by Earthwings on Mon Nov 29, 2004 11:24 pm; edited 1 time in total

----------

## brodo

 *Earthwings wrote:*   

> http://www.stud.uni-karlsruhe.de/power-management-guide-draft.html

 

```
The requested URL /power-management-guide-draft.html was not found on this server.
```

----------

## Earthwings

Thanks, forgot a couple of directories...

----------

## lovecraft

 *blmartin777 wrote:*   

> I still haven't been able to resolve my problem
> 
> NO: /sys/devices/system/cpu/cpu0/cpufreq/  and I can't create one
> 
> Any ideas on what I should do.

 

Here's what I did:

1) Under Power management options -> CPU Frequency Scaling, set all processor-specific options as modules.

2) make && make install_modules, etc.

3) Look under /lib/modules/<your kernel name>/kernel/arch/i386/arch/cpu/cpufreq for a bunch of modules.

4) Choose one of these modules most relevant to your CPU and modprobe it.

You should now get a bunch of stuff under /sys to play with.  Best of luck.

----------

## samsonus

sorry, but i miss permission for the howto.

bye samsonus

----------

## catzooka

I also seem to have a problem with a Mobile Pentium 3 (Coppermine) on the Intel 440BX/ZX/DX chipset (on my Sony Vaio z505LSK notebook). Nothing shows up under /sys/devices/system/cpu/cpu0 despite having put in support in my kernel for it. I am running the latest gentoo-dev-sources at 2.6.11-r4. Interstingly enough, despite not getting any errors under dmesg, when I compile the driver support as a module, i get the error:

```
meriloon linux # modprobe speedstep-smi

FATAL: Error inserting speedstep_smi (/lib/modules/2.6.11-gentoo-r4/kernel/arch/i386/kernel/cpu/cpufreq/speedstep-smi.ko): No such device
```

Though I am pretty sure that my processor support cpu scaling, since cat /proc/cpuinfo reveals this:

```
meriloon linux # cat /proc/cpuinfo

processor       : 0

vendor_id       : GenuineIntel

cpu family      : 6

model           : 8

model name      : Pentium III (Coppermine)

stepping        : 3

cpu MHz         : 744.733

cache size      : 256 KB

fdiv_bug        : no

hlt_bug         : no

f00f_bug        : no

coma_bug        : no

fpu             : yes

fpu_exception   : yes

cpuid level     : 2

wp              : yes

flags           : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr sse

bogomips        : 1470.46
```

Also, dmesg | grep 'CPU' reveals this:

```
CPU: Intel Pentium III (Coppermine) stepping 03

ACPI: CPU0 (power states: C1[C1] C2[C2])

ACPI: Processor [CPU0] (supports 8 throttling states)

```

So, what am I doing wrong here? Or am I just out of luck, and my specific CPU isn't supported with the kernel drivers?

----------

## brodo

Please re-check that your processor does support CPU frequency scaling before doing the following:

```
modprobe speedstep-smi smi_port=0xb2 smi_cmd=0x82 smi_sig=1
```

This overrides the values reported by the BIOS with the default values for controlling SpeedStep: several BIOSes report such faulty values to the kernel, causing CPU frequency scaling not to work properly.

----------

## catzooka

Thanks a bunch, those arguments to the module worked like a charm. Thanks  :Razz: 

----------

## malusnyana

 *jarealist wrote:*   

> 
> 
> Thanks for the howto. However, I'm having a problem getting the following module to load:
> 
> <M> ACPI Processor P-States driver
> ...

 

 *Earthwings wrote:*   

> 
> 
> It's the same for me. I haven't yet figured out what the problem is, but if you did, please post here

 

Firstly, you are calling the module with an incorrect name i think. P-States module name is "acpi-cpufreq". Try modprobing that and see what you get.

It is my understanding that ACPI P-States are to allow ACPI to set the scaling of the CPU by using BIOS and DSDT interfaces. Using the CPUFreq speedstep driver changes the scaling by directly accessing the southbridge registers to change the frequency. (id be happy to be corrected on this one)

So, why would one use the Enhanced speedstepping at all, since with the ACPI P-states, you still have access to all the same govenors and frequency scaling options? Also, since the 2 modules are mutually exclusive (ie acpi-cpufreq will not load in conjunction with another cpufreq module (in my case speedstep-centrino, but i dont think this is limited to just my case obviously you cant have 2 things battling between changing the frequency, using different means).

Cheers all,

mat

----------

## dgrant

I'm also having a problem with Mobile Pentium 3 (Coppermine) on the Intel 440BX/ZX/DX chipset.

I've compiled all the acpi and cpufreq stuff as modules. I can't even load the speedstep-smi module, it reports an error, i.e. "can't insert module" or something like that.

This particular chipset is a real bitch.

----------

