libhns: Add support for direct wqe
v3 cover libhns: Add support for direct wqe
Direct wqe is a mechanism to fill wqe directly into the hardware. In the case of light load, the wqe will be filled into pcie bar space of the hardware, this will reduce one memory access operation and therefore reduce the latency.
The kernel parts is named "RDMA/hns: Support direct WQE of userspace".
Changes since v2:
* Only updated kernel-headers.
* Link: https://patchwork.kernel.org/project/linux-rdma/cover/[email protected]/
Changes since v1:
* Changed the mapping scheme of direct wqe.
* Use SIMD instructions to load and store dwqe data, and encapsulate instructions into macros.
* Link: https://patchwork.kernel.org/project/linux-rdma/cover/[email protected]/
Wenpeng Liang (1):
Update kernel headers
Yixing Liu (1):
libhns: Add support for direct wqe
kernel-headers/rdma/hns-abi.h | 2 ++ providers/hns/hns_roce_u.h | 5 +++- providers/hns/hns_roce_u_hw_v2.c | 44 +++++++++++++++++++++++++------- providers/hns/hns_roce_u_hw_v2.h | 31 ++++++++++++---------- providers/hns/hns_roce_u_verbs.c | 26 +++++++++++++++++-- util/mmio.h | 27 +++++++++++++++++++- 6 files changed, 109 insertions(+), 26 deletions(-)
--
2.33.0
PATCH v3 1/2 Update kernel headers
To commit ?? ("RDMA/hns: Support direct wqe of userspace").
--- kernel-headers/rdma/hns-abi.h | 2 ++ 1 file changed, 2 insertions(+)
kernel-headers/rdma/hns-abi.h +2 -0
@@ -77,10 +77,12 @@ 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_DIRECT_WQE = 1 << 5, };struct hns_roce_ib_create_qp_resp {__aligned_u64 cap_flags; +__aligned_u64 dwqe_mmap_key; }; struct hns_roce_ib_alloc_ucontext_resp {
Signature · 1 line
2.33.0
PATCH v3 2/2 libhns: Add support for direct wqe
In reply to Wenpeng LiangFrom: Yixing Liu <[email protected]>
The current write wqe mechanism is to write to DDR first, and then notify the hardware through doorbell to read the data. Direct wqe is a mechanism to fill wqe directly into the hardware. In the case of light load, the wqe will be filled into pcie bar space of the hardware, this will reduce one memory access operation and therefore reduce the latency. SIMD instructions allows cpu to write the 512 bits at one time to device memory, thus it can be used for posting direct wqe.
The process of post send of HIP08/09:
+-----------+
| post send |
+-----+-----+
|
+-----+-----+
| write WQE |
+-----+-----+
|
| udma_to_device_barrier()
|
+-----+-----+ Y +-----------+ N
| HIP09 ? +------+ multi WR ?+-------------+
+-----+-----+ +-----+-----+ |
| N | Y |
+-----+-----+ +-----+-----+ +--------+--------+
| ring DB | | ring DB | |direct WQE (ST4) |
+-----------+ +-----------+ +-----------------+--- providers/hns/hns_roce_u.h | 5 +++- providers/hns/hns_roce_u_hw_v2.c | 44 +++++++++++++++++++++++++------- providers/hns/hns_roce_u_hw_v2.h | 31 ++++++++++++---------- providers/hns/hns_roce_u_verbs.c | 26 +++++++++++++++++-- util/mmio.h | 27 +++++++++++++++++++- 5 files changed, 107 insertions(+), 26 deletions(-)
providers/hns/hns_roce_u.h +4 -1
@@ -81,6 +81,8 @@#define INVALID_SGE_LENGTH 0x80000000 +#define HNS_ROCE_DWQE_PAGE_SIZE 65536 +#define HNS_ROCE_ADDRESS_MASK 0xFFFFFFFF#define HNS_ROCE_ADDRESS_SHIFT 32
@@ -280,13 +282,14 @@ struct hns_roce_qp {struct hns_roce_sge_ex ex_sge;unsigned int next_sge;int port_num; -int sl; +uint8_t sl;unsigned int qkey;enum ibv_mtu path_mtu;struct hns_roce_rinl_buf rq_rinl_buf;unsigned long flags;int refcnt;/* specially used for XRC */ +void *dwqe_page; };struct hns_roce_av {
providers/hns/hns_roce_u_hw_v2.c +35 -9
91 lines not on this page · raw message
providers/hns/hns_roce_u_hw_v2.h +18 -13
@@ -40,6 +40,8 @@#define HNS_ROCE_CMDSN_MASK 0x3 +#define HNS_ROCE_SL_SHIFT 2 +/* V2 REG DEFINITION */ #define ROCEE_VF_DB_CFG0_OFFSET 0x0230
@@ -133,6 +135,8 @@ struct hns_roce_db {#define DB_BYTE_4_CMD_S 24#define DB_BYTE_4_CMD_M GENMASK(27, 24) +#define DB_BYTE_4_FLAG_S 31 +#define DB_PARAM_SRQ_PRODUCER_COUNTER_S 0#define DB_PARAM_SRQ_PRODUCER_COUNTER_M GENMASK(15, 0)
@@ -216,8 +220,16 @@ struct hns_roce_rc_sq_wqe { };#define RC_SQ_WQE_BYTE_4_OPCODE_S 0 -#define RC_SQ_WQE_BYTE_4_OPCODE_M \ - (((1UL << 5) - 1) << RC_SQ_WQE_BYTE_4_OPCODE_S) +#define RC_SQ_WQE_BYTE_4_OPCODE_M GENMASK(4, 0) + +#define RC_SQ_WQE_BYTE_4_DB_SL_L_S 5 +#define RC_SQ_WQE_BYTE_4_DB_SL_L_M GENMASK(6, 5) + +#define RC_SQ_WQE_BYTE_4_DB_SL_H_S 13 +#define RC_SQ_WQE_BYTE_4_DB_SL_H_M GENMASK(14, 13) + +#define RC_SQ_WQE_BYTE_4_WQE_INDEX_S 15 +#define RC_SQ_WQE_BYTE_4_WQE_INDEX_M GENMASK(30, 15)#define RC_SQ_WQE_BYTE_4_OWNER_S 7
@@ -239,6 +251,8 @@ struct hns_roce_rc_sq_wqe {#define RC_SQ_WQE_BYTE_4_RDMA_WRITE_S 22 +#define RC_SQ_WQE_BYTE_4_FLAG_S 31 +#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)
@@ -311,23 +325,12 @@ struct hns_roce_ud_sq_wqe {#define UD_SQ_WQE_OPCODE_S 0#define UD_SQ_WQE_OPCODE_M GENMASK(4, 0) -#define UD_SQ_WQE_DB_SL_L_S 5 -#define UD_SQ_WQE_DB_SL_L_M GENMASK(6, 5) - -#define UD_SQ_WQE_DB_SL_H_S 13 -#define UD_SQ_WQE_DB_SL_H_M GENMASK(14, 13) - -#define UD_SQ_WQE_INDEX_S 15 -#define UD_SQ_WQE_INDEX_M GENMASK(30, 15) -#define UD_SQ_WQE_OWNER_S 7#define UD_SQ_WQE_CQE_S 8#define UD_SQ_WQE_SE_S 11 -#define UD_SQ_WQE_FLAG_S 31 -#define UD_SQ_WQE_PD_S 0#define UD_SQ_WQE_PD_M GENMASK(23, 0)
@@ -376,4 +379,6 @@ struct hns_roce_ud_sq_wqe {#define MAX_SERVICE_LEVEL 0x7 +void hns_roce_v2_clear_qp (struct hns_roce_context *ctx,struct hns_roce_qp *qp); +#endif /* _HNS_ROCE_U_HW_V2_H */
providers/hns/hns_roce_u_verbs.c +24 -2
@@ -1119,7 +1119,8 @@ static int hns_roce_store_qp(struct hns_roce_context *ctx,static int qp_exec_create_cmd (struct ibv_qp_init_attr_ex *attr,struct hns_roce_qp *qp, -struct hns_roce_context *ctx) +struct hns_roce_context *ctx, +uint64_t *dwqe_mmap_key) {struct hns_roce_create_qp_ex_resp resp_ex = {};struct hns_roce_create_qp_ex cmd_ex = {};
@@ -1136,6 +1137,7 @@ static int qp_exec_create_cmd(struct ibv_qp_init_attr_ex *attr, &resp_ex.ibv_resp, sizeof(resp_ex)); qp->flags = resp_ex.drv_payload.cap_flags; + *dwqe_mmap_key = resp_ex.drv_payload.dwqe_mmap_key;return ret; }
@@ -1187,11 +1189,23 @@ static int hns_roce_alloc_qp_buf(struct ibv_qp_init_attr_ex *attr,return ret; } +static int mmap_dwqe (struct ibv_context *ibv_ctx,struct hns_roce_qp *qp, +uint64_t dwqe_mmap_key) +{ + qp->dwqe_page =mmap (NULL ,HNS_ROCE_DWQE_PAGE_SIZE ,PROT_WRITE , +MAP_SHARED , ibv_ctx->cmd_fd, dwqe_mmap_key); +if (qp->dwqe_page ==MAP_FAILED ) +return -EINVAL ; + +return 0 ; +} +static struct ibv_qp *create_qp (struct ibv_context *ibv_ctx,struct ibv_qp_init_attr_ex *attr) {struct hns_roce_context *context =to_hr_ctx (ibv_ctx);struct hns_roce_qp *qp; +uint64_t dwqe_mmap_key;int ret; ret =verify_qp_create_attr (context, attr);
@@ -1210,7 +1224,7 @@ static struct ibv_qp *create_qp(struct ibv_context *ibv_ctx,if (ret) goto err_buf; - ret =qp_exec_create_cmd (attr, qp, context); + ret =qp_exec_create_cmd (attr, qp, context, &dwqe_mmap_key);if (ret) goto err_cmd;
@@ -1218,10 +1232,18 @@ static struct ibv_qp *create_qp(struct ibv_context *ibv_ctx,if (ret) goto err_store; +if (qp->flags &HNS_ROCE_QP_CAP_DIRECT_WQE ) { + ret =mmap_dwqe (ibv_ctx, qp, dwqe_mmap_key); +if (ret) + goto err_dwqe; + } +qp_setup_config (attr, qp, context);return &qp->verbs_qp.qp; +err_dwqe: +hns_roce_v2_clear_qp (context, qp); err_store:ibv_cmd_destroy_qp (&qp->verbs_qp.qp); err_cmd:
util/mmio.h +26 -1
@@ -210,8 +210,33 @@ static inline void mmio_memcpy_x64(void *dest, const void *src, size_t bytecnt) {s390_mmio_write (dest, src, bytecnt); } -#else +#elif defined(__aarch64__) || defined(__arm__) +#include <arm_neon.h> + +static inline void _mmio_memcpy_x64_64b (void *dest,const void *src) +{ +vst4q_u64 (dest,vld4q_u64 (src)); +} + +static inline void _mmio_memcpy_x64 (void *dest,const void *src,size_t bytecnt) +{ +do { +_mmio_memcpy_x64_64b (dest, src); + bytecnt -=sizeof (uint64x2x4_t); + src +=sizeof (uint64x2x4_t); + }while (bytecnt >0 ); +} + +#define mmio_memcpy_x64 (dest, src, bytecount) \ + ({ \ + if (__builtin_constant_p((bytecount) == 64)) \ + _mmio_memcpy_x64_64b((dest), (src)); \ + else \ + _mmio_memcpy_x64((dest), (src), (bytecount)); \ + }) + +#else /* Transfer is some multiple of 64 bytes */ static inline void mmio_memcpy_x64 (void *dest,const void *src,size_t bytecnt) {
Signature · 1 line
2.33.0