rickysarraf/laptop-mode-tools — pull request #30 by shuber2 (2014-05-25 08:17:01+00:00)
Title: Ethernet poweroff

The following commit replaces the "echo 0 > enabled" code to disable PCI devices
by "ip link set dev DEV down". The reason are as follows:

1. The "enabled" sysfs attr for PCI devices is an enabled counter, i.e., a kind
of reference counter that keeps track of the number of requests to enable a
device. Writing "0" to it decrements the counter as we can see from
pci-sysfs.c:enablestore()
pci.c:disable_device()

Simply writing 0 to enabled may have no effects. Indeed, disabling a disabled
device provokes a kernel warning, see disable_device(). Hence, we should not
disable a device which we didn't enable before, which again would not make
sense for our ultimate goal: powering down the device. If we do "echo 0" to
an disabled device, we get -EIO returned, see enablestore(). This also
resolves Issue #21 in github.

2. Even if the device becomes disabled, it does not mean that the device would
stop draining power. In fact, my e1000e ethernet device drains roughly
700-800 mW even though the counter became 0. (Actually, enabeling and
disabeling it frequently makes the kernel unstable. Maybe this is related to
the fact that we are altering reference counters?)

Using "ip link set dev DEV down" causes my ethernet device (e1000e) to consume 0
mW according to powertop. As a side result, the code becomes much cleaner.