PowerTop is a script which shows you whether the computer's CPU is spending time in low-power states.
Low power states are great for your battery life, and for the planet. But latency is also important, and some processes cause the CPU to "wake" out of low-power states very regularly.
PowerTop has a nice display which tells you the processes which are
waking the CPU, so you can
kill -9 them as needed.
The kernel also wakes up the CPU. For example, it will wake up the CPU and the hard disk, so that it can free memory (ie: to do swapping, aka paging).
This is controllable using
/proc/. PowerTop suggests that
is set to
1500 (15 seconds), and you can set this by hitting
on the appropriate line.
This is one example, and PowerTop has a lot more suggestions. You can set them all by:
Job done... except that the values in
/proc/ reset every time you restart
Time for some automation!
Systemd is how modern linux boots up.
It's efficient and has a lot of features.
/usr/sbin/powertop --auto-tune as root, every time the computer
The man page for
eventually tells you to put your scripts in
We want this to run as part of boot, which means it's
WantedBy a fully booted
multi-user.target). This matches the
in the documentation.
WantedBy is one of many options to describe the dependency tree, as it
tries to describe which things which happen in parallel and which have strict
ordering. A useful overview of the end result is:
sudo systemctl list-dependencies
We want to run a command, so we need a
service. Other types of unit are a
target (roughly equivalent to a SystemV runlevel) and a
socket (you can
create a socket first, and then start the server and client in parallel)
The different types of service are listed in the
We want to run a script and exit, which is
Most services would want to think about the security-related options given in
which include the ability to protect
/proc/ from a service
running as root.
But we need to be powerful here - we write to
It ends up being a simple script.
[Unit] Description=Run powertop auto-tune [Service] Type=oneshot ExecStart=/usr/sbin/powertop --auto-tune [Install] WantedBy=multi-user.target
The script should probably have permissions
You will need to get Systemd to reload its config files:
sudo systemctl daemon-reload
make sure it runs at all:
sudo systemctl start powertop-h2g2bob.service sudo systemctl status powertop-h2g2bob.service
and enable it to run at boot:
sudo systemctl enable powertop-h2g2bob.service
Done! Power is saved, every time.