ucs_status_t ucp_ep_create(ucp_worker_h worker, const ucp_address_t *address, ucp_ep_h *ep_p) { char peer_name[UCP_WORKER_NAME_MAX]; uint8_t addr_indices[UCP_MAX_LANES]; ucp_address_entry_t *address_list; unsigned address_count; ucs_status_t status; uint64_t dest_uuid; ucp_ep_h ep; UCS_ASYNC_BLOCK(&worker->async); status = ucp_address_unpack(address, &dest_uuid, peer_name, sizeof(peer_name), &address_count, &address_list); if (status != UCS_OK) { ucs_error("failed to unpack remote address: %s", ucs_status_string(status)); goto out; } ep = ucp_worker_ep_find(worker, dest_uuid); if (ep != NULL) { /* TODO handle a case where the existing endpoint is incomplete */ *ep_p = ep; status = UCS_OK; goto out_free_address; } /* allocate endpoint */ status = ucp_ep_new(worker, dest_uuid, peer_name, "from api call", &ep); if (status != UCS_OK) { goto out_free_address; } /* initialize transport endpoints */ status = ucp_wireup_init_lanes(ep, address_count, address_list, addr_indices); if (status != UCS_OK) { goto err_destroy_ep; } /* send initial wireup message */ if (!(ep->flags & UCP_EP_FLAG_LOCAL_CONNECTED)) { status = ucp_wireup_send_request(ep); if (status != UCS_OK) { goto err_destroy_ep; } } *ep_p = ep; goto out_free_address; err_destroy_ep: ucp_ep_destroy(ep); out_free_address: ucs_free(address_list); out: UCS_ASYNC_UNBLOCK(&worker->async); return status; }
ucs_status_t ucp_ep_create(ucp_worker_h worker, const ucp_address_t *address, ucp_ep_h *ep_p) { char peer_name[UCP_WORKER_NAME_MAX]; ucs_status_t status; uint64_t dest_uuid; unsigned address_count; ucp_address_entry_t *address_list; ucp_ep_h ep; UCS_ASYNC_BLOCK(&worker->async); status = ucp_address_unpack(address, &dest_uuid, peer_name, sizeof(peer_name), &address_count, &address_list); if (status != UCS_OK) { ucs_error("failed to unpack remote address: %s", ucs_status_string(status)); goto out; } ep = ucp_worker_ep_find(worker, dest_uuid); if (ep != NULL) { /* TODO handle a case where the existing endpoint is incomplete */ ucs_debug("returning existing ep %p which is already connected to %"PRIx64, ep, ep->dest_uuid); *ep_p = ep; status = UCS_OK; goto out_free_address; } status = ucp_ep_create_connected(worker, dest_uuid, peer_name, address_count, address_list, " from api call", &ep); if (status != UCS_OK) { goto out_free_address; } /* send initial wireup message */ if (!(ep->flags & UCP_EP_FLAG_LOCAL_CONNECTED)) { status = ucp_wireup_send_request(ep); if (status != UCS_OK) { goto err_destroy_ep; } } *ep_p = ep; goto out_free_address; err_destroy_ep: ucp_ep_destroy(ep); out_free_address: ucs_free(address_list); out: UCS_ASYNC_UNBLOCK(&worker->async); return status; }
static void ucp_wireup_process_ack(ucp_worker_h worker, uint64_t uuid) { ucp_ep_h ep = ucp_worker_ep_find(worker, uuid); if (ep == NULL) { ucs_debug("ignoring connection ack - ep not exists"); return; } ucs_trace("ep %p: got wireup ack", ep); ep->flags |= UCP_EP_FLAG_REMOTE_CONNECTED; ucp_wireup_ep_remote_connected(ep); }
static void ucp_wireup_process_reply(ucp_worker_h worker, ucp_wireup_msg_t *msg, uint64_t uuid, unsigned address_count, const ucp_address_entry_t *address_list) { ucp_ep_h ep = ucp_worker_ep_find(worker, uuid); ucp_rsc_index_t rsc_tli[UCP_MAX_LANES]; ucs_status_t status; int ack; if (ep == NULL) { ucs_debug("ignoring connection reply - not exists"); return; } ucs_trace("ep %p: got wireup reply", ep); /* Connect p2p addresses to remote endpoint */ if (!(ep->flags & UCP_EP_FLAG_LOCAL_CONNECTED)) { status = ucp_wireup_connect_local(ep, msg->tli, address_count, address_list); if (status != UCS_OK) { return; } ep->flags |= UCP_EP_FLAG_LOCAL_CONNECTED; ack = 1; } else { ack = 0; } if (!(ep->flags & UCP_EP_FLAG_REMOTE_CONNECTED)) { ucp_wireup_ep_remote_connected(ep); ep->flags |= UCP_EP_FLAG_REMOTE_CONNECTED; } if (ack) { /* Send ACK without any address, we've already sent it as part of the request */ memset(rsc_tli, -1, sizeof(rsc_tli)); status = ucp_wireup_msg_send(ep, UCP_WIREUP_MSG_ACK, 0, rsc_tli); if (status != UCS_OK) { return; } } }
ucs_status_t ucp_ep_create(ucp_worker_h worker, ucp_address_t *address, ucp_ep_h *ep_p) { uint64_t dest_uuid = ucp_address_uuid(address); char peer_name[UCP_PEER_NAME_MAX]; ucs_status_t status; ucp_ep_h ep; UCS_ASYNC_BLOCK(&worker->async); ep = ucp_worker_ep_find(worker, dest_uuid); if (ep != NULL) { ucs_debug("returning existing ep %p which is already connected to %"PRIx64, ep, ep->dest_uuid); goto out; } ucp_address_peer_name(address, peer_name); status = ucp_ep_new(worker, dest_uuid, peer_name, " from api call", &ep); if (status != UCS_OK) { goto err; } status = ucp_wireup_start(ep, address); if (status != UCS_OK) { goto err_free; } out: UCS_ASYNC_UNBLOCK(&worker->async); *ep_p = ep; return UCS_OK; err_free: ucs_free(ep); err: UCS_ASYNC_UNBLOCK(&worker->async); return status; }
static void ucp_wireup_process_request(ucp_worker_h worker, const ucp_wireup_msg_t *msg, uint64_t uuid, const char *peer_name, unsigned address_count, const ucp_address_entry_t *address_list) { ucp_ep_h ep = ucp_worker_ep_find(worker, uuid); ucp_rsc_index_t rsc_tli[UCP_MAX_LANES]; uint8_t addr_indices[UCP_MAX_LANES]; ucp_lane_index_t lane, remote_lane; ucp_rsc_index_t rsc_index; ucs_status_t status; uint64_t tl_bitmap = 0; ucs_trace("ep %p: got wireup request from %s", ep, peer_name); /* Create a new endpoint if does not exist */ if (ep == NULL) { status = ucp_ep_new(worker, uuid, peer_name, "remote-request", &ep); if (status != UCS_OK) { return; } } /* Initialize lanes (possible destroy existing lanes) */ status = ucp_wireup_init_lanes(ep, address_count, address_list, addr_indices); if (status != UCS_OK) { return; } /* Connect p2p addresses to remote endpoint */ if (!(ep->flags & UCP_EP_FLAG_LOCAL_CONNECTED)) { status = ucp_wireup_connect_local(ep, addr_indices, address_count, address_list); if (status != UCS_OK) { return; } ep->flags |= UCP_EP_FLAG_LOCAL_CONNECTED; /* Construct the list that tells the remote side with which address we * have connected to each of its lanes. */ memset(rsc_tli, -1, sizeof(rsc_tli)); for (lane = 0; lane < ucp_ep_num_lanes(ep); ++lane) { rsc_index = ucp_ep_get_rsc_index(ep, lane); for (remote_lane = 0; remote_lane < UCP_MAX_LANES; ++remote_lane) { /* If 'lane' has connected to 'remote_lane' ... */ if (addr_indices[lane] == msg->tli[remote_lane]) { ucs_assert(ucp_worker_is_tl_p2p(worker, rsc_index)); rsc_tli[remote_lane] = rsc_index; tl_bitmap |= UCS_BIT(rsc_index); } } } ucs_trace("ep %p: sending wireup reply", ep); status = ucp_wireup_msg_send(ep, UCP_WIREUP_MSG_REPLY, tl_bitmap, rsc_tli); if (status != UCS_OK) { return; } } }