How to save energy

powersaving
powertop

(tom) #1

salve

there are good reasons for lower the power consummation by minimal performance impact as example:

  • less fan noise because the cpu is staying longer and will be earlier cool
  • longer battery duration on a notebook
  • costs for energy are rising rapidly
  • more peace of conscience because climate warming

there isn’t a common interface to tweak all power related options unfortunately so i will split in to two sections:

  • post boot changeable
  • changeable only at boot time

i will begin with the post boot changeable section:

  • find and enable various powersaving modes in userspace, kernel and hardware

=> install powertop and find the power related setting

sudo pacman -S powertop

run as root:

sudo powertop

then switch to the “tunables” tab and there you can toggle available options by clicking “enter” but this isn’t a persistent setting. if you want to have thy persistent then copy the shown path(s) and options to /etc/tmpfiles.d/write.conf

sudoedit /etc/tmpfiles.d/powertop.conf

you can use wildcards to toggle many with one line
mine as example:

[tom@frija ~]$ cat /etc/tmpfiles.d/write.conf 
#better network perfomance
w /proc/sys/net/core/busy_read - - - - 50
w /proc/sys/net/core/busy_poll - - - - 50

#enable aspm
w /sys/module/pcie_aspm/parameters/policy - - - - powersupersave

#change io scheduler
w /sys/block/sda/queue/scheduler - - - - none

#set power save on my i soundcard
w /sys/module/snd_hda_intel/parameters/power_save_controler - - - - y
w /sys/module/snd_hda_intel/parameters/power_save - - - - 10 

#set div modul options for i915
w /sys/module/i915/parameters/fastboot - - - - y
#enable frequency scaling for my graphicalcard
w /sys/module/i915/parameters/enable_fbc - - - - 1
w /sys/module/i915/parameters/enable_psr - - - - 1
w /sys/module/iwldvm/parameters/force_cam - - - - n

#enable compression if memory beginns to swap 
w /sys/module/zswap/parameters/enable - - - - y

#set cpu frequency govenor
#w /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor - - - - performance

#set swappines to 10
w /proc/sys/vm/swappiness - - - - 10
w /proc/sys/vm/dirty_writeback_centisecs - - - - 1500

#disable kernel watchdog
w /proc/sys/kernel/nmi_watchdog - - - - 0

#set scsi devices to min_power by using a wildcard
w /sys/class/scsi_host/host*/link_power_management_policy - - - - min_power

#set bus controller to usin
w /sys/bus/i2c/devices/i2c-1/device/power/control - - - - auto
w /sys/bus/i2c/devices/i2c-4/device/power/control - - - - auto
w /sys/bus/i2c/devices/i2c-6/device/power/control - - - - auto

w /sys/bus/usb/devices/*/power/control - - - - auto

w /sys/bus/pci/devices/*/power/control - - - - auto
man systemd-tmpfiles

for the lazy powertop can edit automatically the available options with this service

sudoedit /etc/systemd/system/powertop.service
[Unit]
Description=Powertop tunings

[Service]
ExecStart=/usr/bin/powertop --auto-tune
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

  1. only tweak able at boot time
  • find module options
    there is a script to find these options and must be executed with root privileges
#!/bin/bash

for i in $(find /sys/devices -name "bMaxPower")
do
	busdir=${i%/*}
	busnum=$(<$busdir/busnum)
	devnum=$(<$busdir/devnum)
	title=$(lsusb -s $busnum:$devnum)

	printf "\n\n+++ %s\n  -%s\n" "$title" "$busdir"

	for ff in $(find $busdir/power -type f ! -empty 2>/dev/null)
	do
		v=$(cat $ff 2>/dev/null|tr -d "\n")
		[[ ${#v} -gt 0 ]] && echo -e " ${ff##*/}=$v";
		v=;
	done | sort -g;
done;

printf "\n\n\n+++ %s\n" "Kernel Modules"
for mod in $(lspci -k | sed -n '/in use:/s,^.*: ,,p' | sort -u)
do
	echo "+ $mod";
	systool -v -m $mod 2> /dev/null | sed -n "/Parameters:/,/^$/p";
done

if you got the modules names then check the available modules options by using “modinfo”. as example i915

[tom@frija ~]$ modinfo -p iwlwifi
swcrypto:  using crypto in software (default 0 [hardware]) (int)
11n_disable:disable 11n functionality, bitmap: 1: full, 2: disable agg TX, 4: disable agg RX, 8 enable agg TX (uint)
amsdu_size:  amsdu size 0: 12K for multi Rx queue devices, 4K for other devices 1:4K 2:8K 3:12K (default 0) (int)
fw_restart:  restart firmware in case of error (default true) (bool)
antenna_coupling:  specify antenna coupling in dB (default: 0 dB) (int)
nvm_file:  NVM file name (charp)
d0i3_disable:  disable d0i3 functionality (default: Y) (bool)
lar_disable:  disable LAR functionality (default: N) (bool)
uapsd_disable:  disable U-APSD functionality bitmap 1: BSS 2: P2P Client (default: 3) (uint)
bt_coex_active:  enable wifi/bt co-exist (default: enable) (bool)
led_mode:  0=system default, 1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0) (int)
power_save:  enable WiFi power management (default: disable) (bool)
power_level:  default power save level (range from 1 - 5, default: 1) (int)
fw_monitor:  firmware monitor - to debug FW (default: false - needs lots of memory) (bool)
d0i3_timeout:  Timeout to D0i3 entry when idle (ms) (uint)
disable_11ac:  Disable VHT capabilities (default: false) (bool)

some options can only be set by kernel command line or modprobe

  • a modprobe example
/etc/modprobe.d/iwlwifi.conf

options iwlwifi async_probe 11n_disable=8 power_save=y uapsd_disable=0 power_level=6

do you using different hard ware? no problem, it is always the same:

  1. install powertop and make the settings are persistent
  2. find modules with the script and with modinfo find relevant settings and set these option
man systemd-modules-load.service 

sources:
https://wiki.archlinux.org/index.php/Power_saving
https://wiki.archlinux.org/index.php/Powertop
https://en.opensuse.org/Powersaving
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/power_management_guide/overview