diff mbox

[v3,1/2] PM / sleep: Let devices force direct_complete

Message ID 1429284290-25153-2-git-send-email-tomeu.vizoso@collabora.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Tomeu Vizoso April 17, 2015, 3:24 p.m. UTC
Introduce a new per-device flag power.force_direct_complete that will
instruct the PM core to ignore the runtime PM status of its descendants
when deciding whether to let this device remain in runtime suspend when
the system goes into a sleep power state.

This is needed because otherwise it would be needed to get dozens of
drivers to implement the prepare() callback and be runtime PM active
even if they don't have a 1-to-1 relationship with a piece of HW.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
---
 drivers/base/power/main.c | 13 +++++++++----
 include/linux/pm.h        |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)

Comments

Greg Kroah-Hartman April 17, 2015, 3:33 p.m. UTC | #1
On Fri, Apr 17, 2015 at 05:24:49PM +0200, Tomeu Vizoso wrote:
> Introduce a new per-device flag power.force_direct_complete that will
> instruct the PM core to ignore the runtime PM status of its descendants
> when deciding whether to let this device remain in runtime suspend when
> the system goes into a sleep power state.
> 
> This is needed because otherwise it would be needed to get dozens of
> drivers to implement the prepare() callback and be runtime PM active
> even if they don't have a 1-to-1 relationship with a piece of HW.
> 
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> ---
>  drivers/base/power/main.c | 13 +++++++++----
>  include/linux/pm.h        |  1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 3d874ec..728c2dc 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1438,7 +1438,9 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async)
>  		if (parent) {
>  			spin_lock_irq(&parent->power.lock);
>  
> -			dev->parent->power.direct_complete = false;
> +			if (!dev->parent->power.force_direct_complete)
> +				dev->parent->power.direct_complete = false;
> +
>  			if (dev->power.wakeup_path
>  			    && !dev->parent->power.ignore_children)
>  				dev->parent->power.wakeup_path = true;
> @@ -1605,9 +1607,12 @@ static int device_prepare(struct device *dev, pm_message_t state)
>  	 * will do the same thing with all of its descendants".  This only
>  	 * applies to suspend transitions, however.
>  	 */
> -	spin_lock_irq(&dev->power.lock);
> -	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
> -	spin_unlock_irq(&dev->power.lock);
> +	if (state.event == PM_EVENT_SUSPEND) {
> +		spin_lock_irq(&dev->power.lock);
> +		dev->power.direct_complete = ret > 0 ||
> +			dev->power.force_direct_complete;
> +		spin_unlock_irq(&dev->power.lock);
> +	}
>  	return 0;
>  }
>  
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 2d29c64..2e41cfd 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -553,6 +553,7 @@ struct dev_pm_info {
>  	bool			ignore_children:1;
>  	bool			early_init:1;	/* Owned by the PM core */
>  	bool			direct_complete:1;	/* Owned by the PM core */
> +	bool			force_direct_complete:1;

Where have you documented this?  I foresee this just getting messier and
messier...
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Laurent Pinchart April 17, 2015, 3:35 p.m. UTC | #2
Hi Tomeu,

Thank you for the patch.

On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
> Introduce a new per-device flag power.force_direct_complete that will
> instruct the PM core to ignore the runtime PM status of its descendants
> when deciding whether to let this device remain in runtime suspend when
> the system goes into a sleep power state.
> 
> This is needed because otherwise it would be needed to get dozens of
> drivers to implement the prepare() callback and be runtime PM active
> even if they don't have a 1-to-1 relationship with a piece of HW.

I'll let PM experts comment on the approach, but I believe the new flag would 
benefit from being documented (likely in Documentation/power/devices.txt) :-)

> Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
> ---
>  drivers/base/power/main.c | 13 +++++++++----
>  include/linux/pm.h        |  1 +
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index 3d874ec..728c2dc 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1438,7 +1438,9 @@ static int __device_suspend(struct device *dev,
> pm_message_t state, bool async) if (parent) {
>  			spin_lock_irq(&parent->power.lock);
> 
> -			dev->parent->power.direct_complete = false;
> +			if (!dev->parent->power.force_direct_complete)
> +				dev->parent->power.direct_complete = false;
> +
>  			if (dev->power.wakeup_path
>  			    && !dev->parent->power.ignore_children)
>  				dev->parent->power.wakeup_path = true;
> @@ -1605,9 +1607,12 @@ static int device_prepare(struct device *dev,
> pm_message_t state) * will do the same thing with all of its descendants". 
> This only * applies to suspend transitions, however.
>  	 */
> -	spin_lock_irq(&dev->power.lock);
> -	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
> -	spin_unlock_irq(&dev->power.lock);
> +	if (state.event == PM_EVENT_SUSPEND) {
> +		spin_lock_irq(&dev->power.lock);
> +		dev->power.direct_complete = ret > 0 ||
> +			dev->power.force_direct_complete;
> +		spin_unlock_irq(&dev->power.lock);
> +	}
>  	return 0;
>  }
> 
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 2d29c64..2e41cfd 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -553,6 +553,7 @@ struct dev_pm_info {
>  	bool			ignore_children:1;
>  	bool			early_init:1;	/* Owned by the PM core */
>  	bool			direct_complete:1;	/* Owned by the PM core */
> +	bool			force_direct_complete:1;
>  	spinlock_t		lock;
>  #ifdef CONFIG_PM_SLEEP
>  	struct list_head	entry;
Alan Stern April 17, 2015, 5:30 p.m. UTC | #3
On Fri, 17 Apr 2015, Laurent Pinchart wrote:

> Hi Tomeu,
> 
> Thank you for the patch.
> 
> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
> > Introduce a new per-device flag power.force_direct_complete that will
> > instruct the PM core to ignore the runtime PM status of its descendants
> > when deciding whether to let this device remain in runtime suspend when
> > the system goes into a sleep power state.
> > 
> > This is needed because otherwise it would be needed to get dozens of
> > drivers to implement the prepare() callback and be runtime PM active
> > even if they don't have a 1-to-1 relationship with a piece of HW.
> 
> I'll let PM experts comment on the approach, but I believe the new flag would 
> benefit from being documented (likely in Documentation/power/devices.txt) :-)

Documentation/power/runtime_pm.txt is the right place.

However, I'm not sure that this is the sort of thing Rafael meant when 
he suggested adding a new flag.  I thought he meant the PM core would 
look at the new flag only if there was no ->prepare method at all.  
Then if the new flag was set, the PM core would act as though ->prepare 
had returned 1.  That way there would be no need to add silly little
one-line *_prepare() routines all over the place.

Maybe he had something else in mind, though...

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tomeu Vizoso April 20, 2015, 7:10 a.m. UTC | #4
On 17 April 2015 at 19:30, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Fri, 17 Apr 2015, Laurent Pinchart wrote:
>
>> Hi Tomeu,
>>
>> Thank you for the patch.
>>
>> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
>> > Introduce a new per-device flag power.force_direct_complete that will
>> > instruct the PM core to ignore the runtime PM status of its descendants
>> > when deciding whether to let this device remain in runtime suspend when
>> > the system goes into a sleep power state.
>> >
>> > This is needed because otherwise it would be needed to get dozens of
>> > drivers to implement the prepare() callback and be runtime PM active
>> > even if they don't have a 1-to-1 relationship with a piece of HW.
>>
>> I'll let PM experts comment on the approach, but I believe the new flag would
>> benefit from being documented (likely in Documentation/power/devices.txt) :-)
>
> Documentation/power/runtime_pm.txt is the right place.
>
> However, I'm not sure that this is the sort of thing Rafael meant when
> he suggested adding a new flag.  I thought he meant the PM core would
> look at the new flag only if there was no ->prepare method at all.
> Then if the new flag was set, the PM core would act as though ->prepare
> had returned 1.  That way there would be no need to add silly little
> one-line *_prepare() routines all over the place.
>
> Maybe he had something else in mind, though...

Yeah, I also interpreted it like that, but when I started looking at
how it would work, I found that it would be awkward if the uvcvideo
driver had to track all the devices that get attached below its
devices in order to set that flag to them.

When thinking about it, it occurred to me that it may make more sense
if we model this as a property of the device bound to the uvcvideo
driver, as what's happening here is that the uvcvideo driver knows
that it's safe to remain in runtime suspend when the system goes to
sleep, and that all its descendant devices can be ignored in that
regard.

Was meaning to explain this in the cover letter, but I forgot to, sorry.

Thanks,

Tomeu

> Alan Stern
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alan Stern April 20, 2015, 2:12 p.m. UTC | #5
On Mon, 20 Apr 2015, Tomeu Vizoso wrote:

