static inline int mca_btl_ugni_ep_connect_finish (mca_btl_base_endpoint_t *ep) { gni_return_t grc; int rc; BTL_VERBOSE(("finishing connection. remote attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " "msg_maxsize = %d", ep->remote_attr.smsg_attr.msg_type, ep->remote_attr.smsg_attr.msg_buffer, ep->remote_attr.smsg_attr.buff_size, ep->remote_attr.smsg_attr.mem_hndl.qword1, ep->remote_attr.smsg_attr.mem_hndl.qword2, ep->remote_attr.smsg_attr.mbox_offset, ep->remote_attr.smsg_attr.mbox_maxcredit, ep->remote_attr.smsg_attr.msg_maxsize)); BTL_VERBOSE(("finishing connection. local attributes: msg_type = %d, msg_buffer = %p, buff_size = %d, " "mem_hndl = {qword1 = %" PRIu64 ", qword2 = %" PRIu64 "}, mbox = %d, mbox_maxcredit = %d, " "msg_maxsize = %d", ep->mailbox->attr.smsg_attr.msg_type, ep->mailbox->attr.smsg_attr.msg_buffer, ep->mailbox->attr.smsg_attr.buff_size, ep->mailbox->attr.smsg_attr.mem_hndl.qword1, ep->mailbox->attr.smsg_attr.mem_hndl.qword2, ep->mailbox->attr.smsg_attr.mbox_offset, ep->mailbox->attr.smsg_attr.mbox_maxcredit, ep->mailbox->attr.smsg_attr.msg_maxsize)); grc = GNI_SmsgInit (ep->smsg_ep_handle, &ep->mailbox->attr.smsg_attr, &ep->remote_attr.smsg_attr); if (OPAL_UNLIKELY(GNI_RC_SUCCESS != grc)) { BTL_ERROR(("error initializing SMSG protocol. rc = %d", grc)); return opal_common_rc_ugni_to_opal (grc); } /* set the local event data to the local index and the remote event data to my * index on the remote peer. This makes lookup of endpoints on completion take * a single lookup in the endpoints array. we will not be able to change the * remote peer's index in the endpoint's array after this point. */ GNI_EpSetEventData (ep->rdma_ep_handle, ep->index, ep->remote_attr.index); GNI_EpSetEventData (ep->smsg_ep_handle, ep->index, ep->remote_attr.index); ep->rmt_irq_mem_hndl = ep->remote_attr.rmt_irq_mem_hndl; ep->state = MCA_BTL_UGNI_EP_STATE_CONNECTED; (void) opal_atomic_add_64 (&ep->btl->connected_peer_count, 1); /* send all pending messages */ BTL_VERBOSE(("endpoint connected. posting %u sends", (unsigned int) opal_list_get_size (&ep->frag_wait_list))); rc = mca_btl_ugni_progress_send_wait_list (ep); if (OPAL_UNLIKELY(OPAL_SUCCESS != rc)) { OPAL_THREAD_LOCK(&ep->btl->ep_wait_list_lock); if (false == ep->wait_listed) { opal_list_append (&ep->btl->ep_wait_list, &ep->super); ep->wait_listed = true; } OPAL_THREAD_UNLOCK(&ep->btl->ep_wait_list_lock); } return OPAL_SUCCESS; }
ucs_status_t uct_ugni_smsg_ep_connect_to_ep(uct_ep_h tl_ep, const uct_device_addr_t *dev_addr, const uct_ep_addr_t *ep_addr) { uct_ugni_smsg_ep_t *ep = ucs_derived_of(tl_ep, uct_ugni_smsg_ep_t); uct_ugni_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_ugni_iface_t); const uct_sockaddr_smsg_ugni_t *iface_addr = (const uct_sockaddr_smsg_ugni_t*)ep_addr; const uct_devaddr_ugni_t *ugni_dev_addr = (const uct_devaddr_ugni_t *)dev_addr; gni_smsg_attr_t *local_attr = (gni_smsg_attr_t*)&ep->smsg_attr->mbox_attr; uct_ugni_compact_smsg_attr_t *compact_remote_attr = (uct_ugni_compact_smsg_attr_t *)&iface_addr->smsg_compact_attr; gni_smsg_attr_t remote_attr; gni_return_t gni_rc; ucs_status_t rc = UCS_OK; uint32_t ep_hash; uncompact_smsg_attr(ucs_derived_of(iface, uct_ugni_smsg_iface_t), compact_remote_attr, &remote_attr); rc = ugni_connect_ep(iface, ugni_dev_addr, &iface_addr->super, &ep->super); if(UCS_OK != rc){ ucs_error("Could not connect ep in smsg"); return rc; } uct_ugni_cdm_lock(&iface->cdm); gni_rc = GNI_SmsgInit(ep->super.ep, local_attr, &remote_attr); uct_ugni_cdm_unlock(&iface->cdm); if(GNI_RC_SUCCESS != gni_rc){ ucs_error("Failed to initalize smsg. %s [%i]", gni_err_str[gni_rc], gni_rc); if(GNI_RC_INVALID_PARAM == gni_rc){ return UCS_ERR_INVALID_PARAM; } else { return UCS_ERR_NO_MEMORY; } } ep_hash = (uint32_t)iface_addr->ep_hash; uct_ugni_cdm_lock(&iface->cdm); gni_rc = GNI_EpSetEventData(ep->super.ep, iface->cdm.domain_id, ep_hash); uct_ugni_cdm_unlock(&iface->cdm); if(GNI_RC_SUCCESS != gni_rc){ ucs_error("Could not set GNI_EpSetEventData!"); } return rc; }
ucs_status_t uct_ugni_smsg_ep_connect_to_ep(uct_ep_h tl_ep, const struct sockaddr *addr){ uct_ugni_smsg_ep_t *ep = ucs_derived_of(tl_ep, uct_ugni_smsg_ep_t); uct_ugni_iface_t *iface = ucs_derived_of(tl_ep->iface, uct_ugni_iface_t); const uct_sockaddr_smsg_ugni_t *iface_addr = (const uct_sockaddr_smsg_ugni_t*)addr; gni_smsg_attr_t *local_attr = (gni_smsg_attr_t*)&ep->smsg_attr->mbox_attr; gni_smsg_attr_t *remote_attr = (gni_smsg_attr_t *)&iface_addr->smsg_attr; gni_return_t gni_rc; ucs_status_t rc = UCS_OK; uint32_t ep_hash; pthread_mutex_lock(&uct_ugni_global_lock); rc = ugni_connect_ep(iface, &iface_addr->super, &ep->super); if(UCS_OK != rc){ ucs_error("Could not connect ep in smsg"); goto exit_lock; } gni_rc = GNI_SmsgInit(ep->super.ep, local_attr, remote_attr); if(GNI_RC_SUCCESS != gni_rc){ ucs_error("Failed to initalize smsg. %s [%i]", gni_err_str[gni_rc], gni_rc); if(GNI_RC_INVALID_PARAM == gni_rc){ rc = UCS_ERR_INVALID_PARAM; } else { rc = UCS_ERR_NO_MEMORY; } goto exit_lock; } ep_hash = (uint32_t)iface_addr->ep_hash; gni_rc = GNI_EpSetEventData(ep->super.ep, iface->domain_id, ep_hash); if(GNI_RC_SUCCESS != gni_rc){ ucs_error("Could not set GNI_EpSetEventData!"); } exit_lock: pthread_mutex_unlock(&uct_ugni_global_lock); return rc; }
/* * helper function to initialize an SMSG connection */ static int __gnix_vc_smsg_init(struct gnix_vc *vc, int peer_id, gni_smsg_attr_t *peer_smsg_attr) { int ret = FI_SUCCESS; struct gnix_fid_ep *ep; struct gnix_fid_domain *dom; struct gnix_mbox *mbox = NULL; gni_smsg_attr_t local_smsg_attr; gni_return_t __attribute__((unused)) status; ssize_t __attribute__((unused)) len; GNIX_TRACE(FI_LOG_EP_CTRL, "\n"); assert(vc); ep = vc->ep; assert(ep); dom = ep->domain; if (dom == NULL) return -FI_EINVAL; mbox = vc->smsg_mbox; assert (mbox); local_smsg_attr.msg_type = GNI_SMSG_TYPE_MBOX_AUTO_RETRANSMIT; local_smsg_attr.msg_buffer = mbox->base; local_smsg_attr.buff_size = vc->ep->nic->mem_per_mbox; local_smsg_attr.mem_hndl = *mbox->memory_handle; local_smsg_attr.mbox_offset = (uint64_t)mbox->offset; local_smsg_attr.mbox_maxcredit = dom->params.mbox_maxcredit; local_smsg_attr.msg_maxsize = dom->params.mbox_msg_maxsize; /* * now build the SMSG connection */ fastlock_acquire(&ep->nic->lock); status = GNI_EpCreate(ep->nic->gni_nic_hndl, ep->nic->tx_cq, &vc->gni_ep); if (status != GNI_RC_SUCCESS) { GNIX_WARN(FI_LOG_EP_CTRL, "GNI_EpCreate returned %s\n", gni_err_str[status]); ret = gnixu_to_fi_errno(status); goto err; } status = GNI_EpBind(vc->gni_ep, vc->peer_addr.device_addr, vc->peer_addr.cdm_id); if (status != GNI_RC_SUCCESS) { GNIX_WARN(FI_LOG_EP_CTRL, "GNI_EpBind returned %s\n", gni_err_str[status]); ret = gnixu_to_fi_errno(status); goto err1; } status = GNI_SmsgInit(vc->gni_ep, &local_smsg_attr, peer_smsg_attr); if (status != GNI_RC_SUCCESS) { GNIX_WARN(FI_LOG_EP_CTRL, "GNI_SmsgInit returned %s\n", gni_err_str[status]); ret = gnixu_to_fi_errno(status); goto err1; } status = GNI_EpSetEventData(vc->gni_ep, vc->vc_id, peer_id); if (status != GNI_RC_SUCCESS) { GNIX_WARN(FI_LOG_EP_CTRL, "GNI_EpSetEventData returned %s\n", gni_err_str[status]); ret = gnixu_to_fi_errno(status); goto err1; } fastlock_release(&ep->nic->lock); return ret; err1: GNI_EpDestroy(vc->gni_ep); err: fastlock_release(&ep->nic->lock); return ret; }