Comment réduire sa consommation électrique avec GNU/Linux ?
image/svg+xml
Comment réduire sa consommation électrique avec GNU/Linux ?
Michael Opdenacker
JDLL 2023, Lyon
How to reduce power
consumption with GNU/Linux ?
Free Software enthusiast
Founder of Bootlin
Embedded Linux Software Engineering
Headquarters are in Lyon ;-)
Author of free training materials
(Embedded Linux, Linux kernel, Linux
boot time reduction...)
Contributor to the Linux Ecology HOWTO
in the 2000s.
Michael Opdenacker
Following the energy crisis and the climate emergency
Need to save energy rather than producing more
GNU/Linux allows to use your hardware longer
Project to update the "Linux Ecology HOWTO"
Why this presentation?
Have longer running time on battery,
make the battery life longer
Learn how to make my penguin
hibernate
Sharing our best techniques
More technical motives
Main target hardware: laptops running GNU/Linux
Too : desktop computers, servers
And (a bit) : embedded Linux boards
Target of this presentation
Measure your consumption
Suspending, hibernating
Screen management
Frequency and performance
Identifying the top sources
of power consumption
Covered topics (1)
Measure your power consumption
Disabling unused devices
Making good use of generated
heat--
Covered topics (2)
Licence Creative Commons - BY - SA - 4.0
https://creativecommons.org/licenses/by-sa/4.0/
Raspberry Pi 3 Model B V1.2
Power
HDMI
Audio
USB 2x
USB 2x
ETHERNET
DSI (DISPLAY)
CSI (CAMERA)
GPIO
© Raspberry Pi 2015
Questions?
michael.opdenacker@bootlin.com
Link to presentation
https://bootlin.com/pub/conferences/2023/jdll/
Presentation made with Free Software: Sozi and Inkscape
Presentation sources and image credits:
https://gitlab.com/michaelopdenacker/reduce-power-consumption-with-gnu-linux
Get your hands on a wattmeter
New : about 20 EUR / USD
Not ideal for measuring the total
consumption of a PC (measured in kW),
but good for instant consumption (W)
This will be useful for other devices
in your household.
Suspend your system
Almost everything is off, except RAM
Negligible consumption for the wattmeter.
But still can drain your battery in a few days.
Very easy to do whenever you leave your PC:
- From the command line
- With systemd
How to suspend your system?
Should be easy with any graphical distro
From the command line (with systemd):
systemctl suspend
Or with a low-level command (doesn't lock the screen):
sudo sh -c "echo mem > /sys/power/state"
How to wake up your system?
It's always easy to suspend than to wake-up
On a PC, just need to press the power button
Sometimes, just moving a USB mouse is enough
The wake-up sources can be found in
/sys/class/wakeup/
More details on
https://wiki.archlinux.org/title/Power_management/Wakeup_triggers
No simple solution on a remote server
to resume from suspend.
Summary
Suspend your system every time
you leave it.
Make it hibernate every night, and using
a master switch, switch off all devices,
including the ISP box (if possible).
While traveling, use hibernation to extend
the lifetime of your battery.
The CPU frequency automatically adapts
to the activity of your programs.
Pay attention of the power consumption
of your screens.
Harvest dissipated heat
Let your imagination guide you
My leaven loves my Livebox
(ISP box, consumption: 12 W)
Other idea...
Hibernate your system
The state of your system is stored on disk,
and them your system is switched off.
Better for long periods of inactivity , because no power
consumption and not wearing out the battery in a laptop.
Unfortunately, not often available by default in recent
distributions.
Not very difficult to set up fortunately.
Hibernation principles (1)
Hibernation is based on suspending to RAM
To hibernate:
1. You simulate suspending to RAM.
The state of devices is stored in RAM.
2. All the RAM gets copied to disk
Need a swap partition or a file at least as big as RAM.
3. The machine is switched off.
Hibernation principles (2)
For waking-up:
1. The system is powered on. Linux boots.
2. The memory contents are restored from
the contents stored on disk.
3. We resume from RAM,
as if we were returning from suspend.
How to set up hibernation? (1)
Need space on disk to store
the RAM contents
Simplest solution : a swap partition almost
as bit as the RAM size
Otherwise, possible to store the RAM contents
in a file, but a little bit more complicated:
https://ubuntuhandbook.org/index.php/2021/08/enable-hibernate-ubuntu-21-10/
How to set up hibernation? (2)
1. Find the UUID of your swap partition
cat /etc/fstab | grep UUID=
2. Add
resume=UUID=xxxx
to
GRUB_CMDLINE_LINUX_DEFAULT
in
/etc/default/grub
3. Update Grub's configuration file:
sudo update-grub
Tested on Ubuntu 22.04
How to trigger hibernation?
Easy to do with Systemd
(the most exhaustive soulution: locks the session):
systemctl hibernate
The low-level solution (no session locking):
sudo sh -c "echo disk > /sys/power/state"
How to get out of hibernation?
Power-on your system, that's all!
On a remote server, possible to use
"Wake on LAN"
1. Enable this in the BIOS
2. Find the MAC address of the network interface of your server:
ip a
3. Pass this address to the wakeonlan command :
wakeonlan f8:ca:b8:17:44:02
Sending magic packet to 255.255.255.255:9 with f8:ca:b8:17:44:02
Easy to do for a machine on the same network, but possible too
(under some conditions) on a remote network.
Add a "hibernate" option (1)
Tested on Ubuntu 22.04
Start GNOME's Extension Manager:
extension-manager
Look for "Hibernate Status Button", install and activate
this extension.
Add a "hibernate" option (2)
Tested on Ubuntu 22.04
You also have to create the
/etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
file:
[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;
org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;
org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes
Source :
https://ubuntuhandbook.org/index.php/2021/08/enable-hibernate-ubuntu-21-10/
Beware of the consumption of your screens
Laptop doing nothing, maximum brightness
14.88 W
Laptop doing nothing, minimum brightness
10.04 W
Laptop doing nothing, screen off
7.44 W
Conclusion: a display at maximum brightness can represent
half of the power consumption of your PC when it's not
running anything.
How to switch off your screens?
Not very practical because of
sudo
:
$ sudo vbetool dpms off
(bof: avec sudo)
$ sudo vbetool dpms on
More convenient to switch off a specific screen:
$ xrandr -q
(identifier les écrans)
$ xrandr --output DP-2-3 --off
(éteindre)
$ xrandr --output DP-2-3 --auto
(rallumer)
Wasn't working for me on a system with a single screen
The easiest solution to switch off your screens without
suspending a probably screen locking (Super - L)
But better to go to suspend if your PC is idle!
Adapt your CPU performance
Ubuntu offers standard options to control
CPU frequency.
This is based of the "cpufreq" infrastructure
of the Linux kernel. You can even have
different settings for each CPU core!
GNOME CPU Power Manager Extension (1)
GNOME offers more specific options
to control the frequency and performance
of your CPU.
GNOME CPU Power Manager Extension (2)
Compiling the Linux kernel ("defconfig" configuration on x86)
- "High performance" : 14:37 min (active mode: 35W, passive mode: 10 W)
- "Power save" : 40:45 min (active mode: 15,5 W (average), passive mode: 15 W)
- "Multimedia" : 13:47 min (active mode: 38W, passive mode: 13W)
- "Silent" : 36:20 min (active mode: 17.8 W, passive mode: 12W)
=> A bit surprising results, which I should run again starting from a cold mother
board. It seems that power management takes temperature into account.
Thanks to the participants for this plausible explanation!
Lessons learnt:
- The "Power save" mode guarantees a minimal energy consumption. Good when
running on battery..
- The "High performance" mode doesn't make your system run at full speed all the
time. It just authorizes to run at full speed.
(a bit raw) performance tests
PowerTop - Available everywhere
Measures the most consuming tasks on your PC.
Also gives you advise for improving settings.
Need to be root and operate on battery (more information):
$sudo powertop
Which will consume 30 times less ?
If what you need is a server or a display controler.
An exception to the rule of keeping your hardware.
PowerTop - Overview
PowerTop - Tunables
Replace your big old PC by an embedded board
Detect tasks consuming most energy
New options in the "power" menu
What's "Hybrid Sleep"?
It's suspending and hybernating at the same time
- If you get back to your computer quickly, it wakes up instantly
- If you leave your computer for a longer time, the battery could drain
completely, but when you switch it on again, you get back to the saved
state thanks to hibernation.
That's like a safer "Suspend" option, but not an alternative to hibernation,
which is the only one preserving your battery.
1
Title
Michael Opdenacker
Why this presentation?
More technical motives
Target of this presentation