mpt2/mpt3sas lock reduction for scsi-mq
Subsystems (2)
RFC PATCH v2 1/1 mpt2/mpt3sas lock reduction for scsi-mq
Hi,
This is v2 of the series. Generally addressed Christoph's review comments, but more specifically, changes since v1:
- Kill the MPI2_FUNCTION_SCSI_TASK_MGMT support, which in turn enabled me to drop the SCSI/blk iter patches and the smid work-around for scsi-mq in mpt2/3 for bumping to hpr for NULL command.
- Made init/exit_command() work (sort of) on non scsi-mq. Drivers will have to set request_index related information separately still for non scsi-mq, since we don't have a reliable one
- Use scsi_cmd_priv() instead of adding a new helper.
- Make scsi_find_tag() only return in-progress IO for scsi-mq. This is simiar to the ->special check for non-mq.
- Ensure that mpt3sas is in sync with the mpt2sas changes.
drivers/scsi/mpt2sas/mpt2sas_base.c | 187 ++++++++++++++++++++++++----------- drivers/scsi/mpt2sas/mpt2sas_base.h | 3 drivers/scsi/mpt2sas/mpt2sas_ctl.c | 126 +---------------------- drivers/scsi/mpt2sas/mpt2sas_scsih.c | 87 ++++++++++++---- drivers/scsi/mpt3sas/mpt3sas_base.c | 173 +++++++++++++++++++++++--------- drivers/scsi/mpt3sas/mpt3sas_base.h | 2 drivers/scsi/mpt3sas/mpt3sas_ctl.c | 130 +----------------------- drivers/scsi/mpt3sas/mpt3sas_scsih.c | 69 ++++++++++-- drivers/scsi/scsi.c | 9 + drivers/scsi/scsi_lib.c | 16 ++ include/scsi/scsi_host.h | 6 - include/scsi/scsi_tcq.h | 11 +- 12 files changed, 448 insertions(+), 371 deletions(-)
PATCH 1/6 scsi: add host template init/exit_command hooks
If a LLD has hardware commands in the request pdu, then we need some helper hooks to help the driver initialize state at load time, and potentially to tear down state at rmmod time. Add a host template ->init_command() and ->exit_command() hook to help with that.
Note that for the non scsi-mq case, we can't pass in a reliable request index, since we don't have one...
--- drivers/scsi/scsi.c | 9 +++++++++ drivers/scsi/scsi_lib.c | 16 ++++++++++++++++ include/scsi/scsi_host.h | 6 +++++- 3 files changed, 30 insertions(+), 1 deletion(-)
drivers/scsi/scsi.c +9 -0
@@ -182,6 +182,8 @@ scsi_host_free_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd) {struct scsi_host_cmd_pool *pool = shost->cmd_pool; +if (shost->hostt->exit_command) + shost->hostt->exit_command (shost, cmd);if (cmd->prot_sdb)kmem_cache_free (scsi_sdb_cache, cmd->prot_sdb);kmem_cache_free (pool->sense_slab, cmd->sense_buffer);
@@ -217,8 +219,15 @@ scsi_host_alloc_command(struct Scsi_Host *shost, gfp_t gfp_mask) goto fail_free_sense; } +if (shost->hostt->init_command) { +if (shost->hostt->init_command (shost, cmd,0 )) + goto fail_init; + } +return cmd; +fail_init: +kmem_cache_free (scsi_sdb_cache, cmd->prot_sdb); fail_free_sense:kmem_cache_free (pool->sense_slab, cmd->sense_buffer); fail_free_cmd:
drivers/scsi/scsi_lib.c +16 -0
@@ -2056,11 +2056,23 @@ static int scsi_init_request(void *data, struct request *rq, unsigned int numa_node) {struct scsi_cmnd *cmd =blk_mq_rq_to_pdu (rq); +struct Scsi_Host *shost = data; cmd->sense_buffer =kzalloc_node (SCSI_SENSE_BUFFERSIZE ,GFP_KERNEL , numa_node);if (!cmd->sense_buffer)return -ENOMEM ; + +if (shost->hostt->init_command) { +int ret; + + ret = shost->hostt->init_command (shost, cmd, request_idx); +if (ret) { +kfree (cmd->sense_buffer); +return ret; + } + } +return 0 ; }
@@ -2068,8 +2080,12 @@ static void scsi_exit_request(void *data, struct request *rq, unsigned int hctx_idx, unsigned int request_idx) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); +struct Scsi_Host *shost = data;kfree (cmd->sense_buffer); + +if (shost->hostt->exit_command) + shost->hostt->exit_command (shost, cmd); }static u64 scsi_calculate_bounce_limit (struct Scsi_Host *shost)
include/scsi/scsi_host.h +5 -1
@@ -496,10 +496,14 @@ struct scsi_host_template {u64 vendor_id;/* -* Additional per-command data allocated for the driver. +* Additional per-command data allocated for the driver, along +* with init/exit helper hooks. */ unsigned int cmd_size;struct scsi_host_cmd_pool *cmd_pool; +int (*init_command)(struct Scsi_Host *,struct scsi_cmnd *, +unsigned int ); +void (*exit_command)(struct Scsi_Host *,struct scsi_cmnd *);/* temporary flag to disable blk-mq I/O path */ bool disable_blk_mq;
Signature · 1 line
1.9.1
PATCH 2/6 scsi: ensure that a request is valid when returning it from scsi_find_tag()
In reply to Jens AxboeFor the scsi-mq case, ensure that the request has been started before returning it from scsi_find_tag(). This is akin to the ->special check for the non-mq case, it ensures that the request has been setup and issued.
--- include/scsi/scsi_tcq.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
include/scsi/scsi_tcq.h +9 -2
@@ -35,8 +35,15 @@ static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)struct request *req;if (tag !=SCSI_NO_TAG ) { -if (shost_use_blk_mq (sdev->host)) -return scsi_mq_find_tag (sdev->host, tag); +if (shost_use_blk_mq (sdev->host)) { +struct scsi_cmnd *scmd; + + scmd =scsi_mq_find_tag (sdev->host, tag); +if (blk_mq_request_started (scmd->request)) +return scmd; + +return NULL ; + } req =blk_queue_find_tag (sdev->request_queue, tag);return req ? (struct scsi_cmnd *)req->special :NULL ;
Signature · 1 line
1.9.1
Re: [PATCH 2/6] scsi: ensure that a request is valid when returning it from scsi_find_tag()
Quoted 6 lines · Jens Axboe
For the scsi-mq case, ensure that the request has been started before returning it from
scsi_find_tag(). This is akin to the ->special check for the non-mq case, it ensures that the request has been setup and issued.Signed-off-by Jens Axboe <[email protected]>
Shouldn't this be done in blk_mq_tag_to_rq? In general when a driver looks for an active tag it wants an active tag, so working around this in the driver seems like a bad idea.
PATCH 3/6 mpt2sas: get rid of MPI2_FUNCTION_SCSI_TASK_MGMT
In reply to Jens AxboeThis involves a lot of nasty lookup of a specific running command, across the host. If anybody is using this code, it should be moved to proper error handling instead.
--- drivers/scsi/mpt2sas/mpt2sas_ctl.c | 126 +++---------------------------------- 1 file changed, 10 insertions(+), 116 deletions(-)
drivers/scsi/mpt2sas/mpt2sas_ctl.c +10 -116
@@ -530,84 +530,6 @@ _ctl_poll(struct file *filep, poll_table *wait) }/** -* _ctl_set_task_mid - assign an active smid to tm request -* @ioc: per adapter object -* @karg - (struct mpt2_ioctl_command) -* @tm_request - pointer to mf from user space -* -* Returns 0 when an smid if found, else fail. -* during failure, the reply frame is filled. -*/ -static int -_ctl_set_task_mid (struct MPT2SAS_ADAPTER *ioc,struct mpt2_ioctl_command *karg, -Mpi2SCSITaskManagementRequest_t *tm_request) -{ -u8 found =0 ; -u16 i; -u16 handle; -struct scsi_cmnd *scmd; -struct MPT2SAS_DEVICE *priv_data; -unsigned long flags; -Mpi2SCSITaskManagementReply_t *tm_reply; -u32 sz; -u32 lun; -char *desc =NULL ; - -if (tm_request->TaskType ==MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ) - desc ="abort_task" ; -else if (tm_request->TaskType ==MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK ) - desc ="query_task" ; -else -return 0 ; - - lun =scsilun_to_int ((struct scsi_lun *)tm_request->LUN); - - handle =le16_to_cpu (tm_request->DevHandle); -spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); -for (i = ioc->scsiio_depth; i && !found; i--) { - scmd = ioc->scsi_lookup[i -1 ].scmd; -if (scmd ==NULL || scmd->device ==NULL || - scmd->device->hostdata ==NULL ) -continue ; -if (lun != scmd->device->lun) -continue ; - priv_data = scmd->device->hostdata; -if (priv_data->sas_target ==NULL ) -continue ; -if (priv_data->sas_target->handle != handle) -continue ; - tm_request->TaskMID =cpu_to_le16 (ioc->scsi_lookup[i -1 ].smid); - found =1 ; - } -spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); - -if (!found) { -dctlprintk (ioc,printk (MPT2SAS_INFO_FMT "%s: " -"handle(0x%04x), lun(%d), no active mid!!\n" , ioc->name, - desc,le16_to_cpu (tm_request->DevHandle), lun)); - tm_reply = ioc->ctl_cmds.reply; - tm_reply->DevHandle = tm_request->DevHandle; - tm_reply->Function =MPI2_FUNCTION_SCSI_TASK_MGMT ; - tm_reply->TaskType = tm_request->TaskType; - tm_reply->MsgLength =sizeof (Mpi2SCSITaskManagementReply_t)/4 ; - tm_reply->VP_ID = tm_request->VP_ID; - tm_reply->VF_ID = tm_request->VF_ID; - sz =min_t (u32, karg->max_reply_bytes, ioc->reply_sz); -if (copy_to_user (karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply, - sz)) -printk (KERN_ERR "failure at %s:%d/%s()!\n" , __FILE__, - __LINE__, __func__); -return 1 ; - } - -dctlprintk (ioc,printk (MPT2SAS_INFO_FMT "%s: " -"handle(0x%04x), lun(%d), task_mid(%d)\n" , ioc->name, - desc,le16_to_cpu (tm_request->DevHandle), lun, -le16_to_cpu (tm_request->TaskMID))); -return 0 ; -} - -/** * _ctl_do_mpt_command - main handler for MPT2COMMAND opcode * @ioc: per adapter object * @karg - (struct mpt2_ioctl_command)
@@ -689,22 +611,18 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command karg, }if (mpi_request->Function ==MPI2_FUNCTION_SCSI_TASK_MGMT ) { - smid =mpt2sas_base_get_smid_hpr (ioc, ioc->ctl_cb_idx); -if (!smid) { -printk (MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n" , - ioc->name, __func__); - ret = -EAGAIN ; - goto out; - } - }else { +printk (MPT2SAS_ERR_FMT "%s: ignoring " +"MPI2_FUNCTION_SCSI_TASK_MGMT\n" , ioc->name, __func__); + ret = -EINVAL ; + goto out; + } - smid =mpt2sas_base_get_smid_scsiio (ioc, ioc->ctl_cb_idx,NULL ); -if (!smid) { -printk (MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n" , + smid =mpt2sas_base_get_smid_hpr (ioc, ioc->ctl_cb_idx); +if (!smid) { +printk (MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n" , ioc->name, __func__); - ret = -EAGAIN ; - goto out; - } + ret = -EAGAIN ; + goto out; } ret =0 ;
@@ -822,30 +740,6 @@ _ctl_do_mpt_command(struct MPT2SAS_ADAPTER *ioc, struct mpt2_ioctl_command karg,mpt2sas_base_put_smid_default (ioc, smid);break ; } -case MPI2_FUNCTION_SCSI_TASK_MGMT : - { -Mpi2SCSITaskManagementRequest_t *tm_request = - (Mpi2SCSITaskManagementRequest_t *)request; - -dtmprintk (ioc,printk (MPT2SAS_INFO_FMT "TASK_MGMT: " -"handle(0x%04x), task_type(0x%02x)\n" , ioc->name, -le16_to_cpu (tm_request->DevHandle), tm_request->TaskType)); - -if (tm_request->TaskType == -MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK || - tm_request->TaskType == -MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK ) { -if (_ctl_set_task_mid (ioc, &karg, tm_request)) { -mpt2sas_base_free_smid (ioc, smid); - goto out; - } - } - -mpt2sas_scsih_set_tm_flag (ioc,le16_to_cpu ( - tm_request->DevHandle)); -mpt2sas_base_put_smid_hi_priority (ioc, smid); -break ; - }case MPI2_FUNCTION_SMP_PASSTHROUGH : { Mpi2SmpPassthroughRequest_t *smp_request =
Signature · 1 line
1.9.1
Re: [PATCH 3/6] mpt2sas: get rid of MPI2_FUNCTION_SCSI_TASK_MGMT
This should also mention that you now allocate the hdr for the normal pass through from a different pool. Actually that change probably should really be a separate patch..
PATCH 4/6 mpt2sas: store scsi io tracker data in the scsi request
In reply to Jens AxboeInstead of storing the IO tracker structure in a separate list that we need to pop/push to on every submit and complete (and lock), store it in the pdu associated with a request. This is possible on scsi-mq only, and further cuts the spinlock associated time for higher IOPS IO workloads. At 100K IOPS, this effectively cuts the locking time in half.
--- drivers/scsi/mpt2sas/mpt2sas_base.c | 187 ++++++++++++++++++++++++----------- drivers/scsi/mpt2sas/mpt2sas_base.h | 3 + drivers/scsi/mpt2sas/mpt2sas_scsih.c | 87 ++++++++++++---- 3 files changed, 204 insertions(+), 73 deletions(-)
drivers/scsi/mpt2sas/mpt2sas_base.c +132 -55
@@ -828,6 +828,20 @@ _base_async_event(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, u32 reply)return ; } +struct scsiio_tracker * +mpt2sas_get_st_from_smid (struct MPT2SAS_ADAPTER *ioc,u16 smid) +{ +if (shost_use_blk_mq (ioc->shost)) { +struct scsi_cmnd *scmd; + + scmd =scsi_mq_find_tag (ioc->shost, smid -1 ); +if (!scmd) +return NULL ; +return scsi_cmd_priv (scmd); + }else +return &ioc->scsi_lookup[smid -1 ]; +} +/** * _base_get_cb_idx - obtain the callback index * @ioc: per adapter object
@@ -842,8 +856,10 @@ _base_get_cb_idx(struct MPT2SAS_ADAPTER *ioc, u16 smid)u8 cb_idx;if (smid < ioc->hi_priority_smid) { - i = smid -1 ; - cb_idx = ioc->scsi_lookup[i].cb_idx; +struct scsiio_tracker *st; + + st =mpt2sas_get_st_from_smid (ioc, smid); + cb_idx = st->cb_idx; }else if (smid < ioc->internal_smid) { i = smid - ioc->hi_priority_smid; cb_idx = ioc->hpr_lookup[i].cb_idx;
@@ -962,18 +978,17 @@ _base_interrupt(int irq, void *bus_id) goto next;if (smid) { cb_idx =_base_get_cb_idx (ioc, smid); -if ((likely (cb_idx <MPT_MAX_CALLBACKS )) +if ((likely (cb_idx <MPT_MAX_CALLBACKS )) && (likely (mpt_callbacks[cb_idx] !=NULL ))) { rc = mpt_callbacks[cb_idx](ioc, smid, msix_index, reply); -if (reply) -_base_display_reply_info (ioc, smid, - msix_index, reply); -if (rc) -mpt2sas_base_free_smid (ioc, smid); +if (reply) +_base_display_reply_info (ioc, smid, + msix_index, reply); +if (rc) +mpt2sas_base_free_smid (ioc, smid); } - } -if (!smid) + }else _base_async_event (ioc, msix_index, reply);/* reply free queue handling */
@@ -1724,6 +1739,11 @@ mpt2sas_base_get_smid_scsiio(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx,struct scsiio_tracker *request;u16 smid; +if (shost_use_blk_mq (ioc->shost)) { + request =scsi_cmd_priv (scmd); +return request->smid; + } +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);if (list_empty (&ioc->free_list)) {spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags);
@@ -1771,6 +1791,31 @@ mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx)return smid; } +static void +_base_recovery_check (struct MPT2SAS_ADAPTER *ioc) +{ +/* +* See _wait_for_commands_to_complete() call with regards to this code. +*/ +if (ioc->shost_recovery && ioc->pending_io_count) { +if (ioc->pending_io_count ==1 ) +wake_up (&ioc->reset_wq); + ioc->pending_io_count =0 ; + } +} + +static void +_dechain_st (struct MPT2SAS_ADAPTER *ioc,struct scsiio_tracker *st) +{ +struct chain_tracker *chain_req; + +while (!list_empty (&st->chain_list)) { + chain_req =list_first_entry (&st->chain_list, + struct chain_tracker, + tracker_list); +list_move (&chain_req->tracker_list, &ioc->free_chain_list); + } +}/** * mpt2sas_base_free_smid - put smid back on free_list
@@ -1784,20 +1829,32 @@ mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid) {unsigned long flags;int i; -struct chain_tracker *chain_req, *next; + +if (shost_use_blk_mq (ioc->shost) && smid < ioc->hi_priority_smid) { +struct scsiio_tracker *st; + + st =mpt2sas_get_st_from_smid (ioc, smid); +if (!st) +return ; + + st->direct_io =0 ; + +if (!list_empty (&st->chain_list)) { +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); +_dechain_st (ioc, st); +spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); + } + +_base_recovery_check (ioc); +return ; + }spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);if (smid < ioc->hi_priority_smid) {/* scsiio queue */ i = smid -1 ; -if (!list_empty (&ioc->scsi_lookup[i].chain_list)) { -list_for_each_entry_safe (chain_req, next, - &ioc->scsi_lookup[i].chain_list, tracker_list) { -list_del_init (&chain_req->tracker_list); -list_add (&chain_req->tracker_list, - &ioc->free_chain_list); - } - } +if (!list_empty (&ioc->scsi_lookup[i].chain_list)) +_dechain_st (ioc, &ioc->scsi_lookup[i]); ioc->scsi_lookup[i].cb_idx =0xFF ; ioc->scsi_lookup[i].scmd =NULL ; ioc->scsi_lookup[i].direct_io =0 ;
@@ -1805,15 +1862,7 @@ mpt2sas_base_free_smid(struct MPT2SAS_ADAPTER *ioc, u16 smid) &ioc->free_list);spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); -/* -* See _wait_for_commands_to_complete() call with regards -* to this code. -*/ -if (ioc->shost_recovery && ioc->pending_io_count) { -if (ioc->pending_io_count ==1 ) -wake_up (&ioc->reset_wq); - ioc->pending_io_count--; - } +_base_recovery_check (ioc);return ; }else if (smid < ioc->internal_smid) {/* hi-priority */
@@ -2723,14 +2772,23 @@ _base_allocate_memory_pools(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) ioc->name, (unsigned long long) ioc->request_dma)); total_sz += sz; - sz = ioc->scsiio_depth *sizeof (struct scsiio_tracker ); - ioc->scsi_lookup_pages =get_order (sz); - ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages ( -GFP_KERNEL , ioc->scsi_lookup_pages); -if (!ioc->scsi_lookup) { -printk (MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages failed, " -"sz(%d)\n" , ioc->name, (int )sz); - goto out; +/* +* Don't need to allocate memory for scsiio_tracker array if we +* are using scsi-mq, we embed it in the scsi_cmnd for that case. +*/ +if (!shost_use_blk_mq (ioc->shost)) { + sz = ioc->scsiio_depth *sizeof (struct scsiio_tracker ); + ioc->scsi_lookup_pages =get_order (sz); + ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages ( +GFP_KERNEL , ioc->scsi_lookup_pages); +if (!ioc->scsi_lookup) { +printk (MPT2SAS_ERR_FMT "scsi_lookup: get_free_pages " +"failed, sz(%d)\n" , ioc->name, (int )sz); + goto out; + } + }else { + ioc->scsi_lookup_pages =0 ; + ioc->scsi_lookup =NULL ; } dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "scsiio(0x%p): "
@@ -4299,15 +4357,17 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)/* initialize the scsi lookup free list */ spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);INIT_LIST_HEAD (&ioc->free_list); - smid =1 ; -for (i =0 ; i < ioc->scsiio_depth; i++, smid++) { -INIT_LIST_HEAD (&ioc->scsi_lookup[i].chain_list); - ioc->scsi_lookup[i].cb_idx =0xFF ; - ioc->scsi_lookup[i].smid = smid; - ioc->scsi_lookup[i].scmd =NULL ; - ioc->scsi_lookup[i].direct_io =0 ; -list_add_tail (&ioc->scsi_lookup[i].tracker_list, - &ioc->free_list); +if (!shost_use_blk_mq (ioc->shost)) { + smid =1 ; +for (i =0 ; i < ioc->scsiio_depth; i++, smid++) { +INIT_LIST_HEAD (&ioc->scsi_lookup[i].chain_list); + ioc->scsi_lookup[i].cb_idx =0xFF ; + ioc->scsi_lookup[i].smid = smid; + ioc->scsi_lookup[i].scmd =NULL ; + ioc->scsi_lookup[i].direct_io =0 ; +list_add_tail (&ioc->scsi_lookup[i].tracker_list, + &ioc->free_list); + } }/* hi-priority queue */
@@ -4772,7 +4832,7 @@ _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) {u32 ioc_state;unsigned long flags; -u16 i; +u16 i, pending, loops; ioc->pending_io_count =0 ;if (sleep_flag !=CAN_SLEEP )
@@ -4783,17 +4843,34 @@ _wait_for_commands_to_complete(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)return ;/* pending command count */ -spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); -for (i =0 ; i < ioc->scsiio_depth; i++) -if (ioc->scsi_lookup[i].cb_idx !=0xFF ) - ioc->pending_io_count++; -spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); + loops =0 ; +do { + pending =0 ; +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); +for (i =0 ; i < ioc->scsiio_depth; i++) { +struct scsiio_tracker *st; +struct scsi_cmnd *scmd; + +if (shost_use_blk_mq (ioc->shost)) { + scmd =scsi_mq_find_tag (ioc->shost, i); +if (scmd) + pending++; + }else { + st =mpt2sas_get_st_from_smid (ioc, i +1 ); +if (st->cb_idx !=0xFF ) + pending++; + } + } +spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); -if (!ioc->pending_io_count) -return ; +if (!pending) +break ; + + ioc->pending_io_count =1 ; -/* wait for pending commands to complete */ -wait_event_timeout (ioc->reset_wq, ioc->pending_io_count ==0 ,10 *HZ ); +/* wait for pending commands to complete */ +wait_event_timeout (ioc->reset_wq, ioc->pending_io_count ==0 ,HZ ); + }while (++loops <=10 ); }/**
drivers/scsi/mpt2sas/mpt2sas_base.h +3 -0
@@ -1045,6 +1045,9 @@ u16 mpt2sas_base_get_smid_hpr(struct MPT2SAS_ADAPTER *ioc, u8 cb_idx);u16 mpt2sas_base_get_smid_scsiio (struct MPT2SAS_ADAPTER *ioc,u8 cb_idx,struct scsi_cmnd *scmd); + +struct scsiio_tracker *mpt2sas_get_st_from_smid (struct MPT2SAS_ADAPTER *ioc, +u16 smid);u16 mpt2sas_base_get_smid (struct MPT2SAS_ADAPTER *ioc,u8 cb_idx);void mpt2sas_base_free_smid (struct MPT2SAS_ADAPTER *ioc,u16 smid); void mpt2sas_base_put_smid_scsi_io(struct MPT2SAS_ADAPTER *ioc, u16 smid,
drivers/scsi/mpt2sas/mpt2sas_scsih.c +69 -18
178 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 4/6] mpt2sas: store scsi io tracker data in the scsi request
Quoted 6 lines · Jens Axboe
Instead of storing the IO tracker structure in a separate list that we need to pop/push to on every submit and complete (and lock), store it in the pdu associated with a request. This is possible on scsi-mq only, and further cuts the spinlock associated time for higher IOPS IO workloads. At 100K IOPS, this effectively cuts the locking time in half.
As mentioned before please call scsi_init_shared_tag_map and use your new code path for the !mq case as well.
PATCH 5/6 mpt3sas: get rid of MPI2_FUNCTION_SCSI_TASK_MGMT
In reply to Jens AxboeThis involves a lot of nasty lookup of a specific running command, across the host. If anybody is using this code, it should be moved to proper error handling instead.
--- drivers/scsi/mpt3sas/mpt3sas_ctl.c | 130 +++---------------------------------- 1 file changed, 10 insertions(+), 120 deletions(-)
drivers/scsi/mpt3sas/mpt3sas_ctl.c +10 -120
@@ -524,85 +524,6 @@ _ctl_poll(struct file *filep, poll_table *wait) }/** -* _ctl_set_task_mid - assign an active smid to tm request -* @ioc: per adapter object -* @karg - (struct mpt3_ioctl_command) -* @tm_request - pointer to mf from user space -* -* Returns 0 when an smid if found, else fail. -* during failure, the reply frame is filled. -*/ -static int -_ctl_set_task_mid (struct MPT3SAS_ADAPTER *ioc,struct mpt3_ioctl_command *karg, -Mpi2SCSITaskManagementRequest_t *tm_request) -{ -u8 found =0 ; -u16 i; -u16 handle; -struct scsi_cmnd *scmd; -struct MPT3SAS_DEVICE *priv_data; -unsigned long flags; -Mpi2SCSITaskManagementReply_t *tm_reply; -u32 sz; -u32 lun; -char *desc =NULL ; - -if (tm_request->TaskType ==MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK ) - desc ="abort_task" ; -else if (tm_request->TaskType ==MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK ) - desc ="query_task" ; -else -return 0 ; - - lun =scsilun_to_int ((struct scsi_lun *)tm_request->LUN); - - handle =le16_to_cpu (tm_request->DevHandle); -spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); -for (i = ioc->scsiio_depth; i && !found; i--) { - scmd = ioc->scsi_lookup[i -1 ].scmd; -if (scmd ==NULL || scmd->device ==NULL || - scmd->device->hostdata ==NULL ) -continue ; -if (lun != scmd->device->lun) -continue ; - priv_data = scmd->device->hostdata; -if (priv_data->sas_target ==NULL ) -continue ; -if (priv_data->sas_target->handle != handle) -continue ; - tm_request->TaskMID =cpu_to_le16 (ioc->scsi_lookup[i -1 ].smid); - found =1 ; - } -spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); - -if (!found) { -dctlprintk (ioc,pr_info (MPT3SAS_FMT -"%s: handle(0x%04x), lun(%d), no active mid!!\n" , - ioc->name, - desc,le16_to_cpu (tm_request->DevHandle), lun)); - tm_reply = ioc->ctl_cmds.reply; - tm_reply->DevHandle = tm_request->DevHandle; - tm_reply->Function =MPI2_FUNCTION_SCSI_TASK_MGMT ; - tm_reply->TaskType = tm_request->TaskType; - tm_reply->MsgLength =sizeof (Mpi2SCSITaskManagementReply_t)/4 ; - tm_reply->VP_ID = tm_request->VP_ID; - tm_reply->VF_ID = tm_request->VF_ID; - sz =min_t (u32, karg->max_reply_bytes, ioc->reply_sz); -if (copy_to_user (karg->reply_frame_buf_ptr, ioc->ctl_cmds.reply, - sz)) -pr_err ("failure at %s:%d/%s()!\n" , __FILE__, - __LINE__, __func__); -return 1 ; - } - -dctlprintk (ioc,pr_info (MPT3SAS_FMT -"%s: handle(0x%04x), lun(%d), task_mid(%d)\n" , ioc->name, - desc,le16_to_cpu (tm_request->DevHandle), lun, -le16_to_cpu (tm_request->TaskMID))); -return 0 ; -} - -/** * _ctl_do_mpt_command - main handler for MPT3COMMAND opcode * @ioc: per adapter object * @karg - (struct mpt3_ioctl_command)
@@ -685,22 +606,18 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg, }if (mpi_request->Function ==MPI2_FUNCTION_SCSI_TASK_MGMT ) { - smid =mpt3sas_base_get_smid_hpr (ioc, ioc->ctl_cb_idx); -if (!smid) { -pr_err (MPT3SAS_FMT "%s: failed obtaining a smid\n" , - ioc->name, __func__); - ret = -EAGAIN ; - goto out; - } - }else { +printk (MPT3SAS_FMT "%s: ignoring " +"MPI2_FUNCTION_SCSI_TASK_MGMT\n" , ioc->name, __func__); + ret = -EINVAL ; + goto out; + } - smid =mpt3sas_base_get_smid_scsiio (ioc, ioc->ctl_cb_idx,NULL ); -if (!smid) { -pr_err (MPT3SAS_FMT "%s: failed obtaining a smid\n" , + smid =mpt3sas_base_get_smid_hpr (ioc, ioc->ctl_cb_idx); +if (!smid) { +pr_err (MPT3SAS_FMT "%s: failed obtaining a smid\n" , ioc->name, __func__); - ret = -EAGAIN ; - goto out; - } + ret = -EAGAIN ; + goto out; } ret =0 ;
@@ -784,33 +701,6 @@ _ctl_do_mpt_command(struct MPT3SAS_ADAPTER *ioc, struct mpt3_ioctl_command karg,mpt3sas_base_put_smid_default (ioc, smid);break ; } -case MPI2_FUNCTION_SCSI_TASK_MGMT : - { -Mpi2SCSITaskManagementRequest_t *tm_request = - (Mpi2SCSITaskManagementRequest_t *)request; - -dtmprintk (ioc,pr_info (MPT3SAS_FMT -"TASK_MGMT: handle(0x%04x), task_type(0x%02x)\n" , - ioc->name, -le16_to_cpu (tm_request->DevHandle), tm_request->TaskType)); - -if (tm_request->TaskType == -MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK || - tm_request->TaskType == -MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK ) { -if (_ctl_set_task_mid (ioc, &karg, tm_request)) { -mpt3sas_base_free_smid (ioc, smid); - goto out; - } - } - -mpt3sas_scsih_set_tm_flag (ioc,le16_to_cpu ( - tm_request->DevHandle)); - ioc->build_sg_mpi (ioc, psge, data_out_dma, data_out_sz, - data_in_dma, data_in_sz); -mpt3sas_base_put_smid_hi_priority (ioc, smid); -break ; - }case MPI2_FUNCTION_SMP_PASSTHROUGH : { Mpi2SmpPassthroughRequest_t *smp_request =
Signature · 1 line
1.9.1
PATCH 6/6 mpt3sas: store scsi io tracker data in the scsi request
In reply to Jens AxboeInstead of storing the IO tracker structure in a separate list that we need to pop/push to on every submit and complete (and lock), store it in the pdu associated with a request. This is possible on scsi-mq only, and further cuts the spinlock associated time for higher IOPS IO workloads. At 100K IOPS, this effectively cuts the locking time in half.
--- drivers/scsi/mpt3sas/mpt3sas_base.c | 173 +++++++++++++++++++++++++---------- drivers/scsi/mpt3sas/mpt3sas_base.h | 2 + drivers/scsi/mpt3sas/mpt3sas_scsih.c | 69 +++++++++++--- 3 files changed, 185 insertions(+), 59 deletions(-)
drivers/scsi/mpt3sas/mpt3sas_base.c +125 -48
@@ -815,6 +815,20 @@ _base_async_event(struct MPT3SAS_ADAPTER *ioc, u8 msix_index, u32 reply)return 1 ; } +struct scsiio_tracker * +mpt3sas_get_st_from_smid (struct MPT3SAS_ADAPTER *ioc,u16 smid) +{ +if (shost_use_blk_mq (ioc->shost)) { +struct scsi_cmnd *scmd; + + scmd =scsi_mq_find_tag (ioc->shost, smid -1 ); +if (!scmd) +return NULL ; +return scsi_cmd_priv (scmd); + }else +return &ioc->scsi_lookup[smid -1 ]; +} +/** * _base_get_cb_idx - obtain the callback index * @ioc: per adapter object
@@ -829,8 +843,10 @@ _base_get_cb_idx(struct MPT3SAS_ADAPTER *ioc, u16 smid)u8 cb_idx;if (smid < ioc->hi_priority_smid) { - i = smid -1 ; - cb_idx = ioc->scsi_lookup[i].cb_idx; +struct scsiio_tracker *st; + + st =mpt3sas_get_st_from_smid (ioc, smid); + cb_idx = st->cb_idx; }else if (smid < ioc->internal_smid) { i = smid - ioc->hi_priority_smid; cb_idx = ioc->hpr_lookup[i].cb_idx;
@@ -1176,6 +1192,7 @@ static struct chain_tracker * _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid) {struct chain_tracker *chain_req; +struct scsiio_tracker *st;unsigned long flags;spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);
@@ -1188,8 +1205,8 @@ _base_get_chain_buffer_tracker(struct MPT3SAS_ADAPTER *ioc, u16 smid) chain_req =list_entry (ioc->free_chain_list.next, struct chain_tracker, tracker_list);list_del_init (&chain_req->tracker_list); -list_add_tail (&chain_req->tracker_list, - &ioc->scsi_lookup[smid -1 ].chain_list); + st =mpt3sas_get_st_from_smid (ioc, smid); +list_add_tail (&chain_req->tracker_list, &st->chain_list);spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags);return chain_req; }
@@ -2006,6 +2023,11 @@ mpt3sas_base_get_smid_scsiio(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx,struct scsiio_tracker *request;u16 smid; +if (shost_use_blk_mq (ioc->shost)) { + request =scsi_cmd_priv (scmd); +return request->smid; + } +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);if (list_empty (&ioc->free_list)) {spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags);
@@ -2053,6 +2075,32 @@ mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx)return smid; } +static void +_base_recovery_check (struct MPT3SAS_ADAPTER *ioc) +{ +/* +* See _wait_for_commands_to_complete() call with regards to this code. +*/ +if (ioc->shost_recovery && ioc->pending_io_count) { +if (ioc->pending_io_count ==1 ) +wake_up (&ioc->reset_wq); + ioc->pending_io_count =0 ; + } +} + +static void +_dechain_st (struct MPT3SAS_ADAPTER *ioc,struct scsiio_tracker *st) +{ +struct chain_tracker *chain_req; + +while (!list_empty (&st->chain_list)) { + chain_req =list_first_entry (&st->chain_list, + struct chain_tracker, + tracker_list); +list_move (&chain_req->tracker_list, &ioc->free_chain_list); + } +} +/** * mpt3sas_base_free_smid - put smid back on free_list * @ioc: per adapter object
@@ -2065,34 +2113,36 @@ mpt3sas_base_free_smid(struct MPT3SAS_ADAPTER *ioc, u16 smid) {unsigned long flags;int i; -struct chain_tracker *chain_req, *next; + +if (shost_use_blk_mq (ioc->shost) && smid < ioc->hi_priority_smid) { +struct scsiio_tracker *st; + + st =mpt3sas_get_st_from_smid (ioc, smid); +if (!st) +return ; + +if (!list_empty (&st->chain_list)) { +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); +_dechain_st (ioc, st); +spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); + } + +_base_recovery_check (ioc); +return ; + }spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);if (smid < ioc->hi_priority_smid) {/* scsiio queue */ i = smid -1 ; -if (!list_empty (&ioc->scsi_lookup[i].chain_list)) { -list_for_each_entry_safe (chain_req, next, - &ioc->scsi_lookup[i].chain_list, tracker_list) { -list_del_init (&chain_req->tracker_list); -list_add (&chain_req->tracker_list, - &ioc->free_chain_list); - } - } +if (!list_empty (&ioc->scsi_lookup[i].chain_list)) +_dechain_st (ioc, &ioc->scsi_lookup[i]); ioc->scsi_lookup[i].cb_idx =0xFF ; ioc->scsi_lookup[i].scmd =NULL ;list_add (&ioc->scsi_lookup[i].tracker_list, &ioc->free_list);spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); -/* -* See _wait_for_commands_to_complete() call with regards -* to this code. -*/ -if (ioc->shost_recovery && ioc->pending_io_count) { -if (ioc->pending_io_count ==1 ) -wake_up (&ioc->reset_wq); - ioc->pending_io_count--; - } +_base_recovery_check (ioc);return ; }else if (smid < ioc->internal_smid) {/* hi-priority */
@@ -2896,14 +2946,23 @@ _base_allocate_memory_pools(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) ioc->name, (unsigned long long) ioc->request_dma)); total_sz += sz; - sz = ioc->scsiio_depth *sizeof (struct scsiio_tracker ); - ioc->scsi_lookup_pages =get_order (sz); - ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages ( -GFP_KERNEL , ioc->scsi_lookup_pages); -if (!ioc->scsi_lookup) { -pr_err (MPT3SAS_FMT "scsi_lookup: get_free_pages failed, sz(%d)\n" , - ioc->name, (int )sz); - goto out; +/* +* Don't need to allocate memory for scsiio_tracker array if we +* are using scsi-mq, we embed it in the scsi_cmnd for that case. +*/ +if (!shost_use_blk_mq (ioc->shost)) { + sz = ioc->scsiio_depth *sizeof (struct scsiio_tracker ); + ioc->scsi_lookup_pages =get_order (sz); + ioc->scsi_lookup = (struct scsiio_tracker *)__get_free_pages ( +GFP_KERNEL , ioc->scsi_lookup_pages); +if (!ioc->scsi_lookup) { +pr_err (MPT3SAS_FMT "scsi_lookup: get_free_pages " +"failed, sz(%d)\n" , ioc->name, (int )sz); + goto out; + } + }else { + ioc->scsi_lookup_pages =0 ; + ioc->scsi_lookup =NULL ; } dinitprintk(ioc, pr_info(MPT3SAS_FMT "scsiio(0x%p): depth(%d)\n",
@@ -4439,14 +4498,17 @@ _base_make_ioc_operational(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)/* initialize the scsi lookup free list */ spin_lock_irqsave (&ioc->scsi_lookup_lock, flags);INIT_LIST_HEAD (&ioc->free_list); - smid =1 ; -for (i =0 ; i < ioc->scsiio_depth; i++, smid++) { -INIT_LIST_HEAD (&ioc->scsi_lookup[i].chain_list); - ioc->scsi_lookup[i].cb_idx =0xFF ; - ioc->scsi_lookup[i].smid = smid; - ioc->scsi_lookup[i].scmd =NULL ; -list_add_tail (&ioc->scsi_lookup[i].tracker_list, - &ioc->free_list); + +if (!shost_use_blk_mq (ioc->shost)) { + smid =1 ; +for (i =0 ; i < ioc->scsiio_depth; i++, smid++) { +INIT_LIST_HEAD (&ioc->scsi_lookup[i].chain_list); + ioc->scsi_lookup[i].cb_idx =0xFF ; + ioc->scsi_lookup[i].smid = smid; + ioc->scsi_lookup[i].scmd =NULL ; +list_add_tail (&ioc->scsi_lookup[i].tracker_list, + &ioc->free_list); + } }/* hi-priority queue */
@@ -4895,7 +4957,7 @@ _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc, int sleep_flag) {u32 ioc_state;unsigned long flags; -u16 i; +u16 i, pending, loops; ioc->pending_io_count =0 ;if (sleep_flag !=CAN_SLEEP )
@@ -4906,17 +4968,32 @@ _wait_for_commands_to_complete(struct MPT3SAS_ADAPTER *ioc, int sleep_flag)return ;/* pending command count */ -spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); -for (i =0 ; i < ioc->scsiio_depth; i++) -if (ioc->scsi_lookup[i].cb_idx !=0xFF ) - ioc->pending_io_count++; -spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); + loops =0 ; +do { + pending =0 ; +spin_lock_irqsave (&ioc->scsi_lookup_lock, flags); +for (i =0 ; i < ioc->scsiio_depth; i++) { +struct scsiio_tracker *st; +struct scsi_cmnd *scmd; + +if (shost_use_blk_mq (ioc->shost)) { + scmd =scsi_mq_find_tag (ioc->shost, i); +if (scmd) + pending++; + }else { + st =mpt3sas_get_st_from_smid (ioc, i +1 ); +if (st->cb_idx !=0xFF ) + pending++; + } + } +spin_unlock_irqrestore (&ioc->scsi_lookup_lock, flags); -if (!ioc->pending_io_count) -return ; +if (!pending) +break ; -/* wait for pending commands to complete */ -wait_event_timeout (ioc->reset_wq, ioc->pending_io_count ==0 ,10 *HZ ); +/* wait for pending commands to complete */ +wait_event_timeout (ioc->reset_wq, ioc->pending_io_count ==0 ,HZ ); + }while (++loops <=10 ); }/**
drivers/scsi/mpt3sas/mpt3sas_base.h +2 -0
@@ -986,6 +986,8 @@ u16 mpt3sas_base_get_smid_hpr(struct MPT3SAS_ADAPTER *ioc, u8 cb_idx);u16 mpt3sas_base_get_smid_scsiio (struct MPT3SAS_ADAPTER *ioc,u8 cb_idx,struct scsi_cmnd *scmd); +struct scsiio_tracker *mpt3sas_get_st_from_smid (struct MPT3SAS_ADAPTER *ioc, +u16 smid);u16 mpt3sas_base_get_smid (struct MPT3SAS_ADAPTER *ioc,u8 cb_idx);void mpt3sas_base_free_smid (struct MPT3SAS_ADAPTER *ioc,u16 smid); void mpt3sas_base_put_smid_scsi_io(struct MPT3SAS_ADAPTER *ioc, u16 smid,
drivers/scsi/mpt3sas/mpt3sas_scsih.c +58 -11
129 lines not on this page · raw message
Signature · 1 line
1.9.1
This looks good modulo my minor comments and using and testing the new code path for the !mq case as well. Please also Cc the Avago people on your next submission.