> On 17 April 2015 at 19:30, Alan Stern <stern@rowland.harvard.edu> wrote:
> > On Fri, 17 Apr 2015, Laurent Pinchart wrote:
> >
> >> Hi Tomeu,
> >>
> >> Thank you for the patch.
> >>
> >> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
> >> > Introduce a new per-device flag power.force_direct_complete that will
> >> > instruct the PM core to ignore the runtime PM status of its descendants
> >> > when deciding whether to let this device remain in runtime suspend when
> >> > the system goes into a sleep power state.
> >> >
> >> > This is needed because otherwise it would be needed to get dozens of
> >> > drivers to implement the prepare() callback and be runtime PM active
> >> > even if they don't have a 1-to-1 relationship with a piece of HW.
> >>
> >> I'll let PM experts comment on the approach, but I believe the new flag would
> >> benefit from being documented (likely in Documentation/power/devices.txt) :-)
> >
> > Documentation/power/runtime_pm.txt is the right place.
> >
> > However, I'm not sure that this is the sort of thing Rafael meant when
> > he suggested adding a new flag.  I thought he meant the PM core would
> > look at the new flag only if there was no ->prepare method at all.
> > Then if the new flag was set, the PM core would act as though ->prepare
> > had returned 1.  That way there would be no need to add silly little
> > one-line *_prepare() routines all over the place.
> >
> > Maybe he had something else in mind, though...
> 
> Yeah, I also interpreted it like that, but when I started looking at
> how it would work, I found that it would be awkward if the uvcvideo
> driver had to track all the devices that get attached below its
> devices in order to set that flag to them.
> 
> When thinking about it, it occurred to me that it may make more sense
> if we model this as a property of the device bound to the uvcvideo
> driver, as what's happening here is that the uvcvideo driver knows
> that it's safe to remain in runtime suspend when the system goes to
> sleep, and that all its descendant devices can be ignored in that
> regard.

What you're proposing makes sense, but it is a significant change to 
the runtime PM core.  It should be submitted separately, not as part of 
an update to the UVC driver, and it should be discussed at length.

Basically, you want to mark certain devices to say that they will
_always_ use direct-suspend.  This means that all descendant devices
will be forced to use direct-suspend also, and therefore any driver
bound to one of these descendant devices will be unable to communicate
with it during a system sleep transition.  This is a non-trivial
restriction.

Among other things, it means that wakeup settings can't be altered 
during a sleep transition.  Therefore this should be allowed only for 
devices that are not wakeup-capable.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tomeu Vizoso April 28, 2015, 2:26 p.m. UTC | #6
On 20 April 2015 at 16:12, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Mon, 20 Apr 2015, Tomeu Vizoso wrote:
>
>> On 17 April 2015 at 19:30, Alan Stern <stern@rowland.harvard.edu> wrote:
>> > On Fri, 17 Apr 2015, Laurent Pinchart wrote:
>> >
>> >> Hi Tomeu,
>> >>
>> >> Thank you for the patch.
>> >>
>> >> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
>> >> > Introduce a new per-device flag power.force_direct_complete that will
>> >> > instruct the PM core to ignore the runtime PM status of its descendants
>> >> > when deciding whether to let this device remain in runtime suspend when
>> >> > the system goes into a sleep power state.
>> >> >
>> >> > This is needed because otherwise it would be needed to get dozens of
>> >> > drivers to implement the prepare() callback and be runtime PM active
>> >> > even if they don't have a 1-to-1 relationship with a piece of HW.
>> >>
>> >> I'll let PM experts comment on the approach, but I believe the new flag would
>> >> benefit from being documented (likely in Documentation/power/devices.txt) :-)
>> >
>> > Documentation/power/runtime_pm.txt is the right place.
>> >
>> > However, I'm not sure that this is the sort of thing Rafael meant when
>> > he suggested adding a new flag.  I thought he meant the PM core would
>> > look at the new flag only if there was no ->prepare method at all.
>> > Then if the new flag was set, the PM core would act as though ->prepare
>> > had returned 1.  That way there would be no need to add silly little
>> > one-line *_prepare() routines all over the place.
>> >
>> > Maybe he had something else in mind, though...
>>
>> Yeah, I also interpreted it like that, but when I started looking at
>> how it would work, I found that it would be awkward if the uvcvideo
>> driver had to track all the devices that get attached below its
>> devices in order to set that flag to them.
>>
>> When thinking about it, it occurred to me that it may make more sense
>> if we model this as a property of the device bound to the uvcvideo
>> driver, as what's happening here is that the uvcvideo driver knows
>> that it's safe to remain in runtime suspend when the system goes to
>> sleep, and that all its descendant devices can be ignored in that
>> regard.
>
> What you're proposing makes sense, but it is a significant change to
> the runtime PM core.  It should be submitted separately, not as part of
> an update to the UVC driver, and it should be discussed at length.
>
> Basically, you want to mark certain devices to say that they will
> _always_ use direct-suspend.  This means that all descendant devices
> will be forced to use direct-suspend also, and therefore any driver
> bound to one of these descendant devices will be unable to communicate
> with it during a system sleep transition.  This is a non-trivial
> restriction.
>
> Among other things, it means that wakeup settings can't be altered
> during a sleep transition.  Therefore this should be allowed only for
> devices that are not wakeup-capable.

