/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int more_in_batch, void *cb_prv_data) { struct xio_msg *rsp; struct thread_data *tdata = cb_prv_data; /* alloc transaction */ rsp = msg_pool_get(tdata->pool); /* fill response */ rsp->request = req; rsp->more_in_batch = more_in_batch; rsp->in.header.iov_len = 0; rsp->out.header.iov_len = 0; vmsg_sglist_set_nents(&rsp->in, 0); if (tdata->user_param->verb == READ) vmsg_sglist_set_nents(&rsp->out, 0); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(tdata->pool, req); } return 0; }
/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int last_in_rxq, void *cb_prv_data) { struct xio_msg *rsp; struct thread_data *tdata = (struct thread_data *)cb_prv_data; /* process request */ process_request(tdata, req); /* alloc transaction */ rsp = msg_pool_get(tdata->pool); rsp->request = req; /* fill response */ msg_build_out_sgl(&msg_prms, rsp, test_config.hdr_len, 1, test_config.data_len); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(tdata->pool, req); /* better to do disconnect */ /*xio_disconnect(tdata->conn);*/ xio_assert(0); } tdata->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int more_in_batch, void *cb_user_context) { struct xio_msg *rsp; /* process request */ process_request(req); /* alloc transaction */ rsp = msg_pool_get(pool); rsp->request = req; rsp->more_in_batch = 0; /* fill response */ msg_write(&msg_params, rsp, test_config.hdr_len, 1, test_config.data_len); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, rsp); } return 0; }
/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int more_in_batch, void *cb_prv_data) { struct xio_msg *rsp; if (req->status) printf("**** request completed with error. [%s]\n", xio_strerror(req->status)); /* process request */ process_request(req); /* alloc transaction */ rsp = msg_pool_get(pool); rsp->request = req; rsp->more_in_batch = 0; /* fill response */ msg_set(rsp, 0, test_config.hdr_len, test_config.data_len); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, rsp); } return 0; }
/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int last_in_rxq, void *cb_prv_data) { struct xio_msg *rsp; /* process request */ process_request(req); /* alloc transaction */ rsp = msg_pool_get(pool); rsp->request = req; /* fill response */ msg_build_out_sgl(&msg_params, rsp, test_config.hdr_len, 1, test_config.data_len); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, req); xio_assert(0); } return 0; }
/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int last_in_rxq, void *cb_user_context) { struct ow_test_params *ow_params = (struct ow_test_params *)cb_user_context; struct xio_msg *new_msg; process_tx_message(ow_params, msg); ow_params->ndelivered++; /* can be safely returned to pool */ msg_pool_put(ow_params->pool, msg); if (ow_params->finite_run) { if (ow_params->ndelivered == ow_params->disconnect_nr) { xio_disconnect(ow_params->conn); return 0; } if (ow_params->nsent == ow_params->disconnect_nr) return 0; } /* peek message from the pool */ new_msg = msg_pool_get(ow_params->pool); if (new_msg == NULL) { printf("pool is empty\n"); return 0; } /* assign buffers to the message */ msg_write(&ow_params->msg_params, new_msg, test_config.hdr_len, 1, test_config.data_len); /* * ask for receipt since we need to put the message back * to pool */ new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send it */ if (xio_send_msg(ow_params->conn, new_msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, new_msg); xio_assert(0); } ow_params->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int on_new_session(struct xio_session *session, struct xio_new_session_req *session_data, void *cb_prv_data) { struct xio_msg *req; int i = 0; printf("**** [%p] on_new_session :%s:%d\n", session, get_ip((struct sockaddr *)&session_data->src_addr), get_port((struct sockaddr *)&session_data->src_addr)); xio_accept(session, NULL, 0, NULL, 0); msg_pool_reset(pool); conn = xio_get_connection(session, ctx); printf("**** starting ...\n"); while (1) { /* create transaction */ req = msg_pool_get(pool); if (req == NULL) break; /* get pointers to internal buffers */ req->in.header.iov_base = NULL; req->in.header.iov_len = 0; req->in.data_iovlen = 1; req->in.data_iov[0].iov_base = NULL; req->in.data_iov[0].iov_len = ONE_MB; req->in.data_iov[0].mr = NULL; /* recycle the message and fill new request */ msg_set(req, 1, test_config.hdr_len, test_config.data_len); /* try to send it */ if (xio_send_request(conn, req) == -1) { printf("**** sent %d messages\n", i); if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, req); return 0; } i++; if (i == 256) break; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_new_session(struct xio_session *session, struct xio_new_session_req *req, void *cb_user_context) { int i = 0; struct ow_test_params *ow_params = cb_user_context; struct xio_msg *msg; printf("**** [%p] on_new_session :%s:%d\n", session, get_ip((struct sockaddr *)&req->src_addr), get_port((struct sockaddr *)&req->src_addr)); xio_accept(session, NULL, 0, NULL, 0); if (ow_params->connection == NULL) ow_params->connection = xio_get_connection(session, ow_params->ctx); for (i = 0; i < MAX_OUTSTANDING_REQS; i++) { /* pick message from the pool */ msg = msg_pool_get(ow_params->pool); if (msg == NULL) break; /* assign buffers to the message */ msg_write(&ow_params->msg_params, msg, NULL, test_config.hdr_len, NULL, test_config.data_len); /* ask for read receipt since the message needed to be * recycled to the pool */ msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send the message */ if (xio_send_msg(ow_params->connection, msg) == -1) { printf("**** sent %d messages\n", i); if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, msg); return 0; } ow_params->nsent++; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int more_in_batch, void *cb_user_context) { struct xio_msg *new_msg; struct ow_test_params *ow_params = cb_user_context; ow_params->ndelivered++; /* can be safely freed */ msg_pool_put(ow_params->pool, msg); #if TEST_DISCONNECT if (ow_params->ndelivered == DISCONNECT_NR) { xio_disconnect(ow_params->connection); return 0; } if (ow_params->nsent == DISCONNECT_NR) return 0; #endif /* peek new message from the pool */ new_msg = msg_pool_get(ow_params->pool); new_msg->more_in_batch = 0; /* fill response */ msg_write(&ow_params->msg_params, new_msg, NULL, test_config.hdr_len, NULL, test_config.data_len); new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; if (xio_send_msg(ow_params->connection, new_msg) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(ow_params->pool, new_msg); } ow_params->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int on_message_delivered(struct xio_session *session, struct xio_msg *msg, int more_in_batch, void *cb_user_context) { struct xio_msg *new_msg; process_tx_message(msg); /* can be safely returned to pool */ msg_pool_put(pool, msg); /* peek message from the pool */ new_msg = msg_pool_get(pool); if (new_msg == NULL) { printf("pool is empty\n"); return 0; } /* assign buffers to the message */ msg_write(new_msg, NULL, test_config.hdr_len, NULL, test_config.data_len); /* * ask for receipt since we need to put the message back * to pool */ new_msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; /* send it */ if (xio_send_msg(conn, new_msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_msg " \ "failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(pool, new_msg); return 0; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_connection_established(struct xio_connection *conn) { struct xio_msg *msg; pr_info("**** starting ...\n"); /* create transaction */ msg = msg_pool_get(pool); if (!msg) return 0; /* get pointers to internal buffers */ msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; msg->in.data_tbl.nents = 0; /* sglist = vmsg_sglist(&msg->in); sglist[0].iov_base = NULL; sglist[0].iov_len = ONE_MB; sglist[0].mr = NULL; vmsg_sglist_set_nents(&msg->in, 1); */ /* recycle the message and fill new request */ msg_build_out_sgl(&msg_params, msg, test_config.hdr_len, 1, test_config.data_len); /* try to send it */ if (xio_send_request(conn, msg) == -1) { pr_info("**** sent %d messages\n", 1); if (xio_errno() != EAGAIN) pr_info("**** [%p] Error - xio_send_msg " \ "failed. %s\n", conn, xio_strerror(xio_errno())); msg_pool_put(pool, msg); xio_assert(0); } return 0; }
/*---------------------------------------------------------------------------*/ static int on_request(struct xio_session *session, struct xio_msg *req, int more_in_batch, void *cb_user_context) { struct xio_msg *rsp; struct test_params *test_params = cb_user_context; if (req->status) printf("**** request completed with error. [%s]\n", xio_strerror(req->status)); /* process request */ process_request(req); /* alloc transaction */ rsp = msg_pool_get(test_params->pool); rsp->request = req; rsp->more_in_batch = 0; /* fill response */ msg_write(&test_params->msg_params, rsp, NULL, test_config.hdr_len, NULL, test_config.data_len); if (xio_send_response(rsp) == -1) { printf("**** [%p] Error - xio_send_msg failed. %s\n", session, xio_strerror(xio_errno())); msg_pool_put(test_params->pool, req); } test_params->nsent++; return 0; }
/*---------------------------------------------------------------------------*/ static int raio_handle_setup(void *prv_session_data, void *prv_portal_data, struct raio_command *cmd, char *cmd_data, struct xio_msg *req) { int fd, j; struct raio_io_session_data *sd = prv_session_data; struct raio_io_portal_data *pd = prv_portal_data; if (3*sizeof(int) != cmd->data_len) { errno = EINVAL; printf("io setup request rejected\n"); goto reject; } unpack_u32((uint32_t *)&pd->iodepth, unpack_u32((uint32_t *)&fd, cmd_data)); pd->io_u_free_nr = pd->iodepth + EXTRA_MSGS; pd->io_us_free = calloc(pd->io_u_free_nr, sizeof(struct raio_io_u)); pd->rsp_pool = msg_pool_create(512, MAXBLOCKSIZE, pd->io_u_free_nr); TAILQ_INIT(&pd->io_u_free_list); /* register each io_u in the free list */ for (j = 0; j < pd->io_u_free_nr; j++) { pd->io_us_free[j].rsp = msg_pool_get(pd->rsp_pool); TAILQ_INSERT_TAIL(&pd->io_u_free_list, &pd->io_us_free[j], io_u_list); } if (sd->is_null) pd->bs_dev = raio_bs_init(pd->ctx, "null"); else pd->bs_dev = raio_bs_init(pd->ctx, "aio"); errno = -raio_bs_open(pd->bs_dev, fd); reject: if (errno) { struct raio_answer ans = { RAIO_CMD_IO_SETUP, 0, -1, errno }; pack_u32((uint32_t *)&ans.ret_errno, pack_u32((uint32_t *)&ans.ret, pack_u32(&ans.data_len, pack_u32(&ans.command, pd->rsp_hdr)))); } else { struct raio_answer ans = { RAIO_CMD_IO_SETUP, 0, 0, 0 }; pack_u32((uint32_t *)&ans.ret_errno, pack_u32((uint32_t *)&ans.ret, pack_u32(&ans.data_len, pack_u32(&ans.command, pd->rsp_hdr)))); } pd->rsp.out.header.iov_len = sizeof(struct raio_answer); pd->rsp.request = req; xio_send_response(&pd->rsp); return 0; }
/*---------------------------------------------------------------------------*/ static void *worker_thread(void *data) { struct thread_data *tdata = data; cpu_set_t cpuset; struct xio_msg *msg; int i; /* set affinity to thread */ CPU_ZERO(&cpuset); CPU_SET(tdata->affinity, &cpuset); pthread_setaffinity_np(tdata->thread_id, sizeof(cpu_set_t), &cpuset); /* prepare data for the cuurent thread */ tdata->pool = msg_pool_alloc(tdata->user_param->queue_depth); /* create thread context for the client */ tdata->ctx = xio_context_create(NULL, tdata->user_param->poll_timeout, tdata->affinity); /* connect the session */ tdata->conn = xio_connect(tdata->session, tdata->ctx, tdata->cid, NULL, tdata); if (tdata->data_len) tdata->xbuf = xio_alloc(tdata->data_len); for (i = 0; i < tdata->user_param->queue_depth; i++) { /* create transaction */ msg = msg_pool_get(tdata->pool); if (msg == NULL) break; /* get pointers to internal buffers */ msg->in.header.iov_len = 0; msg->in.data_iovlen = 0; msg->out.header.iov_len = 0; if (tdata->data_len) { msg->out.data_iovlen = 1; msg->out.data_iov[0].iov_base = tdata->xbuf->addr; msg->out.data_iov[0].iov_len = tdata->xbuf->length; msg->out.data_iov[0].mr = tdata->xbuf->mr; } else { msg->out.data_iovlen = 0; } msg->user_context = (void *)get_cycles(); /* send first message */ if (xio_send_request(tdata->conn, msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_request " \ "failed. %s\n", tdata->session, xio_strerror(xio_errno())); msg_pool_put(tdata->pool, msg); return 0; } if (tdata->do_stat) tdata->stat.scnt++; tdata->tx_nr++; } /* the default xio supplied main loop */ xio_context_run_loop(tdata->ctx, XIO_INFINITE); /* normal exit phase */ if (tdata->pool) msg_pool_free(tdata->pool); if (tdata->xbuf) xio_free(&tdata->xbuf); /* free the context */ xio_context_destroy(tdata->ctx); return NULL; }
/*---------------------------------------------------------------------------*/ static int on_response(struct xio_session *session, struct xio_msg *msg, int last_in_rxq, void *cb_user_context) { struct test_params *test_params = (struct test_params *)cb_user_context; struct xio_iovec_ex *sglist; static int chain_messages = CHAIN_MESSAGES; size_t j; test_params->nrecv++; process_response(test_params, msg); /* message is no longer needed */ xio_release_response(msg); msg_pool_put(test_params->pool, msg); if (test_params->finite_run) { if (test_params->nrecv == test_params->disconnect_nr) { xio_disconnect(test_params->connection); return 0; } if (test_params->nsent == test_params->disconnect_nr) return 0; } /* peek message from the pool */ msg = msg_pool_get(test_params->pool); if (msg == NULL) { printf("pool is empty\n"); return 0; } msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; sglist = vmsg_sglist(&msg->in); vmsg_sglist_set_nents(&msg->in, test_config.in_iov_len); /* tell accelio to use 1MB buffer from its internal pool */ for (j = 0; j < test_config.in_iov_len; j++) { sglist[j].iov_base = NULL; sglist[j].iov_len = ONE_MB; sglist[j].mr = NULL; } msg->sn = 0; /* assign buffers to the message */ msg_build_out_sgl(&test_params->msg_params, msg, test_config.hdr_len, test_config.out_iov_len, test_config.data_len); if (chain_messages) { msg->next = NULL; if (test_params->chain.head == NULL) { test_params->chain.head = msg; test_params->chain.tail = test_params->chain.head; } else { test_params->chain.tail->next = msg; test_params->chain.tail = test_params->chain.tail->next; } if (++test_params->chain.sz == MAX_OUTSTANDING_REQS) { if (xio_send_request(test_params->connection, test_params->chain.head) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_request " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(test_params->pool, msg); xio_assert(xio_errno() == EAGAIN); } test_params->nsent += test_params->chain.sz; test_params->chain.head = NULL; test_params->chain.sz = 0; } } else { /* try to send it */ /*msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; */ /*msg->flags = XIO_MSG_FLAG_PEER_READ_REQ;*/ if (xio_send_request(test_params->connection, msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_request " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(test_params->pool, msg); xio_assert(xio_errno() == EAGAIN); } test_params->nsent++; } return 0; }
/*---------------------------------------------------------------------------*/ static int on_msg_send_complete(struct xio_session *session, struct xio_msg *msg, void *cb_user_context) { struct test_params *test_params = cb_user_context; process_message(test_params, msg); test_params->ncomp++; /* can be safely freed */ msg_pool_put(test_params->pool, msg); if (test_params->finite_run) { if ((test_params->ncomp+test_params->ndelivered) > test_params->disconnect_nr) return 0; if ((test_params->ncomp + test_params->ndelivered) == test_params->disconnect_nr) { xio_disconnect(test_params->connection); return 0; } } if (test_params->closed) return 0; /* peek message from the pool */ msg = msg_pool_get(test_params->pool); if (msg == NULL) { printf("pool is empty\n"); return 0; } /* reset message */ msg->in.header.iov_base = NULL; msg->in.header.iov_len = 0; msg->in.data_iov.nents = 0; msg->more_in_batch = 0; /* assign buffers to the message */ msg_write(&test_params->msg_params, msg, test_config.hdr_len, 1, test_config.data_len); /* try to send it */ if (test_params->ask_for_receipt) msg->flags = XIO_MSG_FLAG_REQUEST_READ_RECEIPT; else msg->flags = 0; if (xio_send_msg(test_params->connection, msg) == -1) { if (xio_errno() != EAGAIN) printf("**** [%p] Error - xio_send_request " \ "failed %s\n", session, xio_strerror(xio_errno())); msg_pool_put(test_params->pool, msg); xio_assert(0); } test_params->nsent++; return 0; }