libhns: Add support for Dynamic Context Attachment
v2 cover libhns: Add support for Dynamic Context Attachment
The HIP09 introduces the DCA(Dynamic Context Attachment) feature which supports many RC QPs to share the WQE buffer in a memory pool. If a QP enables DCA feature, the WQE's buffer will not be allocated when creating but when the users start to post WRs. This will reduce the memory consumption when there are too many QPs are inactive.
For more detailed information, please refer to the man pages provided by the last patch of this series.
This series is associated with the kernel one "RDMA/hns: Add support for Dynamic Context Attachment", you can review it at:
https://patchwork.kernel.org/project/linux-rdma/cover/[email protected]/
Changes since v1:
- Add direct verbs to set the parameters about size that used to
configuring DCA.
- Add man pages to explain what is DCA, how does it works and how to use
it.
- Link: https://patchwork.kernel.org/project/linux-rdma/cover/[email protected]/
Weihang Li (1):
Update kernel headers
Xi Wang (5):
libhns: Introduce DCA for RC QP
libhns: Add support for shrinking DCA memory pool
libhns: Add support for attaching QP's WQE buffer
libhns: Add direct verb to support config DCA memory pool
libhns: Add man pages to introduce DCA feature
CMakeLists.txt | 1 + debian/ibverbs-providers.install | 1 + debian/ibverbs-providers.lintian-overrides | 4 +- debian/ibverbs-providers.symbols | 5 + debian/libibverbs-dev.install | 6 + kernel-headers/rdma/hns-abi.h | 64 +++++ libibverbs/cmd_qp.c | 3 +- libibverbs/man/ibv_create_qp_ex.3 | 1 + libibverbs/verbs.h | 1 + providers/hns/CMakeLists.txt | 9 +- providers/hns/hns_roce_u.c | 96 +++++++ providers/hns/hns_roce_u.h | 44 ++++ providers/hns/hns_roce_u_abi.h | 1 + providers/hns/hns_roce_u_buf.c | 387 +++++++++++++++++++++++++++++ providers/hns/hns_roce_u_hw_v2.c | 138 +++++++++- providers/hns/hns_roce_u_hw_v2.h | 7 + providers/hns/hns_roce_u_verbs.c | 44 +++- providers/hns/hnsdv.h | 44 ++++ providers/hns/libhns.map | 8 + providers/hns/man/CMakeLists.txt | 6 + providers/hns/man/hns_dca.7.md | 35 +++ providers/hns/man/hnsdv.7.md | 34 +++ providers/hns/man/hnsdv_is_supported.3.md | 39 +++ providers/hns/man/hnsdv_open_device.3.md | 70 ++++++ redhat/rdma-core.spec | 5 + suse/rdma-core.spec | 19 ++ 26 files changed, 1051 insertions(+), 21 deletions(-) create mode 100644 providers/hns/hnsdv.h create mode 100644 providers/hns/libhns.map create mode 100644 providers/hns/man/CMakeLists.txt create mode 100644 providers/hns/man/hns_dca.7.md create mode 100644 providers/hns/man/hnsdv.7.md create mode 100644 providers/hns/man/hnsdv_is_supported.3.md create mode 100644 providers/hns/man/hnsdv_open_device.3.md
Signature · 1 line
2.8.1
RFC PATCH v2 1/6 Update kernel headers
To commit ?? ("RDMA/hns: Add method to query WQE buffer's address").
--- kernel-headers/rdma/hns-abi.h | 64 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
kernel-headers/rdma/hns-abi.h +64 -0
@@ -77,19 +77,83 @@ enum hns_roce_qp_cap_flags {HNS_ROCE_QP_CAP_RQ_RECORD_DB =1 <<0 ,HNS_ROCE_QP_CAP_SQ_RECORD_DB =1 <<1 ,HNS_ROCE_QP_CAP_OWNER_DB =1 <<2 , + HNS_ROCE_QP_CAP_DCA = 1 << 4, };struct hns_roce_ib_create_qp_resp {__aligned_u64 cap_flags; }; +enum { +HNS_ROCE_CAP_FLAG_DCA_MODE =1 <<15 , +}; +struct hns_roce_ib_alloc_ucontext_resp {__u32 qp_tab_size;__u32 cqe_size; +__aligned_u64 cap_flags; };struct hns_roce_ib_alloc_pd_resp {__u32 pdn; }; +#define UVERBS_ID_NS_MASK 0xF000 +#define UVERBS_ID_NS_SHIFT 12 + +enum hns_ib_objects { +HNS_IB_OBJECT_DCA_MEM = (1U <<UVERBS_ID_NS_SHIFT ), +}; + +enum hns_ib_dca_mem_methods { +HNS_IB_METHOD_DCA_MEM_REG = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_METHOD_DCA_MEM_DEREG , +HNS_IB_METHOD_DCA_MEM_SHRINK , +HNS_IB_METHOD_DCA_MEM_ATTACH , +HNS_IB_METHOD_DCA_MEM_DETACH , +HNS_IB_METHOD_DCA_MEM_QUERY , +}; + +enum hns_ib_dca_mem_reg_attrs { +HNS_IB_ATTR_DCA_MEM_REG_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_ATTR_DCA_MEM_REG_LEN , +HNS_IB_ATTR_DCA_MEM_REG_ADDR , +HNS_IB_ATTR_DCA_MEM_REG_KEY , +}; + +enum hns_ib_dca_mem_dereg_attrs { +HNS_IB_ATTR_DCA_MEM_DEREG_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +}; + +enum hns_ib_dca_mem_shrink_attrs { +HNS_IB_ATTR_DCA_MEM_SHRINK_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_ATTR_DCA_MEM_SHRINK_RESERVED_SIZE , +HNS_IB_ATTR_DCA_MEM_SHRINK_OUT_FREE_KEY , +HNS_IB_ATTR_DCA_MEM_SHRINK_OUT_FREE_MEMS , +}; + +#define HNS_IB_ATTACH_FLAGS_NEW_BUFFER 1U + +enum hns_ib_dca_mem_attach_attrs { +HNS_IB_ATTR_DCA_MEM_ATTACH_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_ATTR_DCA_MEM_ATTACH_SQ_OFFSET , +HNS_IB_ATTR_DCA_MEM_ATTACH_SGE_OFFSET , +HNS_IB_ATTR_DCA_MEM_ATTACH_RQ_OFFSET , +HNS_IB_ATTR_DCA_MEM_ATTACH_OUT_ALLOC_FLAGS , +HNS_IB_ATTR_DCA_MEM_ATTACH_OUT_ALLOC_PAGES , +}; + +enum hns_ib_dca_mem_detach_attrs { +HNS_IB_ATTR_DCA_MEM_DETACH_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_ATTR_DCA_MEM_DETACH_SQ_INDEX , +}; + +enum hns_ib_dca_mem_query_attrs { +HNS_IB_ATTR_DCA_MEM_QUERY_HANDLE = (1U <<UVERBS_ID_NS_SHIFT ), +HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX , +HNS_IB_ATTR_DCA_MEM_QUERY_OUT_KEY , +HNS_IB_ATTR_DCA_MEM_QUERY_OUT_OFFSET , +HNS_IB_ATTR_DCA_MEM_QUERY_OUT_PAGE_COUNT , +}; +#endif /* HNS_ABI_USER_H */
Signature · 1 line
2.8.1
RFC PATCH v2 2/6 libhns: Introduce DCA for RC QP
In reply to Weihang LiFrom: Xi Wang <[email protected]>
The HIP09 introduces the DCA(Dynamic context attachment) feature which supports many RC QPs to share the WQE buffer in a memory pool, this will reduce the memory consumption when there are too many QPs inactive.
This patch wraps two functions for adding buffers to memory pool and removing buffers from memory pool by calling ib cmd implemented in hns kernel driver.
If a QP enables DCA feature, the WQE's buffer will be attached to the memory pool when the users start to post WRs and be detached when all CQEs has been polled.
--- providers/hns/hns_roce_u.c | 41 ++++++++++++ providers/hns/hns_roce_u.h | 18 ++++++ providers/hns/hns_roce_u_buf.c | 137 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+)
providers/hns/hns_roce_u.c +41 -0
@@ -89,6 +89,40 @@ static const struct verbs_context_ops hns_common_ops = { .destroy_ah = hns_roce_u_destroy_ah, }; +static int init_dca_context (struct hns_roce_context *ctx,int page_size) +{ +struct hns_roce_dca_ctx *dca_ctx = &ctx->dca_ctx; +int ret; + +if (!(ctx->cap_flags &HNS_ROCE_CAP_FLAG_DCA_MODE )) +return 0 ; + +list_head_init (&dca_ctx->mem_list); + ret =pthread_spin_init (&dca_ctx->lock,PTHREAD_PROCESS_PRIVATE ); +if (ret) +return ret; + + dca_ctx->unit_size = page_size *HNS_DCA_DEFAULT_UNIT_PAGES ; + dca_ctx->max_size =HNS_DCA_MAX_MEM_SIZE ; + dca_ctx->mem_cnt =0 ; + +return 0 ; +} + +static void uninit_dca_context (struct hns_roce_context *ctx) +{ +struct hns_roce_dca_ctx *dca_ctx = &ctx->dca_ctx; + +if (!(ctx->cap_flags &HNS_ROCE_CAP_FLAG_DCA_MODE )) +return ; + +pthread_spin_lock (&dca_ctx->lock); +hns_roce_cleanup_dca_mem (ctx); +pthread_spin_unlock (&dca_ctx->lock); + +pthread_spin_destroy (&dca_ctx->lock); +} +static struct verbs_context *hns_roce_alloc_context (struct ibv_device *ibdev,int cmd_fd,void *private_data)
@@ -110,6 +144,8 @@ static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev, &resp.ibv_resp, sizeof(resp))) goto err_free; + context->cap_flags = resp.cap_flags; + context->num_qps = resp.qp_tab_size; context->qp_table_shift =ffs (context->num_qps) -1 -HNS_ROCE_QP_TABLE_BITS ;
@@ -162,6 +198,9 @@ static struct verbs_context *hns_roce_alloc_context(struct ibv_device *ibdev,verbs_set_ops (&context->ibv_ctx, &hns_common_ops);verbs_set_ops (&context->ibv_ctx, &hr_dev->u_hw->hw_ops); +if (init_dca_context (context, hr_dev->page_size)) + goto db_free; +return &context->ibv_ctx; db_free:
@@ -183,6 +222,8 @@ static void hns_roce_free_context(struct ibv_context *ibctx)if (hr_dev->hw_version ==HNS_ROCE_HW_VER1 )munmap (context->cq_tptr_base,HNS_ROCE_CQ_DB_BUF_SIZE ); +uninit_dca_context (context); +verbs_uninit_context (&context->ibv_ctx);free (context); }
providers/hns/hns_roce_u.h +18 -0
@@ -142,8 +142,21 @@ struct hns_roce_db_page {bitmap *bitmap; }; +#define HNS_DCA_MAX_MEM_SIZE ~0UL +#define HNS_DCA_DEFAULT_UNIT_PAGES 16 + +struct hns_roce_dca_ctx { +struct list_head mem_list; +pthread_spinlock_t lock; +uint64_t max_size; +uint64_t curr_size; +int mem_cnt; +unsigned int unit_size; +}; +struct hns_roce_context {struct verbs_context ibv_ctx; +uint32_t cap_flags;void *uar;pthread_spinlock_t uar_lock;
@@ -167,6 +180,8 @@ struct hns_roce_context {unsigned int max_sge;int max_cqe;unsigned int cqe_size; + +struct hns_roce_dca_ctx dca_ctx; };struct hns_roce_pd {
@@ -395,6 +410,9 @@ void hns_roce_free_buf(struct hns_roce_buf *buf);void hns_roce_free_qp_buf (struct hns_roce_qp *qp,struct hns_roce_context *ctx); +void hns_roce_cleanup_dca_mem (struct hns_roce_context *ctx); +int hns_roce_add_dca_mem (struct hns_roce_context *ctx,uint32_t size); +void hns_roce_init_qp_indices (struct hns_roce_qp *qp);extern const struct hns_roce_u_hw hns_roce_u_hw_v1;
providers/hns/hns_roce_u_buf.c +137 -0
140 lines not on this page · raw message
Signature · 1 line
2.8.1
RFC PATCH v2 3/6 libhns: Add support for shrinking DCA memory pool
In reply to Weihang LiFrom: Xi Wang <[email protected]>
The QP's WQE buffer may be detached after QP is modified or CQE is polled, and the state of DCA mem object may be changed as clean for no QP is using it. So shrink the clean DCA mem from the memory pool and destroy the DCA mem's buffer to reduce the memory consumption.
--- providers/hns/hns_roce_u.h | 2 + providers/hns/hns_roce_u_buf.c | 96 ++++++++++++++++++++++++++++++++++++++++ providers/hns/hns_roce_u_hw_v2.c | 7 +++ 3 files changed, 105 insertions(+)
providers/hns/hns_roce_u.h +2 -0
@@ -149,6 +149,7 @@ struct hns_roce_dca_ctx {struct list_head mem_list;pthread_spinlock_t lock;uint64_t max_size; +uint64_t min_size;uint64_t curr_size;int mem_cnt;unsigned int unit_size;
@@ -410,6 +411,7 @@ void hns_roce_free_buf(struct hns_roce_buf *buf);void hns_roce_free_qp_buf (struct hns_roce_qp *qp,struct hns_roce_context *ctx); +void hns_roce_shrink_dca_mem (struct hns_roce_context *ctx);void hns_roce_cleanup_dca_mem (struct hns_roce_context *ctx);int hns_roce_add_dca_mem (struct hns_roce_context *ctx,uint32_t size);
providers/hns/hns_roce_u_buf.c +96 -0
111 lines not on this page · raw message
providers/hns/hns_roce_u_hw_v2.c +7 -0
@@ -651,6 +651,10 @@ static int hns_roce_u_v2_poll_cq(struct ibv_cq *ibvcq, int ne,pthread_spin_unlock (&cq->lock); +/* Try to shrink the DCA mem */ +if (ctx->dca_ctx.mem_cnt >0 ) +hns_roce_shrink_dca_mem (ctx); +return err ==V2_CQ_POLL_ERR ? err : npolled; }
@@ -1478,6 +1482,9 @@ static int hns_roce_u_v2_destroy_qp(struct ibv_qp *ibqp)free (qp); +if (ctx->dca_ctx.mem_cnt >0 ) +hns_roce_shrink_dca_mem (ctx); +return ret; }
Signature · 1 line
2.8.1
RFC PATCH v2 4/6 libhns: Add support for attaching QP's WQE buffer
In reply to Weihang LiFrom: Xi Wang <[email protected]>
If a uQP works in DCA mode, the WQE's buffer will be split as many blocks and be stored into a list. The blocks are allocated from the DCA's memory pool before posting WRs and are dropped when the QP's CI is equal to PI after polling CQ.
--- providers/hns/hns_roce_u.h | 24 +++++- providers/hns/hns_roce_u_buf.c | 156 ++++++++++++++++++++++++++++++++++++++- providers/hns/hns_roce_u_hw_v2.c | 131 +++++++++++++++++++++++++++++--- providers/hns/hns_roce_u_hw_v2.h | 7 ++ providers/hns/hns_roce_u_verbs.c | 32 ++++++-- 5 files changed, 332 insertions(+), 18 deletions(-)
providers/hns/hns_roce_u.h +23 -1
@@ -119,6 +119,12 @@ struct hns_roce_device {int hw_version; }; +struct hns_roce_buf_list { +void **bufs; +unsigned int max_cnt; +unsigned int shift; +}; +struct hns_roce_buf {void *buf;unsigned int length;
@@ -268,9 +274,20 @@ struct hns_roce_rinl_buf {unsigned int wqe_cnt; }; +struct hns_roce_dca_attach_attr { +uint32_t sq_offset; +uint32_t sge_offset; +uint32_t rq_offset; +}; + +struct hns_roce_dca_detach_attr { +uint32_t sq_index; +}; +struct hns_roce_qp {struct verbs_qp verbs_qp;struct hns_roce_buf buf; +struct hns_roce_buf_list page_list;int max_inline_data;int buf_size;unsigned int sq_signal_bits;
@@ -316,6 +333,7 @@ struct hns_roce_u_hw {* minimum page size. */ #define hr_hw_page_align (x) align(x, HNS_HW_PAGE_SIZE) +#define hr_hw_page_count (x) (hr_hw_page_align(x) / HNS_HW_PAGE_SIZE)static inline unsigned int to_hr_hem_entries_size (int count,int buf_shift) {
@@ -411,9 +429,13 @@ void hns_roce_free_buf(struct hns_roce_buf *buf);void hns_roce_free_qp_buf (struct hns_roce_qp *qp,struct hns_roce_context *ctx); +int hns_roce_attach_dca_mem (struct hns_roce_context *ctx,uint32_t handle, +struct hns_roce_dca_attach_attr *attr, +uint32_t size,struct hns_roce_buf_list *buf_list); +void hns_roce_detach_dca_mem (struct hns_roce_context *ctx,uint32_t handle, +struct hns_roce_dca_detach_attr *attr);void hns_roce_shrink_dca_mem (struct hns_roce_context *ctx);void hns_roce_cleanup_dca_mem (struct hns_roce_context *ctx); -int hns_roce_add_dca_mem (struct hns_roce_context *ctx,uint32_t size);void hns_roce_init_qp_indices (struct hns_roce_qp *qp);
providers/hns/hns_roce_u_buf.c +155 -1
171 lines not on this page · raw message
providers/hns/hns_roce_u_hw_v2.c +121 -10
202 lines not on this page · raw message
providers/hns/hns_roce_u_hw_v2.h +7 -0
@@ -250,6 +250,13 @@ struct hns_roce_rc_sq_wqe {#define RC_SQ_WQE_BYTE_4_RDMA_WRITE_S 22 +#define RC_SQ_WQE_BYTE_4_SQPN_L_W 2 +#define RC_SQ_WQE_BYTE_4_SQPN_L_S 5 +#define RC_SQ_WQE_BYTE_4_SQPN_L_M GENMASK(5, 2) + +#define RC_SQ_WQE_BYTE_4_SQPN_H_S 13 +#define RC_SQ_WQE_BYTE_4_SQPN_H_M GENMASK(18, 13) +#define RC_SQ_WQE_BYTE_16_XRC_SRQN_S 0#define RC_SQ_WQE_BYTE_16_XRC_SRQN_M \ (((1UL << 24) - 1) << RC_SQ_WQE_BYTE_16_XRC_SRQN_S)
providers/hns/hns_roce_u_verbs.c +26 -6
@@ -688,6 +688,14 @@ static int calc_qp_buff_size(struct hns_roce_device *hr_dev,return 0 ; } +static inline bool check_qp_support_dca (bool pool_en,enum ibv_qp_type qp_type) +{ +if (pool_en && (qp_type ==IBV_QPT_RC || qp_type ==IBV_QPT_XRC_SEND )) +return true; + +return false; +} +static void qp_free_wqe (struct hns_roce_qp *qp) {qp_free_recv_inl_buf (qp);
@@ -699,8 +707,8 @@ static void qp_free_wqe(struct hns_roce_qp *qp)hns_roce_free_buf (&qp->buf); } -static int qp_alloc_wqe (struct ibv_qp_cap *cap,struct hns_roce_qp *qp, -struct hns_roce_context *ctx) +static int qp_alloc_wqe (struct ibv_qp_init_attr_ex *attr, +struct hns_roce_qp *qp,struct hns_roce_context *ctx) {struct hns_roce_device *hr_dev =to_hr_dev (ctx->ibv_ctx.context.device);
@@ -718,12 +726,24 @@ static int qp_alloc_wqe(struct ibv_qp_cap *cap, struct hns_roce_qp *qp, }if (qp->rq_rinl_buf.wqe_cnt) { -if (qp_alloc_recv_inl_buf (cap, qp)) +if (qp_alloc_recv_inl_buf (&attr->cap, qp)) goto err_alloc; } -if (hns_roce_alloc_buf (&qp->buf, qp->buf_size,HNS_HW_PAGE_SIZE )) - goto err_alloc; +if (check_qp_support_dca (ctx->dca_ctx.max_size !=0 , attr->qp_type)) { +/* when DCA is enabled, use a buffer list to store page addr */ + qp->buf.buf =NULL ; + qp->page_list.max_cnt =hr_hw_page_count (qp->buf_size); + qp->page_list.shift =HNS_HW_PAGE_SHIFT ; + qp->page_list.bufs =calloc (qp->page_list.max_cnt, +sizeof (void *)); +if (!qp->page_list.bufs) + goto err_alloc; + }else { +if (hns_roce_alloc_buf (&qp->buf, qp->buf_size, +HNS_HW_PAGE_SIZE )) + goto err_alloc; + }return 0 ;
@@ -928,7 +948,7 @@ static int hns_roce_alloc_qp_buf(struct ibv_qp_init_attr_ex *attr, pthread_spin_init(&qp->rq.lock, PTHREAD_PROCESS_PRIVATE))return -ENOMEM ; - ret =qp_alloc_wqe (&attr->cap, qp, ctx); + ret =qp_alloc_wqe (attr, qp, ctx);if (ret)return ret;
Signature · 1 line
2.8.1
RFC PATCH v2 5/6 libhns: Add direct verb to support config DCA memory pool
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Add a direct verb 'hnsdv_open_device' to config DCA memory pool, and append 'IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH' for creating a DCA QP.
--- debian/ibverbs-providers.install | 1 + debian/ibverbs-providers.lintian-overrides | 4 +- debian/ibverbs-providers.symbols | 5 +++ debian/libibverbs-dev.install | 4 ++ libibverbs/cmd_qp.c | 3 +- libibverbs/verbs.h | 1 + providers/hns/CMakeLists.txt | 9 +++- providers/hns/hns_roce_u.c | 71 ++++++++++++++++++++++++++---- providers/hns/hns_roce_u.h | 4 +- providers/hns/hns_roce_u_abi.h | 1 + providers/hns/hns_roce_u_verbs.c | 18 ++++++-- providers/hns/hnsdv.h | 44 ++++++++++++++++++ providers/hns/libhns.map | 8 ++++ redhat/rdma-core.spec | 3 ++ suse/rdma-core.spec | 19 ++++++++ 15 files changed, 178 insertions(+), 17 deletions(-) create mode 100644 providers/hns/hnsdv.h create mode 100644 providers/hns/libhns.map
debian/ibverbs-providers.install +1 -0
@@ -1,5 +1,6 @@ etc/libibverbs.d/ usr/lib/*/libefa.so.* usr/lib/*/libibverbs/lib*-rdmav*.so +usr/lib/*/libhns.so.* usr/lib/*/libmlx4.so.* usr/lib/*/libmlx5.so.*
debian/ibverbs-providers.lintian-overrides +2 -2
@@ -1,2 +1,2 @@ -# libefa, libmlx4 and libmlx5 are ibverbs provider that provides more functions. -ibverbs-providers: package-name-doesnt-match-sonames libefa1 libmlx4-1 libmlx5-1 +# libefa, libhns, libmlx4 and libmlx5 are ibverbs provider that provides more functions. +ibverbs-providers: package-name-doesnt-match-sonames libefa1 libhns-1 libmlx4-1 libmlx5-1
debian/ibverbs-providers.symbols +5 -0
@@ -132,3 +132,8 @@ libefa.so.1 ibverbs-providers #MINVER# efadv_create_qp_ex@EFA_1.1 26 efadv_query_device@EFA_1.1 26 efadv_query_ah@EFA_1.1 26 +libhns.so.1 ibverbs-providers #MINVER# +* Build-Depends-Package: libibverbs-dev + HNS_1.0@HNS_1.0 34 + hnsdv_is_supported@HNS_1.0 34 + hnsdv_open_device@HNS_1.0 34
debian/libibverbs-dev.install +4 -0
@@ -1,5 +1,6 @@ usr/include/infiniband/arch.h usr/include/infiniband/efadv.h +usr/include/infiniband/hnsdv.h usr/include/infiniband/ib_user_ioctl_verbs.h usr/include/infiniband/mlx4dv.h usr/include/infiniband/mlx5_api.h
@@ -14,6 +15,8 @@ usr/include/infiniband/verbs_api.h usr/lib/*/lib*-rdmav*.a usr/lib/*/libefa.a usr/lib/*/libefa.so +usr/lib/*/libhns.a +usr/lib/*/libhns.so usr/lib/*/libibverbs*.so usr/lib/*/libibverbs.a usr/lib/*/libmlx4.a
@@ -21,6 +24,7 @@ usr/lib/*/libmlx4.so usr/lib/*/libmlx5.a usr/lib/*/libmlx5.so usr/lib/*/pkgconfig/libefa.pc +usr/lib/*/pkgconfig/libhns.pc usr/lib/*/pkgconfig/libibverbs.pc usr/lib/*/pkgconfig/libmlx4.pc usr/lib/*/pkgconfig/libmlx5.pc
libibverbs/cmd_qp.c +2 -1
@@ -38,7 +38,8 @@ enum {IBV_QP_CREATE_SCATTER_FCS |IBV_QP_CREATE_CVLAN_STRIPPING |IBV_QP_CREATE_SOURCE_QPN | - IBV_QP_CREATE_PCI_WRITE_END_PADDING +IBV_QP_CREATE_PCI_WRITE_END_PADDING | + IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH };
libibverbs/verbs.h +1 -0
@@ -918,6 +918,7 @@ enum ibv_qp_create_flags {IBV_QP_CREATE_CVLAN_STRIPPING =1 <<9 ,IBV_QP_CREATE_SOURCE_QPN =1 <<10 ,IBV_QP_CREATE_PCI_WRITE_END_PADDING =1 <<11 , + IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH = 1 << 13, }; enum ibv_qp_create_send_ops_flags {
providers/hns/CMakeLists.txt +8 -1
@@ -1,4 +1,5 @@ -rdma_provider(hns +rdma_shared_provider(hns libhns.map + 1 1.0.${PACKAGE_VERSION} hns_roce_u.c hns_roce_u_buf.c hns_roce_u_db.c
@@ -6,3 +7,9 @@ rdma_provider(hns hns_roce_u_hw_v2.c hns_roce_u_verbs.c ) + +publish_headers(infiniband + hnsdv.h +) + +rdma_pkg_config("hns" "libibverbs" "${CMAKE_THREAD_LIBS_INIT}")
providers/hns/hns_roce_u.c +63 -8
102 lines not on this page · raw message
providers/hns/hns_roce_u.h +3 -1
@@ -154,11 +154,11 @@ struct hns_roce_db_page {struct hns_roce_dca_ctx {struct list_head mem_list;pthread_spinlock_t lock; +uint32_t unit_size;uint64_t max_size;uint64_t min_size;uint64_t curr_size;int mem_cnt; -unsigned int unit_size; };struct hns_roce_context {
@@ -376,6 +376,8 @@ static inline struct hns_roce_ah *to_hr_ah(struct ibv_ah *ibv_ah) return container_of(ibv_ah, struct hns_roce_ah, ibv_ah); } +bool is_hns_dev (struct ibv_device *device); +int hns_roce_u_query_device (struct ibv_context *context,const struct ibv_query_device_ex_input *input,struct ibv_device_attr_ex *attr,size_t attr_size);
providers/hns/hns_roce_u_abi.h +1 -0
@@ -36,6 +36,7 @@#include <infiniband/kern-abi.h> #include <rdma/hns-abi.h> #include <kernel-abi/hns-abi.h> +#include "hnsdv.h" DECLARE_DRV_CMD (hns_roce_alloc_pd,IB_USER_VERBS_CMD_ALLOC_PD , empty, hns_roce_ib_alloc_pd_resp);
providers/hns/hns_roce_u_verbs.c +14 -4
@@ -542,7 +542,7 @@ int hns_roce_u_destroy_srq(struct ibv_srq *srq) }enum { -CREATE_QP_SUP_CREATE_FLAGS =0 , +CREATE_QP_SUP_CREATE_FLAGS =IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH , };enum {
@@ -688,10 +688,11 @@ static int calc_qp_buff_size(struct hns_roce_device *hr_dev,return 0 ; } -static inline bool check_qp_support_dca (bool pool_en,enum ibv_qp_type qp_type) +static inline bool check_qp_support_dca (bool pool_en,enum ibv_qp_type qp_type, +uint32_t create_flags) {if (pool_en && (qp_type ==IBV_QPT_RC || qp_type ==IBV_QPT_XRC_SEND )) -return true; +return !!(create_flags &IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH );return false; }
@@ -730,7 +731,8 @@ static int qp_alloc_wqe(struct ibv_qp_init_attr_ex *attr, goto err_alloc; } -if (check_qp_support_dca (ctx->dca_ctx.max_size !=0 , attr->qp_type)) { +if (check_qp_support_dca (ctx->dca_ctx.unit_size !=0 , + attr->qp_type, attr->create_flags)) {/* when DCA is enabled, use a buffer list to store page addr */ qp->buf.buf =NULL ; qp->page_list.max_cnt =hr_hw_page_count (qp->buf_size);
@@ -901,6 +903,14 @@ static int qp_exec_create_cmd(struct ibv_qp_init_attr_ex *attr,struct hns_roce_create_qp_ex cmd_ex = {};int ret; +/* +* When the kernel driver handling the command , whether to enable the +* DCA mode of the user QP depends on whether the cmd.buf_addr is NULL +* instead of whether the DCA bit of attr->create_flags is set, so +* clear this bit before sending the command. +*/ + attr->create_flags &= ~IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH ; + cmd_ex.sdb_addr = (uintptr_t )qp->sdb; cmd_ex.db_addr = (uintptr_t )qp->rdb; cmd_ex.buf_addr = (uintptr_t )qp->buf.buf;
providers/hns/hnsdv.h new file +44 -0
44 lines not on this page · raw message
providers/hns/libhns.map new file +8 -0
@@ -0,0 +1,8 @@ +/* Export symbols should be added below according to + Documentation/versioning.md document. */ +HNS_1.0 { + global: + hnsdv_is_supported; + hnsdv_open_device; + local: *; +};
redhat/rdma-core.spec +3 -0
@@ -151,6 +151,8 @@ Provides: libefa = %{version}-%{release} Obsoletes: libefa < %{version}-%{release} Provides: libhfi1 = %{version}-%{release} Obsoletes: libhfi1 < %{version}-%{release} +Provides: libhns = %{version}-%{release} +Obsoletes: libhns < %{version}-%{release} Provides: libi40iw = %{version}-%{release} Obsoletes: libi40iw < %{version}-%{release} Provides: libipathverbs = %{version}-%{release}
@@ -563,6 +565,7 @@ fi %dir %{_sysconfdir}/libibverbs.d %dir %{_libdir}/libibverbs %{_libdir}/libefa.so.* +%{_libdir}/libhns.so.* %{_libdir}/libibverbs*.so.* %{_libdir}/libibverbs/*.so %{_libdir}/libmlx5.so.*
suse/rdma-core.spec +19 -0
@@ -30,6 +30,7 @@ License: GPL-2.0-only OR BSD-2-Clause Group: Productivity/Networking/Other %define efa_so_major 1 +%define hns_so_major 1 %define verbs_so_major 1 %define rdmacm_so_major 1 %define umad_so_major 3
@@ -39,6 +40,7 @@ Group: Productivity/Networking/Other %define mad_major 5 %define efa_lname libefa%{efa_so_major} +%define hns_lname libhns%{hns_so_major} %define verbs_lname libibverbs%{verbs_so_major} %define rdmacm_lname librdmacm%{rdmacm_so_major} %define umad_lname libibumad%{umad_so_major}
@@ -145,6 +147,7 @@ Requires: %{umad_lname} = %{version}-%{release} Requires: %{verbs_lname} = %{version}-%{release} %if 0%{?dma_coherent} Requires: %{efa_lname} = %{version}-%{release} +Requires: %{hns_lname} = %{version}-%{release} Requires: %{mlx4_lname} = %{version}-%{release} Requires: %{mlx5_lname} = %{version}-%{release} %endif
@@ -185,6 +188,7 @@ Requires: %{name}%{?_isa} = %{version}-%{release} Obsoletes: libcxgb4-rdmav2 < %{version}-%{release} Obsoletes: libefa-rdmav2 < %{version}-%{release} Obsoletes: libhfi1verbs-rdmav2 < %{version}-%{release} +Obsoletes: libhns-rdmav2 < %{version}-%{release} Obsoletes: libi40iw-rdmav2 < %{version}-%{release} Obsoletes: libipathverbs-rdmav2 < %{version}-%{release} Obsoletes: libmlx4-rdmav2 < %{version}-%{release}
@@ -194,6 +198,7 @@ Obsoletes: libocrdma-rdmav2 < %{version}-%{release} Obsoletes: librxe-rdmav2 < %{version}-%{release} %if 0%{?dma_coherent} Requires: %{efa_lname} = %{version}-%{release} +Requires: %{hns_lname} = %{version}-%{release} Requires: %{mlx4_lname} = %{version}-%{release} Requires: %{mlx5_lname} = %{version}-%{release} %endif
@@ -239,6 +244,13 @@ Group: System/Libraries %description -n %efa_lname This package contains the efa runtime library. +%package -n %hns_lname +Summary: HNS runtime library +Group: System/Libraries + +%description -n %hns_lname +This package contains the hns runtime library. + %package -n %mlx4_lname Summary: MLX4 runtime library Group: System/Libraries
@@ -477,6 +489,9 @@ rm -rf %{buildroot}/%{_sbindir}/srp_daemon.sh %post -n %efa_lname -p /sbin/ldconfig %postun -n %efa_lname -p /sbin/ldconfig +%post -n %hns_lname -p /sbin/ldconfig +%postun -n %hns_lname -p /sbin/ldconfig + %post -n %mlx4_lname -p /sbin/ldconfig %postun -n %mlx4_lname -p /sbin/ldconfig
@@ -659,6 +674,10 @@ rm -rf %{buildroot}/%{_sbindir}/srp_daemon.sh %defattr(-,root,root) %{_libdir}/libefa*.so.* +%files -n %hns_lname +%defattr(-,root,root) +%{_libdir}/libhns*.so.* + %files -n %mlx4_lname %defattr(-,root,root) %{_libdir}/libmlx4*.so.*
Signature · 1 line
2.8.1
Jason Gunthorpe
maintainerRe: [PATCH RFC v2 rdma-core 5/6] libhns: Add direct verb to support config DCA memory pool
libibverbs/verbs.h enum ibv_qp_create_flags { · line 922
Quoted 9 lines · Weihang Li
libibverbs/verbs.h +2
-0+++ b/libibverbs/verbs.h@@ -918,6 +918,7 @@ enum ibv_qp_create_flags {IBV_QP_CREATE_CVLAN_STRIPPING =1 <<9 ,IBV_QP_CREATE_SOURCE_QPN =1 <<10 ,IBV_QP_CREATE_PCI_WRITE_END_PADDING =1 <<11 , + IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH = 1 << 13, };
No, all the stuff related to these kinds of extensions must be in the hnsdv.h and can't be used with the normal APIs at all
Jason
Re: [PATCH RFC v2 rdma-core 5/6] libhns: Add direct verb to support config DCA memory pool
Quoted 14 lines · Jason Gunthorpe
libibverbs/verbs.h enum ibv_qp_create_flags { · line 922
Quoted 9 lines · Weihang Li
libibverbs/verbs.h +2
-0+++ b/libibverbs/verbs.h@@ -918,6 +918,7 @@ enum ibv_qp_create_flags {IBV_QP_CREATE_CVLAN_STRIPPING =1 <<9 ,IBV_QP_CREATE_SOURCE_QPN =1 <<10 ,IBV_QP_CREATE_PCI_WRITE_END_PADDING =1 <<11 , + IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH = 1 << 13, };No, all the stuff related to these kinds of extensions must be in the
hnsdv.hand can't be used with the normal APIs at all
Quoted 2 lines
Jason
OK, we will add a hnsdv_create_qp instead.
Thank you,
Weihang
RFC PATCH v2 6/6 libhns: Add man pages to introduce DCA feature
In reply to Weihang LiFrom: Xi Wang <[email protected]>
Document hns DCA feature and related direct verbs.
--- CMakeLists.txt | 1 + debian/ibverbs-providers.install | 2 +- debian/libibverbs-dev.install | 2 + libibverbs/man/ibv_create_qp_ex.3 | 1 + providers/hns/man/CMakeLists.txt | 6 +++ providers/hns/man/hns_dca.7.md | 35 ++++++++++++++++ providers/hns/man/hnsdv.7.md | 34 +++++++++++++++ providers/hns/man/hnsdv_is_supported.3.md | 39 +++++++++++++++++ providers/hns/man/hnsdv_open_device.3.md | 70 +++++++++++++++++++++++++++++++ redhat/rdma-core.spec | 2 + 10 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 providers/hns/man/CMakeLists.txt create mode 100644 providers/hns/man/hns_dca.7.md create mode 100644 providers/hns/man/hnsdv.7.md create mode 100644 providers/hns/man/hnsdv_is_supported.3.md create mode 100644 providers/hns/man/hnsdv_open_device.3.md
CMakeLists.txt +1 -0
@@ -666,6 +666,7 @@ add_subdirectory(providers/cxgb4) # NO SPARSE add_subdirectory(providers/efa) add_subdirectory(providers/efa/man) add_subdirectory(providers/hns) +add_subdirectory(providers/hns/man) add_subdirectory(providers/i40iw) # NO SPARSE add_subdirectory(providers/mlx4) add_subdirectory(providers/mlx4/man)
debian/ibverbs-providers.install +1 -1
@@ -1,6 +1,6 @@ etc/libibverbs.d/ usr/lib/*/libefa.so.* -usr/lib/*/libibverbs/lib*-rdmav*.so usr/lib/*/libhns.so.* +usr/lib/*/libibverbs/lib*-rdmav*.so usr/lib/*/libmlx4.so.* usr/lib/*/libmlx5.so.*
debian/libibverbs-dev.install +2 -0
@@ -29,11 +29,13 @@ usr/lib/*/pkgconfig/libibverbs.pc usr/lib/*/pkgconfig/libmlx4.pc usr/lib/*/pkgconfig/libmlx5.pc usr/share/man/man3/efadv_*.3 +usr/share/man/man3/hns*.3 usr/share/man/man3/ibv_* usr/share/man/man3/mbps_to_ibv_rate.3 usr/share/man/man3/mlx4dv_*.3 usr/share/man/man3/mlx5dv_*.3 usr/share/man/man3/mult_to_ibv_rate.3 usr/share/man/man7/efadv.7 +usr/share/man/man3/hns*.7 usr/share/man/man7/mlx4dv.7 usr/share/man/man7/mlx5dv.7
libibverbs/man/ibv_create_qp_ex.3 +1 -0
@@ -61,6 +61,7 @@ IBV_QP_CREATE_SCATTER_FCS = 1 << 8, /* FCS field will be scattered IBV_QP_CREATE_CVLAN_STRIPPING = 1 << 9, /* CVLAN field will be stripped from incoming packets */ IBV_QP_CREATE_SOURCE_QPN = 1 << 10, /* The created QP will use the source_qpn as its wire QP number */ IBV_QP_CREATE_PCI_WRITE_END_PADDING = 1 << 11, /* Incoming packets will be padded to cacheline size */ +IBV_QP_CREATE_DYNAMIC_CONTEXT_ATTACH = 1 << 13, /* The WQE buffer will be allocated from a memory pool which belongs to the user context */ .in -8 }; .fi
providers/hns/man/CMakeLists.txt new file +6 -0
@@ -0,0 +1,6 @@ +rdma_man_pages( + hnsdv_is_supported.3.md + hnsdv_open_device.3.md + hnsdv.7 + hns_dca.7 +)
providers/hns/man/hns_dca.7.md new file +35 -0
@@ -0,0 +1,35 @@ +--- +layout: page +title: DCA +section: 7 +tagline: DCA +date: 2021-03-03 +header: "HNS DCA Manual" +footer: hns +--- + +# NAME + +DCA - Dynamic Context Attachment + +This allows all WQEs to share a memory pool that belongs to the user context. + +# DESCRIPTION + +The DCA feature aims to reduce memory consumption by sharing WQE memory for QPs working in sparse traffic scenarios. + +The DCA memory pool consists of multiple umem objects. Each umem object is a buffer allocated in user driver and register into kernel driver. The ULP need to setup the memory pool's parameter by calling hnsdv_open_device() and the driver will expand or shrink the memory pool based on this parameter. + +When a QP's DCA was enabled by setting create flags through ibv_create_qp_ex(), the WQE buffer will not be allocated directly until the ULP invokes the ibv_post_xxx(). If the memory in the pool is insufficient and the capacity expansion conditions are met, the driver will add new umem objects to the pool. + +When all WQEs of a QP are not used by the ROCEE after ibv_poll_cq() or ibv_modify_qp() are invoked, the WQE buffer will be reclaimed to the DCA memory pool. If the free memory in the pool meets the shrink conditions, the driver will delete the unused umem object. + +# SEE ALSO + +*hnsdv_open_device(3)*, *ibv_create_qp_ex(3)* + +# AUTHORS + +Xi Wang <[email protected]> + +Weihang Li <[email protected]>
providers/hns/man/hnsdv.7.md new file +34 -0
@@ -0,0 +1,34 @@ +--- +layout: page +title: HNSDV +section: 7 +tagline: Verbs +date: 2021-03-03 +header: "HNS Direct Verbs Manual" +footer: hns +--- + +# NAME + +hnsdv - Direct verbs for hns devices + +This provides low level access to hns devices to perform direct operations, +without general branching performed by libibverbs. + +# DESCRIPTION + +The libibverbs API is an abstract one. It is agnostic to any underlying provider specific implementation. While this abstraction has the advantage of user applications portability, it has a performance penalty. For some applications optimizing performance is more important than portability. + +The hns direct verbs API is intended for such applications. It exposes hns specific low level operations, allowing the application to bypass the libibverbs API. + +The direct include of hnsdv.h together with linkage to hns library will allow usage of this new interface. + +# SEE ALSO + +**verbs**(7) + +# AUTHORS + +Xi Wang <[email protected]> + +Weihang Li <[email protected]>
providers/hns/man/hnsdv_is_supported.3.md new file +39 -0
@@ -0,0 +1,39 @@ +--- +layout: page +title: hnsdv_is_supported +section: 3 +tagline: Verbs +--- + +# NAME + +hnsdv_is_supported - Check whether an RDMA device implemented by the hns provider + +# SYNOPSIS + +```c +#include <infiniband/hnsdv.h> + +bool hnsdv_is_supported(struct ibv_device *device); +``` + +# DESCRIPTION + +hnsdv functions may be called only if this function returns true for the RDMA device. + +# ARGUMENTS + +*device* +: RDMA device to check. + +# RETURN VALUE + +Returns true if device is implemented by hns provider. + +# SEE ALSO + +*hnsdv(7)* + +# AUTHOR + +Xi Wang <[email protected]>
providers/hns/man/hnsdv_open_device.3.md new file +70 -0
70 lines not on this page · raw message
redhat/rdma-core.spec +2 -0
@@ -440,6 +440,7 @@ fi %{_libdir}/lib*.so %{_libdir}/pkgconfig/*.pc %{_mandir}/man3/efadv* +%{_mandir}/man3/hns* %{_mandir}/man3/ibv_* %{_mandir}/man3/rdma* %{_mandir}/man3/umad*
@@ -448,6 +449,7 @@ fi %{_mandir}/man3/mlx5dv* %{_mandir}/man3/mlx4dv* %{_mandir}/man7/efadv* +%{_mandir}/man7/hns* %{_mandir}/man7/mlx5dv* %{_mandir}/man7/mlx4dv* %{_mandir}/man3/ibnd_*
Signature · 1 line
2.8.1