TLP - Don't go chasing power management


Updated: January 9, 2017

AKA The Myth of Power Management in Linux. Today, I am going to talk to you about a sensitive topic. The battery life of your laptop, when eastbound and down, loaded up and running with Linux. Can you extend it? Can you make Linux eat less juice?

Enter TLP, a tool designed to bring you the benefits of advanced power management for the glorious benefit of optimized battery life. It is a command-line utility and it is intended for people with good Linux skills, even though it advertises itself as being approachable even by people who are less than l33t nerds. So let's see what gives shall we?

The story

I am normally skeptical when it comes to tweaks. In general, your performance will be first and foremost limited by your hardware. It's not like software vendors are totally clueless or purposefully crippling systems so you get less than ideal results. On average, default configurations, kernel, software, whatever, are fairly good, designed for most typical workloads, and under normal conditions, they are just as good as any.

I've discussed this to some extent in my third Linux cool hacks guide. Changing tunables under /proc and /sys will not create any miracles. On servers, under special conditions, yes, maybe. In your home? Nah. You will not be able to tell the difference, no matter what scheduler or swappiness ratio you choose. Seriously.

Then, there's a tool like TLP, and it promises a lot. It is available for most major distros, and it can help with things like dirty buffer timeouts, Wi-Fi and audio power saving, scheduling, disk spin down, Wake-on-LAN, ALPM, and more. All of this sounds quite fascinating, so I decided to test the utility and check how useful and accessible it really is to the common user. In fact, this is probably the most important piece here, and the one I want to validate. Can normal users truly tap into the power of TLP? And for that matter, do advanced users really need this tool, or can they manually manage their systems in an effective way?

Combat test

I installed TLP on Fedora 24, following the online instructions. There are some odd problems here and there, like masking the systemd-rfkill service, which did not seem to work. But starting TLP worked just fine.

sudo systemctl mask systemd-rfkill@.service
Failed to execute operation: Invalid argument

sudo systemctl enable tlp

Once you enable TLP, it will load with the default configuration, which is stored under /etc/default/tlp. Your next step is to examine the file, see the default options, and the slowly start making changes. But if you want to be effective, you will need to do this in a very structured way: 1) keep backups 2) be fully aware of what each option does 3) only make one change at a time 4) reliably measure the difference in your performance and battery life as a result.

To fully gain from TLP without fooling yourself with a nice placebo effect or random luck of your erratic browsing habits, you will need a lot of time, and I doubt most people will be interested in a proper experiment methodology. Second, every setting has its good and bad sides, and you really need to understand what you're doing. Then, you can always check your currently load config with the tlp-stat command:

sudo tlp-stat

--- TLP 0.9 --------------------------------------------

+++ Configured Settings: /etc/default/tlp
TLP_ENABLE=1
TLP_DEFAULT_MODE=AC
DISK_IDLE_SECS_ON_AC=0
DISK_IDLE_SECS_ON_BAT=2
MAX_LOST_WORK_SECS_ON_AC=15
MAX_LOST_WORK_SECS_ON_BAT=60
SCHED_POWERSAVE_ON_AC=0
SCHED_POWERSAVE_ON_BAT=1
NMI_WATCHDOG=0
ENERGY_PERF_POLICY_ON_AC=performance
ENERGY_PERF_POLICY_ON_BAT=powersave
DISK_DEVICES="sda sdb"

+++ PCIe Active State Power Management
/sys/module/pcie_aspm/parameters/policy = default (using bios preferences)

+++ Intel Graphics
/sys/module/i915/parameters/powersave   = (not available)
/sys/module/i915/parameters/enable_rc6  =  1 (enabled)
/sys/module/i915/parameters/enable_dc   = -1 (use per-chip         default)
/sys/module/i915/parameters/enable_fbc  =  0 (disabled)

I started exploring what each options does and how it affects the system. Just so you know, whatever you choose in the configuration file actually maps to a tunable under /sys, and if you're savvy enough, you can manually play. Do be warned that you could cause damage or inconvenience to yourself if you set a wrong parameter. For example, you can offline your CPU cores, you can delete SATA devices, and so forth. You really need to be careful and confident.

Furthermore, while tweaking, I also installed powertop, and had it running, so I could gage the power consumption. Powertop will also report on your tunables, and whether it thinks they are correctly set up - by correctly, I mean power-friendly.

Moreover, you also need to establish a baseline, and this is quite difficult when running a GUI and using Wireless. The simple geometric positioning of your laptop in relation to the router antenna will determine some of the power bleed. The desktop will also have its own noise, with processes spinning up and down, and your power usage will fluctuate a good percentage without you doing anything significant.

Powertop 1

Powertop 2

In a nutshell

There will be four major parameters affecting your battery life, apart from the physical properties of the actual battery. One, CPU utilization. I could probably spend a whole day talking about power management in processors, C states, P states, BIOS firmware, and how the kernel affects this whole thing. But it comes down to - the more power you're using, the more you drain the battery. Base frequency and then how high up and how quickly you go when there are increased workloads.

