# Laptop Battery Issue

## xtx

Brand new Asus UX31 (core i5, ssd, 4 gigs ram) with a fresh gentoo install. Asus advertises a 6+ hour battery life, however, I only get about 2 hours. 

I have installed laptop_mode_tools and started it. cat /proc/sys/vm/laptop_mode returns 5 when it is on battery power, so it is working. 

kernel 3.2.1-gentoo-r2

```
Power Management and ACPI Options

  [*] Suspend to RAM and standby

  [*] Run-Time PM core functionality

  [ ] Power Management Debug Support

  [*] ACPI Support --> 

    [*] Deprecated /proc/acpi files

    [*] Deprecated power /proc/acpi directories

    <> EC read/write access through /sys/kernel/debug/ec

    [*] Deprecated /proc/acpi/event Support

    <*> AC Adapter

    <*> Battery

    -*- Button

    -*- Video

    <> Fan

    [*] Dock

    <*> Processor

    <*> Processor Aggregator

    <*> Thermal Zone

    [ ] Debug Statements

    <> PCI slot detection error

    [*] Power Management Timer Support

    <*> Smart Battery System

    <> Hardware Error Device

    <> Allow ACPI methods to be inserted/replaced at run time

    [] ACPI Platform Error Interface

  [ ] SFI Support -->

  [*] CPU Frequency scaling --->

     [*] CPU Frequency scaling

     <> CPU frequency translation statistics

           Default CPUFreq governor (userspace) -->

      <*>   'performance' governor

      <*>   'powersave' governor

       _*_   'userspace' governor

      <*>   'ondemand' governor

      <*>   'conservative' governor

           

                x86 CPU frequency scaling drivers -->

                     <> Processor Clocking Control interface driver

                     <*> ACPI Processor P-States driver

                     < > AMD Opteron/Athlon64 PowerNow!  

                     < > Intel Enhanced SpeedStep (deprecated)

                     < > Intel Pentium 4 clock modulation

      _*_ CPU idle PM support

      [*] Cpuidle Driver for Intel Processors

            Memory power savings

                      <*> Intel chpiset idle memory power savings driver

```

On an unrelated note the laptop also does not resume from 'sleep'. it only shows a black screen with a single, solid, underscore in the top left of the screen.

----------

## CrankyPenguin

As a first point I see you have "userspace" set as your frequency default.  Do you have an appropriate governor running in userspace?  If not then support or no support your system may just be running at full power.  I don't think that the laptop-mode-tools handles userspace frequency scaling out of the box.  

As a second point is hdparm setup properly for your system?  

Keep in mind that the 6+ advertisement is based upon the assumption that you will do absolutely nothing with it other than turn it on, let the screen go dim and never, ever, ever, open a file  :Smile: 

----------

## xtx

changed my frequency default to conservative. recompiled, restarted, clicked on the battery icon, and i'm just watching it without moving the mouse, with the screen at the dimmest possible setting. the kde battery monitor is estimating about 3 hours 10 minutes. while that is a full hour better than before, it is still only 50% what is advertised.

forgive my ignorance, this is my first linux laptop, but i've never heard of hdparm before. i'll start googling it right now but would welcome any info/advice about it that you guys may have.

i also don't even know what having an appropriate governor in userspace means... i'll look that up too.

----------

## candamil

https://forums.gentoo.org/viewtopic-t-920122.html

Same problem. Do you have an hybrid graphics system? If so, maybe it's what I'm thinking and the dedicated video card is draining your battery, as mine.

----------

## xtx

 *candamil wrote:*   

> https://forums.gentoo.org/viewtopic-t-920122.html
> 
> Same problem. Do you have an hybrid graphics system? If so, maybe it's what I'm thinking and the dedicated video card is draining your battery, as mine.

 

i don't have a hybrid graphics system, i have "intel hd graphics 3000" according to the ux31 spec sheet. this is very frustrating, how is windows so much more effecient in regard to battery consumption?

----------

## candamil

