Skip to content

Commit

Permalink
libhns: Add pthread_spin_destroy()
Browse files Browse the repository at this point in the history
The driver should call pthread_spin_destroy() to destroy spin locks
before exiting.

Signed-off-by: Junxian Huang <[email protected]>
  • Loading branch information
Junxian Huang authored and Junxian Huang committed Apr 18, 2024
1 parent 6772962 commit c71bb6d
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions providers/hns/hns_roce_u_verbs.c
Expand Up @@ -385,8 +385,9 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *context,
hns_roce_free_db(hr_ctx, cq->db, HNS_ROCE_CQ_TYPE_DB);
err_db:
hns_roce_free_buf(&cq->buf);
err_lock:
err_buf:
pthread_spin_destroy(&cq->lock);
err_lock:
free(cq);
err:
if (ret < 0)
Expand Down Expand Up @@ -437,16 +438,20 @@ int hns_roce_u_modify_cq(struct ibv_cq *cq, struct ibv_modify_cq_attr *attr)

int hns_roce_u_destroy_cq(struct ibv_cq *cq)
{
struct hns_roce_cq *hr_cq = to_hr_cq(cq);
int ret;

ret = ibv_cmd_destroy_cq(cq);
if (ret)
return ret;

hns_roce_free_db(to_hr_ctx(cq->context), to_hr_cq(cq)->db,
HNS_ROCE_CQ_TYPE_DB);
hns_roce_free_buf(&to_hr_cq(cq)->buf);
free(to_hr_cq(cq));
hns_roce_free_db(to_hr_ctx(cq->context), hr_cq->db,
HNS_ROCE_CQ_TYPE_DB);
hns_roce_free_buf(&hr_cq->buf);

pthread_spin_destroy(&hr_cq->lock);

free(hr_cq);

return ret;
}
Expand Down Expand Up @@ -674,7 +679,7 @@ static struct ibv_srq *create_srq(struct ibv_context *context,

set_srq_param(context, srq, init_attr);
if (alloc_srq_buf(srq))
goto err_free_srq;
goto err_destroy_lock;

srq->rdb = hns_roce_alloc_db(hr_ctx, HNS_ROCE_SRQ_TYPE_DB);
if (!srq->rdb)
Expand Down Expand Up @@ -705,6 +710,9 @@ static struct ibv_srq *create_srq(struct ibv_context *context,
err_srq_buf:
free_srq_buf(srq);

err_destroy_lock:
pthread_spin_destroy(&srq->lock);

err_free_srq:
free(srq);

Expand Down Expand Up @@ -780,6 +788,8 @@ int hns_roce_u_destroy_srq(struct ibv_srq *ibv_srq)

hns_roce_free_db(ctx, srq->rdb, HNS_ROCE_SRQ_TYPE_DB);
free_srq_buf(srq);

pthread_spin_destroy(&srq->lock);
free(srq);

return 0;
Expand Down Expand Up @@ -1295,6 +1305,8 @@ void hns_roce_free_qp_buf(struct hns_roce_qp *qp, struct hns_roce_context *ctx)
{
qp_free_db(qp, ctx);
qp_free_wqe(qp);
pthread_spin_destroy(&qp->rq.lock);
pthread_spin_destroy(&qp->sq.lock);
}

static int hns_roce_alloc_qp_buf(struct ibv_qp_init_attr_ex *attr,
Expand All @@ -1303,17 +1315,30 @@ static int hns_roce_alloc_qp_buf(struct ibv_qp_init_attr_ex *attr,
{
int ret;

if (pthread_spin_init(&qp->sq.lock, PTHREAD_PROCESS_PRIVATE) ||
pthread_spin_init(&qp->rq.lock, PTHREAD_PROCESS_PRIVATE))
return -ENOMEM;
ret = pthread_spin_init(&qp->sq.lock, PTHREAD_PROCESS_PRIVATE);
if (ret)
return ret;

ret = pthread_spin_init(&qp->rq.lock, PTHREAD_PROCESS_PRIVATE);
if (ret)
goto err_rq_lock;

ret = qp_alloc_wqe(&attr->cap, qp, ctx);
if (ret)
return ret;
goto err_wqe;

ret = qp_alloc_db(attr, qp, ctx);
if (ret)
qp_free_wqe(qp);
goto err_db;

return 0;

err_db:
qp_free_wqe(qp);
err_wqe:
pthread_spin_destroy(&qp->rq.lock);
err_rq_lock:
pthread_spin_destroy(&qp->sq.lock);

return ret;
}
Expand Down

0 comments on commit c71bb6d

Please sign in to comment.