Hi Rafael,

do you have any comments on this?

Thanks,

Tomeu
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rafael J. Wysocki April 28, 2015, 2:54 p.m. UTC | #7
On Tuesday, April 28, 2015 04:26:39 PM Tomeu Vizoso wrote:
> On 20 April 2015 at 16:12, Alan Stern <stern@rowland.harvard.edu> wrote:
> > On Mon, 20 Apr 2015, Tomeu Vizoso wrote:
> >
> >> On 17 April 2015 at 19:30, Alan Stern <stern@rowland.harvard.edu> wrote:
> >> > On Fri, 17 Apr 2015, Laurent Pinchart wrote:
> >> >
> >> >> Hi Tomeu,
> >> >>
> >> >> Thank you for the patch.
> >> >>
> >> >> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
> >> >> > Introduce a new per-device flag power.force_direct_complete that will
> >> >> > instruct the PM core to ignore the runtime PM status of its descendants
> >> >> > when deciding whether to let this device remain in runtime suspend when
> >> >> > the system goes into a sleep power state.
> >> >> >
> >> >> > This is needed because otherwise it would be needed to get dozens of
> >> >> > drivers to implement the prepare() callback and be runtime PM active
> >> >> > even if they don't have a 1-to-1 relationship with a piece of HW.
> >> >>
> >> >> I'll let PM experts comment on the approach, but I believe the new flag would
> >> >> benefit from being documented (likely in Documentation/power/devices.txt) :-)
> >> >
> >> > Documentation/power/runtime_pm.txt is the right place.
> >> >
> >> > However, I'm not sure that this is the sort of thing Rafael meant when
> >> > he suggested adding a new flag.  I thought he meant the PM core would
> >> > look at the new flag only if there was no ->prepare method at all.
> >> > Then if the new flag was set, the PM core would act as though ->prepare
> >> > had returned 1.  That way there would be no need to add silly little
> >> > one-line *_prepare() routines all over the place.
> >> >
> >> > Maybe he had something else in mind, though...
> >>
> >> Yeah, I also interpreted it like that, but when I started looking at
> >> how it would work, I found that it would be awkward if the uvcvideo
> >> driver had to track all the devices that get attached below its
> >> devices in order to set that flag to them.
> >>
> >> When thinking about it, it occurred to me that it may make more sense
> >> if we model this as a property of the device bound to the uvcvideo
> >> driver, as what's happening here is that the uvcvideo driver knows
> >> that it's safe to remain in runtime suspend when the system goes to
> >> sleep, and that all its descendant devices can be ignored in that
> >> regard.
> >
> > What you're proposing makes sense, but it is a significant change to
> > the runtime PM core.  It should be submitted separately, not as part of
> > an update to the UVC driver, and it should be discussed at length.
> >
> > Basically, you want to mark certain devices to say that they will
> > _always_ use direct-suspend.  This means that all descendant devices
> > will be forced to use direct-suspend also, and therefore any driver
> > bound to one of these descendant devices will be unable to communicate
> > with it during a system sleep transition.  This is a non-trivial
> > restriction.
> >
> > Among other things, it means that wakeup settings can't be altered
> > during a sleep transition.  Therefore this should be allowed only for
> > devices that are not wakeup-capable.
> 
> Hi Rafael,
> 
> do you have any comments on this?

