All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Phillip Susi <psusi@ubuntu.com>, Aaron Lu <aaron.lu@intel.com>,
	Linux-pm mailing list <linux-pm@vger.kernel.org>
Subject: Re: Allow runtime suspend during system resume
Date: Sat, 11 Jan 2014 00:02:18 +0100	[thread overview]
Message-ID: <66174540.xyTk2QCVeJ@vostro.rjw.lan> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1401101012400.1399-100000@iolanthe.rowland.org>

On Friday, January 10, 2014 10:25:32 AM Alan Stern wrote:
> On Fri, 10 Jan 2014, Rafael J. Wysocki wrote:
> 
> > On Thursday, January 09, 2014 10:32:37 AM Alan Stern wrote:
> > > On Thu, 9 Jan 2014, Rafael J. Wysocki wrote:
> > > 
> > > > > The situation isn't quite so simple.
> > > > > 
> > > > > We're talking specifically about disk drives.  Depending on the drive,
> > > > > it may or may not spin up all by itself when the system wakes up.  If
> > > > > it does spin up, the final state should be RPM_ACTIVE (the way it is
> > > > > now).  If it doesn't, we want the final state to be RPM_SUSPENDED.
> > > > > This is true regardless of the runtime status before the system sleep.
> > > > 
> > > > OK
> > > > 
> > > > We can do all that in .resume_early() which runs with runtime PM disabled.
> > > 
> > > Either the .resume_early or the .resume routine would be okay, as far
> > > as I'm concerned.  Is there any strong reason to prefer one over the
> > > other, besides the fact that in .resume_early the pm_runtime_disable
> > > and _enable calls wouldn't be needed?
> > 
> > Not so much, at least I don't have anything like that in mind right now, but
> > I'm not a big fan of disabling/enabling runtime PM temporarily to have a look
> > at the "current" status.  That just doesn't seem quite right. :-)
> 
> The disable/enable is in order to _set_ the status, not to have a look 
> at it.

Right.

I should have said that in my opinion disabling runtime PM in order to do
anything with the fields owned by it and re-enabling it right after that
wasn't quite right in principle.  Re-adjusting those fields *before* we
re-enable runtime PM during system resume is quite different from doing
the on-off trick *after* we've re-enabled runtime PM.

So, my opinion is that the runtime PM internal information should be made
reflect the actual (and/or desirable) state of things before it is re-enabled,
which practically means in the .resume_noirq()/.resume_early() time frame.

Doing it after that might actually work, but is questionable from the
overall consistency perspective (it basically would mean that we ran with
wrong runtime PM data for a while after we'd re-enabled it and before it
got adjusted, so we shouldn't have re-enabled it in the first place).

> > > I had in mind something more like this for the driver's .resume (or
> > > .resume_early) routine:
> > > 
> > > 	bool leave_suspended = false;
> > > 	int rc = 0;
> > > 
> > > 	if (!pm_runtime_in_use(dev) && !disk_is_spinning(dev))
> > > 		leave_suspended = true;
> > > 	else
> > > 		rc = spin_up_the_disk(dev);
> > > 
> > > 	if (rc == 0) {
> > > 		pm_runtime_disable(dev);
> > > 		if (leave_suspended)
> > > 			pm_runtime_set_suspended(dev);
> > > 		else
> > > 			pm_runtime_set_active(dev);
> > > 		pm_runtime_enable(dev);
> > > 	}
> > > 	return rc;
> > > 
> > > That wouldn't need any special support from the PM core, other than the
> > > new pm_runtime_in_use routine.
> > 
> > That looks reasonable, but in .resume_early() you can do it like this I think:
> > 
> > 	bool disk_spinning = disk_is_spinning(dev);
> > 	int rc = 0;
> > 
> > 	if (!pm_runtime_in_use(dev) && !disk_spinning) {
> > 		pm_runtime_set_suspended(dev);
> > 	} else {
> > 		pm_runtime_set_active(dev);
> > 		if (!disk_spinning)
> > 			rc = spin_up_the_disk(dev);
> > 	}
> > 
> > and of course there needs to be a flag to pass to .resume() in case the
> > device is supposed to be left in the suspended state.
> 
> Agreed, there are various ways to get the same end result.  My question 
> here is: How should we implement pm_runtime_in_use()?

In my opinion what really matters is (a) whether or not the pm_runtime_enable()
in device_resume_early() will actually enable runtime PM and (b) whether or not
the pm_runtime_put() in device_complete() will actually make it possible to
suspend the device.  So, these are the conditions that I would check.

> > > > > In addition, we only want to end up in RPM_SUSPENDED if the usage
> > > > > counters are 0 (in particular, power/control = "auto").  Otherwise, we
> > > > > want the resume routine always to spin up the drive, if it hasn't spun
> > > > > up by itself.
> > > > 
> > > > That still can be done in .resume_early().  Or in .resume_noirq() if device
> > > > interrupts are not requisite for that.
> > > 
> > > No, currently it cannot be done.
> > > 
> > > In both resume_early and resume_noirq, the usage counter is _always_ >
> > > 0.  This is because device_prepare calls pm_runtime_get_noresume, and
> > > the corresponding pm_runtime_put doesn't occur until device_complete.  
> > > That's the problem I need to fix.
> > 
> > Hmm.  Why do you have to compare usage_count with 0 and not with 1?
> 
> It is an awkward problem.  During a system sleep transition,
> pm_runtime_in_use() should return 0 if the usage_count is 1 (because of
> the pm_runtime_get_noresume() in device_prepare()).
> 
> But at other times (i.e., during normal operation), pm_runtime_in_use()  
> should return 0 if the usage_count is 0.
> 
> I suppose a simple way to solve the problem is to document that
> pm_runtime_in_use() should only be invoked from within a system sleep
> callback routine.  Then we can compare against 1 and not worry about
> the normal-operation case.  Maybe call it
> pm_runtime_usage_during_sleep() to make this restriction explicit.
> 
> Would that be acceptable?

Yes, it would, as far as I'm concerned.

In my opinion it only is really useful to call it before calling
pm_runtime_enable() in device_resume_early().

Thanks,
Rafael


  reply	other threads:[~2014-01-10 22:48 UTC|newest]

