public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>
Cc: "axboe@kernel.dk" <axboe@kernel.dk>,
	"jthumshirn@suse.de" <jthumshirn@suse.de>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
	"hch@lst.de" <hch@lst.de>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"hare@suse.de" <hare@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>,
	"jianchao.w.wang@oracle.com" <jianchao.w.wang@oracle.com>,
	"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>,
	"adrian.hunter@intel.com" <adrian.hunter@intel.com>
Subject: Re: [RFC PATCH 13/14] block: simplify runtime PM support
Date: Wed, 8 Aug 2018 11:50:41 +0800	[thread overview]
Message-ID: <20180808035040.GC9523@ming.t460p> (raw)
In-Reply-To: <a1b7afb7e912c84b908342922b2fba12a364fd76.camel@wdc.com>

On Tue, Aug 07, 2018 at 07:54:44PM +0000, Bart Van Assche wrote:
> On Wed, 2018-08-08 at 01:44 +0800, Ming Lei wrote:
> > @@ -3772,6 +3764,7 @@ int blk_pre_runtime_suspend(struct request_queue *q)
> >         if (!q->dev)
> >                 return ret;
> >  
> > +       mutex_lock(&q->pm_lock);
> >         spin_lock_irq(q->queue_lock);
> >         if (q->nr_pending) {
> >                 ret = -EBUSY;
> > @@ -3780,6 +3773,13 @@ int blk_pre_runtime_suspend(struct request_queue *q)
> >                 q->rpm_status = RPM_SUSPENDING;
> >         }
> 
> Hello Ming,
> 
> As far as I can see none of the patches in this series adds a call to
> blk_pm_add_request() in the blk-mq code. Does that mean that q->nr_pending
> will always be zero for blk-mq code with your approach and hence that runtime

The counter of q->nr_pending is legacy only, and I just forgot to check
blk-mq queue idle in next patch, but the runtime PM still works in this
way for blk-mq, :-)

> suspend can get triggered while I/O is in progress, e.g. if blk_queue_enter()
> is called concurrently with blk_pre_runtime_suspend()?

In this patchset, for blk-mq, runtime suspend is tried when the auto_suspend
period is expired.

Yes, blk_queue_enter() can run concurrently with blk_pre_runtime_suspend().

	1) if queue isn't frozen, blk_pre_runtime_suspend() will wait for
	completion of the coming request

	2) if queue is frozen, blk_queue_enter() will try to resume the device
	via blk_resume_queue(), and q->pm_lock is use for covering the two paths.

But I should have checked the inflight request counter in blk_pre_runtime_suspend()
like the following way before freezing queue, will add it in V2 if no
one objects this approach.

diff --git a/block/blk-core.c b/block/blk-core.c
index 26f9ceb85318..d1a5cd1da861 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3730,6 +3730,24 @@ void blk_pm_runtime_init(struct request_queue *q, struct device *dev)
 }
 EXPORT_SYMBOL(blk_pm_runtime_init);
 
+static void blk_mq_pm_check_idle(struct blk_mq_hw_ctx *hctx,
+		struct request *rq, void *priv, bool reserved)
+{
+	unsigned long *cnt = priv;
+
+	(*cnt)++;
+}
+
+static bool blk_mq_pm_queue_idle(struct request_queue *q)
+{
+	unsigned long idle_cnt;
+
+	idle_cnt = 0;
+	blk_mq_queue_tag_busy_iter(q, blk_mq_pm_check_idle, &idle_cnt);
+
+	return idle_cnt == 0;
+}
+
 /**
  * blk_pre_runtime_suspend - Pre runtime suspend check
  * @q: the queue of the device
@@ -3754,13 +3772,18 @@ EXPORT_SYMBOL(blk_pm_runtime_init);
 int blk_pre_runtime_suspend(struct request_queue *q)
 {
 	int ret = 0;
+	bool mq_idle = false;
 
 	if (!q->dev)
 		return ret;
 
 	mutex_lock(&q->pm_lock);
+
+	if (q->mq_ops)
+		mq_idle = blk_mq_pm_queue_idle(q);
+
 	spin_lock_irq(q->queue_lock);
-	if (q->nr_pending) {
+	if (q->nr_pending || !mq_idle) {
 		ret = -EBUSY;
 		pm_runtime_mark_last_busy(q->dev);
 	} else {

Thanks,
Ming

  reply	other threads:[~2018-08-08  3:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-07 17:44 [RFC PATCH 00/14] SCSI: introduce per-host admin queue & enable runtime PM Ming Lei
2018-08-07 17:44 ` [RFC PATCH 01/14] blk-mq: allow to pass default queue flags for creating & initializing queue Ming Lei
2018-08-07 17:44 ` [RFC PATCH 02/14] blk-mq: convert BLK_MQ_F_NO_SCHED into per-queue flag Ming Lei
2018-08-07 17:44 ` [RFC PATCH 03/14] SCSI: try to retrieve request_queue via 'scsi_cmnd' if possible Ming Lei
2018-08-07 17:44 ` [RFC PATCH 04/14] SCSI: pass 'scsi_device' instance from 'scsi_request' Ming Lei
2018-08-07 17:44 ` [RFC PATCH 05/14] SCSI: prepare for introducing admin queue for legacy path Ming Lei
2018-08-07 17:44 ` [RFC PATCH 06/14] SCSI: pass scsi_device to scsi_mq_prep_fn Ming Lei
2018-08-07 23:24   ` Bart Van Assche
2018-08-08  3:37     ` Ming Lei
2018-08-07 17:44 ` [RFC PATCH 07/14] SCSI: don't set .queuedata in scsi_mq_alloc_queue() Ming Lei
2018-08-07 17:44 ` [RFC PATCH 08/14] SCSI: deal with admin queue busy Ming Lei
2018-08-07 17:44 ` [RFC PATCH 09/14] SCSI: create admin queue for each host Ming Lei
2018-08-08  5:57   ` jianchao.wang
2018-08-08  7:11     ` Ming Lei
2018-08-08  7:34       ` jianchao.wang
2018-08-08  7:46         ` Ming Lei
2018-08-07 17:44 ` [RFC PATCH 10/14] SCSI: use the dedicated admin queue to send admin commands Ming Lei
2018-08-07 23:33   ` Bart Van Assche
2018-08-08  3:36     ` Ming Lei
2018-08-07 17:44 ` [RFC PATCH 11/14] SCSI: transport_spi: resume a quiesced device Ming Lei
2018-08-07 17:44 ` [RFC PATCH 12/14] SCSI: use admin queue to implement queue QUIESCE Ming Lei
2018-08-07 17:44 ` [RFC PATCH 13/14] block: simplify runtime PM support Ming Lei
2018-08-07 19:54   ` Bart Van Assche
2018-08-08  3:50     ` Ming Lei [this message]
2018-08-08  7:57       ` jianchao.wang
2018-08-07 17:44 ` [RFC PATCH 14/14] block: enable runtime PM for blk-mq Ming Lei
2018-08-08 14:06 ` [RFC PATCH 00/14] SCSI: introduce per-host admin queue & enable runtime PM Alan Stern
2018-08-08 15:25   ` Ming Lei

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=20180808035040.GC9523@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=adrian.hunter@intel.com \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jianchao.w.wang@oracle.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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