linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Huang Ying <ying.huang@intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: ming.m.lin@intel.com, linux-kernel@vger.kernel.org,
	linux-scsi@vger.kernel.org, linux-pm@vger.kernel.org,
	"Rafael J. Wysocki" <rjw@sisk.pl>,
	James Bottomley <JBottomley@parallels.com>,
	Huang Ying <ying.huang@intel.com>
Subject: [RFC 3/5] scsi, pm, add pm_runtime_get/put in scsi request function
Date: Mon,  6 Feb 2012 15:32:26 +0800	[thread overview]
Message-ID: <1328513548-19786-4-git-send-email-ying.huang@intel.com> (raw)
In-Reply-To: <1328513548-19786-1-git-send-email-ying.huang@intel.com>

To support request based scsi device runtime PM.

Signed-off-by: Huang Ying <ying.huang@intel.com>
---
 drivers/scsi/scsi_lib.c  |   10 ++++++++++
 drivers/scsi/scsi_pm.c   |   30 ++++++++++++++++++++++++++++++
 drivers/scsi/scsi_priv.h |    8 ++++++++
 3 files changed, 48 insertions(+)

--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -314,6 +314,8 @@ void scsi_device_unbusy(struct scsi_devi
 	spin_unlock(shost->host_lock);
 	spin_lock(sdev->request_queue->queue_lock);
 	sdev->device_busy--;
+	if (!sdev->device_busy)
+		scsi_autopm_put_device(sdev);
 	spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
 }
 
@@ -1418,6 +1420,8 @@ static void scsi_kill_request(struct req
 	 * bump busy counts.  To bump the counters, we need to dance
 	 * with the locks as normal issue path does.
 	 */
+	if (!sdev->device_busy)
+		scsi_autopm_get_device_noresume(sdev);
 	sdev->device_busy++;
 	spin_unlock(sdev->request_queue->queue_lock);
 	spin_lock(shost->host_lock);
@@ -1520,6 +1524,10 @@ static void scsi_request_fn(struct reque
 		}
 
 
+		if (!sdev->device_busy) {
+			if (scsi_autopm_get_device(sdev))
+				break;
+		}
 		/*
 		 * Remove the request from the request list.
 		 */
@@ -1600,6 +1608,8 @@ static void scsi_request_fn(struct reque
 	spin_lock_irq(q->queue_lock);
 	blk_requeue_request(q, req);
 	sdev->device_busy--;
+	if (sdev->device_busy == 0)
+		scsi_autopm_put_device_noidle(sdev);
 out_delay:
 	if (sdev->device_busy == 0)
 		blk_delay_queue(q, SCSI_QUEUE_DELAY);
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -176,12 +176,42 @@ int scsi_autopm_get_device_sync(struct s
 }
 EXPORT_SYMBOL_GPL(scsi_autopm_get_device_sync);
 
+int scsi_autopm_get_device(struct scsi_device *sdev)
+{
+	int	err;
+
+	err = pm_runtime_get(&sdev->sdev_gendev);
+	if (err < 0 && err != -EACCES && err != -EINPROGRESS &&
+	    err != -EAGAIN)
+		pm_runtime_put_noidle(&sdev->sdev_gendev);
+	else
+		err = 0;
+	return err;
+}
+
+void scsi_autopm_get_device_noresume(struct scsi_device *sdev)
+{
+	pm_runtime_get_noresume(&sdev->sdev_gendev);
+}
+
 void scsi_autopm_put_device_sync(struct scsi_device *sdev)
 {
+	pm_runtime_mark_last_busy(&sdev->sdev_gendev);
 	pm_runtime_put_sync(&sdev->sdev_gendev);
 }
 EXPORT_SYMBOL_GPL(scsi_autopm_put_device_sync);
 
+void scsi_autopm_put_device(struct scsi_device *sdev)
+{
+	pm_runtime_mark_last_busy(&sdev->sdev_gendev);
+	pm_runtime_put(&sdev->sdev_gendev);
+}
+
+void scsi_autopm_put_device_noidle(struct scsi_device *sdev)
+{
+	pm_runtime_put_noidle(&sdev->sdev_gendev);
+}
+
 void scsi_autopm_get_target_sync(struct scsi_target *starget)
 {
 	pm_runtime_get_sync(&starget->dev);
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -151,11 +151,19 @@ static inline void scsi_netlink_exit(voi
 extern const struct dev_pm_ops scsi_bus_pm_ops;
 #endif
 #ifdef CONFIG_PM_RUNTIME
+extern int scsi_autopm_get_device(struct scsi_device *);
+extern void scsi_autopm_get_device_noresume(struct scsi_device *);
+extern void scsi_autopm_put_device(struct scsi_device *);
+extern void scsi_autopm_put_device_noidle(struct scsi_device *);
 extern void scsi_autopm_get_target_sync(struct scsi_target *);
 extern void scsi_autopm_put_target_sync(struct scsi_target *);
 extern int scsi_autopm_get_host_sync(struct Scsi_Host *);
 extern void scsi_autopm_put_host_sync(struct Scsi_Host *);
 #else
+extern int scsi_autopm_get_device(struct scsi_device *sdev) { return 0; }
+extern void scsi_autopm_get_device_noresume(struct scsi_device *sdev) {}
+extern void scsi_autopm_put_device(struct scsi_device *sdev) {}
+extern void scsi_autopm_put_device_noidle(struct scsi_device *sdev) {}
 static inline void scsi_autopm_get_target_sync(struct scsi_target *t) {}
 static inline void scsi_autopm_put_target_sync(struct scsi_target *t) {}
 static inline int scsi_autopm_get_host_sync(struct Scsi_Host *h) { return 0; }

  parent reply	other threads:[~2012-02-06  7:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-06  7:32 [RFC 0/5] scsi, sd, pm, request based runtime PM for scsi disk Huang Ying
2012-02-06  7:32 ` [RFC 1/5] pm, runtime, Add resume notifier Huang Ying
2012-02-06  7:32 ` [RFC 2/5] scsi, pm, rename scsi_autopm_get/put_xxx to scsi_autopm_get/put_xxx_sync Huang Ying
2012-02-06  7:32 ` Huang Ying [this message]
2012-02-06  7:32 ` [RFC 4/5] scsi, pm, use autosuspend for scsi runtime PM Huang Ying
2012-02-06  7:32 ` [RFC 5/5] scsi, sd, pm, request based runtime PM support Huang Ying
2012-02-06 15:13 ` [RFC 0/5] scsi, sd, pm, request based runtime PM for scsi disk Alan Stern
2012-02-07  4:59   ` Huang Ying
2012-02-11 19:37   ` Oliver Neukum
2012-02-12 18:05     ` Alan Stern
2012-02-12 20:00       ` Oliver Neukum
2012-02-13  1:42         ` Alan Stern
2012-02-13  9:28           ` Oliver Neukum
2012-02-13 15:20             ` Alan Stern
2012-02-18 20:44         ` Alan Stern

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=1328513548-19786-4-git-send-email-ying.huang@intel.com \
    --to=ying.huang@intel.com \
    --cc=JBottomley@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=ming.m.lin@intel.com \
    --cc=rjw@sisk.pl \
    --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).