Skip to content

Commit cb97b37

Browse files
Kalesh APrleon
authored andcommitted
RDMA/bnxt_re: Refurbish CQ to NQ hash calculation
There are few use cases where CQ create and destroy is seen before re-creating the CQ, this kind of use case is disturbing the RR distribution and all the active CQ getting mapped to only 2 NQ alternatively. Fixing the CQ to NQ hash calculation by implementing a quick load sorting mechanism under a mutex. Using this, if the CQ was allocated and destroyed before using it, the nq selecting algorithm still obtains the least loaded CQ. Thus balancing the load on NQs. Signed-off-by: Selvin Xavier <[email protected]> Signed-off-by: Kalesh AP <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 30b8713 commit cb97b37

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

drivers/infiniband/hw/bnxt_re/bnxt_re.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ struct bnxt_re_pacing {
159159
struct bnxt_re_nq_record {
160160
struct bnxt_qplib_nq nq[BNXT_RE_MAX_MSIX];
161161
int num_msix;
162+
/* serialize NQ access */
163+
struct mutex load_lock;
162164
};
163165

164166
#define MAX_CQ_HASH_BITS (16)

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,28 @@ int bnxt_re_post_recv(struct ib_qp *ib_qp, const struct ib_recv_wr *wr,
30293029
return rc;
30303030
}
30313031

3032+
static struct bnxt_qplib_nq *bnxt_re_get_nq(struct bnxt_re_dev *rdev)
3033+
{
3034+
int min, indx;
3035+
3036+
mutex_lock(&rdev->nqr->load_lock);
3037+
for (indx = 0, min = 0; indx < (rdev->nqr->num_msix - 1); indx++) {
3038+
if (rdev->nqr->nq[min].load > rdev->nqr->nq[indx].load)
3039+
min = indx;
3040+
}
3041+
rdev->nqr->nq[min].load++;
3042+
mutex_unlock(&rdev->nqr->load_lock);
3043+
3044+
return &rdev->nqr->nq[min];
3045+
}
3046+
3047+
static void bnxt_re_put_nq(struct bnxt_re_dev *rdev, struct bnxt_qplib_nq *nq)
3048+
{
3049+
mutex_lock(&rdev->nqr->load_lock);
3050+
nq->load--;
3051+
mutex_unlock(&rdev->nqr->load_lock);
3052+
}
3053+
30323054
/* Completion Queues */
30333055
int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
30343056
{
@@ -3047,6 +3069,8 @@ int bnxt_re_destroy_cq(struct ib_cq *ib_cq, struct ib_udata *udata)
30473069
hash_del(&cq->hash_entry);
30483070
}
30493071
bnxt_qplib_destroy_cq(&rdev->qplib_res, &cq->qplib_cq);
3072+
3073+
bnxt_re_put_nq(rdev, nq);
30503074
ib_umem_release(cq->umem);
30513075

30523076
atomic_dec(&rdev->stats.res.cq_count);
@@ -3065,8 +3089,6 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
30653089
rdma_udata_to_drv_context(udata, struct bnxt_re_ucontext, ib_uctx);
30663090
struct bnxt_qplib_dev_attr *dev_attr = &rdev->dev_attr;
30673091
struct bnxt_qplib_chip_ctx *cctx;
3068-
struct bnxt_qplib_nq *nq = NULL;
3069-
unsigned int nq_alloc_cnt;
30703092
int cqe = attr->cqe;
30713093
int rc, entries;
30723094
u32 active_cqs;
@@ -3117,16 +3139,10 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
31173139

31183140
cq->qplib_cq.dpi = &rdev->dpi_privileged;
31193141
}
3120-
/*
3121-
* Allocating the NQ in a round robin fashion. nq_alloc_cnt is a
3122-
* used for getting the NQ index.
3123-
*/
3124-
nq_alloc_cnt = atomic_inc_return(&rdev->nq_alloc_cnt);
3125-
nq = &rdev->nqr->nq[nq_alloc_cnt % (rdev->nqr->num_msix - 1)];
31263142
cq->qplib_cq.max_wqe = entries;
3127-
cq->qplib_cq.cnq_hw_ring_id = nq->ring_id;
3128-
cq->qplib_cq.nq = nq;
31293143
cq->qplib_cq.coalescing = &rdev->cq_coalescing;
3144+
cq->qplib_cq.nq = bnxt_re_get_nq(rdev);
3145+
cq->qplib_cq.cnq_hw_ring_id = cq->qplib_cq.nq->ring_id;
31303146

31313147
rc = bnxt_qplib_create_cq(&rdev->qplib_res, &cq->qplib_cq);
31323148
if (rc) {
@@ -3136,7 +3152,6 @@ int bnxt_re_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
31363152

31373153
cq->ib_cq.cqe = entries;
31383154
cq->cq_period = cq->qplib_cq.period;
3139-
nq->budget++;
31403155

31413156
active_cqs = atomic_inc_return(&rdev->stats.res.cq_count);
31423157
if (active_cqs > rdev->stats.res.cq_watermark)

drivers/infiniband/hw/bnxt_re/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,8 @@ static int bnxt_re_init_res(struct bnxt_re_dev *rdev)
15661566

15671567
bnxt_qplib_init_res(&rdev->qplib_res);
15681568

1569+
mutex_init(&rdev->nqr->load_lock);
1570+
15691571
for (i = 1; i < rdev->nqr->num_msix ; i++) {
15701572
db_offt = rdev->en_dev->msix_entries[i].db_offset;
15711573
rc = bnxt_qplib_enable_nq(rdev->en_dev->pdev, &rdev->nqr->nq[i - 1],

drivers/infiniband/hw/bnxt_re/qplib_fp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ int bnxt_qplib_enable_nq(struct pci_dev *pdev, struct bnxt_qplib_nq *nq,
551551
nq->pdev = pdev;
552552
nq->cqn_handler = cqn_handler;
553553
nq->srqn_handler = srqn_handler;
554+
nq->load = 0;
554555

555556
/* Have a task to schedule CQ notifiers in post send case */
556557
nq->cqn_wq = create_singlethread_workqueue("bnxt_qplib_nq");

drivers/infiniband/hw/bnxt_re/qplib_fp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ struct bnxt_qplib_nq {
519519
struct tasklet_struct nq_tasklet;
520520
bool requested;
521521
int budget;
522+
u32 load;
522523

523524
cqn_handler_t cqn_handler;
524525
srqn_handler_t srqn_handler;

0 commit comments

Comments
 (0)