/* * Copyright (c) 2004-2005 The Trustees of Indiana University. * All rights reserved. * Copyright (c) 2004-2005 The Trustees of the University of Tennessee. * All rights reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "ompi_config.h" #include #include "ompi/include/constants.h" #include "mca/pml/pml.h" #include "mca/btl/btl.h" #include "mca/errmgr/errmgr.h" #include "mca/mpool/mpool.h" #include "pml_ob1.h" #include "pml_ob1_hdr.h" #include "pml_ob1_proc.h" #include "pml_ob1_sendreq.h" #include "pml_ob1_rdmafrag.h" #include "pml_ob1_recvreq.h" #include "pml_ob1_endpoint.h" #include "mca/bml/base/base.h" static int mca_pml_ob1_send_request_fini(struct ompi_request_t** request) { MCA_PML_OB1_FINI(request); return OMPI_SUCCESS; } static int mca_pml_ob1_send_request_free(struct ompi_request_t** request) { MCA_PML_OB1_FREE(request); return OMPI_SUCCESS; } static int mca_pml_ob1_send_request_cancel(struct ompi_request_t* request, int complete) { /* we dont cancel send requests by now */ return OMPI_SUCCESS; } static void mca_pml_ob1_send_request_construct(mca_pml_ob1_send_request_t* req) { req->req_send.req_base.req_type = MCA_PML_REQUEST_SEND; req->req_send.req_base.req_ompi.req_fini = mca_pml_ob1_send_request_fini; req->req_send.req_base.req_ompi.req_free = mca_pml_ob1_send_request_free; req->req_send.req_base.req_ompi.req_cancel = mca_pml_ob1_send_request_cancel; } static void mca_pml_ob1_send_request_destruct(mca_pml_ob1_send_request_t* req) { } OBJ_CLASS_INSTANCE( mca_pml_ob1_send_request_t, mca_pml_base_send_request_t, mca_pml_ob1_send_request_construct, mca_pml_ob1_send_request_destruct); /** * Completion of a short message - nothing left to schedule. */ void mca_pml_ob1_match_completion( struct mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* descriptor, int status) { mca_pml_ob1_send_request_t* sendreq = (mca_pml_ob1_send_request_t*)descriptor->des_cbdata; mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) descriptor->des_context; /* check completion status */ if(OMPI_SUCCESS != status) { /* TSW - FIX */ opal_output(0, "%s:%d FATAL", __FILE__, __LINE__); orte_errmgr.abort(); } /* attempt to cache the descriptor */ MCA_BML_BASE_BTL_DES_RETURN( bml_btl, descriptor ); /* signal request completion */ OPAL_THREAD_LOCK(&ompi_request_lock); sendreq->req_bytes_delivered = sendreq->req_send.req_bytes_packed; MCA_PML_OB1_SEND_REQUEST_COMPLETE(sendreq); OPAL_THREAD_UNLOCK(&ompi_request_lock); } /* * Completion of the first fragment of a long message that * requires an acknowledgement */ static void mca_pml_ob1_rndv_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* descriptor, int status) { mca_pml_ob1_send_request_t* sendreq = (mca_pml_ob1_send_request_t*)descriptor->des_cbdata; mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) descriptor->des_context; /* check completion status */ if(OMPI_SUCCESS != status) { /* TSW - FIX */ opal_output(0, "%s:%d FATAL", __FILE__, __LINE__); orte_errmgr.abort(); } /* count bytes of user data actually delivered */ OPAL_THREAD_LOCK(&ompi_request_lock); MCA_PML_OB1_SEND_REQUEST_SET_BYTES_DELIVERED(sendreq,descriptor,sizeof(mca_pml_ob1_rendezvous_hdr_t)); OPAL_THREAD_UNLOCK(&ompi_request_lock); /* return the descriptor */ mca_bml_base_free(bml_btl, descriptor); /* advance the request */ MCA_PML_OB1_SEND_REQUEST_ADVANCE(sendreq); /* check for pending requests */ MCA_PML_OB1_SEND_REQUEST_PROCESS_PENDING(); } /** * Completion of a get request. */ static void mca_pml_ob1_rget_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* des, int status) { mca_pml_ob1_send_request_t* sendreq = (mca_pml_ob1_send_request_t*)des->des_cbdata; /* count bytes of user data actually delivered and check for request completion */ OPAL_THREAD_LOCK(&ompi_request_lock); MCA_PML_OB1_SEND_REQUEST_SET_BYTES_DELIVERED(sendreq,des,0); if (sendreq->req_bytes_delivered == sendreq->req_send.req_bytes_packed) { MCA_PML_OB1_SEND_REQUEST_COMPLETE(sendreq); } OPAL_THREAD_LOCK(&ompi_request_lock); /* release resources */ btl->btl_free(btl,des); } /** * Completion of a control message - return resources. */ static void mca_pml_ob1_ctl_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* descriptor, int status) { /* return the descriptor */ mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) descriptor->des_context; mca_bml_base_free(bml_btl, descriptor); } /** * Completion of additional fragments of a large message - may need * to schedule additional fragments. */ static void mca_pml_ob1_frag_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* descriptor, int status) { mca_pml_ob1_send_request_t* sendreq = (mca_pml_ob1_send_request_t*)descriptor->des_cbdata; mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) descriptor->des_context; bool schedule; /* check completion status */ if(OMPI_SUCCESS != status) { /* TSW - FIX */ opal_output(0, "%s:%d FATAL", __FILE__, __LINE__); orte_errmgr.abort(); } /* check for request completion */ OPAL_THREAD_LOCK(&ompi_request_lock); /* count bytes of user data actually delivered */ MCA_PML_OB1_SEND_REQUEST_SET_BYTES_DELIVERED(sendreq,descriptor,sizeof(mca_pml_ob1_frag_hdr_t)); if (OPAL_THREAD_ADD_SIZE_T(&sendreq->req_pipeline_depth,-1) == 0 && sendreq->req_bytes_delivered == sendreq->req_send.req_bytes_packed) { MCA_PML_OB1_SEND_REQUEST_COMPLETE(sendreq); schedule = false; } else { schedule = true; } OPAL_THREAD_UNLOCK(&ompi_request_lock); if(schedule) { mca_pml_ob1_send_request_schedule(sendreq); } /* return the descriptor */ mca_bml_base_free(bml_btl, descriptor); /* check for pending requests */ MCA_PML_OB1_SEND_REQUEST_PROCESS_PENDING(); } /** * BTL requires "specially" allocated memory. Request a segment that * is used for initial hdr and any eager data. */ int mca_pml_ob1_send_request_start_copy( mca_pml_ob1_send_request_t* sendreq, mca_bml_base_btl_t* bml_btl) { int rc; mca_btl_base_descriptor_t* descriptor; mca_btl_base_segment_t* segment; mca_pml_ob1_hdr_t* hdr; size_t size = sendreq->req_send.req_bytes_packed; struct iovec iov; unsigned int iov_count; size_t max_data; bool ack = false; /* determine first fragment size */ if(size > bml_btl->btl_eager_limit - sizeof(mca_pml_ob1_hdr_t)) { size = bml_btl->btl_eager_limit - sizeof(mca_pml_ob1_hdr_t); ack = true; } else if (sendreq->req_send.req_send_mode == MCA_PML_BASE_SEND_SYNCHRONOUS) { ack = true; } /* if an acknowledgment is not required - can get by w/ shorter hdr */ if (ack == false) { int32_t free_after; /* allocate descriptor */ mca_bml_base_alloc(bml_btl, &descriptor, sizeof(mca_pml_ob1_match_hdr_t) + size); if(NULL == descriptor) { return OMPI_ERR_OUT_OF_RESOURCE; } segment = descriptor->des_src; /* pack the data into the supplied buffer */ iov.iov_base = (void*)((unsigned char*)segment->seg_addr.pval + sizeof(mca_pml_ob1_match_hdr_t)); iov.iov_len = size; iov_count = 1; max_data = size; if((rc = ompi_convertor_pack( &sendreq->req_send.req_convertor, &iov, &iov_count, &max_data, &free_after)) < 0) { mca_bml_base_free(bml_btl, descriptor); return rc; } /* build match header */ hdr = (mca_pml_ob1_hdr_t*)segment->seg_addr.pval; hdr->hdr_common.hdr_flags = 0; hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_MATCH; hdr->hdr_match.hdr_ctx = sendreq->req_send.req_base.req_comm->c_contextid; hdr->hdr_match.hdr_src = sendreq->req_send.req_base.req_comm->c_my_rank; hdr->hdr_match.hdr_dst = sendreq->req_send.req_base.req_peer; hdr->hdr_match.hdr_tag = sendreq->req_send.req_base.req_tag; hdr->hdr_match.hdr_seq = sendreq->req_send.req_base.req_sequence; /* update lengths */ segment->seg_len = sizeof(mca_pml_ob1_match_hdr_t) + max_data; sendreq->req_send_offset = max_data; sendreq->req_rdma_offset = max_data; /* short message */ descriptor->des_cbfunc = mca_pml_ob1_match_completion; /* request is complete at mpi level */ ompi_request_complete((ompi_request_t*)sendreq); /* rendezvous header is required */ } else { struct mca_mpool_base_registration_t* registration = NULL; struct mca_bml_base_btl_t* reg_btl = NULL; bool do_rdma; /* check to see if memory is registered */ sendreq->req_chunk = mca_mpool_base_find(sendreq->req_send.req_addr); if(NULL != sendreq->req_chunk) { struct mca_mpool_base_reg_mpool_t *reg = sendreq->req_chunk->mpools; while(reg->mpool != NULL) { if(NULL != (reg_btl = mca_bml_base_btl_array_find(&sendreq->bml_endpoint->btl_rdma, (mca_btl_base_module_t*) reg->user_data))) { registration = reg->mpool_registration; break; } reg++; } } /* if the data is already registed or leave_pinned is set - then we * will attempt to do an rdma of the entire message. */ do_rdma = (reg_btl != NULL || mca_pml_ob1.leave_pinned) && ompi_convertor_need_buffers(&sendreq->req_send.req_convertor) == false; if(do_rdma == false || (reg_btl != NULL && (reg_btl->btl_flags & MCA_BTL_FLAGS_GET) == 0)) { int32_t free_after; /* allocate space for hdr + first fragment */ mca_bml_base_alloc(bml_btl, &descriptor, sizeof(mca_pml_ob1_rendezvous_hdr_t) + size); if(NULL == descriptor) { return OMPI_ERR_OUT_OF_RESOURCE; } segment = descriptor->des_src; /* rdma put is supported rather than rdma get */ if(do_rdma) { max_data = 0; /* dont eager send any data */ } else { iov.iov_base = (void*)((unsigned char*)segment->seg_addr.pval + sizeof(mca_pml_ob1_rendezvous_hdr_t)); iov.iov_len = size; iov_count = 1; max_data = size; if((rc = ompi_convertor_pack( &sendreq->req_send.req_convertor, &iov, &iov_count, &max_data, &free_after)) < 0) { mca_bml_base_free(bml_btl , descriptor); return rc; } } /* build hdr */ hdr = (mca_pml_ob1_hdr_t*)segment->seg_addr.pval; hdr->hdr_common.hdr_flags = (sendreq->req_chunk != NULL ? MCA_PML_OB1_HDR_FLAGS_PIN : 0); hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_RNDV; hdr->hdr_match.hdr_ctx = sendreq->req_send.req_base.req_comm->c_contextid; hdr->hdr_match.hdr_src = sendreq->req_send.req_base.req_comm->c_my_rank; hdr->hdr_match.hdr_dst = sendreq->req_send.req_base.req_peer; hdr->hdr_match.hdr_tag = sendreq->req_send.req_base.req_tag; hdr->hdr_match.hdr_seq = sendreq->req_send.req_base.req_sequence; hdr->hdr_rndv.hdr_msg_length = sendreq->req_send.req_bytes_packed; hdr->hdr_rndv.hdr_src_req.pval = sendreq; /* update lengths with number of bytes actually packed */ segment->seg_len = sizeof(mca_pml_ob1_rendezvous_hdr_t) + max_data; sendreq->req_send_offset = max_data; /* first fragment of a long message */ descriptor->des_cbfunc = mca_pml_ob1_rndv_completion; /* the buffer is already pinned */ } else { mca_btl_base_descriptor_t* src; size_t i; /* prepare descriptor */ if(reg_btl != NULL) { bml_btl = reg_btl; } mca_bml_base_prepare_src( bml_btl, registration, &sendreq->req_send.req_convertor, 0, &sendreq->req_send.req_bytes_packed, &src); if(NULL == src) { return OMPI_ERR_OUT_OF_RESOURCE; } src->des_cbfunc = mca_pml_ob1_rget_completion; src->des_cbdata = sendreq; /* allocate space for hdr + segment list */ mca_bml_base_alloc(bml_btl, &descriptor, sizeof(mca_pml_ob1_rget_hdr_t) + (sizeof(mca_btl_base_segment_t)*(src->des_src_cnt-1))); if(NULL == descriptor) { return OMPI_ERR_OUT_OF_RESOURCE; } segment = descriptor->des_src; /* build match header */ hdr = (mca_pml_ob1_hdr_t*)segment->seg_addr.pval; hdr->hdr_common.hdr_flags = (sendreq->req_chunk != NULL ? MCA_PML_OB1_HDR_FLAGS_PIN : 0); hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_RGET; hdr->hdr_match.hdr_ctx = sendreq->req_send.req_base.req_comm->c_contextid; hdr->hdr_match.hdr_src = sendreq->req_send.req_base.req_comm->c_my_rank; hdr->hdr_match.hdr_dst = sendreq->req_send.req_base.req_peer; hdr->hdr_match.hdr_tag = sendreq->req_send.req_base.req_tag; hdr->hdr_match.hdr_seq = sendreq->req_send.req_base.req_sequence; hdr->hdr_rndv.hdr_msg_length = sendreq->req_send.req_bytes_packed; hdr->hdr_rndv.hdr_src_req.pval = sendreq; hdr->hdr_rget.hdr_des.pval = src; hdr->hdr_rget.hdr_seg_cnt = src->des_src_cnt; for(i=0; ides_src_cnt; i++) hdr->hdr_rget.hdr_segs[i] = src->des_src[i]; descriptor->des_cbfunc = mca_pml_ob1_ctl_completion; } } descriptor->des_flags |= MCA_BTL_DES_FLAGS_PRIORITY; descriptor->des_cbdata = sendreq; /* send */ rc = mca_bml_base_send(bml_btl, descriptor, MCA_BTL_TAG_PML); if(OMPI_SUCCESS != rc) { mca_bml_base_free(bml_btl, descriptor ); } return rc; } /** * BTL can send directly from user buffer so allow the BTL * to prepare the segment list. */ int mca_pml_ob1_send_request_start_prepare( mca_pml_ob1_send_request_t* sendreq, mca_bml_base_btl_t* bml_btl) { int rc; mca_btl_base_descriptor_t* descriptor; mca_btl_base_segment_t* segment; mca_pml_ob1_hdr_t* hdr; size_t size = sendreq->req_send.req_bytes_packed; bool ack = false; /* determine first fragment size */ if(size > bml_btl->btl_eager_limit - sizeof(mca_pml_ob1_hdr_t)) { size = bml_btl->btl_eager_limit - sizeof(mca_pml_ob1_hdr_t); ack = true; } else if (sendreq->req_send.req_send_mode == MCA_PML_BASE_SEND_SYNCHRONOUS) { ack = true; } /* if an acknowledgment is not required - can get by w/ shorter hdr */ if (ack == false) { /* prepare descriptor */ mca_bml_base_prepare_src( bml_btl, NULL, &sendreq->req_send.req_convertor, sizeof(mca_pml_ob1_match_hdr_t), &size, &descriptor); if(NULL == descriptor) { return OMPI_ERR_OUT_OF_RESOURCE; } segment = descriptor->des_src; /* build match header */ hdr = (mca_pml_ob1_hdr_t*)segment->seg_addr.pval; hdr->hdr_common.hdr_flags = 0; hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_MATCH; hdr->hdr_match.hdr_ctx = sendreq->req_send.req_base.req_comm->c_contextid; hdr->hdr_match.hdr_src = sendreq->req_send.req_base.req_comm->c_my_rank; hdr->hdr_match.hdr_dst = sendreq->req_send.req_base.req_peer; hdr->hdr_match.hdr_tag = sendreq->req_send.req_base.req_tag; hdr->hdr_match.hdr_seq = sendreq->req_send.req_base.req_sequence; /* short message */ descriptor->des_cbfunc = mca_pml_ob1_match_completion; /* update lengths */ sendreq->req_send_offset = size; sendreq->req_rdma_offset = size; /* request is complete at mpi level */ ompi_request_complete((ompi_request_t*)sendreq); /* rendezvous header is required */ } else { /* check to see if memory is registered */ sendreq->req_chunk = mca_mpool_base_find(sendreq->req_send.req_addr); /* if the buffer is not pinned and leave pinned is false we eagerly send data to cover the cost of pinning the recv buffers on the peer */ if(size && NULL == sendreq->req_chunk && !mca_pml_ob1.leave_pinned) { /* prepare descriptor */ mca_bml_base_prepare_src( bml_btl, NULL, &sendreq->req_send.req_convertor, sizeof(mca_pml_ob1_rendezvous_hdr_t), &size, &descriptor); } /* if the buffer is pinned or leave pinned is true we do not eagerly * send any data */ else { /* allocate space for hdr only */ mca_bml_base_alloc(bml_btl, &descriptor, sizeof(mca_pml_ob1_rendezvous_hdr_t)); size = 0; } if(NULL == descriptor) { return OMPI_ERR_OUT_OF_RESOURCE; } segment = descriptor->des_src; /* build hdr */ hdr = (mca_pml_ob1_hdr_t*)segment->seg_addr.pval; hdr->hdr_common.hdr_flags = (sendreq->req_chunk != NULL ? MCA_PML_OB1_HDR_FLAGS_PIN : 0); hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_RNDV; hdr->hdr_match.hdr_ctx = sendreq->req_send.req_base.req_comm->c_contextid; hdr->hdr_match.hdr_src = sendreq->req_send.req_base.req_comm->c_my_rank; hdr->hdr_match.hdr_dst = sendreq->req_send.req_base.req_peer; hdr->hdr_match.hdr_tag = sendreq->req_send.req_base.req_tag; hdr->hdr_match.hdr_seq = sendreq->req_send.req_base.req_sequence; hdr->hdr_rndv.hdr_msg_length = sendreq->req_send.req_bytes_packed; hdr->hdr_rndv.hdr_src_req.pval = sendreq; /* first fragment of a long message */ descriptor->des_cbfunc = mca_pml_ob1_rndv_completion; sendreq->req_send_offset = size; } descriptor->des_flags |= MCA_BTL_DES_FLAGS_PRIORITY; descriptor->des_cbdata = sendreq; /* send */ rc = mca_bml_base_send( bml_btl, descriptor, MCA_BTL_TAG_PML); if(OMPI_SUCCESS != rc) { mca_bml_base_free(bml_btl, descriptor ); } return rc; } /** * */ int mca_pml_ob1_send_request_schedule(mca_pml_ob1_send_request_t* sendreq) { /* * Only allow one thread in this routine for a given request. * However, we cannot block callers on a mutex, so simply keep track * of the number of times the routine has been called and run through * the scheduling logic once for every call. */ mca_bml_base_endpoint_t* bml_endpoint = sendreq->bml_endpoint; if(OPAL_THREAD_ADD32(&sendreq->req_lock,1) == 1) { do { /* allocate remaining bytes to BTLs */ size_t bytes_remaining = sendreq->req_rdma_offset - sendreq->req_send_offset; while(bytes_remaining > 0 && (sendreq->req_pipeline_depth < mca_pml_ob1.send_pipeline_depth || sendreq->req_rdma_offset < sendreq->req_send.req_bytes_packed)) { mca_pml_ob1_frag_hdr_t* hdr; mca_btl_base_descriptor_t* des; int rc; size_t size; mca_bml_base_btl_t* bml_btl = mca_bml_base_btl_array_get_next(&bml_endpoint->btl_send); size_t num_btl_avail = bml_endpoint->btl_rdma.arr_size; if(num_btl_avail == 1 || bytes_remaining < bml_btl->btl_min_send_size) { size = bytes_remaining; /* otherwise attempt to give the BTL a percentage of the message * based on a weighting factor. for simplicity calculate this as * a percentage of the overall message length (regardless of amount * previously assigned) */ } else { size = (bml_btl->btl_weight * bytes_remaining) / 100; } /* makes sure that we don't exceed BTL max send size */ if (bml_btl->btl_max_send_size != 0 && size > bml_btl->btl_max_send_size - sizeof(mca_pml_ob1_frag_hdr_t)) { size = bml_btl->btl_max_send_size - sizeof(mca_pml_ob1_frag_hdr_t); } /* pack into a descriptor */ ompi_convertor_set_position(&sendreq->req_send.req_convertor, &sendreq->req_send_offset); mca_bml_base_prepare_src( bml_btl, NULL, &sendreq->req_send.req_convertor, sizeof(mca_pml_ob1_frag_hdr_t), &size, &des ); if(des == NULL) { OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.send_pending, (opal_list_item_t*)sendreq); OPAL_THREAD_UNLOCK(&mca_pml_ob1.lock); break; } des->des_cbfunc = mca_pml_ob1_frag_completion; des->des_cbdata = sendreq; /* setup header */ hdr = (mca_pml_ob1_frag_hdr_t*)des->des_src->seg_addr.pval; hdr->hdr_common.hdr_flags = 0; hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_FRAG; hdr->hdr_frag_offset = sendreq->req_send_offset; hdr->hdr_src_req.pval = sendreq; hdr->hdr_dst_req = sendreq->req_recv; /* update state */ sendreq->req_send_offset += size; OPAL_THREAD_ADD_SIZE_T(&sendreq->req_pipeline_depth,1); /* initiate send - note that this may complete before the call returns */ rc = mca_bml_base_send( bml_btl, des, MCA_BTL_TAG_PML); if(rc == OMPI_SUCCESS) { bytes_remaining -= size; } else { sendreq->req_send_offset -= size; OPAL_THREAD_ADD_SIZE_T(&sendreq->req_pipeline_depth,-1); mca_bml_base_free(bml_btl,des); OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.send_pending, (opal_list_item_t*)sendreq); OPAL_THREAD_UNLOCK(&mca_pml_ob1.lock); break; } mca_pml_ob1_progress(); } } while (OPAL_THREAD_ADD32(&sendreq->req_lock,-1) > 0); } return OMPI_SUCCESS; } /** * Return resources used by the RDMA */ static void mca_pml_ob1_fin_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* des, int status) { mca_pml_ob1_rdma_frag_t* frag = (mca_pml_ob1_rdma_frag_t*)des->des_cbdata; mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) des->des_context; MCA_PML_OB1_RDMA_FRAG_RETURN(frag); MCA_BML_BASE_BTL_DES_RETURN(bml_btl, des); } /** * An RDMA put operation has completed: * (1) Update request status and if required set completed * (2) Send FIN control message to the destination */ static void mca_pml_ob1_put_completion( mca_btl_base_module_t* btl, struct mca_btl_base_endpoint_t* ep, struct mca_btl_base_descriptor_t* des, int status) { mca_pml_ob1_rdma_frag_t* frag = (mca_pml_ob1_rdma_frag_t*)des->des_cbdata; mca_pml_ob1_send_request_t* sendreq = frag->rdma_req; mca_btl_base_descriptor_t* fin; mca_pml_ob1_fin_hdr_t* hdr; mca_bml_base_btl_t* bml_btl = (mca_bml_base_btl_t*) des->des_context; int rc; /* check completion status */ if(OMPI_SUCCESS != status) { /* TSW - FIX */ ORTE_ERROR_LOG(status); orte_errmgr.abort(); } /* check for request completion */ OPAL_THREAD_LOCK(&ompi_request_lock); sendreq->req_bytes_delivered += frag->rdma_length; if(sendreq->req_bytes_delivered >= sendreq->req_send.req_bytes_packed) { MCA_PML_OB1_SEND_REQUEST_COMPLETE(sendreq); } OPAL_THREAD_UNLOCK(&ompi_request_lock); /* allocate descriptor for fin control message - note that * the rdma descriptor cannot be reused as it points directly * at the user buffer */ frag->rdma_state = MCA_PML_OB1_RDMA_FIN; MCA_BML_BASE_BTL_DES_ALLOC(bml_btl, fin, sizeof(mca_pml_ob1_fin_hdr_t)); if(NULL == fin) { OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.rdma_pending, (opal_list_item_t*)frag); OPAL_THREAD_LOCK(&mca_pml_ob1.lock); goto cleanup; } fin->des_flags |= MCA_BTL_DES_FLAGS_PRIORITY; fin->des_cbfunc = mca_pml_ob1_fin_completion; fin->des_cbdata = frag; /* fill in header */ hdr = (mca_pml_ob1_fin_hdr_t*)fin->des_src->seg_addr.pval; hdr->hdr_common.hdr_flags = 0; hdr->hdr_common.hdr_type = MCA_PML_OB1_HDR_TYPE_FIN; hdr->hdr_des = frag->rdma_hdr.hdr_rdma.hdr_des; /* queue request */ rc = mca_bml_base_send( bml_btl, fin, MCA_BTL_TAG_PML ); if(OMPI_SUCCESS != rc) { mca_bml_base_free(bml_btl, fin); if(rc == OMPI_ERR_OUT_OF_RESOURCE) { OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.rdma_pending, (opal_list_item_t*)frag); OPAL_THREAD_LOCK(&mca_pml_ob1.lock); } else { /* TSW - FIX */ ORTE_ERROR_LOG(rc); orte_errmgr.abort(); } } cleanup: /* return rdma descriptor - do this after queuing the fin message - as * release rdma resources (unpin memory) can take some time. */ des->des_dst = NULL; des->des_dst_cnt = 0; mca_bml_base_free(bml_btl, des); } /** * Receiver has scheduled an RDMA operation: * (1) Allocate an RDMA fragment to maintain the state of the operation * (2) Call BTL prepare_src to pin/prepare source buffers * (3) Queue the RDMA put */ void mca_pml_ob1_send_request_put( mca_pml_ob1_send_request_t* sendreq, mca_btl_base_module_t* btl, mca_pml_ob1_rdma_hdr_t* hdr) { mca_mpool_base_registration_t* reg = NULL; mca_bml_base_btl_t* bml_btl; mca_btl_base_descriptor_t* des; mca_pml_ob1_rdma_frag_t* frag; size_t offset = hdr->hdr_rdma_offset; size_t i, size = 0; int rc; bml_btl = mca_bml_base_btl_array_find(&sendreq->bml_endpoint->btl_rdma, btl); MCA_PML_OB1_RDMA_FRAG_ALLOC(frag, rc); if(NULL == frag) { /* TSW - FIX */ ORTE_ERROR_LOG(rc); orte_errmgr.abort(); } /* setup fragment */ for(i=0; ihdr_seg_cnt; i++) { size += hdr->hdr_segs[i].seg_len; frag->rdma_segs[i] = hdr->hdr_segs[i]; } frag->rdma_hdr.hdr_rdma = *hdr; frag->rdma_req = sendreq; frag->rdma_ep = sendreq->bml_endpoint; frag->rdma_state = MCA_PML_OB1_RDMA_PREPARE; /* look for a prior registration on this interface */ if(NULL != sendreq->req_chunk) { mca_mpool_base_reg_mpool_t* mpool = sendreq->req_chunk->mpools; while(mpool->mpool != NULL) { if(mpool->user_data == (void*) btl) { reg = mpool->mpool_registration; break; } mpool++; } } /* setup descriptor */ ompi_convertor_set_position(&sendreq->req_send.req_convertor, &offset); mca_bml_base_prepare_src( bml_btl, reg, &sendreq->req_send.req_convertor, 0, &size, &des); if(NULL == des) { OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.rdma_pending, (opal_list_item_t*)frag); OPAL_THREAD_UNLOCK(&mca_pml_ob1.lock); } frag->rdma_state = MCA_PML_OB1_RDMA_PUT; frag->rdma_length = size; des->des_dst = frag->rdma_segs; des->des_dst_cnt = hdr->hdr_seg_cnt; des->des_cbfunc = mca_pml_ob1_put_completion; des->des_cbdata = frag; if(OMPI_SUCCESS != (rc = mca_bml_base_put(bml_btl, des))) { if(rc == OMPI_ERR_OUT_OF_RESOURCE) { OPAL_THREAD_LOCK(&mca_pml_ob1.lock); opal_list_append(&mca_pml_ob1.rdma_pending, (opal_list_item_t*)frag); OPAL_THREAD_UNLOCK(&mca_pml_ob1.lock); } else { /* TSW - FIX */ ORTE_ERROR_LOG(rc); orte_errmgr.abort(); } } #ifdef HAVE_SCHED_YIELD sched_yield(); #endif }