The tools: top, iotop, powertop2

The hardware: Lenovo X230, HDD, 29Wh battery (nominal)

The software: Fedora 20, KDE 4.12, Linux 3.13 to 3.14

Idle power consumption: about 11W with WiFi on, brightness 20% (Linux 3.13), about 9.5W with WiFi off, Linux 3.14.

Goal: get as much battery time as possible for productive work.

Computer usage patterns

The easiest way to reduce power consumption is to turn it off. However, this is not very useful. Because of that, the first step in reducing power usage is to identify how I'm going to use the computer. This will let me avoid removing functionality which I actually need.

The programs and devices I will probably use:

  • Firefox with noscript - keep my docs open
  • USB modem + NetworkManager
  • gkrellm & plasma monitors - useful for knowing whether I'm killing the CPU
  • email client
  • Konversation - even though it logs conversations to filesystem as they come
  • ssh
  • text editors & IDEs
  • PDF readers

These features will need to stay enabled and behave somewhat decently while on battery.

Basic optimizations

The basic rule of optimization is: if you don't need it, don't use it. I attempted to disable unnecessary features while keeping the system somewhat idle, somewhat work-ready.

Services

The first line of optimizations is to disable unnecessary services. On KDE side, one of the first ones to go was Klipper (right-click icon, quit, do not start).

Next was Nepomuk: System settings -> Desktop search -> Basic settings -> uncheck Enable Nepomuk Additional services at your leisure.

System-wide services are another thing wasting cycles. Postfix, fingerprint daemon, nfs, had to stop.

After applying those changes, at 20% backlight, the system took about 9.5W.

Power states

powertop --calibrate will help you figure out what consumes how much power. You will probably need to unlplug first.

Powertop suggests many optimizations that you can enable for moderate gain (1-2W idle gain on my system). Most of them don't have significant drawbacks (are you really using power-on-lan on your laptop?). I usually turn on all except VM Writeback timeout for fear of data loss (this delays writes to disk to help it spin down, but it didn't change much for me).

You should also disable any devices you're not using (preferably in BIOS), like the camera or bluetooth module. You might want to flip the physical WiFi switch.

CPU

Any program ececuting will wake the CPU and make it consume power. For those, we have the basic tool - top. Ideally, all non-crucial programs should stay at 0.0% CPU usage. While I'm writing this post, four processes stand out:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND  
  695 root      20   0  222500  46396  27484 S   4.6  1.2   6:03.13 X        
  981 rhn       20   0 3258612  87304  37772 S   3.3  2.3   3:38.16 kwin     
  994 rhn       20   0 3530188 171456  48828 S   3.0  4.4   5:03.44 plasma-+ 
 2887 rhn       20   0  979396  36796  17800 S   2.3  1.0   0:33.99 gedit    

Looks good - no obvious wasted resources.

Let's look at the details with powertop. You might follow the estimates of power usage to identify processes that keep the CPU in a higher power state than necessary. The only non-crucial process that's above 10 mW on my system is ksysguardd, but it's a required for my CPU monitoring widgets.

I/O

The second obvious way to drain power is to do I/O activity. While I don't know about a way to monitor per-process network traffic in Linux (pointers appreciated), I can find out the HD usage.

Any disk write will prevent the HD from spinning down, making it consume power. This doesn't apply to all reads, as these can be cached in RAM - as long as these are reads from the same resource.

Despite disabling all unneeded services the HDD didn't spin down on my system and I could hear a faint noise coming from the computer. Using iotop -a and leaving it on for a few minutes, I found some programs writing to disk when the system was idle:

  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND       
  300 be/3 root          0.00 B     48.00 K  0.00 %  0.63 % [jbd2/sda5-8]
  545 be/3 root          0.00 B    132.00 K  0.00 %  0.33 % [jbd2/sda6-8]
  387 be/4 root        104.00 K    264.00 K  0.00 %  0.10 % systemd-journald

Ideally, nothing should exceed 0 on this screen.

The first two, jbd2-sda5-8 and jbd2-sda6-8, are kernel threads, having something to do with my root and home partitions. My educated guess is that they manage metadata written by some userspace applications. Unfortunately, I don't know a way to trace which application exactly is causing the writes, but they usually happened together with other writes.

noatime

That's why I decided to act preemptively and add noatime option to my / and /home mount points. Additional benefit of this is that your system should be much faster after this change. Excerpt from /etc/fstab:

