├── LICENSE ├── Makefile ├── README.md ├── modprobe.d ├── blacklist.conf └── powersave.conf ├── rules.d ├── 50-powersave-net.rules ├── 50-powersave-pci.rules ├── 50-powersave-sata.rules ├── 50-powersave-suspend.rules └── 50-powersave-usb.rules ├── sysctl.d └── 99-powersave.conf └── tmpfiles.d └── powersave.conf /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. 14 | 15 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | LIBPREFIX = ${PREFIX}/lib 3 | 4 | install: 5 | install -d ${DESTDIR}${LIBPREFIX}/sysctl.d ${DESTDIR}${LIBPREFIX}/tmpfiles.d \ 6 | ${DESTDIR}${LIBPREFIX}/modprobe.d ${DESTDIR}${LIBPREFIX}/udev/rules.d 7 | install -Dm 0644 sysctl.d/* ${DESTDIR}${LIBPREFIX}/sysctl.d/ 8 | install -Dm 0644 tmpfiles.d/* ${DESTDIR}${LIBPREFIX}/tmpfiles.d/ 9 | install -Dm 0644 modprobe.d/* ${DESTDIR}${LIBPREFIX}/modprobe.d/ 10 | install -Dm 0644 rules.d/*.rules ${DESTDIR}${LIBPREFIX}/udev/rules.d/ 11 | 12 | uninstall: 13 | rm -f ${LIBPREFIX}/sysctl.d/99-powersave.conf 14 | rm -f ${LIBPREFIX}/tmpfiles.d/powersave.conf 15 | rm -f ${LIBPREFIX}/modprobe.d/powersave.conf 16 | rm -f ${LIBPREFIX}/modprobe.d/blacklist.conf 17 | rm -f ${LIBPREFIX}/udev/rules.d/50-powersave-*.rules 18 | 19 | .PHONY: install uninstall 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Powersave 2 | ========= 3 | 4 | These files enable power saving on Linux. Note that these settings are applied regardless of whether 5 | the system is on battery or AC. Power saving is applied to: 6 | 7 | * Audio card (`modprobe.d/99-powersave.conf`) 8 | * Backlight brightness (`rules.d/50-powersave-brightness.rules`) 9 | * Bluetooth (disabled completely: `modprobe.d/blacklist.conf`) 10 | * NMI watchdog (`sysctl.d/99-powersave.conf`) 11 | * Writeback times (`sysctl.d/99-powersave.conf`) 12 | * Laptop mode (`sysctl.d/99-powersave.conf`) 13 | * Network interfaces, both wired and wireless (`modprobe.d/50-powersave-net.rules`) 14 | * Buses (ASPM, PCI, USB, SATA ALPM, `tmpfiles.d/powersave.conf` and `modprobe.d/50-powersave-[pci|usb|sata].rules`) 15 | 16 | Power saving is *not* applied to: 17 | * HDD, since it is replaced with an SSD. SSD power usage is simply ignored, since I have yet to look 18 | into this (and I believe it isn't that high). Tips are welcome! 19 | * CPU frequencies, since the default is fine (using the `intel_pstate` driver). 20 | * Swappiness, since I don't use a swap partition. 21 | 22 | You might also want to edit `/etc/fstab` to add `commits=` to the `options` column of your 23 | partitions. See the [mount man page][man-mount]. 24 | 25 | It is fit for my own laptop (Lenovo Thinkpad Edge E130), which means that this script will **not** 26 | work on every setup. Please **check** this before running it on your computer! Things might break 27 | otherwise and I am **not** responsible for any damage that has been done. 28 | 29 | TODO 30 | ---- 31 | 32 | * `git grep TODO` 33 | * Test the suspend-on-low-battery udev rule (`rules.d/50-powersave-suspend.rules`) 34 | * SSD powersaving? 35 | * Apply noop schedular in powersave instead of boot config? 36 | 37 | Installation 38 | ------------ 39 | 40 | The script will need the following dependencies to run: 41 | * iw 42 | * ip 43 | * ethtool 44 | * udev 45 | * systemd 46 | 47 | Just run `make install` as root to install the whole set. 48 | 49 | To enable the ASPM setting to work, append `pcie_aspm=force` to your kernel parameter list. However, 50 | before doing so, verify that all PCIe hardware on your system support ASPM! 51 | 52 | [man-mount]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT%20OPTIONS 53 | 54 | -------------------------------------------------------------------------------- /modprobe.d/blacklist.conf: -------------------------------------------------------------------------------- 1 | # Do not load these modules on boot 2 | 3 | # Bluetooth related 4 | blacklist bluetooth 5 | blacklist hci 6 | blacklist hci_uart 7 | blacklist hci_vhci 8 | -------------------------------------------------------------------------------- /modprobe.d/powersave.conf: -------------------------------------------------------------------------------- 1 | # Sound card 2 | options snd-hda-intel power_save=1 power_save_controller=y 3 | 4 | # Graphics card - marks kernel as tainted. Defaults are probably sane. 5 | #options i915 i915_enable_rc6=7 i915_enable_fbc=1 lvds_downclock=1 6 | 7 | # USB Autosuspend 8 | options usbcore autosuspend=2 9 | 10 | # Thinkpad Fan Control 11 | options thinkpad_acpi fan_control=1 12 | -------------------------------------------------------------------------------- /rules.d/50-powersave-net.rules: -------------------------------------------------------------------------------- 1 | # Disable ethernet ports 2 | ACTION=="add", SUBSYSTEM=="net", KERNEL=="enp*", RUN+="/usr/bin/ip link set dev %k down" 3 | 4 | # Disable Wake-on-LAN 5 | ACTION=="add", SUBSYSTEM=="net", KERNEL=="enp*", RUN+="/usr/bin/ethtool -s %k wol d" 6 | 7 | # Enable powersaving on all wireless devices 8 | ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlp*", RUN+="/usr/bin/iw dev %k set power_save on" 9 | -------------------------------------------------------------------------------- /rules.d/50-powersave-pci.rules: -------------------------------------------------------------------------------- 1 | # PCI Runtime power management 2 | ACTION=="add", SUBSYSTEM=="pci", ATTR{power/control}="auto" 3 | -------------------------------------------------------------------------------- /rules.d/50-powersave-sata.rules: -------------------------------------------------------------------------------- 1 | # SATA Active Link Power Management 2 | # This does add latency to drives that have been idle, so perhaps one should toggle this setting 3 | # whether or not the system is on AC. TODO: decide on this. 4 | # WARNING: This can lead to data loss on some devices. 5 | ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_policy}="min_power" 6 | -------------------------------------------------------------------------------- /rules.d/50-powersave-suspend.rules: -------------------------------------------------------------------------------- 1 | # Suspend when battery is at 2% 2 | SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="2", RUN+="/usr/bin/systemctl suspend" 3 | -------------------------------------------------------------------------------- /rules.d/50-powersave-usb.rules: -------------------------------------------------------------------------------- 1 | # USB Autosuspend. 2 | 3 | # Blacklist Logitech USB Mouse. 4 | ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c52f", GOTO="power_usb_rules_end" 5 | 6 | # Blacklist Logitech G403, both wireless receiver and wired. 7 | ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c082", GOTO="power_usb_rules_end" 8 | ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="046d", ATTR{idProduct}=="c539", GOTO="power_usb_rules_end" 9 | 10 | ACTION=="add", SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto" 11 | 12 | LABEL="power_usb_rules_end" 13 | -------------------------------------------------------------------------------- /sysctl.d/99-powersave.conf: -------------------------------------------------------------------------------- 1 | # Disable NMI watchdog 2 | kernel.nmi_watchdog = 0 3 | 4 | # laptop_mode is a knob that controls "laptop mode". All the things that are controlled by this 5 | # knob are discussed in https://www.kernel.org/doc/Documentation/laptops/laptop-mode.txt (Default 6 | # is 0). 7 | vm.laptop_mode = 5 8 | 9 | # Contains, as a percentage of total available memory that contains free pages and reclaimable 10 | # pages, the number of pages at which a process which is generating disk writes will itself start 11 | # writing out dirty data (Default is 20). 12 | #vm.dirty_ratio = 20 13 | 14 | # Contains, as a percentage of total available memory that contains free pages and reclaimable 15 | # pages, the number of pages at which the background kernel flusher threads will start writing out 16 | # dirty data (Default is 10). 17 | #vm.dirty_background_ratio = 10 18 | 19 | # This tunable is used to define when dirty data is old enough to be eligible for writeout by the 20 | # kernel flusher threads. It is expressed in 100'ths of a second. Data which has been dirty 21 | # in-memory for longer than this interval will be written out next time a flusher thread wakes up 22 | # (Default is 3000). 23 | #vm.dirty_expire_centisecs = 3000 24 | 25 | # The kernel flusher threads will periodically wake up and write `old' data out to disk. This 26 | # tunable expresses the interval between those wakeups, in 100'ths of a second (Default is 500). 27 | vm.dirty_writeback_centisecs = 1500 28 | 29 | -------------------------------------------------------------------------------- /tmpfiles.d/powersave.conf: -------------------------------------------------------------------------------- 1 | w /sys/module/pcie_aspm/parameters/policy - - - - powersave 2 | --------------------------------------------------------------------------------