# Thinkpad T420s: temperature, power consumption, battery

## YsndHalf

Hi all,

I have a Lenovo Thinkpad T420s with the following main features:

- Intel Core i7 2640M 2.8GHz

- 4GB RAM, 160GB SSD

- 14" TFT

- Wifi Ultimate-N 6300, WiMAX (what's that BTW?), WWAN UMTS/3G Ericsson F5521

- Hybrid grahics (Intel HD plus nVidia Optimus, NVS 4200M)

As you can see, that's a beast   :Cool:   so I can imagine that its battery life may not be very good.

Nevertheless, it has dual boot (I kept the original Windows 7 in a separate partition), and in Windows the battery life is significantly longer (at least 3h or so) and the laptop is in general much cooler (and the fan much more silent). In Gentoo the battery lasts at most 2h without even stressing the CPU.

I've been improving this a bit, thanks to many hints found in thinkwiki.org and other sites (including these Gentoo forums). I've found the PowerTOP utility specially interesting.

But I've reached a point where I don't know what else to do. So that's why I write you, hoping that somebody can clearly see something that I may be doing wrong...

I use to travel rather frequently, so obviously I'm interested in having better autonomy - even if that's at the expense of slightly worse performance when on battery power.

First, I use to set the CPU like this:

```
 /usr/bin/cpufreq-set -f 800000 -r 
```

...that is, the lowest frequency (800MHz). I've verified that it helps a bit. Intel and PowerTOP recommend the 'ondemand' strategy, but this minimum frequency setting gives slightly better results.

Then, after some checks, I prepared this simple script that I launch when going into battery (taken from some web that I cannot recall now):

```

echo 5 > /proc/sys/vm/laptop_mode

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

echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor

echo 1500 > /proc/sys/vm/dirty_writeback_centisecs

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

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

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

```

I've also included things like 'thinkfan' for tuning the fan level of the CPU, keeping it a bit cooler when needed (it was reaching 90ºC when emerging!), and also a bit more silent when possible (i.e. when around 40-50ºC).

I also found some recommendations such as passing the "pcie_aspm=force" (for the PCI Express) and "usbcore.autosuspend=1" options to the kernel. Or like using 'irqbalance' and adding that (init.d) to the boot level.

With all this, I get typical CPU temperatures of 55-60ºC, the fan always on (typ. level 3 over 7) - and the air temperature from the fan is indeed warm. And... the funny thing is that, in an 'idle' KDE (even with some applications open such as Chromium, Thunderbird or Eclipse), the CPU usage, even with this setting of 800MHz forced, is typ. below 10% (and most time <4-5%). Except, of course, when opening some other application or running intensive things (e.g. watching a YouTube full-screen it goes to 50%). I mean, there's nothing eating up the CPU, it's simply... hot, and that's it.

I don't know if it could be the nVidia being always on. How could I check the nVidia GPU usage?

The problem is that it seems that my X/KDE is not even detecting the nVidia Optimus! (it's just running on the Intel graphics - and OK, that's fine if that means more battery time). Even deactivating the nVidia from BIOS doesn't help.

"powertop -d" shows this (in KDE, just Kate+Konsole open, Wifi active, screen brightness around 60%, WiMAX+Bluetooth turned off by BIOS, also HyperThreading turned off but keeping both i7 cores active):

```

PowerTOP 1.13   (C) 2007 - 2010 Intel Corporation 

Collecting data for 15 seconds 

Cn                Avg residency

C0 (cpu running)        ( 3.7%)

polling           0.0ms ( 0.0%)

C1 mwait          0.6ms ( 2.9%)

C2 mwait          0.7ms ( 0.4%)

C3 mwait          1.1ms ( 0.1%)

C4 mwait          7.6ms (92.9%)

P-states (frequencies)

  2.81 Ghz     5.0%

  2.00 Ghz     0.4%

  1200 Mhz     0.5%

  1000 Mhz     0.4%

   800 Mhz    92.2%

Wakeups-from-idle per second : 172.5    interval: 15.0s

Power usage (ACPI estimate): 15.6W (3.1 hours) 

Top causes for wakeups:

  50.2% (244.4)   [xhci_hcd:usb1, ehci_hcd:usb3, i915] <interrupt>

  20.2% ( 98.3)   [Rescheduling interrupts] <kernel IPI>

  10.6% ( 51.6)   [iwlwifi] <interrupt>

   9.6% ( 46.9)   [snd_hda_intel] <interrupt>

   4.1% ( 20.1)   knotify4

   1.1% (  5.1)   [ahci, mmc0] <interrupt>

   1.0% (  4.9)   kwin

   0.8% (  3.7)   plasma-desktop

   0.8% (  3.7)   X

   0.2% (  1.1)   gam_server                                                                                                                                              

   0.2% (  1.1)   swapper/0                                                                                                                                               

   0.2% (  1.0)   krunner                                                                                                                                                 

   0.2% (  1.0)   ifplugd                                                                                                                                                 

   0.2% (  0.9)   kworker/0:3                                                                                                                                             

   0.1% (  0.5)   udisks-daemon                                                                                                                                           

   0.1% (  0.5)   kworker/u:4                                                                                                                                             

   0.1% (  0.3)   kded4                                                                                                                                                   

   0.0% (  0.2)   konsole                                                                                                                                                 

   0.0% (  0.2)   wpa_cli                                                                                                                                                 

   0.0% (  0.2)   kactivitymanage                                                                                                                                         

   0.0% (  0.2)   init

   0.0% (  0.1)   flush-8:0

   0.0% (  0.1)   [Function call interrupts] <kernel IPI>

   0.0% (  0.1)   wpa_supplicant

   0.0% (  0.1)   irqbalance

   0.0% (  0.1)   akonadi_control

   0.0% (  0.1)   akonadiserver

Suggestion: increase the VM dirty writeback time from 5.00 to 15 seconds with:

  echo 1500 > /proc/sys/vm/dirty_writeback_centisecs 

This wakes the disk up less frequently for background VM activity

Suggestion: Enable the CONFIG_INOTIFY kernel configuration option.

This option allows programs to wait for changes in files and directories

instead of having to poll for these changes

Recent USB suspend statistics

Active  Device name

  0.0%  USB device 4-1.4 : F5521gw (Lenovo)

  0.0%  USB device 3-1.6 : Integrated Camera (Chicony Electronics Co., Ltd.)

  0.0%  USB device 3-1.3 : Biometric Coprocessor (UPEK)

  0.0%  /sys/bus/usb/devices/4-1

  0.0%  /sys/bus/usb/devices/3-1

  0.0%  USB device usb4 : EHCI Host Controller (Linux 3.2.12-gentoo ehci_hcd)

  0.0%  USB device  1-1 : USB Receiver (Logitech)

  0.0%  USB device usb3 : EHCI Host Controller (Linux 3.2.12-gentoo ehci_hcd)

  0.0%  USB device usb2 : xHCI Host Controller (Linux 3.2.12-gentoo xhci_hcd)

  0.0%  USB device usb1 : xHCI Host Controller (Linux 3.2.12-gentoo xhci_hcd)

Runtime Device Power Management statistics

Active  Device name

  0.0%  0d:00.0 USB controller: NEC Corporation uPD720200 USB 3.0 Host Controller 

100.0%  05:00.0 System peripheral: Ricoh Co Ltd Device e823 

100.0%  03:00.0 Network controller: Intel Corporation Centrino Ultimate-N 6300 

100.0%  00:1f.3 SMBus: Intel Corporation 6 Series/C200 Series Chipset Family SMBus Controller 

100.0%  00:1f.2 SATA controller: Intel Corporation 6 Series/C200 Series Chipset Family 6 port SATA AHCI Controller 

  0.0%  00:1d.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 

100.0%  00:1c.4 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 5 

100.0%  00:1c.3 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 4 

100.0%  00:1c.1 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 2 

100.0%  00:1c.0 PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 1 

100.0%  00:1b.0 Audio device: Intel Corporation 6 Series/C200 Series Chipset Family High Definition Audio Controller 

  0.0%  00:1a.0 USB controller: Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #2 

  0.0%  00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection 

100.0%  00:16.3 Serial controller: Intel Corporation 6 Series/C200 Series Chipset Family KT Controller 

100.0%  00:02.0 VGA compatible controller: Intel Corporation 2nd Generation Core Processor Family Integrated Graphics Controller 

100.0%  00:00.0 Host bridge: Intel Corporation 2nd Generation Core Processor Family DRAM Controller 

Devices without runtime PM

00:1f.0 ISA bridge: Intel Corporation QM67 Express Chipset Family LPC Controller 

00:16.0 Communication controller: Intel Corporation 6 Series/C200 Series Chipset Family MEI Controller #1 

Recent audio activity statistics

Active  Device name

Recent SATA AHCI link activity statistics

Active  Partial Slumber Device name

```

The Kernel config can be found here. My feeling is that it should be something wrong in the kernel configuration, but... what?

Many, many thanks in advance...

----------

## BillWho

YsndHalf,

I always thought that gentoo, or any linux distro for that matter, would suck less power than windoze, but I now stand corrected   :Embarassed: 

This isn't going to make a big difference, probably none at all, but this line:

```
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
```

is only setting cpu0 - or so it seems. The following

```
for p in $(sed -n '/processor/p' /proc/cpuinfo|cut -d: -f2); do cpufreq-set -c $p -g powersave;done
```

could be used instead to set all the cpus.

cpufreq-info will display available governors for the cpu.

Good luck   :Cool: 

----------

## YsndHalf

BillWho, many thanks! I was a bit sleepy when copying those commands into that script   :Razz:   so I didn't realize that it was setting the CPU governor (I'm already setting that separately - and I do consider all the CPUs).

