vhost: allocate just one ctx per foreach_session chain
We used to allocate a ctx whenever new event had to be sent, but since all events in foreach_session are always called in a chain, we could allocate one ctx at the start and then re-initialize it before sending each msg. Change-Id: Ie5477b07242f0c6eb6dc2160055a829da8ba5d11 Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459167 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
3fb1a9565e
commit
feaf45d31a
@ -981,9 +981,8 @@ spdk_vhost_session_send_event(struct vhost_poll_group *pg,
|
|||||||
return g_dpdk_response;
|
return g_dpdk_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void foreach_session_continue(struct spdk_vhost_dev *vdev,
|
static void foreach_session_continue(struct spdk_vhost_session_fn_ctx *ev_ctx,
|
||||||
struct spdk_vhost_session *vsession,
|
struct spdk_vhost_session *vsession);
|
||||||
spdk_vhost_session_fn fn, void *arg);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
foreach_session_finish_cb(void *arg1)
|
foreach_session_finish_cb(void *arg1)
|
||||||
@ -1042,28 +1041,27 @@ foreach_session_continue_cb(void *arg1)
|
|||||||
|
|
||||||
rc = ctx->cb_fn(vdev, vsession, ctx->user_ctx);
|
rc = ctx->cb_fn(vdev, vsession, ctx->user_ctx);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
goto out_unlock;
|
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
||||||
|
free(ctx);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_unlock_continue:
|
out_unlock_continue:
|
||||||
vsession = spdk_vhost_session_next(vdev, ctx->vsession_id);
|
vsession = spdk_vhost_session_next(vdev, ctx->vsession_id);
|
||||||
foreach_session_continue(vdev, vsession, ctx->cb_fn, ctx->user_ctx);
|
foreach_session_continue(ctx, vsession);
|
||||||
out_unlock:
|
|
||||||
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
pthread_mutex_unlock(&g_spdk_vhost_mutex);
|
||||||
free(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
foreach_session_continue(struct spdk_vhost_dev *vdev,
|
foreach_session_continue(struct spdk_vhost_session_fn_ctx *ev_ctx,
|
||||||
struct spdk_vhost_session *vsession,
|
struct spdk_vhost_session *vsession)
|
||||||
spdk_vhost_session_fn fn, void *arg)
|
|
||||||
{
|
{
|
||||||
struct spdk_vhost_session_fn_ctx *ev_ctx;
|
struct spdk_vhost_dev *vdev = ev_ctx->vdev;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
while (vsession != NULL && !vsession->started) {
|
while (vsession != NULL && !vsession->started) {
|
||||||
if (vsession->initialized) {
|
if (vsession->initialized) {
|
||||||
rc = fn(vdev, vsession, arg);
|
rc = ev_ctx->cb_fn(vdev, vsession, ev_ctx->user_ctx);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1072,17 +1070,6 @@ foreach_session_continue(struct spdk_vhost_dev *vdev,
|
|||||||
vsession = spdk_vhost_session_next(vdev, vsession->id);
|
vsession = spdk_vhost_session_next(vdev, vsession->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ev_ctx = calloc(1, sizeof(*ev_ctx));
|
|
||||||
if (ev_ctx == NULL) {
|
|
||||||
SPDK_ERRLOG("Failed to alloc vhost event.\n");
|
|
||||||
assert(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ev_ctx->vdev = vdev;
|
|
||||||
ev_ctx->cb_fn = fn;
|
|
||||||
ev_ctx->user_ctx = arg;
|
|
||||||
|
|
||||||
if (vsession != NULL) {
|
if (vsession != NULL) {
|
||||||
ev_ctx->vsession_id = vsession->id;
|
ev_ctx->vsession_id = vsession->id;
|
||||||
spdk_thread_send_msg(vsession->poll_group->thread,
|
spdk_thread_send_msg(vsession->poll_group->thread,
|
||||||
@ -1099,10 +1086,22 @@ spdk_vhost_dev_foreach_session(struct spdk_vhost_dev *vdev,
|
|||||||
spdk_vhost_session_fn fn, void *arg)
|
spdk_vhost_session_fn fn, void *arg)
|
||||||
{
|
{
|
||||||
struct spdk_vhost_session *vsession = TAILQ_FIRST(&vdev->vsessions);
|
struct spdk_vhost_session *vsession = TAILQ_FIRST(&vdev->vsessions);
|
||||||
|
struct spdk_vhost_session_fn_ctx *ev_ctx;
|
||||||
|
|
||||||
|
ev_ctx = calloc(1, sizeof(*ev_ctx));
|
||||||
|
if (ev_ctx == NULL) {
|
||||||
|
SPDK_ERRLOG("Failed to alloc vhost event.\n");
|
||||||
|
assert(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ev_ctx->vdev = vdev;
|
||||||
|
ev_ctx->cb_fn = fn;
|
||||||
|
ev_ctx->user_ctx = arg;
|
||||||
|
|
||||||
assert(vdev->pending_async_op_num < UINT32_MAX);
|
assert(vdev->pending_async_op_num < UINT32_MAX);
|
||||||
vdev->pending_async_op_num++;
|
vdev->pending_async_op_num++;
|
||||||
foreach_session_continue(vdev, vsession, fn, arg);
|
foreach_session_continue(ev_ctx, vsession);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user