Linux networking: Saving power when in sleep/standby

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

nickcmaynard

New Member
May 31, 2024
1
2
3
I put a number of my Linux systems into "standby" overnight. I have noticed that in standby, the Ethernet interfaces remain at full speed.

Now, we all know that higher-speed Ethernet sucks more power. From my own cursory testing of one of my boxes, this amounts to a 1-2W difference at both ends, total 3-4W, when comparing 10Mbps and 2.5Gbps. It's possible this is something particular to my setup, though - corroborating evidence would be helpful!

As all I need when my systems are in standby is the ability to respond to WOL packets, I wrote a small hook for systemd-sleep to throttle connection speed just before entering the sleep state, and restore auto-negotiation on wake up.

Bash:
$ cat /usr/lib/systemd/system-sleep/wol-ethspeed

#!/bin/bash

shopt -s nullglob
case $1 in
  pre)
    for i in /sys/class/net/e{n,th}*; do
      /usr/sbin/ethtool -s `basename $i` autoneg off
      /usr/sbin/ethtool -s `basename $i` speed 10
    done
    ;;
  post)
    for i in /sys/class/net/e{n,th}*; do
      /usr/sbin/ethtool -s `basename $i` autoneg on
    done
    ;;
esac
Once added, systemctl suspend does the trick.

I hope this helps others.