Skip to content

Commit e8661f3

Browse files
committed
efa: Add support to allocate thread domains
In order to optimize our CQ polling functions and QP posting functions, implement the alloc/dealloc thread domain verb so the ULP will have better control on the synchronization mechanisms EFA provider uses in our data path functions. Signed-off-by: Yonatan Nachum <[email protected]>
1 parent c0d5740 commit e8661f3

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

providers/efa/efa.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
22
/*
3-
* Copyright 2019-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2019-2025 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include <stdio.h>
@@ -28,13 +28,15 @@ static const struct verbs_match_ent efa_table[] = {
2828

2929
static const struct verbs_context_ops efa_ctx_ops = {
3030
.alloc_pd = efa_alloc_pd,
31+
.alloc_td = efa_alloc_td,
3132
.create_ah = efa_create_ah,
3233
.create_cq = efa_create_cq,
3334
.create_cq_ex = efa_create_cq_ex,
3435
.create_qp = efa_create_qp,
3536
.create_qp_ex = efa_create_qp_ex,
3637
.cq_event = efa_cq_event,
3738
.dealloc_pd = efa_dealloc_pd,
39+
.dealloc_td = efa_dealloc_td,
3840
.dereg_mr = efa_dereg_mr,
3941
.destroy_ah = efa_destroy_ah,
4042
.destroy_cq = efa_destroy_cq,

providers/efa/efa.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ struct efa_pd {
5353
uint16_t pdn;
5454
};
5555

56+
struct efa_td {
57+
struct ibv_td ibvtd;
58+
/* Number of parent domains referencing this TD */
59+
atomic_int refcount;
60+
};
61+
5662
struct efa_sub_cq {
5763
uint16_t consumed_cnt;
5864
int phase;
@@ -201,6 +207,11 @@ static inline struct efa_ah *to_efa_ah(struct ibv_ah *ibvah)
201207
return container_of(ibvah, struct efa_ah, ibvah);
202208
}
203209

210+
static inline struct efa_td *to_efa_td(struct ibv_td *ibvtd)
211+
{
212+
return container_of(ibvtd, struct efa_td, ibvtd);
213+
}
214+
204215
bool is_efa_dev(struct ibv_device *device);
205216

206217
#endif /* __EFA_H__ */

providers/efa/verbs.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,3 +2636,38 @@ int efa_destroy_ah(struct ibv_ah *ibvah)
26362636

26372637
return 0;
26382638
}
2639+
2640+
struct ibv_td *efa_alloc_td(struct ibv_context *ibvctx, struct ibv_td_init_attr *init_attr)
2641+
{
2642+
struct efa_td *td;
2643+
2644+
if (!check_comp_mask(init_attr->comp_mask, 0)) {
2645+
verbs_err(verbs_get_ctx(ibvctx), "Invalid comp_mask\n");
2646+
errno = EOPNOTSUPP;
2647+
return NULL;
2648+
}
2649+
2650+
td = calloc(1, sizeof(*td));
2651+
if (!td) {
2652+
errno = ENOMEM;
2653+
return NULL;
2654+
}
2655+
2656+
td->ibvtd.context = ibvctx;
2657+
atomic_init(&td->refcount, 0);
2658+
2659+
return &td->ibvtd;
2660+
}
2661+
2662+
int efa_dealloc_td(struct ibv_td *ibvtd)
2663+
{
2664+
struct efa_td *td;
2665+
2666+
td = to_efa_td(ibvtd);
2667+
if (atomic_load(&td->refcount) > 0)
2668+
return EBUSY;
2669+
2670+
free(td);
2671+
2672+
return 0;
2673+
}

providers/efa/verbs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
22
/*
3-
* Copyright 2019-2023 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2019-2025 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#ifndef __EFA_VERBS_H__
@@ -50,5 +50,7 @@ int efa_post_recv(struct ibv_qp *ibvqp, struct ibv_recv_wr *wr,
5050

5151
struct ibv_ah *efa_create_ah(struct ibv_pd *ibvpd, struct ibv_ah_attr *attr);
5252
int efa_destroy_ah(struct ibv_ah *ibvah);
53+
struct ibv_td *efa_alloc_td(struct ibv_context *ibvctx, struct ibv_td_init_attr *init_attr);
54+
int efa_dealloc_td(struct ibv_td *ibvtd);
5355

5456
#endif /* __EFA_VERBS_H__ */

0 commit comments

Comments
 (0)