Well, what Alan has said sounds correct to me.

Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson April 30, 2015, 7:11 a.m. UTC | #8
On 20 April 2015 at 16:12, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Mon, 20 Apr 2015, Tomeu Vizoso wrote:
>
>> On 17 April 2015 at 19:30, Alan Stern <stern@rowland.harvard.edu> wrote:
>> > On Fri, 17 Apr 2015, Laurent Pinchart wrote:
>> >
>> >> Hi Tomeu,
>> >>
>> >> Thank you for the patch.
>> >>
>> >> On Friday 17 April 2015 17:24:49 Tomeu Vizoso wrote:
>> >> > Introduce a new per-device flag power.force_direct_complete that will
>> >> > instruct the PM core to ignore the runtime PM status of its descendants
>> >> > when deciding whether to let this device remain in runtime suspend when
>> >> > the system goes into a sleep power state.
>> >> >
>> >> > This is needed because otherwise it would be needed to get dozens of
>> >> > drivers to implement the prepare() callback and be runtime PM active
>> >> > even if they don't have a 1-to-1 relationship with a piece of HW.
>> >>
>> >> I'll let PM experts comment on the approach, but I believe the new flag would
>> >> benefit from being documented (likely in Documentation/power/devices.txt) :-)
>> >
>> > Documentation/power/runtime_pm.txt is the right place.
>> >
>> > However, I'm not sure that this is the sort of thing Rafael meant when
>> > he suggested adding a new flag.  I thought he meant the PM core would
>> > look at the new flag only if there was no ->prepare method at all.
>> > Then if the new flag was set, the PM core would act as though ->prepare
>> > had returned 1.  That way there would be no need to add silly little
>> > one-line *_prepare() routines all over the place.
>> >
>> > Maybe he had something else in mind, though...
>>
>> Yeah, I also interpreted it like that, but when I started looking at
>> how it would work, I found that it would be awkward if the uvcvideo
>> driver had to track all the devices that get attached below its
>> devices in order to set that flag to them.
>>
>> When thinking about it, it occurred to me that it may make more sense
>> if we model this as a property of the device bound to the uvcvideo
>> driver, as what's happening here is that the uvcvideo driver knows
>> that it's safe to remain in runtime suspend when the system goes to
>> sleep, and that all its descendant devices can be ignored in that
>> regard.
>
> What you're proposing makes sense, but it is a significant change to
> the runtime PM core.  It should be submitted separately, not as part of
> an update to the UVC driver, and it should be discussed at length.
>
> Basically, you want to mark certain devices to say that they will
> _always_ use direct-suspend.  This means that all descendant devices
> will be forced to use direct-suspend also, and therefore any driver
> bound to one of these descendant devices will be unable to communicate
> with it during a system sleep transition.  This is a non-trivial
> restriction.
>
> Among other things, it means that wakeup settings can't be altered
> during a sleep transition.  Therefore this should be allowed only for
> devices that are not wakeup-capable.
>

I hesitated to send this reply, since it might add confusion. If
that's the case, please ignore it.

I have a long term vision to fully enable support for a runtime PM
centric configuration for drivers/subsystems. The idea is, that such
driver/subsystem should get system PM for "free".

The main goal is to simplify PM implementation for these drivers/subsystems.

They should need to implement the runtime PM callbacks only and not
the system PM ones. During system PM suspend, the requirement is that
the corresponding devices should be guaranteed to be "runtime PM
suspended". Somehow that then needs to be managed by the PM core.

I am not sure it's doable, but I wanted to bring it up within the
context of $subject patch, since it proposes yet another optimization
path for runtime PM during system PM.

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alan Stern April 30, 2015, 2:53 p.m. UTC | #9
On Thu, 30 Apr 2015, Ulf Hansson wrote:

> I hesitated to send this reply, since it might add confusion. If
> that's the case, please ignore it.
> 
> I have a long term vision to fully enable support for a runtime PM
> centric configuration for drivers/subsystems. The idea is, that such
> driver/subsystem should get system PM for "free".
> 
> The main goal is to simplify PM implementation for these drivers/subsystems.
> 
> They should need to implement the runtime PM callbacks only and not
> the system PM ones. During system PM suspend, the requirement is that
> the corresponding devices should be guaranteed to be "runtime PM
> suspended". Somehow that then needs to be managed by the PM core.
> 
> I am not sure it's doable, but I wanted to bring it up within the
> context of $subject patch, since it proposes yet another optimization
> path for runtime PM during system PM.

