From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>
Cc: "tom.leiming@gmail.com" <tom.leiming@gmail.com>,
"hch@lst.de" <hch@lst.de>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"jthumshirn@suse.de" <jthumshirn@suse.de>,
"stern@rowland.harvard.edu" <stern@rowland.harvard.edu>,
"axboe@kernel.dk" <axboe@kernel.dk>
Subject: Re: [PATCH 2/3] block, scsi: Rework runtime power management
Date: Thu, 19 Jul 2018 06:45:46 +0800 [thread overview]
Message-ID: <20180718224545.GA15589@ming.t460p> (raw)
In-Reply-To: <60ce50f281bf41483b53246d509697f6d95360f8.camel@wdc.com>
On Wed, Jul 18, 2018 at 03:45:15PM +0000, Bart Van Assche wrote:
> On Wed, 2018-07-18 at 20:16 +0800, Ming Lei wrote:
> > On Wed, Jul 18, 2018 at 7:49 AM, Bart Van Assche <bart.vanassche@wdc.com> wrote:
> > > @@ -3801,8 +3778,11 @@ int blk_pre_runtime_suspend(struct request_queue *q)
> > > if (!q->dev)
> > > return ret;
> > >
> > > + blk_set_preempt_only(q);
> > > + blk_freeze_queue_start(q);
> > > +
> > > spin_lock_irq(q->queue_lock);
> > > - if (q->nr_pending) {
> > > + if (!percpu_ref_is_zero(&q->q_usage_counter)) {
> >
> > This way can't work reliably because the percpu ref isn't in atomic mode
> > yet after blk_freeze_queue_start() returns, then percpu_ref_is_zero() won't
> > see accurate value of the counter, finally the device may be put down before
> > in-flight requests are completed by hardware.
>
> Hello Ming,
>
> The blk_freeze_queue_start() implementation is as follows:
>
> void blk_freeze_queue_start(struct request_queue *q)
> {
> int freeze_depth;
>
> freeze_depth = atomic_inc_return(&q->mq_freeze_depth);
> if (freeze_depth == 1) {
> percpu_ref_kill(&q->q_usage_counter);
> if (q->mq_ops)
> blk_mq_run_hw_queues(q, false);
> }
> }
>
> From the documentation header in include/linux/percpu-refcount.h above
> percpu_ref_kill():
>
> * Switches @ref into atomic mode before gathering up the percpu counters
> * and dropping the initial ref.
IMO, the comment isn't accurate enough. Yes, the counter becomes atomic
mode after percpu_ref_kill() returns, but the counter can't be retrieved
accurately before the rcu confirmation is done.
One extra get is done in __percpu_ref_switch_to_atomic(), and the put pair
is run in percpu_ref_call_confirm_rcu(), which is scheduled via call_rcu_sched().
So once blk_freeze_queue_start() returns, percpu_ref_is_zero() won't
return true only until the rcu confirmation is done. That means this
approach may not put device down.
Thanks,
Ming
next prev parent reply other threads:[~2018-07-18 22:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-17 23:49 [PATCH 0/3] blk-mq: Enable runtime power management Bart Van Assche
2018-07-17 23:49 ` [PATCH 1/3] block: Fix a comment in a header file Bart Van Assche
2018-07-18 6:47 ` Johannes Thumshirn
2018-07-17 23:49 ` [PATCH 2/3] block, scsi: Rework runtime power management Bart Van Assche
2018-07-18 12:16 ` Ming Lei
2018-07-18 15:45 ` Bart Van Assche
2018-07-18 22:45 ` Ming Lei [this message]
2018-07-19 15:54 ` Bart Van Assche
2018-07-19 23:26 ` Ming Lei
2018-07-17 23:49 ` [PATCH 3/3] blk-mq: Enable support for " Bart Van Assche
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=20180718224545.GA15589@ming.t460p \
--to=ming.lei@redhat.com \
--cc=Bart.VanAssche@wdc.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=jthumshirn@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tom.leiming@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox