All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: Phillip Susi <psusi@ubuntu.com>,
	Sujit Reddy Thumma <sthumma@codeaurora.org>
Cc: todd.e.brandt@linux.intel.com, tj@kernel.org,
	JBottomley@parallels.com, linux-ide@vger.kernel.org,
	linux-scsi@vger.kernel.org,
	Alan Stern <stern@rowland.harvard.edu>,
	Linux-pm mailing list <linux-pm@vger.kernel.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>
Subject: Re: REQ_PM vs REQ_TYPE_PM_RESUME
Date: Tue, 07 Jan 2014 15:49:28 +0800	[thread overview]
Message-ID: <52CBB188.2080707@intel.com> (raw)
In-Reply-To: <52CAC067.20601@ubuntu.com>

On 01/06/2014 10:40 PM, Phillip Susi wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 1/6/2014 4:15 AM, Aaron Lu wrote:
>> My guess why it doesn't work for you is that, when you call 
>> blk_pre_runtime_suspend in sd_resume_work, there are requests left
>> in the queue so that call will simply fail, it's not meant to be
>> used that way.
> 
> There should be no other requests during the system resume callback.

There can be requests left when system resume callback is invoked, but
it's not always the case and depends on what you are doing before system
suspend.

> 
>> It seems you are making use of runtime PM to speed up disk resume,
>> if that is the case, I think we can simply make sure the disk's
>> block queue is put into the same state as runtime suspended and
>> then mark it as runtime suspended during system suspend phase; on
>> system resume, call
> 
> I think I tried that and it didn't work; when it is runtime suspended
> when the system suspends, it's no longer runtime suspended when the
> system resume function was called.  Hence why I'm using the

We can modify the device's system resume callback. To better illustrate
the idea, I just made two patches to do this and I did some quick tests
and didn't find anything wrong.

The two patches are here.

From: Aaron Lu <aaron.lu@intel.com>
Date: Tue, 7 Jan 2014 15:02:13 +0800
Subject: [PATCH 1/2] SCSI: pm: make use of runtime PM for SCSI device

To make system resume fast, modify SCSI PM callbacks so that if
CONFIG_PM_RUNTIME is set, during a system suspend transition, make the
disk device's status exactly the same as runtime suspended, i.e. drain
its request queue and set its request queue's status to RPM_SUSPENDED,
so that during system resume phase, instead of resuming the device
synchronously, we can relay the resume operation to runtime PM framework
by calling pm_request_resume to take advantage of the block layer
runtime PM.

The simplest way to achieve this would be to use the bus' runtime suspend
callback for system suspend callback, but for sr driver, it will refuse
to enter runtime suspend state if there is media inside. This is obviously
not acceptable for system suspend, so instead of using driver's runtime
suspend callback, we keep using driver's system suspend callback(which
is the same for sd and doesn't matter for sr). In addition to drain device's
request queue and set proper runtime status for its request queue, we will
also set the device's runtime status accordingly in its system suspend
callback.

This is part 1, we will also need to do the same thing for the disk's
host, i.e. ATA port on PCs. The next patch will handle just that.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/scsi/scsi_lib.c  | 11 +++++++++
 drivers/scsi/scsi_pm.c   | 60 +++++++++++++++++++++++++++++++++++++++---------
 drivers/scsi/scsi_priv.h |  3 +++
 3 files changed, 63 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 7bd7f0d5f050..2b490813d5ed 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2433,6 +2433,17 @@ void scsi_device_resume(struct scsi_device *sdev)
 }
 EXPORT_SYMBOL(scsi_device_resume);
 
+#ifdef CONFIG_PM_RUNTIME
+void scsi_device_drain_queue(struct scsi_device *sdev)
+{
+	scsi_run_queue(sdev->request_queue);
+	while (sdev->request_queue->nr_pending) {
+		msleep_interruptible(200);
+		scsi_run_queue(sdev->request_queue);
+	}
+}
+#endif
+
 static void
 device_quiesce_fn(struct scsi_device *sdev, void *data)
 {
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index 001e9ceda4c3..4f3fbd91c396 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -16,6 +16,24 @@
 
 #include "scsi_priv.h"
 
+#ifdef CONFIG_PM_RUNTIME
+static int sdev_runtime_suspend_common(struct device *dev,
+				       int (*cb)(struct device *))
+{
+	struct scsi_device *sdev = to_scsi_device(dev);
+	int err;
+
+	err = blk_pre_runtime_suspend(sdev->request_queue);
+	if (err)
+		return err;
+	if (cb)
+		err = cb(dev);
+	blk_post_runtime_suspend(sdev->request_queue, err);
+
+	return err;
+}
+#endif
+
 #ifdef CONFIG_PM_SLEEP
 
 static int scsi_dev_type_suspend(struct device *dev, int (*cb)(struct device *))
@@ -95,6 +113,35 @@ static int scsi_bus_prepare(struct device *dev)
 	return 0;
 }
 