I suspect it is _not_ doable.  Consider a reasonable scenario: a driver
that does pm_runtime_get_sync() in its open routine and
pm_runtime_put() in its release routine.  If a user process holds the
device file open during a system suspend, it will be impossible for the
PM core to do a runtime suspend.

On the other hand, there's nothing to prevent drivers from setting 
their ->suspend and ->runtime_suspend structure members to point at the 
same routine.  The routine would need to handle the case where it was 
called for a system suspend while the device was already runtime 
suspended, but that doesn't seem too hard.  With the "direct-suspend" 
option, even this wouldn't be necessary.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson May 6, 2015, 8:30 a.m. UTC | #10
On 30 April 2015 at 16:53, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Thu, 30 Apr 2015, Ulf Hansson wrote:
>
>> I hesitated to send this reply, since it might add confusion. If
>> that's the case, please ignore it.
>>
>> I have a long term vision to fully enable support for a runtime PM
>> centric configuration for drivers/subsystems. The idea is, that such
>> driver/subsystem should get system PM for "free".
>>
>> The main goal is to simplify PM implementation for these drivers/subsystems.
>>
>> They should need to implement the runtime PM callbacks only and not
>> the system PM ones. During system PM suspend, the requirement is that
>> the corresponding devices should be guaranteed to be "runtime PM
>> suspended". Somehow that then needs to be managed by the PM core.
>>
>> I am not sure it's doable, but I wanted to bring it up within the
>> context of $subject patch, since it proposes yet another optimization
>> path for runtime PM during system PM.
>
> I suspect it is _not_ doable.  Consider a reasonable scenario: a driver
> that does pm_runtime_get_sync() in its open routine and
> pm_runtime_put() in its release routine.  If a user process holds the
> device file open during a system suspend, it will be impossible for the
> PM core to do a runtime suspend.

Alan, thanks for your reply.

There are certainly drivers/subsystems that can't full-fill the
requirements to have the PM core to deal with what I propose. Somehow
drivers/subsystems would have to announce its capability for this.

Those drivers/subsystems I have been looking at, is dealing with I/O.
Typically platform/amba devices, which drivers has registered
subsystem specific callbacks at ->probe(). One of these callbacks are
invoked when there is an I/O request to serve from the subsystem's
core layer.

In the beginning of that callback, pm_runtime_get_sync() is invoked.
When the request has been served and the controller can be runtime PM
suspended, the driver call pm_runtime_put() or possibly
pm_runtime_put_autosuspend().

These drivers/subsystem may be considered as being "runtime PM
centric", since during system PM suspend they don't have any system PM
specific things to deal with. They only want to make sure their
devices becomes "runtime PM suspended".

There's no doubt that they can do that by implementing the system PM
->suspend() callbacks, in one way or the other.

To simplify PM implementation for these drivers/subsystems, it would
have been nice if the PM core could handle this "automagically", thus
drivers/subsystems wouldn't have to implement the system PM callbacks
at all. Reaching that point, would likely make it easier to understand
how to implement a "runtime PM centric" driver/subsystem.

>
> On the other hand, there's nothing to prevent drivers from setting
> their ->suspend and ->runtime_suspend structure members to point at the
> same routine.  The routine would need to handle the case where it was
> called for a system suspend while the device was already runtime
> suspended, but that doesn't seem too hard.  With the "direct-suspend"
> option, even this wouldn't be necessary.

That would likely work, but again it would require drivers/subsystems
to assign system PM callbacks.

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alan Stern May 6, 2015, 2:43 p.m. UTC | #11
On Wed, 6 May 2015, Ulf Hansson wrote:

