1- /* -*- Mode: C; c-basic-offset:4 ; -*- */
1+ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22/*
33 * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
44 * University Research and Technology
1111 * Copyright (c) 2004-2005 The Regents of the University of California.
1212 * All rights reserved.
1313 * Copyright (c) 2006-2013 Cisco Systems, Inc. All rights reserved.
14- * Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights
14+ * Copyright (c) 2006-2014 Los Alamos National Security, LLC. All rights
1515 * reserved.
1616 * Copyright (c) 2006-2007 Voltaire All rights reserved.
1717 * Copyright (c) 2006-2009 Mellanox Technologies, Inc. All rights reserved.
5454static void mca_btl_openib_endpoint_construct (mca_btl_base_endpoint_t * endpoint );
5555static void mca_btl_openib_endpoint_destruct (mca_btl_base_endpoint_t * endpoint );
5656
57- static inline int acruire_wqe (mca_btl_openib_endpoint_t * ep ,
57+ static inline int acquire_wqe (mca_btl_openib_endpoint_t * ep ,
5858 mca_btl_openib_send_frag_t * frag )
5959{
6060 int qp = to_base_frag (frag )-> base .order ;
@@ -70,91 +70,34 @@ static inline int acruire_wqe(mca_btl_openib_endpoint_t *ep,
7070 return OPAL_SUCCESS ;
7171}
7272
73- static int acquire_send_credit (mca_btl_openib_endpoint_t * endpoint ,
74- mca_btl_openib_send_frag_t * frag )
75- {
76- mca_btl_openib_module_t * openib_btl = endpoint -> endpoint_btl ;
77- int qp = to_base_frag (frag )-> base .order ;
78- int prio = !(to_base_frag (frag )-> base .des_flags & MCA_BTL_DES_FLAGS_PRIORITY );
79-
80- if (BTL_OPENIB_QP_TYPE_PP (qp )) {
81- if (OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , -1 ) < 0 ) {
82- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , 1 );
83- opal_list_append (& endpoint -> qps [qp ].no_credits_pending_frags [prio ],
84- (opal_list_item_t * )frag );
85- return OPAL_ERR_OUT_OF_RESOURCE ;
86- }
87- } else {
88- if (OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , -1 ) < 0 )
89- {
90- OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , 1 );
91- OPAL_THREAD_LOCK (& openib_btl -> ib_lock );
92- opal_list_append (& openib_btl -> qps [qp ].u .srq_qp .pending_frags [prio ],
93- (opal_list_item_t * )frag );
94- OPAL_THREAD_UNLOCK (& openib_btl -> ib_lock );
95- return OPAL_ERR_OUT_OF_RESOURCE ;
96- }
97- }
98-
99- return OPAL_SUCCESS ;
100- }
101-
10273/* this function is called with endpoint->endpoint_lock held */
10374int mca_btl_openib_endpoint_post_send (mca_btl_openib_endpoint_t * endpoint ,
10475 mca_btl_openib_send_frag_t * frag )
10576{
77+ int prio = !(to_base_frag (frag )-> base .des_flags & MCA_BTL_DES_FLAGS_PRIORITY );
10678 mca_btl_openib_header_t * hdr = frag -> hdr ;
10779 mca_btl_base_descriptor_t * des = & to_base_frag (frag )-> base ;
108- int qp , ib_rc ;
109- int32_t cm_return ;
80+ int qp , ib_rc , rc ;
11081 bool do_rdma = false;
111- size_t eager_limit ;
82+ size_t size ;
11283
11384 if (OPAL_LIKELY (des -> order == MCA_BTL_NO_ORDER ))
11485 des -> order = frag -> qp_idx ;
11586
11687 qp = des -> order ;
11788
118- if (acruire_wqe (endpoint , frag ) != OPAL_SUCCESS )
89+ if (acquire_wqe (endpoint , frag ) != OPAL_SUCCESS )
11990 return OPAL_ERR_RESOURCE_BUSY ;
12091
121- eager_limit = mca_btl_openib_component .eager_limit +
122- sizeof (mca_btl_openib_header_coalesced_t ) +
123- sizeof (mca_btl_openib_control_header_t );
124- if (des -> des_local -> seg_len + frag -> coalesced_length <= eager_limit &&
125- (des -> des_flags & MCA_BTL_DES_FLAGS_PRIORITY )) {
126- /* High priority frag. Try to send over eager RDMA */
127- if (acquire_eager_rdma_send_credit (endpoint ) == OPAL_SUCCESS )
128- do_rdma = true;
129- }
92+ size = des -> des_local -> seg_len + frag -> coalesced_length ;
13093
131- if (!do_rdma && acquire_send_credit (endpoint , frag ) != OPAL_SUCCESS ) {
94+ rc = mca_btl_openib_endpoint_credit_acquire (endpoint , qp , prio , size ,
95+ & do_rdma , frag , true);
96+ if (OPAL_UNLIKELY (OPAL_SUCCESS != rc )) {
13297 qp_put_wqe (endpoint , qp );
13398 return OPAL_ERR_RESOURCE_BUSY ;
13499 }
135100
136- BTL_OPENIB_GET_CREDITS (endpoint -> eager_rdma_local .credits , hdr -> credits );
137- if (hdr -> credits )
138- hdr -> credits |= BTL_OPENIB_RDMA_CREDITS_FLAG ;
139-
140- if (!do_rdma ) {
141- if (BTL_OPENIB_QP_TYPE_PP (qp ) && 0 == hdr -> credits ) {
142- BTL_OPENIB_GET_CREDITS (endpoint -> qps [qp ].u .pp_qp .rd_credits , hdr -> credits );
143- }
144- } else {
145- hdr -> credits |= (qp << 11 );
146- }
147-
148- BTL_OPENIB_GET_CREDITS (endpoint -> qps [qp ].u .pp_qp .cm_return , cm_return );
149- /* cm_seen is only 8 bytes, but cm_return is 32 bytes */
150- if (cm_return > 255 ) {
151- hdr -> cm_seen = 255 ;
152- cm_return -= 255 ;
153- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .cm_return , cm_return );
154- } else {
155- hdr -> cm_seen = cm_return ;
156- }
157-
158101 qp_reset_signal_count (endpoint , qp );
159102 ib_rc = post_send (endpoint , frag , do_rdma , 1 );
160103
@@ -164,27 +107,12 @@ int mca_btl_openib_endpoint_post_send(mca_btl_openib_endpoint_t *endpoint,
164107 if (endpoint -> nbo )
165108 BTL_OPENIB_HEADER_NTOH (* hdr );
166109
167- if (BTL_OPENIB_IS_RDMA_CREDITS (hdr -> credits )) {
168- OPAL_THREAD_ADD32 (& endpoint -> eager_rdma_local .credits ,
169- BTL_OPENIB_CREDITS (hdr -> credits ));
170- }
110+ mca_btl_openib_endpoint_credit_release (endpoint , qp , do_rdma , frag );
171111
172112 qp_put_wqe (endpoint , qp );
173113
174- if (do_rdma ) {
175- OPAL_THREAD_ADD32 (& endpoint -> eager_rdma_remote .tokens , 1 );
176- } else {
177- if (BTL_OPENIB_QP_TYPE_PP (qp )) {
178- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .rd_credits ,
179- hdr -> credits );
180- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , 1 );
181- } else if BTL_OPENIB_QP_TYPE_SRQ (qp ){
182- mca_btl_openib_module_t * openib_btl = endpoint -> endpoint_btl ;
183- OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , 1 );
184- }
185- }
186- BTL_ERROR (("error posting send request error %d: %s\n" ,
187- ib_rc , strerror (ib_rc )));
114+ BTL_ERROR (("error posting send request error %d: %s. size = %lu\n" ,
115+ ib_rc , strerror (ib_rc ), size ));
188116 return OPAL_ERROR ;
189117}
190118
@@ -709,8 +637,8 @@ void mca_btl_openib_endpoint_connected(mca_btl_openib_endpoint_t *endpoint)
709637 /* We need to post this one */
710638
711639 if (OPAL_ERROR == mca_btl_openib_endpoint_post_send (endpoint , frag )) {
712- BTL_ERROR (("Error posting send" ));
713- }
640+ BTL_ERROR (("Error posting send" ));
641+ }
714642 }
715643 OPAL_THREAD_UNLOCK (& endpoint -> endpoint_lock );
716644
0 commit comments