linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Linux PM list <linux-pm@vger.kernel.org>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Aaron Lu <aaron.lu@intel.com>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH 1/3] PM / sleep: Flag to speed up suspend-resume of runtime-suspended devices
Date: Sat, 10 May 2014 00:49:25 +0200	[thread overview]
Message-ID: <1599191.L8hnSpOETp@vostro.rjw.lan> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1405082110330.13708-100000@netrider.rowland.org>

On Thursday, May 08, 2014 09:52:18 PM Alan Stern wrote:
> On Thu, 8 May 2014, Rafael J. Wysocki wrote:
> 
> > Well, no.
> > 
> > The reason why that doesn't work is because ->prepare() callbacks are
> > executed in the reverse order, so the perent's ones will be run before
> > the ->prepare() of the children.  Thus if ->prepare() sets the flag
> > with the expectation that ->suspend() (and the subsequent callbacks)
> > won't be executed, that expectation may not be met actually.
> 
> That's true also if the flag gets set in ->suspend(), isn't it?  A
> driver may set direct_resume in its ->suspend() callback, expecting
> that the subsequent callbacks won't be executed.  But if a descendant
> hasn't also set its flag then the callbacks _will_ be executed.

No, that's not possible with the current patch, because __device_suspend() is
executed for descendants first and then for ancestors and it clears
direct_suspend for the parents of devices that don't have it set.  This means
that the ancestor's ->suspend() will see the flag clear if it is unset for
any of its descendants.

IOW, the only case in which the ancestor's ->suspend() sees the flag set is
when it has been set for all of its descendants.  Thus, if it leaves the
flag set, the late/early and noirq callbacks won't be executed for it.

Now, there is a reason for concern in that, because ->suspend() may set the
flag as a result of an error and that may lead to unexpected consequences.

> > So I'm going to do what I said above.  I prefer it anyway. :-)
> 
> In your most recent patch (and in the earlier ones too), after you call
> dev's ->suspend() routine, if dev->power.direct_resume isn't set then
> you clear dev->parent->direct_resume.  But what good will that do if
> dev->parent's ->suspend() routine turns the flag back on when it gets
> called later?

In fact, ->suspend() is not supposed to set the flag when it is clear.
It can clear it when it is set, which means that we have "normal" suspend.

> I can think of two ways to make this work.
> 
> 	Expect subsystems and drivers to set the flag during 
> 	->suspend().  Turn on the flag in every device during 
> 	device_prepare().  Then in __device_suspend(), remember the
> 	flag's value and turn it off before invoking the callback.

That doesn't work, because ->suspend() has to decide whether or not
to resume the device and do things it would do normally, so it needs to know
the value of the flag.

>       If the flag is on again when the callback returns, set the flag 
> 	back to the remembered value.  If the flag ends up being off
> 	then turn off the parent's flag.

That'd be too late.  The only thing we can do to kind of protect the PM
core from errors in drivers in that case would be to remember the value of
the flag before calling ->suspend() and return an error if it the flag after
->suspend() is set, but it wasn't before.

> 	Expect subsystems and drivers to set the flag during 
> 	->prepare().  Whenever a callback returns with the flag not
> 	set, clear the flag in all of the device's ancestors.
> 
> Both are somewhat awkward, and both involve turning the flag off after 
> the callback has turned it on.

After the callback set it on while it shouldn't, it might have done something
wrong already.

> Also, how do you expect direct_resume to work with the PCI subsystem?  
> Will the PCI core set the flag appropriately on behalf of the driver?

Yes.

> If the core does set the flag, will it invoke the driver's ->suspend()
> callback or skip the callback?

It will skip the driver's callback.  [It would actually help if you looked
at patch [3/3] which is there to illustrate my idea of how to do those
things in a subsystem.]

> If it invokes the driver's callback but
> leaves the device in runtime suspend, what happens if the driver
> expects the device always to be at full power when its ->suspend()  
> routine runs?  If the core skips the driver's ->suspend() callback,
> what happens if one of the device's children did not set direct_resume 
> and so the later PM callbacks do get invoked?

Then the parent will have direct_resume unset.  That is not a concern.
The only concern to me is possible errors in ->suspend() setting the
flag when it shouldn't.

