static int pp_listen_ctx(struct pingpong_context *ctx) { int rc = 0; rc = fi_passive_ep(ctx->fabric, ctx->info, &ctx->lep, NULL); if (rc) { fprintf(stderr, "Unable to open listener endpoint\n"); return 1; } /* Create listener EQ */ rc = pp_eq_create(ctx); if (rc) { fprintf(stderr, "Unable to allocate listener resources\n"); return 1; } rc = fi_pep_bind(ctx->lep, &ctx->eq->fid, 0); if (rc) { FT_PRINTERR("fi_pep_bind", rc); return 1; } rc = fi_listen(ctx->lep); if (rc) { FT_PRINTERR("fi_listen", rc); return 1; } printf("Listening for incoming connections...\n"); return 0; }
static int rxm_ep_ctrl(struct fid *fid, int command, void *arg) { struct rxm_ep *rxm_ep; struct rxm_fabric *rxm_fabric; int ret; rxm_ep = container_of(fid, struct rxm_ep, util_ep.ep_fid.fid); rxm_fabric = container_of(rxm_ep->util_ep.domain->fabric, struct rxm_fabric, util_fabric); switch (command) { case FI_ENABLE: if (!rxm_ep->util_ep.rx_cq || !rxm_ep->util_ep.tx_cq) return -FI_ENOCQ; if (!rxm_ep->util_ep.av) return -FI_EOPBADSTATE; /* TODO: Add FI_ENOAV */ ret = fi_pep_bind(rxm_ep->msg_pep, &rxm_fabric->msg_eq->fid, 0); if (ret) { FI_WARN(&rxm_prov, FI_LOG_EP_CTRL, "Unable to bind msg PEP to msg EQ\n"); return ret; } ret = fi_listen(rxm_ep->msg_pep); if (ret) { FI_WARN(&rxm_prov, FI_LOG_EP_CTRL, "Unable to set msg PEP to listen state\n"); return ret; } break; default: return -FI_ENOSYS; } return 0; }
int cm_server_start(void) { int ret; struct sockaddr_in loc_sa; cm_local_ip(&loc_sa); srv_hints = fi_allocinfo(); srv_hints->fabric_attr->name = strdup("gni"); srv_hints->ep_attr->type = FI_EP_MSG; srv_hints->domain_attr->mr_mode = GNIX_DEFAULT_MR_MODE; ret = fi_getinfo(fi_version(), inet_ntoa(loc_sa.sin_addr), DEF_PORT, FI_SOURCE, srv_hints, &srv_fi); cr_assert(!ret); ret = fi_fabric(srv_fi->fabric_attr, &srv_fab, NULL); cr_assert(!ret); ret = fi_eq_open(srv_fab, &eq_attr, &srv_eq, NULL); cr_assert(!ret); ret = fi_passive_ep(srv_fab, srv_fi, &srv_pep, NULL); cr_assert(!ret); ret = fi_pep_bind(srv_pep, &srv_eq->fid, 0); cr_assert(!ret); ret = fi_listen(srv_pep); cr_assert(!ret); dbg_printf("Server start complete.\n"); return 0; }
static int server_listen(void) { struct fi_info *fi; int ret; /* Get fabric info */ ret = fi_getinfo(FT_FIVERSION, NULL, opts.src_port, FI_SOURCE, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); return ret; } /* Open the fabric */ ret = fi_fabric(fi->fabric_attr, &fab, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); goto err0; } /* Open a passive endpoint */ ret = fi_passive_ep(fab, fi, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); goto err1; } /* Allocate connection management resources */ ret = alloc_cm_res(); if (ret) goto err2; /* Bind EQ to passive endpoint */ ret = fi_pep_bind(pep, &cmeq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); goto err3; } /* Listen for incoming connections */ ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); goto err3; } fi_freeinfo(fi); return 0; err3: fi_close(&cmeq->fid); err2: fi_close(&pep->fid); err1: fi_close(&fab->fid); err0: fi_freeinfo(fi); return ret; }
static int server_listen(void) { struct fi_info *fi; int ret; ret = fi_getinfo(FT_FIVERSION, opts.src_addr, opts.src_port, FI_SOURCE, hints, &fi); if (ret) { FT_PRINTERR("fi_getinfo", ret); return ret; } ret = fi_fabric(fi->fabric_attr, &fab, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); goto err0; } ret = fi_passive_ep(fab, fi, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); goto err1; } ret = alloc_cm_res(); if (ret) goto err2; ret = fi_pep_bind(pep, &cmeq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); goto err3; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); goto err3; } fi_freeinfo(fi); return 0; err3: free_lres(); err2: fi_close(&pep->fid); err1: fi_close(&fab->fid); err0: fi_freeinfo(fi); return ret; }
static int server_listen(void) { int ret; ret = fi_pep_bind(pep, &eq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); return ret; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); return ret; } return 0; }
int ft_start_server(void) { int ret; ret = fi_getinfo(FT_FIVERSION, opts.src_addr, opts.src_port, FI_SOURCE, hints, &fi_pep); if (ret) { FT_PRINTERR("fi_getinfo", ret); return ret; } ret = fi_fabric(fi_pep->fabric_attr, &fabric, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); return ret; } ret = fi_eq_open(fabric, &eq_attr, &eq, NULL); if (ret) { FT_PRINTERR("fi_eq_open", ret); return ret; } ret = fi_passive_ep(fabric, fi_pep, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); return ret; } ret = fi_pep_bind(pep, &eq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); return ret; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); return ret; } return 0; }
int ft_start_server(void) { int ret; ret = ft_getinfo(hints, &fi_pep); if (ret) return ret; ret = fi_fabric(fi_pep->fabric_attr, &fabric, NULL); if (ret) { FT_PRINTERR("fi_fabric", ret); return ret; } ret = fi_eq_open(fabric, &eq_attr, &eq, NULL); if (ret) { FT_PRINTERR("fi_eq_open", ret); return ret; } ret = fi_passive_ep(fabric, fi_pep, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); return ret; } ret = fi_pep_bind(pep, &eq->fid, 0); if (ret) { FT_PRINTERR("fi_pep_bind", ret); return ret; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); return ret; } return 0; }
/* * rpmemd_fip_init_fabric_res -- initialize common fabric's resources */ static int rpmemd_fip_init_fabric_res(struct rpmemd_fip *fip) { int ret; ret = fi_fabric(fip->fi->fabric_attr, &fip->fabric, NULL); if (ret) { RPMEMD_FI_ERR(ret, "opening fabric domain"); goto err_fi_fabric; } ret = fi_domain(fip->fabric, fip->fi, &fip->domain, NULL); if (ret) { RPMEMD_FI_ERR(ret, "opening fabric access domain"); goto err_fi_domain; } struct fi_eq_attr eq_attr = { .size = 0, /* use default */ .flags = 0, .wait_obj = FI_WAIT_UNSPEC, .signaling_vector = 0, .wait_set = NULL, }; ret = fi_eq_open(fip->fabric, &eq_attr, &fip->eq, NULL); if (ret) { RPMEMD_FI_ERR(ret, "opening event queue"); goto err_eq_open; } ret = fi_passive_ep(fip->fabric, fip->fi, &fip->pep, NULL); if (ret) { RPMEMD_FI_ERR(ret, "allocating passive endpoint"); goto err_pep; } ret = fi_pep_bind(fip->pep, &fip->eq->fid, 0); if (ret) { RPMEMD_FI_ERR(ret, "binding event queue to passive endpoint"); goto err_pep_bind_eq; } return 0; err_pep_bind_eq: RPMEMD_FI_CLOSE(fip->pep, "closing passive endpoint"); err_pep: RPMEMD_FI_CLOSE(fip->eq, "closing event queue"); err_eq_open: RPMEMD_FI_CLOSE(fip->domain, "closing fabric access domain"); err_fi_domain: RPMEMD_FI_CLOSE(fip->fabric, "closing fabric domain"); err_fi_fabric: return ret; } /* * rpmemd_fip_fini_fabric_res -- deinitialize common fabric resources */ static void rpmemd_fip_fini_fabric_res(struct rpmemd_fip *fip) { RPMEMD_FI_CLOSE(fip->pep, "closing passive endpoint"); RPMEMD_FI_CLOSE(fip->eq, "closing event queue"); RPMEMD_FI_CLOSE(fip->domain, "closing fabric access domain"); RPMEMD_FI_CLOSE(fip->fabric, "closing fabric domain"); }
static void test_connect_with_accept_blocking_on_eq_fq_SERVER(void) { int ret; printf("SERVER running\n"); setup_ofi(NULL, NULL, FI_SOURCE); #if WANT_FDS // Add the EQ FD to the epoll fd static struct epoll_event edt; memset(&edt, 0, sizeof(edt)); edt.events = EPOLLIN; edt.data.u32 = 2222; ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fidev.eq_fd, &edt); if (ret < 0) { error("server epoll_ctl failed"); } #endif // Make a PEP ret = fi_passive_ep(fidev.fabric, fidev.info, &fidev.pep, NULL); if (0 != ret) { error("fi_passive_ep failed"); } #if WANT_FIXED_PORT size_t ss = sizeof(sin); ret = fi_getname(&(fidev.pep->fid), &sin, &ss); if (0 != ret) { error("fi_setname failed"); } sin.sin_port = htons(listen_port); // Bind the PEP to listen on a specific port ret = fi_setname(&(fidev.pep->fid), &sin, sizeof(sin)); if (0 != ret) { error("fi_setname failed"); } #endif // Bind the EQ to the PEP ret = fi_pep_bind(fidev.pep, &fidev.eq->fid, 0); if (0 != ret) { error("fi_pep_bind failed"); } // Listen ret = fi_listen(fidev.pep); if (0 != ret) { error("fi_listen failed"); } // Get the actual address of this PEP struct sockaddr_in sinout; size_t s = sizeof(sinout); ret = fi_getname(&(fidev.pep->fid), &sinout, &s); if (0 != ret) { error("fi_setname failed"); } sin.sin_family = sinout.sin_family; sin.sin_addr = sinout.sin_addr; sin.sin_port = sinout.sin_port; // Print server addr printf("SERVER listening on %s\n", addrstr(&sin)); // Send our node (IP addr) and service (port) to the client snprintf(ofi_node, sizeof(ofi_node) - 1, "%s", inet_ntoa(sin.sin_addr)); snprintf(ofi_service, sizeof(ofi_service) - 1, "%d", ntohs(sin.sin_port)); MPI_Send(ofi_node, sizeof(ofi_node) - 1, MPI_CHAR, 1, 101, MPI_COMM_WORLD); MPI_Send(ofi_service, sizeof(ofi_service) - 1, MPI_CHAR, 1, 102, MPI_COMM_WORLD); printf("SERVER sent via MPI to client: %s / %s\n", ofi_node, ofi_service); #if WANT_FDS // Now wait for the listen to complete int nevents; #define NEVENTS 32 struct epoll_event events[NEVENTS]; int timeout = 10000; while (1) { printf("SERVER blocking on epoll\n"); nevents = epoll_wait(epoll_fd, events, NEVENTS, timeout); if (nevents < 0) { if (errno != EINTR) { error("server epoll wait failed"); } else { continue; } } else { printf("SERVER successfully woke up from epoll! %d events\n", nevents); for (int i = 0; i < nevents; ++i) { if (events[i].data.u32 != 2222) { error("server unexpected epoll return type"); } } // If we got the expected event, then go read from the EQ break; } } #endif // Wait for the FI_CONNREQ event uint32_t event; uint8_t *entry_buffer; size_t expected_len = sizeof(struct fi_eq_cm_entry) + sizeof(client_data); entry_buffer = (uint8_t*) calloc(1, expected_len); if (NULL == entry_buffer) { error("calloc failed"); } struct fi_eq_cm_entry *entry = (struct fi_eq_cm_entry*) entry_buffer; while (1) { printf("SERVER waiting for FI_CONNREQ\n"); #if WANT_FDS ret = fi_eq_read(fidev.eq, &event, entry, expected_len, 0); #else ret = fi_eq_sread(fidev.eq, &event, entry, expected_len, -1, 0); #endif if (-FI_EAVAIL == ret) { printf("server fi_eq_sread failed because there's something in the error queue\n"); char buffer[2048]; struct fi_eq_err_entry *err_entry = (struct fi_eq_err_entry*) buffer; ret = fi_eq_readerr(fidev.eq, err_entry, 0); printf("error code: %d (%s), prov err code: %d (%s)\n", err_entry->err, fi_strerror(err_entry->err), err_entry->prov_errno, fi_strerror(err_entry->prov_errno)); error("sad panda"); } else if (-EAGAIN == ret) { fprintf(stderr, "SERVER fi_eq_sread fail got -EAGAIN... trying again...\n"); sleep(1); continue; } else if (ret < 0) { fprintf(stderr, "SERVER fi_eq_sread fail: %s (FI_EAVAIL = %d, -ret = %d)\n", fi_strerror(-ret), FI_EAVAIL, -ret); error("SERVER fi_eq_sread failed for some random reason"); } else if (event != FI_CONNREQ) { error("SERVER got some unexpected event"); } else if (ret != expected_len) { error("SERVER got wrong length back from fi_eq_sread"); } uint32_t *d = (uint32_t*) entry->data; for (int i = 0; i < (sizeof(client_data) / sizeof(uint32_t)); ++i) { if (d[i] != client_data[i]) { printf("SERVER got wrong CM client data: d[%d]=%d, should be %d\n", i, d[i], client_data[i]); } } printf("SERVER got FI_CONNREQ, correct size, and correct data -- yay!\n"); break; } // Silly logistics: setup_ofi_active adds the fd to the epoll set. // But we already added it. So for simplicity, just remove it // here so that setup_ofi_active() can re-add it. #if WANT_FDS // Remove the EQ FD from the epoll fd ret = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fidev.eq_fd, &edt); if (ret < 0) { error("server epoll_ctl DEL failed"); } #endif // Make an active endpoint setup_ofi_active(entry->info, &ficonn.ep); // Accept the incoming connection ret = fi_accept(ficonn.ep, (void*) server_data, sizeof(server_data)); if (ret != 0) { printf("fi_accept: ret=%d, %s\n", ret, fi_strerror(-ret)); error("SERVER fi_accept failed\n"); } // Need to read and get a FI_CONNECTED event while (1) { printf("SERVER waiting for FI_CONNECTED\n"); #if WANT_FDS ret = fi_eq_read(fidev.eq, &event, entry, expected_len, 0); #else ret = fi_eq_sread(fidev.eq, &event, entry, expected_len, -1, 0); #endif if (-FI_EAVAIL == ret) { printf("server fi_eq_sread failed because there's something in the error queue\n"); char buffer[2048]; struct fi_eq_err_entry *err_entry = (struct fi_eq_err_entry*) buffer; ret = fi_eq_readerr(fidev.eq, err_entry, 0); printf("error code: %d (%s), prov err code: %d (%s)\n", err_entry->err, fi_strerror(err_entry->err), err_entry->prov_errno, fi_strerror(err_entry->prov_errno)); error("sad panda"); } else if (-EAGAIN == ret) { fprintf(stderr, "SERVER fi_eq_sread fail got -EAGAIN... trying again...\n"); sleep(1); continue; } else if (ret < 0) { fprintf(stderr, "SERVER fi_eq_sread fail: %s (FI_EAVAIL = %d, -ret = %d)\n", fi_strerror(-ret), FI_EAVAIL, -ret); error("SERVER fi_eq_sread failed for some random reason"); } else if (event != FI_CONNECTED) { error("SERVER got some unexpected event"); } printf("SERVER got FI_CONNECTED -- yay!\n"); break; } // Post a recv buffer for the client to send int msg[4] = { 0 }; int len = sizeof(msg); printf("SERVER receiving len of %d\n", len); struct fid_mr no_mr; struct fid_mr *mr; void *recv_context = (void*) 0x17; #if 0 fi_mr_reg(fidev.domain, msg, len, FI_SEND | FI_RECV, 0, (uint64_t)(uintptr_t) msg, 0, &mr, NULL); #else // Try using no mr, like fi_msg_pingpong... memset(&no_mr, 0, sizeof(no_mr)); mr = &no_mr; #endif ret = fi_recv(ficonn.ep, msg, len, fi_mr_desc(mr), 0, recv_context); if (ret < 0) { printf("fi_recv failed! %d, %s\n", ret, fi_strerror(-ret)); MPI_Abort(MPI_COMM_WORLD, 37); } sleep(1); printf("SERVER posted receive -- waiting for client to send\n"); MPI_Barrier(MPI_COMM_WORLD); // Wait for receive completion struct fi_cq_entry cqe; while (1) { ret = fi_cq_sread(ficonn.cq, &cqe, 1, 0, -1); if (cqe.op_context == recv_context) { printf("SERVER receive completed\n"); break; } else { printf("SERVER got some other completion... continuing\n"); } } printf("SERVER finished -- waiting for client before teardown\n"); MPI_Barrier(MPI_COMM_WORLD); printf("SERVER tearing down\n"); fi_close(&(mr->fid)); teardown_ofi(); }
static int run_server(void) { int i, ret; printf("cmatose: starting server\n"); ret = fi_passive_ep(fabric, info, &pep, NULL); if (ret) { FT_PRINTERR("fi_passive_ep", ret); return ret; } ret = fi_pep_bind(pep, &eq->fid, 0); if (ret) { FT_PRINTERR("fi_ep_bind", ret); goto out; } ret = fi_listen(pep); if (ret) { FT_PRINTERR("fi_listen", ret); goto out; } ret = connect_events(); if (ret) goto out; if (hints->tx_attr->size) { printf("initiating data transfers\n"); for (i = 0; i < connections; i++) { ret = post_sends(&nodes[i]); if (ret) goto out; } printf("completing sends\n"); ret = poll_cqs(SEND_CQ_INDEX); if (ret) goto out; printf("receiving data transfers\n"); ret = poll_cqs(RECV_CQ_INDEX); if (ret) goto out; printf("data transfers complete\n"); } printf("cmatose: disconnecting\n"); for (i = 0; i < connections; i++) { if (!nodes[i].connected) continue; nodes[i].connected = 0; fi_shutdown(nodes[i].ep, 0); } ret = shutdown_events(); printf("disconnected\n"); out: fi_close(&pep->fid); return ret; }