[PATCH rdma-core 6/6] mlx5: Add custom allocation support for SRQ buffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add custom allocation support for SRQ buffer by extending the internal
allocation flow to consider this option.

As part of this change other options that were missed as of "extern
allocator" became applicable as well.

Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx>
---
 providers/mlx5/mlx5.h   |  3 ++-
 providers/mlx5/mlx5dv.h |  1 +
 providers/mlx5/srq.c    | 25 ++++++++++++++++++++-----
 providers/mlx5/verbs.c  | 10 +++++-----
 4 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/providers/mlx5/mlx5.h b/providers/mlx5/mlx5.h
index 9a5cd6b..953abe2 100644
--- a/providers/mlx5/mlx5.h
+++ b/providers/mlx5/mlx5.h
@@ -71,6 +71,7 @@ enum {
 #define MLX5_QP_PREFIX "MLX_QP"
 #define MLX5_MR_PREFIX "MLX_MR"
 #define MLX5_RWQ_PREFIX "MLX_RWQ"
+#define MLX5_SRQ_PREFIX "MLX_SRQ"
 #define MLX5_MAX_LOG2_CONTIG_BLOCK_SIZE 23
 #define MLX5_MIN_LOG2_CONTIG_BLOCK_SIZE 12
 
@@ -863,7 +864,7 @@ int mlx5_query_srq(struct ibv_srq *srq,
 			   struct ibv_srq_attr *attr);
 int mlx5_destroy_srq(struct ibv_srq *srq);
 int mlx5_alloc_srq_buf(struct ibv_context *context, struct mlx5_srq *srq,
-		       uint32_t nwr);
+		       uint32_t nwr, struct ibv_pd *pd);
 void mlx5_complete_odp_fault(struct mlx5_srq *srq, int ind);
 void mlx5_free_srq_wqe(struct mlx5_srq *srq, int ind);
 int mlx5_post_srq_recv(struct ibv_srq *ibsrq,
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index ac291eb..1f49352 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -63,6 +63,7 @@ extern "C" {
 #define MLX5DV_RES_TYPE_QP ((uint64_t)RDMA_DRIVER_MLX5 << 32 | 1)
 #define MLX5DV_RES_TYPE_RWQ ((uint64_t)RDMA_DRIVER_MLX5 << 32 | 2)
 #define MLX5DV_RES_TYPE_DBR ((uint64_t)RDMA_DRIVER_MLX5 << 32 | 3)
+#define MLX5DV_RES_TYPE_SRQ ((uint64_t)RDMA_DRIVER_MLX5 << 32 | 4)
 
 enum {
 	MLX5_RCV_DBR	= 0,
diff --git a/providers/mlx5/srq.c b/providers/mlx5/srq.c
index 1c15656..e9568c6 100644
--- a/providers/mlx5/srq.c
+++ b/providers/mlx5/srq.c
@@ -250,13 +250,14 @@ static void set_srq_buf_ll(struct mlx5_srq *srq, int start, int end)
 }
 
 int mlx5_alloc_srq_buf(struct ibv_context *context, struct mlx5_srq *srq,
-		       uint32_t max_wr)
+		       uint32_t max_wr, struct ibv_pd *pd)
 {
 	int size;
 	int buf_size;
 	struct mlx5_context	   *ctx;
 	uint32_t orig_max_wr = max_wr;
 	bool have_wq = true;
+	enum mlx5_alloc_type alloc_type;
 
 	ctx = to_mctx(context);
 
@@ -296,11 +297,25 @@ int mlx5_alloc_srq_buf(struct ibv_context *context, struct mlx5_srq *srq,
 	srq->max = align_queue_size(max_wr);
 	buf_size = srq->max * size;
 
-	if (mlx5_alloc_buf(&srq->buf, buf_size,
-			   to_mdev(context->device)->page_size))
+	mlx5_get_alloc_type(ctx, pd, MLX5_SRQ_PREFIX, &alloc_type,
+			    MLX5_ALLOC_TYPE_ANON);
+
+	if (alloc_type == MLX5_ALLOC_TYPE_CUSTOM) {
+		srq->buf.mparent_domain = to_mparent_domain(pd);
+		srq->buf.req_alignment = to_mdev(context->device)->page_size;
+		srq->buf.resource_type = MLX5DV_RES_TYPE_SRQ;
+	}
+
+	if (mlx5_alloc_prefered_buf(ctx,
+				    &srq->buf, buf_size,
+				    to_mdev(context->device)->page_size,
+				    alloc_type,
+				    MLX5_SRQ_PREFIX))
 		return -1;
 
-	memset(srq->buf.buf, 0, buf_size);
+	if (srq->buf.type != MLX5_ALLOC_TYPE_CUSTOM)
+		memset(srq->buf.buf, 0, buf_size);
+
 	srq->head = 0;
 	srq->tail = align_queue_size(orig_max_wr + 1) - 1;
 	if (have_wq)  {
@@ -313,7 +328,7 @@ int mlx5_alloc_srq_buf(struct ibv_context *context, struct mlx5_srq *srq,
 
 	srq->wrid = malloc(srq->max * sizeof(*srq->wrid));
 	if (!srq->wrid) {
-		mlx5_free_buf(&srq->buf);
+		mlx5_free_actual_buf(ctx, &srq->buf);
 		return -1;
 	}
 
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index 1e026af..786a75e 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -1023,7 +1023,7 @@ struct ibv_srq *mlx5_create_srq(struct ibv_pd *pd,
 	srq->max_gs  = attr->attr.max_sge;
 	srq->counter = 0;
 
-	if (mlx5_alloc_srq_buf(pd->context, srq, attr->attr.max_wr)) {
+	if (mlx5_alloc_srq_buf(pd->context, srq, attr->attr.max_wr, pd)) {
 		fprintf(stderr, "%s-%d:\n", __func__, __LINE__);
 		goto err;
 	}
@@ -1082,7 +1082,7 @@ err_db:
 
 err_free:
 	free(srq->wrid);
-	mlx5_free_buf(&srq->buf);
+	mlx5_free_actual_buf(ctx, &srq->buf);
 
 err:
 	free(srq);
@@ -1130,7 +1130,7 @@ int mlx5_destroy_srq(struct ibv_srq *srq)
 		mlx5_clear_srq(ctx, msrq->srqn);
 
 	mlx5_free_db(ctx, msrq->db, srq->pd, msrq->custom_db);
-	mlx5_free_buf(&msrq->buf);
+	mlx5_free_actual_buf(ctx, &msrq->buf);
 	free(msrq->tm_list);
 	free(msrq->wrid);
 	free(msrq->op);
@@ -2890,7 +2890,7 @@ struct ibv_srq *mlx5_create_srq_ex(struct ibv_context *context,
 	msrq->max_gs  = attr->attr.max_sge;
 	msrq->counter = 0;
 
-	if (mlx5_alloc_srq_buf(context, msrq, attr->attr.max_wr)) {
+	if (mlx5_alloc_srq_buf(context, msrq, attr->attr.max_wr, attr->pd)) {
 		fprintf(stderr, "%s-%d:\n", __func__, __LINE__);
 		goto err;
 	}
@@ -2998,7 +2998,7 @@ err_free_db:
 
 err_free:
 	free(msrq->wrid);
-	mlx5_free_buf(&msrq->buf);
+	mlx5_free_actual_buf(ctx, &msrq->buf);
 
 err:
 	free(msrq);
-- 
1.8.3.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux