Skip to content

Commit 532a239

Browse files
Shreyas Deodhargregkh
authored andcommitted
scsi: qla2xxx: Select qpair depending on which CPU post_cmd() gets called
[ Upstream commit 1d201c8 ] 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 <[email protected]> Signed-off-by: Nilesh Javali <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]> Stable-dep-of: 59f10a0 ("scsi: qla2xxx: Use raw_smp_processor_id() instead of smp_processor_id()") Signed-off-by: Sasha Levin <[email protected]>
1 parent 6642b4e commit 532a239

File tree

6 files changed

+69
-3
lines changed

6 files changed

+69
-3
lines changed

drivers/scsi/qla2xxx/qla_def.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,7 @@ struct qla_msix_entry {
34613461
int have_irq;
34623462
int in_use;
34633463
uint32_t vector;
3464+
uint32_t vector_base0;
34643465
uint16_t entry;
34653466
char name[30];
34663467
void *handle;
@@ -4119,6 +4120,7 @@ struct qla_hw_data {
41194120
struct req_que **req_q_map;
41204121
struct rsp_que **rsp_q_map;
41214122
struct qla_qpair **queue_pair_map;
4123+
struct qla_qpair **qp_cpu_map;
41224124
unsigned long req_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
41234125
unsigned long rsp_qid_map[(QLA_MAX_QUEUES / 8) / sizeof(unsigned long)];
41244126
unsigned long qpair_qid_map[(QLA_MAX_QUEUES / 8)

drivers/scsi/qla2xxx/qla_init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9779,8 +9779,6 @@ struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
97799779
qpair->req = ha->req_q_map[req_id];
97809780
qpair->rsp->req = qpair->req;
97819781
qpair->rsp->qpair = qpair;
9782-
/* init qpair to this cpu. Will adjust at run time. */
9783-
qla_cpu_update(qpair, raw_smp_processor_id());
97849782

97859783
if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
97869784
if (ha->fw_attributes & BIT_4)

drivers/scsi/qla2xxx/qla_inline.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,58 @@ fcport_is_bigger(fc_port_t *fcport)
573573
{
574574
return !fcport_is_smaller(fcport);
575575
}
576+
577+
static inline struct qla_qpair *
578+
qla_mapq_nvme_select_qpair(struct qla_hw_data *ha, struct qla_qpair *qpair)
579+
{
580+
int cpuid = smp_processor_id();
581+
582+
if (qpair->cpuid != cpuid &&
583+
ha->qp_cpu_map[cpuid]) {
584+
qpair = ha->qp_cpu_map[cpuid];
585+
}
586+
return qpair;
587+
}
588+
589+
static inline void
590+
qla_mapq_init_qp_cpu_map(struct qla_hw_data *ha,
591+
struct qla_msix_entry *msix,
592+
struct qla_qpair *qpair)
593+
{
594+
const struct cpumask *mask;
595+
unsigned int cpu;
596+
597+
if (!ha->qp_cpu_map)
598+
return;
599+
mask = pci_irq_get_affinity(ha->pdev, msix->vector_base0);
600+
qpair->cpuid = cpumask_first(mask);
601+
for_each_cpu(cpu, mask) {
602+
ha->qp_cpu_map[cpu] = qpair;
603+
}
604+
msix->cpuid = qpair->cpuid;
605+
}
606+
607+
static inline void
608+
qla_mapq_free_qp_cpu_map(struct qla_hw_data *ha)
609+
{
610+
if (ha->qp_cpu_map) {
611+
kfree(ha->qp_cpu_map);
612+
ha->qp_cpu_map = NULL;
613+
}
614+
}
615+
616+
static inline int qla_mapq_alloc_qp_cpu_map(struct qla_hw_data *ha)
617+
{
618+
scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
619+
620+
if (!ha->qp_cpu_map) {
621+
ha->qp_cpu_map = kcalloc(NR_CPUS, sizeof(struct qla_qpair *),
622+
GFP_KERNEL);
623+
if (!ha->qp_cpu_map) {
624+
ql_log(ql_log_fatal, vha, 0x0180,
625+
"Unable to allocate memory for qp_cpu_map ptrs.\n");
626+
return -1;
627+
}
628+
}
629+
return 0;
630+
}

drivers/scsi/qla2xxx/qla_isr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3782,7 +3782,6 @@ void qla24xx_process_response_queue(struct scsi_qla_host *vha,
37823782

37833783
if (rsp->qpair->cpuid != smp_processor_id() || !rsp->qpair->rcv_intr) {
37843784
rsp->qpair->rcv_intr = 1;
3785-
qla_cpu_update(rsp->qpair, smp_processor_id());
37863785
}
37873786

37883787
#define __update_rsp_in(_update, _is_shadow_hba, _rsp, _rsp_in) \
@@ -4396,6 +4395,7 @@ qla24xx_enable_msix(struct qla_hw_data *ha, struct rsp_que *rsp)
43964395
for (i = 0; i < ha->msix_count; i++) {
43974396
qentry = &ha->msix_entries[i];
43984397
qentry->vector = pci_irq_vector(ha->pdev, i);
4398+
qentry->vector_base0 = i;
43994399
qentry->entry = i;
44004400
qentry->have_irq = 0;
44014401
qentry->in_use = 0;
@@ -4623,5 +4623,6 @@ int qla25xx_request_irq(struct qla_hw_data *ha, struct qla_qpair *qpair,
46234623
}
46244624
msix->have_irq = 1;
46254625
msix->handle = qpair;
4626+
qla_mapq_init_qp_cpu_map(ha, msix, qpair);
46264627
return ret;
46274628
}

drivers/scsi/qla2xxx/qla_nvme.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
598598
fc_port_t *fcport;
599599
struct srb_iocb *nvme;
600600
struct scsi_qla_host *vha;
601+
struct qla_hw_data *ha;
601602
int rval;
602603
srb_t *sp;
603604
struct qla_qpair *qpair = hw_queue_handle;
@@ -618,6 +619,7 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
618619
return -ENODEV;
619620

620621
vha = fcport->vha;
622+
ha = vha->hw;
621623

622624
if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
623625
return -EBUSY;
@@ -632,6 +634,8 @@ static int qla_nvme_post_cmd(struct nvme_fc_local_port *lport,
632634
if (fcport->nvme_flag & NVME_FLAG_RESETTING)
633635
return -EBUSY;
634636

637+
qpair = qla_mapq_nvme_select_qpair(ha, qpair);
638+
635639
/* Alloc SRB structure */
636640
sp = qla2xxx_get_qpair_sp(vha, qpair, fcport, GFP_ATOMIC);
637641
if (!sp)

drivers/scsi/qla2xxx/qla_os.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ static int qla2x00_alloc_queues(struct qla_hw_data *ha, struct req_que *req,
467467
"Unable to allocate memory for queue pair ptrs.\n");
468468
goto fail_qpair_map;
469469
}
470+
if (qla_mapq_alloc_qp_cpu_map(ha) != 0) {
471+
kfree(ha->queue_pair_map);
472+
ha->queue_pair_map = NULL;
473+
goto fail_qpair_map;
474+
}
470475
}
471476

472477
/*
@@ -541,6 +546,7 @@ static void qla2x00_free_queues(struct qla_hw_data *ha)
541546
ha->base_qpair = NULL;
542547
}
543548

549+
qla_mapq_free_qp_cpu_map(ha);
544550
spin_lock_irqsave(&ha->hardware_lock, flags);
545551
for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
546552
if (!test_bit(cnt, ha->req_qid_map))

0 commit comments

Comments
 (0)