+#ifdef CONFIG_PM_RUNTIME
+static int sdev_system_suspend(struct device *dev, int (*cb)(struct device *))
+{
+	scsi_device_drain_queue(to_scsi_device(dev));
+	return sdev_runtime_suspend_common(dev, cb);
+}
+
+static int scsi_bus_suspend(struct device *dev)
+{
+	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
+	int err = 0;
+
+	if (scsi_is_sdev_device(dev))
+		err = sdev_system_suspend(dev, pm ? pm->suspend : NULL);
+
+	if (!err) {
+		__pm_runtime_disable(dev, false);
+		pm_runtime_set_suspended(dev);
+		pm_runtime_enable(dev);
+	}
+
+	return err;
+}
+
+static int scsi_bus_resume(struct device *dev)
+{
+	return pm_request_resume(dev);
+}
+#else
 static int scsi_bus_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
@@ -106,6 +153,7 @@ static int scsi_bus_resume(struct device *dev)
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 	return scsi_bus_resume_common(dev, pm ? pm->resume : NULL);
 }
+#endif
 
 static int scsi_bus_freeze(struct device *dev)
 {
@@ -148,17 +196,7 @@ static int scsi_bus_restore(struct device *dev)
 static int sdev_runtime_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
-	struct scsi_device *sdev = to_scsi_device(dev);
-	int err;
-
-	err = blk_pre_runtime_suspend(sdev->request_queue);
-	if (err)
-		return err;
-	if (pm && pm->runtime_suspend)
-		err = pm->runtime_suspend(dev);
-	blk_post_runtime_suspend(sdev->request_queue, err);
-
-	return err;
+	return sdev_runtime_suspend_common(dev, pm->runtime_suspend);
 }
 
 static int scsi_runtime_suspend(struct device *dev)
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index f079a598bed4..fdd3a3a04eb4 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -90,6 +90,9 @@ extern void scsi_run_host_queues(struct Scsi_Host *shost);
 extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev);
 extern int scsi_init_queue(void);
 extern void scsi_exit_queue(void);
+#ifdef CONFIG_PM_RUNTIME
+extern void scsi_device_drain_queue(struct scsi_device *sdev);
+#endif
 struct request_queue;
 struct request;
 extern struct kmem_cache *scsi_sdb_cache;
-- 
1.8.4.2


From: Aaron Lu <aaron.lu@intel.com>
Date: Tue, 7 Jan 2014 15:14:09 +0800
Subject: [PATCH 2/2] ata: pm: make use of runtime PM for ata port

To realize fast resume for hard disks, the ata port's device will also
need to make use of runtime PM in its system resume callback.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/ata/libata-core.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 1393a5890ed5..4f92a7834dd1 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5396,10 +5396,18 @@ static int ata_port_suspend_common(struct device *dev, pm_message_t mesg)
 
 static int ata_port_suspend(struct device *dev)
 {
+	int err;
+
 	if (pm_runtime_suspended(dev))
 		return 0;
 
-	return ata_port_suspend_common(dev, PMSG_SUSPEND);
+	err = ata_port_suspend_common(dev, PMSG_SUSPEND);
+	if (!err) {
+		__pm_runtime_disable(dev, false);
+		pm_runtime_set_suspended(dev);
+		pm_runtime_enable(dev);
+	}
+	return err;
 }
 
 static int ata_port_do_freeze(struct device *dev)
@@ -5432,6 +5440,12 @@ static int ata_port_resume_common(struct device *dev, pm_message_t mesg)
 	return __ata_port_resume_common(ap, mesg, NULL);
 }
 
+#ifdef CONFIG_PM_RUNTIME
+static int ata_port_resume(struct device *dev)
+{
+	return pm_request_resume(dev);
+}
+#else
 static int ata_port_resume(struct device *dev)
 {
 	int rc;
@@ -5445,6 +5459,7 @@ static int ata_port_resume(struct device *dev)
 
 	return rc;
 }
+#endif
 
 /*
  * For ODDs, the upper layer will poll for media change every few seconds,
-- 
1.8.4.2


  parent reply	other threads:[~2014-01-07  7:49 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 [this message]
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
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=52CBB188.2080707@intel.com \
    --to=aaron.lu@intel.com \
    --cc=JBottomley@parallels.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=psusi@ubuntu.com \
    --cc=rjw@rjwysocki.net \
    --cc=stern@rowland.harvard.edu \
    --cc=sthumma@codeaurora.org \
    --cc=tj@kernel.org \
    --cc=todd.e.brandt@linux.intel.com \
    /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.