[linux-pm] calling runtime PM from system PM methods

Kevin Hilman khilman at ti.com
Wed Jun 15 14:54:00 PDT 2011


"Rafael J. Wysocki" <rjw at sisk.pl> writes:

> On Saturday, June 11, 2011, Alan Stern wrote:
>> On Fri, 10 Jun 2011, Kevin Hilman wrote:
>> 
>> > Alan Stern <stern at rowland.harvard.edu> writes:
>> > 
>> > [...]
>> 
>> > > If the wakeup setting is not correct, it has to be changed.  That 
>> > > often implies going back to full power in order to change the 
>> > > wakeup setting, then going to low power again.
>> > 
>> > OK, but how should this be implemented?  
>> > 
>> > If the device is runtime suspended at system suspend time, it implies
>> > that somwhere in the system suspend path, the device has to be powered
>> > on and enabled (a.k.a. runtime resumed.)
>> > 
>> > From a driver writer's perspective, doing a pm_runtime_get_sync() would
>> > be the obvious choice, but that causes nesting of ->runtime_resume
>> > callbacks within ->suspend callbacks which is apparently forbidden (or
>> > rather strongly recommended against :)
>> > 
>> > Now, assuming the driver's suspend can't do a pm_runtime_get()...
>> > 
>> > In order to power on & enable the device, the driver has to essentially
>> > duplicate everything that would be done by a runtime resume.
>> 
>> Again, this depends on the subsystem and the driver.  For example, the
>> USB subsystem does call pm_runtime_resume() in order to bring a device
>> back to full power if the wakeup setting needs to be changed.  This is
>> done in the subsystem code, and the subsystem is designed to allow it.
>> 
>> (Actually, it could be improved.  In theory the driver doesn't need to
>> be involved at all; a USB device's wakeup setting can be changed purely
>> by the subsystem.  Nevertheless, the pm_runtime_resume call does wake
>> up the driver, which then needs to be quiesced again shortly thereafter
>> -- overall a waste of time.  This was the easiest approach.)
>> 
>> > The problem comes because this work is shared between the driver and the
>> > subsystem.  IOW, it's the driver's ->suspend() callback that decides
>> > whether or not the device needs to be powered-on/enabled (e.g. to
>> > enable/disable wakeups), but it might be the subsystem that actually has
>> > does the magic_device_set_full_power(), magic_device_enable().
>> > 
>> > So once the driver's ->suspend() realizes it needs to power on & enable
>> > the device, it has no way to tell the subsystem to do so, wait for it to
>> > happen, and then enable/disable its wakeups.
>> 
>> Then the subsystem should _provide_ a way, if that's how you decide to
>> handle things.
>> 
>> > Maybe I'm being really dense, really blind, or really stubborn (or all
>> > three), but it seems to be that using runtime PM calls to implement
>> > these things would be the most obvious and the most readable.
>> 
>> Have you tried actually doing it in a situation where you control both
>> the driver and the subsystem?
>> 
>> Basically, I think what Rafael was saying before referred to the 
>> general case, where you don't know anything about the subsystem and 
>> can't afford to make assumptions.  But in the real world you'll be 
>> writing a driver for a particular subsystem and you'll know how that 
>> subsystem works.  If the subsystem permits runtime PM calls to be 
>> nested within the system PM routines, feel free to go ahead and use 
>> them.
>
> But then we get the problem that user space may echo "on" to the
> device's "control" file in sysfs and the whole clever plan basically goes
> south.
>
> Moreover, on some systems devices will belong to PM domains and their
> drivers may potentially be used with different PM domains on different
> platforms.  This means that drivers really should not make any assumptions
> about whether or not they can use runtime PM in their system suspend/resume
> routines.  They can't.

Sure, but it's easy enough for subsystems that need protection to add
it.  Why not just better document that driver & subsytem runtime PM
callbacks *could* be called during a system suspend (and same for
resume.)  Any subsystems that want/need protection can prevent nesting
simply with pm_runtime_get_noresume() and _put_noidle().

As I mentioned earlier in the thread, this can already happen today
without .suspend() callbacks directly calling pm_runtime_suspend()
(e.g. driver xfer finishes and does pm_runtime_put_sync() anytime after
system suspend has started.)

> Now, Kevin, I think that the problem you really want to address is this:
> Suppose a driver needs to do one thing in its .runtime_suspend() callback
> (e.g. "save state") and it wants to do two things in its .suspend()
> callback (e.g. "quiesce device" and "save state").  Then, it seems, the
> simplest approach would be to call its .runtie_suspend() routine from
> its .suspend() routine (after doing the "quiesce device" thing).

Partially, yes.  But I'm not primarily concerned about the callbacks.
Many of our simple drivers don't even need runtime PM callbacks
(e.g. state is saved using shadow regs, or device is re-init'd for for
every xfer etc.)

More important to me is how driver writers for embedded devices think
about PM for embedded systems.  IMO, driver writers should think
primarily in terms of runtime PM, and use that as the primary API for
all driver PM.



More information about the linux-pm mailing list