Thread overview: 165+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-17 19:33 [PATCH/RESEND v2 0/2] SATA disk resume time optimization Todd E Brandt
2013-11-07  1:53 ` Phillip Susi
2013-11-07  1:57   ` [PATCH 1/3] sd: don't bother spinning up disks on resume Phillip Susi
2013-11-07 18:21     ` Douglas Gilbert
2013-11-07 21:16       ` Phillip Susi
2013-11-16 18:20         ` James Bottomley
2013-11-17  3:50           ` Phillip Susi
2013-11-17  6:43             ` James Bottomley
2013-11-17 16:15               ` Phillip Susi
2013-11-17 23:54                 ` Douglas Gilbert
2013-11-18  1:06                   ` Phillip Susi
2013-11-18 15:54                     ` Phillip Susi
2013-11-20 14:23                       ` Mark Lord
2013-11-20 14:48                         ` Phillip Susi
2013-11-28  1:39                           ` Phillip Susi
2013-11-18  0:09                 ` James Bottomley
2013-11-18  1:11                   ` Phillip Susi
2013-11-16  5:23       ` Mark Lord
2013-11-16 14:52         ` Phillip Susi
2013-11-07  1:57   ` [PATCH 2/3] libata: resume in the background Phillip Susi
2013-11-07  1:57   ` [PATCH 3/3] libata: don't start disks on resume Phillip Susi
2013-11-09  1:20   ` [PATCH/RESEND v2 0/2] SATA disk resume time optimization Todd E Brandt
2013-11-09 20:59     ` Phillip Susi
2013-11-09 21:03       ` [PATCH 0/6] Let sleeping disks lie Phillip Susi
2013-12-16 23:30         ` Phillip Susi
2013-12-16 23:30           ` [PATCH 1/6] libata: use sleep instead of standby command Phillip Susi
2013-12-16 23:30           ` [PATCH 2/6] libata: avoid waking disk for several commands Phillip Susi
2013-12-16 23:30           ` [PATCH 3/6] libata: resume in the background Phillip Susi
2014-01-10 22:26             ` Dan Williams
2014-01-11  2:25               ` Phillip Susi
2014-01-11  3:11                 ` Dan Williams
2013-12-16 23:30           ` [PATCH 4/6] libata: don't start disks on resume Phillip Susi
2013-12-16 23:30           ` [PATCH 5/6] sd: don't start disks on system resume Phillip Susi
2013-12-17  6:43             ` James Bottomley
2013-12-17 15:01               ` Phillip Susi
2013-12-17 17:48                 ` James Bottomley
2013-12-17 18:30                   ` Phillip Susi
2013-12-16 23:30           ` [PATCH 6/6] libata: return power status in REQUEST SENSE command Phillip Susi
2013-12-17 18:02             ` Sergei Shtylyov
2013-12-17 18:35               ` Phillip Susi
2014-01-06  2:14           ` REQ_PM vs REQ_TYPE_PM_RESUME Phillip Susi
2014-01-06  7:36             ` Sujit Reddy Thumma
2014-01-06  9:15               ` Aaron Lu
2014-01-06 14:40                 ` Phillip Susi
2014-01-06 15:38                   ` Alan Stern
2014-01-07  2:44                     ` Phillip Susi
2014-01-07 15:20                       ` Alan Stern
2014-01-07 15:40                         ` Phillip Susi
2014-01-07 15:56                           ` Alan Stern
2014-01-09 18:29                           ` Douglas Gilbert
2014-01-09 19:20                             ` Phillip Susi
2014-01-10  5:23                               ` Douglas Gilbert
2014-01-10 14:29                                 ` Phillip Susi
2014-01-07  7:49                   ` Aaron Lu
2014-01-07 14:50                     ` Phillip Susi
2014-01-08  1:03                       ` Aaron Lu
2014-01-08  1:16                         ` Phillip Susi
2014-01-08  1:32                           ` Aaron Lu
2014-01-08  1:53                             ` Phillip Susi
2014-01-08  2:11                               ` Aaron Lu
2014-01-08  2:19                                 ` Phillip Susi
2014-01-08  2:36                                   ` Aaron Lu
2014-01-08  5:24                                     ` Phillip Susi
2014-01-08  7:00                                       ` Aaron Lu
2014-01-08 19:30                                         ` Phillip Susi
2014-01-07 15:25                     ` Alan Stern
2014-01-07 15:43                       ` Phillip Susi
2014-01-07 16:08                         ` Alan Stern
2014-01-07 16:37                           ` Phillip Susi
2014-01-07 18:05                             ` Alan Stern
2014-01-07 18:43                               ` Phillip Susi
2014-01-07 19:18                                 ` Alan Stern
2014-01-07 23:47                                   ` Phillip Susi
2014-01-08 17:46                                     ` Alan Stern
2014-01-08 18:31                                       ` Alan Stern
2014-01-08 20:44                                         ` Allow runtime suspend during system resume Alan Stern
2014-01-08 21:17                                           ` Phillip Susi
2014-01-08 21:34                                             ` Alan Stern
2014-01-09 10:14                                               ` Ulf Hansson
2014-01-09 15:41                                                 ` Alan Stern
2014-01-08 22:55                                           ` Rafael J. Wysocki
2014-01-08 23:24                                             ` Alan Stern
2014-01-09  0:05                                               ` Rafael J. Wysocki
2014-01-09 15:32                                                 ` Alan Stern
2014-01-09 15:50                                                   ` Phillip Susi
2014-01-09 16:08                                                     ` Alan Stern
2014-01-09 16:30                                                       ` Phillip Susi
2014-01-09 17:04                                                         ` Alan Stern
2014-01-10  1:25                                                   ` Rafael J. Wysocki
2014-01-10  1:55                                                     ` Phillip Susi
2014-01-10 13:35                                                       ` Rafael J. Wysocki
2014-01-10 14:46                                                         ` Phillip Susi
2014-01-10 15:25                                                     ` Alan Stern
2014-01-10 23:02                                                       ` Rafael J. Wysocki [this message]
2014-01-11  2:08                                                         ` Phillip Susi
2014-01-11 22:50                                                           ` Alan Stern
2014-01-12  1:50                                                             ` Phillip Susi
2014-01-11 22:34                                                         ` Alan Stern
2014-01-08 20:20                                       ` REQ_PM vs REQ_TYPE_PM_RESUME Phillip Susi
2014-01-08 21:21                                         ` Alan Stern
2014-01-08 21:50                                           ` Phillip Susi
2014-01-09  1:29                                           ` Aaron Lu
2014-01-09 12:17                                             ` Rafael J. Wysocki
2014-01-09 13:18                                               ` Rafael J. Wysocki
2014-01-09 15:40                                             ` Alan Stern
2014-01-09 15:53                                               ` Phillip Susi
2014-01-09 16:14                                                 ` Alan Stern
2014-01-09 16:34                                                   ` Phillip Susi
2014-01-09 17:06                                                     ` Alan Stern
2014-01-16 16:59                                                 ` Disk spin-up optimization during system resume Alan Stern
2014-01-16 18:04                                                   ` Todd E Brandt
2014-01-16 18:33                                                     ` Phillip Susi
2014-01-16 20:05                                                     ` Alan Stern
2014-01-16 22:04                                                       ` Todd E Brandt
2014-01-17 14:57                                                         ` Alan Stern
2014-01-17 19:31                                                           ` Dan Williams
2014-01-17 20:15                                                             ` Alan Stern
2014-01-17 20:24                                                               ` Tejun Heo
2014-01-17 20:55                                                                 ` Phillip Susi
2014-01-18 14:04                                                                   ` Tejun Heo
2014-01-18  1:36                                                                 ` Todd E Brandt
2014-01-18  1:41                                                                 ` Alan Stern
2014-01-18  2:15                                                                   ` Dan Williams
2014-01-18  2:33                                                                     ` Alan Stern
2014-01-18  3:24                                                                   ` Phillip Susi
2014-01-18 13:59                                                                   ` Tejun Heo
2014-01-17 20:49                                                             ` Phillip Susi
2014-01-17 22:17                                                               ` Dan Williams
2014-01-18  3:18                                                                 ` Phillip Susi
2014-01-18  4:09                                                                   ` Dan Williams
2014-01-18 14:08                                                                     ` Alan Stern
2014-01-21 10:12                                                                       ` Dan Williams
2014-01-21 14:37                                                                         ` Phillip Susi
2014-01-21 16:03                                                                           ` Alan Stern
2014-01-21 16:18                                                                             ` Phillip Susi
2014-01-21 16:49                                                                               ` Alan Stern
2014-01-21 15:44                                                                         ` Alan Stern
2014-01-21 16:18                                                                           ` Dan Williams
2014-01-21 16:55                                                                             ` Dan Williams
2014-01-20 12:38                                                                     ` CrashPlan Pro
2014-01-20 14:30                                                                       ` Phillip Susi
2014-01-18  1:24                                                           ` Todd E Brandt
2014-01-18  3:20                                                             ` Phillip Susi
2014-01-16 18:39                                                   ` Phillip Susi
2014-01-16 20:08                                                     ` Alan Stern
2014-01-17 10:16                                                   ` Oliver Neukum
2014-01-17 10:21                                                     ` Tejun Heo
2014-01-17 18:18                                                       ` Alan Stern
2014-01-17 18:39                                                       ` James Bottomley
2014-01-17 19:07                                                         ` Tejun Heo
2013-11-09 21:03       ` [PATCH 1/6] libata: use sleep instead of standby command Phillip Susi
2013-11-09 21:03       ` [PATCH 2/6] libata: avoid waking disk to check power Phillip Susi
2013-11-11 13:05         ` Sergei Shtylyov
2013-11-09 21:03       ` [PATCH 3/6] sd: don't bother spinning up disks on resume Phillip Susi
2013-11-11 13:08         ` Sergei Shtylyov
2013-11-11 14:28           ` Phillip Susi
2013-11-09 21:03       ` [PATCH 4/6] libata: resume in the background Phillip Susi
2013-11-11 13:10         ` Sergei Shtylyov
2013-11-09 21:03       ` [PATCH 5/6] libata: don't start disks on resume Phillip Susi
2013-11-09 21:03       ` [PATCH 6/6] libata: fake some more commands when drive is sleeping Phillip Susi
2013-11-11 16:59       ` [PATCH/RESEND v2 0/2] SATA disk resume time optimization Todd E Brandt
2013-11-11 17:08         ` Phillip Susi
2013-12-17 12:15           ` Tejun Heo
2013-12-17 14:24             ` Phillip Susi
2013-11-27 16:18 ` Phillip Susi

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=66174540.xyTk2QCVeJ@vostro.rjw.lan \
    --to=rjw@rjwysocki.net \
    --cc=aaron.lu@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=psusi@ubuntu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.