Skip to content

Commit 42ac1f1

Browse files
committed
btl/openib: misc cleanup (tabs, etc) and put credit code into a common place (was duplicated in the send and sendi paths)
1 parent 3a5516b commit 42ac1f1

File tree

3 files changed

+136
-168
lines changed

3 files changed

+136
-168
lines changed

opal/mca/btl/openib/btl_openib.c

Lines changed: 25 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -617,16 +617,16 @@ static int prepare_device_for_use (mca_btl_openib_device_t *device)
617617

618618
#if OPAL_HAVE_THREADS
619619
if(mca_btl_openib_component.use_async_event_thread) {
620-
mca_btl_openib_async_cmd_t async_command;
620+
mca_btl_openib_async_cmd_t async_command;
621621

622622
/* start the async even thread if it is not already started */
623623
if (start_async_event_thread() != OPAL_SUCCESS)
624624
return OPAL_ERROR;
625625

626626
device->got_fatal_event = false;
627627
device->got_port_event = false;
628-
async_command.a_cmd = OPENIB_ASYNC_CMD_FD_ADD;
629-
async_command.fd = device->ib_dev_context->async_fd;
628+
async_command.a_cmd = OPENIB_ASYNC_CMD_FD_ADD;
629+
async_command.fd = device->ib_dev_context->async_fd;
630630
if (write(mca_btl_openib_component.async_pipe[1],
631631
&async_command, sizeof(mca_btl_openib_async_cmd_t))<0){
632632
BTL_ERROR(("Failed to write to pipe [%d]",errno));
@@ -1704,16 +1704,15 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
17041704
{
17051705
mca_btl_openib_module_t *obtl = (mca_btl_openib_module_t*)btl;
17061706
size_t size = payload_size + header_size;
1707-
size_t eager_limit;
17081707
int qp = frag_size_to_order(obtl, size),
17091708
prio = !(flags & MCA_BTL_DES_FLAGS_PRIORITY),
17101709
ib_rc;
1711-
int32_t cm_return;
17121710
bool do_rdma = false;
17131711
ompi_free_list_item_t* item = NULL;
17141712
mca_btl_openib_frag_t *frag;
17151713
mca_btl_openib_header_t *hdr;
17161714
int send_signaled;
1715+
int rc;
17171716

17181717
OPAL_THREAD_LOCK(&ep->endpoint_lock);
17191718

@@ -1735,45 +1734,26 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
17351734

17361735
/* Allocate WQE */
17371736
if(OPAL_UNLIKELY(qp_get_wqe(ep, qp) < 0)) {
1738-
goto no_credits_or_wqe;
1739-
}
1740-
1741-
/* eager rdma or send ? Check eager rdma credits */
1742-
/* Note: Maybe we want to implement isend only for eager rdma ?*/
1743-
eager_limit = mca_btl_openib_component.eager_limit +
1744-
sizeof(mca_btl_openib_header_coalesced_t) +
1745-
sizeof(mca_btl_openib_control_header_t);
1746-
1747-
if(OPAL_LIKELY(size <= eager_limit)) {
1748-
if(acquire_eager_rdma_send_credit(ep) == OPAL_SUCCESS) {
1749-
do_rdma = true;
1750-
}
1751-
}
1752-
1753-
/* if(!do_rdma && acquire_send_credit(ep, frag) != OPAL_SUCCESS) { */
1754-
/* Check send credits if it is no rdma */
1755-
if(!do_rdma) {
1756-
if(BTL_OPENIB_QP_TYPE_PP(qp)) {
1757-
if(OPAL_UNLIKELY(OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, -1) < 0)){
1758-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, 1);
1759-
goto no_credits_or_wqe;
1760-
}
1761-
} else {
1762-
if(OPAL_UNLIKELY(OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, -1) < 0)){
1763-
OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, 1);
1764-
goto no_credits_or_wqe;
1765-
}
1766-
}
1737+
goto cant_send_wqe;
17671738
}
17681739

17691740
/* Allocate fragment */
17701741
OMPI_FREE_LIST_GET_MT(&obtl->device->qps[qp].send_free, item);
17711742
if(OPAL_UNLIKELY(NULL == item)) {
17721743
/* we don't return NULL because maybe later we will try to coalesce */
1773-
goto no_frags;
1744+
goto cant_send_wqe;
17741745
}
17751746
frag = to_base_frag(item);
17761747
hdr = to_send_frag(item)->hdr;
1748+
1749+
/* eager rdma or send ? Check eager rdma credits */
1750+
/* Note: Maybe we want to implement isend only for eager rdma ?*/
1751+
rc = mca_btl_openib_endpoint_credit_acquire (ep, qp, prio, size, &do_rdma,
1752+
to_send_frag(frag), false);
1753+
if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) {
1754+
goto cant_send_frag;
1755+
}
1756+
17771757
frag->segment.base.seg_len = size;
17781758
frag->base.order = qp;
17791759
frag->base.des_flags = flags;
@@ -1798,37 +1778,14 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
17981778
assert(max_data == payload_size);
17991779
}
18001780