It's the same integrated graphics card as in mine. Maybe there is a power saving issue with this card in Linux...

----------

## xtx

that is very possible... if you figure this out please let me know. i just bought this laptop for school and 2 hour battery life (while being used) is not going to get me through my night classes

----------

## candamil

I was using powertop yesterday and the Intel module was one of the most actives. 

If I find anything else I'll let you know.

----------

## xtx

I just found http://www.phoronix.com/scan.php?page=article&item=intel_i915_power&num=2, i'll let you know how the settings work

----------

## xtx

definitely add those settings to your grub.conf. mine now looks like:

```

default 0

timeout 3

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Gentoo Linux 3.2.1-r2 Small

root (hd0,0)

kernel /boot/kernel-3.2.1-r2-small root=/dev/sda2 i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1
```

when i let my system idle the kde battery monitor estimated 5+ hours of battery life. now that i'm using the browser it currently estiamtes 4 hours 22 minutes (and it's only at 91% charged).

still might not be as good as windows but it's much, much closer nowLast edited by xtx on Sat Apr 14, 2012 4:43 pm; edited 1 time in total

----------

## candamil

Ok, I'll give it a try. If it works, I'll try to do a script to change it without reboot (I'm not sure if we can reload the Intel module without hanging the whole system)

----------

## xtx

how necessary is laptop_mode_tools? what does it do differently than kde's default power save features? i only ask because it slows down my boot process

----------

## candamil

I have used your options to boot and, yes, there is an important increase in the battery life (about 4:30).

I used it and also this script I made:

```

#!/bin/bash

mount -o remount,relatime /

hdparm -B 1 -S 12 /dev/sda

echo 5 > /proc/sys/vm/laptop_mode 

echo 40 > /proc/sys/vm/dirty_ratio

echo 10 > /proc/sys/vm/dirty_background_ratio

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

echo min_power > /sys/class/scsi_host/host0/link_power_management_policy

echo powersave > /sys/module/pcie_aspm/parameters/policy

echo 1 > /sys/devices/system/cpu/sched_mc_power_savings

echo 1 > /sys/module/snd_hda_intel/parameters/power_save

/etc/init.d/mysql stop

/etc/init.d/ntpd stop

/etc/init.d/NetworkManager stop

/etc/init.d/cupsd stop

killall akonadiserver

killall akonadi_control

killall wpa_supplicant

```

but I was not using laptop_mode_tools. Now it's a little late here, tomorrow I'll try with it, and we'll see if the improvement is big or not. In windows it lasted 5:36, so there should be more things to do.

----------

## xtx

good to hear the improved battery life. another boot option that the article mentions is "pcie_aspm=force" if you want to give that a try

----------

## candamil

News with my tests. I tried with all of that booting parameters (even the pcie_aspm), with laptop_mode (it just changes some parameters of some files, just as my script does, but is useful anyway), and without using my script. I didn't use the prediction of the energy manager, because it is quite wrong. I just did some maths, and my prediction after 30% of the battery is that it would last between 3:55 and 3:58. It's an hour more than before, but it's still 1:30 less than in windows, so I think there is still a lot of work here. And the fan didn't turn on in the whole test, a good new.

I'll try all the parameters in my script, one by one, because I'm not sure that all of them really help to increase the battery life. Then, I'll put here the results, after each test.

I'll also try removing the widgets in my desktop. I had a couple of temperature and CPU load meters, and maybe they are using more energy than I think.

So, let's begin with this.

PARAMETERS:

- WiFi OFF (hardware)

- Screen brightness: minimum

- Screen off time: none

- Graphic effects OFF

- Sound UNmuted

- Opened programs: acroread

- External hardware: none

- Optimus server started

- Laptop mode server started

- Boot parameters: <deleted for powersaving issue> i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1

- CPU mode: conservative

- ACPI server started

Test 1:

- With widgets

- Without any other configuration

TIME: 3:55 - 3:58

Test 2:

- Same configuration

- Without widgets

TIME: 4:06 - 4:09

Test 3:

- Same configuration

- Without the pcie_aspm=force parameter

TIME: 4:13 - 4:15

Test 4:

- Same configuration

- Added script parameters:

```

#Discrete video card

/etc/init.d/optimus stop

rmmod nvidia

insmod /home/candamil/programas/acpi_call/acpi_call.ko

echo '\_SB.PCI0.PEG0.PEGP._OFF' > /proc/acpi/call

#Miscellaneous

echo 90 > /proc/sys/vm/dirty_ratio

echo 1 > /proc/sys/vm/dirty_background_ratio

echo 6000 > /proc/sys/vm/dirty_writeback_centisecs

echo 9 > /proc/sys/vm/swappiness

#Services

/etc/init.d/mysql stop

/etc/init.d/ntpd stop

/etc/init.d/NetworkManager stop

/etc/init.d/cupsd stop

#Processes

killall akonadiserver

killall akonadi_control

killall wpa_supplicant

killall java

```

TIME: 6:45 - 6:48 <<<< CRAZY!

--------------------------------------------------------------------------

TESTS WITH LOAD

Script:

```

#!/bin/bash

while true

do

        emacs &

        xterm &

        let j=3

        for i in {1..200000}

        do

                let j=j**5

                echo $j

        done

        sleep 30

        ffmpeg -i /home/candamil/test/video-test.avi -acodec libmp3lame -b:a 128k -vcodec libxvid -b:v 600k -aspect 16:9 /home/candam

il/test/deleteme.avi 

        sleep 30

        rm /home/candamil/test/deleteme.avi

        wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.3.2.tar.bz2 -O /home/candamil/test/deleteme.dl

        sleep 30

        rm /home/candamil/test/deleteme.dl

        glxgears &

        sleep 30

        killall glxgears

        killall xterm

        killall emacs

        sleep 30

done

```

PARAMETERS:

- WiFi ON

- Screen brightness: minimum

- Screen off time: none

- Graphic effects OFF

- Sound UNmuted

- External hardware: none

- Laptop mode server started

- Boot parameters: i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1

- CPU mode: conservative

- ACPI server started

- irqbalance server started (added after test 2)

Initial parameters script:

```

#!/bin/bash

#Discrete video card

/etc/init.d/optimus stop

rmmod nvidia

insmod /home/candamil/programas/acpi_call/acpi_call.ko

echo '\_SB.PCI0.PEG0.PEGP._OFF' > /proc/acpi/call

#Miscellaneous

echo 90 > /proc/sys/vm/dirty_ratio

echo 1 > /proc/sys/vm/dirty_background_ratio

echo 6000 > /proc/sys/vm/dirty_writeback_centisecs

echo 9 > /proc/sys/vm/swappiness

#Services

/etc/init.d/mysql stop

/etc/init.d/ntpd stop

/etc/init.d/cupsd stop

#Processes

killall akonadiserver

killall akonadi_control

killall java

```

Test 1:

- irqbalance OFF

TIME: 3:13 - 3:18

Test 2:

- irqbalance ON

TIME: 3:53 - 3:58

Test 3:

Added

```

#WiFi

iwconfig wlan0 power on

ethtool -s wlan0 wol d

 

#Wired LAN

ethtool -s eth0 wol d

ethtool -s eth0 autoneg off speed 100

```

TIME: 3:38 - 3:44

Test 4:

Added

```

#Hard drive

mount -o remount,relatime /

```

TIME: 3:55 - 3:58

Test 5:

Added

```

#Hard drive

hdparm -B 1 -S 6 /dev/sda

```

TIME: 3:53 - 3:58

Test 6:

Added

```

#Hard drive

for dev in /dev/sd[a-z]; do blockdev --setra 3072 $dev; done

```

TIME: 3:55 - 4:00

Test 7:

Added

```

#Sound

echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller

```

TIME: 3:55 - 3:58

Test 8:

Added

```

#Miscellaneous

echo noop > /sys/block/sdb/queue/scheduler

for i in $(ls /sys/bus/{pci,i2c}/devices/*/power/control);do echo auto > $i;done

for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done

for i in /sys/bus/usb/devices/*/power/control; do echo auto > $i; done

```

TIME: 3:55 - 4:00

Test 9:

Added

```

#Processor

echo conservative | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

echo 1 > /sys/devices/system/cpu/cpufreq/conservative/ignore_nice_load

echo -n 40 > /sys/devices/system/cpu/cpufreq/conservative/down_threshold

echo -n 90 > /sys/devices/system/cpu/cpufreq/conservative/up_threshold

```

TIME: 4:00 - 4:01

Test 10

Added

```

#Power managers

for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo min_power > $i; done

echo 1 > /sys/devices/system/cpu/sched_mc_power_savings

echo 1 > /sys/devices/system/cpu/sched_smt_power_savings

echo 1 > /sys/module/snd_hda_intel/parameters/power_save

```

TIME: 3:55 - 3:57

Test 11

Added apparently irrelevant code, all together.

```

#Hard drive

for dev in /dev/sd[a-z]; do blockdev --setra 3072 $dev; done

#Miscellaneous

echo noop > /sys/block/sdb/queue/scheduler

for i in $(ls /sys/bus/{pci,i2c}/devices/*/power/control);do echo auto > $i;done

for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done

for i in /sys/bus/usb/devices/*/power/control; do echo auto > $i; done

```

TIME: 3:50 - 3:53Last edited by candamil on Mon Apr 23, 2012 6:48 am; edited 22 times in total

----------

## candamil

Another hint that maybe is useful: in powertop, the first activation reason is [Rescheduling interrupts] <kernel IPI>

Maybe this is also an important problem... In my case, it's about 150 when idle, and about 400-500 when surfing with chrome.

----------

## candamil

Added new test. As soon as my battery is fully loaded, I'll try without the pcie_aspm parameter, as I have read that it could drain more battery.

----------

## candamil

Added new test without the pcie_aspm=force parameter.

Tomorrow I'll start with script parameters.

----------

## hephooey

 *candamil wrote:*   

> Added new test without the pcie_aspm=force parameter.
> 
> Tomorrow I'll start with script parameters.

 

Try to upgrade your kernel as well, the infamous aspm bug is fixed in 3.2.5, 3.2.1 still have the bug (unless gentoo patched it) and pcie_aspm=force will not help , should be able to save a few watt.

----------

## candamil

In fact I am using 3.2.12-gentoo, but as you can see, there is no big difference adding or removing that parameter.

----------

## candamil

Added test with massive improvement for nvidia discrete card users.

----------

## xtx

Solid! Quick question for anybody that reads this, I noticed today (for the first time) that when my laptop was plugged in and then I removed the power, the laptop would immediately shut off. This never happened before but it happened 3 times in a row. I can boot up without power and the battery works fine then...

Anyway, your tests made me want to do some of my own tests, so here it goes:

PARAMETERS: 

- WiFi ON (ath9k driver Atheros AR9485WB-EG)

- Screen brightness: minimum 

- Screen off time: none 

- Graphic effects ON

- Sound UNmuted 

- Opened programs: none

- External hardware: none 

- Boot parameters: i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1  

- CPU mode: conservative 

- With desktop widgets

Test 1: 

- Boot option pcie_aspm=force

- Laptop mode server started 

TIME: ~6 hours 35 minutes

I will do two more tests, one without laptop mode started, and another without pcie_aspm=forceLast edited by xtx on Mon Apr 16, 2012 8:41 pm; edited 5 times in total

----------

## candamil

what I do to measure the time is wait until the battery is full, then unplug and then each 5% calculate the time until 4% with the minutes that passed. 

For example, start time 10:00, 95% at 10:13, 2.6 minutes per %, 249 minutes until 4%, 4:09. 

I finish each test when the prediction stabilizes, normally at about 60-50% remaining.

----------

## candamil

I tried to boot without any parameter extra an then load the parameters of i915, but it doesn't work as well as when you boot directly with them. Discarded.

----------

## xtx

Ok I will start paying attention to that now as well.

Any clue why my laptop is crashing when I unplug it from power?

----------

## candamil

If you are using laptop_mode, maybe it is changing any parameter that does the fail. As I have seen, laptop_mode changes several parameters that you can change manually without that tool (like in the script I am doing). Did you try to unplug without the laptop_mode service enabled?

----------

## candamil

I have done another test with more parameters in my script, but the time is half an hour less, so nevermind.

Anyway, there is still one last thing I would like to test. All the test until now were with the computer idle. That's the best way to do always the test in the same conditions but I think that's not a real test, I mean, a test in real conditions. Not only that, but also the last parameters I tried were all concerning the processor, so maybe the  battery life in idle is a little less, but with load is more. 

So now I would like to do a couple of test with load, but I would like to do all the test with the same load, some kind of moderate load concerning all the systems, processor, WiFi, hard drive... The best way to do all of that stuff is a script, so it's time to think about a script that could do the work. I was thinking about something like this:

```

- Open emacs

- Open xterm

- Do some kind of complex or long mathematic operation (maybe a loop with multiplications or powers)

- Wait 30 seconds (to avoid the fan as much as possible)

- Compress a video, maybe an episode of any show, with ffmpeg

- Wait 30 seconds

- Delete the compressed video

- Wget with some file, maybe a linux kernel. It's not too small, it's not too big.

- Wait 30 seconds

- Delete the downloaded kernel

- Open glxgears

- Wait 30 seconds

- Kill glxgears

- Kill xterm

- Kill emacs

- Restart script

```

What do you think? Would you add or remove anything?

----------

## xtx

looks good to me, let me know how the test goes.

i noticed you mention powertop before but i forgot to look into it until today. i installed and ran it, it gave recommendations for kernel settings which i did, and offered to edit some files for power saving features which i let it, and it seems to have extended my battery life considerably. i also installed irqbalance which supposedly helps keep interrupts low. my wakeups-from-idle while i let my system idle are around 45 and when i browse the web it's around 250. the i915 is still the culprit for the largest number of interrupts. how do these numbers compare to yours?

after all was said and done i let my system idle with the screen completely dimmed and i had an estimated 8 hour battery life.

----------

## candamil

 *xtx wrote:*   

> looks good to me, let me know how the test goes.
> 
> i noticed you mention powertop before but i forgot to look into it until today. i installed and ran it, it gave recommendations for kernel settings which i did, and offered to edit some files for power saving features which i let it, and it seems to have extended my battery life considerably. i also installed irqbalance which supposedly helps keep interrupts low. my wakeups-from-idle while i let my system idle are around 45 and when i browse the web it's around 250. the i915 is still the culprit for the largest number of interrupts. how do these numbers compare to yours?
> 
> after all was said and done i let my system idle with the screen completely dimmed and i had an estimated 8 hour battery life.

 

In my case, the amount of wakeups are very similar to yours, 20-30 when idle, 100-300 right now, with chrome and gentoo forum opened (id depend's if I'm using the trackpad or not, if I'm typing or not...).

I'll try with irqbalance and then I'll do the test with load. When I'm finished, I'll let you know the results.

----------

## candamil

I have just tried with irqbalance, but I think it's not a real improvement in my system when idle. Anyway, I'll post right now the test I'm going to do with load, and then I'll post the result of each test when I do it.

----------

## xtx

any tips for lowering the wakeups? what DE do you run? i'm wondering if mine is higher since i'm using kde

----------

## candamil

I'm using KDE too. I don't have any other hint to lower the wakeups. Anyway, I think that as it is, it's a quite good performance. I've been searching for more possibilities, but I didn't find any other. If I find another thing I'll let you know.

----------

## candamil

Added test 1 results with load.

----------

## candamil

Added test, results with irqbalance. Obviosly better, almost an hour more.

----------

## candamil

Added test 3, slightly worse results. Configuration discarded.

----------

## Xytovl

In recent kernels (I am testing 3.4-rc) i915 has more values for rc6.

Do modinfo i915 to check if it is on/off or multivalues.

```
i915_enable_rc6:Enable power-saving render C-state 6. Different stages can be selected via bitmask values (0 = disable; 1 = enable rc6; 2 = enable deep rc6; 4 = enable deepest rc6). For example, 3 would enable rc6 and deep rc6, and 7 would enable everything. default: -1 (use per-chip default) (int)
```

----------

## candamil

Added test 4. Same results than in best test until now, but since last upgrade, the brightness levels have changed, so I need to repeat the best test, just to have a proper reference.

Xytovl I am using a 3.2.12 kernel, so for now I don't have those options.

----------

## candamil

Added test 5. No difference.

----------

## candamil

Added test 6. Slightly better, but irrelevant.

----------

## candamil

Added test 7. No changes.

----------

## xtx

you're doing awesome work. somebody should document your results (somewhere more permanent than this thread) so that laptop gentoo users can know what options do and do not affect battery life. it wasn't long ago both of us were getting 2 hours battery unloaded.

----------

## candamil

 *xtx wrote:*   

> you're doing awesome work. somebody should document your results (somewhere more permanent than this thread) so that laptop gentoo users can know what options do and do not affect battery life. it wasn't long ago both of us were getting 2 hours battery unloaded.

 

I'm not sure that the final configuration would help, because it depends a lot on your particular hardware. I think that everybody should do the tests to check each configuration in their own system. Anyway, yes, it would be a good idea to have all the possible configurations to do the tests.

Added test 8. Irrelevant.

I think I'm doing a test 11 with that configurations that seem irrelevant, but maybe a couple of minutes of one and a couple of minuts in the other can get a good improvement if used together.

----------

## candamil

Added test 9, slight improvement.

----------

## candamil

Added test 10. Slightly worse.

----------

## candamil

Added test 11. Worse.

----------

## candamil

I have a doubt regarding this issue.

OK, if I configure the i915 module as a module in the kernel, and if I set that configuration to the grub kernel parameter, it is configured and it works. Now, if I configure it embedded in kernel, not as a module, and I keep that grub parameters, do they work the same way?

----------

## Baer

Thanks for this great article. I try to build Gentoo for my UX31 atm and can't replay some of the problems

* Exactly where comes the nvidia-driver into play? As far as I know there's no nvidia hardware built into this box.

* hdparm fails for me, when trying to set up "-B 1" :

```
# hdparm -B1 /dev/sda

/dev/sda:

 setting Advanced Power Management level to 0x01 (1)

 HDIO_DRIVE_CMD failed: Input/output error

 APM_level   = not supported
```

Is there any quick way to fix this?

I'm currently using gentoo-sources 3.3.5 from standard portage.

Regs

Baer

----------

## candamil

If your box has no nvidia hardware, then you don't need to worry about it. In my case, I have two graphics cards, so I need to deactivate the nvidia card if I want the battery to last longer.

It seems your hard drive doesn't support the powersave mode, so you can't use it. What do you get with hdparm -i /dev/sda?

----------

## Baer

Ah ok, i'm pretty sure the UX31 doesn't have nvidia hardware in it, so let's simply close this topic.  :Smile: 

The output from hdparm looks like this:

```
# hdparm -i /dev/sda

/dev/sda:

 Model=SanDisk SSD U100 256GB, FwRev=10.01.02, SerialNo=114433301341

 Config={ Fixed }

 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0

 BuffType=unknown, BuffSize=unknown, MaxMultSect=1, MultSect=off

 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=500118192

 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}

 PIO modes:  pio0 pio1 pio2 pio3 pio4 

 DMA modes:  mdma0 mdma1 mdma2 

 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6 

 AdvancedPM=no WriteCache=enabled

 Drive conforms to: unknown:  ATA/ATAPI-4,5,6,7

 * signifies the current active mode
```

----------

## candamil

Yep, as you can see, your hard drive doesn't support the powersave parameter:

AdvancedPM=no

So you can't use it  :Razz: 

----------