> Several of these questions are a lot easier to answer if the flag gets 
> set during ->prepare() rather than ->suspend().

I agree with that, but I have one concern about this approach.  Namely,
in that case the PM core has to use pm_runtime_resume() or equivalent to
resume devices with the flag set during the device resume stage.  Now,
in the next step we may want to leave certain devices suspended at that
point and the PM core has no way to tell which ones.  Also subsystems
don't really have a chance to tell it about that (they would need to
know in advance during ->prepare(), which is kind of unrealistic, or
perhaps it isn't).

However, if ->resume() is called for devices with the flag set, like in
my most recent patch, the subsystem may decide not to resume the device
if it knows enough about it.

This pretty much is my only concern here, so I'm open to ideas how to deal
with leaving devices suspended (if possible) during the device resume stage. :-)

For one, postponing the resume to ->complete() is an option, but it will have
to be done with care, because the ->complete() callbacks are executed
sequentially, so calling pm_runtime_resume() from there is rather out of the
question.

Rafael


  reply	other threads:[~2014-05-09 22:32 UTC|newest]

Thread overview: 78+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-14 23:12 [RFC][PATCH 0/3] PM: Mechanism to avoid resuming runtime-suspended devices during system suspend Rafael J. Wysocki
2014-01-14 23:13 ` [RFC][PATCH 1/3] PM / sleep: Flag to avoid executing suspend callbacks for devices Rafael J. Wysocki
2014-01-14 23:14 ` [RFC][PATCH 2/3] PM / runtime: Routine for checking device status during system suspend Rafael J. Wysocki
2014-01-16 13:32   ` Mika Westerberg
2014-01-16 16:07     ` [Update][RFC][PATCH " Rafael J. Wysocki
2014-01-14 23:16 ` [RFC][PATCH 3/3] ACPI / PM: Avoid resuming devices in ACPI PM domain " Rafael J. Wysocki
2014-01-15 13:57   ` [Update][RFC][PATCH " Rafael J. Wysocki
2014-02-16 23:49 ` [RFC][PATCH 0/3] PM: Mechanism to avoid resuming runtime-suspended devices " Rafael J. Wysocki
2014-02-16 23:50   ` [PATCH 1/3] PM / sleep: New flag to speed up suspend-resume of suspended devices Rafael J. Wysocki
2014-02-18 12:59     ` Ulf Hansson
2014-02-18 13:25       ` Rafael J. Wysocki
2014-02-19 17:01     ` Alan Stern
2014-02-20  1:23       ` Rafael J. Wysocki
2014-02-20  1:42         ` Rafael J. Wysocki
2014-02-20 17:03         ` Alan Stern
2014-02-24  0:00           ` Rafael J. Wysocki
2014-02-24 19:36             ` Alan Stern
2014-02-25  0:07               ` Rafael J. Wysocki
2014-02-25 17:08                 ` Alan Stern
2014-02-25 23:56                   ` Rafael J. Wysocki
2014-02-26 16:49                     ` Alan Stern
2014-02-26 21:44                       ` Rafael J. Wysocki
2014-02-26 22:17                         ` Alan Stern
2014-02-26 23:13                           ` Rafael J. Wysocki
2014-02-27 15:02                             ` Alan Stern
2014-04-24 22:36                               ` [RFC][PATCH 0/3] PM: Mechanism to avoid resuming runtime-suspended devices during system suspend, v2 Rafael J. Wysocki
2014-04-24 22:37                                 ` [RFC][PATCH 1/3] PM / sleep: Flags to speed up suspend-resume of runtime-suspended devices Rafael J. Wysocki
2014-05-01 21:39                                   ` Alan Stern
2014-05-01 23:15                                     ` Rafael J. Wysocki
2014-05-01 23:36                                       ` Rafael J. Wysocki
2014-05-02  0:04                                         ` Rafael J. Wysocki
2014-05-02 15:41                                           ` Rafael J. Wysocki
2014-05-02 18:44                                             ` Alan Stern
2014-05-05  0:09                                               ` Rafael J. Wysocki
2014-05-05 15:46                                                 ` Alan Stern
2014-05-06  1:31                                                   ` Rafael J. Wysocki
2014-05-06 19:31                                                     ` Alan Stern
2014-05-07  0:36                                                       ` Rafael J. Wysocki
2014-05-07 15:43                                                         ` Alan Stern
2014-05-07 23:27                                                           ` [RFC][PATCH 0/3] (was: Re: [RFC][PATCH 1/3] PM / sleep: Flags to speed up suspend-resume of runtime-suspended devices) Rafael J. Wysocki
2014-05-07 23:29                                                             ` [RFC][PATCH 1/3] PM / sleep: Flag to speed up suspend-resume of runtime-suspended devices Rafael J. Wysocki
2014-05-08  7:49                                                               ` Ulf Hansson
2014-05-08 10:53                                                                 ` Rafael J. Wysocki
2014-05-08 10:59                                                                   ` Ulf Hansson
2014-05-08 11:44                                                                     ` Rafael J. Wysocki
2014-05-08 12:25                                                                       ` Ulf Hansson
2014-05-08 20:02                                                                         ` Rafael J. Wysocki
2014-05-08 14:36                                                                     ` Alan Stern
2014-05-08 14:57                                                               ` Alan Stern
2014-05-08 20:17                                                                 ` Rafael J. Wysocki
2014-05-08 21:03                                                                   ` Rafael J. Wysocki
2014-05-08 21:20                                                                     ` Alan Stern
2014-05-08 21:42                                                                       ` Rafael J. Wysocki
2014-05-08 21:50                                                                         ` Rafael J. Wysocki
2014-05-08 22:28                                                                           ` [RFC][PATCH 0/3] (was: Re: PM / sleep: Flag to speed up suspend-resume of runtime-suspended devices) Rafael J. Wysocki
2014-05-08 22:41                                                                             ` [RFC][PATCH 1/3] PM / sleep: Flag to speed up suspend-resume of runtime-suspended devices Rafael J. Wysocki
2014-05-09  7:23                                                                               ` Ulf Hansson
2014-05-09 11:33                                                                                 ` Rafael J. Wysocki
2014-05-08 22:41                                                                             ` [RFC][PATCH 2/3] PM / runtime: Routine for checking device status during system suspend Rafael J. Wysocki
2014-05-08 22:42                                                                             ` [RFC][PATCH 3/3] ACPI / PM: Avoid resuming devices in ACPI PM domain " Rafael J. Wysocki
2014-05-09  1:52                                                                           ` [RFC][PATCH 1/3] PM / sleep: Flag to speed up suspend-resume of runtime-suspended devices Alan Stern
2014-05-09 22:49                                                                             ` Rafael J. Wysocki [this message]
2014-05-11 16:46                                                                               ` Alan Stern
2014-05-13  0:51                                                                                 ` Rafael J. Wysocki
2014-05-08 21:08                                                                   ` Alan Stern
2014-05-09 22:48                                                               ` Kevin Hilman
2014-05-10  1:38                                                                 ` Rafael J. Wysocki
2014-05-12 16:33                                                                   ` Kevin Hilman
2014-05-07 23:31                                                             ` [Resend][PATCH 2/3] PM / runtime: Routine for checking device status during system suspend Rafael J. Wysocki
2014-05-07 23:33                                                             ` [RFC][PATCH 3/3] ACPI / PM: Avoid resuming devices in ACPI PM domain " Rafael J. Wysocki
2014-05-08 14:59                                                               ` Alan Stern
2014-05-08 19:40                                                                 ` Rafael J. Wysocki
2014-05-02 16:12                                         ` [RFC][PATCH 1/3] PM / sleep: Flags to speed up suspend-resume of runtime-suspended devices Alan Stern
2014-04-24 22:39                                 ` [RFC][PATCH 2/3][Resend] PM / runtime: Routine for checking device status during system suspend Rafael J. Wysocki
2014-04-25 11:28                                   ` Ulf Hansson
2014-04-24 22:40                                 ` [RFC][PATCH 3/3] ACPI / PM: Avoid resuming devices in ACPI PM domain " Rafael J. Wysocki
2014-02-16 23:51   ` [PATCH 2/3][Resend] PM / runtime: Routine for checking device status " Rafael J. Wysocki
2014-02-16 23:52   ` [PATCH 3/3] ACPI / PM: Avoid resuming devices in ACPI PM domain " Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1599191.L8hnSpOETp@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=aaron.lu@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).