Lenovo Thinkpad X300 and Linux – Configuration and power management

I recently replaced my Macbook with a Lenovo Thinkpad X300 notebook. Here are some notes and tips concerning GNU/Linux installation and configuration for an optimal day to day use.

UPDATE (2011/07)

Here are my current settings for power management :

/etc/rc.local: Simplified, no more vm.laptop_mode (not useful with a ssd).

# Audio powersave
echo 1 > /sys/module/snd_hda_intel/parameters/power_save

# For thinkfan
echo watchdog 0 >| /proc/acpi/ibm/fan
chmod 666 /proc/acpi/ibm/fan

# For PHC Voltage regulation kernel patch http://www.linux-phc.org
echo 15 15 15 >| /sys/devices/system/cpu/cpu0/cpufreq/phc_vids
echo 15 15 15 >| /sys/devices/system/cpu/cpu1/cpufreq/phc_vids

/etc/thinkfan.conf: Simplified, less fan, more silence :)

(0,     0,      40)
(1,     35,     58)
(2,     56,     64)
(5,     58,     128)

Do not forget to follow powertop indications.

First, the specs of this new toy:

* Intel® Core 2 Duo SL7100

* 2x1Go PC2-5300 DDR

* 64GB SSD

* 1.61 Kg with 6 cells main battery and Ultrabay 3 cells secondary battery

Hardware

Then, lspci output:

00:00.0 Host bridge: Intel Corporation Mobile PM965/GM965/GL960 Memory Controller Hub (rev 0c)
00:02.0 VGA compatible controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
00:02.1 Display controller: Intel Corporation Mobile GM965/GL960 Integrated Graphics Controller (rev 0c)
00:19.0 Ethernet controller: Intel Corporation 82566MM Gigabit Network Connection (rev 03)
00:1a.0 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #4 (rev 03)
00:1a.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #5 (rev 03)
00:1a.7 USB Controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #2 (rev 03)
00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 03)
00:1c.0 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 1 (rev 03)
00:1c.1 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 2 (rev 03)
00:1c.2 PCI bridge: Intel Corporation 82801H (ICH8 Family) PCI Express Port 3 (rev 03)
00:1d.0 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #1 (rev 03)
00:1d.1 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #2 (rev 03)
00:1d.2 USB Controller: Intel Corporation 82801H (ICH8 Family) USB UHCI Controller #3 (rev 03)
00:1d.7 USB Controller: Intel Corporation 82801H (ICH8 Family) USB2 EHCI Controller #1 (rev 03)
00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev f3)
00:1f.0 ISA bridge: Intel Corporation 82801HBM (ICH8M-E) LPC Interface Controller (rev 03)
00:1f.1 IDE interface: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) IDE Controller (rev 03)
00:1f.2 SATA controller: Intel Corporation 82801HBM/HEM (ICH8M/ICH8M-E) SATA AHCI Controller (rev 03)
00:1f.3 SMBus: Intel Corporation 82801H (ICH8 Family) SMBus Controller (rev 03)
03:00.0 Network controller: Intel Corporation PRO/Wireless 4965 AG or AGN [Kedron] Network Connection (rev 61)

About lsusb, just one useful line:

Bus 003 Device 002: ID 0483:2016 SGS Thomson Microelectronics Fingerprint Reader

Important note: since I disabled Bluetooth, WiMAX and the touchpad in the BIOS,

they are not present in lspci and lsusb outputs, but both Bluetooth and touchpad are functional with Ubuntu.

Quite a modern hardware, and thus some issues concerning Linux support. Indeed, only the 2.6.28 offers a good support, previous versions are either bugged or hackish.

Operating System

I chose Ubuntu 9.04 beta for an easy yet fine setup, with LVM+Crypto for the root partition. However a bug in xserver-xorg-evdev in 64 bits edition breaks the must-have trackpoint scrolling feature. Thus, I decided to run 32-bit version, despite a 64 bits CPU.

Most of the hardware components work out the box, without particular setup, including the webcam. The only regression compared to previous kernel versions is the integrated microphone, which remains disabled. I hope to fix it out soon. However, the jack input line is fully functional. Update: just run alsamixer, type tab to enter in the Capture section and enable the internal microphone. Speakers offer a good (and loud) sound experience, quite surprising from a Thinkpad notebook.

No particular thoughts on Ubuntu itself, except that Jaunty Jackalope will certainly bring a better user experience than ever (new themes, new notification system, general speed improvements, boot time dramatically reduced…).

Power management

Now the real deal: how to maximize battery operation and lifetime with the Lenovo Thinkpad X300?

The average base power consumption is 14 W, WiFi on, 75% backlight, some terminals and Firefox.

First, disable everything you will never use in the BIOS. Currently, I disabled Bluetooth, WiMAX, Wireless WAN (3G), »USB Wifi » (wtf?) and touchpad. Saving: 2 W

Then disable Wake On Lan, unless you need it. It keeps the Gigabit Ethernet Controller to remain in an active state that actually use energy. Saving: 1W

Moreover, I blacklisted the e1000e module, since I mainly use WiFi. When I need wired connection, I simply modprobe it.

Then concerning the wlan0 WiFi interface, just run:

iwconfig wlan0 power on

in order to active Power Management. Saving: 0.5W

Some sysctl tweaking in /etc/sysctl.conf:

vm.laptop_mode = 5  # Activating laptop mode, power friendly I/Os
vm.dirty_writeback_centisecs = 2000
kernel.nmi_watchdog = 0
vm.swappiness = 5

And in /etc/rc.local:

echo 10 > /sys/module/snd_hda_intel/parameters/power_save
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
echo min_power > /sys/class/scsi_host/host1/link_power_management_policy

Saving: 2W

Quite simple, heh? :) Now, my average consumption is 8.8W, allowing a real use of the X300 for more than 6 hours, instead of 4h30.

Last thoughts

The internal fan management is kinda broken in Linux. The workaround is to append thinkpad_acpi to /etc/modules and options thinkpad_acpi fan_control=1 to /etc/modprobe.d/fan for instance.

Then you could use thinkfan and this sample thinkfan.conf:

# thinkfan example config file
# ============================
#
# Syntax:
# (LEVEL, LOW, HIGH)
#
# LEVEL is the fan level that's written to /proc/acpi/ibm/fan
# LOW is the temperature at which to step down to the previous level
# HIGH is the temperature at which to step up to the next level
# All numbers are integers.
#
# You can put spaces anywhere you want. Anything that doesn't match this
# syntax is ignored.
#
# The number of tuples is limited by the size of your system memory.
#
# WARNING: Sanity checks are only made for correct ordering of the fan levels
# and for (LOW < HIGH) within one tuple. You can still use any kind of insane
# temperature limits.

(0,     0,      50)
(1,     48,     58)
(2,     54,     61)
(3,     56,     63)
(4,     58,     65)
(5,     60,     66)
(7,     63,     128)

Concerning lithium batteries, you should keep them charged between 40% and 80%. It is quite easy to do with Thinkpads: just append tp_smapi to /etc/modules, and the upper charge limit will be set to 86%, which is a good compromise. Moreover, instead of completely drain the Ultrabay battery before switching to the main battery, you can manually force discharge; as root type:

echo 1 > /sys/devices/platform/smapi/BAT0/force_discharge

But do not forget that even if you replug your laptop, discharge will resume anyway!

Thus, you have to bypass forced discharge; as root type:

echo 0 > /sys/devices/platform/smapi/BAT0/force_discharge

Annoying workaround, but I will try to find or code a proper solution.

UPDATE: See my Baswim script here.

That’s all folks!