RDMA/hns: Fix CQ and QP cache affinity

[ Upstream commit 9e03dbea2b ]

Currently, the affinity between QP cache and CQ cache is not
considered when assigning QPN, it will affect the message rate of HW.

Allocate QPN from QP cache with better CQ affinity to get better
performance.

Fixes: 71586dd200 ("RDMA/hns: Create QP with selected QPN for bank load balance")
Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
Link: https://lore.kernel.org/r/20230804012711.808069-5-huangjunxian6@hisilicon.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Chengchang Tang 2023-08-04 09:27:11 +08:00 коммит произвёл Greg Kroah-Hartman
Родитель b051c3bf3b
Коммит 42d111304d
2 изменённых файлов: 23 добавлений и 6 удалений

Просмотреть файл

@ -121,6 +121,7 @@
#define HNS_ROCE_CQ_BANK_NUM 4 #define HNS_ROCE_CQ_BANK_NUM 4
#define CQ_BANKID_SHIFT 2 #define CQ_BANKID_SHIFT 2
#define CQ_BANKID_MASK GENMASK(1, 0)
/* The chip implementation of the consumer index is calculated /* The chip implementation of the consumer index is calculated
* according to twice the actual EQ depth * according to twice the actual EQ depth

Просмотреть файл

@ -172,14 +172,29 @@ static void hns_roce_ib_qp_event(struct hns_roce_qp *hr_qp,
} }
} }
static u8 get_least_load_bankid_for_qp(struct hns_roce_bank *bank) static u8 get_affinity_cq_bank(u8 qp_bank)
{ {
u32 least_load = bank[0].inuse; return (qp_bank >> 1) & CQ_BANKID_MASK;
}
static u8 get_least_load_bankid_for_qp(struct ib_qp_init_attr *init_attr,
struct hns_roce_bank *bank)
{
#define INVALID_LOAD_QPNUM 0xFFFFFFFF
struct ib_cq *scq = init_attr->send_cq;
u32 least_load = INVALID_LOAD_QPNUM;
unsigned long cqn = 0;
u8 bankid = 0; u8 bankid = 0;
u32 bankcnt; u32 bankcnt;
u8 i; u8 i;
for (i = 1; i < HNS_ROCE_QP_BANK_NUM; i++) { if (scq)
cqn = to_hr_cq(scq)->cqn;
for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) {
if (scq && (get_affinity_cq_bank(i) != (cqn & CQ_BANKID_MASK)))
continue;
bankcnt = bank[i].inuse; bankcnt = bank[i].inuse;
if (bankcnt < least_load) { if (bankcnt < least_load) {
least_load = bankcnt; least_load = bankcnt;
@ -211,7 +226,8 @@ static int alloc_qpn_with_bankid(struct hns_roce_bank *bank, u8 bankid,
return 0; return 0;
} }
static int alloc_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp) static int alloc_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
struct ib_qp_init_attr *init_attr)
{ {
struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
unsigned long num = 0; unsigned long num = 0;
@ -229,7 +245,7 @@ static int alloc_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
hr_qp->doorbell_qpn = 1; hr_qp->doorbell_qpn = 1;
} else { } else {
mutex_lock(&qp_table->bank_mutex); mutex_lock(&qp_table->bank_mutex);
bankid = get_least_load_bankid_for_qp(qp_table->bank); bankid = get_least_load_bankid_for_qp(init_attr, qp_table->bank);
ret = alloc_qpn_with_bankid(&qp_table->bank[bankid], bankid, ret = alloc_qpn_with_bankid(&qp_table->bank[bankid], bankid,
&num); &num);
@ -1067,7 +1083,7 @@ static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
goto err_buf; goto err_buf;
} }
ret = alloc_qpn(hr_dev, hr_qp); ret = alloc_qpn(hr_dev, hr_qp, init_attr);
if (ret) { if (ret) {
ibdev_err(ibdev, "failed to alloc QPN, ret = %d.\n", ret); ibdev_err(ibdev, "failed to alloc QPN, ret = %d.\n", ret);
goto err_qpn; goto err_qpn;