By Jonathan Corbet
June 10, 2009
For most general-purpose Linux deployments, power management really only
comes into play at suspend and resume time. Embedded systems tend to have
dedicated code which keeps the device's power usage to a minimum, but
there's no real equivalent for Linux as obtained via a standard
distribution installation. A new patch from Rafael Wysocki may change that
situation, though, and, in the process, yield lower power usage and more
reliable power management on general-purpose machines.
Rafael's patch adds
infrastructure supporting a seemingly uncontroversial goal: let the kernel
power down devices which are not currently being used. To that end,
struct dev_pm_ops gains two new function pointers:
int (*autosuspend)(struct device *dev);
int (*autoresume)(struct device *dev);
The idea is simple: if the kernel decides that a specific device is not in
use, and that it can be safely powered down, the autosuspend()
function will be called. At some future point, autoresume() is
called to bring the device back up to full functionality. The driver
should, of course, take steps to save any necessary device state while the
device is sleeping.
The value in this infrastructure should be reasonably clear. If the kernel
can decide that system operation will not suffer if a given device is
powered down, it can call the relevant autosuspend() function and
save some power. But there's more to it than that; a kernel which
uses this infrastructure will exercise the suspend/resume functionality in
specific drivers in a regular way. That, in turn, should turn up obscure
suspend/resume bugs in ways which make them relatively easy to identify
and, hopefully fix. If something goes wrong when suspending or resuming a
system as a whole, determining the culprit can be hard to do. If
suspending a single idle device creates trouble, the source of the problem
will be rather more obvious. So this infrastructure should lead to more
reliable power management in general, which is a good thing.
A reading of the patch shows that one thing is missing: the code which
decides when to suspend and resume specific devices. Rafael left that part
as an exercise for the reader. As it turns out, different readers had
rather different ideas of how this decision needs to be made.
Matthew Garrett quickly suggested that
there would need to be a mechanism by which user space could set the policy
to be used when deciding whether to suspend a specific device. In his
view, it is simply not possible for the kernel to know, on its own, that
suspending a specific device is safe. One example he gives is eSATA; an
eSATA interface is not distinguishable (by the kernel) from an ordinary
SATA interface, but it supports hotplugging of disks. If the kernel
suspends an "unused" eSATA controller, it will fail to notice when the user
attaches a new device. Another example is keyboards; it may make sense to
suspend a keyboard while the screen saver is running - unless the user is
running an audio player and expects the volume keys to work. Situations
like this are hard for the kernel to figure out.
Ingo Molnar has taken a different approach, arguing that this kind of decision really
belongs in the kernel. The kernel should, he says, suspend devices by
default whenever it is safe to do so; there's no point in asking user space
first.
Again, the user wont enter anything, in 95% of the cases - in the
remaining 3% of cases what is entered is wrong and only in another
2% of cases is it correct ;-)
Sane kernel defaults are important and the kernel sure knows what
kind of hardware it runs on. This 'let the user decide policy' for
something as fundamental (and also as arcane) as power saving mode
is really a disease that has caused a lot of unnecessary pain in
Linux in the past 15 years.
The discussion went back and forth without much in the way of seeming
agreement. But the difference between the two positions is, perhaps, not
as large as it seems. Ingo argues for automatically suspending devices
where this operation is known to be safe, and he acknowledges that this may
not be true for the majority of devices out there. That is not too far
from Matthew's position that a variety of devices cannot be automatically
suspended in a safe way. But, Ingo says, we should go ahead and
apply automatic power management in the cases where we know it can be done,
and we should expect that the number of devices with sophisticated (and
correct) power management functionality will grow over time.
So the only real disagreement is over how the kernel can know whether a
given device can be suspended or not. Ingo would like to see the kernel
figure it out from the information which is already available; Matthew
thinks that some sort of new policy-setting interface will be required.
Answering that question may not be possible until somebody has tried to
implement a fully in-kernel policy, and that may take a while. In the mean
time, though, at least we will have the infrastructure which lets
developers begin to play with potential solutions.
(
Log in to post comments)