SCSI: introduce per-host admin queue & enable runtime PM
Subsystems (6)
cover SCSI: introduce per-host admin queue & enable runtime PM
Hi,
This patchset introduces per-host admin request queue for submitting admin request only, and uses this approach to implement both SCSI quiesce and runtime PM in one very simply way. Also runtime PM deadlock can be avoided in case that request pool is used up.
The idea is borrowed from NVMe.
Admin request is submitted via per-host admin queue, and it is still associated with the same scsi_device as before, and respects this scsi_device's all kinds of limits. Admin queue shares host tags with other IO queues.
One core idea is that for admin request submitted from this admin queue, this request won't be called back to block layer via the associated IO queue(scsi_device). And this is done in the 3rd patch. So once IO queue is frozen, it can be observed as really frozen from block layer view.
SCSI quiesce is implemented by admin queue in very simple way, see patch 12.
Also runtime PM for legacy path can be simplified too, see patch 13.
Finally blk-mq simply follows legacy's approach for supporting runtime PM.
Any comments are welcome!
Thanks,
Ming Lei (14):
blk-mq: allow to pass default queue flags for creating & initializing
queue
blk-mq: convert BLK_MQ_F_NO_SCHED into per-queue flag
SCSI: try to retrieve request_queue via 'scsi_cmnd' if possible
SCSI: pass 'scsi_device' instance from 'scsi_request'
SCSI: prepare for introducing admin queue for legacy path
SCSI: pass scsi_device to scsi_mq_prep_fn
SCSI: don't set .queuedata in scsi_mq_alloc_queue()
SCSI: deal with admin queue busy
SCSI: create admin queue for each host
SCSI: use the dedicated admin queue to send admin commands
SCSI: transport_spi: resume a quiesced device
SCSI: use admin queue to implement queue QUIESCE
block: simplify runtime PM support
block: enable runtime PM for blk-mq
block/blk-core.c | 122 ++++++------------ block/blk-mq-debugfs.c | 3 +- block/blk-mq.c | 22 ++-- block/elevator.c | 10 +- drivers/block/null_blk_main.c | 7 +- drivers/nvme/host/fc.c | 4 +- drivers/nvme/host/pci.c | 4 +- drivers/nvme/host/rdma.c | 4 +- drivers/nvme/target/loop.c | 4 +- drivers/scsi/hosts.c | 9 ++ drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_scsi_host.c | 2 +- drivers/scsi/scsi_error.c | 2 +- drivers/scsi/scsi_lib.c | 250 ++++++++++++++++++++++++++---------- drivers/scsi/scsi_priv.h | 1 + drivers/scsi/scsi_scan.c | 1 + drivers/scsi/scsi_sysfs.c | 1 + drivers/scsi/scsi_transport_spi.c | 3 + include/linux/blk-mq.h | 20 ++- include/linux/blkdev.h | 13 +- include/scsi/scsi_device.h | 5 +- include/scsi/scsi_host.h | 2 + include/scsi/scsi_request.h | 5 +- 23 files changed, 306 insertions(+), 190 deletions(-)
Signature · 1 line
2.9.5
RFC PATCH 1/14 blk-mq: allow to pass default queue flags for creating & initializing queue
Prepare for converting the flag of BLK_MQ_F_NO_SCHED into per-queue flag, since the following patches need this way for supporting per-host admin queue.
--- block/blk-mq.c | 16 +++++++++------- include/linux/blk-mq.h | 19 ++++++++++++++++--- 2 files changed, 25 insertions(+), 10 deletions(-)
block/blk-mq.c +9 -7
@@ -2479,7 +2479,8 @@ void blk_mq_release(struct request_queue *q)free_percpu (q->queue_ctx); } -struct request_queue *blk_mq_init_queue (struct blk_mq_tag_set *set) +struct request_queue *__blk_mq_init_queue (struct blk_mq_tag_set *set, +unsigned long def_flags) {struct request_queue *uninit_q, *q;
@@ -2487,13 +2488,13 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)if (!uninit_q)return ERR_PTR (-ENOMEM ); - q =blk_mq_init_allocated_queue (set, uninit_q); + q =__blk_mq_init_allocated_queue (set, uninit_q, def_flags);if (IS_ERR (q))blk_cleanup_queue (uninit_q);return q; } -EXPORT_SYMBOL (blk_mq_init_queue); +EXPORT_SYMBOL (__blk_mq_init_queue);static int blk_mq_hw_ctx_size (struct blk_mq_tag_set *tag_set) {
@@ -2567,8 +2568,9 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,blk_mq_sysfs_register (q); } -struct request_queue *blk_mq_init_allocated_queue (struct blk_mq_tag_set *set, -struct request_queue *q) +struct request_queue *__blk_mq_init_allocated_queue (struct blk_mq_tag_set *set, +struct request_queue *q, +unsigned long def_flags) {/* mark the queue as mq asap */ q->mq_ops = set->ops;
@@ -2602,7 +2604,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, q->nr_queues = nr_cpu_ids; - q->queue_flags |=QUEUE_FLAG_MQ_DEFAULT ; + q->queue_flags |= def_flags;if (!(set->flags &BLK_MQ_F_SG_MERGE ))queue_flag_set_unlocked (QUEUE_FLAG_NO_SG_MERGE , q);
@@ -2652,7 +2654,7 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set, q->mq_ops =NULL ;return ERR_PTR (-ENOMEM ); } -EXPORT_SYMBOL (blk_mq_init_allocated_queue); +EXPORT_SYMBOL (__blk_mq_init_allocated_queue);void blk_mq_free_queue (struct request_queue *q) {
include/linux/blk-mq.h +16 -3
@@ -200,9 +200,22 @@ enum { ((policy & ((1 <<BLK_MQ_F_ALLOC_POLICY_BITS ) -1 )) \ << BLK_MQ_F_ALLOC_POLICY_START_BIT) -struct request_queue *blk_mq_init_queue (struct blk_mq_tag_set *); -struct request_queue *blk_mq_init_allocated_queue (struct blk_mq_tag_set *set, -struct request_queue *q); +struct request_queue *__blk_mq_init_queue (struct blk_mq_tag_set *,unsigned long ); +struct request_queue *__blk_mq_init_allocated_queue (struct blk_mq_tag_set *set, +struct request_queue *q, +unsigned long def_flags); + +static inline struct request_queue *blk_mq_init_queue (struct blk_mq_tag_set *set) +{ +return __blk_mq_init_queue (set,QUEUE_FLAG_MQ_DEFAULT ); +} + +static inline struct request_queue * +blk_mq_init_allocated_queue (struct blk_mq_tag_set *set,struct request_queue *q) +{ +return __blk_mq_init_allocated_queue (set, q,QUEUE_FLAG_MQ_DEFAULT ); +} +int blk_mq_register_dev (struct device *,struct request_queue *);void blk_mq_unregister_dev (struct device *,struct request_queue *);
Signature · 1 line
2.9.5
RFC PATCH 2/14 blk-mq: convert BLK_MQ_F_NO_SCHED into per-queue flag
In reply to Ming LeiWe need to support admin queue for scsi host, and not like NVMe, this support is only from logic view, and the admin queue still has to share same tags with IO queues.
Convert BLK_MQ_F_NO_SCHED into per-queue flag so that we can support admin queue for SCSI.
--- block/blk-mq-debugfs.c | 2 +- block/blk-mq.c | 2 +- block/elevator.c | 3 +-- drivers/block/null_blk_main.c | 7 ++++--- drivers/nvme/host/fc.c | 4 ++-- drivers/nvme/host/pci.c | 4 ++-- drivers/nvme/host/rdma.c | 4 ++-- drivers/nvme/target/loop.c | 4 ++-- include/linux/blk-mq.h | 1 - include/linux/blkdev.h | 5 +++++ 10 files changed, 20 insertions(+), 16 deletions(-)
block/blk-mq-debugfs.c +1 -1
@@ -133,6 +133,7 @@ static const char *const blk_queue_flag_name[] = {QUEUE_FLAG_NAME (SCSI_PASSTHROUGH ),QUEUE_FLAG_NAME (QUIESCED ),QUEUE_FLAG_NAME (PREEMPT_ONLY ), + QUEUE_FLAG_NAME(NO_SCHED), };#undef QUEUE_FLAG_NAME
@@ -246,7 +247,6 @@ static const char *const hctx_flag_name[] = {HCTX_FLAG_NAME (TAG_SHARED ),HCTX_FLAG_NAME (SG_MERGE ), HCTX_FLAG_NAME(BLOCKING), - HCTX_FLAG_NAME(NO_SCHED), };#undef HCTX_FLAG_NAME
block/blk-mq.c +1 -1
@@ -2636,7 +2636,7 @@ struct request_queue *__blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,blk_mq_add_queue_tag_set (set, q);blk_mq_map_swqueue (q); -if (!(set->flags &BLK_MQ_F_NO_SCHED )) { +if (!blk_queue_no_sched (q)) {int ret; ret =elevator_init_mq (q);
block/elevator.c +1 -2
@@ -1108,8 +1108,7 @@ static int __elevator_change(struct request_queue *q, const char *name)static inline bool elv_support_iosched (struct request_queue *q) { -if (q->mq_ops && q->tag_set && (q->tag_set->flags & -BLK_MQ_F_NO_SCHED )) +if (q->mq_ops &&blk_queue_no_sched (q))return false;return true; }
drivers/block/null_blk_main.c +4 -3
@@ -1615,8 +1615,6 @@ static int null_init_tag_set(struct nullb *nullb, struct blk_mq_tag_set *set) set->numa_node = nullb ? nullb->dev->home_node : g_home_node; set->cmd_size =sizeof (struct nullb_cmd ); set->flags =BLK_MQ_F_SHOULD_MERGE ; -if (g_no_sched) - set->flags |=BLK_MQ_F_NO_SCHED ; set->driver_data =NULL ;if ((nullb && nullb->dev->blocking) || g_blocking)
@@ -1701,6 +1699,9 @@ static int null_add_dev(struct nullb_device *dev) goto out_free_nullb;if (dev->queue_mode ==NULL_Q_MQ ) { +unsigned long q_flags = g_no_sched ? +QUEUE_FLAG_MQ_NO_SCHED_DEFAULT :QUEUE_FLAG_MQ_DEFAULT ; +if (shared_tags) { nullb->tag_set = &tag_set; rv =0 ;
@@ -1716,7 +1717,7 @@ static int null_add_dev(struct nullb_device *dev) goto out_cleanup_queues; nullb->tag_set->timeout =5 *HZ ; - nullb->q =blk_mq_init_queue (nullb->tag_set); + nullb->q =__blk_mq_init_queue (nullb->tag_set, q_flags);if (IS_ERR (nullb->q)) { rv = -ENOMEM ; goto out_cleanup_tags;
drivers/nvme/host/fc.c +2 -2
@@ -3034,14 +3034,14 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts, ctrl->admin_tag_set.driver_data = ctrl; ctrl->admin_tag_set.nr_hw_queues =1 ; ctrl->admin_tag_set.timeout =ADMIN_TIMEOUT ; - ctrl->admin_tag_set.flags =BLK_MQ_F_NO_SCHED ; ret =blk_mq_alloc_tag_set (&ctrl->admin_tag_set);if (ret) goto out_free_queues; ctrl->ctrl.admin_tagset = &ctrl->admin_tag_set; - ctrl->ctrl.admin_q =blk_mq_init_queue (&ctrl->admin_tag_set); + ctrl->ctrl.admin_q =__blk_mq_init_queue (&ctrl->admin_tag_set, +QUEUE_FLAG_MQ_NO_SCHED_DEFAULT );if (IS_ERR (ctrl->ctrl.admin_q)) { ret =PTR_ERR (ctrl->ctrl.admin_q); goto out_free_admin_tag_set;
drivers/nvme/host/pci.c +2 -2
@@ -1484,14 +1484,14 @@ static int nvme_alloc_admin_tags(struct nvme_dev *dev) dev->admin_tagset.timeout =ADMIN_TIMEOUT ; dev->admin_tagset.numa_node =dev_to_node (dev->dev); dev->admin_tagset.cmd_size =nvme_pci_cmd_size (dev, false); - dev->admin_tagset.flags =BLK_MQ_F_NO_SCHED ; dev->admin_tagset.driver_data = dev;if (blk_mq_alloc_tag_set (&dev->admin_tagset))return -ENOMEM ; dev->ctrl.admin_tagset = &dev->admin_tagset; - dev->ctrl.admin_q =blk_mq_init_queue (&dev->admin_tagset); + dev->ctrl.admin_q =__blk_mq_init_queue (&dev->admin_tagset, +QUEUE_FLAG_MQ_NO_SCHED_DEFAULT );if (IS_ERR (dev->ctrl.admin_q)) {blk_mq_free_tag_set (&dev->admin_tagset);return -ENOMEM ;
drivers/nvme/host/rdma.c +2 -2
@@ -692,7 +692,6 @@ static struct blk_mq_tag_set *nvme_rdma_alloc_tagset(struct nvme_ctrl *nctrl, set->driver_data = ctrl; set->nr_hw_queues =1 ; set->timeout =ADMIN_TIMEOUT ; - set->flags =BLK_MQ_F_NO_SCHED ; }else { set = &ctrl->tag_set;memset (set,0 ,sizeof (*set));
@@ -770,7 +769,8 @@ static int nvme_rdma_configure_admin_queue(struct nvme_rdma_ctrl *ctrl, goto out_free_async_qe; } - ctrl->ctrl.admin_q =blk_mq_init_queue (&ctrl->admin_tag_set); + ctrl->ctrl.admin_q =__blk_mq_init_queue (&ctrl->admin_tag_set, +QUEUE_FLAG_MQ_NO_SCHED_DEFAULT );if (IS_ERR (ctrl->ctrl.admin_q)) { error =PTR_ERR (ctrl->ctrl.admin_q); goto out_free_tagset;
drivers/nvme/target/loop.c +2 -2
@@ -368,7 +368,6 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl) ctrl->admin_tag_set.driver_data = ctrl; ctrl->admin_tag_set.nr_hw_queues =1 ; ctrl->admin_tag_set.timeout =ADMIN_TIMEOUT ; - ctrl->admin_tag_set.flags =BLK_MQ_F_NO_SCHED ; ctrl->queues[0 ].ctrl = ctrl; error =nvmet_sq_init (&ctrl->queues[0 ].nvme_sq);
@@ -381,7 +380,8 @@ static int nvme_loop_configure_admin_queue(struct nvme_loop_ctrl *ctrl) goto out_free_sq; ctrl->ctrl.admin_tagset = &ctrl->admin_tag_set; - ctrl->ctrl.admin_q =blk_mq_init_queue (&ctrl->admin_tag_set); + ctrl->ctrl.admin_q =__blk_mq_init_queue (&ctrl->admin_tag_set, +QUEUE_FLAG_MQ_NO_SCHED_DEFAULT );if (IS_ERR (ctrl->ctrl.admin_q)) { error =PTR_ERR (ctrl->ctrl.admin_q); goto out_free_tagset;
include/linux/blk-mq.h +0 -1
@@ -181,7 +181,6 @@ enum {BLK_MQ_F_TAG_SHARED =1 <<1 ,BLK_MQ_F_SG_MERGE =1 <<2 ,BLK_MQ_F_BLOCKING =1 <<5 , -BLK_MQ_F_NO_SCHED =1 <<6 ,BLK_MQ_F_ALLOC_POLICY_START_BIT =8 , BLK_MQ_F_ALLOC_POLICY_BITS = 1,
include/linux/blkdev.h +5 -0
@@ -701,6 +701,7 @@ struct request_queue {#define QUEUE_FLAG_SCSI_PASSTHROUGH 27/* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 28/* queue has been quiesced */ #define QUEUE_FLAG_PREEMPT_ONLY 29/* only process REQ_PREEMPT requests */ +#define QUEUE_FLAG_NO_SCHED 30/* no scheduler allowed */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ (1 << QUEUE_FLAG_SAME_COMP) | \
@@ -710,6 +711,9 @@ struct request_queue { (1 << QUEUE_FLAG_SAME_COMP) | \ (1 << QUEUE_FLAG_POLL)) +#define QUEUE_FLAG_MQ_NO_SCHED_DEFAULT (QUEUE_FLAG_MQ_DEFAULT | \ + (1 << QUEUE_FLAG_NO_SCHED)) +void blk_queue_flag_set (unsigned int flag,struct request_queue *q);void blk_queue_flag_clear (unsigned int flag,struct request_queue *q);bool blk_queue_flag_test_and_set (unsigned int flag,struct request_queue *q);
@@ -741,6 +745,7 @@ bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q);#define blk_queue_preempt_only (q) \ test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags)#define blk_queue_fua (q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) +#define blk_queue_no_sched (q) test_bit(QUEUE_FLAG_NO_SCHED, &(q)->queue_flags)extern int blk_set_preempt_only (struct request_queue *q);extern void blk_clear_preempt_only (struct request_queue *q);
Signature · 1 line
2.9.5
RFC PATCH 3/14 SCSI: try to retrieve request_queue via 'scsi_cmnd' if possible
In reply to Ming LeiPrepare for introduing per-host admin queue.
The most important part is that the request originated from admin queue can't be called back to the IO queue associated with scsi_device, especially, one request may be requeued, timedout or completed via block layer helper, so what we should do is to use 'scsi_cmnd->request->q' to retrieve the request queue, and pass that to block layer helper, instead of sdev->request_queue.
Fortunately most of users of 'scsi_device->request_queue' aren't in related IO path(requeue, timeout, complete, run queue), so the audit isn't more difficult than I thought of.
--- drivers/scsi/libsas/sas_ata.c | 2 +- drivers/scsi/libsas/sas_scsi_host.c | 2 +- drivers/scsi/scsi_error.c | 2 +- drivers/scsi/scsi_lib.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/libsas/sas_ata.c +1 -1
@@ -594,7 +594,7 @@ void sas_ata_task_abort(struct sas_task *task)/* Bounce SCSI-initiated commands to the SCSI EH */ if (qc->scsicmd) { -struct request_queue *q = qc->scsicmd->device->request_queue; +struct request_queue *q = qc->scsicmd->request->q;unsigned long flags;spin_lock_irqsave (q->queue_lock, flags);
drivers/scsi/libsas/sas_scsi_host.c +1 -1
@@ -933,7 +933,7 @@ void sas_task_abort(struct sas_task *task)if (dev_is_sata (task->dev)) {sas_ata_task_abort (task); }else { -struct request_queue *q = sc->device->request_queue; +struct request_queue *q = sc->request->q;unsigned long flags;spin_lock_irqsave (q->queue_lock, flags);
drivers/scsi/scsi_error.c +1 -1
@@ -1360,7 +1360,7 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd)int i, rtn =NEEDS_RETRY ;for (i =0 ; rtn ==NEEDS_RETRY && i <2 ; i++) - rtn =scsi_send_eh_cmnd (scmd, stu_command,6 , scmd->device->request_queue->rq_timeout,0 ); + rtn =scsi_send_eh_cmnd (scmd, stu_command,6 , scmd->request->q->rq_timeout,0 );if (rtn ==SUCCESS )return 0 ;
drivers/scsi/scsi_lib.c +3 -3
@@ -168,7 +168,7 @@ static void scsi_mq_requeue_cmd(struct scsi_cmnd *cmd)static void __scsi_queue_insert (struct scsi_cmnd *cmd,int reason,bool unbusy) {struct scsi_device *device = cmd->device; -struct request_queue *q = device->request_queue; +struct request_queue *q = cmd->request->q;unsigned long flags; SCSI_LOG_MLQUEUE(1, scmd_printk(KERN_INFO, cmd,
@@ -667,7 +667,7 @@ static bool scsi_end_request(struct request *req, blk_status_t error, {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);struct scsi_device *sdev = cmd->device; -struct request_queue *q = sdev->request_queue; +struct request_queue *q = cmd->request->q;if (blk_update_request (req, error, bytes))return true;
@@ -792,7 +792,7 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)void scsi_io_completion (struct scsi_cmnd *cmd,unsigned int good_bytes) {int result = cmd->result; -struct request_queue *q = cmd->device->request_queue; +struct request_queue *q = cmd->request->q;struct request *req = cmd->request;blk_status_t error =BLK_STS_OK ;struct scsi_sense_hdr sshdr;
Signature · 1 line
2.9.5
RFC PATCH 4/14 SCSI: pass 'scsi_device' instance from 'scsi_request'
In reply to Ming LeiThis patch prepares for introducing SCSI per-host admin queue, which is only used for queuing admin requests, which are now submitted via __scsi_execute().
--- drivers/scsi/scsi_lib.c | 2 ++ include/scsi/scsi_request.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +2 -0
@@ -279,6 +279,8 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, rq->cmd_len =COMMAND_SIZE (cmd[0 ]);memcpy (rq->cmd, cmd, rq->cmd_len); rq->retries = retries; + rq->sdev = sdev;/* only valid in submit path */ + req->timeout = timeout; req->cmd_flags |= flags; req->rq_flags |= rq_flags |RQF_QUIET ;
include/scsi/scsi_request.h +4 -1
@@ -14,7 +14,10 @@ struct scsi_request {unsigned int sense_len;unsigned int resid_len;/* residual count */ int retries; -void *sense; +union { +void *sense; +struct scsi_device *sdev; + }; };static inline struct scsi_request *scsi_req (struct request *rq)
Signature · 1 line
2.9.5
RFC PATCH 5/14 SCSI: prepare for introducing admin queue for legacy path
In reply to Ming LeiUses scsi_is_admin_queue() and scsi_get_scsi_dev() to retrieve 'scsi_device' for legacy path.
The same approach can be used in SCSI_MQ path too, just not efficiently, and will deal with this issue when introducing admin queue for SCSI_MQ.
--- drivers/scsi/scsi_lib.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
drivers/scsi/scsi_lib.c +27 -5
@@ -46,6 +46,20 @@ static DEFINE_MUTEX(scsi_sense_cache_mutex);static void scsi_mq_uninit_cmd (struct scsi_cmnd *cmd); +/* For admin queue, its queuedata is NULL */ +static inline bool scsi_is_admin_queue (struct request_queue *q) +{ +return !q->queuedata; +} + +/* This helper can only be used in req prep stage */ +static inline struct scsi_device *scsi_get_scsi_dev (struct request *rq) +{ +if (scsi_is_admin_queue (rq->q)) +return scsi_req (rq)->sdev; +return rq->q->queuedata; +} +static inline struct kmem_cache *scsi_select_sense_cache (bool unchecked_isa_dma) {
@@ -1378,7 +1392,7 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)static int scsi_prep_return (struct request_queue *q,struct request *req,int ret) { -struct scsi_device *sdev = q->queuedata; +struct scsi_device *sdev =scsi_get_scsi_dev (req);switch (ret) {case BLKPREP_KILL :
@@ -1411,7 +1425,7 @@ scsi_prep_return(struct request_queue *q, struct request *req, int ret)static int scsi_prep_fn (struct request_queue *q,struct request *req) { -struct scsi_device *sdev = q->queuedata; +struct scsi_device *sdev =scsi_get_scsi_dev (req);struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req);int ret;
@@ -1613,6 +1627,9 @@ static int scsi_lld_busy(struct request_queue *q)if (blk_queue_dying (q))return 0 ; +if (WARN_ON_ONCE (scsi_is_admin_queue (q))) +return 0 ; + shost = sdev->host;/*
@@ -1816,7 +1833,7 @@ static void scsi_request_fn(struct request_queue *q) __releases(q->queue_lock) __acquires(q->queue_lock) { -struct scsi_device *sdev = q->queuedata; +struct scsi_device *sdev;struct Scsi_Host *shost;struct scsi_cmnd *cmd;struct request *req;
@@ -1825,7 +1842,6 @@ static void scsi_request_fn(struct request_queue *q)* To start with, we keep looping until the queue is empty, or until * the host is no longer able to accept any more requests. */ - shost = sdev->host;for (;;) {int rtn;/*
@@ -1837,6 +1853,10 @@ static void scsi_request_fn(struct request_queue *q)if (!req)break ; + cmd =blk_mq_rq_to_pdu (req); + sdev = cmd->device; + shost = sdev->host; +if (unlikely (!scsi_device_online (sdev))) {sdev_printk (KERN_ERR , sdev,"rejecting I/O to offline device\n" );
@@ -1854,7 +1874,6 @@ static void scsi_request_fn(struct request_queue *q)blk_start_request (req);spin_unlock_irq (q->queue_lock); - cmd =blk_mq_rq_to_pdu (req);if (cmd != req->special) {printk (KERN_CRIT "impossible request in %s.\n" "please mail a stack trace to "
@@ -2332,6 +2351,9 @@ struct scsi_device *scsi_device_from_queue(struct request_queue *q) {struct scsi_device *sdev =NULL ; +/* admin queue won't be exposed to external users */ +WARN_ON_ONCE (scsi_is_admin_queue (q)); +if (q->mq_ops) {if (q->mq_ops == &scsi_mq_ops) sdev = q->queuedata;
Signature · 1 line
2.9.5
RFC PATCH 6/14 SCSI: pass scsi_device to scsi_mq_prep_fn
In reply to Ming LeiThis patchset will introduce per-host admin queue, so it may not to get 'scsi_device' via q->queuedata.
--- drivers/scsi/scsi_lib.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/scsi/scsi_lib.c +2 -3
@@ -1971,10 +1971,9 @@ static unsigned int scsi_mq_sgl_size(struct Scsi_Host *shost)sizeof (struct scatterlist ); } -static int scsi_mq_prep_fn (struct request *req) +static int scsi_mq_prep_fn (struct scsi_device *sdev,struct request *req) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req); -struct scsi_device *sdev = req->q->queuedata;struct Scsi_Host *shost = sdev->host;struct scatterlist *sg;
@@ -2070,7 +2069,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, goto out_dec_target_busy;if (!(req->rq_flags &RQF_DONTPREP )) { - ret =prep_to_mq (scsi_mq_prep_fn (req)); + ret =prep_to_mq (scsi_mq_prep_fn (sdev, req));if (ret !=BLK_STS_OK ) goto out_dec_host_busy; req->rq_flags |=RQF_DONTPREP ;
Signature · 1 line
2.9.5
Re: [RFC PATCH 06/14] SCSI: pass scsi_device to scsi_mq_prep_fn
drivers/scsi/scsi_lib.=
Quoted 1 line · Ming Lei
drivers/scsi/scsi_lib.= renamed from drivers/scsi/scsi_lib.c +0
-0
c
Quoted 4 lines
index
435347f58328..52e498fb6280100644
---a/drivers/scsi/scsi_lib.c
+-+-+-b/drivers/scsi/scsi_lib.c
@@ -1971,10 +-1971,9 @@ static unsigned int scsi_mq�
F8-sgl_size(struct Scsi_Host *shost)
Quoted 5 lines
sizeof(struct scatterlist);
}
=20
-static intscsi_mq_prep_fn(struct request *req)+-static int scsi_mq_prep_fn(structscsi_device*=
sdev, struct request *req)
Quoted 2 lines
{
structscsi_cmnd*cmd = blk_mq_rq_to_pd=
u(req);
drivers/scsi/scsi_lib.=
Quoted 1 line
drivers/scsi/scsi_lib.= renamed from drivers/scsi/scsi_lib.c +0
-1- struct scsi_device *sdev = req->q->queuedata�
s-
Quoted 4 lines
drivers/scsi/scsi_lib.= renamed from drivers/scsi/scsi_lib.c +0
-0struct Scsi_Host *shost = sdev->host; struct scatterlist *sg;=20
@@ -2070,7 +-2069,7 @@ staticblk_status_tscsi�
F8-queue_rq(struct blk_mq_hw_ctx *hctx,
drivers/scsi/scsi_lib.=
Quoted 4 lines
goto
out_dec_target_busy;
=20drivers/scsi/scsi_lib.= renamed from drivers/scsi/scsi_lib.c +0
-1if (!(req->rq_flags & RQF_DONTPREP)) { - ret = prep_to_mq(scsi_mq_prep_fn(req));
-
Quoted 1 line
+- ret = prep_to_mq(scsi_mq_prep_fn(sdev, re=
q));
drivers/scsi/scsi_lib.=
Quoted 3 lines
drivers/scsi/scsi_lib.= renamed from drivers/scsi/scsi_lib.c +0
-0if (ret != BLK_STS_OK) goto out_dec_host_busy; req->rq_flags |= RQF_DONTPREP;
This patch looks useful to me since it probably realizes a (small) performa= nce
improvement. I think this patch does not depend on any of the previous patc= hes
in this series. Is that correct?
Bart.
Re: [RFC PATCH 06/14] SCSI: pass scsi_device to scsi_mq_prep_fn
Quoted 20 lines · Bart Van Assche
Quoted 19 lines · Ming Lei
drivers/scsi/scsi_lib.c +1
-2@@ -1971,10 +1971,9 @@ static unsigned int scsi_mq_sgl_size(struct Scsi_Host *shost)sizeof (struct scatterlist ); } -static int scsi_mq_prep_fn (struct request *req) +static int scsi_mq_prep_fn (struct scsi_device *sdev,struct request *req) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (req); -struct scsi_device *sdev = req->q->queuedata;struct Scsi_Host *shost = sdev->host;struct scatterlist *sg;@@ -2070,7 +2069,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, goto out_dec_target_busy;
Quoted 10 lines
drivers/scsi/scsi_lib.c static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, · line 2075
Quoted 6 lines
drivers/scsi/scsi_lib.c +1
-1if (!(req->rq_flags &RQF_DONTPREP )) { - ret =prep_to_mq (scsi_mq_prep_fn (req)); + ret =prep_to_mq (scsi_mq_prep_fn (sdev, req));if (ret !=BLK_STS_OK ) goto out_dec_host_busy; req->rq_flags |=RQF_DONTPREP ;This patch looks useful to me since it probably realizes a (small) performance improvement. I think this patch does not depend on any of the previous patches in this series. Is that correct?
Yes, it is.
Thanks,
Ming
RFC PATCH 7/14 SCSI: don't set .queuedata in scsi_mq_alloc_queue()
In reply to Ming Lei.queuedata is set in scsi_alloc_sdev() for both non-mq and scsi_mq, so not necessary to do it in scsi_mq_alloc_queue().
--- drivers/scsi/scsi_lib.c | 1 - 1 file changed, 1 deletion(-)
drivers/scsi/scsi_lib.c +0 -1
@@ -2305,7 +2305,6 @@ struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev)if (IS_ERR (sdev->request_queue))return NULL ; - sdev->request_queue->queuedata = sdev;__scsi_init_queue (sdev->host, sdev->request_queue);blk_queue_flag_set (QUEUE_FLAG_SCSI_PASSTHROUGH , sdev->request_queue);return sdev->request_queue;
Signature · 1 line
2.9.5
RFC PATCH 8/14 SCSI: deal with admin queue busy
In reply to Ming LeiWhen request originated from admin queue isn't queued successfully, we deal with it just like for normal requests, that said the admin queue will be rerun after one request in this host is completed.
--- drivers/scsi/scsi_lib.c | 46 +++++++++++++++++++++++++++++++++------------- include/scsi/scsi_host.h | 2 ++ 2 files changed, 35 insertions(+), 13 deletions(-)
drivers/scsi/scsi_lib.c +33 -13
@@ -475,10 +475,14 @@ static void scsi_starved_list_run(struct Scsi_Host *shost)LIST_HEAD (starved_list);struct scsi_device *sdev;unsigned long flags; +bool run_admin;spin_lock_irqsave (shost->host_lock, flags);list_splice_init (&shost->starved_list, &starved_list); + run_admin = shost->run_admin_queue; + shost->run_admin_queue = false; +while (!list_empty (&starved_list)) {struct request_queue *slq;
@@ -527,6 +531,10 @@ static void scsi_starved_list_run(struct Scsi_Host *shost)/* put any unprocessed entries back */ list_splice (&starved_list, &shost->starved_list);spin_unlock_irqrestore (shost->host_lock, flags); + +/* no need to get queue for admin_q */ +if (run_admin) +scsi_kick_queue (shost->admin_q); }/*
@@ -541,14 +549,16 @@ static void scsi_starved_list_run(struct Scsi_Host *shost)* Notes: The previous command was completely finished, start * a new one if possible. */ -static void scsi_run_queue (struct request_queue *q) +static void scsi_run_queue (struct Scsi_Host *shost,struct request_queue *q) { -struct scsi_device *sdev = q->queuedata; +if (!scsi_is_admin_queue (q)) { +struct scsi_device *sdev = q->queuedata; +if (scsi_target (sdev)->single_lun) +scsi_single_lun_run (sdev); + } -if (scsi_target (sdev)->single_lun) -scsi_single_lun_run (sdev); -if (!list_empty (&sdev->host->starved_list)) -scsi_starved_list_run (sdev->host); +if (!list_empty (&shost->starved_list) || shost->run_admin_queue) +scsi_starved_list_run (shost);if (q->mq_ops)blk_mq_run_hw_queues (q, false);
@@ -563,7 +573,7 @@ void scsi_requeue_run_queue(struct work_struct *work) sdev = container_of(work, struct scsi_device, requeue_work); q = sdev->request_queue; -scsi_run_queue (q); +scsi_run_queue (sdev->host, q); }/*
@@ -597,7 +607,7 @@ static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd)blk_requeue_request (q, req);spin_unlock_irqrestore (q->queue_lock, flags); -scsi_run_queue (q); +scsi_run_queue (sdev->host, q);put_device (&sdev->sdev_gendev); }
@@ -607,7 +617,7 @@ void scsi_run_host_queues(struct Scsi_Host *shost)struct scsi_device *sdev;shost_for_each_device (sdev, shost) -scsi_run_queue (sdev->request_queue); +scsi_run_queue (shost, sdev->request_queue); }static void scsi_uninit_cmd (struct scsi_cmnd *cmd)
@@ -731,7 +741,7 @@ static bool scsi_end_request(struct request *req, blk_status_t error,blk_finish_request (req, error);spin_unlock_irqrestore (q->queue_lock, flags); -scsi_run_queue (q); +scsi_run_queue (sdev->host, q); }put_device (&sdev->sdev_gendev);
@@ -1495,6 +1505,12 @@ static inline int scsi_dev_queue_ready(struct request_queue *q,return 1 ; out_dec:atomic_dec (&sdev->device_busy); + +if (unlikely (scsi_is_admin_queue (q))) { +spin_lock_irq (sdev->host->host_lock); + sdev->host->run_admin_queue = true; +spin_unlock_irq (sdev->host->host_lock); + }return 0 ; }
@@ -1503,7 +1519,7 @@ static inline int scsi_dev_queue_ready(struct request_queue *q,* @sdev: scsi device on starget to check. */ static inline int scsi_target_queue_ready (struct Scsi_Host *shost, -struct scsi_device *sdev) +struct scsi_device *sdev,bool admin) {struct scsi_target *starget =scsi_target (sdev);unsigned int busy;
@@ -1545,6 +1561,8 @@ static inline int scsi_target_queue_ready(struct Scsi_Host *shost, starved:spin_lock_irq (shost->host_lock);list_move_tail (&sdev->starved_entry, &shost->starved_list); +if (admin) + shost->run_admin_queue = true;spin_unlock_irq (shost->host_lock); out_dec:if (starget->can_queue >0 )
@@ -1601,6 +1619,8 @@ static inline int scsi_host_queue_ready(struct request_queue *q,spin_lock_irq (shost->host_lock);if (list_empty (&sdev->starved_entry))list_add_tail (&sdev->starved_entry, &shost->starved_list); +if (scsi_is_admin_queue (q)) + shost->run_admin_queue = true;spin_unlock_irq (shost->host_lock); out_dec:scsi_dec_host_busy (shost);
@@ -1900,7 +1920,7 @@ static void scsi_request_fn(struct request_queue *q) goto not_ready; } -if (!scsi_target_queue_ready (shost, sdev)) +if (!scsi_target_queue_ready (shost, sdev,scsi_is_admin_queue (q))) goto not_ready;if (!scsi_host_queue_ready (q, shost, sdev))
@@ -2063,7 +2083,7 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, goto out_put_budget; ret =BLK_STS_RESOURCE ; -if (!scsi_target_queue_ready (shost, sdev)) +if (!scsi_target_queue_ready (shost, sdev,scsi_is_admin_queue (q))) goto out_put_budget;if (!scsi_host_queue_ready (q, shost, sdev)) goto out_dec_target_busy;
include/scsi/scsi_host.h +2 -0
@@ -532,6 +532,8 @@ struct Scsi_Host {struct list_head __devices;struct list_head __targets; +struct request_queue *admin_q; +bool run_admin_queue;struct list_head starved_list;spinlock_t default_lock;
Signature · 1 line
2.9.5
RFC PATCH 9/14 SCSI: create admin queue for each host
In reply to Ming LeiThe created admin queue will be used to send internal admin commands, so we can simplify the sync between some admin commands and IO requests, typical examples are system suspend and runtime PM.
--- drivers/scsi/hosts.c | 9 ++++ drivers/scsi/scsi_lib.c | 111 +++++++++++++++++++++++++++++++++++++++++------ drivers/scsi/scsi_priv.h | 1 + 3 files changed, 108 insertions(+), 13 deletions(-)
drivers/scsi/hosts.c +9 -0
@@ -242,6 +242,9 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, shost->dma_dev = dma_dev; +if (!scsi_init_admin_queue (shost)) + goto out_remove_tags; +/* * Increase usage count temporarily here so that calling * scsi_autopm_put_host() will trigger runtime idle if there is
@@ -309,6 +312,9 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,pm_runtime_disable (&shost->shost_gendev);pm_runtime_set_suspended (&shost->shost_gendev);pm_runtime_put_noidle (&shost->shost_gendev); +blk_cleanup_queue (shost->admin_q); +blk_put_queue (shost->admin_q); + out_remove_tags:if (shost_use_blk_mq (shost))scsi_mq_destroy_tags (shost); fail:
@@ -344,6 +350,9 @@ static void scsi_host_dev_release(struct device *dev)kfree (dev_name (&shost->shost_dev)); } +blk_cleanup_queue (shost->admin_q); +blk_put_queue (shost->admin_q); +if (shost_use_blk_mq (shost)) {if (shost->tag_set.tags)scsi_mq_destroy_tags (shost);
drivers/scsi/scsi_lib.c +98 -13
176 lines not on this page · raw message
drivers/scsi/scsi_priv.h +1 -0
@@ -94,6 +94,7 @@ extern void scsi_run_host_queues(struct Scsi_Host *shost);extern void scsi_requeue_run_queue (struct work_struct *work);extern struct request_queue *scsi_old_alloc_queue (struct scsi_device *sdev);extern struct request_queue *scsi_mq_alloc_queue (struct scsi_device *sdev); +extern struct request_queue *scsi_init_admin_queue (struct Scsi_Host *shost);extern void scsi_start_queue (struct scsi_device *sdev);extern int scsi_mq_setup_tags (struct Scsi_Host *shost);extern void scsi_mq_destroy_tags (struct Scsi_Host *shost);
Signature · 1 line
2.9.5
Re: [RFC PATCH 09/14] SCSI: create admin queue for each host
Hi Ming
Quoted 4 lines · Ming Lei
drivers/scsi/scsi_lib.c +3
-0+static struct request_queue *scsi_mq_alloc_admin_queue (struct Scsi_Host *shost) +{ + struct request_queue *q = __blk_mq_init_queue(&shost->tag_set,
drivers/scsi/scsi_lib.c struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) · line 2399
Quoted 10 lines
drivers/scsi/scsi_lib.c +10
-0+ QUEUE_FLAG_MQ_NO_SCHED_DEFAULT); +if (IS_ERR (q)) +return NULL ; + + q->mq_ops = &scsi_mq_admin_ops; + +__scsi_init_queue (shost, q); + +return q; +}
In your patch set, the logical adminq per host is standalone request_queue which share the tagset with other request_queue.
Due to the hctx_may_queue,
If only one LUN, the adminq will take away half of the driver tags when the adminq is active.
And when multiple LUNs, all of the LUNs have to share the limited budget of tags of the adminq.
This is unacceptable.
And also, not all the admin request is send out through scsi_execute, maybe SG_IO. So the admin queue here looks more like the pm queue ?
Thanks
Jianchao
Re: [RFC PATCH 09/14] SCSI: create admin queue for each host
Quoted 21 lines · jianchao.wang
Hi Ming
Quoted 4 lines · Ming Lei
drivers/scsi/scsi_lib.c +3
-0+static struct request_queue *scsi_mq_alloc_admin_queue (struct Scsi_Host *shost) +{ + struct request_queue *q = __blk_mq_init_queue(&shost->tag_set,drivers/scsi/scsi_lib.c struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) · line 2399
Quoted 10 lines
drivers/scsi/scsi_lib.c +10
-0+ QUEUE_FLAG_MQ_NO_SCHED_DEFAULT); +if (IS_ERR (q)) +return NULL ; + + q->mq_ops = &scsi_mq_admin_ops; + +__scsi_init_queue (shost, q); + +return q; +}In your patch set, the logical adminq per host is standalone
request_queuewhich share the tagset with otherrequest_queue.
Quoted 3 lines
Due to the
hctx_may_queue,
If only one LUN, the adminq will take away half of the driver tags when the adminq is active.
Most of times, the admin queue is inactive, so it shouldn't be a big deal.
Quoted 3 lines
And when multiple LUNs, all of the LUNs have to share the limited budget of tags of the adminq.
This is unacceptable.
That can be solved easily, such as, let __blk_mq_tag_busy() not take account of admin queue, will do it in V2.
Quoted 3 lines
And also, not all the admin request is send out through
scsi_execute, maybeSG_IO. So the admin queue here looks more like the pm queue ?
SG_IO should be covered by IO queue in which SCSI_PASSTHROUGH is enabled. It is reasonable too since SG_IO can be normal IO from userspace.
thanks,
Ming Lei
Re: [RFC PATCH 09/14] SCSI: create admin queue for each host
Quoted 37 lines · Ming Lei
Quoted 21 lines · jianchao.wang
Hi Ming
Quoted 4 lines · Ming Lei
drivers/scsi/scsi_lib.c +3
-0+static struct request_queue *scsi_mq_alloc_admin_queue (struct Scsi_Host *shost) +{ + struct request_queue *q = __blk_mq_init_queue(&shost->tag_set,drivers/scsi/scsi_lib.c struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) · line 2399
Quoted 10 lines
drivers/scsi/scsi_lib.c +10
-0+ QUEUE_FLAG_MQ_NO_SCHED_DEFAULT); +if (IS_ERR (q)) +return NULL ; + + q->mq_ops = &scsi_mq_admin_ops; + +__scsi_init_queue (shost, q); + +return q; +}In your patch set, the logical adminq per host is standalone
request_queuewhich share the tagset with otherrequest_queue.Quoted 3 lines
Due to the
hctx_may_queue,
If only one LUN, the adminq will take away half of the driver tags when the adminq is active.Most of times, the admin queue is inactive, so it shouldn't be a big deal.
Quoted 3 lines
And when multiple LUNs, all of the LUNs have to share the limited budget of tags of the adminq.
This is unacceptable.That can be solved easily, such as, let
__blk_mq_tag_busy()not take account of admin queue, will do it in V2.Quoted 1 line
Quoted 7 lines
Quoted 2 lines
And also, not all the admin request is send out through
scsi_execute, maybeSG_IO. So the admin queue here looks more like the pm queue ?
SG_IOshould be covered by IO queue in whichSCSI_PASSTHROUGHis enabled. It is reasonable too sinceSG_IOcan be normal IO from userspace.
I just concern too much complexity would be introduced by this logical admin queue. ;)
Thanks
Jianchao
Re: [RFC PATCH 09/14] SCSI: create admin queue for each host
Quoted 43 lines · jianchao.wang
Quoted 40 lines · Ming Lei
Quoted 21 lines · jianchao.wang
Hi Ming
Quoted 4 lines · Ming Lei
drivers/scsi/scsi_lib.c +3
-0+static struct request_queue *scsi_mq_alloc_admin_queue (struct Scsi_Host *shost) +{ + struct request_queue *q = __blk_mq_init_queue(&shost->tag_set,drivers/scsi/scsi_lib.c struct request_queue *scsi_mq_alloc_queue(struct scsi_device *sdev) · line 2399
Quoted 10 lines
drivers/scsi/scsi_lib.c +10
-0+ QUEUE_FLAG_MQ_NO_SCHED_DEFAULT); +if (IS_ERR (q)) +return NULL ; + + q->mq_ops = &scsi_mq_admin_ops; + +__scsi_init_queue (shost, q); + +return q; +}In your patch set, the logical adminq per host is standalone
request_queuewhich share the tagset with otherrequest_queue.Quoted 3 lines
Due to the
hctx_may_queue,
If only one LUN, the adminq will take away half of the driver tags when the adminq is active.Most of times, the admin queue is inactive, so it shouldn't be a big deal.
Quoted 3 lines
And when multiple LUNs, all of the LUNs have to share the limited budget of tags of the adminq.
This is unacceptable.That can be solved easily, such as, let
__blk_mq_tag_busy()not take account of admin queue, will do it in V2.Quoted 3 lines
And also, not all the admin request is send out through
scsi_execute, maybeSG_IO. So the admin queue here looks more like the pm queue ?
Quoted 6 lines
Quoted 4 lines
SG_IOshould be covered by IO queue in whichSCSI_PASSTHROUGHis enabled. It is reasonable too sinceSG_IOcan be normal IO from userspace.I just concern too much complexity would be introduced by this logical admin queue. ;)
About this concern, I am pretty sure the logic is simple, :-)
If no one objects the admin queue approach. I plan to rename the queue flag of NO_SCHED into ADMIN in V2, then we can simply not increase/decrease the counter of 'active_queues' in case of one ADMIN queue.
As you saw, the complexity is reduced a lot about implementing runtime PM and SCSI quiesce with this patch.
Thanks,
Ming Lei
RFC PATCH 10/14 SCSI: use the dedicated admin queue to send admin commands
In reply to Ming LeiNow the per-host dedicated admin queue is ready, so use this queue to send admin commands only.
--- drivers/scsi/scsi_lib.c | 11 ++++++++--- drivers/scsi/scsi_scan.c | 1 + drivers/scsi/scsi_sysfs.c | 1 + include/scsi/scsi_device.h | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-)
drivers/scsi/scsi_lib.c +8 -3
@@ -278,16 +278,16 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,struct request *req;struct scsi_request *rq;int ret =DRIVER_ERROR <<24 ; +struct request_queue *q = sdev->host->admin_q; - req =blk_get_request (sdev->request_queue, + req =blk_get_request (q, data_direction ==DMA_TO_DEVICE ?REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN ,BLK_MQ_REQ_PREEMPT );if (IS_ERR (req))return ret; rq =scsi_req (req); -if (bufflen &&blk_rq_map_kern (sdev->request_queue, req, - buffer, bufflen,GFP_NOIO )) +if (bufflen &&blk_rq_map_kern (q, req, buffer, bufflen,GFP_NOIO )) goto out; rq->cmd_len =COMMAND_SIZE (cmd[0 ]);
@@ -299,6 +299,8 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, req->cmd_flags |= flags; req->rq_flags |= rq_flags |RQF_QUIET ; +atomic_inc (&sdev->nr_admin_pending); +/* * head injection *required* here otherwise quiesce won't work */
@@ -323,6 +325,9 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, out:blk_put_request (req); +atomic_dec (&sdev->nr_admin_pending); +wake_up_all (&sdev->admin_wq); +return ret; }EXPORT_SYMBOL (__scsi_execute);
drivers/scsi/scsi_scan.c +1 -0
@@ -243,6 +243,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,mutex_init (&sdev->inquiry_mutex);INIT_WORK (&sdev->event_work, scsi_evt_thread);INIT_WORK (&sdev->requeue_work, scsi_requeue_run_queue); +init_waitqueue_head (&sdev->admin_wq); sdev->sdev_gendev.parent =get_device (&starget->dev); sdev->sdev_target = starget;
drivers/scsi/scsi_sysfs.c +1 -0
@@ -1377,6 +1377,7 @@ void __scsi_remove_device(struct scsi_device *sdev)blk_cleanup_queue (sdev->request_queue);cancel_work_sync (&sdev->requeue_work); +wait_event (sdev->admin_wq, !atomic_read (&sdev->nr_admin_pending));if (sdev->host->hostt->slave_destroy) sdev->host->hostt->slave_destroy (sdev);
include/scsi/scsi_device.h +4 -0
@@ -227,6 +227,10 @@ struct scsi_device {struct mutex state_mutex;enum scsi_device_state sdev_state;struct task_struct *quiesced_by; + +atomic_t nr_admin_pending; +wait_queue_head_t admin_wq; +unsigned long sdev_data[0 ]; } __attribute__((aligned(sizeof(unsigned long))));
Signature · 1 line
2.9.5
Re: [RFC PATCH 10/14] SCSI: use the dedicated admin queue to send admin commands
Quoted 3 lines · Ming Lei
---
a/drivers/scsi/scsi_lib.c
+-+-+-b/drivers/scsi/scsi_lib.c
@@ -278,16 +-278,16 @@ int __scsi_execute(struc=
t scsi_device *sdev, const unsigned char *cmd,
drivers/scsi/scsi_lib.c int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
Quoted 4 lines
drivers/scsi/scsi_lib.c +1
-0struct request *req;struct scsi_request *rq;int ret =DRIVER_ERROR <<24 ; +- struct request_queue *q = sdev->host->admin�
8-q;
drivers/scsi/scsi_lib.c int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
Quoted 5 lines
=20
drivers/scsi/scsi_lib.c +1
-1- req =blk_get_request (sdev->request_queue, +- req =blk_get_request (q, data_direction ==DMA_TO_DEVICE ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_
-MQ_REQ_PREEMPT);
The above looks weird to me. Why are all RQF_PREEMPT requests sent to t= he admin
queue instead of only RQF_PM requests?
Quoted 1 line
@@ -299,6 +-299,8 @@ int __scsi_execute(struct =
scsi_device *sdev, const unsigned char *cmd,
drivers/scsi/scsi_lib.c int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, · line 300
Quoted 2 lines
drivers/scsi/scsi_lib.c +0
-0req->cmd_flags |= flags; req->rq_flags |= rq_flags |RQF_QUIET ;
-
Quoted 2 lines
=20
+-atomic_inc(&sdev->nr_admin_pending);
Why has a new counter been introduced to keep track of admin requests inste= ad of
using q_usage_counter?
Thanks,
Bart.
Re: [RFC PATCH 10/14] SCSI: use the dedicated admin queue to send admin commands
Quoted 9 lines · Bart Van Assche
Quoted 8 lines · Ming Lei
drivers/scsi/scsi_lib.c +1
-0@@ -278,16 +278,16 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,struct request *req;struct scsi_request *rq;int ret =DRIVER_ERROR <<24 ; +struct request_queue *q = sdev->host->admin_q;
Quoted 7 lines
drivers/scsi/scsi_lib.c int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, · line 285
Quoted 4 lines
drivers/scsi/scsi_lib.c +1
-1- req =blk_get_request (sdev->request_queue, + req =blk_get_request (q, data_direction ==DMA_TO_DEVICE ?REQ_OP_SCSI_OUT :REQ_OP_SCSI_IN ,BLK_MQ_REQ_PREEMPT );The above looks weird to me. Why are all
RQF_PREEMPTrequests sent to the admin queue instead of onlyRQF_PMrequests?
The motivation is to use the dedicated admin queue for sending any admin request, and that is why it isn't named as pm_queue, :-)
Also usually RQF_PREEMPT request is allowed when queue is quiesced, which can be used in both system suspend and sending domain validation.
Quoted 9 lines
drivers/scsi/scsi_lib.c int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, · line 302
Quoted 6 lines
drivers/scsi/scsi_lib.c +1
-0@@ -299,6 +299,8 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, req->cmd_flags |= flags; req->rq_flags |= rq_flags |RQF_QUIET ; +atomic_inc (&sdev->nr_admin_pending);Why has a new counter been introduced to keep track of admin requests instead of using
q_usage_counter?
Just for making sure all admin requests sent to this scsi_device can be completed before removing this scsi_device, given this patch switches to use per-host admin queue to send admin requests to all scsi_devices in this host.
So we can't use the q_usage_counter of scsi_device's queue or the per-host admin queue.
It won't be one big deal since scsi_execute() won't be run in fast path.
Thanks,
Ming
RFC PATCH 11/14 SCSI: transport_spi: resume a quiesced device
In reply to Ming LeiWe have to preempt freeze queue in scsi_device_quiesce(), and unfreeze in scsi_device_resume(), so call scsi_device_resume() for the device which is quiesced by scsi_device_quiesce().
--- drivers/scsi/scsi_transport_spi.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/scsi_transport_spi.c +3 -0
@@ -1052,6 +1052,9 @@ spi_dv_device(struct scsi_device *sdev)scsi_target_resume (starget); +/* undo what scsi_device_quiesce() did */ +scsi_device_resume (sdev); +spi_initial_dv (starget) =1 ; out_free:
Signature · 1 line
2.9.5
RFC PATCH 12/14 SCSI: use admin queue to implement queue QUIESCE
In reply to Ming LeiAll admin commands are sent via per-host admin queue, so we can simply freeze the IO queue for quiescing scsi device.
Also the current SCSI stack guarantees that any request originated from admin queue won't be called back to block layer via the associated IO queue, and it is always dealt with by the admin queue.
So it is safe to submit admin request via admin queue when the associated IO queue is frozen, and this way matches the PREEMPT flag perfectly.
Finally, we can remove the preempt_only approach for supporting SCSI quiesce, then the code in block fast path is simplified a lot.
--- block/blk-core.c | 44 ++------------------------------------------ block/blk-mq-debugfs.c | 1 - drivers/scsi/scsi_lib.c | 29 +++-------------------------- include/linux/blkdev.h | 6 ------ include/scsi/scsi_device.h | 1 - 5 files changed, 5 insertions(+), 76 deletions(-)
block/blk-core.c +2 -42
@@ -421,26 +421,6 @@ void blk_sync_queue(struct request_queue *q)EXPORT_SYMBOL (blk_sync_queue);/** -* blk_set_preempt_only - set QUEUE_FLAG_PREEMPT_ONLY -* @q: request queue pointer -* -* Returns the previous value of the PREEMPT_ONLY flag - 0 if the flag was not -* set and 1 if the flag was already set. -*/ -int blk_set_preempt_only (struct request_queue *q) -{ -return blk_queue_flag_test_and_set (QUEUE_FLAG_PREEMPT_ONLY , q); -} -EXPORT_SYMBOL_GPL (blk_set_preempt_only); - -void blk_clear_preempt_only (struct request_queue *q) -{ -blk_queue_flag_clear (QUEUE_FLAG_PREEMPT_ONLY , q); -wake_up_all (&q->mq_freeze_wq); -} -EXPORT_SYMBOL_GPL (blk_clear_preempt_only); - -/** * __blk_run_queue_uncond - run a queue whether or not it has been stopped * @q: The queue to run *
@@ -911,27 +891,8 @@ EXPORT_SYMBOL(blk_alloc_queue);*/ int blk_queue_enter (struct request_queue *q,blk_mq_req_flags_t flags) { -const bool preempt = flags &BLK_MQ_REQ_PREEMPT ; -while (true) { -bool success = false; - -rcu_read_lock (); -if (percpu_ref_tryget_live (&q->q_usage_counter)) { -/* -* The code that sets the PREEMPT_ONLY flag is -* responsible for ensuring that that flag is globally -* visible before the queue is unfrozen. -*/ -if (preempt || !blk_queue_preempt_only (q)) { - success = true; - }else { -percpu_ref_put (&q->q_usage_counter); - } - } -rcu_read_unlock (); - -if (success) +if (percpu_ref_tryget_live (&q->q_usage_counter))return 0 ;if (flags &BLK_MQ_REQ_NOWAIT )
@@ -947,8 +908,7 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)smp_rmb ();wait_event (q->mq_freeze_wq, - (atomic_read (&q->mq_freeze_depth) ==0 && - (preempt || !blk_queue_preempt_only (q))) || +atomic_read (&q->mq_freeze_depth) ==0 ||blk_queue_dying (q));if (blk_queue_dying (q))return -ENODEV ;
block/blk-mq-debugfs.c +0 -1
@@ -132,7 +132,6 @@ static const char *const blk_queue_flag_name[] = {QUEUE_FLAG_NAME (REGISTERED ),QUEUE_FLAG_NAME (SCSI_PASSTHROUGH ),QUEUE_FLAG_NAME (QUIESCED ), -QUEUE_FLAG_NAME (PREEMPT_ONLY ), QUEUE_FLAG_NAME(NO_SCHED), };#undef QUEUE_FLAG_NAME
drivers/scsi/scsi_lib.c +3 -26
@@ -3118,34 +3118,12 @@ static void scsi_wait_for_queuecommand(struct scsi_device *sdev)int scsi_device_quiesce (struct scsi_device *sdev) { -struct request_queue *q = sdev->request_queue;int err; -/* -* It is allowed to call scsi_device_quiesce() multiple times from -* the same context but concurrent scsi_device_quiesce() calls are -* not allowed. -*/ -WARN_ON_ONCE (sdev->quiesced_by && sdev->quiesced_by != current); - -blk_set_preempt_only (q); - -blk_mq_freeze_queue (q); -/* -* Ensure that the effect of blk_set_preempt_only() will be visible -* for percpu_ref_tryget() callers that occur after the queue -* unfreeze even if the queue was already frozen before this function -* was called. See also https://lwn.net/Articles/573497/. -*/ -synchronize_rcu (); -blk_mq_unfreeze_queue (q); +blk_mq_freeze_queue (sdev->request_queue);mutex_lock (&sdev->state_mutex); err =scsi_device_set_state (sdev,SDEV_QUIESCE ); -if (err ==0 ) - sdev->quiesced_by = current; -else -blk_clear_preempt_only (q);mutex_unlock (&sdev->state_mutex);return err;
@@ -3168,12 +3146,11 @@ void scsi_device_resume(struct scsi_device *sdev)* device deleted during suspend) */ mutex_lock (&sdev->state_mutex); -WARN_ON_ONCE (!sdev->quiesced_by); - sdev->quiesced_by =NULL ; -blk_clear_preempt_only (sdev->request_queue);if (sdev->sdev_state ==SDEV_QUIESCE )scsi_device_set_state (sdev,SDEV_RUNNING );mutex_unlock (&sdev->state_mutex); + +blk_mq_unfreeze_queue (sdev->request_queue); }EXPORT_SYMBOL (scsi_device_resume);
include/linux/blkdev.h +0 -6
@@ -700,7 +700,6 @@ struct request_queue {#define QUEUE_FLAG_REGISTERED 26/* queue has been registered to a disk */ #define QUEUE_FLAG_SCSI_PASSTHROUGH 27/* queue supports SCSI commands */ #define QUEUE_FLAG_QUIESCED 28/* queue has been quiesced */ -#define QUEUE_FLAG_PREEMPT_ONLY 29/* only process REQ_PREEMPT requests */ #define QUEUE_FLAG_NO_SCHED 30/* no scheduler allowed */ #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
@@ -742,14 +741,9 @@ bool blk_queue_flag_test_and_clear(unsigned int flag, struct request_queue *q); ((rq)->cmd_flags & (REQ_FAILFAST_DEV |REQ_FAILFAST_TRANSPORT | \ REQ_FAILFAST_DRIVER))#define blk_queue_quiesced (q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) -#define blk_queue_preempt_only (q) \ - test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags)#define blk_queue_fua (q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags)#define blk_queue_no_sched (q) test_bit(QUEUE_FLAG_NO_SCHED, &(q)->queue_flags) -extern int blk_set_preempt_only (struct request_queue *q); -extern void blk_clear_preempt_only (struct request_queue *q); -static inline int queue_in_flight (struct request_queue *q) {return q->in_flight[0 ] + q->in_flight[1 ];
include/scsi/scsi_device.h +0 -1
@@ -226,7 +226,6 @@ struct scsi_device {unsigned char access_state;struct mutex state_mutex;enum scsi_device_state sdev_state; -struct task_struct *quiesced_by;atomic_t nr_admin_pending;wait_queue_head_t admin_wq;
Signature · 1 line
2.9.5
RFC PATCH 13/14 block: simplify runtime PM support
In reply to Ming LeiThis patch simplifies runtime PM support by the following approach:
1) resume device in blk_queue_enter() if this device isn't active
2) freeze queue in blk_pre_runtime_suspend()
3) unfreeze queue in blk_pre_runtime_resume()
4) remove checking on RRF_PM because now we requires out-of-band PM request to resume device
Then we can remove blk_pm_allow_request(), and more importantly this way can be applied to blk-mq path too.
--- block/blk-core.c | 72 ++++++++++++++++++++++++++----------------------- block/elevator.c | 7 +++-- drivers/scsi/scsi_lib.c | 7 +++++ include/linux/blkdev.h | 2 ++ 4 files changed, 51 insertions(+), 37 deletions(-)
block/blk-core.c +39 -33
@@ -884,6 +884,24 @@ struct request_queue *blk_alloc_queue(gfp_t gfp_mask) }EXPORT_SYMBOL (blk_alloc_queue); +#ifdef CONFIG_PM +static void blk_resume_queue (struct request_queue *q) +{ +if (!q->dev) +return ; + +/* PM request needs to be dealt with out of band */ +mutex_lock (&q->pm_lock); +if (q->rpm_status ==RPM_SUSPENDED || q->rpm_status ==RPM_SUSPENDING ) +pm_runtime_resume (q->dev); +mutex_unlock (&q->pm_lock); +} +#else +static void blk_resume_queue (struct request_queue *q) +{ +} +#endif +/** * blk_queue_enter() - try to increase q->q_usage_counter * @q: request queue pointer
@@ -907,6 +925,8 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)*/ smp_rmb (); +blk_resume_queue (q); +wait_event (q->mq_freeze_wq,atomic_read (&q->mq_freeze_depth) ==0 ||blk_queue_dying (q));
@@ -1684,7 +1704,7 @@ EXPORT_SYMBOL_GPL(part_round_stats);#ifdef CONFIG_PM static void blk_pm_put_request (struct request *rq) { -if (rq->q->dev && !(rq->rq_flags &RQF_PM ) && !--rq->q->nr_pending) +if (rq->q->dev && !--rq->q->nr_pending)pm_runtime_mark_last_busy (rq->q->dev); }#else
@@ -2702,30 +2722,6 @@ void blk_account_io_done(struct request *req, u64 now) } } -#ifdef CONFIG_PM -/* -* Don't process normal requests when queue is suspended -* or in the process of suspending/resuming -*/ -static bool blk_pm_allow_request (struct request *rq) -{ -switch (rq->q->rpm_status) { -case RPM_RESUMING : -case RPM_SUSPENDING : -return rq->rq_flags &RQF_PM ; -case RPM_SUSPENDED : -return false; -default : -return true; - } -} -#else -static bool blk_pm_allow_request (struct request *rq) -{ -return true; -} -#endif -void blk_account_io_start (struct request *rq,bool new_io) {struct hd_struct *part;
@@ -2770,13 +2766,8 @@ static struct request *elv_next_request(struct request_queue *q)WARN_ON_ONCE (q->mq_ops);while (1 ) { -list_for_each_entry (rq, &q->queue_head, queuelist) { -if (blk_pm_allow_request (rq)) -return rq; - -if (rq->rq_flags &RQF_SOFTBARRIER ) -break ; - } +list_for_each_entry (rq, &q->queue_head, queuelist) +return rq;/* * Flush request is running and flush request isn't queueable
@@ -3737,6 +3728,7 @@ void blk_pm_runtime_init(struct request_queue *q, struct device *dev)return ; } +mutex_init (&q->pm_lock); q->dev = dev; q->rpm_status =RPM_ACTIVE ;pm_runtime_set_autosuspend_delay (q->dev,-1 );
@@ -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 ; }spin_unlock_irq (q->queue_lock); + +if (!ret) { +blk_freeze_queue (q); + q->rpm_q_frozen = true; + } +mutex_unlock (&q->pm_lock); +return ret; }EXPORT_SYMBOL (blk_pre_runtime_suspend);
@@ -3854,16 +3854,22 @@ void blk_post_runtime_resume(struct request_queue *q, int err)if (!q->dev)return ; +lockdep_assert_held (&q->pm_lock); +spin_lock_irq (q->queue_lock);if (!err) { q->rpm_status =RPM_ACTIVE ; -__blk_run_queue (q);pm_runtime_mark_last_busy (q->dev);pm_request_autosuspend (q->dev); }else { q->rpm_status =RPM_SUSPENDED ; }spin_unlock_irq (q->queue_lock); + +if (!err && q->rpm_q_frozen) { +blk_mq_unfreeze_queue (q); + q->rpm_q_frozen = false; + } }EXPORT_SYMBOL (blk_post_runtime_resume);
block/elevator.c +3 -4
@@ -560,15 +560,14 @@ void elv_bio_merged(struct request_queue *q, struct request *rq,#ifdef CONFIG_PM static void blk_pm_requeue_request (struct request *rq) { -if (rq->q->dev && !(rq->rq_flags &RQF_PM )) +if (rq->q->dev) rq->q->nr_pending--; }static void blk_pm_add_request (struct request_queue *q,struct request *rq) { -if (q->dev && !(rq->rq_flags &RQF_PM ) && q->nr_pending++ ==0 && - (q->rpm_status ==RPM_SUSPENDED || q->rpm_status ==RPM_SUSPENDING )) -pm_request_resume (q->dev); +if (q->dev) + q->nr_pending++; }#else static inline void blk_pm_requeue_request (struct request *rq) {}
drivers/scsi/scsi_lib.c +7 -0
@@ -279,6 +279,10 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,struct scsi_request *rq;int ret =DRIVER_ERROR <<24 ;struct request_queue *q = sdev->host->admin_q; +bool pm_rq = rq_flags &RQF_PM ; + +if (!pm_rq) +scsi_autopm_get_device (sdev); req = blk_get_request(q, data_direction == DMA_TO_DEVICE ?
@@ -328,6 +332,9 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,atomic_dec (&sdev->nr_admin_pending);wake_up_all (&sdev->admin_wq); +if (!pm_rq) +scsi_autopm_put_device (sdev); +return ret; }EXPORT_SYMBOL (__scsi_execute);
include/linux/blkdev.h +2 -0
@@ -544,6 +544,8 @@ struct request_queue {struct device *dev;int rpm_status;unsigned int nr_pending; +bool rpm_q_frozen; +struct mutex pm_lock;#endif /*
Signature · 1 line
2.9.5
Re: [RFC PATCH 13/14] block: simplify runtime PM support
Quoted 1 line · Ming Lei
@@ -3772,6 +-3764,7 @@ int blk_pre_runtime_su=
spend(struct request_queue *q)
Quoted 8 lines
if (!q->dev) return ret; =20 +- 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_s=
uspend(struct request_queue *q)
Quoted 2 lines
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-=
Quoted 1 line
nr_pending
will always be zero for blk-mq code with your approach and hence that runti= me
suspend can get triggered while I/O is in progress, e.g. if blk_queue� F8-enter()
is called concurrently with blk_pre_runtime_suspend()?
Thanks,
Bart.
Re: [RFC PATCH 13/14] block: simplify runtime PM support
Quoted 15 lines · Bart Van Assche
Review int blk_pre_runtime_suspend(struct request_queue *q) · line 3774
Quoted 11 lines · Ming Lei
(quoted diff) +1
-0@@ -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,
Quoted 3 lines
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 thatq->nr_pendingwill 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, :-)
Quoted 2 lines
suspend can get triggered while I/O is in progress, e.g. if
blk_queue_enter()is called concurrently withblk_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.
block/blk-core.c +24 -1
@@ -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
Re: [RFC PATCH 13/14] block: simplify runtime PM support
Hi Ming and Bart
Would you mind to combine your solution together ? ;)
It could be like this:
blk_pre_runtime_suspend
if (q->mq_ops) {
if (!blk_mq_pm_queue_idle(q)) {
ret = -EBUSY;
pm_runtime_mark_last_busy(q->dev);
} else {
blk_set_preempt_only(q);
synchronize_rcu()
if (!blk_mq_pm_queue_idle(q)) {
blk_clear_preempt_only(q);
ret = -EBUSY;
} else {
q->rpm_status = RPM_SUSPENDING;
}
}
} else {
spin_lock_irq(q->queue_lock);
if (q->nr_pending) {
ret = -EBUSY;
pm_runtime_mark_last_busy(q->dev);
} else {
q->rpm_status = RPM_SUSPENDING;
}
spin_unlock_irq(q->queue_lock);
}blk_queue_enter
blk_resume_queue(q);
wait_event(q->mq_freeze_wq, atomic_read(&q->mq_freeze_depth) == 0 || blk_queue_dying(q));
Thanks
Jianchao
Quoted 49 lines · Ming Lei
iff --git
a/block/blk-core.cb/block/blk-core.c
index26f9ceb85318..d1a5cd1da861100644block/blk-core.c +24
-1@@ -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 {
RFC PATCH 14/14 block: enable runtime PM for blk-mq
In reply to Ming LeiNow blk-mq can borrow the runtime PM approach from legacy path, so enable it simply.
--- block/blk-core.c | 6 ------ block/blk-mq.c | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-)
block/blk-core.c +0 -6
@@ -3722,12 +3722,6 @@ EXPORT_SYMBOL(blk_finish_plug);*/ void blk_pm_runtime_init (struct request_queue *q,struct device *dev) { -/* Don't enable runtime PM for blk-mq until it is ready */ -if (q->mq_ops) { -pm_runtime_disable (dev); -return ; - } -mutex_init (&q->pm_lock); q->dev = dev; q->rpm_status =RPM_ACTIVE ;
block/blk-mq.c +4 -0
@@ -25,6 +25,7 @@#include <linux/delay.h> #include <linux/crash_dump.h> #include <linux/prefetch.h> +#include <linux/pm_runtime.h> #include <trace/events/block.h>
@@ -479,6 +480,9 @@ static void __blk_mq_free_request(struct request *rq)blk_mq_put_tag (hctx, hctx->sched_tags, ctx, sched_tag);blk_mq_sched_restart (hctx);blk_queue_exit (q); + +if (q->dev) +pm_runtime_mark_last_busy (q->dev); }void blk_mq_free_request (struct request *rq)
Signature · 1 line
2.9.5
Quoted 19 lines · Ming Lei
Hi,
This patchset introduces per-host admin request queue for submitting admin request only, and uses this approach to implement both SCSI quiesce and runtime PM in one very simply way. Also runtime PM deadlock can be avoided in case that request pool is used up.
The idea is borrowed from NVMe.
Admin request is submitted via per-host admin queue, and it is still associated with the same
scsi_deviceas before, and respects this scsi_device's all kinds of limits. Admin queue shares host tags with other IO queues.One core idea is that for admin request submitted from this admin queue, this request won't be called back to block layer via the associated IO
queue(scsi_device). And this is done in the 3rd patch. So once IO queue is frozen, it can be observed as really frozen from block layer view.
Quoted 8 lines
SCSI quiesce is implemented by admin queue in very simple way, see patch 12.
Also runtime PM for legacy path can be simplified too, see patch 13.
Finally blk-mq simply follows legacy's approach for supporting runtime PM.
Any comments are welcome!
The admin queue is meant for a few other types of request, not just PM requests, right?
Which raises a question: How do you prevent those other types of request, once they are added to the admin queue, from being sent to the device while it is in low-power mode?
Or turn the question around: Suppose you prevent all requests, even those on the admin queue, from being sent to the device while it is in low-power mode. Then how do you send the request which tells the device to go back to full power?
It seems to me that any queue-based approach needs to be aware of which requests will actually change the device's power level.
Alan Stern
Quoted 24 lines · Alan Stern
Quoted 22 lines · Ming Lei
Hi,
This patchset introduces per-host admin request queue for submitting admin request only, and uses this approach to implement both SCSI quiesce and runtime PM in one very simply way. Also runtime PM deadlock can be avoided in case that request pool is used up.
The idea is borrowed from NVMe.
Admin request is submitted via per-host admin queue, and it is still associated with the same
scsi_deviceas before, and respects this scsi_device's all kinds of limits. Admin queue shares host tags with other IO queues.One core idea is that for admin request submitted from this admin queue, this request won't be called back to block layer via the associated IO
queue(scsi_device). And this is done in the 3rd patch. So once IO queue is frozen, it can be observed as really frozen from block layer view.SCSI quiesce is implemented by admin queue in very simple way, see patch 12.
Quoted 8 lines
Quoted 5 lines
Also runtime PM for legacy path can be simplified too, see patch 13.
Finally blk-mq simply follows legacy's approach for supporting runtime PM.
Any comments are welcome!
The admin queue is meant for a few other types of request, not just PM requests, right?
Yes, they are all requests sent via scsi_execute() actually.
Quoted 4 lines
Which raises a question: How do you prevent those other types of request, once they are added to the admin queue, from being sent to the device while it is in low-power mode?
If other non-PM types of request needs to be submitted via admin queue, the related IO queue will be resumed first, which is done via scsi_autopm_get_device() in scsi_execute().
Quoted 5 lines
Or turn the question around: Suppose you prevent all requests, even those on the admin queue, from being sent to the device while it is in low-power mode. Then how do you send the request which tells the device to go back to full power?
For normal IO request, the IO queue is resumed before allocating the IO request.
For other non-PM request, the related IO queue is resumed via scsi_autopm_get_device() before allocating this request from admin queue.
Quoted 3 lines
It seems to me that any queue-based approach needs to be aware of which requests will actually change the device's power level.
Now looks we suppose it is only done by RQF_PM request.
Thanks,
Ming