Skip to content

Commit cde79bf

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 9bae131 commit cde79bf

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
@@ -634,16 +634,16 @@ static int prepare_device_for_use (mca_btl_openib_device_t *device)
634634

635635
#if OPAL_HAVE_THREADS
636636
if(mca_btl_openib_component.use_async_event_thread) {
637-
mca_btl_openib_async_cmd_t async_command;
637+
mca_btl_openib_async_cmd_t async_command;
638638

639639
/* start the async even thread if it is not already started */
640640
if (start_async_event_thread() != OPAL_SUCCESS)
641641
return OPAL_ERROR;
642642

643643
device->got_fatal_event = false;
644644
device->got_port_event = false;
645-
async_command.a_cmd = OPENIB_ASYNC_CMD_FD_ADD;
646-
async_command.fd = device->ib_dev_context->async_fd;
645+
async_command.a_cmd = OPENIB_ASYNC_CMD_FD_ADD;
646+
async_command.fd = device->ib_dev_context->async_fd;
647647
if (write(mca_btl_openib_component.async_pipe[1],
648648
&async_command, sizeof(mca_btl_openib_async_cmd_t))<0){
649649
BTL_ERROR(("Failed to write to pipe [%d]",errno));
@@ -1721,16 +1721,15 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
17211721
{
17221722
mca_btl_openib_module_t *obtl = (mca_btl_openib_module_t*)btl;
17231723
size_t size = payload_size + header_size;
1724-
size_t eager_limit;
17251724
int qp = frag_size_to_order(obtl, size),
17261725
prio = !(flags & MCA_BTL_DES_FLAGS_PRIORITY),
17271726
ib_rc;
1728-
int32_t cm_return;
17291727
bool do_rdma = false;
17301728
ompi_free_list_item_t* item = NULL;
17311729
mca_btl_openib_frag_t *frag;
17321730
mca_btl_openib_header_t *hdr;
17331731
int send_signaled;
1732+
int rc;
17341733

17351734
OPAL_THREAD_LOCK(&ep->endpoint_lock);
17361735

@@ -1752,45 +1751,26 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
17521751

17531752
/* Allocate WQE */
17541753
if(OPAL_UNLIKELY(qp_get_wqe(ep, qp) < 0)) {
1755-
goto no_credits_or_wqe;
1756-
}
1757-
1758-
/* eager rdma or send ? Check eager rdma credits */
1759-
/* Note: Maybe we want to implement isend only for eager rdma ?*/
1760-
eager_limit = mca_btl_openib_component.eager_limit +
1761-
sizeof(mca_btl_openib_header_coalesced_t) +
1762-
sizeof(mca_btl_openib_control_header_t);
1763-
1764-
if(OPAL_LIKELY(size <= eager_limit)) {
1765-
if(acquire_eager_rdma_send_credit(ep) == OPAL_SUCCESS) {
1766-
do_rdma = true;
1767-
}
1768-
}
1769-
1770-
/* if(!do_rdma && acquire_send_credit(ep, frag) != OPAL_SUCCESS) { */
1771-
/* Check send credits if it is no rdma */
1772-
if(!do_rdma) {
1773-
if(BTL_OPENIB_QP_TYPE_PP(qp)) {
1774-
if(OPAL_UNLIKELY(OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, -1) < 0)){
1775-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, 1);
1776-
goto no_credits_or_wqe;
1777-
}
1778-
} else {
1779-
if(OPAL_UNLIKELY(OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, -1) < 0)){
1780-
OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, 1);
1781-
goto no_credits_or_wqe;
1782-
}
1783-
}
1754+
goto cant_send_wqe;
17841755
}
17851756

17861757
/* Allocate fragment */
17871758
OMPI_FREE_LIST_GET_MT(&obtl->device->qps[qp].send_free, item);
17881759
if(OPAL_UNLIKELY(NULL == item)) {
17891760
/* we don't return NULL because maybe later we will try to coalesce */
1790-
goto no_frags;
1761+
goto cant_send_wqe;
17911762
}
17921763
frag = to_base_frag(item);
17931764
hdr = to_send_frag(item)->hdr;
1765+
1766+
/* eager rdma or send ? Check eager rdma credits */
1767+
/* Note: Maybe we want to implement isend only for eager rdma ?*/
1768+
rc = mca_btl_openib_endpoint_credit_acquire (ep, qp, prio, size, &do_rdma,
1769+
to_send_frag(frag), false);
1770+
if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) {
1771+
goto cant_send_frag;
1772+
}
1773+
17941774
frag->segment.base.seg_len = size;
17951775
frag->base.order = qp;
17961776
frag->base.des_flags = flags;
@@ -1815,37 +1795,14 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
18151795
assert(max_data == payload_size);
18161796
}
18171797