UUID=XXXXXXXXX /                       ext4    defaults,noatime        1 1
UUID=XXXXXXXXX /boot                   ext4    defaults        1 2
UUID=XXXXXXXXX          /boot/efi               vfat    umask=0077,shortname=winnt 0 0
UUID=XXXXXXXXX /home                   ext4    defaults,noatime        1 2

Make sure you restart your machine immediately to catch errors early.

WARNING: mistakes may break your system. Have a rescue system ready (e.g. live USB).

ModemManager

systemd-journald writes pointed me to the system journal, where broken programs might leave warnings. journalctl --since=today revealed that ModemManager is misbehaving:

May 03 21:31:20 movable ModemManager[630]: <info>  Modem /org/freedesktop/ModemManager1/Modem/1: signal quality updated (40)

There's no need for this kind of spam on my system. Unfortunately, documentation is scarce and I could only find how to disable it temporarily.

$ mmcli -G WARN
Successfully set logging level

Another way (you may have to replace ModemManager1 with something else, look at your logs):

$ dbus-send --system --dest=org.freedesktop.ModemManager1 --print-reply /org/freedesktop/ModemManager1 org.freedesktop.ModemManager1.SetLogging string:Warn
method return sender=:1.2 -> dest=:1.59 reply_serial=2

If you know how to make it permanent, let me know.

Work-time optimizations

The second line of defense is reducing power usage from programs you actually use. I'm going to re-analyze iotop results under some load.

Firefox proved to do many unnecessary writes even when it wasn't used. The most likely reason for that is that a web page keeps doing something in the background (very bad for power consumption). I recommend only keeping simple web sites open, using NoScript or some strict Adblock rules.

There are some programs in KDE that write for reasons unknown to me. Why does an idle Okular need to touch the filesystem every few minutes? Why does Dolphin and plasma-desktop do the same?

Nothing really can be done about programs that modify files on your hard drive - like file editors, development environments, email client or messengers with logging on.

There's another way however to deal with this.

SSD

You might use a solid-state drive for frequently accessed files, like your workspace or to store logs or keep data of misbehaving programs. Additional device means more power consumption, but if it allows HD to spin down and stay that way most of the time, then the overall power usage should be less. Of course, you need to have a place to put the SSD in - my computer has a free mSATA slot.

I'm going to use it for Firefox, system logs, IRC logs, emails and my immediate workspace.

Keep in mind that this is not SSD caching. SSD caching captures accesses and writes everything to the HD anyway again, but later, after HD can catch up. That means you have a faster system, but you write everything twice. We don't want that.

I decided to go the easy way: some hot places from /home will be symlinked to a SSD partition for ease of testing and to save SSD space. I'm going to move /var/ completely to SSD as well:

  • /home/.cache: for the odd program writing
  • /home/tmp: likewise
  • /home/logs: Konversation chat logs
  • /home/.mozilla: for Firefox needs
  • /home/.claws-mail: local copy of emails

I will update with results as soon as I buy an SSD :)

Troublesome programs

Speech dispatcher

This one was detected with powertop. pulseaudio created 200 wakeups/s, and there were some input streams in pavucontrol named "speech-dispatcher-something". In my case, it was activated by Mumble and never turned off after I turned off Mumble.

I'm never going to remember to kill it manually after I use Mumble on AC power, therefore I disabled it completely by adding the following line in /etc/speech-dispatcher/speechd.conf:

# The DisableAutoSpawn option will disable the autospawn mechanism.
# Thus the server will not start automatically on requests from the clients
DisableAutoSpawn 1

Power loss: 1.5W

libvirtd

I use it extensively, but it leaves network interfaces running all the time until manually stopped. Powertop says they are using power, so I disable them just in case using virt-manager. Power loss: 0?

Results so far

Before I optimized my system, it took 11W while idle on Linux 3.13. After the optimizations idle power usage, it took 8.5W while idle. The next step is to measure power usage while working.

This article will be updated as I find new ways to kill power usage

Profile

rhn

rhn

An open source culture enthusiast (really "Free Source"), software developer, tinkerer in all things electronic. Slight privacy nut. Cyclist, occasional gamer. Some projects: http://rhn.github.com/.

Syndicate

RSS Atom

Expand Cut Tags

No cut tags