Skip to content

Commit 7a0c8f4

Browse files
Guy Levidledford
authored andcommitted
IB/mlx5: Support padded 128B CQE feature
In some benchmarks and some CPU architectures, writing the CQE on a full cache line size improves performance by saving memory access operations (read-modify-write) relative to partial cache line change. This patch lets the user to configure the device to pad the CQE up to 128B in case its content is less than 128B. Currently the driver supports only padding for a CQE size of 128B. Signed-off-by: Guy Levi <guyle@mellanox.com> Reviewed-by: Mark Bloch <markb@mellanox.com> Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent de57f2a commit 7a0c8f4

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

‎drivers/infiniband/hw/mlx5/cq.c‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,13 +754,13 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
754754
int err;
755755

756756
ucmdlen = udata->inlen < sizeof(ucmd) ?
757-
(sizeof(ucmd) - sizeof(ucmd.reserved)) : sizeof(ucmd);
757+
(sizeof(ucmd) - sizeof(ucmd.flags)) : sizeof(ucmd);
758758

759759
if (ib_copy_from_udata(&ucmd, udata, ucmdlen))
760760
return -EFAULT;
761761

762762
if (ucmdlen == sizeof(ucmd) &&
763-
ucmd.reserved != 0)
763+
(ucmd.flags & ~(MLX5_IB_CREATE_CQ_FLAGS_CQE_128B_PAD)))
764764
return -EINVAL;
765765

766766
if (ucmd.cqe_size != 64 && ucmd.cqe_size != 128)
@@ -830,6 +830,19 @@ static int create_cq_user(struct mlx5_ib_dev *dev, struct ib_udata *udata,
830830
ilog2(ucmd.cqe_comp_res_format));
831831
}
832832

833+
if (ucmd.flags & MLX5_IB_CREATE_CQ_FLAGS_CQE_128B_PAD) {
834+
if (*cqe_size != 128 ||
835+
!MLX5_CAP_GEN(dev->mdev, cqe_128_always)) {
836+
err = -EOPNOTSUPP;
837+
mlx5_ib_warn(dev,
838+
"CQE padding is not supported for CQE size of %dB!\n",
839+
*cqe_size);
840+
goto err_cqb;
841+
}
842+
843+
cq->private_flags |= MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD;
844+
}
845+
833846
return 0;
834847

835848
err_cqb:
@@ -989,7 +1002,10 @@ struct ib_cq *mlx5_ib_create_cq(struct ib_device *ibdev,
9891002
cq->cqe_size = cqe_size;
9901003

9911004
cqc = MLX5_ADDR_OF(create_cq_in, cqb, cq_context);
992-
MLX5_SET(cqc, cqc, cqe_sz, cqe_sz_to_mlx_sz(cqe_size));
1005+
MLX5_SET(cqc, cqc, cqe_sz,
1006+
cqe_sz_to_mlx_sz(cqe_size,
1007+
cq->private_flags &
1008+
MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD));
9931009
MLX5_SET(cqc, cqc, log_cq_size, ilog2(entries));
9941010
MLX5_SET(cqc, cqc, uar_page, index);
9951011
MLX5_SET(cqc, cqc, c_eqn, eqn);
@@ -1339,7 +1355,10 @@ int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
13391355

13401356
MLX5_SET(cqc, cqc, log_page_size,
13411357
page_shift - MLX5_ADAPTER_PAGE_SHIFT);
1342-
MLX5_SET(cqc, cqc, cqe_sz, cqe_sz_to_mlx_sz(cqe_size));
1358+
MLX5_SET(cqc, cqc, cqe_sz,
1359+
cqe_sz_to_mlx_sz(cqe_size,
1360+
cq->private_flags &
1361+
MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD));
13431362
MLX5_SET(cqc, cqc, log_cq_size, ilog2(entries));
13441363

13451364
MLX5_SET(modify_cq_in, in, op_mod, MLX5_CQ_OPMOD_RESIZE);

‎drivers/infiniband/hw/mlx5/main.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,13 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
826826

827827
if (field_avail(typeof(resp), flags, uhw->outlen)) {
828828
resp.response_length += sizeof(resp.flags);
829+
829830
if (MLX5_CAP_GEN(mdev, cqe_compression_128))
830831
resp.flags |=
831832
MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP;
833+
834+
if (MLX5_CAP_GEN(mdev, cqe_128_always))
835+
resp.flags |= MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD;
832836
}
833837

834838
if (field_avail(typeof(resp), sw_parsing_caps,

‎drivers/infiniband/hw/mlx5/mlx5_ib.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,10 @@ struct mlx5_shared_mr_info {
444444
struct ib_umem *umem;
445445
};
446446

447+
enum mlx5_ib_cq_pr_flags {
448+
MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD = 1 << 0,
449+
};
450+
447451
struct mlx5_ib_cq {
448452
struct ib_cq ibcq;
449453
struct mlx5_core_cq mcq;
@@ -466,6 +470,7 @@ struct mlx5_ib_cq {
466470
struct list_head wc_list;
467471
enum ib_cq_notify_flags notify_flags;
468472
struct work_struct notify_work;
473+
u16 private_flags; /* Use mlx5_ib_cq_pr_flags */
469474
};
470475

471476
struct mlx5_ib_wc {

‎include/linux/mlx5/cq.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ struct mlx5_cq_modify_params {
125125
enum {
126126
CQE_SIZE_64 = 0,
127127
CQE_SIZE_128 = 1,
128+
CQE_SIZE_128_PAD = 2,
128129
};
129130

130-
static inline int cqe_sz_to_mlx_sz(u8 size)
131+
static inline int cqe_sz_to_mlx_sz(u8 size, int padding_128_en)
131132
{
132-
return size == 64 ? CQE_SIZE_64 : CQE_SIZE_128;
133+
return padding_128_en ? CQE_SIZE_128_PAD :
134+
size == 64 ? CQE_SIZE_64 : CQE_SIZE_128;
133135
}
134136

135137
static inline void mlx5_cq_set_ci(struct mlx5_core_cq *cq)

‎include/uapi/rdma/mlx5-abi.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ struct mlx5_ib_striding_rq_caps {
206206
enum mlx5_ib_query_dev_resp_flags {
207207
/* Support 128B CQE compression */
208208
MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_COMP = 1 << 0,
209+
MLX5_IB_QUERY_DEV_RESP_FLAGS_CQE_128B_PAD = 1 << 1,
209210
};
210211

211212
struct mlx5_ib_query_device_resp {
@@ -221,13 +222,17 @@ struct mlx5_ib_query_device_resp {
221222
struct mlx5_ib_striding_rq_caps striding_rq_caps;
222223
};
223224

225+
enum mlx5_ib_create_cq_flags {
226+
MLX5_IB_CREATE_CQ_FLAGS_CQE_128B_PAD = 1 << 0,
227+
};
228+
224229
struct mlx5_ib_create_cq {
225230
__u64 buf_addr;
226231
__u64 db_addr;
227232
__u32 cqe_size;
228233
__u8 cqe_comp_en;
229234
__u8 cqe_comp_res_format;
230-
__u16 reserved; /* explicit padding (optional on i386) */
235+
__u16 flags;
231236
};
232237

233238
struct mlx5_ib_create_cq_resp {

0 commit comments

Comments
 (0)