1818-
/* Set all credits */
1819-
BTL_OPENIB_GET_CREDITS(ep->eager_rdma_local.credits, hdr->credits);
1820-
if(hdr->credits)
1821-
hdr->credits |= BTL_OPENIB_RDMA_CREDITS_FLAG;
1822-
1823-
if(!do_rdma) {
1824-
if(BTL_OPENIB_QP_TYPE_PP(qp) && 0 == hdr->credits) {
1825-
BTL_OPENIB_GET_CREDITS(ep->qps[qp].u.pp_qp.rd_credits, hdr->credits);
1826-
}
1827-
} else {
1828-
hdr->credits |= (qp << 11);
1829-
}
1830-
1831-
BTL_OPENIB_GET_CREDITS(ep->qps[qp].u.pp_qp.cm_return, cm_return);
1832-
/* cm_seen is only 8 bytes, but cm_return is 32 bytes */
1833-
if(cm_return > 255) {
1834-
hdr->cm_seen = 255;
1835-
cm_return -= 255;
1836-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.cm_return, cm_return);
1837-
} else {
1838-
hdr->cm_seen = cm_return;
1839-
}
1840-
18411798
#if BTL_OPENIB_FAILOVER_ENABLED
18421799
send_signaled = 1;
18431800
#else
18441801
send_signaled = qp_need_signal(ep, qp, payload_size + header_size, do_rdma);
18451802
#endif
18461803
ib_rc = post_send(ep, to_send_frag(item), do_rdma, send_signaled);
18471804

1848-
if(!ib_rc) {
1805+
if (!ib_rc) {
18491806
if (0 == send_signaled) {
18501807
MCA_BTL_IB_FRAG_RETURN(frag);
18511808
}
@@ -1856,33 +1813,21 @@ int mca_btl_openib_sendi( struct mca_btl_base_module_t* btl,
18561813
}
18571814
#endif
18581815
OPAL_THREAD_UNLOCK(&ep->endpoint_lock);
1816+
18591817
return OPAL_SUCCESS;
18601818
}
18611819

18621820
/* Failed to send, do clean up all allocated resources */
1863-
if(ep->nbo) {
1821+
if (ep->nbo) {
18641822
BTL_OPENIB_HEADER_NTOH(*hdr);
18651823
}
1866-
if(BTL_OPENIB_IS_RDMA_CREDITS(hdr->credits)) {
1867-
OPAL_THREAD_ADD32(&ep->eager_rdma_local.credits,
1868-
BTL_OPENIB_CREDITS(hdr->credits));
1869-
}
1870-
if (!do_rdma && BTL_OPENIB_QP_TYPE_PP(qp)) {
1871-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.rd_credits,
1872-
hdr->credits);
1873-
}
1874-
no_frags:
1875-
if(do_rdma) {
1876-
OPAL_THREAD_ADD32(&ep->eager_rdma_remote.tokens, 1);
1877-
} else {
1878-
if(BTL_OPENIB_QP_TYPE_PP(qp)) {
1879-
OPAL_THREAD_ADD32(&ep->qps[qp].u.pp_qp.sd_credits, 1);
1880-
} else if BTL_OPENIB_QP_TYPE_SRQ(qp){
1881-
OPAL_THREAD_ADD32(&obtl->qps[qp].u.srq_qp.sd_credits, 1);
1882-
}
1883-
}
1884-
no_credits_or_wqe:
1885-
qp_put_wqe(ep, qp);
1824+
1825+
mca_btl_openib_endpoint_credit_release (ep, qp, do_rdma, to_send_frag(frag));
1826+
1827+
cant_send_frag:
1828+
MCA_BTL_IB_FRAG_RETURN(frag);
1829+
cant_send_wqe:
1830+
qp_put_wqe (ep, qp);
18861831
cant_send:
18871832
OPAL_THREAD_UNLOCK(&ep->endpoint_lock);
18881833
/* 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.
@@ -54,7 +54,7 @@
5454
static void mca_btl_openib_endpoint_construct(mca_btl_base_endpoint_t* endpoint);
5555
static 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 */
10374
int 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

Comments
 (0)