@@ -1536,6 +1536,10 @@ int destroy_ctx(struct pingpong_context *ctx,
15361536 }
15371537 }
15381538
1539+ for (i = 0 ; i < dereg_counter ; i ++ ) {
1540+ ctx -> memory -> free_buffer (ctx -> memory , 0 , ctx -> buf [i ], ctx -> buff_size );
1541+ }
1542+
15391543 if (ctx -> send_rcredit ) {
15401544 if (ibv_dereg_mr (ctx -> credit_mr )) {
15411545 fprintf (stderr , "Failed to deregister send credit MR\n" );
@@ -1578,13 +1582,15 @@ int destroy_ctx(struct pingpong_context *ctx,
15781582 }
15791583 #endif
15801584
1581- #ifdef HAVE_TD_API
1582- if (user_param -> no_lock ) {
1585+ if (ctx -> pad && ctx -> pad != ctx -> pd ) {
15831586 if (ibv_dealloc_pd (ctx -> pad )) {
15841587 fprintf (stderr , "Failed to deallocate PAD - %s\n" , strerror (errno ));
15851588 test_result = 1 ;
15861589 }
1590+ }
15871591
1592+ #ifdef HAVE_TD_API
1593+ if (user_param -> no_lock && ctx -> td ) {
15881594 if (ibv_dealloc_td (ctx -> td )) {
15891595 fprintf (stderr , "Failed to deallocate TD - %s\n" , strerror (errno ));
15901596 test_result = 1 ;
@@ -1622,10 +1628,6 @@ int destroy_ctx(struct pingpong_context *ctx,
16221628 }
16231629 }
16241630
1625- for (i = 0 ; i < dereg_counter ; i ++ ) {
1626- ctx -> memory -> free_buffer (ctx -> memory , 0 , ctx -> buf [i ], ctx -> buff_size );
1627- }
1628-
16291631 free (ctx -> qp );
16301632 #ifdef HAVE_IBV_WR_API
16311633 free (ctx -> qpx );
@@ -1853,15 +1855,13 @@ int create_reg_cqs(struct pingpong_context *ctx,
18531855 .comp_vector = user_param -> eq_num ,
18541856 };
18551857
1856- #ifdef HAVE_TD_API
1857- if (user_param -> no_lock ) {
1858+ if (ctx -> pad != ctx -> pd ) {
18581859 send_cq_attr .parent_domain = ctx -> pad ;
18591860 send_cq_attr .comp_mask = IBV_CQ_INIT_ATTR_MASK_PD ;
18601861 }
1861- #endif
18621862 ctx -> send_cq = ibv_cq_ex_to_cq (ibv_create_cq_ex (ctx -> context , & send_cq_attr ));
18631863 if (!ctx -> send_cq ) {
1864- if (! user_param -> no_lock && errno == EOPNOTSUPP )
1864+ if (ctx -> pad == ctx -> pd && errno == EOPNOTSUPP )
18651865 goto cq_ex_not_supported ;
18661866 fprintf (stderr , "Couldn't create CQ\n" );
18671867 return FAILURE ;
@@ -1874,12 +1874,10 @@ int create_reg_cqs(struct pingpong_context *ctx,
18741874 .channel = ctx -> recv_channel ,
18751875 .comp_vector = user_param -> eq_num ,
18761876 };
1877- #ifdef HAVE_TD_API
1878- if (user_param -> no_lock ) {
1877+ if (ctx -> pad != ctx -> pd ) {
18791878 recv_cq_attr .parent_domain = ctx -> pad ;
18801879 recv_cq_attr .comp_mask = IBV_CQ_INIT_ATTR_MASK_PD ;
18811880 }
1882- #endif
18831881 ctx -> recv_cq = ibv_cq_ex_to_cq (ibv_create_cq_ex (ctx -> context , & recv_cq_attr ));
18841882 if (!ctx -> recv_cq ) {
18851883 fprintf (stderr , "Couldn't create a receiver CQ\n" );
@@ -2076,7 +2074,7 @@ static struct ibv_mr *register_mr_ex(struct pingpong_context *ctx,
20762074 in .dmah = ctx -> dmah ;
20772075 }
20782076
2079- return ibv_reg_mr_ex (ctx -> pd , & in );
2077+ return ibv_reg_mr_ex (ctx -> pad , & in );
20802078}
20812079#endif
20822080
@@ -2129,7 +2127,7 @@ static struct ibv_mr *register_mr(struct pingpong_context *ctx,
21292127#endif
21302128 } else {
21312129 /* Regular memory registration using standard API */
2132- return ibv_reg_mr (ctx -> pd , ctx -> buf [qp_index ], ctx -> buff_size , flags );
2130+ return ibv_reg_mr (ctx -> pad , ctx -> buf [qp_index ], ctx -> buff_size , flags );
21332131 }
21342132}
21352133
@@ -2554,33 +2552,37 @@ int ctx_init(struct pingpong_context *ctx, struct perftest_parameters *user_para
25542552 goto comp_channel ;
25552553 }
25562554
2555+ int need_parent_domain = 0 ;
25572556 #ifdef HAVE_TD_API
2558- /* Allocating the Thread domain, Parent domain. */
2559- if (user_param -> no_lock ) {
2560- struct ibv_td_init_attr td_attr = {0 };
2561- ctx -> td = ibv_alloc_td (ctx -> context , & td_attr );
2562- if (!ctx -> td ) {
2563- fprintf (stderr , "Couldn't allocate TD\n" );
2564- goto pd ;
2565- }
2557+ need_parent_domain |= user_param -> no_lock ;
2558+ #endif
25662559
2560+ if (need_parent_domain ) {
25672561 struct ibv_parent_domain_init_attr pad_attr = {
25682562 .pd = ctx -> pd ,
2569- .td = ctx -> td ,
25702563 .comp_mask = 0 ,
25712564 };
25722565
2566+ #ifdef HAVE_TD_API
2567+ if (user_param -> no_lock ) {
2568+ struct ibv_td_init_attr td_attr = {0 };
2569+ ctx -> td = ibv_alloc_td (ctx -> context , & td_attr );
2570+ if (!ctx -> td ) {
2571+ fprintf (stderr , "Couldn't allocate TD\n" );
2572+ goto pd ;
2573+ }
2574+ pad_attr .td = ctx -> td ;
2575+ }
2576+ #endif
2577+
25732578 ctx -> pad = ibv_alloc_parent_domain (ctx -> context , & pad_attr );
25742579 if (!ctx -> pad ) {
25752580 fprintf (stderr , "Couldn't allocate PAD\n" );
25762581 goto td ;
25772582 }
25782583 } else {
2579- #endif
25802584 ctx -> pad = ctx -> pd ;
2581- #ifdef HAVE_TD_API
25822585 }
2583- #endif
25842586
25852587
25862588 #ifdef HAVE_AES_XTS
@@ -2829,16 +2831,15 @@ xrcd: __attribute__((unused))
28292831 mlx5dv_dek_destroy (ctx -> dek [i ]);
28302832#endif
28312833
2832- #ifdef HAVE_TD_API
2833- if (user_param -> no_lock )
2834+ if (ctx -> pad && ctx -> pad != ctx -> pd )
28342835 ibv_dealloc_pd (ctx -> pad );
28352836
28362837td :
2837- if (user_param -> no_lock )
2838+ #ifdef HAVE_TD_API
2839+ if (user_param -> no_lock && ctx -> td )
28382840 ibv_dealloc_td (ctx -> td );
2839- pd :
28402841#endif
2841-
2842+ pd :
28422843 ibv_dealloc_pd (ctx -> pd );
28432844 ctx -> pd = NULL ;
28442845
0 commit comments