How to reduce power consumption with GNU/Linux? image/svg+xml How to reduce power consumption with GNU/Linux?   Michael OpdenackerToulouse, 2023 How to reduce powerconsumption with GNU/Linux ? Free Software enthusiastFounder of BootlinEmbedded Linux Software EngineeringStrong presence in Toulouse ;-)Author of free training materials(Embedded Linux, Linux kernel, Linuxboot time reduction...)Contributor to the Linux Ecology HOWTOin the 2000s. Michael Opdenacker Following the energy crisis and the climate emergencyNeed to save energy rather than producing moreGNU/Linux allows to use your hardware longer Why this presentation? Have longer running time on battery,make the battery life longerLearn how to make my penguinhibernateSharing our best techniques More technical motives Main target hardware: laptops running GNU/LinuxToo : desktop computers, serversAnd (a bit) : embedded Linux boards Target of this presentation Measure your consumptionSuspending, hibernatingScreen managementFrequency and performanceIdentifying the top sourcesof power consumption Covered topics (1) Measure your power consumption Disabling unused devicesMaking good use of generated heat Covered topics (2) For more accurate measurements Using the ACME board from BaylibreCost : about 100 EUR / USD (thanks for the gift!)Open Source Hardware and Software for accuratemeasurement of power consumption.Perfect to measure the consumption of embeddedboards or small circuits.This allowed me to measure the consumptionof my BeagleBone Black (ARM). Unfortunately,it's hard to make this board suspend to RAMor even go idle. It seems special firmware is neededand I still have issues building it.https://baylibre.com/acme/https://bootlin.com/blog/power-measurement-with-acme/ Let your penguin relax Suspend to Idle Meaning of "mem" in /sys/power/state When you are not using your computer any more.Linux can support 4 energy saving states: - "Suspend-To-Idle" (freeze) : devices are suspended, The CPU stops executing processes ("idle").- "Standby / Power-On Suspend" (standby) : Same, but with some additional processors switched off. Never seen on the systems I own.- "Suspend-to-RAM" (mem) : everything but RAM is switched off- "Suspend-to-disk" (disk) : hibernate to disk - everything is off and the RAM contents are kept on storage.See which modes are available:$ cat /sys/power/statefreeze mem diskhttps://www.kernel.org/doc/Documentation/power/states.txt According to kernel documentation, the "Freeze" mode is always available anddoesn't require any special hardware support, at least at the processor level.- The CPU stops executing processes- The devices are suspended or even turned off (requires drives able to suspend them)- The CPU has nothing left to do and therefore switches to an "idle" mode, enabling to cut the power supply of some of its hardware blocks and save a lot of power.- Suspend to Idle remplaces Suspend to RAM when the latter is not supported on your hardware. Except in this case, the only advantage of this mode is reduced wake-up time (< 1s instead of 3-4s), which is not significant on a PC (but may be useful on an embedded system always trying to switch to a power saving mode whenever possible).To trigger a switch to this mode:sudo sh -c "echo freeze > /sys/power/state"To wake up your system, same techniques as for Suspend to RAM (see next slides). mem in /sys/power/state can take several meanings:If Suspend-to-RAM is available, deep appears in /sys/power_memsleep:s2idle [deep]- Here [deep] means that by défaut, mem corresponds to Suspend-to-RAM.- s2idle (Suspend-To-Idle, "freeze") is available but not selected.You can temporarily change the default setting:sudo sh -c "echo s2idle > /sys/power/power_memsleep"Or in a permanent way by editing the kernel command line, byadding mem_sleep_default=s2idle to GRUB_CMDLINE_LINUX_DEFAULTin /etc/default/grub. Then run sudo update-grub. Suspend to RAM vs. hibernate? On old Dell Latitude laptop- Estimated life of a 100% charged battery : 1h12- Suspended: -6.9% (94 mAh) per hour- Hibernated: remains at 100% after one night.On a recent Dell XPS laptop- Estimated life of a 100% charged battery : 8h30- Suspended: -0.8% (58 mAh) per hour- Hibernated: remains at 100% after one night.Avoid wearing out your battery by using hibernation! Licence Creative Commons - BY - SA - 4.0https://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 and its sources:https://bootlin.com/pub/conferences/2023/cdl/ Presentation made with Free Software: Sozi and Inkscape Get your hands on a wattmeterNew : about 20 EUR / USDNot ideal for measuring the totalconsumption of a PC (measured in kW),but good for instant consumption (W)This will be useful for other devicesin your household. Suspend your system Almost everything is off, except RAMNegligible 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 distroFrom the command line (with systemd):systemctl suspendOr 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-upOn a PC, just need to press the power buttonSometimes, just moving a USB mouse is enoughThe wake-up sources can be found in/sys/class/wakeup/More details onhttps://wiki.archlinux.org/title/Power_management/Wakeup_triggersNo simple solution on a remote serverto resume from suspend. Summary Suspend your system every timeyou leave it.Make it hibernate every night, and usinga master switch, switch off all devices,including the ISP box (if possible).While traveling, use hibernation to extendthe lifetime of your battery.Install the TLP service to deactivate unuseddevice and enable power friendly settings.The CPU frequency automatically adaptsto the activity of your programs.Pay attention of the power consumptionof your screens. Harvest dissipated heat Let your imagination guide youMy 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 powerconsumption and not wearing out the battery in a laptop.Unfortunately, not often available by default in recentdistributions.Not very difficult to set up fortunately. Hibernation principles (1) Hibernation is based on suspending to RAMTo 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 contentsSimplest solution : a swap partition almostas bit as the RAM sizeOtherwise, possible to store the RAM contentsin 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/grub3. Update Grub's configuration file: sudo update-grubTested on Ubuntu 22.04 How to trigger hibernation? Easy to do with Systemd(the most exhaustive soulution: locks the session):systemctl hibernateThe low-level solution (no session locking):sudo sh -c "echo disk > /sys/power/state" How to get out of hibernation? Power your system back on, 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 a3. Pass this address to the wakeonlan command :wakeonlan f8:ca:b8:17:44:02Sending magic packet to 255.255.255.255:9 with f8:ca:b8:17:44:02Easy to do for a machine on the same network, but not over the Internet. Add a "hibernate" option (1) Tested on Ubuntu 22.04Start GNOME's Extension Manager:extension-managerLook for "Hibernate Status Button", install and activatethis extension. Add a "hibernate" option (2) Tested on Ubuntu 22.04You 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.hibernateResultActive=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-inhibitResultActive=yesSource :https://ubuntuhandbook.org/index.php/2021/08/enable-hibernate-ubuntu-21-10/ Beware of the consumption of your screens (1) Laptop doing nothing, maximum brightness14.88 WLaptop doing nothing, minimum brightness10.04 WLaptop doing nothing, screen off7.44 WConclusion: a display at maximum brightness can representhalf of the power consumption of your PC when it's notrunning anything. Beware of the consumption of your screens (2) Using ddcutil On my old LCD IIyama monitor (2012)At maximum brightness:45 W !At 50% brightness, sufficient, mais making a light but annoying hiss :-/30 WAt minimum brightness, sufficient at nuit, the annoying hiss remains :15 W ddcutil is a Linux program for managing monitor settings,such as brightness, color levels, and input source. Generallyspeaking, any setting that can be changed by pressing buttonson the monitor can be modified by ddcutil.https://www.ddcutil.com/$ sudo ddcutil capabilities... Feature: D6 (Power mode) Values: 01: DPM: On, DPMS: Off 04: DPM: Off, DPMS: Off...To switch off the monitor:$ sudo ddcutil setvcp D6 04To switch it back on:$ sudo ddcutil setvcp D6 01 How to switch off your screens? Difficult to find universal commands!With X, 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 screenWith ddutil, you can control your external screens, theway you would do it with the control buttons.On my laptop, the F8 key allows to alternate betweenpowered on screens (all or only one), without having togo through the configuration menus. However, I find iteasier to set brightness to its minimum leve.The easiest solution to switch off your screens withoutsuspending 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 controlCPU frequency.This is based of the "cpufreq" infrastructureof the Linux kernel. You can even havedifferent settings for each CPU core! GNOME CPU Power Manager Extension (1) GNOME offers more specific optionsto control the frequency and performanceof 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 motherboard. It seems that power management takes temperature into account.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 everywhereMeasures 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 powertopA variant that first runs tests on your system for finerpower consumption estimates:$ sudo powertop --calibrate 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. Bootlin is recruiting interns and engineershttps://bootlin.com/company/careers/ It's possible to use the tool manually and apply itsrecommendations:$ sudo powertop --auto-tuneBut it's easier to make them permanent:$ sudo systemctl enable powertop$ sudo systemctl start powertop (ou redémarrer)Results on old Dell Latitude (on AC),LCD at maximum brightness:consumption reduced from 15.12W to 12.55W PowerTop - Integration https://linrunner.de/tlp/Similar to powertop --auto-tune, applies settings to reducepower consumption.- Enabled automatically at installation time (no need for PowerTop) :$ sudo apt-install tlp (Ubuntu)- Two profiles: on battery and on AC, automatically selected.- The battery profile is said to be more aggressive than the AC one.- Possible to tune the settings if wanted (unlike with PowerTop), even if default settings are usually sufficient.- tlp-stat command: many useful info on battery, disks, etc. Results on old Dell Latitude on AC, LCD screen at max brightness :consumption reduced from 15,12W to 12,65W.Would be interesting to run a battery life comparison too. Even better: TLP
1
  1. Title
  2. Michael Opdenacker
  3. Why this presentation?
  4. More technical motives
  5. Target of this presentation