scsi: qla2xxx: Select qpair depending on which CPU post_cmd() gets called
authorShreyas Deodhar <sdeodhar@marvell.com>
Thu, 22 Dec 2022 04:39:32 +0000 (20:39 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Oct 2023 12:56:45 +0000 (14:56 +0200)
[ Upstream commit 1d201c81d4cc6840735bbcc99e6031503e5cf3b8 ]

In current I/O path, Tx and Rx may not be processed on same CPU. This may
lead to thrashing and optimum performance may not be achieved.

Pick qpair such that Tx and Rx are processed on same CPU.

Signed-off-by: Shreyas Deodhar <sdeodhar@marvell.com>
Signed-off-by: Nilesh Javali <njavali@marvell.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Stable-dep-of: 59f10a05b5c7 ("scsi: qla2xxx: Use raw_smp_processor_id() instead of smp_processor_id()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_init.c
drivers/scsi/qla2xxx/qla_inline.h
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_nvme.c
drivers/scsi/qla2xxx/qla_os.c

index 7d282906598f3badf2302e381e31e48bbf64aba6..817efdd32ad63853dd549a6c84f9e9104f2361f0 100644 (file)
@@ -3475,6 +3475,7 @@ struct qla_msix_entry {
        int have_irq;
        int in_use;
        uint32_t vector;
+       uint32_t vector_base0;
        uint16_t entry;
        char name[30];
        void *handle;
@@ -4133,6 +4134,7 @@ struct qla_hw_data {
        struct req_que **req_q_map;
        struct rsp_que **rsp_q_map;
        struct qla_qpair **queue_pair_map;
+       struct qla_qpair **qp_cpu_map;
        unsigned long req_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
        unsigned long rsp_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
        unsigned long qpair_qid_map[(QLA_MAX_QUEUES / 8)
index 36abdb0de1694f8f9ca57d22c0f868bba609983b..79de31e7e8b2a1029ed618079fcedac1a8f924d2 100644 (file)
@@ -9758,8 +9758,6 @@ struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
                qpair->req = ha->req_q_map[req_id];
                qpair->rsp->req = qpair->req;
                qpair->rsp->qpair = qpair;
-               /* init qpair to this cpu. Will adjust at run time. */
-               qla_cpu_update(qpair, raw_smp_processor_id());
 
                if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
                        if (ha->fw_attributes & BIT_4)
index a7b5d1114682716e99104b7f905a49004b1967b7..d5cf9db2a8ea3bfe7d924fb4258d8e16a9e260d8 100644 (file)
@@ -573,3 +573,58 @@ fcport_is_bigger(fc_port_t *fcport)
 {
        return !fcport_is_smaller(fcport);
 }
+
+static inline struct qla_qpair *
+qla_mapq_nvme_select_qpair(struct qla_hw_data *ha, struct qla_qpair *qpair)
+{
+       int cpuid = smp_processor_id();
+
+       if (qpair->cpuid != cpuid &&
+           ha->qp_cpu_map[cpuid]) {
+               qpair = ha->qp_cpu_map[cpuid];
+       }
+       return qpair;
+}
+
+static inline void
+qla_mapq_init_qp_cpu_map(struct qla_hw_data *ha,
+                        struct qla_msix_entry *msix,
+                        struct qla_qpair *qpair)
+{
+       const struct cpumask *mask;
+       unsigned int cpu;
+
+       if (!ha->qp_cpu_map)
+               return;
+       mask = pci_irq_get_affinity(ha->pdev, msix->vector_base0);
+       qpair->cpuid = cpumask_first(mask);
+       for_each_cpu(cpu, mask) {
+               ha->qp_cpu_map[cpu] = qpair;
+       }
+       msix->cpuid = qpair->cpuid;
+}
+
+static inline void
+qla_mapq_free_qp_cpu_map(struct qla_hw_data *ha)
+{
+       if (ha->qp_cpu_map) {
+               kfree(ha->qp_cpu_map);
+               ha->qp_cpu_map = NULL;
+       }
+}
+
+static inline int qla_mapq_alloc_qp_cpu_map(struct qla_hw_data *ha)
+{
+       scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
+
+       if (!ha->qp_cpu_map) {
+               ha->qp_cpu_map = kcalloc(NR_CPUS, sizeof(struct qla_qpair *),
+                                        GFP_KERNEL);
+               if (!ha->qp_cpu_map) {
+                       ql_log(ql_log_fatal, vha, 0x0180,
+                              "Unable to allocate memory for qp_cpu_map ptrs.\n");
+                       return -1;
+               }
+       }
+       return 0;
+}
index 0111249cc877413bedf00b4f435f79582cf4f40c..a5e6246127ed30dee45fbcc8311303cdbf63623b 100644 (file)
@@ -3819,7 +3819,6 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha,
 
        if (rsp->qpair->cpuid != smp_processor_id() || !rsp->qpair->rcv_intr) {
                rsp->qpair->rcv_intr = 1;
-               qla_cpu_update(rsp->qpair, smp_processor_id());
        }
 
 #define __update_rsp_in(_is_shadow_hba, _rsp, _rsp_in)                 \
@@ -4425,6 +4424,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
        for (i = 0; i < ha->msix_count; i++) {
                qentry = &ha->msix_entries[i];
                qentry->vector = pci_irq_vector(ha->pdev, i);
+               qentry->vector_base0 = i;
                qentry->entry = i;
                qentry->have_irq = 0;
                qentry->in_use = 0;
@@ -4652,5 +4652,6 @@ int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair,
        }
        msix->have_irq = 1;
        msix->handle = qpair;
+       qla_mapq_init_qp_cpu_map(ha, msix, qpair);
        return ret;
 }
index c9a6fc882a8014a1901c8a07d94602ecab14327d..9941b38eac93c5a59ef8084f24b5c46a21deea91 100644 (file)
@@ -609,6 +609,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
        fc_port_t *fcport;
        struct srb_iocb *nvme;
        struct scsi_qla_host *vha;
+       struct qla_hw_data *ha;
        int rval;
        srb_t *sp;
        struct qla_qpair *qpair = hw_queue_handle;
@@ -629,6 +630,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
                return -ENODEV;
 
        vha = fcport->vha;
+       ha = vha->hw;
 
        if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
                return -EBUSY;
@@ -643,6 +645,8 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
        if (fcport->nvme_flag & NVME_FLAG_RESETTING)
                return -EBUSY;
 
+       qpair = qla_mapq_nvme_select_qpair(ha, qpair);
+
        /* Alloc SRB structure */
        sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
        if (!sp)
index 78f7cd16967fa6137c704738577e74ad62f9c919..b33ffec1cb75e30ceac9f7d6cba26bd1d4c177a4 100644 (file)
@@ -480,6 +480,11 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
                            "Unable to allocate memory for queue pair ptrs.\n");
                        goto fail_qpair_map;
                }
+               if (qla_mapq_alloc_qp_cpu_map(ha) != 0) {
+                       kfree(ha->queue_pair_map);
+                       ha->queue_pair_map = NULL;
+                       goto fail_qpair_map;
+               }
        }
 
        /*
@@ -554,6 +559,7 @@ static void qla2x00_free_queues(struct qla_hw_data *ha)
                ha->base_qpair = NULL;
        }
 
+       qla_mapq_free_qp_cpu_map(ha);
        spin_lock_irqsave(&ha->hardware_lock, flags);
        for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
                if (!test_bit(cnt, ha->req_qid_map))