Regarding the windoze/linux issue, yes, I fear that the Lenovo guys sell their laptops with a very-well-prepared windoze installation (with all the power utilities, etc), so it will be tricky to beat that.

Anyway I must say that I'm very happy with my Gentoo there. It's running very smooth  :Smile: 

Cheers!

----------

## DirtyHairy

I have a very similar configuration; the only difference is graphics (and the hard drive, I have no SSD): no discrete graphics, only the integrated intel HD. When near-idling (writing text, code, surfing the web, etc). I have a power consumption of 9 - 11 watts, giving me a battery life with the stock battery of well above 3 hours. I didn't invest much time in power tuning; I use the ondemand governor (laptop-mode-tools is very handy for setting the governor).

However, I have found the intel GPU has a deep power-saving mode which was deactivated by default somewhere around 2.6.39 -> 3.0 due to issues on some systems which makes a difference of  2- 3 watts for me. You can activate it by adding

```
i915.i915_enable_rc6=1
```

to the kernel command line. If you'd like to use your nvidia chip after all: http://www.bumblebee-project.org/ might do the trick...

----------

## toralf

With a T420 I do this (http://bpaste.net/show/42623/) thinkfan config file currently test. At least the values in /sys/devices/system/cpu/cpu?/thermal_throttle/package_power_limit_count are all 0 so I'm with that config file I'm on the safe site IMHO.

----------

## YsndHalf

Hi all,

thanks for your latest hints!

A few days ago I updated the kernel to 3.4.9 and... it seemed to improve the battery life!

That was forcing the nVidia to Disabled in BIOS (completely disabled, not even trying to detect that 'optimus' automatic feature).

A few days later I wanted to give BOINC/Seti@home's CUDA a try  :Wink:   so I activated again the nVidia through Bios, restarted and... found that I forgot to update the nVidia drivers after the kernel update. I did it, and then I was able to use CUDA  :Smile:   (amazing computing power, considering that it's a laptop...)

