Post

Optimising power consumption with cpupower

Optimising power consumption with cpupower

There are several ways that I try to watch and reduce the electric consumption of the devices in my home lab, some are upgrading the devices to more efficient ones, but that pretty much only happens when the device I have is completely gone and can’t be fixed, even then it is mostly the parts themselves that are being replaced or upgraded.

One of the things I started lately implementing, and it is a shame I did not do this much much earlier - using cpupower package - something that has been around for a while.

cpupower is a linux package that allows you to optimize your system’s power management. It is a Linux utility tool, part of the kernel itself, which is used to fine-tune CPU settings on managing power consumption and performance.

I did research a bit of history as I always do on everything that I use and the power management infrastructure in the Linux kernel has evolved quite a bit over time. In the early days, CPU frequency scaling was managed by individual programs like cpufreqd, cpudyn, and powersaved. But as the kernel evolved, these separate utilities were unified and migrated into the kernel, which provided better efficiency and control. Eventually, this coalesced into what we now call cpupower.

Some links may be affiliate links that keep this site running.

Getting hands on with cpupower

First thing first, you need to have cpupower installed on your system. For most Linux distributions, the command would be something like this on debian systems:

1
sudo apt install cpupower

and on Ubuntu systems you’ll need to run:

1
sudo apt install linux-tools-common linux-tools-`uname -r`

Once you have cpupower installed, let’s check the current frequency settings using the following command:

1
cpupower frequency-info

This command will display a wealth of information, including the driver in use, the current and available CPU frequencies, the governor in use, and more.

CPUpower frequency info CPUpower frequency info

I host majority of my cloud instances on HostHatch VPS (Virtual Private Server) Instance (In Asia) for a steal. Some of the other hosts I use are RackNerd (US) and WebHorizon (Asia+Europe) VPS, and decided that it is time to move away from Linode - which is a Great service, but I am looking to reduce the billing on instances. For comparison, I save more than 50% on HostHatch compared to Linode ($3.33 compared to $8) - Don't get me wrong, if this was an extremely (like REALLY) critical application, I would keep it on Linode.

The Governors’ Conference: Understanding The Different States (I tried to make a joke here) When it comes to CPU frequency scaling, the different settings, or “governors”, determine how your CPU will adjust its frequency in response to the system load. Each governor follows a different policy which suits different scenarios. Let’s take a look at these governors:

  • Performance: This governor sets the CPU to its maximum frequency, ensuring the best possible performance. It is perfect for high-demand tasks, like gaming or video editing, but it consumes the most power.
  • Powersave: Quite the opposite of the Performance governor, the Powersave governor sets the CPU at its lowest possible frequency, thus conserving power. However, this comes at the expense of performance. _ Userspace: This is an interesting one! The Userspace governor allows the user to set the CPU’s operating frequency manually. This provides the most control but requires a deep understanding of your system to use effectively.
  • OnDemand/Conservative: These two governors dynamically adjust the CPU frequency based on the system load. The OnDemand governor rapidly increases the frequency when the load goes up, providing a balance between power saving and performance. On the other hand, the Conservative governor is more cautious and gradually scales up the frequency, focusing more on power saving.
  • Schedutil: The newest kid on the block, the Schedutil governor, utilizes the kernel’s scheduler utilization data to make its frequency decisions, aiming for a balance between power and performance. To change the governor, you can use the cpupower command followed by the frequency-set option and -g flag. For instance, to set the governor to performance mode, you would use:

To change the governor, you can use the cpupower command followed by the frequency-set option and -g flag. For instance, to set the governor to performance mode, you would use:

1
sudo cpupower frequency-set -g ondemand
This post is licensed under CC BY 4.0 by the author.