> On 30 April 2015 at 16:53, Alan Stern <stern@rowland.harvard.edu> wrote:
> > On Thu, 30 Apr 2015, Ulf Hansson wrote:
> >
> >> I hesitated to send this reply, since it might add confusion. If
> >> that's the case, please ignore it.
> >>
> >> I have a long term vision to fully enable support for a runtime PM
> >> centric configuration for drivers/subsystems. The idea is, that such
> >> driver/subsystem should get system PM for "free".
> >>
> >> The main goal is to simplify PM implementation for these drivers/subsystems.
> >>
> >> They should need to implement the runtime PM callbacks only and not
> >> the system PM ones. During system PM suspend, the requirement is that
> >> the corresponding devices should be guaranteed to be "runtime PM
> >> suspended". Somehow that then needs to be managed by the PM core.
> >>
> >> I am not sure it's doable, but I wanted to bring it up within the
> >> context of $subject patch, since it proposes yet another optimization
> >> path for runtime PM during system PM.
> >
> > I suspect it is _not_ doable.  Consider a reasonable scenario: a driver
> > that does pm_runtime_get_sync() in its open routine and
> > pm_runtime_put() in its release routine.  If a user process holds the
> > device file open during a system suspend, it will be impossible for the
> > PM core to do a runtime suspend.
> 
> Alan, thanks for your reply.
> 
> There are certainly drivers/subsystems that can't full-fill the
> requirements to have the PM core to deal with what I propose. Somehow
> drivers/subsystems would have to announce its capability for this.
> 
> Those drivers/subsystems I have been looking at, is dealing with I/O.
> Typically platform/amba devices, which drivers has registered
> subsystem specific callbacks at ->probe(). One of these callbacks are
> invoked when there is an I/O request to serve from the subsystem's
> core layer.
> 
> In the beginning of that callback, pm_runtime_get_sync() is invoked.
> When the request has been served and the controller can be runtime PM
> suspended, the driver call pm_runtime_put() or possibly
> pm_runtime_put_autosuspend().
> 
> These drivers/subsystem may be considered as being "runtime PM
> centric", since during system PM suspend they don't have any system PM
> specific things to deal with. They only want to make sure their
> devices becomes "runtime PM suspended".
> 
> There's no doubt that they can do that by implementing the system PM
> ->suspend() callbacks, in one way or the other.
> 
> To simplify PM implementation for these drivers/subsystems, it would
> have been nice if the PM core could handle this "automagically", thus
> drivers/subsystems wouldn't have to implement the system PM callbacks
> at all. Reaching that point, would likely make it easier to understand
> how to implement a "runtime PM centric" driver/subsystem.

The drivers/subsystems don't have to implement these things, because
you have _already_ implemented them: pm_runtime_force_suspend() and 
pm_runtime_force_resume().  A driver/subsystem merely has to store 
pointers to these routines in its dev_pm_ops structure.

> > On the other hand, there's nothing to prevent drivers from setting
> > their ->suspend and ->runtime_suspend structure members to point at the
> > same routine.  The routine would need to handle the case where it was
> > called for a system suspend while the device was already runtime
> > suspended, but that doesn't seem too hard.  With the "direct-suspend"
> > option, even this wouldn't be necessary.
> 
> That would likely work, but again it would require drivers/subsystems
> to assign system PM callbacks.

You said just above that the driver/subsystem would have to announce
its capability for this somehow.  Using suitable callback pointers
would be a good way to make that announcement.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Ulf Hansson May 6, 2015, 4:05 p.m. UTC | #12
On 6 May 2015 at 16:43, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Wed, 6 May 2015, Ulf Hansson wrote:
>
>> On 30 April 2015 at 16:53, Alan Stern <stern@rowland.harvard.edu> wrote:
>> > On Thu, 30 Apr 2015, Ulf Hansson wrote:
>> >
>> >> I hesitated to send this reply, since it might add confusion. If
>> >> that's the case, please ignore it.
>> >>
>> >> I have a long term vision to fully enable support for a runtime PM
>> >> centric configuration for drivers/subsystems. The idea is, that such
>> >> driver/subsystem should get system PM for "free".
>> >>
>> >> The main goal is to simplify PM implementation for these drivers/subsystems.
>> >>
>> >> They should need to implement the runtime PM callbacks only and not
>> >> the system PM ones. During system PM suspend, the requirement is that
>> >> the corresponding devices should be guaranteed to be "runtime PM
>> >> suspended". Somehow that then needs to be managed by the PM core.
>> >>
>> >> I am not sure it's doable, but I wanted to bring it up within the
>> >> context of $subject patch, since it proposes yet another optimization
>> >> path for runtime PM during system PM.
>> >
>> > I suspect it is _not_ doable.  Consider a reasonable scenario: a driver
>> > that does pm_runtime_get_sync() in its open routine and
>> > pm_runtime_put() in its release routine.  If a user process holds the
>> > device file open during a system suspend, it will be impossible for the
>> > PM core to do a runtime suspend.
>>
>> Alan, thanks for your reply.
>>
>> There are certainly drivers/subsystems that can't full-fill the
>> requirements to have the PM core to deal with what I propose. Somehow
>> drivers/subsystems would have to announce its capability for this.
>>
>> Those drivers/subsystems I have been looking at, is dealing with I/O.
>> Typically platform/amba devices, which drivers has registered
>> subsystem specific callbacks at ->probe(). One of these callbacks are
>> invoked when there is an I/O request to serve from the subsystem's
>> core layer.
>>
>> In the beginning of that callback, pm_runtime_get_sync() is invoked.
>> When the request has been served and the controller can be runtime PM
>> suspended, the driver call pm_runtime_put() or possibly
>> pm_runtime_put_autosuspend().
>>
>> These drivers/subsystem may be considered as being "runtime PM
>> centric", since during system PM suspend they don't have any system PM
>> specific things to deal with. They only want to make sure their
>> devices becomes "runtime PM suspended".
>>
>> There's no doubt that they can do that by implementing the system PM
>> ->suspend() callbacks, in one way or the other.
>>
>> To simplify PM implementation for these drivers/subsystems, it would
>> have been nice if the PM core could handle this "automagically", thus
>> drivers/subsystems wouldn't have to implement the system PM callbacks
>> at all. Reaching that point, would likely make it easier to understand
>> how to implement a "runtime PM centric" driver/subsystem.
>
> The drivers/subsystems don't have to implement these things, because
> you have _already_ implemented them: pm_runtime_force_suspend() and
> pm_runtime_force_resume().  A driver/subsystem merely has to store
> pointers to these routines in its dev_pm_ops structure.