1801-
/* Set all credits */
1802-
BTL_OPENIB_GET_CREDITS(ep->eager_rdma_local.credits, hdr->credits);
1803-
if(hdr->credits)
1804-
hdr->credits |= BTL_OPENIB_RDMA_CREDITS_FLAG;
1805-
1806-
if(!do_rdma) {
1807-
if(BTL_OPENIB_QP_TYPE_PP(qp) && 0 == hdr->credits) {
1808-
BTL_OPENIB_GET_CREDITS(ep->qps[qp].u.pp_qp.rd_credits, hdr->credits);
1809-
}
1810-
} else {
1811-
hdr->credits |= (qp << 11);
1812-
}
1813-
1814-
BTL_OPENIB_GET_CREDITS(ep->qps[qp].u.pp_qp.cm_return, cm_return);
1815-
/* cm_seen is only 8 bytes, but cm_return is 32 bytes */
1816-
if(cm_return > 255) {
1817-
hdr->cm_seen = 255;
1818-
cm_return -= 255;
1819-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.cm_return, cm_return);
1820-
} else {
1821-
hdr->cm_seen = cm_return;
1822-
}
1823-
18241781
#if BTL_OPENIB_FAILOVER_ENABLED
18251782
send_signaled = 1;
18261783
#else
18271784
send_signaled = qp_need_signal(ep, qp, payload_size + header_size, do_rdma);
18281785
#endif
18291786
ib_rc = post_send(ep, to_send_frag(item), do_rdma, send_signaled);
18301787

1831-
if(!ib_rc) {
1788+
if (!ib_rc) {
18321789
if (0 == send_signaled) {
18331790
MCA_BTL_IB_FRAG_RETURN(frag);
18341791
}
@@ -1839,33 +1796,21 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
18391796
}
18401797
#endif
18411798
OPAL_THREAD_UNLOCK(&ep->endpoint_lock);
1799+
18421800
return OPAL_SUCCESS;
18431801
}
18441802

18451803
/* Failed to send, do clean up all allocated resources */
1846-
if(ep->nbo) {
1804+
if (ep->nbo) {
18471805
BTL_OPENIB_HEADER_NTOH(*hdr);
18481806
}
1849-
if(BTL_OPENIB_IS_RDMA_CREDITS(hdr->credits)) {
1850-
OPAL_THREAD_ADD32(&ep->eager_rdma_local.credits,
1851-
BTL_OPENIB_CREDITS(hdr->credits));
1852-
}
1853-
if (!do_rdma && BTL_OPENIB_QP_TYPE_PP(qp)) {
1854-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.rd_credits,
1855-
hdr->credits);
1856-
}
1857-
no_frags:
1858-
if(do_rdma) {
1859-
OPAL_THREAD_ADD32(&ep->eager_rdma_remote.tokens, 1);
1860-
} else {
1861-
if(BTL_OPENIB_QP_TYPE_PP(qp)) {
1862-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, 1);
1863-
} else if BTL_OPENIB_QP_TYPE_SRQ(qp){
1864-
OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, 1);
1865-
}
1866-
}
1867-
no_credits_or_wqe:
1868-
qp_put_wqe(ep, qp);
1807+
1808+
mca_btl_openib_endpoint_credit_release (ep, qp, do_rdma, to_send_frag(frag));
1809+
1810+
cant_send_frag:
1811+
MCA_BTL_IB_FRAG_RETURN(frag);
1812+
cant_send_wqe:
1813+
qp_put_wqe (ep, qp);
18691814
cant_send:
18701815
OPAL_THREAD_UNLOCK(&ep->endpoint_lock);
18711816
/* We can not send the data directly, so we just return descriptor */

opal/mca/btl/openib/btl_openib_endpoint.c

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -11,7 +11,7 @@
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.
@@ -51,7 +51,7 @@
5151
static void mca_btl_openib_endpoint_construct(mca_btl_base_endpoint_t* endpoint);
5252
static 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 */
10071
int 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

Comments
 (0)