Comment réduire sa consommation électrique avec GNU/Linux ? image/svg+xml Comment réduire sa consommation électrique avec GNU/Linux ?   Michael OpdenackerJDLL 2023, Lyon How to reduce powerconsumption with GNU/Linux ? Free Software enthusiastFounder of BootlinEmbedded Linux Software EngineeringHeadquarters are in Lyon ;-)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 longerProject to update the "Linux Ecology HOWTO" 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 generatedheat-- Covered topics (2) 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 presentationhttps://bootlin.com/pub/conferences/2023/jdll/ Presentation made with Free Software: Sozi and InkscapePresentation sources and image credits:https://gitlab.com/michaelopdenacker/reduce-power-consumption-with-gnu-linux 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.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-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 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 possible too(under some conditions) on a remote network. 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 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. How to switch off your screens? Not very practical because of sudo :$ sudo vbetool dpms off (bof: avec sudo)$ sudo vbetool dpms onMore 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 screenThe 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.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 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 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
  1. Title
  2. Michael Opdenacker
  3. Why this presentation?
  4. More technical motives
  5. Target of this presentation