Two, Wireless - the strength of your signal and the utilization of the antenna. Very dependent on the actual setup. Three, screen brightness. Four, the graphics card, and it could potentially be the chief culprit, depending on your setup. The drain will depend on your usage model first and foremost, not the idle power usage. Everything else is just to keep you busy and happy.

It's all about the drivers

And so we go to the one thing that makes everything tick - the drivers. Your hardware will behave based on how it's configured and how the operating system interfaces with the different components. If your distro does not fully support the hardware stack, you will probably have a sub-optimized power utilization. No matter how diligently you try to improve on the little things, at the end of the day, it's about the big things.

Media works fine

So what about drivers? Just think Nouveau vs Nvidia. Think whether the driver set you get on Linux is optimal. Think about certain processor families, especially newer models, not being fully supported on Linux. Think of the various kernel versions. You introduce so much variance through the software stack it becomes very difficult to keep an accurate track of your power drain.

Optimization & examples

Yes, you CAN improve on the current state by potentially tuning the system down to a less aggressive level. But ultimately, the benefits will be far outweighed by the sheer drain through normal activities.

You could tweak your system, but the fine changes are dwarfed by the raw power use when you spin up workloads. For example, my Lenovo Ideapad Y50-70 machine uses about 15W idle, but can spin up to about 115W under full load.

Now, let's say you can optimize the baseline down to about 10W, which is a very respectable 33% improvement. But then, if your CPU bursts to about 50W for even one second, it will take roughly 10 seconds of total idleness to compensate for that compared to the average load. If you're doing meaningful things, idle usage optimizations will not make much difference.

I talked a lot vaguely - let's see some practical examples, and I will definitely draw on my experience from the HPC world, as I have outlined in my problem solving book. Let's look at what we can do. To wit:

CPU_SCALING_GOVERNOR_ON_AC=powersave
CPU_SCALING_GOVERNOR_ON_BAT=powersave

This setting selects the CPU scaling governor for automatic frequency scaling. Configuration depends on the active driver.

All right. But what does this actually mean? Well, it means you will have better performance and/or lower power usage if you're heavily utilizing your CPU. You will see decent differences if you're running 24/7 100%. Less so otherwise. The functionality also depends on your BIOS firmware and settings. However, the reality is far more complicated than this. For example, you could read some kernel documentation just to get a better impression how tricky this whole thing is. In fact, you really need to understand what you're doing and what algorithms you need to change. Server stuff really.

DISK_IOSCHED="deadline cfq"

You won't see any big difference really. Honest, miss.

PCIE_ASPM_ON_AC=performance
PCIE_ASPM_ON_BAT=powersave

This settings sets PCIe ASPM power saving mode on kernels 2.6.35 and above. It is part of the PCI Express Bus tweaks available through TLP. If you have no idea what this actually means, Intel has a lengthy paper on the topic.

Then, we have some dangerous options like overvolting - which also requires kernel patching. Nope. Wi-Fi power management - can lead to degraded signal, which could lead to slower upload and download rates, which could then lead to longer times needed to get things done. So what is cheaper, your antenna working at 100% or your browser eating through bytes while it spends extra time handling the traffic? And so on and on.

End state

It's the matter of value. How much effort you invest versus gain. You will benefit from having the right set of drivers more than anything for your given hardware. Under normal work conditions, all other savings will be minimal. Screen brightness will give you as much as tweaking the CPU, which will often be running at about 10-20% anyway. And then, the choice of software will also dictate what happens. The desktop environment and the app stack is a great example - cleaner, lighter code = less CPU.

The best practical example is MX-15 or Fedora 24 versus say openSUSE or such. We're talking roughly 4.5 hours versus 2.5 hours. And for that matter, Windows 10 on my notorious Lenovo G50 box also gives a very respectable 4-5-hour battery life. Same hardware, so much variance, even only counting Linux distros and excluding the whole Windows side of things. Tweaking does not really matter here.

Conclusion

Advanced power management and TLP work, do not get me wrong. They sure do. But not for you, the ordinary users at home, trying to make your laptops drink less juice. Yes you can, but there are simpler, faster, safer ways of doing it. Some luck with the distro choice to begin with, screen brightness and where you sit in relation to the Wireless antenna. These will be an order of magnitude more important than any risky little tweak you try.

Which is why you should not play with things that affect such important parameters in your system. If anything, these should be exposed through simple GUI options, and most distros do actually let you control some of that. But you do not have access to the underlying bits and pieces, and that's an important distinction.

My recommendation is - no matter how tempted you are - do not change things under /sys, do not fiddle, do not tweak. That won't end well for most of you, and you won't even know why. If you're not a kernel expert, you have no reason to tamper with it, and the small gains will be nothing compared to your sanity and some best practices, the biggest of which is the right choice of the desktop environment. Enjoy your Linux escapades. See you around, fellas.

Cheers.

RSS Feed icon

del.icio.us del.icio.us stumbleupon stumble digg digg reddit reddit slashdot slashdot



Advertise!

Would you like to advertise your product/site on Dedoimedo?

Read more

Donate to Dedoimedo!

Do you want to
help me take early retirement? How about donating
some dinero to
Dedoimedo?

Read more

Donate