ucs_status_t ucp_tag_init(ucp_context_h context) { if (!(context->config.features & UCP_FEATURE_TAG)) { return UCS_OK; } ucs_queue_head_init(&context->tag.expected); ucs_queue_head_init(&context->tag.unexpected); return UCS_OK; }
ucs_status_t ucp_init_version(unsigned api_major_version, unsigned api_minor_version, const ucp_params_t *params, const ucp_config_t *config, ucp_context_h *context_p) { unsigned major_version, minor_version, release_number; ucp_context_t *context; ucs_status_t status; ucp_get_version(&major_version, &minor_version, &release_number); if ((api_major_version != major_version) || (api_minor_version != minor_version)) { ucs_error("UCP version is incompatible, required: %d.%d, actual: %d.%d (release %d)", api_major_version, api_minor_version, major_version, minor_version, release_number); status = UCS_ERR_NOT_IMPLEMENTED; goto err; } /* allocate a ucp context */ context = ucs_calloc(1, sizeof(*context), "ucp context"); if (context == NULL) { status = UCS_ERR_NO_MEMORY; goto err; } status = ucp_fill_config(context, params, config); if (status != UCS_OK) { goto err_free_ctx; } /* fill resources we should use */ status = ucp_fill_resources(context, config); if (status != UCS_OK) { goto err_free_config; } /* initialize tag matching */ ucs_queue_head_init(&context->tag.expected); ucs_queue_head_init(&context->tag.unexpected); ucs_debug("created ucp context %p [%d mds %d tls] features 0x%lx", context, context->num_mds, context->num_tls, context->config.features); *context_p = context; return UCS_OK; err_free_config: ucp_free_config(context); err_free_ctx: ucs_free(context); err: return status; }
UCS_CLASS_INIT_FUNC(ucp_stub_ep_t, ucp_ep_h ucp_ep) { memset(&self->iface, 0, sizeof(self->iface)); self->iface.ops.ep_flush = (void*)ucs_empty_function_return_success; self->iface.ops.ep_destroy = UCS_CLASS_DELETE_FUNC_NAME(ucp_stub_ep_t); self->iface.ops.ep_pending_add = ucp_stub_pending_add; self->iface.ops.ep_pending_purge = ucp_stub_pending_purge; self->iface.ops.ep_put_short = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_put_bcopy = (void*)ucp_stub_ep_bcopy_send_func; self->iface.ops.ep_put_zcopy = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_get_bcopy = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_get_zcopy = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_am_short = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_am_bcopy = (void*)ucp_stub_ep_bcopy_send_func; self->iface.ops.ep_am_zcopy = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_add64 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_fadd64 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_swap64 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_cswap64 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_add32 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_fadd32 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_swap32 = (void*)ucp_stub_ep_send_func; self->iface.ops.ep_atomic_cswap32 = (void*)ucp_stub_ep_send_func; self->super.iface = &self->iface; self->ep = ucp_ep; self->aux_ep = NULL; self->next_ep = NULL; self->pending_count = 0; ucs_queue_head_init(&self->pending_q); return UCS_OK; }
static UCS_CLASS_INIT_FUNC(uct_tcp_ep_t, uct_tcp_iface_t *iface, int fd, const struct sockaddr_in *dest_addr) { ucs_status_t status; UCS_CLASS_CALL_SUPER_INIT(uct_base_ep_t, &iface->super) self->buf = ucs_malloc(iface->config.buf_size, "tcp_buf"); if (self->buf == NULL) { return UCS_ERR_NO_MEMORY; } self->events = 0; self->offset = 0; self->length = 0; ucs_queue_head_init(&self->pending_q); if (fd == -1) { status = ucs_tcpip_socket_create(&self->fd); if (status != UCS_OK) { goto err; } /* TODO use non-blocking connect */ status = uct_tcp_socket_connect(self->fd, dest_addr); if (status != UCS_OK) { goto err_close; } } else { self->fd = fd; } status = ucs_sys_fcntl_modfl(self->fd, O_NONBLOCK, 0); if (status != UCS_OK) { goto err_close; } status = uct_tcp_iface_set_sockopt(iface, self->fd); if (status != UCS_OK) { goto err_close; } uct_tcp_ep_epoll_ctl(self, EPOLL_CTL_ADD); UCS_ASYNC_BLOCK(iface->super.worker->async); ucs_list_add_tail(&iface->ep_list, &self->list); UCS_ASYNC_UNBLOCK(iface->super.worker->async); ucs_debug("tcp_ep %p: created on iface %p, fd %d", self, iface, self->fd); return UCS_OK; err_close: close(self->fd); err: return status; }
static void uct_ud_ep_reset(uct_ud_ep_t *ep) { ep->tx.psn = 1; /* TODO: configurable max window size */ ep->tx.max_psn = ep->tx.psn + UCT_UD_MAX_WINDOW; ep->tx.acked_psn = 0; ep->tx.pending.ops = UCT_UD_EP_OP_NONE; ucs_queue_head_init(&ep->tx.window); ep->rx.acked_psn = 0; ucs_frag_list_init(ep->tx.psn-1, &ep->rx.ooo_pkts, 0 /*TODO: ooo support */ UCS_STATS_ARG(ep->rx.stats)); }
static UCS_CLASS_INIT_FUNC(uct_cm_iface_t, uct_pd_h pd, uct_worker_h worker, const char *dev_name, size_t rx_headroom, const uct_iface_config_t *tl_config) { uct_cm_iface_config_t *config = ucs_derived_of(tl_config, uct_cm_iface_config_t); ucs_status_t status; int ret; ucs_trace_func(""); UCS_CLASS_CALL_SUPER_INIT(uct_ib_iface_t, &uct_cm_iface_ops, pd, worker, dev_name, rx_headroom, 0 /* rx_priv_len */, 0 /* rx_hdr_len */, 1 /* tx_cq_len */, IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE, /* mss */ &config->super); if (worker->async == NULL) { ucs_error("cm must have async!=NULL"); return UCS_ERR_INVALID_PARAM; } self->service_id = (uint32_t)(ucs_generate_uuid((uintptr_t)self) & (~IB_CM_ASSIGN_SERVICE_ID_MASK)); self->num_outstanding = 0; self->config.timeout_ms = (int)(config->timeout * 1e3 + 0.5); self->config.max_outstanding = config->max_outstanding; self->config.retry_count = ucs_min(config->retry_count, UINT8_MAX); self->notify_q.head = NULL; ucs_queue_head_init(&self->notify_q); self->outstanding = ucs_calloc(self->config.max_outstanding, sizeof(*self->outstanding), "cm_outstanding"); if (self->outstanding == NULL) { status = UCS_ERR_NO_MEMORY; goto err; } self->cmdev = ib_cm_open_device(uct_ib_iface_device(&self->super)->ibv_context); if (self->cmdev == NULL) { ucs_error("ib_cm_open_device() failed: %m. Check if ib_ucm.ko module is loaded."); status = UCS_ERR_NO_DEVICE; goto err_free_outstanding; } status = ucs_sys_fcntl_modfl(self->cmdev->fd, O_NONBLOCK, 0); if (status != UCS_OK) { goto err_close_device; } ret = ib_cm_create_id(self->cmdev, &self->listen_id, self); if (ret) { ucs_error("ib_cm_create_id() failed: %m"); status = UCS_ERR_NO_DEVICE; goto err_close_device; } ret = ib_cm_listen(self->listen_id, self->service_id, 0); if (ret) { ucs_error("ib_cm_listen() failed: %m"); status = UCS_ERR_INVALID_ADDR; goto err_destroy_id; } if (config->async_mode == UCS_ASYNC_MODE_SIGNAL) { ucs_warn("ib_cm fd does not support SIGIO"); } status = ucs_async_set_event_handler(config->async_mode, self->cmdev->fd, POLLIN, uct_cm_iface_event_handler, self, worker->async); if (status != UCS_OK) { ucs_error("failed to set event handler"); goto err_destroy_id; } ucs_debug("listening for SIDR service_id 0x%x on fd %d", self->service_id, self->cmdev->fd); return UCS_OK; err_destroy_id: ib_cm_destroy_id(self->listen_id); err_close_device: ib_cm_close_device(self->cmdev); err_free_outstanding: ucs_free(self->outstanding); err: return status; }