コード例 #1
0
ファイル: xio_perftest_server.c プロジェクト: xiaom/accelio
/*---------------------------------------------------------------------------*/
static int assign_data_in_buf(struct xio_msg *msg, void *cb_user_context)
{
	struct thread_data	*tdata = cb_user_context;
	struct xio_iovec_ex	*sglist = vmsg_sglist(&msg->in);

	if (!tdata->in_xbuf) {
		tdata->in_xbuf = xio_alloc(sglist[0].iov_len);
	} else if (tdata->in_xbuf->length < sglist[0].iov_len) {
		xio_free(&tdata->in_xbuf);
		tdata->in_xbuf = xio_alloc(sglist[0].iov_len);
	}

	vmsg_sglist_set_nents(&msg->in, 1);

	sglist[0].iov_base	= tdata->in_xbuf->addr;
	sglist[0].iov_len	= tdata->in_xbuf->length;
	sglist[0].mr		= tdata->in_xbuf->mr;

	return 0;
}
コード例 #2
0
ファイル: xio_bidi_client.c プロジェクト: xiaom/accelio
/*---------------------------------------------------------------------------*/
static int assign_data_in_buf(struct xio_msg *msg, void *cb_user_context)
{
	struct xio_iovec_ex	*sglist = vmsg_sglist(&msg->in);

	vmsg_sglist_set_nents(&msg->in, 1);
	if (xbuf == NULL)
		xbuf = xio_alloc(XIO_READ_BUF_LEN);

	sglist[0].iov_base = xbuf->addr;
	sglist[0].mr = xbuf->mr;
	sglist[0].iov_len = XIO_READ_BUF_LEN;

	return 0;
}
コード例 #3
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;
}