After that small experiment, I assessed that leaving nVidia activated through Bios significantly warms up the laptop (and obviously reduces the battery time). So I deactivated it... but afterwards I was seeing some ~10-15% continuous CPU usage. That was some knotify4, some kworker I think, and things like that. Hmm. Dammit.

I checked that no nvidia module was loaded. I also removed the nvidia section/screen from my X config. I saw once the 'modprobe' process consuming some CPU (???). And... I finally tried removing the nvidia-drivers, and deleting the nvidia.ko module from the lib folder. And it seems to work! The CPU usage is negligible again, and (I'll check tomorrow) the battery seems to last as before - about 2h or so with a normal usage.

For some reason it seems that the... kernel? tries to use the nvidia module even without having the nVidia card activated through Bios, so if you really want the best battery simply remove everything.

FYI, just in case it helps somebody else...

Cheers!

----------

## depontius

A couple of notes...

I don't have a T420 - I have a W510, quite a different beast, but many of the same problems.  I also have friends around here with other Thinkpads and have seen them have problems like this.

* There have been some reports that its better for power to use "ondemand" instead of "powersave" for the governor.  The concept is called "race-to-idle", and that you're better off running as fast as possible until everything is done, then go into the deeper idle states to save more power.

* From what I've read, the best OSS video drivers are for Intel - AFAIK the only company with a significant presence in OSS video driver development.

* From what I've heard, the OSS video drivers aren't that hot (or more precisely, cool) with the power issue - except for Intel.  If you need to use nVidia or ATI video and want the best possible power, you're probably better off with the proprietary drivers.  That said, I'm using Nouveau, though my W510 spends most of its time in its port replicator.

* XOrg really can't use the switchable video like Windows can - yet.  They're getting there - a whole bunch of infrastructure needs to be built, and that work is getting done.  At some point in the future you will be able to get the low power of the Intel graphics when graphical demands are light, then have the nVidia hardware kick in when the going gets tough.  That may well come some time in the next year.

* With current XOrg, the dual video can be problematic.  You're probably best off going whole-hog with one video or the other.  Either disable nVidia in BIOS, or fully install nVidia support.  Doing the job halfway results in a slow, crash-prone system.

----------

