Save some extra power on your linux box

Powersaving

The linux operating system has some nice options to make it use less power. I was looking into this because I wanted to make my laptop battery last a bit longer and make my media server just an extra bit more quiet. Sometimes the cooling fan of my media server’s power supply was making quit some noise as were the disks. The media server is a net top that already has it’s fan is already replace by a thicker and slower turning one which makes a a big difference.

The powertop command can be used to see how your systems power consumtion is doing. The command must be ran by root by the way.

Take a look at this :

PowerTOP 1.97 Overview Idle stats Frequency stats Device stats Tunables
 >> Good Enable Audio codec power management
 Good NMI watchdog should be turned off
 Good VM writeback timeout
 Good Autosuspend for USB device EHCI Host Controller [usb1]
 Good Autosuspend for USB device Trust Keyboard (MLK)
 Good Autosuspend for USB device UHCI Host Controller [usb2]
 Good Autosuspend for USB device UHCI Host Controller [usb3]
 Good Autosuspend for USB device UHCI Host Controller [usb4]
 Good Autosuspend for USB device UHCI Host Controller [usb5]
 Good Autosuspend for USB device USB2.0-CRW (Generic)
 Good Runtime PM for PCI Device Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controlle
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family PCI Express Port 4
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family SMBus Controller
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family PCI Express Port 1
 Good Runtime PM for PCI Device Intel Corporation 82801G (ICH7 Family) IDE Controller
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family PCI Express Port 3
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family USB2 EHCI Controller
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family PCI Express Port 2
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family USB UHCI Controller #4
 Good Runtime PM for PCI Device Atheros Communications Inc. AR242x / AR542x Wireless Network Adapter (PCI-Express)
 Good Runtime PM for PCI Device Intel Corporation 82945G/GZ/P/PL Memory Controller Hub
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family USB UHCI Controller #3
 Good Runtime PM for PCI Device Intel Corporation 82945G/GZ Integrated Graphics Controller
 Good Runtime PM for PCI Device Intel Corporation N10/ICH 7 Family High Definition Audio Controller
<ESC> Exit | <Enter> Toggle tunable

See all the ‘Good’s ? :)

Well this was not what it looked like at first. In fact all of them had a ‘Bad’ when I first looked. So the powertop command was telling me that there was some room for improvement ! Nice :)
I looked into all the items and come up with some settings that I added to the ‘start’ stanza of /etc/init.d/rc.local. Here they are :

#added some powersaving items
#shutdown the NMI watchdog
echo 0 > /proc/sys/kernel/watchdog
#more time between disk writes
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
# power control for pci devices
for i in /sys/bus/pci/devices/*/power/control ; do
  echo auto > ${i}
done
# power control for usb devices
for i in /sys/bus/usb/devices/*/power/control ; do
  echo auto > ${i}
done

I’ll explain some more on what the settings are about.

The NMI watchdog can help to debug interrupt hangups. Interrupt hangups will cause a hanging piece of hardware. The watchdog will issue a non maskable interrupt from time to time to check and see if there is a hangup. So the NMI watchdog is nice to have when there’s hardware hangs to debug. when this is not the case it will just cause extra power consuming wake-ups. It can be shut off when not needed.

Next is the vm writeback time. The linux kernel combines writes in order to work more efficiently. How often these writes happen is configurable. Default on my systems was 500 milliseconds. When this is set to a higher value writes happen less frequent causing less disk writes. This adds a bit of a risc. When the system crashes or the power is gone suddenly the writes are lost. So that’s a tradeoff. On a laptop there’s always the battery as a power source backup and on my media station it’s not that important if a write is lost to I changes the 500 milliseconds to 1500. So now instead of every half second writes are done every 1,5 second.

Last the usb and pic power controls. The linux kernel can temporarily suspend and idle device. When there is no process using the device it will be suspended. The driver of individual devices will know if the device itself is able to initiate an event and will keep the device active or only suspend it for short periods of time.

Ok that’s it for now. Happy saving power ! :)