Skip to content

Commit c4b67b5

Browse files
Chengchang Tangrleon
authored andcommitted
RDMA/hns: Fix recv CQ and QP cache affinity
Currently driver enforces affinity between QP cache and send CQ cache, which helps improve the performance of sending, but doesn't set affinity with recv CQ cache, resulting in suboptimal performance of receiving. Use one CQ bank per context to ensure the affinity among QP, send CQ and recv CQ. For kernel ULP, CQ bank is fixed to 0. Fixes: 9e03dbe ("RDMA/hns: Fix CQ and QP cache affinity") Signed-off-by: Chengchang Tang <[email protected]> Signed-off-by: Junxian Huang <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Leon Romanovsky <[email protected]>
1 parent d871315 commit c4b67b5

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

drivers/infiniband/hw/hns/hns_roce_cq.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,51 @@
3030
* SOFTWARE.
3131
*/
3232

33+
#include <linux/pci.h>
3334
#include <rdma/ib_umem.h>
3435
#include <rdma/uverbs_ioctl.h>
3536
#include "hns_roce_device.h"
3637
#include "hns_roce_cmd.h"
3738
#include "hns_roce_hem.h"
3839
#include "hns_roce_common.h"
3940

41+
void hns_roce_put_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx)
42+
{
43+
struct hns_roce_dev *hr_dev = to_hr_dev(uctx->ibucontext.device);
44+
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
45+
46+
if (hr_dev->pci_dev->revision < PCI_REVISION_ID_HIP09)
47+
return;
48+
49+
mutex_lock(&cq_table->bank_mutex);
50+
cq_table->ctx_num[uctx->cq_bank_id]--;
51+
mutex_unlock(&cq_table->bank_mutex);
52+
}
53+
54+
void hns_roce_get_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx)
55+
{
56+
struct hns_roce_dev *hr_dev = to_hr_dev(uctx->ibucontext.device);
57+
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
58+
u32 least_load = cq_table->ctx_num[0];
59+
u8 bankid = 0;
60+
u8 i;
61+
62+
if (hr_dev->pci_dev->revision < PCI_REVISION_ID_HIP09)
63+
return;
64+
65+
mutex_lock(&cq_table->bank_mutex);
66+
for (i = 1; i < HNS_ROCE_CQ_BANK_NUM; i++) {
67+
if (cq_table->ctx_num[i] < least_load) {
68+
least_load = cq_table->ctx_num[i];
69+
bankid = i;
70+
}
71+
}
72+
cq_table->ctx_num[bankid]++;
73+
mutex_unlock(&cq_table->bank_mutex);
74+
75+
uctx->cq_bank_id = bankid;
76+
}
77+
4078
static u8 get_least_load_bankid_for_cq(struct hns_roce_bank *bank)
4179
{
4280
u32 least_load = bank[0].inuse;
@@ -55,15 +93,29 @@ static u8 get_least_load_bankid_for_cq(struct hns_roce_bank *bank)
5593
return bankid;
5694
}
5795

58-
static int alloc_cqn(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq)
96+
static u8 select_cq_bankid(struct hns_roce_dev *hr_dev,
97+
struct hns_roce_bank *bank, struct ib_udata *udata)
98+
{
99+
struct hns_roce_ucontext *uctx = udata ?
100+
rdma_udata_to_drv_context(udata, struct hns_roce_ucontext,
101+
ibucontext) : NULL;
102+
103+
if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
104+
return uctx ? uctx->cq_bank_id : 0;
105+
106+
return get_least_load_bankid_for_cq(bank);
107+
}
108+
109+
static int alloc_cqn(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq,
110+
struct ib_udata *udata)
59111
{
60112
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
61113
struct hns_roce_bank *bank;
62114
u8 bankid;
63115
int id;
64116

65117
mutex_lock(&cq_table->bank_mutex);
66-
bankid = get_least_load_bankid_for_cq(cq_table->bank);
118+
bankid = select_cq_bankid(hr_dev, cq_table->bank, udata);
67119
bank = &cq_table->bank[bankid];
68120

69121
id = ida_alloc_range(&bank->ida, bank->min, bank->max, GFP_KERNEL);
@@ -396,7 +448,7 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr,
396448
goto err_cq_buf;
397449
}
398450

399-
ret = alloc_cqn(hr_dev, hr_cq);
451+
ret = alloc_cqn(hr_dev, hr_cq, udata);
400452
if (ret) {
401453
ibdev_err(ibdev, "failed to alloc CQN, ret = %d.\n", ret);
402454
goto err_cq_db;

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct hns_roce_ucontext {
217217
struct mutex page_mutex;
218218
struct hns_user_mmap_entry *db_mmap_entry;
219219
u32 config;
220+
u8 cq_bank_id;
220221
};
221222

222223
struct hns_roce_pd {
@@ -495,6 +496,7 @@ struct hns_roce_cq_table {
495496
struct hns_roce_hem_table table;
496497
struct hns_roce_bank bank[HNS_ROCE_CQ_BANK_NUM];
497498
struct mutex bank_mutex;
499+
u32 ctx_num[HNS_ROCE_CQ_BANK_NUM];
498500
};
499501

500502
struct hns_roce_srq_table {
@@ -1305,5 +1307,7 @@ hns_roce_user_mmap_entry_insert(struct ib_ucontext *ucontext, u64 address,
13051307
size_t length,
13061308
enum hns_roce_mmap_type mmap_type);
13071309
bool check_sl_valid(struct hns_roce_dev *hr_dev, u8 sl);
1310+
void hns_roce_put_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx);
1311+
void hns_roce_get_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx);
13081312

13091313
#endif /* _HNS_ROCE_DEVICE_H */

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
425425
if (ret)
426426
goto error_fail_copy_to_udata;
427427

428+
hns_roce_get_cq_bankid_for_uctx(context);
429+
428430
return 0;
429431

430432
error_fail_copy_to_udata:
@@ -447,6 +449,8 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
447449
struct hns_roce_ucontext *context = to_hr_ucontext(ibcontext);
448450
struct hns_roce_dev *hr_dev = to_hr_dev(ibcontext->device);
449451

452+
hns_roce_put_cq_bankid_for_uctx(context);
453+
450454
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
451455
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
452456
mutex_destroy(&context->page_mutex);

0 commit comments

Comments
 (0)