Skip to content

Commit

Permalink
Merge pull request #1482 from hginjgerx/td
Browse files Browse the repository at this point in the history
libhns: Support lock-free for data path
  • Loading branch information
rleon authored Jul 7, 2024
2 parents 194c37c + b38bae4 commit d74b960
Show file tree
Hide file tree
Showing 4 changed files with 345 additions and 77 deletions.
5 changes: 4 additions & 1 deletion providers/hns/hns_roce_u.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static const struct verbs_context_ops hns_common_ops = {
.create_qp = hns_roce_u_create_qp,
.create_qp_ex = hns_roce_u_create_qp_ex,
.dealloc_mw = hns_roce_u_dealloc_mw,
.dealloc_pd = hns_roce_u_free_pd,
.dealloc_pd = hns_roce_u_dealloc_pd,
.dereg_mr = hns_roce_u_dereg_mr,
.destroy_cq = hns_roce_u_destroy_cq,
.modify_cq = hns_roce_u_modify_cq,
Expand All @@ -88,6 +88,9 @@ static const struct verbs_context_ops hns_common_ops = {
.close_xrcd = hns_roce_u_close_xrcd,
.open_qp = hns_roce_u_open_qp,
.get_srq_num = hns_roce_u_get_srq_num,
.alloc_td = hns_roce_u_alloc_td,
.dealloc_td = hns_roce_u_dealloc_td,
.alloc_parent_domain = hns_roce_u_alloc_pad,
};

static uint32_t calc_table_shift(uint32_t entry_count, uint32_t size_shift)
Expand Down
74 changes: 69 additions & 5 deletions providers/hns/hns_roce_u.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ struct hns_roce_db_page {
unsigned long *bitmap;
};

struct hns_roce_spinlock {
pthread_spinlock_t lock;
int need_lock;
};

struct hns_roce_context {
struct verbs_context ibv_ctx;
void *uar;
Expand Down Expand Up @@ -230,15 +235,27 @@ struct hns_roce_context {
unsigned int max_inline_data;
};

struct hns_roce_td {
struct ibv_td ibv_td;
atomic_int refcount;
};

struct hns_roce_pd {
struct ibv_pd ibv_pd;
unsigned int pdn;
atomic_int refcount;
struct hns_roce_pd *protection_domain;
};

struct hns_roce_pad {
struct hns_roce_pd pd;
struct hns_roce_td *td;
};

struct hns_roce_cq {
struct verbs_cq verbs_cq;
struct hns_roce_buf buf;
pthread_spinlock_t lock;
struct hns_roce_spinlock hr_lock;
unsigned int cqn;
unsigned int cq_depth;
unsigned int cons_index;
Expand All @@ -248,6 +265,7 @@ struct hns_roce_cq {
unsigned long flags;
unsigned int cqe_size;
struct hns_roce_v2_cqe *cqe;
struct ibv_pd *parent_domain;
};

struct hns_roce_idx_que {
Expand All @@ -273,7 +291,7 @@ struct hns_roce_srq {
struct verbs_srq verbs_srq;
struct hns_roce_idx_que idx_que;
struct hns_roce_buf wqe_buf;
pthread_spinlock_t lock;
struct hns_roce_spinlock hr_lock;
unsigned long *wrid;
unsigned int srqn;
unsigned int wqe_cnt;
Expand All @@ -287,7 +305,7 @@ struct hns_roce_srq {

struct hns_roce_wq {
unsigned long *wrid;
pthread_spinlock_t lock;
struct hns_roce_spinlock hr_lock;
unsigned int wqe_cnt;
int max_post;
unsigned int head;
Expand Down Expand Up @@ -405,9 +423,33 @@ static inline struct hns_roce_context *to_hr_ctx(struct ibv_context *ibv_ctx)
return container_of(ibv_ctx, struct hns_roce_context, ibv_ctx.context);
}

static inline struct hns_roce_td *to_hr_td(struct ibv_td *ibv_td)
{
return container_of(ibv_td, struct hns_roce_td, ibv_td);
}

/* to_hr_pd always returns the real hns_roce_pd obj. */
static inline struct hns_roce_pd *to_hr_pd(struct ibv_pd *ibv_pd)
{
return container_of(ibv_pd, struct hns_roce_pd, ibv_pd);
struct hns_roce_pd *pd =
container_of(ibv_pd, struct hns_roce_pd, ibv_pd);

if (pd->protection_domain)
return pd->protection_domain;

return pd;
}

static inline struct hns_roce_pad *to_hr_pad(struct ibv_pd *ibv_pd)
{
struct hns_roce_pad *pad = ibv_pd ?
container_of(ibv_pd, struct hns_roce_pad, pd.ibv_pd) : NULL;

if (pad && pad->pd.protection_domain)
return pad;

/* Otherwise ibv_pd isn't a parent_domain */
return NULL;
}

static inline struct hns_roce_cq *to_hr_cq(struct ibv_cq *ibv_cq)
Expand All @@ -430,14 +472,35 @@ 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);
}

static inline int hns_roce_spin_lock(struct hns_roce_spinlock *hr_lock)
{
if (hr_lock->need_lock)
return pthread_spin_lock(&hr_lock->lock);

return 0;
}

static inline int hns_roce_spin_unlock(struct hns_roce_spinlock *hr_lock)
{
if (hr_lock->need_lock)
return pthread_spin_unlock(&hr_lock->lock);

return 0;
}

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);
int hns_roce_u_query_port(struct ibv_context *context, uint8_t port,
struct ibv_port_attr *attr);

struct ibv_td *hns_roce_u_alloc_td(struct ibv_context *context,
struct ibv_td_init_attr *attr);
int hns_roce_u_dealloc_td(struct ibv_td *ibv_td);
struct ibv_pd *hns_roce_u_alloc_pad(struct ibv_context *context,
struct ibv_parent_domain_init_attr *attr);
struct ibv_pd *hns_roce_u_alloc_pd(struct ibv_context *context);
int hns_roce_u_free_pd(struct ibv_pd *pd);
int hns_roce_u_dealloc_pd(struct ibv_pd *pd);

struct ibv_mr *hns_roce_u_reg_mr(struct ibv_pd *pd, void *addr, size_t length,
uint64_t hca_va, int access);
Expand Down Expand Up @@ -496,6 +559,7 @@ int hns_roce_u_close_xrcd(struct ibv_xrcd *ibv_xrcd);
int hns_roce_alloc_buf(struct hns_roce_buf *buf, unsigned int size,
int page_size);
void hns_roce_free_buf(struct hns_roce_buf *buf);
void hns_roce_qp_spinlock_destroy(struct hns_roce_qp *qp);

void hns_roce_free_qp_buf(struct hns_roce_qp *qp, struct hns_roce_context *ctx);

Expand Down
Loading

0 comments on commit d74b960

Please sign in to comment.