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.
5151static void mca_btl_openib_endpoint_construct (mca_btl_base_endpoint_t * endpoint );
5252static void mca_btl_openib_endpoint_destruct (mca_btl_base_endpoint_t * endpoint );
5353
54- static inline int acruire_wqe (mca_btl_openib_endpoint_t * ep ,
54+ static inline int acquire_wqe (mca_btl_openib_endpoint_t * ep ,
5555 mca_btl_openib_send_frag_t * frag )
5656{
5757 int qp = to_base_frag (frag )-> base .order ;
@@ -67,91 +67,34 @@ static inline int acruire_wqe(mca_btl_openib_endpoint_t *ep,
6767 return OPAL_SUCCESS ;
6868}
6969
70- static int acquire_send_credit (mca_btl_openib_endpoint_t * endpoint ,
71- mca_btl_openib_send_frag_t * frag )
72- {
73- mca_btl_openib_module_t * openib_btl = endpoint -> endpoint_btl ;
74- int qp = to_base_frag (frag )-> base .order ;
75- int prio = !(to_base_frag (frag )-> base .des_flags & MCA_BTL_DES_FLAGS_PRIORITY );
76-
77- if (BTL_OPENIB_QP_TYPE_PP (qp )) {
78- if (OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , -1 ) < 0 ) {
79- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , 1 );
80- opal_list_append (& endpoint -> qps [qp ].no_credits_pending_frags [prio ],
81- (opal_list_item_t * )frag );
82- return OPAL_ERR_OUT_OF_RESOURCE ;
83- }
84- } else {
85- if (OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , -1 ) < 0 )
86- {
87- OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , 1 );
88- OPAL_THREAD_LOCK (& openib_btl -> ib_lock );
89- opal_list_append (& openib_btl -> qps [qp ].u .srq_qp .pending_frags [prio ],
90- (opal_list_item_t * )frag );
91- OPAL_THREAD_UNLOCK (& openib_btl -> ib_lock );
92- return OPAL_ERR_OUT_OF_RESOURCE ;
93- }
94- }
95-
96- return OPAL_SUCCESS ;
97- }
98-
9970/* this function is called with endpoint->endpoint_lock held */
10071int mca_btl_openib_endpoint_post_send (mca_btl_openib_endpoint_t * endpoint ,
10172 mca_btl_openib_send_frag_t * frag )
10273{
74+ int prio = !(to_base_frag (frag )-> base .des_flags & MCA_BTL_DES_FLAGS_PRIORITY );
10375 mca_btl_openib_header_t * hdr = frag -> hdr ;
10476 mca_btl_base_descriptor_t * des = & to_base_frag (frag )-> base ;
105- int qp , ib_rc ;
106- int32_t cm_return ;
77+ int qp , ib_rc , rc ;
10778 bool do_rdma = false;
108- size_t eager_limit ;
79+ size_t size ;
10980
11081 if (OPAL_LIKELY (des -> order == MCA_BTL_NO_ORDER ))
11182 des -> order = frag -> qp_idx ;
11283
11384 qp = des -> order ;
11485
115- if (acruire_wqe (endpoint , frag ) != OPAL_SUCCESS )
86+ if (acquire_wqe (endpoint , frag ) != OPAL_SUCCESS )
11687 return OPAL_ERR_RESOURCE_BUSY ;
11788
118- eager_limit = mca_btl_openib_component .eager_limit +
119- sizeof (mca_btl_openib_header_coalesced_t ) +
120- sizeof (mca_btl_openib_control_header_t );
121- if (des -> des_local -> seg_len + frag -> coalesced_length <= eager_limit &&
122- (des -> des_flags & MCA_BTL_DES_FLAGS_PRIORITY )) {
123- /* High priority frag. Try to send over eager RDMA */
124- if (acquire_eager_rdma_send_credit (endpoint ) == OPAL_SUCCESS )
125- do_rdma = true;
126- }
89+ size = des -> des_segments -> seg_len + frag -> coalesced_length ;
12790
128- if (!do_rdma && acquire_send_credit (endpoint , frag ) != OPAL_SUCCESS ) {
91+ rc = mca_btl_openib_endpoint_credit_acquire (endpoint , qp , prio , size ,
92+ & do_rdma , frag , true);
93+ if (OPAL_UNLIKELY (OPAL_SUCCESS != rc )) {
12994 qp_put_wqe (endpoint , qp );
13095 return OPAL_ERR_RESOURCE_BUSY ;
13196 }
13297
133- BTL_OPENIB_GET_CREDITS (endpoint -> eager_rdma_local .credits , hdr -> credits );
134- if (hdr -> credits )
135- hdr -> credits |= BTL_OPENIB_RDMA_CREDITS_FLAG ;
136-
137- if (!do_rdma ) {
138- if (BTL_OPENIB_QP_TYPE_PP (qp ) && 0 == hdr -> credits ) {
139- BTL_OPENIB_GET_CREDITS (endpoint -> qps [qp ].u .pp_qp .rd_credits , hdr -> credits );
140- }
141- } else {
142- hdr -> credits |= (qp << 11 );
143- }
144-
145- BTL_OPENIB_GET_CREDITS (endpoint -> qps [qp ].u .pp_qp .cm_return , cm_return );
146- /* cm_seen is only 8 bytes, but cm_return is 32 bytes */
147- if (cm_return > 255 ) {
148- hdr -> cm_seen = 255 ;
149- cm_return -= 255 ;
150- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .cm_return , cm_return );
151- } else {
152- hdr -> cm_seen = cm_return ;
153- }
154-
15598 qp_reset_signal_count (endpoint , qp );
15699 ib_rc = post_send (endpoint , frag , do_rdma , 1 );
157100
@@ -161,27 +104,12 @@ int mca_btl_openib_endpoint_post_send(mca_btl_openib_endpoint_t *endpoint,
161104 if (endpoint -> nbo )
162105 BTL_OPENIB_HEADER_NTOH (* hdr );
163106
164- if (BTL_OPENIB_IS_RDMA_CREDITS (hdr -> credits )) {
165- OPAL_THREAD_ADD32 (& endpoint -> eager_rdma_local .credits ,
166- BTL_OPENIB_CREDITS (hdr -> credits ));
167- }
107+ mca_btl_openib_endpoint_credit_release (endpoint , qp , do_rdma , frag );
168108
169109 qp_put_wqe (endpoint , qp );
170110
171- if (do_rdma ) {
172- OPAL_THREAD_ADD32 (& endpoint -> eager_rdma_remote .tokens , 1 );
173- } else {
174- if (BTL_OPENIB_QP_TYPE_PP (qp )) {
175- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .rd_credits ,
176- hdr -> credits );
177- OPAL_THREAD_ADD32 (& endpoint -> qps [qp ].u .pp_qp .sd_credits , 1 );
178- } else if BTL_OPENIB_QP_TYPE_SRQ (qp ){
179- mca_btl_openib_module_t * openib_btl = endpoint -> endpoint_btl ;
180- OPAL_THREAD_ADD32 (& openib_btl -> qps [qp ].u .srq_qp .sd_credits , 1 );
181- }
182- }
183- BTL_ERROR (("error posting send request error %d: %s\n" ,
184- ib_rc , strerror (ib_rc )));
111+ BTL_ERROR (("error posting send request error %d: %s. size = %lu\n" ,
112+ ib_rc , strerror (ib_rc ), size ));
185113 return OPAL_ERROR ;
186114}
187115
@@ -690,8 +618,8 @@ void mca_btl_openib_endpoint_connected(mca_btl_openib_endpoint_t *endpoint)
690618 /* We need to post this one */
691619
692620 if (OPAL_ERROR == mca_btl_openib_endpoint_post_send (endpoint , frag )) {
693- BTL_ERROR (("Error posting send" ));
694- }
621+ BTL_ERROR (("Error posting send" ));
622+ }
695623 }
696624 OPAL_THREAD_UNLOCK (& endpoint -> endpoint_lock );
697625
0 commit comments