Yes, apparently I have touched this topic earlier. :-)

As we are moving towards removing the Kconfig option CONFIG_PM_SLEEP
(CONFIG_PM_RUNTIME is already removed) and only have the CONFIG_PM,
parts of what the above helper functions addresses becomes redundant.

>
>> > On the other hand, there's nothing to prevent drivers from setting
>> > their ->suspend and ->runtime_suspend structure members to point at the
>> > same routine.  The routine would need to handle the case where it was
>> > called for a system suspend while the device was already runtime
>> > suspended, but that doesn't seem too hard.  With the "direct-suspend"
>> > option, even this wouldn't be necessary.
>>
>> That would likely work, but again it would require drivers/subsystems
>> to assign system PM callbacks.
>
> You said just above that the driver/subsystem would have to announce
> its capability for this somehow.  Using suitable callback pointers
> would be a good way to make that announcement.

I was thinking, for simplicity purpose, that we could try to move this
a step forward.

Having a API like pm_runtime_centric() (or whatever name we can come
up with) to announce the capability, could be easier to understand and
use. Of course that's my opinion.

Kind regards
Uffe
--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 3d874ec..728c2dc 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1438,7 +1438,9 @@  static int __device_suspend(struct device *dev, pm_message_t state, bool async)
 		if (parent) {
 			spin_lock_irq(&parent->power.lock);
 
-			dev->parent->power.direct_complete = false;
+			if (!dev->parent->power.force_direct_complete)
+				dev->parent->power.direct_complete = false;
+
 			if (dev->power.wakeup_path
 			    && !dev->parent->power.ignore_children)
 				dev->parent->power.wakeup_path = true;
@@ -1605,9 +1607,12 @@  static int device_prepare(struct device *dev, pm_message_t state)
 	 * will do the same thing with all of its descendants".  This only
 	 * applies to suspend transitions, however.
 	 */
-	spin_lock_irq(&dev->power.lock);
-	dev->power.direct_complete = ret > 0 && state.event == PM_EVENT_SUSPEND;
-	spin_unlock_irq(&dev->power.lock);
+	if (state.event == PM_EVENT_SUSPEND) {
+		spin_lock_irq(&dev->power.lock);
+		dev->power.direct_complete = ret > 0 ||
+			dev->power.force_direct_complete;
+		spin_unlock_irq(&dev->power.lock);
+	}
 	return 0;
 }
 
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 2d29c64..2e41cfd 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -553,6 +553,7 @@  struct dev_pm_info {
 	bool			ignore_children:1;
 	bool			early_init:1;	/* Owned by the PM core */
 	bool			direct_complete:1;	/* Owned by the PM core */
+	bool			force_direct_complete:1;
 	spinlock_t		lock;
 #ifdef CONFIG_PM_SLEEP
 	struct list_head	entry;